-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
6,221 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/react/src/drafts/MarkdownToolbar/MarkdownToolbar.docs.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"id": "drafts_markdown_viewer", | ||
"name": "MarkdownViewer", | ||
"status": "draft", | ||
"a11yReviewed": false, | ||
"stories": [], | ||
"props": [ | ||
{ | ||
"name": "markdownValue", | ||
"type": "string", | ||
"description": "The markdown the HTML was rendered from. This is not used for viewing, only as a source for change events." | ||
}, | ||
{ | ||
"name": "dangerousRenderHTML", | ||
"type": "{ __html: string }", | ||
"description": "Set the rendered HTML of the viewer. To prevent XSS, ensure that the source of this HTML is trusted!" | ||
}, | ||
{ | ||
"name": "loading", | ||
"type": "boolean", | ||
"description": "Show a loading spinner instead of content." | ||
}, | ||
{ | ||
"name": "onLinkClick", | ||
"type": "(event: MouseEvent) => void", | ||
"description": "Called when the user clicks a link element. This can be used to intercept the click and provide custom routing. Note that this is a native HTML `MouseEvent` and not a `React.ClickEvent`." | ||
}, | ||
{ | ||
"name": "openLinksInNewTab", | ||
"type": "boolean" | ||
}, | ||
{ | ||
"name": "onChange", | ||
"type": "(markdown: string) => void | Promise<void>", | ||
"description": "Called when the user interacts and updates the Markdown. The rendered Markdown is updated eagerly - if the request fails, a rejected Promise should be returned by this handler. In that case, the viewer will revert the visual change. If the change is handled by an async API request (as it typically will be in production code), the viewer should be `disabled` while the request is pending to avoid conflicts. To allow users to check multiple boxes rapidly, the API request should be debounced (an ideal debounce duration is about 1 second)." | ||
}, | ||
{ | ||
"name": "disabled", | ||
"type": "boolean", | ||
"description": "Control whether interaction is disabled." | ||
} | ||
], | ||
"subcomponents": [] | ||
} |
90 changes: 90 additions & 0 deletions
90
packages/react/src/drafts/MarkdownToolbar/MarkdownToolbar.features.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, {Meta} from '@storybook/react' | ||
import {debounce} from 'lodash' | ||
import {useCallback, useMemo, useState} from 'react' | ||
import BaseStyles from '../../BaseStyles' | ||
import Box from '../../Box' | ||
import ThemeProvider from '../../ThemeProvider' | ||
import {useSafeAsyncCallback} from '../hooks/useSafeAsyncCallback' | ||
import MarkdownToolbar from './MarkdownToolbar' | ||
|
||
const meta: Meta = { | ||
title: 'Draft/Components/MarkdownViewer/Features', | ||
decorators: [ | ||
Story => { | ||
return ( | ||
<ThemeProvider> | ||
<BaseStyles> | ||
<Box sx={{maxWidth: 800}}>{Story()}</Box> | ||
</BaseStyles> | ||
</ThemeProvider> | ||
) | ||
}, | ||
], | ||
parameters: { | ||
controls: { | ||
include: ['Loading', 'Open Links In New Tab'], | ||
}, | ||
}, | ||
component: MarkdownToolbar, | ||
args: { | ||
loading: false, | ||
linksInNewTab: false, | ||
}, | ||
argTypes: { | ||
loading: { | ||
name: 'Loading', | ||
control: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
linksInNewTab: { | ||
name: 'Open Links In New Tab', | ||
control: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export default meta | ||
|
||
type ArgProps = { | ||
loading: boolean | ||
linksInNewTab: boolean | ||
} | ||
|
||
const sampleMarkdownSource = ` | ||
### Sample markdown | ||
#### Formatted text | ||
- **bold** | ||
- _italic_ | ||
- \`inline code\` | ||
> quote | ||
\`\`\` | ||
code block | ||
\`\`\` | ||
#### Links | ||
- [GitHub](https://github.com) | ||
- [Primer](https://primer.style) | ||
- [Universe](https://www.githubuniverse.com/) | ||
#### Tasks | ||
- [ ] Task 1 | ||
- [ ] Task 2 | ||
- [ ] Task 3` | ||
|
||
export const Basic: Story = args => { | ||
const {...rest} = args | ||
const id = useId() | ||
return <> | ||
<MarkdownToolbar for={id} {...rest} /> | ||
<textarea id={id} defualtValue={sampleMarkdownSource}></textarea> | ||
</> | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/react/src/drafts/MarkdownToolbar/MarkdownToolbar.playground.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import type {Meta, StoryFn} from '@storybook/react' | ||
import MarkdownToolbar from './MarkdownToolbar' | ||
import TextArea from '../../Textarea' | ||
import {useId} from '../../hooks/useId' | ||
import {ActionList, Box} from '../../.index' | ||
import data from './mock-story-data' | ||
|
||
export default { | ||
title: 'Drafts/Components/MarkdownToolbar/Playground', | ||
component: MarkdownToolbar, | ||
|
||
args: {}, | ||
argTypes: {}, | ||
} as Meta<typeof MarkdownToolbar> | ||
|
||
export const Playground: StoryFn = args => { | ||
const id = useId() | ||
return ( | ||
<> | ||
<MarkdownToolbar for={id} sx={{display: 'block'}}> | ||
<MarkdownToolbar.DefaultButtons></MarkdownToolbar.DefaultButtons> | ||
</MarkdownToolbar> | ||
<TextArea id={id} /> | ||
</> | ||
) | ||
} |
Oops, something went wrong.