diff --git a/apps/example/.rnstorybook/stories/components/EnrichedMarkdownText/EnrichedMarkdownText.stories.tsx b/apps/example/.rnstorybook/stories/components/EnrichedMarkdownText/EnrichedMarkdownText.stories.tsx deleted file mode 100644 index c886173c..00000000 --- a/apps/example/.rnstorybook/stories/components/EnrichedMarkdownText/EnrichedMarkdownText.stories.tsx +++ /dev/null @@ -1,322 +0,0 @@ -import React from 'react'; -import type { ComponentProps } from 'react'; -import type { Meta, StoryObj } from '@storybook/react-native'; -import { EnrichedMarkdownText } from 'react-native-enriched-markdown'; -import { - EnrichedMarkdownTextStory, - SpoilerStory, -} from './EnrichedMarkdownTextStory'; - -const meta: Meta = { - title: 'EnrichedMarkdownText', - component: EnrichedMarkdownText, - parameters: { - controls: { exclude: ['markdown'] }, - }, - argTypes: { - style: { control: 'object' }, - onLinkPress: { name: 'onLinkPress', action: 'onLinkPress' }, - onLinkLongPress: { name: 'onLinkLongPress', action: 'onLinkLongPress' }, - onTaskListItemPress: { - name: 'onTaskListItemPress', - action: 'onTaskListItemPress', - }, - }, -}; - -export default meta; -type Story = Omit, 'args' | 'render' | 'argTypes'> & { - args?: ComponentProps & Record; - render: ( - args: ComponentProps & Record - ) => React.ReactElement; - argTypes?: Record; -}; - -export const InlineMarkdown: Story = { - args: { - markdown: - '**Bold**, *italic*, ***bold italic***, ~~strikethrough~~, `inline code`, [link](https://example.com)', - }, - render: (args) => ( - - ), -}; - -export const Headings: Story = { - args: { - markdown: '# H1\n## H2\n### H3\n#### H4\n##### H5\n###### H6', - }, - render: (args) => ( - - ), -}; - -export const CodeBlock: Story = { - args: { - markdown: '`inline code` and\n\n```\nconst x = 1;\nconsole.log(x);\n```', - }, - render: (args) => ( - - ), -}; - -export const Table: Story = { - args: { - markdown: - '| Col A | Col B |\n| ----- | ----- |\n| one | two |\n| three | four |', - flavor: 'github', - }, - argTypes: { - flavor: { - options: ['github', 'commonmark'], - control: { type: 'inline-radio' }, - }, - }, - render: (args) => ( - - ), -}; - -export const Md4cFlags: Story = { - args: { - markdown: '_underline_\n\ntext^superscript^\n\ntext~subscript~', - underline: true, - superscript: true, - subscript: true, - }, - argTypes: { - underline: { - label: 'Underline', - control: 'boolean', - description: 'When on, _text_ = underline. Only *text* works for italic.', - }, - superscript: { - label: 'Superscript', - control: 'boolean', - description: '^text^ renders as superscript.', - }, - subscript: { - label: 'Subscript', - control: 'boolean', - description: - '~text~ renders as subscript. When off, single tilde is strikethrough.', - }, - }, - render: ({ underline, superscript, subscript, ...args }) => ( - - ), -}; - -export const Spoiler: Story = { - args: { - markdown: "The twist: ||the butler did it||. Don't spoil it.", - overlay: 'particles', - }, - argTypes: { - overlay: { - options: ['particles', 'solid'], - control: { type: 'inline-radio' }, - }, - onReloadSpoiler: { action: 'onReloadSpoiler' }, - }, - render: (args) => ( - - ), -}; - -export const ThematicBreak: Story = { - args: { - markdown: 'text before\n\n---\n\ntext after', - }, - render: (args) => ( - - ), -}; - -export const BlockQuote: Story = { - args: { - markdown: - '> This is a blockquote.\n>> Double blockquote!\n\n> Have you heard what did she say?\n\nyes thats crazy!', - }, - render: (args) => ( - - ), -}; - -export const Lists: Story = { - args: { - markdown: - '- Unordered item\n- Another item\n - Nested unordered\n - Also nested\n\n1. First ordered\n2. Second ordered\n 1. Nested ordered\n 2. Still nested\n3. Back to top level', - }, - render: (args) => ( - - ), -}; - -export const Links: Story = { - args: { - markdown: - 'Check out [React Native](https://reactnative.dev) and [Expo](https://expo.dev).', - preview: true, - }, - argTypes: { - preview: { - control: 'boolean', - description: 'Show a preview sheet on long-press.', - }, - }, - render: ({ preview, ...args }) => ( - - ), -}; - -export const TaskList: Story = { - args: { - markdown: - '- [x] Design component API\n- [x] Write native bridge\n- [ ] Add tests\n- [ ] Publish to npm', - flavor: 'github', - }, - argTypes: { - flavor: { - label: 'Flavor', - options: ['github', 'commonmark'], - control: { type: 'inline-radio' }, - description: - 'Task lists require flavor="github" (GFM). commonmark renders them as plain list items.', - }, - }, - render: (args) => ( - - ), -}; - -export const Selection: Story = { - args: { - markdown: - 'Select some of this text to see the highlight color in action.\n\nYou can also try **bold**, _italic_, and `code` spans.', - selectable: true, - }, - argTypes: { - selectable: { - control: 'boolean', - description: 'Allow text to be selected.', - }, - selColor: { - control: 'color', - description: - 'Highlight color. On iOS also sets the caret and handle color.', - }, - handleColor: { - control: 'color', - description: 'Drag handle color. Android only, API 29+.', - }, - }, - render: ({ selColor, handleColor, ...args }) => ( - - ), -}; - -export const SelectionMenu: Story = { - args: { - markdown: - 'Select this text and open the context menu to see the built-in actions.\n\nHere is some **bold** and _italic_ text, plus `inline code`.\n\n![Misty forest at sunrise](https://images.unsplash.com/photo-1448375240586-882707db888b?w=800)', - copyMd: true, - imgUrl: true, - }, - argTypes: { - copyMd: { - control: 'boolean', - description: 'Show "Copy as Markdown" in the selection menu.', - }, - imgUrl: { - control: 'boolean', - description: - 'Show "Copy Image URL" when selected content contains images.', - }, - }, - render: ({ copyMd, imgUrl, ...args }) => ( - - ), -}; - -export const LatexMath: Story = { - args: { - markdown: - 'Inline: $E = mc^2$\n\nBlock:\n\n$$\n\\int_0^\\infty e^{-x}\\,dx = 1\n$$\n', - latexMath: true, - flavor: 'github', - }, - argTypes: { - latexMath: { - label: 'LaTeX math', - control: 'boolean', - description: 'Enable LaTeX math parsing.', - }, - }, - render: ({ latexMath, ...args }) => ( - - ), -}; diff --git a/apps/example/.rnstorybook/stories/components/EnrichedMarkdownText/EnrichedMarkdownTextStory.tsx b/apps/example/.rnstorybook/stories/components/EnrichedMarkdownText/EnrichedMarkdownTextStory.tsx index c969323b..2a866e4a 100644 --- a/apps/example/.rnstorybook/stories/components/EnrichedMarkdownText/EnrichedMarkdownTextStory.tsx +++ b/apps/example/.rnstorybook/stories/components/EnrichedMarkdownText/EnrichedMarkdownTextStory.tsx @@ -1,12 +1,5 @@ import React, { useState } from 'react'; -import { - Button, - ScrollView, - Text, - TextInput, - View, - StyleSheet, -} from 'react-native'; +import { ScrollView, Text, TextInput, View, StyleSheet } from 'react-native'; import { EnrichedMarkdownText } from 'react-native-enriched-markdown'; import type { EnrichedMarkdownTextProps } from 'react-native-enriched-markdown'; @@ -17,15 +10,21 @@ type Props = { style?: EnrichedMarkdownTextProps['markdownStyle']; } & EnrichedMarkdownTextProps; -export function EnrichedMarkdownTextStory({ +type MarkdownStoryLayoutProps = { + title: string; + description: string; + markdown: string; + onMarkdownChange: (markdown: string) => void; + output: React.ReactNode; +}; + +export function MarkdownStoryLayout({ title, description, - markdown: initialMarkdown, - style, - ...props -}: Props) { - const [markdown, setMarkdown] = useState(initialMarkdown); - + markdown, + onMarkdownChange, + output, +}: MarkdownStoryLayoutProps) { return ( {title} @@ -36,7 +35,7 @@ export function EnrichedMarkdownTextStory({ Output - - - + {output} ); } -export function SpoilerStory({ - overlay, - onReloadSpoiler, +export function EnrichedMarkdownTextStory({ + title, + description, + markdown: initialMarkdown, + style, ...props -}: EnrichedMarkdownTextProps & Record) { - const [key, setKey] = React.useState(0); +}: Props) { + const [markdown, setMarkdown] = useState(initialMarkdown); + return ( - - - -