From 2cd187abaf00401f9f6e8ab0d4ba35795bf3415f Mon Sep 17 00:00:00 2001 From: Chris Svenningsen Date: Thu, 20 Aug 2020 11:23:09 -0700 Subject: [PATCH] Migrate AddNewLines to Storybook --- ts/components/conversation/AddNewLines.md | 35 ------------ .../conversation/AddNewLines.stories.tsx | 57 +++++++++++++++++++ ts/components/conversation/AddNewLines.tsx | 2 +- 3 files changed, 58 insertions(+), 36 deletions(-) delete mode 100644 ts/components/conversation/AddNewLines.md create mode 100644 ts/components/conversation/AddNewLines.stories.tsx diff --git a/ts/components/conversation/AddNewLines.md b/ts/components/conversation/AddNewLines.md deleted file mode 100644 index 14d2b35ec..000000000 --- a/ts/components/conversation/AddNewLines.md +++ /dev/null @@ -1,35 +0,0 @@ -### All newlines - -```jsx - -``` - -### Starting and ending with newlines - -```jsx - -``` - -### With newlines in the middle - -```jsx - -``` - -### No newlines - -```jsx - -``` - -### Providing custom non-newline render function - -```jsx -const renderNonNewLine = ({ text, key }) => ( - This is my custom content! -); -; -``` diff --git a/ts/components/conversation/AddNewLines.stories.tsx b/ts/components/conversation/AddNewLines.stories.tsx new file mode 100644 index 000000000..94d050ee1 --- /dev/null +++ b/ts/components/conversation/AddNewLines.stories.tsx @@ -0,0 +1,57 @@ +import * as React from 'react'; + +import { text } from '@storybook/addon-knobs'; +import { storiesOf } from '@storybook/react'; + +import { AddNewLines, Props } from './AddNewLines'; + +const story = storiesOf('Components/Conversation/AddNewLines', module); +const createProps = (overrideProps: Partial = {}): Props => ({ + renderNonNewLine: overrideProps.renderNonNewLine, + text: text('text', overrideProps.text || ''), +}); + +story.add('All newlines', () => { + const props = createProps({ + text: '\n\n\n', + }); + + return ; +}); + +story.add('Starting/Ending with Newlines', () => { + const props = createProps({ + text: '\nSome text\n', + }); + + return ; +}); + +story.add('Newlines in the Middle', () => { + const props = createProps({ + text: 'Some\ntext', + }); + + return ; +}); + +story.add('No Newlines', () => { + const props = createProps({ + text: 'Some text', + }); + + return ; +}); + +story.add('Custom Render Function', () => { + const props = createProps({ + text: 'Some text', + renderNonNewLine: ({ text: theText, key }) => ( +
+ {theText} +
+ ), + }); + + return ; +}); diff --git a/ts/components/conversation/AddNewLines.tsx b/ts/components/conversation/AddNewLines.tsx index 986a9a5b7..ca745b8fb 100644 --- a/ts/components/conversation/AddNewLines.tsx +++ b/ts/components/conversation/AddNewLines.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { RenderTextCallbackType } from '../../types/Util'; -interface Props { +export interface Props { text: string; /** Allows you to customize now non-newlines are rendered. Simplest is just a . */ renderNonNewLine?: RenderTextCallbackType;