-
-
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5c9853f
docs: add props-table into button docs
raymondanythings 66805c0
feat: create PropsTable component and update imports in documentation
raymondanythings 4eb792a
refactor: simplify Table component props by using ComponentPropsWitho…
raymondanythings 4fad9b0
refactor: restructure table components into individual files for bett…
raymondanythings ddcff65
refactor: remove unused component prop types from index export
raymondanythings fd47036
refactor: consolidate table components into a single Table component …
raymondanythings 505b593
Fix token keyword
owjs3901 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 44 additions & 10 deletions
54
apps/landing/src/app/(detail)/components/[component]/button/Api.mdx
This file contains hidden or 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 |
|---|---|---|
| @@ -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`', | ||
| }, | ||
| ]} | ||
| /> |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 { Text, VStack } from '@devup-ui/react' | ||
| import Markdown from 'react-markdown' | ||
|
|
||
| import { _components } from '@/mdx-components' | ||
|
|
||
| import { CustomCodeBlock } from './mdx/components/CustomCodeBlock' | ||
| import { | ||
| Table, | ||
| TableBody, | ||
| TableCell, | ||
| TableHead, | ||
| TableHeaderCell, | ||
| TableRow, | ||
| } from './mdx/components/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 ( | ||
| <Table 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> | ||
| </Table> | ||
| ) | ||
| } |
21 changes: 21 additions & 0 deletions
21
apps/landing/src/components/mdx/components/CustomCodeBlock.tsx
This file contains hidden or 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,21 @@ | ||
| import { Box, Text } from '@devup-ui/react' | ||
|
|
||
| export function CustomCodeBlock({ children }: { children: string }) { | ||
| return ( | ||
| <Box | ||
| as="code" | ||
| bg="$containerBackground" | ||
| borderRadius="0.25rem" | ||
| color="var(--text)" | ||
| padding="0.25rem" | ||
| whiteSpace="pre-wrap" | ||
| > | ||
| {children.split('<br>').map((line, index) => ( | ||
| <Text key={index.toString()} whiteSpace="pre"> | ||
| {index > 0 && <br />} | ||
| {line} | ||
| </Text> | ||
| ))} | ||
| </Box> | ||
| ) | ||
| } | ||
51 changes: 51 additions & 0 deletions
51
apps/landing/src/components/mdx/components/Table/index.tsx
This file contains hidden or 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,51 @@ | ||
| import { Box } from '@devup-ui/react' | ||
| import { type ComponentProps } from 'react' | ||
|
|
||
| export const Table = ({ ...props }: ComponentProps<'table'>) => { | ||
| return ( | ||
| <Box borderRadius="0.5rem" overflow="hidden"> | ||
| <Box {...props} as="table" borderCollapse="collapse" borderSpacing={0} /> | ||
| </Box> | ||
| ) | ||
| } | ||
|
|
||
| export const TableBody = ({ ...props }: ComponentProps<'tbody'>) => { | ||
| return <Box {...props} as="tbody" /> | ||
| } | ||
|
|
||
| export const TableCell = ({ ...props }: ComponentProps<'th'>) => { | ||
| return <Box {...props} as="td" padding="0.5rem 1rem" /> | ||
| } | ||
|
|
||
| export const TableHead = ({ ...props }: ComponentProps<'thead'>) => { | ||
| return ( | ||
| <Box | ||
| {...props} | ||
| as="thead" | ||
| selectors={{ | ||
| '& tr': { | ||
| bg: '$cardBg', | ||
| }, | ||
| }} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| export const TableHeaderCell = ({ ...props }: ComponentProps<'th'>) => { | ||
| return <Box {...props} as="th" padding="0.5rem 1rem" textAlign="left" /> | ||
| } | ||
|
|
||
| export const TableRow = ({ ...props }: ComponentProps<'tr'>) => { | ||
| return ( | ||
| <Box | ||
| {...props} | ||
| as="tr" | ||
| borderBottom="1px solid var(--border, #E4E4E4)" | ||
| selectors={{ | ||
| '& + &:last-of-type': { | ||
| borderBottom: 'none', | ||
| }, | ||
| }} | ||
| /> | ||
| ) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.