Skip to content

Commit

Permalink
Dropdown, Module, Table: use autogen descriptions for subcomponents (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dangerismycat committed Feb 22, 2022
1 parent 024bdc7 commit 4f840d7
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 107 deletions.
59 changes: 40 additions & 19 deletions docs/pages/dropdown.js
Expand Up @@ -77,7 +77,9 @@ export default function DropdownPage({
);
}`}
/>

<GeneratedPropTable generatedDocGen={generatedDocGen.Dropdown} />

<MainSection name="Usage guidelines">
<MainSection.Subsection columns={2}>
<MainSection.Card
Expand All @@ -102,6 +104,7 @@ export default function DropdownPage({
/>
</MainSection.Subsection>
</MainSection>

<MainSection name="Best practices">
<MainSection.Subsection columns={2}>
<MainSection.Card
Expand Down Expand Up @@ -545,25 +548,43 @@ function TruncationDropdownExample() {
/>
</MainSection.Subsection>
</MainSection>
<MainSection name="Subcomponents" />
<GeneratedPropTable
Component={Dropdown?.Item}
name="Dropdown.Item"
id="Dropdown.Item"
generatedDocGen={generatedDocGen.DropdownItem}
/>
<GeneratedPropTable
Component={Dropdown?.Link}
name="Dropdown.Link"
id="Dropdown.Link"
generatedDocGen={generatedDocGen.DropdownLink}
/>
<GeneratedPropTable
Component={Dropdown?.Section}
name="Dropdown.Section"
id="Dropdown.Section"
generatedDocGen={generatedDocGen.DropdownSection}
/>

<MainSection name="Subcomponents">
<MainSection.Subsection
title={generatedDocGen?.DropdownItem?.displayName}
description={generatedDocGen?.DropdownItem?.description}
>
<GeneratedPropTable
Component={Dropdown?.Item}
name="Dropdown.Item"
id="Dropdown.Item"
generatedDocGen={generatedDocGen.DropdownItem}
/>
</MainSection.Subsection>
<MainSection.Subsection
title={generatedDocGen?.DropdownLink?.displayName}
description={generatedDocGen?.DropdownLink?.description}
>
<GeneratedPropTable
Component={Dropdown?.Link}
name="Dropdown.Link"
id="Dropdown.Link"
generatedDocGen={generatedDocGen.DropdownLink}
/>
</MainSection.Subsection>
<MainSection.Subsection
title={generatedDocGen?.DropdownSection?.displayName}
description={generatedDocGen?.DropdownSection?.description}
>
<GeneratedPropTable
Component={Dropdown?.Section}
name="Dropdown.Section"
id="Dropdown.Section"
generatedDocGen={generatedDocGen.DropdownSection}
/>
</MainSection.Subsection>
</MainSection>

<MainSection name="Variants">
<MainSection.Subsection title="Types of items" columns={2}>
<MainSection.Card
Expand Down
17 changes: 10 additions & 7 deletions docs/pages/module.js
@@ -1,6 +1,5 @@
// @flow strict
import { type Node } from 'react';
import { Module } from 'gestalt';
import GeneratedPropTable from '../components/GeneratedPropTable.js';
import MainSection from '../components/MainSection.js';
import Page from '../components/Page.js';
Expand Down Expand Up @@ -45,12 +44,16 @@ export default function DocsPage({
</MainSection>

<MainSection name="Subcomponents">
<GeneratedPropTable
Component={Module.Expandable}
name="Module.Expandable"
id="Module.Expandable"
generatedDocGen={generatedDocGen.ModuleExpandable}
/>
<MainSection.Subsection
title={generatedDocGen?.ModuleExpandable?.displayName}
description={generatedDocGen?.ModuleExpandable?.description}
>
<GeneratedPropTable
generatedDocGen={generatedDocGen.ModuleExpandable}
id="Module.Expandable"
name="Module.Expandable"
/>
</MainSection.Subsection>
</MainSection>

<MainSection name="Variants">
Expand Down
140 changes: 88 additions & 52 deletions docs/pages/table.js
@@ -1,6 +1,5 @@
// @flow strict
import { type Node } from 'react';
import { Table } from 'gestalt';
import PageHeader from '../components/PageHeader.js';
import MainSection from '../components/MainSection.js';
import Page from '../components/Page.js';
Expand Down Expand Up @@ -81,7 +80,9 @@ export default function TablePage({
</Table>
`}
/>

<GeneratedPropTable generatedDocGen={generatedDocGen.Table} />

