paris 0.17.9 → 0.18.0
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.
- package/CHANGELOG.md +16 -0
- package/package.json +139 -150
- package/src/helpers/renderEnhancer.tsx +4 -5
- package/src/helpers/useResizeObserver.ts +17 -23
- package/src/pages/_document.tsx +1 -3
- package/src/pages/index.tsx +8 -24
- package/src/stories/Pagination.mdx +1 -1
- package/src/stories/Tokens.mdx +1 -1
- package/src/stories/Welcome.mdx +1 -1
- package/src/stories/accordion/Accordion.stories.ts +1 -1
- package/src/stories/accordion/Accordion.tsx +14 -35
- package/src/stories/accordionselect/AccordionSelect.stories.ts +2 -5
- package/src/stories/accordionselect/AccordionSelect.tsx +26 -50
- package/src/stories/avatar/Avatar.stories.ts +1 -1
- package/src/stories/avatar/Avatar.tsx +14 -13
- package/src/stories/button/Button.stories.ts +18 -15
- package/src/stories/button/Button.tsx +44 -48
- package/src/stories/callout/Callout.stories.ts +3 -7
- package/src/stories/callout/Callout.tsx +4 -8
- package/src/stories/card/Card.stories.ts +1 -1
- package/src/stories/card/Card.tsx +4 -11
- package/src/stories/cardbutton/CardButton.stories.tsx +1 -1
- package/src/stories/cardbutton/CardButton.tsx +16 -18
- package/src/stories/checkbox/Checkbox.stories.ts +1 -1
- package/src/stories/checkbox/Checkbox.tsx +37 -49
- package/src/stories/combobox/Combobox.stories.ts +65 -71
- package/src/stories/combobox/Combobox.tsx +80 -89
- package/src/stories/dialog/Dialog.stories.tsx +2 -2
- package/src/stories/dialog/Dialog.tsx +45 -68
- package/src/stories/drawer/Drawer.stories.tsx +63 -105
- package/src/stories/drawer/Drawer.tsx +93 -90
- package/src/stories/field/Field.stories.ts +1 -1
- package/src/stories/field/Field.tsx +25 -30
- package/src/stories/icon/Ellipsis.tsx +4 -1
- package/src/stories/icon/Icon.stories.ts +2 -2
- package/src/stories/icon/Icon.tsx +16 -26
- package/src/stories/icon/Info.tsx +4 -1
- package/src/stories/icon/Spinner.tsx +4 -2
- package/src/stories/icon/index.ts +6 -6
- package/src/stories/informationaltooltip/InformationalTooltip.stories.tsx +12 -11
- package/src/stories/informationaltooltip/InformationalTooltip.tsx +23 -28
- package/src/stories/input/Input.stories.ts +14 -15
- package/src/stories/input/Input.tsx +119 -95
- package/src/stories/markdown/Markdown.module.scss +384 -0
- package/src/stories/markdown/Markdown.stories.ts +203 -0
- package/src/stories/markdown/Markdown.tsx +293 -0
- package/src/stories/markdown/index.ts +1 -0
- package/src/stories/menu/Menu.module.scss +9 -0
- package/src/stories/menu/Menu.stories.tsx +4 -10
- package/src/stories/menu/Menu.tsx +27 -29
- package/src/stories/pagination/usePagination.ts +8 -8
- package/src/stories/popover/Popover.stories.ts +2 -2
- package/src/stories/popover/Popover.tsx +4 -10
- package/src/stories/select/Select.stories.ts +10 -10
- package/src/stories/select/Select.tsx +268 -240
- package/src/stories/styledlink/StyledLink.stories.ts +1 -1
- package/src/stories/styledlink/StyledLink.tsx +11 -17
- package/src/stories/table/Table.stories.ts +1 -1
- package/src/stories/table/Table.tsx +55 -65
- package/src/stories/tabs/Tabs.stories.tsx +2 -2
- package/src/stories/tabs/Tabs.tsx +15 -21
- package/src/stories/tag/Tag.stories.ts +1 -4
- package/src/stories/tag/Tag.tsx +9 -17
- package/src/stories/text/Text.stories.ts +1 -1
- package/src/stories/text/Text.tsx +49 -31
- package/src/stories/text/Typography.module.css +120 -120
- package/src/stories/textarea/TextArea.stories.ts +2 -5
- package/src/stories/textarea/TextArea.tsx +91 -84
- package/src/stories/theme/index.ts +1 -1
- package/src/stories/theme/themes.ts +423 -424
- package/src/stories/theme/tokens.ts +3 -3
- package/src/stories/theme/tw-preflight.css +4 -3
- package/src/stories/tilt/Tilt.stories.tsx +3 -6
- package/src/stories/tilt/Tilt.tsx +160 -126
- package/src/stories/toast/Toast.stories.tsx +2 -2
- package/src/stories/toast/Toast.tsx +3 -6
- package/src/stories/utility/RemoveFromDOM.tsx +9 -13
- package/src/stories/utility/TextWhenString.tsx +3 -16
- package/src/stories/utility/VisuallyHidden.tsx +10 -17
- package/src/styles/Home.module.css +185 -195
- package/src/styles/globals.css +0 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useId } from 'react';
|
|
1
|
+
import { Switch } from '@headlessui/react';
|
|
3
2
|
import * as RadixCheckbox from '@radix-ui/react-checkbox';
|
|
4
3
|
import { clsx } from 'clsx';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import { TextWhenString, VisuallyHidden } from '../utility';
|
|
4
|
+
import type { FC, ReactNode } from 'react';
|
|
5
|
+
import { useId } from 'react';
|
|
8
6
|
import { Check, Icon } from '../icon';
|
|
7
|
+
import { TextWhenString, VisuallyHidden } from '../utility';
|
|
8
|
+
import styles from './Checkbox.module.scss';
|
|
9
9
|
|
|
10
10
|
export type CheckboxProps = {
|
|
11
11
|
/** The visual style of the Checkbox. `default` is a standard checkbox with a label next to it, `surface` is a clickable card that displays a check when selected, `panel` is a clickable card with the checkbox aligned right, `switch` is a switch toggle. */
|
|
@@ -24,17 +24,17 @@ export type CheckboxProps = {
|
|
|
24
24
|
} & Omit<React.ComponentPropsWithoutRef<'label'>, 'onChange' | 'children'>;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* A Checkbox component.
|
|
28
|
-
*
|
|
29
|
-
* <hr />
|
|
30
|
-
*
|
|
31
|
-
* To use this component, import it as follows:
|
|
32
|
-
*
|
|
33
|
-
* ```js
|
|
34
|
-
* import { Checkbox } from 'paris/checkbox';
|
|
35
|
-
* ```
|
|
36
|
-
* @constructor
|
|
37
|
-
*/
|
|
27
|
+
* A Checkbox component.
|
|
28
|
+
*
|
|
29
|
+
* <hr />
|
|
30
|
+
*
|
|
31
|
+
* To use this component, import it as follows:
|
|
32
|
+
*
|
|
33
|
+
* ```js
|
|
34
|
+
* import { Checkbox } from 'paris/checkbox';
|
|
35
|
+
* ```
|
|
36
|
+
* @constructor
|
|
37
|
+
*/
|
|
38
38
|
export const Checkbox: FC<CheckboxProps> = ({
|
|
39
39
|
kind = 'default',
|
|
40
40
|
checked,
|
|
@@ -62,14 +62,18 @@ export const Checkbox: FC<CheckboxProps> = ({
|
|
|
62
62
|
aria-details={typeof children === 'string' ? children : undefined}
|
|
63
63
|
>
|
|
64
64
|
{(kind === 'surface' || kind === 'panel') && (
|
|
65
|
-
<TextWhenString kind="paragraphXSmall">
|
|
66
|
-
{children}
|
|
67
|
-
</TextWhenString>
|
|
65
|
+
<TextWhenString kind="paragraphXSmall">{children}</TextWhenString>
|
|
68
66
|
)}
|
|
69
67
|
{kind === 'panel' && <div className={styles.box} />}
|
|
70
68
|
<RadixCheckbox.Indicator className={styles.indicator}>
|
|
71
69
|
{(kind === 'default' || kind === 'panel') && (
|
|
72
|
-
<svg
|
|
70
|
+
<svg
|
|
71
|
+
width={14}
|
|
72
|
+
height={14}
|
|
73
|
+
viewBox="0 0 14 14"
|
|
74
|
+
fill="none"
|
|
75
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
76
|
+
>
|
|
73
77
|
<path
|
|
74
78
|
className={styles.checkSvg}
|
|
75
79
|
data-disabled={disabled}
|
|
@@ -78,43 +82,27 @@ export const Checkbox: FC<CheckboxProps> = ({
|
|
|
78
82
|
</svg>
|
|
79
83
|
)}
|
|
80
84
|
{kind === 'surface' && (
|
|
81
|
-
<Icon
|
|
82
|
-
icon={Check}
|
|
83
|
-
size={12.8}
|
|
84
|
-
data-disabled={disabled}
|
|
85
|
-
className={styles.checkIcon}
|
|
86
|
-
/>
|
|
85
|
+
<Icon icon={Check} size={12.8} data-disabled={disabled} className={styles.checkIcon} />
|
|
87
86
|
)}
|
|
88
87
|
</RadixCheckbox.Indicator>
|
|
89
88
|
</RadixCheckbox.Root>
|
|
90
89
|
)}
|
|
91
90
|
{kind === 'switch' && (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
aria-hidden="true"
|
|
103
|
-
className={clsx(styles.knob, checked && styles.knobChecked)}
|
|
104
|
-
/>
|
|
105
|
-
</Switch>
|
|
106
|
-
</>
|
|
91
|
+
<Switch
|
|
92
|
+
checked={checked}
|
|
93
|
+
onChange={onChange}
|
|
94
|
+
className={styles.switchContainer}
|
|
95
|
+
data-disabled={disabled}
|
|
96
|
+
id={inputID}
|
|
97
|
+
aria-details={typeof children === 'string' ? children : undefined}
|
|
98
|
+
>
|
|
99
|
+
<span aria-hidden="true" className={clsx(styles.knob, checked && styles.knobChecked)} />
|
|
100
|
+
</Switch>
|
|
107
101
|
)}
|
|
108
102
|
{(kind === 'default' || kind === 'switch') && !hideLabel && (
|
|
109
|
-
<TextWhenString kind="paragraphXSmall">
|
|
110
|
-
{children}
|
|
111
|
-
</TextWhenString>
|
|
112
|
-
)}
|
|
113
|
-
{hideLabel && (
|
|
114
|
-
<VisuallyHidden>
|
|
115
|
-
{children}
|
|
116
|
-
</VisuallyHidden>
|
|
103
|
+
<TextWhenString kind="paragraphXSmall">{children}</TextWhenString>
|
|
117
104
|
)}
|
|
105
|
+
{hideLabel && <VisuallyHidden>{children}</VisuallyHidden>}
|
|
118
106
|
</label>
|
|
119
107
|
);
|
|
120
108
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/nextjs-vite';
|
|
2
2
|
import { createElement, useState } from 'react';
|
|
3
|
+
import { Text } from '../text';
|
|
3
4
|
import type { ComboboxProps, Option } from './Combobox';
|
|
4
5
|
import { Combobox } from './Combobox';
|
|
5
|
-
import { Text } from '../text';
|
|
6
6
|
|
|
7
7
|
const meta: Meta<typeof Combobox> = {
|
|
8
8
|
title: 'Inputs/Combobox',
|
|
@@ -97,9 +97,7 @@ const ComboboxArgs2: ComboboxProps<{ name: string }> = {
|
|
|
97
97
|
export const Default: Story = {
|
|
98
98
|
args: ComboboxArgs,
|
|
99
99
|
render: function Render(args) {
|
|
100
|
-
const [selected, setSelected] = useState<Option<{ name: string }> | null>(
|
|
101
|
-
null,
|
|
102
|
-
);
|
|
100
|
+
const [selected, setSelected] = useState<Option<{ name: string }> | null>(null);
|
|
103
101
|
const [inputValue, setInputValue] = useState<string>('');
|
|
104
102
|
return createElement(
|
|
105
103
|
'div',
|
|
@@ -109,18 +107,18 @@ export const Default: Story = {
|
|
|
109
107
|
createElement(Combobox<{ name: string }>, {
|
|
110
108
|
...args,
|
|
111
109
|
value:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
options: (args.options as Option<{ name: string }>[]).filter((o) =>
|
|
122
|
-
.toLowerCase()
|
|
123
|
-
|
|
110
|
+
selected?.id === null
|
|
111
|
+
? {
|
|
112
|
+
id: null,
|
|
113
|
+
node: inputValue,
|
|
114
|
+
metadata: {
|
|
115
|
+
name: inputValue,
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
: (selected as Option<{ name: string }> | null),
|
|
119
|
+
options: (args.options as Option<{ name: string }>[]).filter((o) =>
|
|
120
|
+
((o.metadata?.name as string) || '').toLowerCase().includes(inputValue.toLowerCase()),
|
|
121
|
+
),
|
|
124
122
|
onChange: (e) => setSelected(e),
|
|
125
123
|
onInputChange: (e) => setInputValue(e),
|
|
126
124
|
}),
|
|
@@ -145,18 +143,18 @@ export const AllowCustomValue: Story = {
|
|
|
145
143
|
createElement(Combobox<{ name: string }>, {
|
|
146
144
|
...args,
|
|
147
145
|
value:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
options: (args.options as Option<{ name: string }>[]).filter((o) =>
|
|
158
|
-
.toLowerCase()
|
|
159
|
-
|
|
146
|
+
selected?.id === null
|
|
147
|
+
? {
|
|
148
|
+
id: null,
|
|
149
|
+
node: inputValue,
|
|
150
|
+
metadata: {
|
|
151
|
+
name: inputValue,
|
|
152
|
+
},
|
|
153
|
+
}
|
|
154
|
+
: (selected as Option<{ name: string }> | null),
|
|
155
|
+
options: (args.options as Option<{ name: string }>[]).filter((o) =>
|
|
156
|
+
((o.metadata?.name as string) || '').toLowerCase().includes(inputValue.toLowerCase()),
|
|
157
|
+
),
|
|
160
158
|
onChange: (e) => setSelected(e),
|
|
161
159
|
onInputChange: (e) => setInputValue(e),
|
|
162
160
|
}),
|
|
@@ -181,18 +179,18 @@ export const CustomValueWithDivider: Story = {
|
|
|
181
179
|
createElement(Combobox<{ name: string }>, {
|
|
182
180
|
...args,
|
|
183
181
|
value:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
options: (args.options as Option<{ name: string }>[]).filter((o) =>
|
|
194
|
-
.toLowerCase()
|
|
195
|
-
|
|
182
|
+
selected?.id === null
|
|
183
|
+
? {
|
|
184
|
+
id: null,
|
|
185
|
+
node: inputValue,
|
|
186
|
+
metadata: {
|
|
187
|
+
name: inputValue,
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
: (selected as Option<{ name: string }> | null),
|
|
191
|
+
options: (args.options as Option<{ name: string }>[]).filter((o) =>
|
|
192
|
+
((o.metadata?.name as string) || '').toLowerCase().includes(inputValue.toLowerCase()),
|
|
193
|
+
),
|
|
196
194
|
onChange: (e) => setSelected(e),
|
|
197
195
|
onInputChange: (e) => setInputValue(e),
|
|
198
196
|
overrides: {
|
|
@@ -208,9 +206,7 @@ export const CustomValueWithDivider: Story = {
|
|
|
208
206
|
export const HideOptionsInitially: Story = {
|
|
209
207
|
args: ComboboxArgs,
|
|
210
208
|
render: function Render(args) {
|
|
211
|
-
const [selected, setSelected] = useState<Option<{ name: string }> | null>(
|
|
212
|
-
null,
|
|
213
|
-
);
|
|
209
|
+
const [selected, setSelected] = useState<Option<{ name: string }> | null>(null);
|
|
214
210
|
const [inputValue, setInputValue] = useState<string>('');
|
|
215
211
|
return createElement(
|
|
216
212
|
'div',
|
|
@@ -220,18 +216,18 @@ export const HideOptionsInitially: Story = {
|
|
|
220
216
|
createElement(Combobox<{ name: string }>, {
|
|
221
217
|
...args,
|
|
222
218
|
value:
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
options: (args.options as Option<{ name: string }>[]).filter((o) =>
|
|
233
|
-
.toLowerCase()
|
|
234
|
-
|
|
219
|
+
selected?.id === null
|
|
220
|
+
? {
|
|
221
|
+
id: null,
|
|
222
|
+
node: inputValue,
|
|
223
|
+
metadata: {
|
|
224
|
+
name: inputValue,
|
|
225
|
+
},
|
|
226
|
+
}
|
|
227
|
+
: (selected as Option<{ name: string }> | null),
|
|
228
|
+
options: (args.options as Option<{ name: string }>[]).filter((o) =>
|
|
229
|
+
((o.metadata?.name as string) || '').toLowerCase().includes(inputValue.toLowerCase()),
|
|
230
|
+
),
|
|
235
231
|
onChange: (e) => setSelected(e),
|
|
236
232
|
onInputChange: (e) => setInputValue(e),
|
|
237
233
|
hideOptionsInitially: true,
|
|
@@ -243,9 +239,7 @@ export const HideOptionsInitially: Story = {
|
|
|
243
239
|
export const HideClearButton: Story = {
|
|
244
240
|
args: ComboboxArgs2,
|
|
245
241
|
render: function Render(args) {
|
|
246
|
-
const [selected, setSelected] = useState<Option<{ name: string }> | null>(
|
|
247
|
-
null,
|
|
248
|
-
);
|
|
242
|
+
const [selected, setSelected] = useState<Option<{ name: string }> | null>(null);
|
|
249
243
|
const [inputValue, setInputValue] = useState<string>('');
|
|
250
244
|
return createElement(
|
|
251
245
|
'div',
|
|
@@ -255,18 +249,18 @@ export const HideClearButton: Story = {
|
|
|
255
249
|
createElement(Combobox<{ name: string }>, {
|
|
256
250
|
...args,
|
|
257
251
|
value:
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
options: (args.options as Option<{ name: string }>[]).filter((o) =>
|
|
268
|
-
.toLowerCase()
|
|
269
|
-
|
|
252
|
+
selected?.id === null
|
|
253
|
+
? {
|
|
254
|
+
id: null,
|
|
255
|
+
node: inputValue,
|
|
256
|
+
metadata: {
|
|
257
|
+
name: inputValue,
|
|
258
|
+
},
|
|
259
|
+
}
|
|
260
|
+
: (selected as Option<{ name: string }> | null),
|
|
261
|
+
options: (args.options as Option<{ name: string }>[]).filter((o) =>
|
|
262
|
+
((o.metadata?.name as string) || '').toLowerCase().includes(inputValue.toLowerCase()),
|
|
263
|
+
),
|
|
270
264
|
onChange: (e) => setSelected(e),
|
|
271
265
|
onInputChange: (e) => setInputValue(e),
|
|
272
266
|
hideClearButton: true,
|
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import type { ComponentPropsWithoutRef, CSSProperties, ReactNode } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
useMemo, useId, useState,
|
|
6
|
-
} from 'react';
|
|
7
|
-
import {
|
|
8
|
-
Combobox as HCombobox, ComboboxInput, ComboboxOptions, ComboboxOption, Transition,
|
|
9
|
-
} from '@headlessui/react';
|
|
10
|
-
import { clsx } from 'clsx';
|
|
11
|
-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
12
3
|
import { faClose } from '@fortawesome/free-solid-svg-icons';
|
|
4
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
5
|
+
import { ComboboxInput, ComboboxOption, ComboboxOptions, Combobox as HCombobox, Transition } from '@headlessui/react';
|
|
6
|
+
import { clsx } from 'clsx';
|
|
7
|
+
import type { ComponentPropsWithoutRef, CSSProperties, ReactNode } from 'react';
|
|
8
|
+
import { useId, useMemo, useState } from 'react';
|
|
9
|
+
import { MemoizedEnhancer } from '../../helpers/renderEnhancer';
|
|
10
|
+
import type { ButtonProps } from '../button';
|
|
11
|
+
import { Button } from '../button';
|
|
12
|
+
import type { FieldProps } from '../field';
|
|
13
|
+
import { Field } from '../field';
|
|
14
|
+
import type { InputProps } from '../input';
|
|
13
15
|
import inputStyles from '../input/Input.module.scss';
|
|
14
|
-
import dropdownStyles from '../utility/Dropdown.module.scss';
|
|
15
16
|
import styles from '../select/Select.module.scss';
|
|
16
17
|
import type { TextProps } from '../text';
|
|
17
18
|
import { Text } from '../text';
|
|
18
|
-
import type { InputProps } from '../input';
|
|
19
|
-
import { MemoizedEnhancer } from '../../helpers/renderEnhancer';
|
|
20
19
|
import { pget, theme } from '../theme';
|
|
21
|
-
import type { FieldProps } from '../field';
|
|
22
|
-
import { Field } from '../field';
|
|
23
|
-
import type { ButtonProps } from '../button';
|
|
24
|
-
import { Button } from '../button';
|
|
25
20
|
import { TextWhenString } from '../utility';
|
|
26
|
-
import
|
|
21
|
+
import dropdownStyles from '../utility/Dropdown.module.scss';
|
|
27
22
|
|
|
28
|
-
export type Option<T extends Record<string, any> = Record<string, any>> =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
export type Option<T extends Record<string, any> = Record<string, any>> =
|
|
24
|
+
| {
|
|
25
|
+
id: string;
|
|
26
|
+
node: ReactNode;
|
|
27
|
+
metadata?: T;
|
|
28
|
+
}
|
|
29
|
+
| {
|
|
30
|
+
id: null;
|
|
31
|
+
node: string;
|
|
32
|
+
metadata?: T;
|
|
33
|
+
};
|
|
37
34
|
|
|
38
35
|
export type ComboboxProps<T extends Record<string, any>> = {
|
|
39
36
|
/**
|
|
@@ -119,7 +116,7 @@ export type ComboboxProps<T extends Record<string, any>> = {
|
|
|
119
116
|
startEnhancerContainer?: ComponentPropsWithoutRef<'div'>;
|
|
120
117
|
endEnhancerContainer?: ComponentPropsWithoutRef<'div'>;
|
|
121
118
|
clearButton?: ButtonProps;
|
|
122
|
-
}
|
|
119
|
+
};
|
|
123
120
|
} & Omit<InputProps, 'type' | 'overrides'>;
|
|
124
121
|
|
|
125
122
|
/**
|
|
@@ -167,12 +164,10 @@ export function Combobox<T extends Record<string, any> = Record<string, any>>({
|
|
|
167
164
|
const [selectedID, setSelectedID] = useState<string | null>(value?.id || null);
|
|
168
165
|
const [query, setQuery] = useState('');
|
|
169
166
|
|
|
170
|
-
const optionsWithCustomValue = useMemo(
|
|
171
|
-
...(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
...options,
|
|
175
|
-
]), [allowCustomValue, customValueToOption, options, query]);
|
|
167
|
+
const optionsWithCustomValue = useMemo(
|
|
168
|
+
() => [...(allowCustomValue && customValueToOption ? [customValueToOption(query)] : []), ...options],
|
|
169
|
+
[allowCustomValue, customValueToOption, options, query],
|
|
170
|
+
);
|
|
176
171
|
|
|
177
172
|
return (
|
|
178
173
|
<Field
|
|
@@ -210,29 +205,32 @@ export function Combobox<T extends Record<string, any> = Record<string, any>>({
|
|
|
210
205
|
}}
|
|
211
206
|
>
|
|
212
207
|
<div
|
|
213
|
-
data-status={disabled ? 'disabled' :
|
|
208
|
+
data-status={disabled ? 'disabled' : status || 'default'}
|
|
214
209
|
{...overrides?.inputContainer}
|
|
215
|
-
className={clsx(
|
|
216
|
-
overrides?.inputContainer?.className,
|
|
217
|
-
inputStyles.inputContainer,
|
|
218
|
-
)}
|
|
210
|
+
className={clsx(overrides?.inputContainer?.className, inputStyles.inputContainer)}
|
|
219
211
|
>
|
|
220
212
|
{!!startEnhancer && (
|
|
221
213
|
<div
|
|
222
214
|
{...overrides?.startEnhancerContainer}
|
|
223
215
|
className={clsx(inputStyles.enhancer, overrides?.startEnhancerContainer?.className)}
|
|
224
|
-
data-status={disabled ? 'disabled' :
|
|
216
|
+
data-status={disabled ? 'disabled' : status || 'default'}
|
|
225
217
|
>
|
|
226
218
|
{!!startEnhancer && (
|
|
227
219
|
<MemoizedEnhancer
|
|
228
220
|
enhancer={startEnhancer}
|
|
229
|
-
size={parseInt(
|
|
221
|
+
size={parseInt(
|
|
222
|
+
pget('typography.styles.paragraphSmall.fontSize') ||
|
|
223
|
+
theme.typography.styles.paragraphSmall.fontSize,
|
|
224
|
+
10,
|
|
225
|
+
)}
|
|
230
226
|
/>
|
|
231
227
|
)}
|
|
232
228
|
</div>
|
|
233
229
|
)}
|
|
234
230
|
<div className={styles.content}>
|
|
235
|
-
{
|
|
231
|
+
{value?.node && typeof value.node !== 'string' ? (
|
|
232
|
+
value.node
|
|
233
|
+
) : (
|
|
236
234
|
<ComboboxInput
|
|
237
235
|
id={inputID}
|
|
238
236
|
{...overrides?.input}
|
|
@@ -244,24 +242,22 @@ export function Combobox<T extends Record<string, any> = Record<string, any>>({
|
|
|
244
242
|
if (onInputChange) onInputChange(e.target.value);
|
|
245
243
|
if (overrides?.input?.onChange) overrides.input.onChange(e);
|
|
246
244
|
if (allowCustomValue && e.target.value) {
|
|
247
|
-
onChange?.(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
245
|
+
onChange?.(
|
|
246
|
+
customValueToOption?.(e.target.value) || {
|
|
247
|
+
id: null,
|
|
248
|
+
node: e.target.value,
|
|
249
|
+
},
|
|
250
|
+
);
|
|
251
251
|
}
|
|
252
252
|
}}
|
|
253
253
|
aria-disabled={disabled}
|
|
254
|
-
data-status={disabled ? 'disabled' :
|
|
255
|
-
className={clsx(
|
|
256
|
-
overrides?.input?.className,
|
|
257
|
-
inputStyles.input,
|
|
258
|
-
styles.field,
|
|
259
|
-
)}
|
|
254
|
+
data-status={disabled ? 'disabled' : status || 'default'}
|
|
255
|
+
className={clsx(overrides?.input?.className, inputStyles.input, styles.field)}
|
|
260
256
|
/>
|
|
261
257
|
)}
|
|
262
258
|
</div>
|
|
263
259
|
|
|
264
|
-
{
|
|
260
|
+
{!!value && (!hideClearButton || typeof value.node !== 'string') && (
|
|
265
261
|
<Button
|
|
266
262
|
size="xs"
|
|
267
263
|
shape="circle"
|
|
@@ -281,12 +277,16 @@ export function Combobox<T extends Record<string, any> = Record<string, any>>({
|
|
|
281
277
|
<div
|
|
282
278
|
{...overrides?.endEnhancerContainer}
|
|
283
279
|
className={clsx(inputStyles.enhancer, overrides?.endEnhancerContainer?.className)}
|
|
284
|
-
data-status={disabled ? 'disabled' :
|
|
280
|
+
data-status={disabled ? 'disabled' : status || 'default'}
|
|
285
281
|
>
|
|
286
282
|
{!!endEnhancer && (
|
|
287
283
|
<MemoizedEnhancer
|
|
288
284
|
enhancer={endEnhancer}
|
|
289
|
-
size={parseInt(
|
|
285
|
+
size={parseInt(
|
|
286
|
+
pget('typography.styles.paragraphSmall.fontSize') ||
|
|
287
|
+
theme.typography.styles.paragraphSmall.fontSize,
|
|
288
|
+
10,
|
|
289
|
+
)}
|
|
290
290
|
/>
|
|
291
291
|
)}
|
|
292
292
|
</div>
|
|
@@ -305,24 +305,20 @@ export function Combobox<T extends Record<string, any> = Record<string, any>>({
|
|
|
305
305
|
<ComboboxOptions
|
|
306
306
|
as="ul"
|
|
307
307
|
{...overrides?.optionsContainer}
|
|
308
|
-
className={clsx(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
} as CSSProperties}
|
|
308
|
+
className={clsx(overrides?.optionsContainer?.className, styles.options)}
|
|
309
|
+
style={
|
|
310
|
+
{
|
|
311
|
+
'--options-maxHeight': `${maxHeight}px`,
|
|
312
|
+
...overrides?.optionsContainer?.style,
|
|
313
|
+
} as CSSProperties
|
|
314
|
+
}
|
|
316
315
|
>
|
|
317
|
-
{
|
|
316
|
+
{allowCustomValue && showCustomValueOption && !customValueToOption && query.length > 0 && (
|
|
318
317
|
<ComboboxOption
|
|
319
318
|
as="li"
|
|
320
319
|
value={query}
|
|
321
320
|
data-selected={false}
|
|
322
|
-
className={clsx(
|
|
323
|
-
overrides?.customValueOption?.className,
|
|
324
|
-
styles.option,
|
|
325
|
-
)}
|
|
321
|
+
className={clsx(overrides?.customValueOption?.className, styles.option)}
|
|
326
322
|
{...overrides?.customValueOption}
|
|
327
323
|
>
|
|
328
324
|
<Text as="span" kind="paragraphSmall">
|
|
@@ -330,28 +326,23 @@ export function Combobox<T extends Record<string, any> = Record<string, any>>({
|
|
|
330
326
|
</Text>
|
|
331
327
|
</ComboboxOption>
|
|
332
328
|
)}
|
|
333
|
-
{
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
{option.node}
|
|
351
|
-
</TextWhenString>
|
|
352
|
-
</ComboboxOption>
|
|
353
|
-
))
|
|
354
|
-
}
|
|
329
|
+
{(optionsWithCustomValue || []).map((option) => (
|
|
330
|
+
<ComboboxOption
|
|
331
|
+
as="li"
|
|
332
|
+
key={option.id}
|
|
333
|
+
value={option.id}
|
|
334
|
+
{...overrides?.option}
|
|
335
|
+
className={clsx(
|
|
336
|
+
overrides?.option?.className,
|
|
337
|
+
styles.option,
|
|
338
|
+
hasOptionBorder && styles.optionBorder,
|
|
339
|
+
)}
|
|
340
|
+
>
|
|
341
|
+
<TextWhenString as="span" kind="paragraphSmall">
|
|
342
|
+
{option.node}
|
|
343
|
+
</TextWhenString>
|
|
344
|
+
</ComboboxOption>
|
|
345
|
+
))}
|
|
355
346
|
</ComboboxOptions>
|
|
356
347
|
</Transition>
|
|
357
348
|
</HCombobox>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/nextjs-vite';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import { Dialog } from './Dialog';
|
|
4
3
|
import { Button } from '../button';
|
|
5
4
|
import { Text } from '../text';
|
|
5
|
+
import { Dialog } from './Dialog';
|
|
6
6
|
|
|
7
7
|
const meta: Meta<typeof Dialog> = {
|
|
8
8
|
title: 'Surfaces/Dialog',
|