Skip to content

Commit

Permalink
docs(site): add components docs (#1556)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusps authored Apr 16, 2024
2 parents a9836ff + 9210c96 commit 3644058
Show file tree
Hide file tree
Showing 261 changed files with 1,177 additions and 2,614 deletions.
2 changes: 1 addition & 1 deletion packages/components/src/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Center } from '../center'

/**
* Buttons triggers allow users to identify and start the most important actions in a container.
* @playground
* @status stable
* @example
* <Button>Action label</Button>
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/icon-button/icon-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
}
)

export interface IconButtonOtions extends ButtonOptions {
export interface IconButtonOptions extends ButtonOptions {
/**
* Icon button label. Needed for accessibility.
*/
label: ReactNode
}

export type IconButtonProps = IconButtonOtions &
export type IconButtonProps = IconButtonOptions &
ComponentPropsWithoutRef<'button'>
2 changes: 1 addition & 1 deletion packages/components/src/menu/menu-trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const MenuTrigger = forwardRef<HTMLButtonElement, MenuTriggerProps>(
}
)

interface MenuTriggerOptions {
export interface MenuTriggerOptions {
/**
* Children composition
* @default false
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/modal/modal-dismiss.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { forwardRef } from 'react'
import { DialogDismiss } from '@ariakit/react'
import { IconX } from '@vtex/shoreline-icons'

import type { IconButtonOtions } from '../icon-button'
import type { IconButtonOptions } from '../icon-button'
import { IconButton } from '../icon-button'

/**
Expand Down Expand Up @@ -54,7 +54,7 @@ export const ModalDismiss = forwardRef<HTMLButtonElement, ModalDismissProps>(
}
)

export type ModalDismissOptions = Pick<IconButtonOtions, 'size'>
export type ModalDismissOptions = Pick<IconButtonOptions, 'size'>

export type ModalDismissProps = ModalDismissOptions &
ComponentPropsWithoutRef<'button'>
2 changes: 1 addition & 1 deletion packages/components/src/page/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const PageContent = forwardRef<HTMLDivElement, PageContentProps>(
}
)

export interface PageContentOptions extends ComponentPropsWithoutRef<'div'> {
export interface PageContentOptions {
/**
* Layout type
* @default 'standard'
Expand Down
34 changes: 28 additions & 6 deletions packages/components/src/toast/toast-stack.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { CSSProperties, ComponentPropsWithoutRef } from 'react'
import type { CSSProperties } from 'react'
import React from 'react'
import type { DefaultToastOptions } from 'react-hot-toast/headless'
import { useToaster } from 'react-hot-toast/headless'

import { ToastAppear } from './toast-appear'
import { Toast } from './toast'
import type { ToastPosition } from './toast-types'

/**
* Stack of toasts
Expand Down Expand Up @@ -65,9 +64,11 @@ export function ToastStack(props: ToastStackProps) {
}

function getPositionStyle(
position: ToastPosition,
position: ToastStackOptions['position'],
offset: number
): CSSProperties {
if (!position) return {}

const top = position.includes('top')
const verticalStyle: CSSProperties = top ? { top: 0 } : { bottom: 0 }
const horizontalStyle: CSSProperties = position.includes('center')
Expand All @@ -87,10 +88,31 @@ function getPositionStyle(
}
}

export interface ToastStackProps
extends Omit<ComponentPropsWithoutRef<'div'>, 'children'> {
position?: ToastPosition
export interface ToastStackOptions {
/**
* Postion of the toasts
* @default 'bottom-right'
*/
position?:
| 'top-left'
| 'top-center'
| 'top-right'
| 'bottom-left'
| 'bottom-center'
| 'bottom-right'
/**
* Options of each toast
*/
toastOptions?: DefaultToastOptions
/**
* Wether should invert the order
*/
reverseOrder?: boolean
/**
* Position distance
* @default 16
*/
gutter?: number
}

export type ToastStackProps = ToastStackOptions
8 changes: 0 additions & 8 deletions packages/components/src/toast/toast-types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
export type ToastPosition =
| 'top-left'
| 'top-center'
| 'top-right'
| 'bottom-left'
| 'bottom-center'
| 'bottom-right'

export type ToastVariant = 'informational' | 'success' | 'critical' | 'warning'
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import allProps from '../../__props__'
import styles from './component-description.module.css'

export function ComponentDescription(props: PropsDocsProps) {
const { name } = props
const { name, children } = props

const reference = allProps[name]

if (!reference) {
if (!reference && !children) {
return <></>
}

return <p className={styles.description}>{reference.description}</p>
return (
<p className={styles.description}>{children ?? reference.description}</p>
)
}

interface PropsDocsProps {
name: string
children?: string
}
13 changes: 13 additions & 0 deletions packages/docs/examples/menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'
import { Menu, MenuItem, MenuSeparator } from '@vtex/shoreline'

export default function Example() {
return (
<Menu label="Open">
<MenuItem>New Tab</MenuItem>
<MenuItem>New Item</MenuItem>
<MenuSeparator />
<MenuItem>Downloads</MenuItem>
</Menu>
)
}
47 changes: 47 additions & 0 deletions packages/docs/examples/modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useState } from 'react'
import {
Button,
Modal,
ModalContent,
ModalDismiss,
ModalFooter,
ModalHeader,
ModalHeading,
} from '@vtex/shoreline'

export default function Example() {
const [open, setOpen] = useState(false)

const toggle = () => {
setOpen((o) => !o)
}

return (
<>
<Button onClick={toggle}>Open Modal</Button>
<Modal open={open} onClose={toggle}>
<ModalHeader>
<ModalHeading>Heading</ModalHeading>
<ModalDismiss />
</ModalHeader>
<ModalContent>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Elit
scelerisque mauris pellentesque pulvinar pellentesque habitant morbi
tristique senectus. Morbi tristique senectus et netus et. Nec
tincidunt praesent semper feugiat nibh sed pulvinar proin gravida.
Morbi tristique senectus et netus et malesuada fames ac. Ultricies leo
integer malesuada nunc vel risus commodo viverra maecenas. Nunc congue
nisi vitae suscipit tellus mauris a diam maecenas. Dui accumsan sit
amet nulla facilisi morbi tempus.
</ModalContent>
<ModalFooter>
<Button onClick={toggle}>Close</Button>
<Button variant="primary" onClick={toggle}>
Ok
</Button>
</ModalFooter>
</Modal>
</>
)
}
16 changes: 16 additions & 0 deletions packages/docs/examples/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import { Page, PageContent, PageHeader, PageHeading } from '@vtex/shoreline'
import { DecorativeBox } from '../components/decorative-box'

export default function Example() {
return (
<Page>
<PageHeader>
<PageHeading>Heading</PageHeading>
</PageHeader>
<PageContent>
<DecorativeBox height="200px" />
</PageContent>
</Page>
)
}
6 changes: 6 additions & 0 deletions packages/docs/examples/search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { Search } from '@vtex/shoreline'

export default function Example() {
return <Search />
}
13 changes: 13 additions & 0 deletions packages/docs/examples/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'
import { Skeleton } from '@vtex/shoreline'

export default function Example() {
return (
<Skeleton
style={{
width: 100,
height: 100,
}}
/>
)
}
6 changes: 6 additions & 0 deletions packages/docs/examples/spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { Spinner } from '@vtex/shoreline'

export default function Example() {
return <Spinner description="loading" />
}
24 changes: 24 additions & 0 deletions packages/docs/examples/tab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import { Tab, TabList, TabPanel, TabProvider } from '@vtex/shoreline'
import { DecorativeBox } from '../components/decorative-box'

export default function Example() {
return (
<TabProvider>
<TabList>
<Tab>Blue</Tab>
<Tab>Green</Tab>
<Tab>Purple</Tab>
</TabList>
<TabPanel>
<DecorativeBox height="200px" color="blue" />
</TabPanel>
<TabPanel>
<DecorativeBox height="200px" color="green" />
</TabPanel>
<TabPanel>
<DecorativeBox height="200px" color="purple" />
</TabPanel>
</TabProvider>
)
}
62 changes: 62 additions & 0 deletions packages/docs/examples/table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react'
import {
Table,
TableBody,
TableCell,
TableHeader,
TableHeaderCell,
TableRow,
Tag,
} from '@vtex/shoreline'

export default function Example() {
return (
<Table
columnWidths={[
'minmax(min-content, auto)',
'minmax(min-content, auto)',
'minmax(min-content, auto)',
'minmax(min-content, auto)',
]}
>
<TableHeader>
<TableRow>
<TableHeaderCell>Name</TableHeaderCell>
<TableHeaderCell>Description</TableHeaderCell>
<TableHeaderCell>Brand</TableHeaderCell>
<TableHeaderCell>Category</TableHeaderCell>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>iPhone 15</TableCell>
<TableCell>A nice phone</TableCell>
<TableCell>Apple</TableCell>
<TableCell>
<Tag variant="secondary">smartphones</Tag>
</TableCell>
</TableRow>
<TableRow>
<TableCell>Aventador SVJ</TableCell>
<TableCell>Good italian car</TableCell>
<TableCell>Lamborghini</TableCell>
<TableCell>
<Tag variant="secondary" color="cyan">
cars
</Tag>
</TableCell>
</TableRow>
<TableRow>
<TableCell>Uno with stair</TableCell>
<TableCell>Fastest car on earth</TableCell>
<TableCell>Fiat</TableCell>
<TableCell>
<Tag variant="secondary" color="cyan">
cars
</Tag>
</TableCell>
</TableRow>
</TableBody>
</Table>
)
}
6 changes: 6 additions & 0 deletions packages/docs/examples/tag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { Tag } from '@vtex/shoreline'

export default function Example() {
return <Tag>Active</Tag>
}
6 changes: 6 additions & 0 deletions packages/docs/examples/text.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { Text } from '@vtex/shoreline'

export default function Example() {
return <Text variant="body">Short text</Text>
}
6 changes: 6 additions & 0 deletions packages/docs/examples/textarea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { Textarea } from '@vtex/shoreline'

export default function Example() {
return <Textarea maxLength={120} optional resizable={false} />
}
27 changes: 27 additions & 0 deletions packages/docs/examples/toast-promise.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react'
import { Button, ToastStack, toast } from '@vtex/shoreline'

export default function Example() {
function promiseToResolve() {
return new Promise(function (resolve) {
setTimeout(resolve, 2000)
})
}

return (
<>
<Button
onClick={() =>
toast.promise(promiseToResolve(), {
success: 'Resolved',
error: 'Promisse has error',
loading: 'Loading',
})
}
>
Show toast
</Button>
<ToastStack />
</>
)
}
Loading

0 comments on commit 3644058

Please sign in to comment.