diff --git a/.changeset/actionlist2-actionmenu2-prefix-types.md b/.changeset/actionlist2-actionmenu2-prefix-types.md new file mode 100644 index 00000000000..b7d4cd11224 --- /dev/null +++ b/.changeset/actionlist2-actionmenu2-prefix-types.md @@ -0,0 +1,21 @@ +--- +'@primer/react': major +--- + +`ActionList2` exported types are now prefixed with `ActionList`: + +``` +ListProps → ActionListProps +GroupProps → ActionListGroupProps +ItemProps → ActionListItemProps +DescriptionProps → ActionListDescriptionProps +LeadingVisualProps → ActionListLeadingVisualProps, +TrailingVisualProps → ActionListTrailingVisualProps +``` + +`ActionMenu2` exported types are now prefixed with `ActionMenu`: + +``` +MenuButtonProps → ActionMenuButtonProps +MenuAnchorProps → ActionMenuAnchorProps +``` diff --git a/.changeset/deprecate-actionlistv1-promote-actionlistv2.md b/.changeset/deprecate-actionlistv1-promote-actionlistv2.md new file mode 100644 index 00000000000..1979e50e66a --- /dev/null +++ b/.changeset/deprecate-actionlistv1-promote-actionlistv2.md @@ -0,0 +1,154 @@ +--- +'@primer/react': major +--- + +### ActionList + +ActionList has been rewritten with a composable API, design updates and accessibility fixes. + +See full list of props and examples: https://primer.style/react/ActionList + + + + + + + + + + + + + + + + + +
Before (v34) After (v35)
+ +```jsx + +``` + + + +```jsx + + New file + Copy link + Edit file + + Delete file + +``` + +
+ +```jsx + , + text: 'mona', + description: 'Monalisa Octocat', + descriptionVariant: 'block' + }, + { + key: '2', + leadingVisual: GearIcon, + text: 'View Settings', + trailingVisual: ArrowRightIcon + } + ]} +/> +``` + + + +```jsx + + + + + + github/primer + + + + + + mona + Monalisa Octocat + + + + + + View settings + + + + + +``` + +
+ +```jsx + +``` + + + +```jsx + + + repo:github/github + + + + + Table + Board Description + + + + View settings + +``` + +
+ +To continue to use the deprecated API for now, change the import path to `@primer/react/deprecated`: + +```js +import {ActionList} from '@primer/react/deprecated' +``` + +You can use the [one-time codemod](https://github.com/primer/react-migrate#readme) to change your import statements automatically. diff --git a/.changeset/deprecate-actionmenuv1-promote-actionmenuv2.md b/.changeset/deprecate-actionmenuv1-promote-actionmenuv2.md new file mode 100644 index 00000000000..3fbec5cf4eb --- /dev/null +++ b/.changeset/deprecate-actionmenuv1-promote-actionmenuv2.md @@ -0,0 +1,69 @@ +--- +'@primer/react': major +--- + +### ActionMenu + +ActionMenu has been rewritten with a composable API, design updates and accessibility fixes. + +See full list of props and examples: https://primer.style/react/ActionMenu + +Main changes: + +1. Instead of using `items` prop, use `ActionList` inside `ActionMenu` +2. Instead of using `anchorContent` on `ActionMenu`, use `ActionMenu.Button` with `children` +3. Instead of using `onAction` prop on `ActionMenu`, use `onSelect` prop on `ActionList.Item` +4. Instead of using `groupMetadata` on `ActionMenu`, use `ActionList.Group` +5. Instead of `overlayProps` on `ActionMenu`, use `ActionMenu.Overlay` + + + + + + + + + +
Before (v34) After (v35)
+ +```jsx + +``` + + + +```jsx + + Menu + + + New file + Copy link + Edit file + + Delete file + + + +``` + +
+ +To continue to use the deprecated API for now, change the import path to `@primer/react/deprecated`: + +```js +import {ActionMenu} from '@primer/react/deprecated' +``` + +You can use the [one-time codemod](https://github.com/primer/react-migrate#readme) to change your import statements automatically. diff --git a/.changeset/deprecate-dropdownmenu.md b/.changeset/deprecate-dropdownmenu.md new file mode 100644 index 00000000000..cc9e225639c --- /dev/null +++ b/.changeset/deprecate-dropdownmenu.md @@ -0,0 +1,107 @@ +--- +'@primer/react': major +--- + +### DropdownMenu + +DropdownMenu has been deprecated in favor of ActionMenu with ActionList + +See example with selection: https://primer.style/react/ActionMenu#with-selection + +Migration guide: + +1. Instead of using `items` prop, use `ActionList` inside `ActionMenu` +2. Use `selectionVariant="single"` on `ActionList` to set the right semantics for selection +3. Instead of using `selectedItem` prop, use `selected` prop on `ActionList.Item` +4. Instead of using `renderAnchor` and `placeholder` props on `DropdownMenu`, use `ActionMenu.Button` or `ActionMenu.Anchor` +5. Instead of using `onChange` prop on `DropdownMenu`, use `onSelect` prop on `ActionList.Item` +6. Instead of using `groupMetadata` on `DropdownMenu`, use `ActionList.Group` +7. Instead of `overlayProps` on `DropdownMenu`, use `ActionMenu.Overlay` + + + + + + + + + +
Before (v34) After (v35)
+ +```js +const fieldTypes = [ + {key: 0, text: 'Text'}, + {key: 1, text: 'Number'}, + {key: 3, text: 'Date'}, + {key: 4, text: 'Single select'}, + {key: 5, text: 'Iteration'} +] + +const Example = () => { + const [selectedType, setSelectedType] = React.useState() + + return ( + ( + + {children} + + )} + placeholder="Field type" + items={fieldTypes} + selectedItem={selectedType} + onChange={setSelectedType} + overlayProps={{width: 'medium'}} + /> + ) +} +``` + + + +```jsx +const fieldTypes = [ + {id: 0, text: 'Text'}, + {id: 1, text: 'Number'}, + {id: 3, text: 'Date'}, + {id: 4, text: 'Single select'}, + {id: 5, text: 'Iteration'} +] + +const Example = () => { + const [selectedType, setSelectedType] = React.useState() + + render( + + {selectedType.name || 'Field type'} + + + {fieldTypes.map(type => ( + setSelectedType(type)} + > + {type.name} + + ))} + + + + ) +} +``` + +
+ +To continue to use the deprecated API for now, change the import path to `@primer/react/deprecated`: + +```js +import {DropdownMenu} from '@primer/react/deprecated' +``` + +You can use the [one-time codemod](https://github.com/primer/react-migrate#readme) to change your import statements automatically. + +### drafts/DropdownMenu2 + +DropdownMenu2 has been removed in favor of ActionMenu with ActionList diff --git a/.changeset/empty-pillows-hunt.md b/.changeset/empty-pillows-hunt.md new file mode 100644 index 00000000000..14a2228fb78 --- /dev/null +++ b/.changeset/empty-pillows-hunt.md @@ -0,0 +1,152 @@ +--- +'@primer/react': major +--- + +### ActionList + +ActionList now ships a composable API. + +See full list of props and examples: https://primer.style/react/ActionList + + + + + + + + + + + + + + + + + +
Before After
+ +```jsx + +``` + + + +```jsx + + New file + Copy link + Edit file + + Delete file + +``` + +
+ +```jsx + , + text: 'mona', + description: 'Monalisa Octocat', + descriptionVariant: 'block' + }, + { + key: '2', + leadingVisual: GearIcon, + text: 'View Settings', + trailingVisual: ArrowRightIcon + } + ]} +/> +``` + + + +```jsx + + + + + + github/primer + + + + + + mona + Monalisa Octocat + + + + + + View settings + + + + + +``` + +
+ +```jsx + +``` + + + +```jsx + + + repo:github/github + + + + + Table + Board Description + + + + View settings + +``` + +
+ +To continue to use the deprecated API for now, change the import path to `@primer/react/deprecated`: + +```js +import {ActionList} from '@primer/react/deprecated' +``` diff --git a/.changeset/odd-apes-guess.md b/.changeset/odd-apes-guess.md new file mode 100644 index 00000000000..e15f28b4809 --- /dev/null +++ b/.changeset/odd-apes-guess.md @@ -0,0 +1,12 @@ +--- +"@primer/react": major +--- + +`PageLayout` is being graduated from the `drafts` bundle to the `main` bundle. + +To upgrade, rewrite your imports accordingly: + +```diff +- import {PageLayout} from '@primer/react/drafts' ++ import {PageLayout} from '@primer/react' +``` diff --git a/.changeset/smooth-cameras-prove.md b/.changeset/smooth-cameras-prove.md new file mode 100644 index 00000000000..f3d34b33be6 --- /dev/null +++ b/.changeset/smooth-cameras-prove.md @@ -0,0 +1,262 @@ +--- +'@primer/react': major +--- + +### SelectMenu + +⚠️ `SelectMenu` has been deprecated. Please use `ActionMenu` instead. + + + + + + + + + +
Before After
+ +```jsx + + + + Projects + + Primer React bugs + Primer React roadmap + Project 3 + Project 4 + + + +``` + + + +```jsx + + Projects + + + + Primer React bugs + Primer React roadmap + Project three + Project four + + + + +``` + +
+ +See [https://primer.style/react/ActionMenu](https://primer.style/react/ActionMenu) for more migration examples. + +### Dropdown + +⚠️ `Dropdown` has been deprecated. Please use `ActionMenu` instead. + + + + + + + + + +
Before After
+ +```jsx +const fieldTypes = [ + {leadingVisual: TypographyIcon, text: 'Text'}, + {leadingVisual: NumberIcon, text: 'Number'} +] + +const Example = () => { + const [selectedItem, setSelectedItem] = React.useState() + + return ( + {children}} + placeholder="Select a field type" + items={fieldTypes} + selectedItem={selectedItem} + onChange={() => setSelectedIndex(index)} + /> + ) +} +``` + + + +```jsx +const fieldTypes = [ + {icon: , name: 'Text'}, + {icon: , name: 'Number'} +] + +const Example = () => { + const [selectedItem, setSelectedItem] = React.useState() + + return ( + + {selectedItem ? selectedItem.name : 'Select a field type'} + + + {fieldTypes.map(field => ( + setSelectedItem(field)} key={field.name}> + {field.icon} + {field.name} + + ))} + + + + ) +} +``` + +
+ +See [https://primer.style/react/ActionMenu](https://primer.style/react/ActionMenu) for more migration examples. + +### Flex + +⚠️ `Flex` has been deprecated. Please use [`Box`](https://primer.style/react/Box) instead. + + + + + + + + + +
Before After
+ +```jsx + + + Item 1 + + +``` + + + +```jsx + + + Item 1 + + +``` + +
+ +### Grid + +⚠️ `Grid` has been deprecated. Please use `ActionMenu` instead. + + + + + + + + + +
Before After
+ +```jsx + + + 1 + + + 2 + + +``` + + + +```jsx + + + 1 + + + 2 + + +``` + +
+ +### BorderBox + +⚠️ `BorderBox` has been deprecated. Please use [`Box`](https://primer.style/react/Box) instead. + + + + + + + + + +
Before After
+ +```jsx +Item 1 +``` + + + +```jsx + + Item 1 + +``` + +
+ +### Position + +⚠️ `Position` has been deprecated. Please use [`Box`](https://primer.style/react/Box) instead. + + + + + + + + + +
Before After
+ +```jsx +<> + ... + ... + ... + ... + ... + +``` + + + +```jsx +<> + ... + ... + ... + ... + ... + +``` + +
diff --git a/deprecated/package.json b/deprecated/package.json new file mode 100644 index 00000000000..e7a211fd303 --- /dev/null +++ b/deprecated/package.json @@ -0,0 +1,9 @@ +{ + "_comment1": "this is required only for typescript. once this is fixed https://github.com/microsoft/TypeScript/issues/33079 we can remove this hack", + "name": "@primer/react/deprecated", + "types": "../lib-esm/deprecated/index.d.ts", + "main": "../lib-esm/deprecated/index.js", + "type": "module", + "sideEffects": false + } + \ No newline at end of file diff --git a/docs/content/ActionList.mdx b/docs/content/ActionList.mdx index 7eb5066cca2..02c2fb4b032 100644 --- a/docs/content/ActionList.mdx +++ b/docs/content/ActionList.mdx @@ -3,98 +3,446 @@ componentId: action_list title: ActionList status: Alpha source: https://github.com/primer/react/tree/main/src/ActionList +storybook: '/react/storybook?path=/story/composite-components-actionlist' +description: An ActionList is a list of items that can be activated or selected. ActionList is the base component for many menu-type components, including ActionMenu and SelectPanel. --- -An `ActionList` is a list of items which can be activated or selected. `ActionList` is the base component for many of our menu-type components, including `DropdownMenu` and `ActionMenu`. +import {Avatar} from '@primer/react' +import {ActionList} from '@primer/react' +import {LinkIcon, AlertIcon, ArrowRightIcon} from '@primer/octicons-react' +import InlineCode from '@primer/gatsby-theme-doctocat/src/components/inline-code' -## Minimal example + + + + + + + github.com/primer + + A React implementation of GitHub's Primer Design System + + + + + + + mona + Monalisa Octocat + + + + + + 4 vulnerabilities + + + + + + + +```js +import {ActionList} from '@primer/react' +``` + +## Examples + +### Minimal example ```jsx live - + + New file + Copy link + Edit file + + Delete file + ``` -## Example with grouped items +### With leading visual + +Leading visuals are optional and appear at the start of an item. They can be octicons, avatars, and other custom visuals that fit a small area. + ```jsx live - + + + + github.com/primer + + + + 4 vulnerabilities + + + + mona + + + ``` -## Example with custom item renderer - -```jsx - - }, - { - text: 'React Router link', - renderItem: props => - }, - { - text: 'NextJS style', - renderItem: props => ( - - - - ) - } - ]} -/> +### With trailing visual + +Trailing visual and trailing text can display auxiliary information. They're placed at the right of the item, and can denote status, keyboard shortcuts, or be used to set expectations about what the action does. + +```jsx live + + + New file + ⌘ + N + + + Copy link + ⌘ + C + + + Edit file + ⌘ + E + + + Delete file + + + +``` + +### With description and dividers + +Item dividers allow users to parse heavier amounts of information. They're placed between items and are useful in complex lists, particularly when descriptions or multi-line text is present. + +```jsx live + + + + + + mona + Monalisa Octocat + + + + + + hubot + Hubot + + + + + + primer-css + GitHub Design Systems Bot + + +``` + +### With links + +When you want to add links to the List instead of actions, use `ActionList.LinkItem` + + +```jsx live + + + + + + github/primer + + + + + + MIT License + + + + + + 1.4k stars + + +``` + +### With groups + +```javascript live noinline +const SelectFields = () => { + const [options, setOptions] = React.useState([ + {text: 'Status', selected: true}, + {text: 'Stage', selected: true}, + {text: 'Assignee', selected: true}, + {text: 'Team', selected: true}, + {text: 'Estimate', selected: false}, + {text: 'Due Date', selected: false} + ]) + + const visibleOptions = options.filter(option => option.selected) + const hiddenOptions = options.filter(option => !option.selected) + + const toggle = text => { + setOptions( + options.map(option => { + if (option.text === text) option.selected = !option.selected + return option + }) + ) + } + + return ( + + + {visibleOptions.map(option => ( + toggle(option.text)}> + {option.text} + + ))} + + + {hiddenOptions.map((option, index) => ( + toggle(option.text)}> + {option.text} + + ))} + {hiddenOptions.length === 0 && No hidden fields} + + + ) +} + +render() ``` ## Props -| Name | Type | Default | Description | -| :--------------- | :------------------------------------------------------------------------------------------------------------------------------------------------ | :---------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------ | -| items | `(ItemProps & Omit, keyof ItemProps>) \| ((Partial & {renderItem: RenderItemFn}) & {key?: Key})` | `undefined` | Required. A list of item objects conforming to the `ActionList.Item` props interface. | -| renderItem | `(props: ItemProps) => JSX.Element` | `ActionList.Item` | Optional. If defined, each item in `items` will be passed to this function, allowing for `ActionList`-wide custom item rendering. | -| groupMetadata | `GroupProps[]` | `undefined` | Optional. If defined, `ActionList` will group `items` into `ActionList.Group`s separated by `ActionList.Divider` according to their `groupId` property. | -| showItemDividers | `boolean` | `false` | Optional. If `true` dividers will be displayed above each `ActionList.Item` which does not follow an `ActionList.Header` or `ActionList.Divider` | +### ActionList + + + + + inset children are offset (vertically and horizontally) from list edges.{' '} + full children are flush (vertically and horizontally) with list edges + + } + /> + + + AriaRole + } + description={ + <> + ARIA role describing the function of the list. listbox and{' '} + menu are a common values. + + } + /> + + + +### ActionList.Item + + + + + danger indicates that the item is destructive. + + } + /> + + + + AriaRole + } + description={ + <> + ARIA role describing the function of the item. option is a common value. + + } + /> + + + +### ActionList.LinkItem + + + + MDN + } + /> + + +### ActionList.LeadingVisual + + + + + + +### ActionList.TrailingVisual + + + + + + +### ActionList.Description + + + + + inline descriptions are positioned beside primary text. block{' '} + descriptions are positioned below primary text. + + } + /> + + + +### ActionList.Group + + + + + + + inline descriptions are positioned beside primary text. block{' '} + descriptions are positioned below primary text. + + } + /> + + Set selectionVariant at the group level. + + } + /> + AriaRole + } + description={ + <> + ARIA role describing the function of the list inside the group. listbox and{' '} + menu are a common values. + + } + /> + + + +## Status + + + +## Further reading + +- [Interface guidelines: Action List](https://primer.style/design/components/action-list) + +## Related components + +- [ActionMenu](/ActionMenu) +- [SelectPanel](/SelectPanel) diff --git a/docs/content/ActionMenu.mdx b/docs/content/ActionMenu.mdx index 1c0e13ecd9b..d2ace211ddf 100644 --- a/docs/content/ActionMenu.mdx +++ b/docs/content/ActionMenu.mdx @@ -2,81 +2,341 @@ componentId: action_menu title: ActionMenu status: Alpha +source: https://github.com/primer/react/tree/main/src/ActionMenu.tsx +storybook: '/react/storybook?path=/story/composite-components-actionmenu' +description: An ActionMenu is an ActionList-based component for creating a menu of actions that expands through a trigger button. --- -An `ActionMenu` is an ActionList-based component for creating a menu of actions that expands through a trigger button. +import {Box, Avatar, ActionList, ActionMenu} from '@primer/react' -## Default example +
+ + + + Menu + + + + Copy link + ⌘C + + + Quote reply + ⌘Q + + + Edit comment + ⌘E + + + + Delete file + ⌘D + + + + + + +
+ +```js +import {ActionMenu} from '@primer/react/drafts' +``` + +
+ +## Examples + +### Minimal example + +`ActionMenu` ships with `ActionMenu.Button` which is an accessible trigger for the overlay. It's recommended to compose `ActionList` with `ActionMenu.Overlay` + +  ```jsx live - console.log(text)} - items={[ - {text: 'New file', key: 'new-file'}, - ActionMenu.Divider, - {text: 'Copy link', key: 'copy-link'}, - {text: 'Edit file', key: 'edit-file'}, - {text: 'Delete file', variant: 'danger', key: 'delete-file'} - ]} -/> + + Menu + + + + console.log('New file')}>New file + Copy link + Edit file + + Delete file + + + ``` -## Example with grouped items +### With a custom anchor + +You can choose to have a different _anchor_ for the Menu dependending on the application's context. + +  ```jsx live - console.log(text)} - groupMetadata={[ - {groupId: '0'}, - {groupId: '1', header: {title: 'Live query', variant: 'subtle'}}, - {groupId: '2', header: {title: 'Layout', variant: 'subtle'}}, - {groupId: '3'}, - {groupId: '4'} - ]} - items={[ - {key: '1', leadingVisual: TypographyIcon, text: 'Rename', groupId: '0'}, - {key: '2', leadingVisual: VersionsIcon, text: 'Duplicate', groupId: '0'}, - {key: '3', leadingVisual: SearchIcon, text: 'repo:github/github', groupId: '1'}, - { - key: '4', - leadingVisual: NoteIcon, - text: 'Table', - description: 'Information-dense table optimized for operations across teams', - descriptionVariant: 'block', - groupId: '2' - }, - { - key: '5', - leadingVisual: ProjectIcon, - text: 'Board', - description: 'Kanban-style board focused on visual states', - descriptionVariant: 'block', - groupId: '2' - }, - { - key: '6', - leadingVisual: FilterIcon, - text: 'Save sort and filters to current view', - disabled: true, - groupId: '3' - }, - {key: '7', leadingVisual: FilterIcon, text: 'Save sort and filters to new view', groupId: '3'}, - {key: '8', leadingVisual: GearIcon, text: 'View settings', groupId: '4'} - ]} -/> + + + + + + + + + + + + + + Rename + + + + + + Archive all cards + + + + + + Delete + + + + +``` + +### With Groups + +```jsx live + + Open column menu + + + + + + + + + repo:github/memex,github/github + + + + + + + + + Table + + Information-dense table optimized for operations across teams + + + + + + + Board + Kanban-style board focused on visual states + + + + + + + + + Save sort and filters to current view + + + + + + Save sort and filters to new view + + + + + + + + + View settings + + + + + +``` + +### With selection + +Use `selectionVariant` on `ActionList` to create a menu with single or multiple selection. + +```javascript live noinline +const fieldTypes = [ + {icon: TypographyIcon, name: 'Text'}, + {icon: NumberIcon, name: 'Number'}, + {icon: CalendarIcon, name: 'Date'}, + {icon: SingleSelectIcon, name: 'Single select'}, + {icon: IterationsIcon, name: 'Iteration'} +] + +const Example = () => { + const [selectedIndex, setSelectedIndex] = React.useState(1) + const selectedType = fieldTypes[selectedIndex] + + return ( + + + {selectedType.name} + + + + {fieldTypes.map((type, index) => ( + setSelectedIndex(index)}> + + + + {type.name} + + ))} + + + + ) +} + +render() ``` -## Component props - -| Name | Type | Default | Description | -| :------------ | :------------------------------------ | :---------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| items | `ItemProps[]` | `undefined` | Required. A list of item objects conforming to the `ActionList.Item` props interface. | -| renderItem | `(props: ItemProps) => JSX.Element` | `ActionList.Item` | Optional. If defined, each item in `items` will be passed to this function, allowing for `ActionList`-wide custom item rendering. | -| groupMetadata | `GroupProps[]` | `undefined` | Optional. If defined, `ActionList` will group `items` into `ActionList.Group`s separated by `ActionList.Divider` according to their `groupId` property. | -| renderAnchor | `(props: ButtonProps) => JSX.Element` | `Button` | Optional. If defined, provided component will be used to render the menu anchor. Will receive the selected `Item` text as `children` prop when an item is activated. | -| anchorContent | React.ReactNode | `undefined` | Optional. If defined, it will be passed to the trigger as the elements child. | -| onAction | (props: ItemProps) => void | `undefined` | Optional. If defined, this function will be called when a menu item is activated either by a click or a keyboard press. | -| open | boolean | `undefined` | Optional. If defined, ActionMenu will use this to control the open/closed state of the Overlay instead of controlling the state internally. Should be used in conjunction with the `setOpen` prop. | -| setOpen | (state: boolean) => void | `undefined` | Optional. If defined, ActionMenu will use this to control the open/closed state of the Overlay instead of controlling the state internally. Should be used in conjunction with the `open` prop. | +### With External Anchor + +To create an anchor outside of the menu, you need to switch to controlled mode for the menu and pass it as `anchorRef` to `ActionMenu`. Make sure you add `aria-expanded` and `aria-haspopup` to the external anchor: + +```javascript live noinline +const Example = () => { + const [open, setOpen] = React.useState(false) + const anchorRef = React.createRef() + + return ( + <> + + + + + + Copy link + Quote reply + Edit comment + + Delete file + + + + + ) +} + +render() +``` + +### With Overlay Props + +To create an anchor outside of the menu, you need to switch to controlled mode for the menu and pass it as `anchorRef` to `ActionMenu`: + +```javascript live noinline +const handleEscape = () => alert('you hit escape!') + +render( + + Open Actions Menu + + + + Open current Codespace + + Your existing Codespace will be opened to its previous state, and you'll be asked to manually switch to + new-branch. + + ⌘O + + + Create new Codespace + + Create a brand new Codespace with a fresh image and checkout this branch. + + ⌘C + + + + +) +``` + +## Props / API reference + +### ActionMenu + +| Name | Type | Default | Description | +| :----------- | :----------------------------- | :-----: | :----------------------------------------------------------------------------------------------------------------------- | +| children\* | `React.ReactElement[]` | - | Required. Recommended: `ActionMenu.Button` or `ActionMenu.Anchor` with `ActionMenu.Overlay` | +| open | `boolean` | - | Optional. If defined, will control the open/closed state of the overlay. Must be used in conjuction with `onOpenChange`. | +| onOpenChange | `(open: boolean) => void` | - | Optional. If defined, will control the open/closed state of the overlay. Must be used in conjuction with `open`. | +| anchorRef | `React.RefObject` | - | Optional. Useful for defining an external anchor | + +### ActionMenu.Button + +| Type | Default | Description | +| :----------------------------------------------- | :-----: | :---------------------------------------------------------------------------------------------------------------- | +| [Button v2 props](/drafts/Button2#api-reference) | - | You can pass all of the props that you would pass to a [`Button`](/drafts/Button2) component like `variant`, `sx` | + +### ActionMenu.Anchor + +| Name | Type | Default | Description | +| :--------- | :------------------- | :-----: | :-------------------------------- | +| children\* | `React.ReactElement` | - | Required. Accepts a single child. | + +### ActionMenu.Overlay + +| Name | Type | Default | Description | +| :--------------------------------------- | :-------------------- | :-----------------: | :-------------------------------------------------------------------------------------------- | +| children\* | `React.ReactElement[] | React.ReactElement` | Required. Recommended: [`ActionList`](/ActionList) | +| [OverlayProps](/Overlay#component-props) | - | - | Optional. Props to be spread on the internal [`AnchoredOverlay`](/AnchoredOverlay) component. | + +## Status + + + +## Further reading + +[Interface guidelines: Action List + Menu](https://primer.style/design/components/action-list) + +## Related components + +- [ActionList](/ActionList) +- [SelectPanel](/SelectPanel) +- [Button](/drafts/Button2) diff --git a/docs/content/drafts/PageLayout.mdx b/docs/content/PageLayout.mdx similarity index 97% rename from docs/content/drafts/PageLayout.mdx rename to docs/content/PageLayout.mdx index a04cfc87307..64d439c49d3 100644 --- a/docs/content/drafts/PageLayout.mdx +++ b/docs/content/PageLayout.mdx @@ -7,7 +7,7 @@ storybook: https://primer.style/react/storybook?path=/story/layout-pagelayout--p --- ```js -import {PageLayout} from '@primer/react/drafts' +import {PageLayout} from '@primer/react' ``` ## Examples @@ -20,7 +20,7 @@ See [storybook](https://primer.style/react/storybook?path=/story/layout-pagelayo ### Default -```jsx live drafts +```jsx live @@ -39,7 +39,7 @@ See [storybook](https://primer.style/react/storybook?path=/story/layout-pagelayo ### With dividers -```jsx live drafts +```jsx live @@ -58,7 +58,7 @@ See [storybook](https://primer.style/react/storybook?path=/story/layout-pagelayo ### With pane on left -```jsx live drafts +```jsx live @@ -77,7 +77,7 @@ See [storybook](https://primer.style/react/storybook?path=/story/layout-pagelayo ### With condensed spacing -```jsx live drafts +```jsx live @@ -96,7 +96,7 @@ See [storybook](https://primer.style/react/storybook?path=/story/layout-pagelayo ### Without header or footer -```jsx live drafts +```jsx live diff --git a/docs/content/SideNav.md b/docs/content/SideNav.md index bb6d6bf3f67..04c2ff0535d 100644 --- a/docs/content/SideNav.md +++ b/docs/content/SideNav.md @@ -114,11 +114,11 @@ It can also appear nested, as a sub navigation. Use margin/padding [System Props ```jsx live - + Account - + Profile diff --git a/docs/content/deprecated/ActionList.mdx b/docs/content/deprecated/ActionList.mdx new file mode 100644 index 00000000000..1bcf8880fc0 --- /dev/null +++ b/docs/content/deprecated/ActionList.mdx @@ -0,0 +1,136 @@ +--- +componentId: action_list +title: ActionList +status: Deprecated +source: https://github.com/primer/react/tree/main/src/deprecated/ActionList +--- + +An `ActionList` is a list of items which can be activated or selected. `ActionList` is the base component for many of our menu-type components, including `DropdownMenu` and `ActionMenu`. + +## Deprecation + +Use [new version of ActionList](/ActionList) with composable API, design updates and accessibility fixes. + +**Before** + +```jsx + +``` + +**After** + +```jsx + + New file + Copy link + Edit file + + Delete file + +``` + +Or continue using deprecated API: + +```js +import {ActionList} from '@primer/react/deprecated' +``` + +## Minimal example + +```jsx live deprecated + +``` + +## Example with grouped items + +```jsx live deprecated + +``` + +## Example with custom item renderer + +```jsx deprecated + + }, + { + text: 'React Router link', + renderItem: props => + }, + { + text: 'NextJS style', + renderItem: props => ( + + + + ) + } + ]} +/> +``` + +## Props + +| Name | Type | Default | Description | +| :--------------- | :------------------------------------------------------------------------------------------------------------------------------------------------ | :---------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------ | +| items | `(ItemProps & Omit, keyof ItemProps>) \| ((Partial & {renderItem: RenderItemFn}) & {key?: Key})` | `undefined` | Required. A list of item objects conforming to the `ActionList.Item` props interface. | +| renderItem | `(props: ItemProps) => JSX.Element` | `ActionList.Item` | Optional. If defined, each item in `items` will be passed to this function, allowing for `ActionList`-wide custom item rendering. | +| groupMetadata | `GroupProps[]` | `undefined` | Optional. If defined, `ActionList` will group `items` into `ActionList.Group`s separated by `ActionList.Divider` according to their `groupId` property. | +| showItemDividers | `boolean` | `false` | Optional. If `true` dividers will be displayed above each `ActionList.Item` which does not follow an `ActionList.Header` or `ActionList.Divider` | diff --git a/docs/content/deprecated/ActionMenu.mdx b/docs/content/deprecated/ActionMenu.mdx new file mode 100644 index 00000000000..0fa65bbc4b9 --- /dev/null +++ b/docs/content/deprecated/ActionMenu.mdx @@ -0,0 +1,127 @@ +--- +componentId: action_menu +title: ActionMenu +status: Deprecated +source: https://github.com/primer/react/tree/main/src/deprecated/ActionMenu.tsx +--- + +An `ActionMenu` is an ActionList-based component for creating a menu of actions that expands through a trigger button. + +## Deprecation + +Use [new version of ActionMenu](/ActionMenu) with composable API, design updates and accessibility fixes. + +**Before** + +```jsx + +``` + +**After** + +```jsx + + Menu + + + New file + Copy link + Edit file + + Delete file + + + +``` + +Or continue using deprecated API: + +```js +import {ActionMenu} from '@primer/react/deprecated' +``` + +## Default example + +```jsx live deprecated + console.log(text)} + items={[ + {text: 'New file', key: 'new-file'}, + ActionMenu.Divider, + {text: 'Copy link', key: 'copy-link'}, + {text: 'Edit file', key: 'edit-file'}, + {text: 'Delete file', variant: 'danger', key: 'delete-file'} + ]} +/> +``` + +## Example with grouped items + +```jsx live deprecated + console.log(text)} + groupMetadata={[ + {groupId: '0'}, + {groupId: '1', header: {title: 'Live query', variant: 'subtle'}}, + {groupId: '2', header: {title: 'Layout', variant: 'subtle'}}, + {groupId: '3'}, + {groupId: '4'} + ]} + items={[ + {key: '1', leadingVisual: TypographyIcon, text: 'Rename', groupId: '0'}, + {key: '2', leadingVisual: VersionsIcon, text: 'Duplicate', groupId: '0'}, + {key: '3', leadingVisual: SearchIcon, text: 'repo:github/github', groupId: '1'}, + { + key: '4', + leadingVisual: NoteIcon, + text: 'Table', + description: 'Information-dense table optimized for operations across teams', + descriptionVariant: 'block', + groupId: '2' + }, + { + key: '5', + leadingVisual: ProjectIcon, + text: 'Board', + description: 'Kanban-style board focused on visual states', + descriptionVariant: 'block', + groupId: '2' + }, + { + key: '6', + leadingVisual: FilterIcon, + text: 'Save sort and filters to current view', + disabled: true, + groupId: '3' + }, + {key: '7', leadingVisual: FilterIcon, text: 'Save sort and filters to new view', groupId: '3'}, + {key: '8', leadingVisual: GearIcon, text: 'View settings', groupId: '4'} + ]} +/> +``` + +## Component props + +| Name | Type | Default | Description | +| :------------ | :------------------------------------ | :---------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| items | `ItemProps[]` | `undefined` | Required. A list of item objects conforming to the `ActionList.Item` props interface. | +| renderItem | `(props: ItemProps) => JSX.Element` | `ActionList.Item` | Optional. If defined, each item in `items` will be passed to this function, allowing for `ActionList`-wide custom item rendering. | +| groupMetadata | `GroupProps[]` | `undefined` | Optional. If defined, `ActionList` will group `items` into `ActionList.Group`s separated by `ActionList.Divider` according to their `groupId` property. | +| renderAnchor | `(props: ButtonProps) => JSX.Element` | `Button` | Optional. If defined, provided component will be used to render the menu anchor. Will receive the selected `Item` text as `children` prop when an item is activated. | +| anchorContent | React.ReactNode | `undefined` | Optional. If defined, it will be passed to the trigger as the elements child. | +| onAction | (props: ItemProps) => void | `undefined` | Optional. If defined, this function will be called when a menu item is activated either by a click or a keyboard press. | +| open | boolean | `undefined` | Optional. If defined, ActionMenu will use this to control the open/closed state of the Overlay instead of controlling the state internally. Should be used in conjunction with the `setOpen` prop. | +| setOpen | (state: boolean) => void | `undefined` | Optional. If defined, ActionMenu will use this to control the open/closed state of the Overlay instead of controlling the state internally. Should be used in conjunction with the `open` prop. | diff --git a/docs/content/deprecated/BorderBox.md b/docs/content/deprecated/BorderBox.md index 45a206fd88e..2be97d6e22a 100644 --- a/docs/content/deprecated/BorderBox.md +++ b/docs/content/deprecated/BorderBox.md @@ -12,13 +12,13 @@ Use [Box](/Box) instead. **Before** -```jsx +```jsx deprecated Item 1 ``` **After** -```jsx +```jsx deprecated Item 1 @@ -26,7 +26,7 @@ Use [Box](/Box) instead. ## Default example -```jsx live +```jsx live deprecated This is a BorderBox ``` diff --git a/docs/content/deprecated/Dialog.md b/docs/content/deprecated/Dialog.md index aafa7065703..dcd79b30623 100644 --- a/docs/content/deprecated/Dialog.md +++ b/docs/content/deprecated/Dialog.md @@ -9,7 +9,7 @@ Use [Dialog2](/Dialog2) instead. **Before** -```jsx +```jsx deprecated setOpen(false)} aria-labelledby="header-id"> Title @@ -20,7 +20,7 @@ Use [Dialog2](/Dialog2) instead. **After** -```jsx +```jsx deprecated { open && ( {([isOpen, setIsOpen]) => { const returnFocusRef = React.useRef(null) @@ -87,7 +87,7 @@ If you're running into z-index issues or are rendering the component inside of a You can also pass any non-text content into the header: -```jsx live +```jsx deprecated live {([isOpen, setIsOpen]) => { const returnFocusRef = React.useRef(null) diff --git a/docs/content/deprecated/Dropdown.md b/docs/content/deprecated/Dropdown.md index b53bb11d42a..f08fd426d2f 100644 --- a/docs/content/deprecated/Dropdown.md +++ b/docs/content/deprecated/Dropdown.md @@ -5,7 +5,7 @@ status: Deprecated ## Deprecation -Use [DropdownMenu](/DropdownMenu) instead. +Use [ActionMenu](/ActionMenu) instead. --- @@ -17,7 +17,7 @@ Dropdown.Menu wraps your menu content. Be sure to pass a `direction` prop to thi ## Default example -```jsx live +```jsx live deprecated Dropdown @@ -30,7 +30,7 @@ Dropdown.Menu wraps your menu content. Be sure to pass a `direction` prop to thi ## With custom button -```jsx live +```jsx live deprecated Dropdown diff --git a/docs/content/DropdownMenu.mdx b/docs/content/deprecated/DropdownMenu.mdx similarity index 65% rename from docs/content/DropdownMenu.mdx rename to docs/content/deprecated/DropdownMenu.mdx index f74fbda16f2..df48fbc532c 100644 --- a/docs/content/DropdownMenu.mdx +++ b/docs/content/deprecated/DropdownMenu.mdx @@ -1,14 +1,91 @@ --- componentId: dropdown_menu title: DropdownMenu -status: Alpha +status: Deprecated --- A `DropdownMenu` provides an anchor (button by default) that will open a floating menu of selectable items. The menu can be opened and navigated using keyboard or mouse. When an item is selected, the menu will close and the `onChange` callback will be called. If the default anchor button is used, the anchor contents will be updated with the selection. +## Deprecation + +Use [new version of ActionMenu](/ActionMenu#with-selection) with composable API, design updates and accessibility fixes. + +**Before** + +```jsx +const fieldTypes = [ + {key: 0, text: 'Text'}, + {key: 1, text: 'Number'}, + {key: 3, text: 'Date'}, + {key: 4, text: 'Single select'}, + {key: 5, text: 'Iteration'} +] + +const Example = () => { + const [selectedType, setSelectedType] = React.useState() + + return ( + ( + + {children} + + )} + placeholder="Field type" + items={fieldTypes} + selectedItem={selectedType} + onChange={setSelectedType} + /> + ) +} +``` + +**After** + +Instead of `DropdownMenu`, you can use the `ActionMenu` with `ActionList selectionVariant=single`, this will give menu items the correct semantics: + +```jsx +const fieldTypes = [ + {id: 0, text: 'Text'}, + {id: 1, text: 'Number'}, + {id: 3, text: 'Date'}, + {id: 4, text: 'Single select'}, + {id: 5, text: 'Iteration'} +] + +const Example = () => { + const [selectedType, setSelectedType] = React.useState() + + render( + + {selectedType.name || 'Field type'} + + + {fieldTypes.map(type => ( + setSelectedType(type)} + > + {type.name} + + ))} + + + + ) +} +``` + +Or continue using deprecated API: + +```js +import {DropdownMenu} from '@primer/react/deprecated' +``` + ## Example -```javascript live noinline +```javascript live noinline deprecated function DemoComponent() { const items = React.useMemo( () => [ diff --git a/docs/content/deprecated/Flex.md b/docs/content/deprecated/Flex.md index 67e7fa385b7..5ad6838dfc8 100644 --- a/docs/content/deprecated/Flex.md +++ b/docs/content/deprecated/Flex.md @@ -12,7 +12,7 @@ Use [Box](/Box) instead. **Before** -```jsx +```jsx deprecated Item 1 @@ -22,7 +22,7 @@ Use [Box](/Box) instead. **After** -```jsx +```jsx deprecated Item 1 @@ -32,7 +32,7 @@ Use [Box](/Box) instead. ## Default example -```jsx live +```jsx deprecated live diff --git a/docs/content/deprecated/Grid.md b/docs/content/deprecated/Grid.md index 305bed992be..905630fe9e7 100644 --- a/docs/content/deprecated/Grid.md +++ b/docs/content/deprecated/Grid.md @@ -12,7 +12,7 @@ Use [Box](/Box) instead. **Before** -```jsx +```jsx deprecated 1 @@ -25,7 +25,7 @@ Use [Box](/Box) instead. **After** -```jsx +```jsx deprecated 1 @@ -38,7 +38,7 @@ Use [Box](/Box) instead. ## Default example -```jsx live +```jsx deprecated live 1 diff --git a/docs/content/deprecated/Position.md b/docs/content/deprecated/Position.md index 74212be10fa..fb2006117ca 100644 --- a/docs/content/deprecated/Position.md +++ b/docs/content/deprecated/Position.md @@ -12,7 +12,7 @@ Use [Box](/Box) instead. **Before** -```jsx +```jsx deprecated <> ... ... @@ -24,7 +24,7 @@ Use [Box](/Box) instead. **After** -```jsx +```jsx deprecated <> ... ... @@ -36,7 +36,7 @@ Use [Box](/Box) instead. ## Default examples -```jsx live +```jsx deprecated live Relative + Absolute diff --git a/docs/content/deprecated/SelectMenu.md b/docs/content/deprecated/SelectMenu.md index faea3452588..b6fbea07843 100644 --- a/docs/content/deprecated/SelectMenu.md +++ b/docs/content/deprecated/SelectMenu.md @@ -3,13 +3,19 @@ title: SelectMenu status: Deprecated --- +## Deprecation + +Use [ActionMenu](/ActionMenu) instead. + +--- + The `SelectMenu` components are a suite of components which can be combined together to make several different variations of our GitHub select menu. At it's most basic form, a select menu is comprised of a `SelectMenu` wrapper, which contains a `summary` component of your choice and a `Select.Modal` which contains the select menu content. Use `SelectMenu.List` to wrap items in the select menu, and `SelectMenu.Item` to wrap each item. Several additional components exist to provide even more functionality: `SelectMenu.Header`, `SelectMenu.Filter`, `SelectMenu.Tabs`, `SelectMenu.TabPanel` `SelectMenu.Footer` and `SelectMenu.Divider`. ## Basic Example -```jsx live +```jsx deprecated live @@ -28,7 +34,7 @@ Several additional components exist to provide even more functionality: `SelectM Main wrapper component for select menu. -```jsx +```jsx deprecated {/* all other sub components are wrapped here*/} ``` @@ -56,7 +62,7 @@ SelectMenu.MenuContext is a [context object](https://reactjs.org/docs/context.ht ### Example Usage -```jsx +```jsx deprecated import {SelectMenu, Button} from `@primer/react` import React, {useContext} from 'react' @@ -83,7 +89,7 @@ const MyButton = () => { Used to wrap the content in a `SelectMenu`. -```jsx +```jsx deprecated {/* all menu content is wrapped in the modal*/} ``` @@ -91,7 +97,7 @@ Used to wrap the content in a `SelectMenu`. Use the `align='right'` prop to align the modal to the right. Note that this only modifies alignment for the modal, and not the SelectMenu itself. You will need to wrap the SelectMenu in a relatively positioned element for this to work properly. -```jsx live +```jsx deprecated live @@ -120,7 +126,7 @@ Use the `align='right'` prop to align the modal to the right. Note that this onl Used to wrap the select menu list content. All menu items **must** be wrapped in a SelectMenu.List in order for the accessbility keyboard handling to function properly. If you are using the `SelectMenu.TabPanel` you do not need to provide a `SelectMenu.List` as that component renders a `SelectMenu.List` as a wrapper. -```jsx +```jsx deprecated {/* all menu list items are wrapped in the list*/} ``` @@ -136,7 +142,7 @@ Individual items in a select menu. SelectMenu.Item renders an anchor tag by defa You can use a `button` tag instead by utilizing the [`as` prop](/core-concepts#the-as-prop). Be sure to consider [which HTML element is the right choice](https://marcysutton.com/links-vs-buttons-in-modern-web-applications) for your usage of the component. -```jsx +```jsx deprecated {/* wraps an individual list item*/} @@ -154,7 +160,7 @@ You can use a `button` tag instead by utilizing the [`as` prop](/core-concepts#t Use a `SelectMenu.Filter` to add a filter UI to your select menu. Users are expected to implement their own filtering and manage the state of the `value` prop on the input. This gives users more flexibility over the type of filtering and type of content passed into each select menu item. -```jsx live +```jsx deprecated live @@ -192,7 +198,7 @@ Each `Select.Menu` tab will need to have an `index` prop. The first tab should b If you need access to the selected tab state, you can find it in the MenuContext object exported from `SelectMenu` as `MenuContext.selectedTab`. -```jsx live +```jsx deprecated live @@ -227,7 +233,7 @@ Used for each individual tab inside of a `SelectMenu.Tabs`. Be sure to set the ` The `onClick` prop is optional and can be used for any events or data fetching you might need to trigger on tab clicks. -```jsx +```jsx deprecated <> @@ -249,7 +255,7 @@ Wraps the content for each tab. Make sure to use the `tabName` prop to identify **Note**: SelectMenu.TabPanel wraps content in a SelectMenu.List, so adding a SelectMenu.List manually is not necessary. -```jsx +```jsx deprecated {/* Wraps content for each tab */} ``` @@ -264,7 +270,7 @@ Wraps the content for each tab. Make sure to use the `tabName` prop to identify Use a `SelectMenu.Divider` to add information between items in a `SelectMenu.List`. -```jsx live +```jsx deprecated live @@ -290,7 +296,7 @@ Use a `SelectMenu.Divider` to add information between items in a `SelectMenu.Lis Use a `SelectMenu.Footer` to add content to the bottom of the select menu. -```jsx live +```jsx deprecated live @@ -316,7 +322,7 @@ Use a `SelectMenu.Footer` to add content to the bottom of the select menu. Use a `SelectMenu.Header` to add a header to the top of the select menu content. -```jsx live +```jsx deprecated live @@ -344,7 +350,7 @@ Use a `SelectMenu.LoadingAnimation` to add a loading animation inside of the Sel **Note**: You will need to handle showing/hiding the appropriate modal content for your application during the loading state. We recommend always showing the `SelectMenu.Filter` and `SelectMenu.Header` (if used) and hiding the rest of the modal content during the loading state. -```jsx live +```jsx deprecated live diff --git a/docs/content/drafts/ActionList2.mdx b/docs/content/drafts/ActionList2.mdx deleted file mode 100644 index bf842be1fe6..00000000000 --- a/docs/content/drafts/ActionList2.mdx +++ /dev/null @@ -1,449 +0,0 @@ ---- -componentId: action_list2 -title: ActionList v2 -status: Alpha -source: https://github.com/primer/react/tree/main/src/ActionList2 -storybook: '/react/storybook?path=/story/composite-components-actionlist2' -description: An ActionList is a list of items that can be activated or selected. ActionList is the base component for many menu-type components, including DropdownMenu and ActionMenu. ---- - -import {Avatar} from '@primer/react' -import {ActionList} from '@primer/react/drafts' -import {LinkIcon, AlertIcon, ArrowRightIcon} from '@primer/octicons-react' -import InlineCode from '@primer/gatsby-theme-doctocat/src/components/inline-code' - - - - - - - - github.com/primer - - A React implementation of GitHub's Primer Design System - - - - - - - mona - Monalisa Octocat - - - - - - 4 vulnerabilities - - - - - - - -```js -import {ActionList} from '@primer/react/drafts' -``` - -## Examples - -### Minimal example - -```jsx live drafts - - New file - Copy link - Edit file - - Delete file - -``` - -### With leading visual - -Leading visuals are optional and appear at the start of an item. They can be octicons, avatars, and other custom visuals that fit a small area. - - -```jsx live drafts - - - - github.com/primer - - - - 4 vulnerabilities - - - - mona - - - -``` - -### With trailing visual - -Trailing visual and trailing text can display auxiliary information. They're placed at the right of the item, and can denote status, keyboard shortcuts, or be used to set expectations about what the action does. - -```jsx live drafts - - - New file - ⌘ + N - - - Copy link - ⌘ + C - - - Edit file - ⌘ + E - - - Delete file - - - -``` - -### With description and dividers - -Item dividers allow users to parse heavier amounts of information. They're placed between items and are useful in complex lists, particularly when descriptions or multi-line text is present. - -```jsx live drafts - - - - - - mona - Monalisa Octocat - - - - - - hubot - Hubot - - - - - - primer-css - GitHub Design Systems Bot - - -``` - -### With links - -When you want to add links to the List instead of actions, use `ActionList.LinkItem` - - -```jsx live drafts - - - - - - github/primer - - - - - - MIT License - - - - - - 1.4k stars - - -``` - -### With groups - -```javascript live noinline drafts -const SelectFields = () => { - const [options, setOptions] = React.useState([ - {text: 'Status', selected: true}, - {text: 'Stage', selected: true}, - {text: 'Assignee', selected: true}, - {text: 'Team', selected: true}, - {text: 'Estimate', selected: false}, - {text: 'Due Date', selected: false} - ]) - - const visibleOptions = options.filter(option => option.selected) - const hiddenOptions = options.filter(option => !option.selected) - - const toggle = text => { - setOptions( - options.map(option => { - if (option.text === text) option.selected = !option.selected - return option - }) - ) - } - - return ( - - - {visibleOptions.map(option => ( - toggle(option.text)}> - {option.text} - - ))} - - - {hiddenOptions.map((option, index) => ( - toggle(option.text)}> - {option.text} - - ))} - {hiddenOptions.length === 0 && No hidden fields} - - - ) -} - -render() -``` - -## Props - -### ActionList - - - - - inset children are offset (vertically and horizontally) from list edges.{' '} - full children are flush (vertically and horizontally) with list edges - - } - /> - - - AriaRole - } - description={ - <> - ARIA role describing the function of the list. listbox and{' '} - menu are a common values. - - } - /> - - - -### ActionList.Item - - - - - danger indicates that the item is destructive. - - } - /> - - - - AriaRole - } - description={ - <> - ARIA role describing the function of the item. option is a common value. - - } - /> - - - -### ActionList.LinkItem - - - - MDN - } - /> - - -### ActionList.LeadingVisual - - - - - - -### ActionList.TrailingVisual - - - - - - -### ActionList.Description - - - - - inline descriptions are positioned beside primary text. block{' '} - descriptions are positioned below primary text. - - } - /> - - - -### ActionList.Group - - - - - - - inline descriptions are positioned beside primary text. block{' '} - descriptions are positioned below primary text. - - } - /> - - Set selectionVariant at the group level. - - } - /> - AriaRole - } - description={ - <> - ARIA role describing the function of the list inside the group. listbox and{' '} - menu are a common values. - - } - /> - - - -## Status - - - -## Further reading - -- [Interface guidelines: Action List](https://primer.style/design/components/action-list) - -## Related components - -- [ActionMenu](/drafts/ActionMenu2) -- [DropdownMenu](/DropdownMenu) -- [SelectPanel](/SelectPanel) diff --git a/docs/content/drafts/ActionMenu2.mdx b/docs/content/drafts/ActionMenu2.mdx deleted file mode 100644 index 4ccc9b3c5a3..00000000000 --- a/docs/content/drafts/ActionMenu2.mdx +++ /dev/null @@ -1,341 +0,0 @@ ---- -componentId: action_menu2 -title: ActionMenu v2 -status: Alpha -source: https://github.com/primer/react/tree/main/src/ActionMenu -storybook: '/react/storybook?path=/story/composite-components-actionmenu2' -description: An ActionMenu is an ActionList-based component for creating a menu of actions that expands through a trigger button. ---- - -import {Box, Avatar} from '@primer/react' -import {ActionMenu, ActionList} from '@primer/react/drafts' -import {Props} from '../../src/props' - -
- - - - Menu - - - - Copy link - ⌘C - - - Quote reply - ⌘Q - - - Edit comment - ⌘E - - - - Delete file - ⌘D - - - - - - -
- -```js -import {ActionMenu} from '@primer/react/drafts' -``` - -
- -## Examples - -### Minimal example - -`ActionMenu` ships with `ActionMenu.Button` which is an accessible trigger for the overlay. It's recommended to compose `ActionList` with `ActionMenu.Overlay` - -  - -```jsx live drafts - - Menu - - - - console.log('New file')}>New file - Copy link - Edit file - - Delete file - - - -``` - -### With a custom anchor - -You can choose to have a different _anchor_ for the Menu dependending on the application's context. - -  - -```jsx live drafts - - - - - - - - - - - - - - Rename - - - - - - Archive all cards - - - - - - Delete - - - - -``` - -### With Groups - -```jsx live drafts - - Open column menu - - - - - - - - - repo:github/memex,github/github - - - - - - - - - Table - - Information-dense table optimized for operations across teams - - - - - - - Board - Kanban-style board focused on visual states - - - - - - - - - Save sort and filters to current view - - - - - - Save sort and filters to new view - - - - - - - - - View settings - - - - - -``` - -### With selection - -Use `selectionVariant` on `ActionList` to create a menu with single or multiple selection. - -```javascript live noinline drafts -const fieldTypes = [ - {icon: TypographyIcon, name: 'Text'}, - {icon: NumberIcon, name: 'Number'}, - {icon: CalendarIcon, name: 'Date'}, - {icon: SingleSelectIcon, name: 'Single select'}, - {icon: IterationsIcon, name: 'Iteration'} -] - -const Example = () => { - const [selectedIndex, setSelectedIndex] = React.useState(1) - const selectedType = fieldTypes[selectedIndex] - - return ( - - - {selectedType.name} - - - - {fieldTypes.map((type, index) => ( - setSelectedIndex(index)}> - {type.name} - - ))} - - - - ) -} - -render() -``` - -### With External Anchor - -To create an anchor outside of the menu, you need to switch to controlled mode for the menu and pass it as `anchorRef` to `ActionMenu`. Make sure you add `aria-expanded` and `aria-haspopup` to the external anchor: - -```javascript live noinline drafts -const Example = () => { - const [open, setOpen] = React.useState(false) - const anchorRef = React.createRef() - - return ( - <> - - - - - - Copy link - Quote reply - Edit comment - - Delete file - - - - - ) -} - -render() -``` - -### With Overlay Props - -To create an anchor outside of the menu, you need to switch to controlled mode for the menu and pass it as `anchorRef` to `ActionMenu`: - -```javascript live noinline drafts -const handleEscape = () => alert('you hit escape!') - -render( - - Open Actions Menu - - - - Open current Codespace - - Your existing Codespace will be opened to its previous state, and you'll be asked to manually switch to - new-branch. - - ⌘O - - - Create new Codespace - - Create a brand new Codespace with a fresh image and checkout this branch. - - ⌘C - - - - -) -``` - -## Props / API reference - -### ActionMenu - -| Name | Type | Default | Description | -| :----------- | :----------------------------- | :-----: | :----------------------------------------------------------------------------------------------------------------------- | -| children\* | `React.ReactElement[]` | - | Required. Recommended: `ActionMenu.Button` or `ActionMenu.Anchor` with `ActionMenu.Overlay` | -| open | `boolean` | - | Optional. If defined, will control the open/closed state of the overlay. Must be used in conjuction with `onOpenChange`. | -| onOpenChange | `(open: boolean) => void` | - | Optional. If defined, will control the open/closed state of the overlay. Must be used in conjuction with `open`. | -| anchorRef | `React.RefObject` | - | Optional. Useful for defining an external anchor | - -### ActionMenu.Button - -| Type | Default | Description | -| :----------------------------------------------- | :-----: | :---------------------------------------------------------------------------------------------------------------- | -| [Button v2 props](/drafts/Button2#api-reference) | - | You can pass all of the props that you would pass to a [`Button`](/drafts/Button2) component like `variant`, `sx` | - -### ActionMenu.Anchor - -| Name | Type | Default | Description | -| :--------- | :------------------- | :-----: | :-------------------------------- | -| children\* | `React.ReactElement` | - | Required. Accepts a single child. | - -### ActionMenu.Overlay - -| Name | Type | Default | Description | -| :--------------------------------------- | :-------------------- | :-----------------: | :-------------------------------------------------------------------------------------------- | -| children\* | `React.ReactElement[] | React.ReactElement` | Required. Recommended: [`ActionList`](/drafts/ActionList2) | -| [OverlayProps](/Overlay#component-props) | - | - | Optional. Props to be spread on the internal [`AnchoredOverlay`](/AnchoredOverlay) component. | - -## Status - - - -## Further reading - -[Interface guidelines: Action List + Menu](https://primer.style/design/components/action-list) - -## Related components - -- [ActionList](/drafts/ActionList2) -- [SelectPanel](/SelectPanel) -- [Button](/drafts/Button2) diff --git a/docs/content/drafts/DropdownMenu2.mdx b/docs/content/drafts/DropdownMenu2.mdx deleted file mode 100644 index 68cd522aa1e..00000000000 --- a/docs/content/drafts/DropdownMenu2.mdx +++ /dev/null @@ -1,364 +0,0 @@ ---- -component_id: dropdown_menu -title: DropdownMenu v2 -status: Alpha -source: https://github.com/primer/react/tree/main/src/DropdownMenu2.tsx -storybook: '/react/storybook?path=/story/composite-components-dropdownmenu2' -description: Use DropdownMenu to select a single option from a list of menu options. ---- - -import {Box, Avatar} from '@primer/react' -import {DropdownMenu, ActionList} from '@primer/react/drafts' -import {Props} from '../../src/props' -import State from '../../components/State' -import {CalendarIcon, IterationsIcon, NumberIcon, SingleSelectIcon, TypographyIcon} from '@primer/octicons-react' - -
- - - {([selectedIndex, setSelectedIndex]) => { - const fieldTypes = [ - {icon: TypographyIcon, name: 'Text'}, - {icon: NumberIcon, name: 'Number'}, - {icon: CalendarIcon, name: 'Date'}, - {icon: SingleSelectIcon, name: 'Single select'}, - {icon: IterationsIcon, name: 'Iteration'} - ] - const selectedType = fieldTypes[selectedIndex] - return ( - - - - {selectedType.name} - - - - {fieldTypes.map(({icon: Icon, name}, index) => ( - setSelectedIndex(index)} - > - {name} - - ))} - - - - - ) - }} - - -
- -```js -import {DropdownMenu} from '@primer/react/drafts' -``` - -
- -## Examples - -### Minimal example - -`DropdownMenu` ships with `DropdownMenu.Button` which is an accessible trigger for the overlay. It's recommended to compose `ActionList` with `DropdownMenu.Overlay` - -  - -```javascript live noinline drafts -const fieldTypes = [ - {icon: TypographyIcon, name: 'Text'}, - {icon: NumberIcon, name: 'Number'}, - {icon: CalendarIcon, name: 'Date'}, - {icon: SingleSelectIcon, name: 'Single select'}, - {icon: IterationsIcon, name: 'Iteration'} -] - -const Example = () => { - const [selectedIndex, setSelectedIndex] = React.useState(1) - const selectedType = fieldTypes[selectedIndex] - - return ( - - - {selectedType.name} - - - - {fieldTypes.map((type, index) => ( - setSelectedIndex(index)}> - {type.name} - - ))} - - - - ) -} - -render() -``` - -### Customise Button - -`Dropdown.Button` uses `Button v2` so you can pass props like `variant` and `leadingIcon` that `Button v2` accepts. - -```javascript live noinline drafts -const Example = () => { - const [duration, setDuration] = React.useState(1) - - return ( - - - {duration} {duration > 1 ? 'weeks' : 'week'} - - - - {[1, 2, 3, 4, 5, 6].map(weeks => ( - setDuration(weeks)}> - {weeks} {weeks > 1 ? 'weeks' : 'week'} - - ))} - - - - ) -} - -render() -``` - -### With External Anchor - -To create an anchor outside of the menu, you need to switch to controlled mode for the menu and pass `open` and `onOpenChange` along with an `anchorRef` to `DropdownMenu`: - -```javascript live noinline drafts -const Example = () => { - const [open, setOpen] = React.useState(false) - const anchorRef = React.createRef() - - return ( - <> - - - - - - Text - Number - Date - Iteration - - - - - ) -} - -render() -``` - -### With Overlay Props - -```javascript live noinline drafts -const fieldTypes = [ - {icon: TypographyIcon, name: 'Text'}, - {icon: NumberIcon, name: 'Number'}, - {icon: CalendarIcon, name: 'Date'}, - {icon: SingleSelectIcon, name: 'Single select'}, - {icon: IterationsIcon, name: 'Iteration'} -] - -const Example = () => { - const handleEscape = () => alert('you hit escape!') - - const [selectedIndex, setSelectedIndex] = React.useState(1) - const selectedType = fieldTypes[selectedIndex] - - return ( - - - {selectedType.name} - - - - {fieldTypes.map((type, index) => ( - setSelectedIndex(index)}> - {type.name} - - ))} - - - - ) -} - -render() -``` - -### With a custom anchor - -You can choose to have a different _anchor_ for the Menu dependending on the application's context. - -  - -```javascript live noinline drafts -render( - - - - - - - - Text - Number - Date - Iteration - - - -) -``` - - - -Use `DropdownMenu` to select an option from a small list. If you’re looking for filters or multiple selection, use [SelectPanel](/SelectPanel) instead. - - - -## Props - -### DropdownMenu - - - - Recommended: DropdownMenu.Button or DropdownMenu.Anchor with{' '} - DropdownMenu.Overlay - - } - /> - - If defined, will control the open/closed state of the overlay. Must be used in conjuction with{' '} - onOpenChange - - } - /> - - If defined, will control the open/closed state of the overlay. Must be used in conjuction with{' '} - open - - } - /> - - - -### DropdownMenu.Button - - - - ButtonProps - - } - description={ - <> - You can pass all of the props that you would pass to a{' '} - - Button - {' '} - component like variant, leadingIcon,{' '} - sx, etc. - - } - /> - - -### DropdownMenu.Anchor - - - - - -### DropdownMenu.Overlay - - - - Recommended:{' '} - - ActionList - - - } - /> - - Props to be spread on the internal{' '} - - AnchoredOverlay - - - } - /> - - -## Status - - - -## Further reading - -[Interface guidelines: Action List + Menu](https://primer.style/design/components/action-list) - -## Related components - -- [ActionList](/drafts/ActionList2) -- [ActionMenu](/ActionMenu2) -- [SelectPanel](/SelectPanel) diff --git a/docs/package-lock.json b/docs/package-lock.json index 5aa240cad2d..f7109a43471 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -8,7 +8,7 @@ "name": "docs", "version": "1.0.0", "dependencies": { - "@primer/gatsby-theme-doctocat": "^3.2.0", + "@primer/gatsby-theme-doctocat": "^3.2.1", "@primer/octicons-react": "^16.1.0", "@primer/primitives": "4.1.0", "@styled-system/prop-types": "^5.1.0", @@ -2719,69 +2719,28 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" }, + "node_modules/@primer/behaviors": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@primer/behaviors/-/behaviors-1.1.0.tgz", + "integrity": "sha512-Ej2OUc3ZIFaR7WwIUqESO1DTzmpb7wc8xbTVRT9s52jZQDjN7g5iljoK3ocYZm+BIAcKn3MvcwB42hEk4Ga4xQ==" + }, "node_modules/@primer/component-metadata": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/@primer/component-metadata/-/component-metadata-0.4.1.tgz", "integrity": "sha512-iy5ZEeIRN6pFFG7px2ruuA726yVB/n4lsgM3msfdg9qJzfS9qE2JCqq2OuvQ+yXUTxb3JKROaDSH403kdpFR4Q==" }, - "node_modules/@primer/components": { - "version": "30.3.0", - "resolved": "https://registry.npmjs.org/@primer/components/-/components-30.3.0.tgz", - "integrity": "sha512-5W2WQtTzBsGE12+SIcc49RlosgkoamFDMkwNh5kKuQq1Ni9fXjxfWQaykh8CaWydcywMfnZbPcESKnuu+KfLZQ==", - "deprecated": "@primer/components has been renamed @primer/react. Use @primer/react instead.", - "dependencies": { - "@primer/octicons-react": "^13.0.0", - "@primer/primitives": "4.8.1", - "@radix-ui/react-polymorphic": "0.0.14", - "@react-aria/ssr": "3.1.0", - "@styled-system/css": "5.1.5", - "@styled-system/props": "5.1.5", - "@styled-system/theme-get": "5.1.2", - "@types/history": "4.7.8", - "@types/styled-components": "5.1.11", - "@types/styled-system": "5.1.12", - "@types/styled-system__css": "5.0.16", - "@types/styled-system__theme-get": "5.0.1", - "classnames": "2.3.1", - "color2k": "1.2.4", - "deepmerge": "4.2.2", - "focus-visible": "5.2.0", - "styled-system": "5.1.5" - }, - "peerDependencies": { - "react": "^17.0.0", - "react-dom": "^17.0.0", - "styled-components": "4.x || 5.x" - } - }, - "node_modules/@primer/components/node_modules/@primer/octicons-react": { - "version": "13.0.0", - "resolved": "https://registry.npmjs.org/@primer/octicons-react/-/octicons-react-13.0.0.tgz", - "integrity": "sha512-j5XppNRCvgaMZLPsVvvmp6GSh7P5pq6PUbsfLNBWi2Kz3KYDeoGDWbPr5MjoxFOGUn6Hjnt6qjHPRxahd11vLQ==", - "engines": { - "node": ">=8" - }, - "peerDependencies": { - "react": ">=15" - } - }, - "node_modules/@primer/components/node_modules/@primer/primitives": { - "version": "4.8.1", - "resolved": "https://registry.npmjs.org/@primer/primitives/-/primitives-4.8.1.tgz", - "integrity": "sha512-mgr6+EKpn4DixuhLt3drk7QmNQO8M7RYONWovg1nkV7p56jklhDLfZmp1luLUee37eQGAxx3ToStL6gqINFjnQ==" - }, "node_modules/@primer/gatsby-theme-doctocat": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@primer/gatsby-theme-doctocat/-/gatsby-theme-doctocat-3.2.0.tgz", - "integrity": "sha512-C/8X4xHKWmVf+TKlzWzvj65+BRbcTv6rWr1VoiFQsf6hQacEvzxe6BiTvuvZTFQ+P7Ei1TWKPnTOGbqg0VUSnw==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@primer/gatsby-theme-doctocat/-/gatsby-theme-doctocat-3.2.1.tgz", + "integrity": "sha512-fwt/gttBmy8cwH2MaSb+/CQayytiRzxvLc9L7QoqxBUsEHkqiqkzjNX46TK+tv+Ntzs/pKyacR5yqXVN5GtfOw==", "dependencies": { "@babel/preset-env": "^7.5.5", "@babel/preset-react": "^7.0.0", "@mdx-js/mdx": "^1.0.21", "@mdx-js/react": "^1.0.21", "@primer/component-metadata": "^0.4.0", - "@primer/components": "^30.0.0", "@primer/octicons-react": "^16.0.0", + "@primer/react": "^34.5.0", "@styled-system/theme-get": "^5.0.12", "@testing-library/jest-dom": "^4.1.0", "@testing-library/react": "^9.1.3", @@ -2849,6 +2808,56 @@ "resolved": "https://registry.npmjs.org/@primer/primitives/-/primitives-4.1.0.tgz", "integrity": "sha512-bACUj3Xl2z5dnYKE/76BpNqN4/JXFngf26dbb7Goph2PU5wcf+Z2Kk3nXwtJPGG8JByO+FcU3gpZjLNoyuLMHQ==" }, + "node_modules/@primer/react": { + "version": "34.6.0", + "resolved": "https://registry.npmjs.org/@primer/react/-/react-34.6.0.tgz", + "integrity": "sha512-a0Mh6YmpEyQF6ad0mnfOJoC+y1heDM4uuvBcQQKJQ28DVeif5mn+slCD2C9ZQvnhkl4qnh3iqXOTxmKN5fCHNQ==", + "dependencies": { + "@primer/behaviors": "1.1.0", + "@primer/octicons-react": "16.1.1", + "@primer/primitives": "7.1.1", + "@radix-ui/react-polymorphic": "0.0.14", + "@react-aria/ssr": "3.1.0", + "@styled-system/css": "5.1.5", + "@styled-system/props": "5.1.5", + "@styled-system/theme-get": "5.1.2", + "@types/styled-components": "5.1.11", + "@types/styled-system": "5.1.12", + "@types/styled-system__css": "5.0.16", + "@types/styled-system__theme-get": "5.0.1", + "classnames": "2.3.1", + "color2k": "1.2.4", + "deepmerge": "4.2.2", + "focus-visible": "5.2.0", + "history": "5.0.0", + "styled-system": "5.1.5" + }, + "engines": { + "node": ">=12", + "npm": ">=7" + }, + "peerDependencies": { + "react": "^17.0.0", + "react-dom": "^17.0.0", + "styled-components": "4.x || 5.x" + } + }, + "node_modules/@primer/react/node_modules/@primer/octicons-react": { + "version": "16.1.1", + "resolved": "https://registry.npmjs.org/@primer/octicons-react/-/octicons-react-16.1.1.tgz", + "integrity": "sha512-xCxQ5z23ol7yDuJs85Lc4ARzyoay+b3zOhAKkEMU7chk0xi2hT2OnRP23QUudNNDPTGozX268RGYLexUa6P4xw==", + "engines": { + "node": ">=8" + }, + "peerDependencies": { + "react": ">=15" + } + }, + "node_modules/@primer/react/node_modules/@primer/primitives": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/@primer/primitives/-/primitives-7.1.1.tgz", + "integrity": "sha512-+Gwo89YK1OFi6oubTlah/zPxxzMNaMLy+inECAYI646KIFdzzhAsKWb3z5tSOu5Ff7no4isRV64rWfMSKLZclw==" + }, "node_modules/@radix-ui/react-polymorphic": { "version": "0.0.14", "resolved": "https://registry.npmjs.org/@radix-ui/react-polymorphic/-/react-polymorphic-0.0.14.tgz", @@ -3310,11 +3319,6 @@ "@types/unist": "*" } }, - "node_modules/@types/history": { - "version": "4.7.8", - "resolved": "https://registry.npmjs.org/@types/history/-/history-4.7.8.tgz", - "integrity": "sha512-S78QIYirQcUoo6UJZx9CSP0O2ix9IaeAXwQi26Rhr/+mg7qqPy8TzaxHSUut7eGjL8WmLccT7/MXf304WjqHcA==" - }, "node_modules/@types/hoist-non-react-statics": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz", @@ -14726,6 +14730,14 @@ "node": "*" } }, + "node_modules/history": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/history/-/history-5.0.0.tgz", + "integrity": "sha512-3NyRMKIiFSJmIPdq7FxkNMJkQ7ZEtVblOQ38VtKaA0zZMW1Eo6Q6W8oDKEflr1kNNTItSnk4JMCO1deeSgbLLg==", + "dependencies": { + "@babel/runtime": "^7.7.6" + } + }, "node_modules/hoist-non-react-statics": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", @@ -28867,60 +28879,28 @@ } } }, + "@primer/behaviors": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@primer/behaviors/-/behaviors-1.1.0.tgz", + "integrity": "sha512-Ej2OUc3ZIFaR7WwIUqESO1DTzmpb7wc8xbTVRT9s52jZQDjN7g5iljoK3ocYZm+BIAcKn3MvcwB42hEk4Ga4xQ==" + }, "@primer/component-metadata": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/@primer/component-metadata/-/component-metadata-0.4.1.tgz", "integrity": "sha512-iy5ZEeIRN6pFFG7px2ruuA726yVB/n4lsgM3msfdg9qJzfS9qE2JCqq2OuvQ+yXUTxb3JKROaDSH403kdpFR4Q==" }, - "@primer/components": { - "version": "30.3.0", - "resolved": "https://registry.npmjs.org/@primer/components/-/components-30.3.0.tgz", - "integrity": "sha512-5W2WQtTzBsGE12+SIcc49RlosgkoamFDMkwNh5kKuQq1Ni9fXjxfWQaykh8CaWydcywMfnZbPcESKnuu+KfLZQ==", - "requires": { - "@primer/octicons-react": "^13.0.0", - "@primer/primitives": "4.8.1", - "@radix-ui/react-polymorphic": "0.0.14", - "@react-aria/ssr": "3.1.0", - "@styled-system/css": "5.1.5", - "@styled-system/props": "5.1.5", - "@styled-system/theme-get": "5.1.2", - "@types/history": "4.7.8", - "@types/styled-components": "5.1.11", - "@types/styled-system": "5.1.12", - "@types/styled-system__css": "5.0.16", - "@types/styled-system__theme-get": "5.0.1", - "classnames": "2.3.1", - "color2k": "1.2.4", - "deepmerge": "4.2.2", - "focus-visible": "5.2.0", - "styled-system": "5.1.5" - }, - "dependencies": { - "@primer/octicons-react": { - "version": "13.0.0", - "resolved": "https://registry.npmjs.org/@primer/octicons-react/-/octicons-react-13.0.0.tgz", - "integrity": "sha512-j5XppNRCvgaMZLPsVvvmp6GSh7P5pq6PUbsfLNBWi2Kz3KYDeoGDWbPr5MjoxFOGUn6Hjnt6qjHPRxahd11vLQ==", - "requires": {} - }, - "@primer/primitives": { - "version": "4.8.1", - "resolved": "https://registry.npmjs.org/@primer/primitives/-/primitives-4.8.1.tgz", - "integrity": "sha512-mgr6+EKpn4DixuhLt3drk7QmNQO8M7RYONWovg1nkV7p56jklhDLfZmp1luLUee37eQGAxx3ToStL6gqINFjnQ==" - } - } - }, "@primer/gatsby-theme-doctocat": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@primer/gatsby-theme-doctocat/-/gatsby-theme-doctocat-3.2.0.tgz", - "integrity": "sha512-C/8X4xHKWmVf+TKlzWzvj65+BRbcTv6rWr1VoiFQsf6hQacEvzxe6BiTvuvZTFQ+P7Ei1TWKPnTOGbqg0VUSnw==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@primer/gatsby-theme-doctocat/-/gatsby-theme-doctocat-3.2.1.tgz", + "integrity": "sha512-fwt/gttBmy8cwH2MaSb+/CQayytiRzxvLc9L7QoqxBUsEHkqiqkzjNX46TK+tv+Ntzs/pKyacR5yqXVN5GtfOw==", "requires": { "@babel/preset-env": "^7.5.5", "@babel/preset-react": "^7.0.0", "@mdx-js/mdx": "^1.0.21", "@mdx-js/react": "^1.0.21", "@primer/component-metadata": "^0.4.0", - "@primer/components": "^30.0.0", "@primer/octicons-react": "^16.0.0", + "@primer/react": "^34.5.0", "@styled-system/theme-get": "^5.0.12", "@testing-library/jest-dom": "^4.1.0", "@testing-library/react": "^9.1.3", @@ -28978,6 +28958,44 @@ "resolved": "https://registry.npmjs.org/@primer/primitives/-/primitives-4.1.0.tgz", "integrity": "sha512-bACUj3Xl2z5dnYKE/76BpNqN4/JXFngf26dbb7Goph2PU5wcf+Z2Kk3nXwtJPGG8JByO+FcU3gpZjLNoyuLMHQ==" }, + "@primer/react": { + "version": "34.6.0", + "resolved": "https://registry.npmjs.org/@primer/react/-/react-34.6.0.tgz", + "integrity": "sha512-a0Mh6YmpEyQF6ad0mnfOJoC+y1heDM4uuvBcQQKJQ28DVeif5mn+slCD2C9ZQvnhkl4qnh3iqXOTxmKN5fCHNQ==", + "requires": { + "@primer/behaviors": "1.1.0", + "@primer/octicons-react": "16.1.1", + "@primer/primitives": "7.1.1", + "@radix-ui/react-polymorphic": "0.0.14", + "@react-aria/ssr": "3.1.0", + "@styled-system/css": "5.1.5", + "@styled-system/props": "5.1.5", + "@styled-system/theme-get": "5.1.2", + "@types/styled-components": "5.1.11", + "@types/styled-system": "5.1.12", + "@types/styled-system__css": "5.0.16", + "@types/styled-system__theme-get": "5.0.1", + "classnames": "2.3.1", + "color2k": "1.2.4", + "deepmerge": "4.2.2", + "focus-visible": "5.2.0", + "history": "5.0.0", + "styled-system": "5.1.5" + }, + "dependencies": { + "@primer/octicons-react": { + "version": "16.1.1", + "resolved": "https://registry.npmjs.org/@primer/octicons-react/-/octicons-react-16.1.1.tgz", + "integrity": "sha512-xCxQ5z23ol7yDuJs85Lc4ARzyoay+b3zOhAKkEMU7chk0xi2hT2OnRP23QUudNNDPTGozX268RGYLexUa6P4xw==", + "requires": {} + }, + "@primer/primitives": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/@primer/primitives/-/primitives-7.1.1.tgz", + "integrity": "sha512-+Gwo89YK1OFi6oubTlah/zPxxzMNaMLy+inECAYI646KIFdzzhAsKWb3z5tSOu5Ff7no4isRV64rWfMSKLZclw==" + } + } + }, "@radix-ui/react-polymorphic": { "version": "0.0.14", "resolved": "https://registry.npmjs.org/@radix-ui/react-polymorphic/-/react-polymorphic-0.0.14.tgz", @@ -29387,11 +29405,6 @@ "@types/unist": "*" } }, - "@types/history": { - "version": "4.7.8", - "resolved": "https://registry.npmjs.org/@types/history/-/history-4.7.8.tgz", - "integrity": "sha512-S78QIYirQcUoo6UJZx9CSP0O2ix9IaeAXwQi26Rhr/+mg7qqPy8TzaxHSUut7eGjL8WmLccT7/MXf304WjqHcA==" - }, "@types/hoist-non-react-statics": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz", @@ -38224,6 +38237,14 @@ "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.7.3.tgz", "integrity": "sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==" }, + "history": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/history/-/history-5.0.0.tgz", + "integrity": "sha512-3NyRMKIiFSJmIPdq7FxkNMJkQ7ZEtVblOQ38VtKaA0zZMW1Eo6Q6W8oDKEflr1kNNTItSnk4JMCO1deeSgbLLg==", + "requires": { + "@babel/runtime": "^7.7.6" + } + }, "hoist-non-react-statics": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", diff --git a/docs/package.json b/docs/package.json index 0346db00bfa..65bc766c8a2 100644 --- a/docs/package.json +++ b/docs/package.json @@ -13,7 +13,7 @@ "npm": ">=7" }, "dependencies": { - "@primer/gatsby-theme-doctocat": "^3.2.0", + "@primer/gatsby-theme-doctocat": "^3.2.1", "@primer/octicons-react": "^16.1.0", "@primer/primitives": "4.1.0", "@styled-system/prop-types": "^5.1.0", diff --git a/docs/src/@primer/gatsby-theme-doctocat/components/live-preview-wrapper.js b/docs/src/@primer/gatsby-theme-doctocat/components/live-preview-wrapper.js index b110b75b748..80e851b9ca9 100644 --- a/docs/src/@primer/gatsby-theme-doctocat/components/live-preview-wrapper.js +++ b/docs/src/@primer/gatsby-theme-doctocat/components/live-preview-wrapper.js @@ -1,4 +1,5 @@ -import {BaseStyles, Box, ThemeProvider, useTheme, DropdownMenu, DropdownButton} from '@primer/react' +import {BaseStyles, Box, ThemeProvider, useTheme} from '@primer/react' +import {DropdownMenu, DropdownButton} from '@primer/react/deprecated' import React from 'react' function ThemeSwitcher() { diff --git a/docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js b/docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js index d8ee2ede36d..a9bbaf0e419 100644 --- a/docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js +++ b/docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js @@ -18,7 +18,7 @@ import { MarkGithubIcon, NoteIcon, NumberIcon, - OctofaceIcon, + SmileyIcon, PencilIcon, PersonIcon, ProjectIcon, @@ -33,6 +33,7 @@ import { } from '@primer/octicons-react' import * as primerComponents from '@primer/react' import * as drafts from '@primer/react/drafts' +import * as deprecated from '@primer/react/deprecated' import {Placeholder} from '@primer/react/Placeholder' import React from 'react' import {AnchoredOverlay} from '../../../../src/AnchoredOverlay' @@ -51,6 +52,7 @@ export default function resolveScope(metastring) { ...doctocatComponents, ...primerComponents, ...(metastring.includes('drafts') ? drafts : {}), + ...(metastring.includes('deprecated') ? deprecated : {}), ReactRouterLink, State, CheckIcon, @@ -58,7 +60,7 @@ export default function resolveScope(metastring) { ZapIcon, XIcon, DotIcon, - OctofaceIcon, + SmileyIcon, PersonIcon, MailIcon, GitCommitIcon, diff --git a/docs/src/@primer/gatsby-theme-doctocat/nav.yml b/docs/src/@primer/gatsby-theme-doctocat/nav.yml index c73fc657523..c50f7f70dd0 100644 --- a/docs/src/@primer/gatsby-theme-doctocat/nav.yml +++ b/docs/src/@primer/gatsby-theme-doctocat/nav.yml @@ -35,6 +35,10 @@ # url: /useOverlay - title: Components children: + - title: ActionList + url: /ActionList + - title: ActionMenu + url: /ActionMenu - title: Autocomplete url: /Autocomplete - title: Avatar @@ -85,6 +89,8 @@ url: /Overlay - title: Pagehead url: /Pagehead + - title: PageLayout + url: /PageLayout - title: Pagination url: /Pagination - title: PointerBox @@ -141,25 +147,27 @@ url: /drafts/LinkButton - title: IconButton url: /drafts/IconButton - - title: ActionList v2 - url: /drafts/ActionList2 - - title: ActionMenu v2 - url: /drafts/ActionMenu2 - title: Deprecated children: + - title: ActionList + url: /deprecated/ActionList + - title: ActionMenu + url: /deprecated/ActionMenu - title: BorderBox url: /deprecated/BorderBox - - title: Flex - url: /deprecated/Flex - - title: Grid - url: /deprecated/Grid - - title: Position - url: /deprecated/Position - title: Dialog url: /deprecated/Dialog - title: Dropdown url: /deprecated/Dropdown + - title: DropdownMenu + url: /deprecated/DropdownMenu + - title: Flex + url: /deprecated/Flex - title: FormGroup url: /FormGroup + - title: Grid + url: /deprecated/Grid + - title: Position + url: /deprecated/Position - title: SelectMenu url: /deprecated/SelectMenu diff --git a/package.json b/package.json index 7b38f4a2785..c09d8afcdc8 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,19 @@ "exports": { ".": { "node": "./lib/index.js", + "require": "./lib/index.js", "default": "./lib-esm/index.js" }, "./drafts": { "node": "./lib/drafts/index.js", + "require": "./lib/drafts/index.js", "default": "./lib-esm/drafts/index.js" }, + "./deprecated": { + "node": "./lib/deprecated/index.js", + "require": "./lib/deprecated/index.js", + "default": "./lib-esm/deprecated/index.js" + }, "./lib-esm/*": { "node": [ "./lib/*.js", diff --git a/src/ActionList2/ActionListContainerContext.tsx b/src/ActionList/ActionListContainerContext.tsx similarity index 100% rename from src/ActionList2/ActionListContainerContext.tsx rename to src/ActionList/ActionListContainerContext.tsx diff --git a/src/ActionList2/Description.tsx b/src/ActionList/Description.tsx similarity index 100% rename from src/ActionList2/Description.tsx rename to src/ActionList/Description.tsx diff --git a/src/ActionList/Divider.tsx b/src/ActionList/Divider.tsx index 0513b60f1ce..e286448eb42 100644 --- a/src/ActionList/Divider.tsx +++ b/src/ActionList/Divider.tsx @@ -1,25 +1,29 @@ import React from 'react' -import styled from 'styled-components' +import Box from '../Box' import {get} from '../constants' - -export const StyledDivider = styled.div` - height: 1px; - background: ${get('colors.border.muted')}; - margin-top: calc(${get('space.2')} - 1px); - margin-bottom: ${get('space.2')}; -` +import {Theme} from '../ThemeProvider' +import {SxProp, merge} from '../sx' /** * Visually separates `Item`s or `Group`s in an `ActionList`. */ -export function Divider(): JSX.Element { - return -} -/** - * `Divider` fulfills the `ItemPropsWithCustomRenderer` contract, - * so it can be used inline in an `ActionList`’s `items` prop. - * In other words, `items={[ActionList.Divider]}` is supported as a concise - * alternative to `items={[{renderItem: () => }]}`. - */ -Divider.renderItem = Divider +export const Divider: React.FC = ({sx = {}}) => { + return ( +