<MainSection name="Usage guidelines">
<MainSection.Subsection columns={2}>
<MainSection.Card
Expand All @@ -105,6 +106,7 @@ export default function TablePage({
/>
</MainSection.Subsection>
</MainSection>

<MainSection name="Best practices">
<MainSection.Subsection title="Style" columns={2}>
<MainSection.Card
Expand Down Expand Up @@ -1508,60 +1510,94 @@ function Example() {
/>
</MainSection.Subsection>
</MainSection>

<MainSection name="Subcomponents">
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableHeader}
Component={Table?.Header}
name="Table.Header"
id="Table.Header"
/>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableBody}
Component={Table?.Body}
name="Table.Body"
id="Table.Body"
/>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableFooter}
Component={Table?.Footer}
name="Table.Footer"
id="Table.Footer"
/>
<MainSection.Subsection
title={generatedDocGen?.TableHeader?.displayName}
description={generatedDocGen?.TableHeader?.description}
>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableHeader}
name="Table.Header"
id="Table.Header"
/>
</MainSection.Subsection>
<MainSection.Subsection
title={generatedDocGen?.TableBody?.displayName}
description={generatedDocGen?.TableBody?.description}
>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableBody}
name="Table.Body"
id="Table.Body"
/>
</MainSection.Subsection>
<MainSection.Subsection
title={generatedDocGen?.TableFooter?.displayName}
description={generatedDocGen?.TableFooter?.description}
>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableFooter}
name="Table.Footer"
id="Table.Footer"
/>
</MainSection.Subsection>
<MainSection.Subsection
title={generatedDocGen?.TableCell?.displayName}
description={generatedDocGen?.TableCell?.description}
>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableCell}
name="Table.Cell"
id="Table.Cell"
excludeProps={['shouldBeSticky', 'previousTotalWidth', 'shouldHaveShadow']}
/>
</MainSection.Subsection>
<MainSection.Subsection
title={generatedDocGen?.TableHeaderCell?.displayName}
description={generatedDocGen?.TableHeaderCell?.description}
>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableHeaderCell}
name="Table.HeaderCell"
id="Table.HeaderCell"
excludeProps={['shouldBeSticky', 'previousTotalWidth', 'shouldHaveShadow']}
/>
</MainSection.Subsection>
<MainSection.Subsection
title={generatedDocGen?.TableSortableHeaderCell?.displayName}
description={generatedDocGen?.TableSortableHeaderCell?.description}
>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableSortableHeaderCell}
name="Table.SortableHeaderCell"
id="Table.SortableHeaderCell"
excludeProps={['shouldBeSticky', 'previousTotalWidth', 'shouldHaveShadow']}
/>
</MainSection.Subsection>
<MainSection.Subsection
title={generatedDocGen?.TableRow?.displayName}
description={generatedDocGen?.TableRow?.description}
>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableRow}
name="Table.Row"
id="Table.Row"
/>
</MainSection.Subsection>

<GeneratedPropTable
generatedDocGen={generatedDocGen.TableCell}
Component={Table?.Cell}
name="Table.Cell"
id="Table.Cell"
excludeProps={['shouldBeSticky', 'previousTotalWidth', 'shouldHaveShadow']}
/>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableHeaderCell}
Component={Table?.HeaderCell}
name="Table.HeaderCell"
id="Table.HeaderCell"
excludeProps={['shouldBeSticky', 'previousTotalWidth', 'shouldHaveShadow']}
/>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableSortableHeaderCell}
Component={Table?.SortableHeaderCell}
name="Table.SortableHeaderCell"
id="Table.SortableHeaderCell"
excludeProps={['shouldBeSticky', 'previousTotalWidth', 'shouldHaveShadow']}
/>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableRow}
Component={Table?.Row}
name="Table.Row"
id="Table.Row"
/>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableRowExpandable}
Component={Table?.RowExpandable}
name="Table.RowExpandable"
id="Table.RowExpandable"
/>
<MainSection.Subsection
title={generatedDocGen?.TableRowExpandable?.displayName}
description={generatedDocGen?.TableRowExpandable?.description}
>
<GeneratedPropTable
generatedDocGen={generatedDocGen.TableRowExpandable}
name="Table.RowExpandable"
id="Table.RowExpandable"
/>
</MainSection.Subsection>
</MainSection>

<MainSection name="Variants">
<MainSection.Subsection title="Sticky header">
<MainSection.Card
Expand Down
8 changes: 4 additions & 4 deletions packages/gestalt/src/Dropdown.js
Expand Up @@ -17,7 +17,7 @@ const KEYS = {
ENTER: 0,
};

const dropdownItemDisplayNames = ['DropdownItem', 'DropdownLink'];
const dropdownItemDisplayNames = ['Dropdown.Item', 'Dropdown.Link'];

