From 2729cb747784662e6cc25613cbc22c77427b0388 Mon Sep 17 00:00:00 2001 From: Armagan Ersoz Date: Wed, 5 Jul 2023 13:00:38 +1000 Subject: [PATCH 1/4] ActionList semantics re-introduce --- src/ActionList/ActionList.docs.json | 46 ++---- .../ActionList.examples.stories.tsx | 87 +++++----- .../ActionList.features.stories.tsx | 69 ++++---- src/ActionList/ActionList.stories.tsx | 40 ++--- src/ActionList/Description.tsx | 1 - src/ActionList/Divider.tsx | 9 +- src/ActionList/Group.tsx | 8 +- src/ActionList/Heading.tsx | 85 ++++++++++ src/ActionList/Item.tsx | 66 ++++++-- src/ActionList/List.tsx | 45 ++++-- src/ActionList/Selection.tsx | 14 +- src/ActionList/Visuals.tsx | 1 + src/ActionList/index.ts | 5 + src/ActionList/shared.ts | 9 ++ src/ActionMenu.tsx | 138 ---------------- .../ActionMenu.examples.stories.tsx | 148 +++++++++--------- .../ActionMenu.features.stories.tsx | 42 ++--- src/ActionMenu/ActionMenu.tsx | 2 +- .../__tests__/ActionMenu.test.tsx | 12 +- .../__tests__/ActionMenu.types.test.tsx | 2 +- src/NavList/NavList.stories.tsx | 17 ++ src/NavList/NavList.test.tsx | 2 +- src/NavList/NavList.tsx | 11 +- src/index.ts | 1 + 24 files changed, 442 insertions(+), 418 deletions(-) create mode 100644 src/ActionList/Heading.tsx delete mode 100644 src/ActionMenu.tsx rename src/{ => ActionMenu}/__tests__/ActionMenu.test.tsx (96%) rename src/{ => ActionMenu}/__tests__/ActionMenu.types.test.tsx (94%) diff --git a/src/ActionList/ActionList.docs.json b/src/ActionList/ActionList.docs.json index 392c6db523a..18610f7f622 100644 --- a/src/ActionList/ActionList.docs.json +++ b/src/ActionList/ActionList.docs.json @@ -7,7 +7,7 @@ "props": [ { "name": "children", - "type": "ActionList.Item[] | ActionList.LinkItem[] | ActionList.Group[]", + "type": "ActionList.Item[] | ActionList.LinkItem[] | ActionList.Divider[]", "defaultValue": "", "required": true, "description": "" @@ -184,50 +184,36 @@ ] }, { - "name": "ActionList.Group", + "name": "ActionList.Heading", "props": [ { - "name": "children", - "type": "ActionList.Item[] | ActionList.LinkItem[]", - "defaultValue": "", - "required": true, + "name": "variant", + "type": "'subtle' | 'filled'", + "defaultValue": "subtle", "description": "" }, { "name": "title", "type": "string", "defaultValue": "", - "description": "Title of the group." + "required": true, + "description": "" }, { - "name": "auxiliaryText", + "name": "subtitle", "type": "string", "defaultValue": "", - "description": "Secondary text that provides additional information about the group." - }, - { - "name": "variant", - "type": "'filled' | 'subtle'", - "defaultValue": "'subtle'", - "description": "`inline` descriptions are positioned beside primary text. `block` descriptions are positioned below primary text." - }, - { - "name": "selectionVariant", - "type": "'single' | 'multiple' | false", - "defaultValue": "", - "description": "Set `selectionVariant` at the group level." - }, - { - "name": "role", - "type": "AriaRole", - "defaultValue": "", - "description": "ARIA role describing the function of the list inside the group. `listbox` and `menu` are a common values." + "required": false, + "description": "" }, { - "name": "sx", - "type": "SystemStyleObject" + "name": "headingLevel", + "type": "'1' | '2' | '3' | '4' | '5' | '6'", + "defaultValue": "3", + "required": false, + "description": "" } ] } ] -} \ No newline at end of file +} diff --git a/src/ActionList/ActionList.examples.stories.tsx b/src/ActionList/ActionList.examples.stories.tsx index ef5c79a08aa..654e4dcf5ee 100644 --- a/src/ActionList/ActionList.examples.stories.tsx +++ b/src/ActionList/ActionList.examples.stories.tsx @@ -132,24 +132,25 @@ export function MixedSelection(): JSX.Element {

List with mixed selection

- In this list, there is a ActionList.Group with single selection for picking one option, followed by a Item that - is an action. This pattern appears inside a menu for selection view options in Memex + In this list, there is a ActionList with single selection for picking one option, followed by another ActionList + with a single Item that is an action. This pattern appears inside a menu for selection view options in Memex.

+ + + {options.map((option, index) => ( + setSelectedIndex(index)} + role="option" + > + {option.icon} + {option.text} + + ))} + - - {options.map((option, index) => ( - setSelectedIndex(index)} - role="option" - > - {option.icon} - {option.text} - - ))} - {typeof selectedIndex === 'number' && ( <> @@ -248,37 +249,31 @@ export function MemexSortable(): JSX.Element { // @ts-ignore react-dnd needs to be updated to support React 18 - - {visibleOptions.map(option => ( - toggle(option.text)} - reorder={reorder} - /> - ))} - - - {hiddenOptions.map((option, index) => ( - toggle(option.text)} - > - {option.icon} - {option.text} - - ))} - {hiddenOptions.length === 0 && No hidden fields} - + + {visibleOptions.map(option => ( + toggle(option.text)} + reorder={reorder} + /> + ))} + + + + {hiddenOptions.map((option, index) => ( + toggle(option.text)} + > + {option.icon} + {option.text} + + ))} + {hiddenOptions.length === 0 && No hidden fields} ) diff --git a/src/ActionList/ActionList.features.stories.tsx b/src/ActionList/ActionList.features.stories.tsx index a27e2181d3c..2888ad1108f 100644 --- a/src/ActionList/ActionList.features.stories.tsx +++ b/src/ActionList/ActionList.features.stories.tsx @@ -3,7 +3,6 @@ import {Meta} from '@storybook/react' import {ActionList} from '.' import {Item} from './Item' import {LinkItem} from './LinkItem' -import {Group} from './Group' import {Divider} from './Divider' import {Description} from './Description' import Avatar from '../Avatar' @@ -28,7 +27,7 @@ import { export default { title: 'Components/ActionList/Features', component: ActionList, - subcomponents: {Item, LinkItem, Group, Divider, Description}, + subcomponents: {Item, LinkItem, Divider, Description}, } as Meta export const SimpleList = () => ( @@ -428,23 +427,22 @@ export const GroupWithSubtleTitle = () => { return ( - - {users.slice(2).map(user => ( - assignee.login === user.login))} - aria-checked={Boolean(assignees.find(assignee => assignee.login === user.login))} - onSelect={() => toggleAssignee(user)} - > - - - - {user.login} - {user.name} - - ))} - + + {users.slice(2).map(user => ( + assignee.login === user.login))} + aria-checked={Boolean(assignees.find(assignee => assignee.login === user.login))} + onSelect={() => toggleAssignee(user)} + > + + + + {user.login} + {user.name} + + ))} ) } @@ -461,23 +459,22 @@ export const GroupWithFilledTitle = () => { return ( - - {users.slice(2).map(user => ( - assignee.login === user.login))} - aria-checked={Boolean(assignees.find(assignee => assignee.login === user.login))} - onSelect={() => toggleAssignee(user)} - > - - - - {user.login} - {user.name} - - ))} - + + {users.slice(2).map(user => ( + assignee.login === user.login))} + aria-checked={Boolean(assignees.find(assignee => assignee.login === user.login))} + onSelect={() => toggleAssignee(user)} + > + + + + {user.login} + {user.name} + + ))} ) } diff --git a/src/ActionList/ActionList.stories.tsx b/src/ActionList/ActionList.stories.tsx index de6f66ae6f5..982dc3c2b71 100644 --- a/src/ActionList/ActionList.stories.tsx +++ b/src/ActionList/ActionList.stories.tsx @@ -1,9 +1,9 @@ import React from 'react' import {Story, Meta} from '@storybook/react' -import {ActionList, ActionListProps, ActionListGroupProps} from '.' +import {ActionList, ActionListProps} from '.' import {Item} from './Item' import {LinkItem} from './LinkItem' -import {Group} from './Group' +import {Heading, ActionListHeadingProps} from './Heading' import {Divider} from './Divider' import {Description} from './Description' import {TypographyIcon, VersionsIcon, SearchIcon, ArrowRightIcon, ArrowLeftIcon} from '@primer/octicons-react' @@ -11,7 +11,7 @@ import {TypographyIcon, VersionsIcon, SearchIcon, ArrowRightIcon, ArrowLeftIcon} export default { title: 'Components/ActionList', component: ActionList, - subcomponents: {Item, LinkItem, Group, Divider, Description}, + subcomponents: {Item, LinkItem, Heading, Divider, Description}, } as Meta export const Default = () => ( @@ -33,7 +33,7 @@ Playground.args = { showDividers: false, selectionVariant: undefined, variant: 'inset', - role: 'listbox', + role: 'list', } Playground.argTypes = { showDividers: { @@ -242,34 +242,34 @@ LinkItemPlayground.argTypes = { }, } -export const GroupPlayground: Story = args => ( +export const HeadingPlayground: Story = args => ( - - Item 1 - Item 2 - + ) -GroupPlayground.argTypes = { + +HeadingPlayground.args = { + title: 'Group title', +} + +HeadingPlayground.argTypes = { variant: { + type: 'string', control: { type: 'radio', }, options: ['subtle', 'filled'], }, - role: { - type: 'string', - }, title: { type: 'string', }, - auxiliaryText: { + subtitle: { type: 'string', }, -} -GroupPlayground.args = { - variant: 'subtle', - role: 'listbox', - title: 'Group title', - auxiliaryText: '', + as: { + control: { + type: 'radio', + }, + options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'], + }, } diff --git a/src/ActionList/Description.tsx b/src/ActionList/Description.tsx index 4027ec22f58..011c1a800b8 100644 --- a/src/ActionList/Description.tsx +++ b/src/ActionList/Description.tsx @@ -44,7 +44,6 @@ export const Description: React.FC {props.children} diff --git a/src/ActionList/Divider.tsx b/src/ActionList/Divider.tsx index 224140dc9ef..2647cc47422 100644 --- a/src/ActionList/Divider.tsx +++ b/src/ActionList/Divider.tsx @@ -4,15 +4,17 @@ import {get} from '../constants' import {Theme} from '../ThemeProvider' import {SxProp, merge} from '../sx' -export type ActionListDividerProps = SxProp +export type ActionListDividerProps = { + as?: React.ElementType +} & SxProp /** * Visually separates `Item`s or `Group`s in an `ActionList`. */ -export const Divider: React.FC> = ({sx = {}}) => { +export const Divider: React.FC> = ({sx = {}, as = 'li'}) => { return (