Skip to content

Commit

Permalink
docs update for table primitive, use theme values, use exampleCode co… (
Browse files Browse the repository at this point in the history
aws-amplify#1202)

* docs update for table primitive, use theme values, use exampleCode component

* remove old DemoBox component and replace it with the Demo component

* remove demobox from TablePropControls, rename example files to PascalCase

* remove field labeller in favor of the built in label prop

* update file reference

* update to file references

Co-authored-by: Jacob Logan <[email protected]>
  • Loading branch information
jacoblogan and Jacob Logan authored Feb 24, 2022
1 parent 1f5e696 commit 8a3e919
Show file tree
Hide file tree
Showing 14 changed files with 395 additions and 283 deletions.
6 changes: 5 additions & 1 deletion docs/src/data/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ export const layoutComponents = [
body: `A layout container using Flexbox.`,
},
{ href: '/components/grid', label: 'Grid', body: `` },
{ href: '/components/table', label: 'Table', body: `` },
{
href: '/components/table',
label: 'Table',
body: `The Table primitive provides users with a styled and customizable table element.`,
},
{
href: '/components/expander',
label: 'Expander',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import * as React from 'react';

import {
CheckboxField,
Flex,
SelectField,
TableProps,
TextField,
} from '@aws-amplify/ui-react';

import { DemoBox } from './DemoBox';
import { FieldLabeler } from './FieldLabeler';

export interface TablePropControlsProps extends TableProps {
setCaption: (value: React.SetStateAction<TableProps['caption']>) => void;
setHighlightOnHover: (
Expand All @@ -32,7 +30,7 @@ export const TablePropControls: TablePropControlsInterface = ({
size,
variation,
}) => (
<DemoBox primitiveName="Table">
<Flex direction="column">
<TextField
id="caption-control"
label="caption"
Expand All @@ -49,35 +47,27 @@ export const TablePropControls: TablePropControlsInterface = ({
label="highlightOnHover"
onChange={(e) => setHighlightOnHover(e.target.checked)}
/>
<FieldLabeler id="size">
<SelectField
id="size"
name="size"
label="size"
labelHidden
placeholder="(default)"
value={size}
onChange={(e) => setSize(e.target.value as TableProps['size'])}
>
<option value="small">small</option>
<option value="large">large</option>
</SelectField>
</FieldLabeler>
<FieldLabeler id="variation">
<SelectField
id="variation"
name="variation"
label="variation"
labelHidden
placeholder="(default)"
value={variation}
onChange={(e) =>
setVariation(e.target.value as TableProps['variation'])
}
>
<option value="bordered">bordered</option>
<option value="striped">striped</option>
</SelectField>
</FieldLabeler>
</DemoBox>
<SelectField
id="size"
name="size"
label="size"
placeholder="(default)"
value={size}
onChange={(e) => setSize(e.target.value as TableProps['size'])}
>
<option value="small">small</option>
<option value="large">large</option>
</SelectField>
<SelectField
id="variation"
name="variation"
label="variation"
placeholder="(default)"
value={variation}
onChange={(e) => setVariation(e.target.value as TableProps['variation'])}
>
<option value="bordered">bordered</option>
<option value="striped">striped</option>
</SelectField>
</Flex>
);
73 changes: 57 additions & 16 deletions docs/src/pages/components/table/demo.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,67 @@
import * as React from 'react';

import { Flex } from '@aws-amplify/ui-react';
import { Demo } from '@/components/Demo';

import { Example } from '@/components/Example';
import { TablePropControls } from '@/components/TablePropControls';
import { useTableProps } from '@/components/useTableProps';
import { TablePropControls } from './TablePropControls';
import { useTableProps } from './useTableProps';
import { BasicExample } from './examples';

const propsToCode = (props) => {
const { caption, highlightOnHover, size, variation } = props;
return `
<Table
caption={${caption}}
highlightOnHover={${highlightOnHover}}
size={${size}}
variation={${variation}}
>
<TableHead>
<TableRow>
<TableCell as="th">Citrus</TableCell>
<TableCell as="th">Stone Fruit</TableCell>
<TableCell as="th">Berry</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Orange</TableCell>
<TableCell>Nectarine</TableCell>
<TableCell>Raspberry</TableCell>
</TableRow>
<TableRow>
<TableCell>Grapefruit</TableCell>
<TableCell>Apricot</TableCell>
<TableCell>Blueberry</TableCell>
</TableRow>
<TableRow>
<TableCell>Lime</TableCell>
<TableCell>Peach</TableCell>
<TableCell>Strawberry</TableCell>
</TableRow>
</TableBody>
</Table>
`;
};

const initialValues = {
caption: '',
highlightOnHover: false,
};

export const TableDemo = () => {
const tableProps = useTableProps({});
const tableProps = useTableProps(initialValues);

return (
<Flex direction="column" gap="0.5rem">
<TablePropControls {...tableProps} />
<Example>
<BasicExample
caption={tableProps.caption}
highlightOnHover={tableProps.highlightOnHover}
size={tableProps.size}
variation={tableProps.variation}
/>
</Example>
</Flex>
<Demo
code={propsToCode(tableProps)}
propControls={<TablePropControls {...tableProps} />}
>
<BasicExample
caption={tableProps.caption}
highlightOnHover={tableProps.highlightOnHover}
size={tableProps.size}
variation={tableProps.variation}
/>
</Demo>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
Table,
TableBody,
TableRow,
TableCell,
useTheme,
} from '@aws-amplify/ui-react';

export const TableFontSizePropExample = () => {
const { tokens } = useTheme();
return (
<Table>
<TableBody>
<TableRow>
<TableCell fontSize={`${tokens.fontSizes.xs}`}>
Smaller Text
</TableCell>
<TableCell fontSize={`${tokens.fontSizes.xs}`}>
Smaller Text
</TableCell>
</TableRow>
</TableBody>
</Table>
);
};
25 changes: 25 additions & 0 deletions docs/src/pages/components/table/examples/TableStylePropExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
Table,
TableBody,
TableRow,
TableCell,
useTheme,
} from '@aws-amplify/ui-react';

export const TableStylePropExample = () => {
const { tokens } = useTheme();
return (
<Table>
<TableBody>
<TableRow>
<TableCell style={{ fontSize: `${tokens.fontSizes.xs}` }}>
Smaller Text
</TableCell>
<TableCell style={{ fontSize: `${tokens.fontSizes.xs}` }}>
Smaller Text
</TableCell>
</TableRow>
</TableBody>
</Table>
);
};
12 changes: 7 additions & 5 deletions docs/src/pages/components/table/examples/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export { BasicExample } from './basicExample';
export { HighlightExample } from './highlightExample';
export { SizeExample } from './sizeExample';
export { SpanExample } from './spanExample';
export { VariationExample } from './variationExample';
export { BasicExample } from './BasicExample';
export { HighlightExample } from './HighlightExample';
export { SizeExample } from './SizeExample';
export { SpanExample } from './SpanExample';
export { TableFontSizePropExample } from './TableFontSizePropExample';
export { TableStylePropExample } from './TableStylePropExample';
export { VariationExample } from './VariationExample';
Loading

0 comments on commit 8a3e919

Please sign in to comment.