function getChildrenOptions(childrenArray) {
return childrenArray.reduce((accumulatedChildren, currentChild) => {
Expand All @@ -26,7 +26,7 @@ function getChildrenOptions(childrenArray) {
type: { displayName },
} = currentChild;

if (currentItemChildren && displayName === 'DropdownSection') {
if (currentItemChildren && displayName === 'Dropdown.Section') {
return [
...accumulatedChildren,
...(Array.isArray(currentItemChildren) ? currentItemChildren : [currentItemChildren]),
Expand All @@ -39,7 +39,7 @@ function getChildrenOptions(childrenArray) {

// eslint-disable-next-line no-console
console.error(
'Only children of type DropdownItem, DropdownLink, or DropdownSection are allowed.',
'Only children of type Dropdown.Item, Dropdown.Link, or Dropdown.Section are allowed.',
);

return [...accumulatedChildren];
Expand All @@ -66,7 +66,7 @@ const renderChildrenWithIndex = (childrenArray) => {
const subSectionChildren = child.props.children;
const childDisplayName = child.type.displayName;

if (subSectionChildren && childDisplayName === 'DropdownSection') {
if (subSectionChildren && childDisplayName === 'Dropdown.Section') {
const sectionChildrenArray = Children.toArray(subSectionChildren);
const childWithIndex = cloneElement(child, {
children: renderDropdownItemsWithIndex(sectionChildrenArray, numItemsRendered),
Expand Down
5 changes: 2 additions & 3 deletions packages/gestalt/src/DropdownItem.js
Expand Up @@ -58,8 +58,7 @@ type Props = {|
|};

/**
* Subcomponent of [Dropdown](https://gestalt.pinterest.systems/dropdown).
Use [Dropdown.Item](https://gestalt.pinterest.systems/dropdown#Types-of-items) for action & selection, when the Dropdown item triggers an action or makes a selection.
* Use [Dropdown.Item](https://gestalt.pinterest.systems/dropdown#Dropdown.Item) for action & selection, when the Dropdown item triggers an action or selects an option.
*/
export default function DropdownItem({
badgeText,
Expand Down Expand Up @@ -96,4 +95,4 @@ export default function DropdownItem({
}

// displayName is necessary for children identification in Dropdown
DropdownItem.displayName = 'DropdownItem';
DropdownItem.displayName = 'Dropdown.Item';
5 changes: 2 additions & 3 deletions packages/gestalt/src/DropdownLink.js
Expand Up @@ -48,8 +48,7 @@ type Props = {|
|};

/**
* Subcomponent of [Dropdown](https://gestalt.pinterest.systems/dropdown).
Use [Dropdown.Link](https://gestalt.pinterest.systems/dropdown#Types-of-items) for navigation, when the Dropdown item navigates to a new page.
* Use [Dropdown.Link](https://gestalt.pinterest.systems/dropdownDropdown.Link) for navigation, when the Dropdown item navigates to a new page.
*/
export default function DropdownLink({
badgeText,
Expand Down Expand Up @@ -88,4 +87,4 @@ export default function DropdownLink({
}

// displayName is necessary for children identification in Dropdown
DropdownLink.displayName = 'DropdownLink';
DropdownLink.displayName = 'Dropdown.Link';
5 changes: 2 additions & 3 deletions packages/gestalt/src/DropdownSection.js
Expand Up @@ -16,8 +16,7 @@ type Props = {|
|};

/**
* Subcomponent of [Dropdown](https://gestalt.pinterest.systems/dropdown).
Use [Dropdown.Section](https://gestalt.pinterest.systems/dropdown#Sections) to create hierarchy within a single Dropdown.
* Use [Dropdown.Section](https://gestalt.pinterest.systems/dropdown#Dropdown.Section) to create hierarchy within a single Dropdown.
*/
export default function DropdownSection({ label, children }: Props): Node {
return (
Expand All @@ -31,4 +30,4 @@ export default function DropdownSection({ label, children }: Props): Node {
}

// displayName is necessary for children identification in Dropdown
DropdownSection.displayName = 'DropdownSection';
DropdownSection.displayName = 'Dropdown.Section';
3 changes: 2 additions & 1 deletion packages/gestalt/src/ModuleExpandable.js
Expand Up @@ -48,7 +48,6 @@ type Props = {|
|};

/**
* Standalone subcomponent of [Module](https://gestalt.pinterest.systems/module).
* Use [Module.Expandable](https://gestalt.pinterest.systems/module) if your module requires expanding and collapsing content.
*/
export default function ModuleExpandable({
Expand Down Expand Up @@ -106,3 +105,5 @@ export default function ModuleExpandable({
</Box>
);
}

ModuleExpandable.displayName = 'Module.Expandable';
5 changes: 3 additions & 2 deletions packages/gestalt/src/TableBody.js
Expand Up @@ -10,9 +10,10 @@ type Props = {|
|};

/**
* Subcomponent of [Table](https://gestalt.pinterest.systems/table).
* Use [Table.Body](https://gestalt.pinterest.systems/table#Table.BodyProps) to group the body content in Table.
* Use [Table.Body](https://gestalt.pinterest.systems/table#Table.Body) to group the body content in Table.
*/
export default function TableBody({ children }: Props): Node {
return <tbody className={styles.tbody}>{children}</tbody>;
}

TableBody.displayName = 'Table.Body';

0 comments on commit 4f840d7

Please sign in to comment.