@dxos/react-ui-searchlist 0.8.4-main.dedc0f3 → 0.8.4-main.ead640a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/lib/browser/index.mjs +246 -131
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +246 -131
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/Combobox/Combobox.d.ts +44 -0
  8. package/dist/types/src/components/Combobox/Combobox.d.ts.map +1 -0
  9. package/dist/types/src/{composites/PopoverCombobox.stories.d.ts → components/Combobox/Combobox.stories.d.ts} +10 -2
  10. package/dist/types/src/components/Combobox/Combobox.stories.d.ts.map +1 -0
  11. package/dist/types/src/components/Combobox/index.d.ts +2 -0
  12. package/dist/types/src/components/Combobox/index.d.ts.map +1 -0
  13. package/dist/types/src/components/Listbox/Listbox.d.ts +31 -0
  14. package/dist/types/src/components/Listbox/Listbox.d.ts.map +1 -0
  15. package/dist/types/src/components/Listbox/Listbox.stories.d.ts +21 -0
  16. package/dist/types/src/components/Listbox/Listbox.stories.d.ts.map +1 -0
  17. package/dist/types/src/components/Listbox/index.d.ts +2 -0
  18. package/dist/types/src/components/Listbox/index.d.ts.map +1 -0
  19. package/dist/types/src/components/{SearchList.d.ts → SearchList/SearchList.d.ts} +7 -27
  20. package/dist/types/src/components/SearchList/SearchList.d.ts.map +1 -0
  21. package/dist/types/src/components/{SearchList.stories.d.ts → SearchList/SearchList.stories.d.ts} +9 -1
  22. package/dist/types/src/components/SearchList/SearchList.stories.d.ts.map +1 -0
  23. package/dist/types/src/components/SearchList/index.d.ts +2 -0
  24. package/dist/types/src/components/SearchList/index.d.ts.map +1 -0
  25. package/dist/types/src/components/index.d.ts +2 -0
  26. package/dist/types/src/components/index.d.ts.map +1 -1
  27. package/dist/types/src/index.d.ts +0 -1
  28. package/dist/types/src/index.d.ts.map +1 -1
  29. package/dist/types/src/translations.d.ts +3 -1
  30. package/dist/types/src/translations.d.ts.map +1 -1
  31. package/dist/types/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +16 -14
  33. package/src/components/Combobox/Combobox.stories.tsx +57 -0
  34. package/src/components/Combobox/Combobox.tsx +335 -0
  35. package/src/components/Combobox/index.ts +5 -0
  36. package/src/components/Listbox/Listbox.stories.tsx +53 -0
  37. package/src/components/Listbox/Listbox.tsx +209 -0
  38. package/src/components/Listbox/index.ts +5 -0
  39. package/src/components/{SearchList.stories.tsx → SearchList/SearchList.stories.tsx} +17 -10
  40. package/src/components/SearchList/SearchList.tsx +163 -0
  41. package/src/components/SearchList/index.ts +5 -0
  42. package/src/components/index.ts +2 -0
  43. package/src/index.ts +0 -1
  44. package/src/translations.ts +3 -1
  45. package/dist/types/src/components/SearchList.d.ts.map +0 -1
  46. package/dist/types/src/components/SearchList.stories.d.ts.map +0 -1
  47. package/dist/types/src/composites/PopoverCombobox.d.ts +0 -32
  48. package/dist/types/src/composites/PopoverCombobox.d.ts.map +0 -1
  49. package/dist/types/src/composites/PopoverCombobox.stories.d.ts.map +0 -1
  50. package/dist/types/src/composites/index.d.ts +0 -2
  51. package/dist/types/src/composites/index.d.ts.map +0 -1
  52. package/src/components/SearchList.tsx +0 -253
  53. package/src/composites/PopoverCombobox.stories.tsx +0 -49
  54. package/src/composites/PopoverCombobox.tsx +0 -209
  55. package/src/composites/index.ts +0 -5
