-
-
Notifications
You must be signed in to change notification settings - Fork 28
docs: add props-table into button docs #446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
5c9853f
66805c0
4eb792a
4fad9b0
ddcff65
fd47036
505b593
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,48 @@ | ||
| import { PropsTable } from '@/components/PropsTable' | ||
|
|
||
| ###### API | ||
|
|
||
| `Button` props extends the button HTML attributes. | ||
|
|
||
| <div style={{ width: '100%', overflow: 'auto'}}> | ||
| | Property | Description | Type | Default | | ||
| | --- | --- | --- | --- | | ||
| | **variant** | The variant of the button | `'primary' \| 'default'` | `'default'` | | ||
| | **colors** | The color variables of the button, i.e. `var(--primary)` | ```{<br> primary?: string<br> error?: string<br> text?: string<br> border?: string<br> inputBackground?: string<br> primaryFocus?: string<br>}``` | `undefined` | | ||
| | **danger** | Signals that it should be used with caution. It is often used in a delete button or to show the error status. | `boolean` | `false` | | ||
| | **size** | The size of the button | `'sm' \| 'md' \| 'lg'` | `'md'` | | ||
| | **icon** | Icon of the button passed in as a form of ReactNode | `React.ReactNode` | `undefined` | | ||
| | **ellipsis** | Whether the button text should be truncated with an ellipsis. The button should have a width to be able to truncate the text. | `boolean` | `false` | | ||
| </div> | ||
| <PropsTable | ||
| componentProps={[ | ||
| { | ||
| property: 'variant', | ||
| description: 'The variant of the button', | ||
| type: "`'primary' | 'default'`", | ||
| default: "`'default'`", | ||
| }, | ||
| { | ||
| property: 'colors', | ||
| description: 'The color variables of the button, i.e. `var(--primary)`', | ||
| type: '```{<br> primary?: string<br> error?: string<br> text?: string<br> border?: string<br> inputBackground?: string<br> primaryFocus?: string<br>}```', | ||
| default: '`undefined`', | ||
| }, | ||
| { | ||
| property: 'danger', | ||
| description: | ||
| 'Signals that it should be used with caution. It is often used in a delete button or to show the error status.', | ||
| type: '`boolean`', | ||
| default: '`false`', | ||
| }, | ||
| { | ||
| property: 'size', | ||
| description: 'The size of the button', | ||
| type: "`'sm' | 'md' | 'lg'`", | ||
| default: "`'md'`", | ||
| }, | ||
| { | ||
| property: 'icon', | ||
| description: 'Icon of the button passed in as a form of ReactNode', | ||
| type: '`React.ReactNode`', | ||
| default: '`undefined`', | ||
| }, | ||
| { | ||
| property: 'ellipsis', | ||
| description: | ||
| 'Whether the button text should be truncated with an ellipsis. The button should have a width to be able to truncate the text.', | ||
| type: '`boolean`', | ||
| default: '`false`', | ||
| }, | ||
| ]} | ||
| /> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { Text, VStack } from '@devup-ui/react' | ||
| import Markdown from 'react-markdown' | ||
|
|
||
| import { _components } from '@/mdx-components' | ||
|
|
||
| import { CustomCodeBlock } from './mdx/components/CustomCodeBlock' | ||
| import { | ||
| TableBody, | ||
| TableCell, | ||
| TableHead, | ||
| TableHeaderCell, | ||
| TableRoot, | ||
| TableRow, | ||
| } from './Table' | ||
|
|
||
| interface ComponentProp { | ||
| property: string | ||
| description?: string | ||
| type?: string | ||
| default?: string | ||
| } | ||
|
|
||
| const MdxComponentsWithCodeBlock = ({ children }: { children?: string }) => { | ||
| return ( | ||
| <Markdown | ||
| components={{ | ||
| ...(_components as any), | ||
| code: CustomCodeBlock, | ||
| }} | ||
| > | ||
| {children} | ||
| </Markdown> | ||
| ) | ||
| } | ||
|
|
||
| interface PropTableProps { | ||
| componentProps: ComponentProp[] | ||
| } | ||
|
|
||
| export const PropsTable = async (props: PropTableProps) => { | ||
| const { componentProps } = props | ||
|
|
||
| return ( | ||
| <TableRoot border={0}> | ||
| <TableHead> | ||
| <TableRow> | ||
| <TableHeaderCell>Prop</TableHeaderCell> | ||
| <TableHeaderCell>description</TableHeaderCell> | ||
| <TableHeaderCell>Type</TableHeaderCell> | ||
| <TableHeaderCell>Default</TableHeaderCell> | ||
| </TableRow> | ||
| </TableHead> | ||
| <TableBody> | ||
| {componentProps.length === 0 && ( | ||
| <TableRow> | ||
| <TableCell colSpan={3}> | ||
| <Text>No props to display</Text> | ||
| </TableCell> | ||
| </TableRow> | ||
| )} | ||
| {componentProps.map( | ||
| ({ property, description, type, default: defaultValue }) => ( | ||
| <TableRow key={property}> | ||
| <TableCell> | ||
| <Text typography="bodyBold">{property}</Text> | ||
| </TableCell> | ||
| <TableCell> | ||
| <MdxComponentsWithCodeBlock> | ||
| {description} | ||
| </MdxComponentsWithCodeBlock> | ||
| </TableCell> | ||
| <TableCell> | ||
| <VStack> | ||
| <MdxComponentsWithCodeBlock> | ||
| {type?.replaceAll('"', "'")} | ||
| </MdxComponentsWithCodeBlock> | ||
| </VStack> | ||
| </TableCell> | ||
| <TableCell> | ||
| <MdxComponentsWithCodeBlock> | ||
| {defaultValue} | ||
| </MdxComponentsWithCodeBlock> | ||
| </TableCell> | ||
| </TableRow> | ||
| ), | ||
| )} | ||
| </TableBody> | ||
| </TableRoot> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { | ||
| Box, | ||
| type DevupComponentBaseProps, | ||
| type DevupComponentProps, | ||
| } from '@devup-ui/react' | ||
|
|
||
| // FIXME: Merge type is not exported in @devup-ui/react | ||
| type Merge<T, U> = Omit<T, Extract<keyof T, keyof U>> & U | ||
|
|
||
| type TableComponentProps<T extends React.ElementType> = Merge< | ||
| DevupComponentBaseProps<T>, | ||
| DevupComponentProps<T> | ||
| > | ||
|
|
||
| const TableRoot = ({ ...props }: TableComponentProps<'table'>) => { | ||
| return ( | ||
| <Box borderRadius="0.5rem" overflow="hidden"> | ||
| <Box as="table" borderCollapse="collapse" borderSpacing={0} {...props} /> | ||
| </Box> | ||
| ) | ||
| } | ||
|
|
||
| const TableHead = ({ ...props }: TableComponentProps<'thead'>) => { | ||
| return ( | ||
| <Box | ||
| as="thead" | ||
| {...props} | ||
| selectors={{ | ||
| '& tr': { | ||
| bg: '$cardBg', | ||
| }, | ||
| }} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| const TableBody = ({ ...props }: TableComponentProps<'tbody'>) => { | ||
| return <Box as="tbody" {...props}></Box> | ||
| } | ||
|
|
||
| const TableRow = ({ ...props }: TableComponentProps<'tr'>) => { | ||
| return ( | ||
| <Box | ||
| as="tr" | ||
| borderBottom="1px solid var(--border, #E4E4E4)" | ||
| selectors={{ | ||
| '& + &:last-of-type': { | ||
| borderBottom: 'none', | ||
| }, | ||
| }} | ||
| {...props} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| const TableCell = ({ ...props }: TableComponentProps<'td'>) => { | ||
| return <Box as="td" padding="0.5rem 1rem" {...props} /> | ||
| } | ||
|
|
||
| const TableHeaderCell = ({ ...props }: TableComponentProps<'th'>) => { | ||
| return <Box as="th" padding="0.5rem 1rem" textAlign="left" {...props} /> | ||
| } | ||
|
|
||
| export { TableBody, TableCell, TableHead, TableHeaderCell, TableRoot, TableRow } | ||
|
||
|
|
||
| export function Table() { | ||
| return <></> | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { Box, Text } from '@devup-ui/react' | ||
|
|
||
| export function CustomCodeBlock({ children }: { children: string }) { | ||
| return ( | ||
| <Box | ||
| as="code" | ||
| bg="var(--containerBackground)" | ||
|
||
| borderRadius="0.25rem" | ||
| color="var(--text)" | ||
owjs3901 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| padding="0.25rem" | ||
| whiteSpace="pre-wrap" | ||
| > | ||
| {children.split('<br>').map((line, index) => ( | ||
| <Text key={index.toString()} whiteSpace="pre"> | ||
| {index > 0 && <br />} | ||
| {line} | ||
| </Text> | ||
| ))} | ||
| </Box> | ||
| ) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Devup UI Works with static analysis.
So props for stying can not be applied...