From 99df32d006a75f7000e57e3b9a4eedd18804ea7f Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 17 Aug 2023 09:54:56 -0500 Subject: [PATCH] wip --- docs/pages/components/Combobox.mdx | 75 ++++++++ docs/pages/components/Listbox.mdx | 170 +++++++++++++++++ .../src/components/Combobox/Combobox.tsx | 132 +++++++++++++ .../src/components/Combobox/ComboboxGroup.tsx | 29 +++ .../src/components/Combobox/ComboboxItem.tsx | 44 +++++ .../react/src/components/Combobox/index.ts | 3 + .../react/src/components/Listbox/Listbox.tsx | 180 ++++++++++++++++++ .../src/components/Listbox/ListboxContext.tsx | 59 ++++++ .../src/components/Listbox/ListboxGroup.tsx | 37 ++++ .../src/components/Listbox/ListboxOption.tsx | 111 +++++++++++ .../react/src/components/Listbox/index.ts | 4 + packages/react/src/index.ts | 10 + packages/styles/combobox.css | 107 +++++++++++ packages/styles/forms.css | 19 +- packages/styles/index.css | 1 + 15 files changed, 972 insertions(+), 9 deletions(-) create mode 100644 docs/pages/components/Combobox.mdx create mode 100644 docs/pages/components/Listbox.mdx create mode 100644 packages/react/src/components/Combobox/Combobox.tsx create mode 100644 packages/react/src/components/Combobox/ComboboxGroup.tsx create mode 100644 packages/react/src/components/Combobox/ComboboxItem.tsx create mode 100644 packages/react/src/components/Combobox/index.ts create mode 100644 packages/react/src/components/Listbox/Listbox.tsx create mode 100644 packages/react/src/components/Listbox/ListboxContext.tsx create mode 100644 packages/react/src/components/Listbox/ListboxGroup.tsx create mode 100644 packages/react/src/components/Listbox/ListboxOption.tsx create mode 100644 packages/react/src/components/Listbox/index.ts create mode 100644 packages/styles/combobox.css diff --git a/docs/pages/components/Combobox.mdx b/docs/pages/components/Combobox.mdx new file mode 100644 index 000000000..f21caa44d --- /dev/null +++ b/docs/pages/components/Combobox.mdx @@ -0,0 +1,75 @@ +--- +title: Combobox +description: An input component to display a list of suggested options matching the current text input. +source: https://github.com/dequelabs/cauldron/tree/develop/packages/react/src/components/Combobox/Combobox.tsx +--- + +import { Combobox, ComboboxItem, ComboboxGroup } from '@deque/cauldron-react' + +```js +import { + Combobox, + ComboboxItem, + ComboboxGroup +} from '@deque/cauldron-react' +``` + +## Examples + +## With Items + +```jsx example +function ComboboxWithItemPropExample() { + const items = [ + { label: 'Red', value: 'Red' }, + { label: 'Orange', value: 'Orange' }, + { label: 'Yellow', value: 'Yellow' }, + { label: 'Green', value: 'Green' }, + { label: 'Blue', value: 'Blue' } + ] + return ( + + ) +} +``` + +## With Children + +```jsx example + + 🍎 Apple + 🍌 Banana + 🥒 Cucumber + 🍊 Orange + 🍑 Peach + 🍐 Pear + +``` + +## Grouping + +```jsx example + + + Canada + Mexico + United States + + + Argentina + Bolivia + Brazil + Chile + Columbia + Ecuador + Falkland Islands + French Guiana + Guyana + Paraguay + Peru + Suriname + Uruguay + Venezuela + + +``` \ No newline at end of file diff --git a/docs/pages/components/Listbox.mdx b/docs/pages/components/Listbox.mdx new file mode 100644 index 000000000..d99083033 --- /dev/null +++ b/docs/pages/components/Listbox.mdx @@ -0,0 +1,170 @@ +--- +title: Listbox +description: An unstyled component to provide a keyboard navigable list of options. +source: https://github.com/dequelabs/cauldron/tree/develop/packages/react/src/components/Listbox/Listbox.tsx +--- + +import { Listbox, ListboxOption, ListboxGroup } from '@deque/cauldron-react'; + +```js +import { + Listbox, + ListboxOption, + ListboxGroup +} from '@deque/cauldron-react'; +``` + +## Examples + + + Listbox follows [aria practices](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/) for _Listbox_ but is not currently intended to be used by itself. This component's intended usage is to be composed with components that have keyboard navigable items like [Combobox](./Combobox) and [OptionsMenu](./OptionsMenu). + + +### Listbox Options + +A listbox can contain a list of options with optional values. + +```jsx example +<> +
Numbers
+ + One + Two + Three + + +``` + +### Disabled Options + +A listbox option can be optionally disabled. + +```jsx example +<> +
Numbers, but two is disabled
+ + One + Two + Three + + +``` + +### Grouped Options + +Listbox options can also be grouped into categories. + +```jsx example +<> +
Colors and Numbers
+ + + Red + Green + Blue + + + One + Two + Three + + + +``` + +### Keyboard Navigation + +By default, keyboard navigation will stop at the first or last option of the list. To wrap around focus to the beginning or the end of the list, `navigation="cycle"` can be set to enable this behavior. + +```jsx example +<> +
Numbers that Cycle
+ + One + Two + Three + + +``` + +### Controlled + +```jsx example +<> +
Controlled Listbox
+ + One + Two + Three + + +``` + +### Uncontrolled + +```jsx example +<> +
Uncontrolled Listbox
+ + One + Two + Three + + +``` + +## Props + +### Listbox + + + +### ListboxOption + + \ No newline at end of file diff --git a/packages/react/src/components/Combobox/Combobox.tsx b/packages/react/src/components/Combobox/Combobox.tsx new file mode 100644 index 000000000..65f809ee0 --- /dev/null +++ b/packages/react/src/components/Combobox/Combobox.tsx @@ -0,0 +1,132 @@ +import React, { + forwardRef, + useState, + useEffect, + useRef, + useCallback +} from 'react'; +import classnames from 'classnames'; +import { useId } from 'react-id-generator'; +import { ContentNode } from '../../types'; +import Listbox from '../Listbox'; +import ComboboxItem from './ComboboxItem'; + +interface ComboboxItem