@@ -1,253 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { createContext } from '@radix-ui/react-context';
6
- import { useControllableState } from '@radix-ui/react-use-controllable-state';
7
- import { CommandEmpty, CommandInput, CommandItem, CommandList, CommandRoot } from 'cmdk';
8
- import React, { type ComponentPropsWithRef, type PropsWithChildren, forwardRef, useCallback } from 'react';
9
-
10
- import {
11
- Button,
12
- type ButtonProps,
13
- Icon,
14
- type TextInputProps,
15
- type ThemedClassName,
16
- useDensityContext,
17
- useElevationContext,
18
- useId,
19
- useThemeContext,
20
- } from '@dxos/react-ui';
21
- import { mx, staticPlaceholderText } from '@dxos/react-ui-theme';
22
-
23
- type SearchListVariant = 'list' | 'menu' | 'listbox';
24
-
25
- type SearchListRootProps = ThemedClassName<ComponentPropsWithRef<typeof CommandRoot>> & {
26
- variant?: SearchListVariant;
27
- };
28
-
29
- type ComboboxContextValue = {
30
- isCombobox: true;
31
- modalId: string;
32
- open: boolean;
33
- onOpenChange: (nextOpen: boolean) => void;
34
- value: string;
35
- onValueChange: (nextValue: string) => void;
36
- placeholder?: string;
37
- };
38
-
39
- const COMBOBOX_NAME = 'Combobox';
40
- const COMBOBOX_TRIGGER_NAME = 'ComboboxTrigger';
41
- const SEARCHLIST_NAME = 'SearchList';
42
- const SEARCHLIST_ITEM_NAME = 'SearchListItem';
43
-
44
- const [ComboboxProvider, useComboboxContext] = createContext<Partial<ComboboxContextValue>>(COMBOBOX_NAME, {});
45
-
46
- type ComboboxRootProps = PropsWithChildren<
47
- Partial<ComboboxContextValue & { defaultOpen: boolean; defaultValue: string; placeholder: string }>
48
- >;
49
-
50
- const SearchListRoot = forwardRef<HTMLDivElement, SearchListRootProps>(
51
- ({ children, classNames, ...props }, forwardedRef) => {
52
- return (
53
- <CommandRoot {...props} className={mx('', classNames)} ref={forwardedRef}>
54
- {children}
55
- </CommandRoot>
56
- );
57
- },
58
- );
59
-
60
- SearchListRoot.displayName = SEARCHLIST_NAME;
61
-
62
- type CommandInputPrimitiveProps = ComponentPropsWithRef<typeof CommandInput>;
63
-
64
- // TODO: Harmonize with other inputs’ `onChange` prop.
65
- type SearchListInputProps = Omit<TextInputProps, 'value' | 'defaultValue' | 'onChange'> &
66
- Pick<CommandInputPrimitiveProps, 'value' | 'onValueChange' | 'defaultValue'>;
67
-
68
- const SearchListInput = forwardRef<HTMLInputElement, SearchListInputProps>(
69
- ({ children, classNames, density: propsDensity, elevation: propsElevation, variant, ...props }, forwardedRef) => {
70
- // CHORE(thure): Keep this in-sync with `TextInput`, or submit a PR for `cmdk` to support `asChild` so we don’t have to.
71
- const { hasIosKeyboard } = useThemeContext();
72
- const { tx } = useThemeContext();
73
- const density = useDensityContext(propsDensity);
74
- const elevation = useElevationContext(propsElevation);
75
-
76
- return (
77
- <CommandInput
78
- {...props}
79
- className={tx(
80
- 'input.input',
81
- 'input',
82
- {
83
- variant,
84
- disabled: props.disabled,
85
- density,
86
- elevation,
87
- },
88
- 'mbe-cardSpacingBlock',
89
- classNames,
90
- )}
91
- {...(props.autoFocus && !hasIosKeyboard && { autoFocus: true })}
92
- ref={forwardedRef}
93
- />
94
- );
95
- },
96
- );
97
-
98
- type SearchListContentProps = ThemedClassName<ComponentPropsWithRef<typeof CommandList>>;
99
-
100
- const SearchListContent = forwardRef<HTMLDivElement, SearchListContentProps>(
101
- ({ children, classNames, ...props }, forwardedRef) => {
102
- return (
103
- <CommandList {...props} className={mx(classNames)} ref={forwardedRef}>
104
- {children}
105
- </CommandList>
106
- );
107
- },
108
- );
109
-
110
- type SearchListEmptyProps = ThemedClassName<ComponentPropsWithRef<typeof CommandEmpty>>;
111
-
112
- const SearchListEmpty = forwardRef<HTMLDivElement, SearchListEmptyProps>(
113
- ({ children, classNames, ...props }, forwardedRef) => {
114
- return (
115
- <CommandEmpty {...props} className={mx(classNames)} ref={forwardedRef}>
116
- {children}
117
- </CommandEmpty>
118
- );
119
- },
120
- );
121
-
122
- type SearchListItemProps = ThemedClassName<ComponentPropsWithRef<typeof CommandItem>>;
123
-
124
- const SearchListItem = forwardRef<HTMLDivElement, SearchListItemProps>(
125
- ({ children, classNames, onSelect, ...props }, forwardedRef) => {
126
- const { onValueChange, onOpenChange } = useComboboxContext(SEARCHLIST_ITEM_NAME);
127
- const handleSelect = useCallback(
128
- (nextValue: string) => {
129
- onValueChange?.(nextValue);
130
- onOpenChange?.(false);
131
- onSelect?.(nextValue);
132
- },
133
- [onValueChange, onOpenChange, onSelect],
134
- );
135
- return (
136
- <CommandItem
137
- {...props}
138
- onSelect={handleSelect}
139
- className={mx(
140
- 'p-1 pis-2 pie-2 rounded-sm select-none cursor-pointer data-[selected]:bg-hoverOverlay',
141
- classNames,
142
- )}
143
- ref={forwardedRef}
144
- >
145
- {children}
146
- </CommandItem>
147
- );
148
- },
149
- );
150
-
151
- SearchListItem.displayName = SEARCHLIST_ITEM_NAME;
152
-
153
- const ComboboxRoot = ({
154
- modalId: propsModalId,
155
- open: propsOpen,
156
- defaultOpen,
157
- onOpenChange: propsOnOpenChange,
158
- value: propsValue,
159
- defaultValue,
160
- onValueChange: propsOnValueChange,
161
- placeholder,
162
- children,
163
- }: ComboboxRootProps) => {
164
- const modalId = useId(COMBOBOX_NAME, propsModalId);
165
- const [open = false, onOpenChange] = useControllableState({
166
- prop: propsOpen,
167
- onChange: propsOnOpenChange,
168
- defaultProp: defaultOpen,
169
- });
170
- const [value = '', onValueChange] = useControllableState({
171
- prop: propsValue,
172
- onChange: propsOnValueChange,
173
- defaultProp: defaultValue,
174
- });
175
- return (
176
- <ComboboxProvider
177
- isCombobox
178
- modalId={modalId}
179
- open={open}
180
- onOpenChange={onOpenChange}
181
- value={value}
182
- onValueChange={onValueChange}
183
- placeholder={placeholder}
184
- >
185
- {children}
186
- </ComboboxProvider>
187
- );
188
- };
189
-
190
- ComboboxRoot.displayName = COMBOBOX_NAME;
191
-
192
- type ComboboxTriggerProps = ButtonProps;
193
-
194
- const ComboboxTrigger = forwardRef<HTMLButtonElement, ComboboxTriggerProps>(
195
- ({ children, onClick, ...props }, forwardedRef) => {
196
- const { modalId, open, onOpenChange, placeholder, value } = useComboboxContext(COMBOBOX_TRIGGER_NAME);
197
- const handleClick = useCallback(
198
- (event: Parameters<Exclude<ButtonProps['onClick'], undefined>>[0]) => {
199
- onClick?.(event);
200
- onOpenChange?.(true);
201
- },
202
- [onClick, onOpenChange],
203
- );
204
- return (
205
- <Button
206
- {...props}
207
- role='combobox'
208
- aria-expanded={open}
209
- aria-controls={modalId}
210
- aria-haspopup='dialog'
211
- onClick={handleClick}
212
- ref={forwardedRef}
213
- >
214
- {children ?? (
215
- <>
216
- <span
217
- className={mx('font-normal text-start flex-1 min-is-0 truncate mie-2', !value && staticPlaceholderText)}
218
- >
219
- {value || placeholder}
220
- </span>
221
- <Icon icon='ph--caret-down--bold' size={3} />
222
- </>
223
- )}
224
- </Button>
225
- );
226
- },
227
- );
228
-
229
- ComboboxTrigger.displayName = COMBOBOX_TRIGGER_NAME;
230
-
231
- export const SearchList = {
232
- Root: SearchListRoot,
233
- Input: SearchListInput,
234
- Content: SearchListContent,
235
- Empty: SearchListEmpty,
236
- Item: SearchListItem,
237
- };
238
-
239
- export const Combobox = {
240
- Root: ComboboxRoot,
241
- Trigger: ComboboxTrigger,
242
- useComboboxContext,
243
- };
244
-
245
- export type {
246
- SearchListRootProps,
247
- SearchListInputProps,
248
- SearchListContentProps,
249
- SearchListEmptyProps,
250
- SearchListItemProps,
251
- ComboboxRootProps,
252
- ComboboxTriggerProps,
253
- };
@@ -1,49 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import '@dxos-theme';
6
-
7
- import { type Meta, type StoryObj } from '@storybook/react-vite';
8
- import React from 'react';
9
-
10
- import { faker } from '@dxos/random';
11
- import { withTheme } from '@dxos/storybook-utils';
12
-
13
- import { PopoverCombobox } from './PopoverCombobox';
14
-
15
- faker.seed(1234);
16
-
17
- const storybookItems = faker.helpers.uniqueArray(faker.commerce.productName, 16);
18
-
19
- const DefaultStory = () => {
20
- return (
21
- <PopoverCombobox.Root placeholder='Nothing selected'>
22
- <PopoverCombobox.Trigger />
23
- <PopoverCombobox.Content filter={(value, search) => (value.includes(search) ? 1 : 0)}>
24
- <PopoverCombobox.Input placeholder='Search...' />
25
- <PopoverCombobox.List>
26
- {storybookItems.map((value) => (
27
- <PopoverCombobox.Item key={value}>{value}</PopoverCombobox.Item>
28
- ))}
29
- </PopoverCombobox.List>
30
- <PopoverCombobox.Arrow />
31
- </PopoverCombobox.Content>
32
- </PopoverCombobox.Root>
33
- );
34
- };
35
-
36
- const meta = {
37
- title: 'ui/react-ui-searchlist/PopoverCombobox',
38
- component: PopoverCombobox.Root as any,
39
- render: DefaultStory,
40
- decorators: [withTheme],
41
- } satisfies Meta<typeof DefaultStory>;
42
-
43
- export default meta;
44
-
45
- type Story = StoryObj<typeof meta>;
46
-
47
- export const Default: Story = {
48
- args: {},
49
- };
@@ -1,209 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { useControllableState } from '@radix-ui/react-use-controllable-state';
6
- import React, { forwardRef } from 'react';
7
-
8
- import {
9
- Popover,
10
- type PopoverArrowProps,
11
- type PopoverContentProps,
12
- type PopoverVirtualTriggerProps,
13
- } from '@dxos/react-ui';
14
-
15
- import {
16
- Combobox,
17
- type ComboboxRootProps,
18
- type ComboboxTriggerProps,
19
- SearchList,
20
- type SearchListContentProps,
21
- type SearchListEmptyProps,
22
- type SearchListInputProps,
23
- type SearchListItemProps,
24
- type SearchListRootProps,
25
- } from '../components';
26
-
27
- type PopoverComboboxRootProps = ComboboxRootProps & { modal?: boolean };
28
-
29
- const PopoverComboboxRoot = ({
30
- modal,
31
- children,
32
- open: propsOpen,
33
- onOpenChange: propsOnOpenChange,
34
- defaultOpen,
35
- ...props
36
- }: PopoverComboboxRootProps) => {
37
- const [open, onOpenChange] = useControllableState({
38
- prop: propsOpen,
39
- onChange: propsOnOpenChange,
40
- defaultProp: defaultOpen,
41
- });
42
- return (
43
- <Combobox.Root open={open} onOpenChange={onOpenChange} {...props}>
44
- <Popover.Root open={open} onOpenChange={onOpenChange} modal={modal}>
45
- {children}
46
- </Popover.Root>
47
- </Combobox.Root>
48
- );
49
- };
50
-
51
- type PopoverComboboxContentProps = SearchListRootProps & PopoverContentProps;
52
-
53
- const POPOVER_COMBOBOX_CONTENT_NAME = 'PopoverComboboxContent';
54
-
55
- const PopoverComboboxContent = forwardRef<HTMLDivElement, PopoverComboboxContentProps>(
56
- (
57
- {
58
- side = 'bottom',
59
- collisionPadding = 48,
60
- sideOffset,
61
- align,
62
- alignOffset,
63
- avoidCollisions,
64
- collisionBoundary,
65
- arrowPadding,
66
- sticky,
67
- hideWhenDetached,
68
- onOpenAutoFocus,
69
- onCloseAutoFocus,
70
- onEscapeKeyDown,
71
- onPointerDownOutside,
72
- onFocusOutside,
73
- onInteractOutside,
74
- forceMount,
75
- children,
76
- classNames,
77
- ...props
78
- },
79
- forwardedRef,
80
- ) => {
81
- const { modalId } = Combobox.useComboboxContext(POPOVER_COMBOBOX_CONTENT_NAME);
82
- return (
83
- <Popover.Content
84
- {...{
85
- side,
86
- sideOffset,
87
- align,
88
- alignOffset,
89
- avoidCollisions,
90
- collisionBoundary,
91
- collisionPadding,
92
- arrowPadding,
93
- sticky,
94
- hideWhenDetached,
95
- onOpenAutoFocus,
96
- onCloseAutoFocus,
97
- onEscapeKeyDown,
98
- onPointerDownOutside,
99
- onFocusOutside,
100
- onInteractOutside,
101
- forceMount,
102
- }}
103
- classNames={[
104
- 'is-[--radix-popover-trigger-width] max-bs-[--radix-popover-content-available-height] grid grid-rows-[min-content_1fr] overflow-hidden',
105
- classNames,
106
- ]}
107
- id={modalId}
108
- ref={forwardedRef}
109
- >
110
- <SearchList.Root {...props} classNames='contents density-fine' role='none'>
111
- {children}
112
- </SearchList.Root>
113
- </Popover.Content>
114
- );
115
- },
116
- );
117
-
118
- PopoverComboboxContent.displayName = POPOVER_COMBOBOX_CONTENT_NAME;
119
-
120
- type PopoverComboboxTriggerProps = ComboboxTriggerProps;
121
-
122
- const PopoverComboboxTrigger = forwardRef<HTMLButtonElement, PopoverComboboxTriggerProps>((props, forwardedRef) => {
123
- return (
124
- <Popover.Trigger asChild>
125
- <Combobox.Trigger {...props} ref={forwardedRef} />
126
- </Popover.Trigger>
127
- );
128
- });
129
-
130
- type PopoverComboboxVirtualTriggerProps = PopoverVirtualTriggerProps;
131
-
132
- const PopoverComboboxVirtualTrigger = Popover.VirtualTrigger;
133
-
134
- type PopoverComboboxInputProps = SearchListInputProps;
135
-
136
- const PopoverComboboxInput = forwardRef<HTMLInputElement, PopoverComboboxInputProps>(
137
- ({ classNames, ...props }, forwardedRef) => {
138
- return (
139
- <SearchList.Input
140
- {...props}
141
- classNames={[
142
- 'mli-cardSpacingChrome mbs-cardSpacingChrome mbe-0 is-[calc(100%-2*var(--dx-cardSpacingChrome))]',
143
- classNames,
144
- ]}
145
- ref={forwardedRef}
146
- />
147
- );
148
- },
149
- );
150
-
151
- type PopoverComboboxListProps = SearchListContentProps;
152
-
153
- const PopoverComboboxList = forwardRef<HTMLDivElement, PopoverComboboxListProps>(
154
- ({ classNames, ...props }, forwardedRef) => {
155
- return (
156
- <SearchList.Content
157
- {...props}
158
- classNames={['min-bs-0 overflow-y-auto plb-cardSpacingChrome', classNames]}
159
- ref={forwardedRef}
160
- />
161
- );
162
- },
163
- );
164
-
165
- type PopoverComboboxItemProps = SearchListItemProps;
166
-
167
- const PopoverComboboxItem = forwardRef<HTMLDivElement, PopoverComboboxItemProps>(
168
- ({ classNames, ...props }, forwardedRef) => {
169
- return (
170
- <SearchList.Item
171
- {...props}
172
- classNames={['mli-cardSpacingChrome pli-cardSpacingChrome', classNames]}
173
- ref={forwardedRef}
174
- />
175
- );
176
- },
177
- );
178
-
179
- type PopoverComboboxArrowProps = PopoverArrowProps;
180
-
181
- const PopoverComboboxArrow = Popover.Arrow;
182
-
183
- type PopoverComboboxEmptyProps = SearchListEmptyProps;
184
-
185
- const PopoverComboboxEmpty = SearchList.Empty;
186
-
187
- export const PopoverCombobox = {
188
- Root: PopoverComboboxRoot,
189
- Content: PopoverComboboxContent,
190
- Trigger: PopoverComboboxTrigger,
191
- VirtualTrigger: PopoverComboboxVirtualTrigger,
192
- Input: PopoverComboboxInput,
193
- List: PopoverComboboxList,
194
- Item: PopoverComboboxItem,
195
- Arrow: PopoverComboboxArrow,
196
- Empty: PopoverComboboxEmpty,
197
- };
198
-
199
- export type {
200
- PopoverComboboxRootProps,
201
- PopoverComboboxContentProps,
202
- PopoverComboboxTriggerProps,
203
- PopoverComboboxVirtualTriggerProps,
204
- PopoverComboboxInputProps,
205
- PopoverComboboxListProps,
206
- PopoverComboboxItemProps,
207
- PopoverComboboxArrowProps,
208
- PopoverComboboxEmptyProps,
209
- };
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export * from './PopoverCombobox';