2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-08-20 18:23:09 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
import { text } from '@storybook/addon-knobs';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { Props } from './AddNewLines';
|
|
|
|
import { AddNewLines } from './AddNewLines';
|
2020-08-20 18:23:09 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export default {
|
|
|
|
title: 'Components/Conversation/AddNewLines',
|
|
|
|
};
|
|
|
|
|
2020-08-20 18:23:09 +00:00
|
|
|
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
|
|
|
|
renderNonNewLine: overrideProps.renderNonNewLine,
|
|
|
|
text: text('text', overrideProps.text || ''),
|
|
|
|
});
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const AllNewlines = (): JSX.Element => {
|
2020-08-20 18:23:09 +00:00
|
|
|
const props = createProps({
|
|
|
|
text: '\n\n\n',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <AddNewLines {...props} />;
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AllNewlines.story = {
|
|
|
|
name: 'All newlines',
|
|
|
|
};
|
2020-08-20 18:23:09 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const StartingEndingWithNewlines = (): JSX.Element => {
|
2020-08-20 18:23:09 +00:00
|
|
|
const props = createProps({
|
|
|
|
text: '\nSome text\n',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <AddNewLines {...props} />;
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
StartingEndingWithNewlines.story = {
|
|
|
|
name: 'Starting/Ending with Newlines',
|
|
|
|
};
|
2020-08-20 18:23:09 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const NewlinesInTheMiddle = (): JSX.Element => {
|
2020-08-20 18:23:09 +00:00
|
|
|
const props = createProps({
|
|
|
|
text: 'Some\ntext',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <AddNewLines {...props} />;
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
NewlinesInTheMiddle.story = {
|
|
|
|
name: 'Newlines in the Middle',
|
|
|
|
};
|
2020-08-20 18:23:09 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const NoNewlines = (): JSX.Element => {
|
2020-08-20 18:23:09 +00:00
|
|
|
const props = createProps({
|
|
|
|
text: 'Some text',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <AddNewLines {...props} />;
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|
2020-08-20 18:23:09 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const CustomRenderFunction = (): JSX.Element => {
|
2020-08-20 18:23:09 +00:00
|
|
|
const props = createProps({
|
|
|
|
text: 'Some text',
|
|
|
|
renderNonNewLine: ({ text: theText, key }) => (
|
|
|
|
<div key={key} style={{ color: 'aquamarine' }}>
|
|
|
|
{theText}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
return <AddNewLines {...props} />;
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|