Skip to content

Commit

Permalink
docs(site): add all components page (#1566)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusps authored Apr 18, 2024
2 parents 8ea17dc + 9f33845 commit 9ca1604
Show file tree
Hide file tree
Showing 114 changed files with 269 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from 'react'
import allProps from '../../__props__'
import styles from './component-description.module.css'
import { getComponentProps } from '../../utils/get-component-props'

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

const reference = allProps[name]
const reference = getComponentProps(name)

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.grid {
--rows: 3;
display: grid;
grid-template-columns: repeat(
auto-fill,
minmax(max(250px, calc((100% - 1rem * 2) / var(--rows))), 1fr)
);
margin-top: var(--sl-space-4);
gap: var(--sl-space-gap);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ComponentPropsWithoutRef, CSSProperties } from 'react'
import React from 'react'
import styles from './component-summary-grid.module.css'

export function ComponentSummaryGrid(props: ComponentSummaryGridProps) {
const { children, rows = 3, style, ...restProps } = props

return (
<div
className={styles.grid}
{...restProps}
style={
{
...style,
'--rows': rows,
} as CSSProperties
}
>
{children}
</div>
)
}

interface ComponentSummaryGridProps extends ComponentPropsWithoutRef<'div'> {
rows?: number
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.card {
--radii: var(--sl-border-radius-large);
border-radius: var(--radii);
}

.card:hover {
background: var(--sl-color-gray-1);
}

.card:hover img,
.card:focus img {
transform: scale(1.1);
}

.imgWrapper {
--radii: var(--sl-border-radius-large);
overflow: hidden;
position: relative;
display: inline-block;
border-radius: var(--radii);
}

.card img {
border-radius: var(--radii);
transition: transform 250ms ease-in-out;
}

.contentWrapper {
display: flex;
flex-direction: column;
padding: var(--sl-space-1) var(--sl-space-3) var(--sl-space-6)
var(--sl-space-3);
gap: var(--sl-space-2);
}

.title {
font: var(--sl-text-display-2-font);
letter-spacing: var(--sl-text-display-2-letter-spacing);
}

.description {
font: var(--sl-text-display-4-font);
letter-spacing: var(--sl-text-display-4-letter-spacing);
color: var(--sl-color-gray-10);
}
54 changes: 54 additions & 0 deletions packages/docs/components/component-summary/component-summary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { ComponentPropsWithoutRef, ReactNode } from 'react'
import React from 'react'
import NextLink from 'next/link'
import Image from 'next/image'
import styles from './component-summary.module.css'
import { getComponentProps } from '../../utils/get-component-props'

const imageEstimatedWidth = 370
const imageEstimatedHeight = 218

/**
* Renders a component summary
*/
export function ComponentSummary(props: ComponentSummaryProps) {
const { href, image, name, ...restProps } = props

const componentProps = getComponentProps(name)

return (
<NextLink
className={styles.card}
href={href || `/components/${name}`}
{...restProps}
>
<div className={styles.imgWrapper}>
<Image
src={`/assets/all-${name}.png`}
alt={name}
width={imageEstimatedWidth}
height={imageEstimatedHeight}
/>
</div>
<div className={styles.contentWrapper}>
<h3 className={styles.title}>{componentProps?.name}</h3>
<p className={styles.description}>{componentProps?.description}</p>
</div>
</NextLink>
)
}

interface ComponentSummaryProps extends ComponentPropsWithoutRef<'a'> {
/**
* Link href
*/
href?: string
/**
* Component image
*/
image?: ReactNode
/**
* Component name
*/
name: string
}
2 changes: 2 additions & 0 deletions packages/docs/components/component-summary/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './component-summary'
export * from './component-summary-grid'
92 changes: 33 additions & 59 deletions packages/docs/pages/components/index.mdx
Original file line number Diff line number Diff line change
@@ -1,61 +1,35 @@
# Components

<RelatedComponentList>
<RelatedComponent title="AccessibleIcon" href="/components/accessible-icon/api-reference"/>
<RelatedComponent title="Alert" href="/components/alert/api-reference"/>
<RelatedComponent title="Bleed" href="/components/bleed/api-reference"/>
<RelatedComponent title="Button" href="/components/button/api-reference"/>
<RelatedComponent title="Center" href="/components/center/api-reference"/>
<RelatedComponent title="Checkbox" href="/components/checkbox/api-reference"/>
<RelatedComponent title="Clickable" href="/components/clickable/api-reference"/>
<RelatedComponent title="Collection" href="/components/collection/api-reference"/>
<RelatedComponent title="ComboboxInput" href="/components/combobox-input/api-reference"/>
<RelatedComponent title="ComboboxItem" href="/components/combobox-item/api-reference"/>
<RelatedComponent title="ComboboxList" href="/components/combobox-list/api-reference"/>
<RelatedComponent title="ComboboxPopover" href="/components/combobox-popover/api-reference"/>
<RelatedComponent title="Composable" href="/components/composable/api-reference"/>
<RelatedComponent title="Compose" href="/components/compose/api-reference"/>
<RelatedComponent title="ConfirmationModal" href="/components/confirmation-modal/api-reference"/>
<RelatedComponent title="Container" href="/components/container/api-reference"/>
<RelatedComponent title="Content" href="/components/content/api-reference"/>
<RelatedComponent title="ContextualHelp" href="/components/contextual-help/api-reference"/>
<RelatedComponent title="Divider" href="/components/divider/api-reference"/>
<RelatedComponent title="EmptyState" href="/components/empty-state/api-reference"/>
<RelatedComponent title="Field" href="/components/field/api-reference"/>
<RelatedComponent title="Filter" href="/components/filter/api-reference"/>
<RelatedComponent title="Flex" href="/components/flex/api-reference"/>
<RelatedComponent title="Grid" href="/components/grid/api-reference"/>
<RelatedComponent title="Heading" href="/components/heading/api-reference"/>
<RelatedComponent title="IconButton" href="/components/icon-button/api-reference"/>
<RelatedComponent title="Input" href="/components/input/api-reference"/>
<RelatedComponent title="Label" href="/components/label/api-reference"/>
<RelatedComponent title="Link" href="/components/link/api-reference"/>
<RelatedComponent title="LocaleProvider" href="/components/locale-provider/api-reference"/>
<RelatedComponent title="Menu" href="/components/menu/api-reference"/>
<RelatedComponent title="Modal" href="/components/modal/api-reference"/>
<RelatedComponent title="Page" href="/components/page/api-reference"/>
<RelatedComponent title="Pagination" href="/components/pagination/api-reference"/>
<RelatedComponent title="Popover" href="/components/popover/api-reference"/>
<RelatedComponent title="Radio" href="/components/radio/api-reference"/>
<RelatedComponent title="Search" href="/components/search/api-reference"/>
<RelatedComponent title="Select" href="/components/select/api-reference"/>
<RelatedComponent title="Skeleton" href="/components/skeleton/api-reference"/>
<RelatedComponent title="Slot" href="/components/slot/api-reference"/>
<RelatedComponent title="Spinner" href="/components/spinner/api-reference"/>
<RelatedComponent title="Stack" href="/components/stack/api-reference"/>
<RelatedComponent title="Tab" href="/components/tab/api-reference"/>
<RelatedComponent title="Table" href="/components/table/api-reference"/>
<RelatedComponent title="Tag" href="/components/tag/api-reference"/>
<RelatedComponent title="Text" href="/components/text/api-reference"/>
<RelatedComponent title="Textarea" href="/components/textarea/api-reference"/>
<RelatedComponent title="ToastStack" href="/components/toast-stack/api-reference"/>
<RelatedComponent title="Tooltip" href="/components/tooltip/api-reference"/>
<RelatedComponent title="VisuallyHidden" href="/components/visually-hidden/api-reference"/>
<RelatedComponent title="Calendar" href="/components/calendar/api-reference"/>
<RelatedComponent title="DateField" href="/components/date-field/api-reference"/>
<RelatedComponent title="DatePicker" href="/components/date-picker/api-reference"/>
<RelatedComponent title="DateRangePicker" href="/components/date-range-picker/api-reference"/>
<RelatedComponent title="DateSegment" href="/components/date-segment/api-reference"/>
<RelatedComponent title="RangeCalendar" href="/components/range-calendar/api-reference"/>
<RelatedComponent title="TimeInput" href="/components/time-input/api-reference"/>
</RelatedComponentList>
import { allComponentsList, allLayoutsList, allPrimitivesList } from '../../utils/all-components-list'
import { pascalCase } from '@vtex/shoreline'

<ComponentSummaryGrid>
{allComponentsList.map(component => (
<ComponentSummary
key={component}
name={component}
/>
))}
</ComponentSummaryGrid>

## Layouts

<ComponentSummaryGrid>
{allLayoutsList.map(component => (
<ComponentSummary
key={component}
name={component}
/>
))}
</ComponentSummaryGrid>

## Primitives

<ComponentSummaryGrid>
{allPrimitivesList.map(component => (
<ComponentSummary
key={component}
name={component}
/>
))}
</ComponentSummaryGrid>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-bleed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-center.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-checkbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-clickable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-collection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-compose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-content.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-date-picker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-empty-state.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-flex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-heading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-icon-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-label.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-link-box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/assets/all-link.png
Binary file added packages/docs/public/assets/all-menu.png
Binary file added packages/docs/public/assets/all-modal.png
Binary file added packages/docs/public/assets/all-page.png
Binary file added packages/docs/public/assets/all-pagination.png
Binary file added packages/docs/public/assets/all-popover.png
Binary file added packages/docs/public/assets/all-radio.png
Binary file added packages/docs/public/assets/all-search.png
Binary file added packages/docs/public/assets/all-select.png
Binary file added packages/docs/public/assets/all-skeleton.png
Binary file added packages/docs/public/assets/all-slot.png
Binary file added packages/docs/public/assets/all-spinner.png
Binary file added packages/docs/public/assets/all-stack.png
Binary file added packages/docs/public/assets/all-tab.png
Binary file added packages/docs/public/assets/all-table.png
Binary file added packages/docs/public/assets/all-tag.png
Binary file added packages/docs/public/assets/all-text.png
Binary file added packages/docs/public/assets/all-textarea.png
Binary file added packages/docs/public/assets/all-time-input.png
Binary file added packages/docs/public/assets/all-toast-stack.png
Binary file added packages/docs/public/assets/all-tooltip.png
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-alert.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-bleed.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-button.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-calendar.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-center.webp
Binary file not shown.
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-checkbox.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-clickable.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-collection.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-combobox.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-compose.webp
Binary file not shown.
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-content.webp
Binary file not shown.
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-date-field.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-field.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-filter.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-flex.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-grid.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-heading.webp
Binary file not shown.
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-label.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-link.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-locale.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-menu.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-modal.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-page.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-pagination.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-popover.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-search.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-select.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-skeleton.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-slot.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-spinner.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-stack.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-tab-list.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-table.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-tag.webp
Binary file not shown.
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-text-input.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-text.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-time-field.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-toast.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-tooltip.webp
Binary file not shown.
Binary file removed packages/docs/public/assets/overview-virtual.webp
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions packages/docs/theme.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
import { Preview } from './components/preview'
import { PropsDocs } from './components/props-docs'
import { ComponentDescription } from './components/component-description'
import {
ComponentSummary,
ComponentSummaryGrid,
} from './components/component-summary'

const config: DocsThemeConfig = {
logo: <Logo />,
Expand All @@ -33,6 +37,8 @@ const config: DocsThemeConfig = {
Preview: Preview as React.FC,
PropsDocs: PropsDocs as React.FC,
ComponentDescription: ComponentDescription as React.FC,
ComponentSummary: ComponentSummary as React.FC,
ComponentSummaryGrid: ComponentSummaryGrid as React.FC,
},
sidebar: {
defaultMenuCollapseLevel: 1,
Expand Down
56 changes: 56 additions & 0 deletions packages/docs/utils/all-components-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export const allComponentsList = [
'alert',
'button',
'checkbox',
'collection',
'confirmation-modal',
'contextual-help',
'date-picker',
'date-range-picker',
'empty-state',
'field',
'filter',
'heading',
'icon-button',
'input',
'label',
'link',
'menu',
'modal',
'page',
'pagination',
'popover',
'radio',
'search',
'select',
'skeleton',
'spinner',
'tab',
'table',
'tag',
'text',
'textarea',
'time-input',
'toast-stack',
'tooltip',
]

export const allLayoutsList = [
'bleed',
'center',
'content',
'flex',
'grid',
'slot',
'stack',
]

export const allPrimitivesList = [
'accessible-icon',
'clickable',
'combobox-input',
'compose',
'link-box',
'locale-provider',
'visually-hidden',
]
34 changes: 34 additions & 0 deletions packages/docs/utils/get-component-props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import allProps from '../__props__'

export function getComponentProps(name: string): ComponentProps | undefined {
const reference = allProps[name]

return reference
}

interface Example {
description: string
language: string
code: string
}

interface PropsRecord {
name: string
type: string
description: string
optional: boolean
defaultValue: string | null
deprecated: boolean
status: string
examples: Example[]
}

interface ComponentProps {
filename: string
name: string
description: string
deprecated: boolean
status: string
examples: Example[]
props: PropsRecord[]
}

0 comments on commit 9ca1604

Please sign in to comment.