Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions components/DataAttributesTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from 'react';
import { Box, Text, Kbd, Code } from '@modulz/design-system';
import { RegionTable } from './RegionTable';

type KeyboardDef = {
attribute: string;
values: string;
};

export function DataAttributesTable({
data,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
}: {
data: KeyboardDef[];
'aria-label'?: string;
'aria-labelledby'?: string;
}) {
const hasAriaLabel = !!(ariaLabel || ariaLabelledBy);
return (
<RegionTable
css={{ width: '100%', textAlign: 'left', borderCollapse: 'collapse' }}
aria-label={hasAriaLabel ? ariaLabel : 'Keyboard Interactions'}
aria-labelledby={ariaLabelledBy}
>
<thead>
<tr>
<Box as="th" css={{ borderBottom: '1px solid $gray6', py: '$3', pr: '$4', width: '40%' }}>
<Text size="2" css={{ color: '$gray11' }}>
Data Attribute
</Text>
</Box>
<Box as="th" css={{ borderBottom: '1px solid $gray6', py: '$3', pr: '$4', width: '60%' }}>
<Text size="2" css={{ color: '$gray11' }}>
Values
</Text>
</Box>
</tr>
</thead>
<tbody>
{data.map(({ attribute, values }, i) => (
<tr key={i}>
<Box
as="td"
css={{
borderBottom: '1px solid $gray6',
py: '$3',
pr: '$4',
whiteSpace: 'nowrap',
}}
>
<Code>{attribute}</Code>
</Box>

<Box as="td" css={{ borderBottom: '1px solid $gray6', py: '$3' }}>
{Array.isArray(values) ? (
<Code css={{ bc: '$gray4', color: '$gray11' }}>
{values.map(
(value, index) => `"${value}" ${values.length !== index + 1 ? ' | ' : ''}`
)}
</Code>
) : (
<Text size="3" css={{ lineHeight: '25px' }}>
{values}
</Text>
)}
</Box>
</tr>
))}
</tbody>
</RegionTable>
);
}
4 changes: 3 additions & 1 deletion components/MDXComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { HeroQuote } from './HeroQuote';
import { Frontmatter } from 'types/frontmatter';
import { ColorScale, ColorScaleGroup } from './Scale';
import * as Demos from './demos';
import { DataAttributesTable } from './DataAttributesTable';

export const components = {
ColorScale,
Expand Down Expand Up @@ -184,8 +185,9 @@ export const components = {
Highlights,
Kbd: DS.Kbd,
Code: DS.Code,
DataAttributesTable: (props) => <DataAttributesTable {...props} />,
PropsTable: (props) => (
<DS.Box css={{ mb: '$5' }}>
<DS.Box css={{ mb: '$2' }}>
<PropsTable {...props} />
</DS.Box>
),
Expand Down
6 changes: 3 additions & 3 deletions components/PropsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ export function PropsTable({
>
<thead>
<tr>
<Box as="th" css={{ borderBottom: '1px solid $gray6', py: '$3', pr: '$4' }}>
<Box as="th" css={{ borderBottom: '1px solid $gray6', py: '$3', pr: '$4', width: '40%' }}>
<Text size="2" css={{ color: '$gray11' }}>
Prop
</Text>
</Box>
<Box as="th" css={{ borderBottom: '1px solid $gray6', py: '$3', pr: '$4' }}>
<Box as="th" css={{ borderBottom: '1px solid $gray6', py: '$3', pr: '$4', width: '30%' }}>
<Text size="2" css={{ color: '$gray11' }}>
Type
</Text>
</Box>
<Box as="th" css={{ borderBottom: '1px solid $gray6', py: '$3', pr: '$4' }}>
<Box as="th" css={{ borderBottom: '1px solid $gray6', py: '$3', pr: '$4', width: '30%' }}>
<Text size="2" css={{ color: '$gray11' }}>
Default
</Text>
Expand Down
52 changes: 52 additions & 0 deletions data/primitives/components/accordion/0.1.7.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,19 @@ Contains all the parts of a collapsible section.
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['open', 'closed'],
},
{
attribute: '[data-disabled]',
values: 'Present when disabled',
},
]}
/>

### Header

Wraps an `Accordion.Trigger`. Use the `asChild` prop to update it to the appropriate heading level for your page.
Expand All @@ -236,6 +249,19 @@ Wraps an `Accordion.Trigger`. Use the `asChild` prop to update it to the appropr
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['open', 'closed'],
},
{
attribute: '[data-disabled]',
values: 'Present when disabled',
},
]}
/>

### Trigger

Toggles the collapsed state of its associated item. It should be nested inside of an `Accordion.Header`.
Expand All @@ -253,6 +279,19 @@ Toggles the collapsed state of its associated item. It should be nested inside o
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['open', 'closed'],
},
{
attribute: '[data-disabled]',
values: 'Present when disabled',
},
]}
/>

### Content

Contains the collapsible content for an item.
Expand Down Expand Up @@ -280,6 +319,19 @@ Contains the collapsible content for an item.
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['open', 'closed'],
},
{
attribute: '[data-disabled]',
values: 'Present when disabled',
},
]}
/>

## Examples

### Expanded by default
Expand Down
27 changes: 27 additions & 0 deletions data/primitives/components/alert-dialog/0.1.8.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ A button that opens the dialog.
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['open', 'closed'],
},
]}
/>

### Portal

When used, portals your overlay and content parts into the `body`.
Expand Down Expand Up @@ -205,6 +214,15 @@ A layer that covers the inert portion of the view when the dialog is open.
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['open', 'closed'],
},
]}
/>

### Content

Contains content to be rendered when the dialog is open.
Expand Down Expand Up @@ -267,6 +285,15 @@ Contains content to be rendered when the dialog is open.
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['open', 'closed'],
},
]}
/>

### Cancel

A button that closes the dialog. This button should be distinguished visually from `AlertDialog.Action` buttons.
Expand Down
26 changes: 26 additions & 0 deletions data/primitives/components/checkbox/0.1.6.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ Contains all the parts of a checkbox. An `input` will also render when used with
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['checked', 'unchecked', 'indeterminate'],
},
{
attribute: '[data-disabled]',
values: 'Present when disabled',
},
]}
/>

### Indicator

Renders when the checkbox is in a checked or indeterminate state. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.
Expand All @@ -150,6 +163,19 @@ Renders when the checkbox is in a checked or indeterminate state. You can style
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['checked', 'unchecked', 'indeterminate'],
},
{
attribute: '[data-disabled]',
values: 'Present when disabled',
},
]}
/>

## Examples

### Indeterminate
Expand Down
39 changes: 39 additions & 0 deletions data/primitives/components/collapsible/0.1.7.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ Contains all the parts of a collapsible.
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['open', 'closed'],
},
{
attribute: '[data-disabled]',
values: 'Present when disabled',
},
]}
/>

### Trigger

The button that toggles the collapsible.
Expand All @@ -115,6 +128,19 @@ The button that toggles the collapsible.
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['open', 'closed'],
},
{
attribute: '[data-disabled]',
values: 'Present when disabled',
},
]}
/>

### Content

The component that contains the collapsible content.
Expand All @@ -138,6 +164,19 @@ The component that contains the collapsible content.
]}
/>

<DataAttributesTable
data={[
{
attribute: '[data-state]',
values: ['open', 'closed'],
},
{
attribute: '[data-disabled]',
values: 'Present when disabled',
},
]}
/>

## Examples

### Animating content size
Expand Down
Loading