Skip to content

Commit

Permalink
markdown toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Mar 1, 2024
1 parent 7236617 commit 2d9b7da
Show file tree
Hide file tree
Showing 12 changed files with 6,221 additions and 1 deletion.
5,491 changes: 5,491 additions & 0 deletions generated/components.json

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
},
"dependencies": {
"@github/combobox-nav": "^2.1.5",
"@github/markdown-toolbar-element": "^2.1.0",
"@github/markdown-toolbar-element": "^2.2.2",
"@github/paste-markdown": "^1.4.0",
"@github/relative-time-element": "^4.1.2",
"@lit-labs/react": "^1.1.1",
Expand Down
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": []
}
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>
</>
}
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} />
</>
)
}
Loading

0 comments on commit 2d9b7da

Please sign in to comment.