@economic/taco 0.0.1-alpha.1543 → 0.0.2-alpha.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/dist/components/Backdrop/Backdrop.d.ts +3 -0
- package/dist/components/Button/Button.d.ts +39 -1
- package/dist/components/Button/util.d.ts +2 -0
- package/dist/components/Checkbox/Checkbox.d.ts +1 -1
- package/dist/components/Combobox/useCombobox.d.ts +3 -3
- package/dist/components/Dialog/Context.d.ts +1 -0
- package/dist/components/Dialog/Dialog.d.ts +14 -12
- package/dist/components/Hanger/Hanger.d.ts +4 -9
- package/dist/components/IconButton/IconButton.d.ts +38 -1
- package/dist/components/Listbox/Listbox.d.ts +0 -1
- package/dist/components/Navigation/Navigation.d.ts +4 -4
- package/dist/components/Popover/Popover.d.ts +5 -9
- package/dist/components/RadioGroup/RadioGroup.d.ts +5 -5
- package/dist/components/Select/Select.d.ts +0 -1
- package/dist/components/Select/useSelect.d.ts +5 -4
- package/dist/components/Table/Table.storyexample.d.ts +1 -1
- package/dist/components/Table/components/PaginatedTable.d.ts +2 -2
- package/dist/components/Table/components/Table.d.ts +2 -2
- package/dist/components/Table/components/WindowedTable.d.ts +2 -2
- package/dist/components/Table/types.d.ts +2 -2
- package/dist/components/Tabs/Tabs.d.ts +2 -2
- package/dist/components/Tooltip/Tooltip.d.ts +11 -1
- package/dist/components/Treeview/Treeview.d.ts +2 -2
- package/dist/esm/index.css +75 -170
- package/dist/esm/src/components/Backdrop/Backdrop.js +12 -0
- package/dist/esm/src/components/Backdrop/Backdrop.js.map +1 -0
- package/dist/esm/src/components/Button/Button.js +6 -9
- package/dist/esm/src/components/Button/Button.js.map +1 -1
- package/dist/esm/src/components/Button/util.js +42 -1
- package/dist/esm/src/components/Button/util.js.map +1 -1
- package/dist/esm/src/components/Calendar/Calendar.js +1 -1
- package/dist/esm/src/components/Checkbox/Checkbox.js +9 -1
- package/dist/esm/src/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/src/components/Combobox/Combobox.js +28 -24
- package/dist/esm/src/components/Combobox/Combobox.js.map +1 -1
- package/dist/esm/src/components/Combobox/useCombobox.js +32 -38
- package/dist/esm/src/components/Combobox/useCombobox.js.map +1 -1
- package/dist/esm/src/components/Datepicker/Datepicker.js +2 -2
- package/dist/esm/src/components/Dialog/Context.js +1 -0
- package/dist/esm/src/components/Dialog/Context.js.map +1 -1
- package/dist/esm/src/components/Dialog/Dialog.js +5 -4
- package/dist/esm/src/components/Dialog/Dialog.js.map +1 -1
- package/dist/esm/src/components/Dialog/components/Content.js +13 -13
- package/dist/esm/src/components/Dialog/components/Content.js.map +1 -1
- package/dist/esm/src/components/Dialog/components/Drawer.js +2 -1
- package/dist/esm/src/components/Dialog/components/Drawer.js.map +1 -1
- package/dist/esm/src/components/Dialog/components/Extra.js +2 -1
- package/dist/esm/src/components/Dialog/components/Extra.js.map +1 -1
- package/dist/esm/src/components/Dialog/components/Trigger.js +2 -1
- package/dist/esm/src/components/Dialog/components/Trigger.js.map +1 -1
- package/dist/esm/src/components/Hanger/Hanger.js +12 -9
- package/dist/esm/src/components/Hanger/Hanger.js.map +1 -1
- package/dist/esm/src/components/IconButton/IconButton.js +9 -11
- package/dist/esm/src/components/IconButton/IconButton.js.map +1 -1
- package/dist/esm/src/components/Input/util.js +6 -6
- package/dist/esm/src/components/Input/util.js.map +1 -1
- package/dist/esm/src/components/Listbox/Listbox.js +21 -5
- package/dist/esm/src/components/Listbox/Listbox.js.map +1 -1
- package/dist/esm/src/components/Listbox/ScrollableList.js +7 -5
- package/dist/esm/src/components/Listbox/ScrollableList.js.map +1 -1
- package/dist/esm/src/components/Navigation/Navigation.js +5 -4
- package/dist/esm/src/components/Navigation/Navigation.js.map +1 -1
- package/dist/esm/src/components/Pagination/PageNumbers.js +1 -1
- package/dist/esm/src/components/Pagination/Pagination.js +2 -1
- package/dist/esm/src/components/Pagination/Pagination.js.map +1 -1
- package/dist/esm/src/components/Popover/Popover.js +9 -6
- package/dist/esm/src/components/Popover/Popover.js.map +1 -1
- package/dist/esm/src/components/RadioGroup/RadioGroup.js +17 -16
- package/dist/esm/src/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/esm/src/components/SearchInput/SearchInput.js +8 -7
- package/dist/esm/src/components/SearchInput/SearchInput.js.map +1 -1
- package/dist/esm/src/components/Select/Select.js +27 -25
- package/dist/esm/src/components/Select/Select.js.map +1 -1
- package/dist/esm/src/components/Select/useSelect.js +77 -37
- package/dist/esm/src/components/Select/useSelect.js.map +1 -1
- package/dist/esm/src/components/Table/components/PaginatedTable.js.map +1 -1
- package/dist/esm/src/components/Table/components/Table.js.map +1 -1
- package/dist/esm/src/components/Table/components/WindowedTable.js.map +1 -1
- package/dist/esm/src/components/Table/hooks/plugins/useRowActions.js +11 -5
- package/dist/esm/src/components/Table/hooks/plugins/useRowActions.js.map +1 -1
- package/dist/esm/src/components/Table/hooks/plugins/useRowSelect.js +3 -3
- package/dist/esm/src/components/Table/hooks/plugins/useRowSelect.js.map +1 -1
- package/dist/esm/src/components/Table/util/renderColumn.js +4 -3
- package/dist/esm/src/components/Table/util/renderColumn.js.map +1 -1
- package/dist/esm/src/components/Table/util/renderRow.js +4 -3
- package/dist/esm/src/components/Table/util/renderRow.js.map +1 -1
- package/dist/esm/src/components/Tabs/Tabs.js.map +1 -1
- package/dist/esm/src/components/Toast/Toast.js +1 -1
- package/dist/esm/src/components/Tooltip/Tooltip.js +11 -10
- package/dist/esm/src/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/esm/src/components/Tour/Tour.js +2 -2
- package/dist/esm/src/components/Treeview/Treeview.js.map +1 -1
- package/dist/esm/src/index.js +8 -7
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/primitives/Button.js +2 -12
- package/dist/esm/src/primitives/Button.js.map +1 -1
- package/dist/esm/src/utils/mergeRefs.js +14 -0
- package/dist/esm/src/utils/mergeRefs.js.map +1 -0
- package/dist/index.css +75 -170
- package/dist/index.d.ts +1 -0
- package/dist/primitives/Button.d.ts +0 -4
- package/dist/taco.cjs.development.js +1688 -1561
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/dist/utils/mergeRefs.d.ts +2 -0
- package/package.json +4 -4
- package/types.json +7297 -0
@@ -1,15 +1,14 @@
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
2
2
|
import { forwardRef, useRef, createElement } from 'react';
|
3
3
|
import cn from 'classnames';
|
4
|
+
import { Root, Anchor, Content } from '@radix-ui/react-popover';
|
4
5
|
import { IconButton } from '../IconButton/IconButton.js';
|
5
|
-
import { PopoverDisclosure, Popover } from 'reakit/Popover';
|
6
6
|
import { Input } from '../Input/Input.js';
|
7
7
|
import { ScrollableList } from '../Listbox/ScrollableList.js';
|
8
8
|
import { useCombobox } from './useCombobox.js';
|
9
9
|
import { useBoundingClientRectListener } from '../../utils/hooks/useBoundingClientRectListener.js';
|
10
10
|
|
11
|
-
var _excluded = ["className", "style"]
|
12
|
-
_excluded2 = ["container"];
|
11
|
+
var _excluded = ["className", "style"];
|
13
12
|
var Combobox = /*#__PURE__*/forwardRef(function Combobox(props, ref) {
|
14
13
|
var externalClassName = props.className,
|
15
14
|
style = props.style,
|
@@ -21,9 +20,6 @@ var Combobox = /*#__PURE__*/forwardRef(function Combobox(props, ref) {
|
|
21
20
|
popover = _useCombobox.popover,
|
22
21
|
list = _useCombobox.list;
|
23
22
|
|
24
|
-
var container = popover.container,
|
25
|
-
base = _objectWithoutPropertiesLoose(popover, _excluded2);
|
26
|
-
|
27
23
|
var internalRef = useRef(null);
|
28
24
|
var selectDimensions = useBoundingClientRectListener(internalRef);
|
29
25
|
var className = cn('inline-flex relative', {
|
@@ -33,28 +29,36 @@ var Combobox = /*#__PURE__*/forwardRef(function Combobox(props, ref) {
|
|
33
29
|
className: className,
|
34
30
|
"data-taco": "combobox",
|
35
31
|
style: style
|
36
|
-
}, createElement(
|
32
|
+
}, createElement(Root, Object.assign({}, popover), createElement(Anchor, {
|
33
|
+
asChild: true,
|
37
34
|
ref: internalRef
|
38
|
-
}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}
|
50
|
-
|
51
|
-
|
52
|
-
|
35
|
+
}, createElement("div", Object.assign({}, combobox, {
|
36
|
+
className: "inline w-full",
|
37
|
+
ref: ref
|
38
|
+
}), createElement(Input, Object.assign({}, input, {
|
39
|
+
autoComplete: "off",
|
40
|
+
button: props.inline ? createElement(IconButton, {
|
41
|
+
appearance: "discrete",
|
42
|
+
className: "focus:!border-none focus:!shadow-none active:!border-none",
|
43
|
+
icon: popover.open ? 'chevron-up' : 'chevron-down',
|
44
|
+
onClick: function onClick() {
|
45
|
+
return popover.onOpenChange(true);
|
46
|
+
},
|
47
|
+
tabIndex: -1
|
48
|
+
}) : props.button
|
49
|
+
})))), createElement(Content, {
|
50
|
+
align: "start",
|
51
|
+
onOpenAutoFocus: function onOpenAutoFocus(event) {
|
52
|
+
event.preventDefault();
|
53
|
+
},
|
54
|
+
sideOffset: 4
|
55
|
+
}, createElement(ScrollableList, Object.assign({}, list, {
|
56
|
+
className: cn('border-blue max-h-[calc(12rem+2px)] w-auto max-w-[theme(spacing.96)]'),
|
53
57
|
style: {
|
54
58
|
minWidth: selectDimensions === null || selectDimensions === void 0 ? void 0 : selectDimensions.width
|
55
59
|
},
|
56
|
-
tabIndex: popover.
|
57
|
-
}))));
|
60
|
+
tabIndex: popover.open ? 0 : -1
|
61
|
+
})))));
|
58
62
|
});
|
59
63
|
|
60
64
|
export { Combobox };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Combobox.js","sources":["../../../../../src/components/Combobox/Combobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport
|
1
|
+
{"version":3,"file":"Combobox.js","sources":["../../../../../src/components/Combobox/Combobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { Input, InputProps } from '../Input/Input';\nimport { useCombobox } from './useCombobox';\nimport { ScrollableList, ScrollableListItem, ScrollableListItemValue } from '../Listbox/ScrollableList';\nimport { useBoundingClientRectListener } from '../../utils/hooks/useBoundingClientRectListener';\nimport { IconButton } from '../IconButton/IconButton';\nimport { State } from '../../types';\nimport './Combobox.css';\n\nexport type ComboboxItem = ScrollableListItem;\nexport type ComboboxValue = ScrollableListItemValue;\n\nexport type ComboboxProps = Omit<InputProps, 'defaultValue' | 'onChange' | 'value'> & {\n /** Array of options in combobox */\n data?: ComboboxItem[];\n /**\n * Initial value of the input in combobox.\n * This is used when combobox is mounted, if no value is provided.\n * *Note* that combobox is a controlled component, setting this will also trigger the `onChange` event\n */\n defaultValue?: ComboboxValue;\n /** Set what value should have an empty option in combobox */\n emptyValue?: ComboboxValue;\n /** Draws attention to the combobox by changing its style and making it visually prominent */\n highlighted?: boolean;\n /**\n * Combobox will display its data when input is clicked/focused, even if the input is empty.\n * *Note* that default combobox will display matching data only when user starts typing in input.\n */\n inline?: boolean; // Example 3 on https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html\n /** Displays loading state in listbox */\n loading?: boolean;\n /**\n * Handler called when user chooses an option from the provided suggestions.\n * Suggestions will be calculated based on the input value.\n * There are two ways to choose an option: either click on it, or navigate using keyboard and press `enter`\n */\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\n /** State will change the style of the combobox **/\n state?: State;\n /** Value of the input in combobox */\n value?: ComboboxValue;\n};\n\nexport const Combobox = React.forwardRef(function Combobox(props: ComboboxProps, ref: React.Ref<HTMLInputElement>) {\n const { className: externalClassName, style, ...otherProps } = props;\n const { combobox, input, popover, list } = useCombobox(otherProps, ref);\n const internalRef = React.useRef<HTMLDivElement>(null);\n const selectDimensions = useBoundingClientRectListener(internalRef);\n const className = cn(\n 'inline-flex relative',\n {\n 'yt-combobox--inline': props.inline,\n },\n externalClassName\n );\n\n return (\n <span className={className} data-taco=\"combobox\" style={style}>\n <PopoverPrimitive.Root {...popover}>\n <PopoverPrimitive.Anchor asChild ref={internalRef}>\n <div {...combobox} className=\"inline w-full\" ref={ref}>\n <Input\n {...input}\n autoComplete=\"off\"\n button={\n props.inline ? (\n <IconButton\n appearance=\"discrete\"\n className=\"focus:!border-none focus:!shadow-none active:!border-none\"\n icon={popover.open ? 'chevron-up' : 'chevron-down'}\n onClick={() => popover.onOpenChange(true)}\n tabIndex={-1}\n />\n ) : (\n props.button\n )\n }\n />\n </div>\n </PopoverPrimitive.Anchor>\n <PopoverPrimitive.Content\n align=\"start\"\n onOpenAutoFocus={event => {\n event.preventDefault();\n }}\n sideOffset={4}\n >\n <ScrollableList\n {...list}\n className={cn('border-blue max-h-[calc(12rem+2px)] w-auto max-w-[theme(spacing.96)]')}\n style={{ minWidth: selectDimensions?.width }}\n tabIndex={popover.open ? 0 : -1}\n />\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Root>\n </span>\n );\n});\n"],"names":["Combobox","React","props","ref","externalClassName","className","style","otherProps","useCombobox","combobox","input","popover","list","internalRef","selectDimensions","useBoundingClientRectListener","cn","inline","PopoverPrimitive","asChild","Input","autoComplete","button","IconButton","appearance","icon","open","onClick","onOpenChange","tabIndex","align","onOpenAutoFocus","event","preventDefault","sideOffset","ScrollableList","minWidth","width"],"mappings":";;;;;;;;;;;IA8CaA,QAAQ,gBAAGC,UAAA,CAAiB,SAASD,QAAT,CAAkBE,KAAlB,EAAwCC,GAAxC;AACrC,MAAmBC,iBAAnB,GAA+DF,KAA/D,CAAQG,SAAR;AAAA,MAAsCC,KAAtC,GAA+DJ,KAA/D,CAAsCI,KAAtC;AAAA,MAAgDC,UAAhD,iCAA+DL,KAA/D;;AACA,qBAA2CM,WAAW,CAACD,UAAD,EAAaJ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AACC,cAAN;AACH;AACDC,IAAAA,UAAU,EAAE;GALhB,EAOIjC,aAAA,CAACkC,cAAD,oBACQvB;AACJP,IAAAA,SAAS,EAAEW,EAAE,CAAC,sEAAD;AACbV,IAAAA,KAAK,EAAE;AAAE8B,MAAAA,QAAQ,EAAEtB,gBAAF,aAAEA,gBAAF,uBAAEA,gBAAgB,CAAEuB;AAA9B;AACPR,IAAAA,QAAQ,EAAElB,OAAO,CAACe,IAAR,GAAe,CAAf,GAAmB,CAAC;IAJlC,CAPJ,CAtBJ,CADJ,CADJ;AAyCH,CAtDuB;;;;"}
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import { useRef,
|
1
|
+
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
2
|
+
import { useRef, useState, useMemo, useEffect } from 'react';
|
3
3
|
import { v4 } from 'uuid';
|
4
|
-
import { usePopoverState } from 'reakit/Popover';
|
5
4
|
import { useProxiedRef } from '../../utils/hooks/useProxiedRef.js';
|
6
5
|
import keycode from 'keycode';
|
7
6
|
import { getId } from '../Listbox/ScrollableList.js';
|
@@ -15,8 +14,7 @@ var convertToInputValue = function convertToInputValue(value) {
|
|
15
14
|
};
|
16
15
|
|
17
16
|
var useCombobox = function useCombobox(_ref, ref) {
|
18
|
-
var
|
19
|
-
ariaLabelledBy = _ref['aria-labelledby'],
|
17
|
+
var ariaLabelledBy = _ref['aria-labelledby'],
|
20
18
|
_ref$data = _ref.data,
|
21
19
|
unfilteredData = _ref$data === void 0 ? [] : _ref$data,
|
22
20
|
defaultValue = _ref.defaultValue,
|
@@ -31,17 +29,18 @@ var useCombobox = function useCombobox(_ref, ref) {
|
|
31
29
|
|
32
30
|
var inputRef = useProxiedRef(ref);
|
33
31
|
var listRef = useRef(null);
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
|
33
|
+
var _React$useState = useState(false),
|
34
|
+
open = _React$useState[0],
|
35
|
+
setOpen = _React$useState[1];
|
36
|
+
|
38
37
|
var listId = useMemo(function () {
|
39
38
|
return v4();
|
40
39
|
}, []);
|
41
40
|
|
42
|
-
var _React$
|
43
|
-
inputValue = _React$
|
44
|
-
setInputValue = _React$
|
41
|
+
var _React$useState2 = useState(convertToInputValue(value)),
|
42
|
+
inputValue = _React$useState2[0],
|
43
|
+
setInputValue = _React$useState2[1];
|
45
44
|
|
46
45
|
var shouldFilterData = !inline || inline && inputValue !== convertToInputValue(value);
|
47
46
|
var flattenedData = useFlattenedData(unfilteredData);
|
@@ -49,9 +48,9 @@ var useCombobox = function useCombobox(_ref, ref) {
|
|
49
48
|
return shouldFilterData ? filterData(flattenedData, inputValue) : flattenedData;
|
50
49
|
}, [shouldFilterData, inputValue, flattenedData]); // listbox/select change value _with_ the index, but combobox changes on select of an index (click/enter), so we need state
|
51
50
|
|
52
|
-
var _React$
|
53
|
-
currentIndex = _React$
|
54
|
-
setCurrentIndex = _React$
|
51
|
+
var _React$useState3 = useState(inputValue !== undefined ? getIndexFromValue(data, inputValue) : undefined),
|
52
|
+
currentIndex = _React$useState3[0],
|
53
|
+
setCurrentIndex = _React$useState3[1];
|
55
54
|
|
56
55
|
var setInputValueByIndex = function setInputValueByIndex(index) {
|
57
56
|
if (index !== undefined) {
|
@@ -99,20 +98,20 @@ var useCombobox = function useCombobox(_ref, ref) {
|
|
99
98
|
if (inputValue && data.length && !isCurrentValue) {
|
100
99
|
setCurrentIndex(0);
|
101
100
|
|
102
|
-
if (!
|
103
|
-
|
101
|
+
if (!open) {
|
102
|
+
setOpen(true);
|
104
103
|
}
|
105
104
|
} else {
|
106
|
-
|
105
|
+
setOpen(false);
|
107
106
|
}
|
108
107
|
}, [inputValue, data]);
|
109
108
|
useEffect(function () {
|
110
|
-
if (
|
109
|
+
if (open) {
|
111
110
|
setCurrentIndex(getIndexFromValue(data, inputValue) || 0);
|
112
111
|
} else {
|
113
112
|
setCurrentIndex(undefined);
|
114
113
|
}
|
115
|
-
}, [
|
114
|
+
}, [open]); // event handlers
|
116
115
|
|
117
116
|
var handleInputBlur = function handleInputBlur(event) {
|
118
117
|
event.persist();
|
@@ -144,8 +143,8 @@ var useCombobox = function useCombobox(_ref, ref) {
|
|
144
143
|
};
|
145
144
|
|
146
145
|
var handleInputClick = function handleInputClick(event) {
|
147
|
-
if (inline || !
|
148
|
-
|
146
|
+
if (inline || !open && inputValue && data.length) {
|
147
|
+
setOpen(true);
|
149
148
|
}
|
150
149
|
|
151
150
|
if (onClick) {
|
@@ -167,7 +166,7 @@ var useCombobox = function useCombobox(_ref, ref) {
|
|
167
166
|
{
|
168
167
|
event.preventDefault();
|
169
168
|
setInputValue(convertToInputValue(value));
|
170
|
-
|
169
|
+
setOpen(false);
|
171
170
|
return;
|
172
171
|
}
|
173
172
|
|
@@ -179,7 +178,7 @@ var useCombobox = function useCombobox(_ref, ref) {
|
|
179
178
|
}
|
180
179
|
|
181
180
|
setCurrentValue(currentIndex);
|
182
|
-
|
181
|
+
setOpen(false);
|
183
182
|
return;
|
184
183
|
}
|
185
184
|
|
@@ -188,7 +187,7 @@ var useCombobox = function useCombobox(_ref, ref) {
|
|
188
187
|
case keycode('home'):
|
189
188
|
case keycode('end'):
|
190
189
|
{
|
191
|
-
if (
|
190
|
+
if (open) {
|
192
191
|
event.preventDefault();
|
193
192
|
}
|
194
193
|
|
@@ -201,12 +200,12 @@ var useCombobox = function useCombobox(_ref, ref) {
|
|
201
200
|
listRef.current.dispatchEvent(createCustomKeyboardEvent(event));
|
202
201
|
}
|
203
202
|
|
204
|
-
if (inline && !
|
203
|
+
if (inline && !open) {
|
205
204
|
if (event.keyCode === keycode('up') || event.keyCode === keycode('down')) {
|
206
205
|
event.preventDefault();
|
207
206
|
var initialIndex = event.keyCode === keycode('up') ? data.length - 1 : 0;
|
208
207
|
setCurrentIndex(currentIndex !== undefined ? currentIndex : initialIndex);
|
209
|
-
|
208
|
+
setOpen(true);
|
210
209
|
}
|
211
210
|
}
|
212
211
|
|
@@ -223,11 +222,11 @@ var useCombobox = function useCombobox(_ref, ref) {
|
|
223
222
|
var handleListboxClick = function handleListboxClick(event, index) {
|
224
223
|
event.preventDefault();
|
225
224
|
setCurrentValue(index);
|
226
|
-
|
225
|
+
setOpen(false);
|
227
226
|
};
|
228
227
|
|
229
228
|
var combobox = {
|
230
|
-
'aria-expanded':
|
229
|
+
'aria-expanded': open,
|
231
230
|
'aria-owns': listId,
|
232
231
|
'aria-haspopup': 'listbox',
|
233
232
|
role: 'combobox'
|
@@ -268,15 +267,10 @@ var useCombobox = function useCombobox(_ref, ref) {
|
|
268
267
|
combobox: combobox,
|
269
268
|
input: input,
|
270
269
|
list: list,
|
271
|
-
popover:
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
'aria-label': ariaLabel,
|
276
|
-
'aria-labelledby': ariaLabelledBy,
|
277
|
-
unstable_initialFocusRef: inputRef
|
278
|
-
}
|
279
|
-
})
|
270
|
+
popover: {
|
271
|
+
open: open,
|
272
|
+
onOpenChange: setOpen
|
273
|
+
}
|
280
274
|
};
|
281
275
|
};
|
282
276
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCombobox.js","sources":["../../../../../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport keycode from 'keycode';\nimport { v4 as uuid } from 'uuid';\nimport { PopoverHTMLProps, PopoverStateReturn, usePopoverState } from 'reakit/Popover';\nimport { ComboboxProps } from './Combobox';\nimport {\n setInputValueByRef,\n getIndexFromValue,\n findByValue,\n useFlattenedData,\n sanitizeItem,\n getOptionParents,\n filterData,\n} from '../Listbox/util';\nimport { createCustomKeyboardEvent } from '../../utils/input';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { getId, ScrollableListItemValue, ScrollableListPropsWithRef } from '../Listbox/ScrollableList';\n\nconst convertToInputValue = (value: ScrollableListItemValue | undefined) => String(value ?? '');\n\ntype useCombobox = React.HTMLAttributes<HTMLDivElement> & {\n combobox: React.HTMLAttributes<HTMLSpanElement>;\n input: Omit<React.HTMLAttributes<HTMLInputElement>, 'defaultValue'> & { ref: React.RefObject<HTMLInputElement> };\n list: ScrollableListPropsWithRef;\n popover: PopoverStateReturn & { container: PopoverHTMLProps };\n};\n\nexport const useCombobox = (\n {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data: unfilteredData = [],\n defaultValue,\n disabled,\n id: nativeId,\n inline,\n loading: __,\n onChange,\n onClick,\n onKeyDown,\n readOnly,\n value,\n ...props\n }: ComboboxProps,\n ref: React.Ref<HTMLInputElement>\n): useCombobox => {\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const listRef = React.useRef<HTMLUListElement>(null);\n const popover = usePopoverState({ gutter: 4, placement: 'bottom-start' });\n const listId = React.useMemo(() => uuid(), []);\n const [inputValue, setInputValue] = React.useState<string>(convertToInputValue(value));\n const shouldFilterData = !inline || (inline && inputValue !== convertToInputValue(value));\n const flattenedData = useFlattenedData(unfilteredData);\n const data = React.useMemo(\n () => (shouldFilterData ? filterData(flattenedData, inputValue) : flattenedData),\n [shouldFilterData, inputValue, flattenedData]\n );\n // listbox/select change value _with_ the index, but combobox changes on select of an index (click/enter), so we need state\n const [currentIndex, setCurrentIndex] = React.useState<number | undefined>(\n inputValue !== undefined ? getIndexFromValue(data, inputValue) : undefined\n );\n\n const setInputValueByIndex = (index: number | undefined): void => {\n if (index !== undefined) {\n const option = data[index];\n\n if (option && !option.disabled) {\n setInputValueByRef(inputRef.current, option.value, 'focusout');\n }\n }\n };\n\n const setCurrentValue = (index: number | undefined) => {\n if (index === undefined) {\n return;\n }\n\n const option = data[index];\n\n // if the selected option is not already selected, trigger blur event\n if (option.value !== value) {\n setInputValueByIndex(index);\n } else {\n // if the selected option is already selected, refill input with its value\n setInputValue(convertToInputValue(value));\n }\n };\n\n // ensure the external value is synced with the internal value when mounting, e.g. incase a default value was set\n React.useEffect(() => {\n if (defaultValue && !value) {\n setInputValueByIndex(getIndexFromValue(data, defaultValue));\n }\n }, [data]);\n\n // update input value if it changed 'externally', e.g. clicking/entering an item in the listbox, from a modal etc\n React.useEffect(() => {\n if (value !== undefined && value !== inputValue) {\n setInputValue(convertToInputValue(value));\n }\n }, [value]);\n\n // show listbox based on input value\n React.useEffect(() => {\n // don't show the popover if the internal (input) value already is the current value\n // this prevents the popover showing after selecting a value or pressing escape\n const isCurrentValue = value !== undefined && value !== null && inputValue === String(value);\n\n if (inputValue && data.length && !isCurrentValue) {\n setCurrentIndex(0);\n\n if (!popover.visible) {\n popover.show();\n }\n } else {\n popover.hide();\n }\n }, [inputValue, data]);\n\n React.useEffect(() => {\n if (popover.visible) {\n setCurrentIndex(getIndexFromValue(data, inputValue) || 0);\n } else {\n setCurrentIndex(undefined);\n }\n }, [popover.visible]);\n\n // event handlers\n const handleInputBlur = (event: React.FocusEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (event.relatedTarget === listRef.current) {\n event.preventDefault();\n return;\n }\n\n if (onChange && event.target.value !== value) {\n const item = findByValue(flattenedData, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const parents = getOptionParents(flattenedData, item?.path);\n\n if (parents !== null && parents.length > 0) {\n (event as any).detail.parents = parents;\n }\n\n onChange(event);\n }\n\n if (props.onBlur) {\n props.onBlur(event);\n }\n };\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n setInputValue(event.target.value);\n };\n\n const handleInputClick = (event: React.MouseEvent<HTMLInputElement>): void => {\n if (inline || (!popover.visible && inputValue && data.length)) {\n popover.show();\n }\n\n if (onClick) {\n event.persist();\n onClick(event);\n }\n };\n\n const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {\n event.persist();\n\n switch (event.keyCode) {\n case keycode('backspace'): {\n return;\n }\n\n case keycode('escape'): {\n event.preventDefault();\n setInputValue(convertToInputValue(value));\n popover.hide();\n return;\n }\n\n case keycode('tab'):\n case keycode('enter'): {\n if (event.keyCode !== keycode('tab')) {\n event.preventDefault();\n }\n\n setCurrentValue(currentIndex);\n popover.hide();\n return;\n }\n\n case keycode('up'):\n case keycode('down'):\n case keycode('home'):\n case keycode('end'): {\n if (popover.visible) {\n event.preventDefault();\n }\n break;\n }\n\n default:\n }\n\n // we aren't focused on the list, so manually forward the keydown event to it\n if (listRef.current) {\n listRef.current.dispatchEvent(createCustomKeyboardEvent(event));\n }\n\n if (inline && !popover.visible) {\n if (event.keyCode === keycode('up') || event.keyCode === keycode('down')) {\n event.preventDefault();\n const initialIndex = event.keyCode === keycode('up') ? data.length - 1 : 0;\n setCurrentIndex(currentIndex !== undefined ? currentIndex : initialIndex);\n popover.show();\n }\n }\n\n if (!event.isDefaultPrevented() && onKeyDown) {\n event.persist();\n onKeyDown(event);\n }\n };\n\n const handleListboxChange = (index: number): void => {\n setCurrentIndex(index);\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>, index: number): void => {\n event.preventDefault();\n setCurrentValue(index);\n popover.hide();\n };\n\n const combobox = {\n 'aria-expanded': popover.visible,\n 'aria-owns': listId,\n 'aria-haspopup': 'listbox' as const,\n role: 'combobox',\n };\n\n const input = {\n ...props,\n 'aria-controls': listId,\n // Indicates that the autocomplete behavior of the text input is to suggest a list of possible values in a popup and that the suggestions\n // are related to the string that is present in the textbox\n 'aria-autocomplete': 'list' as const,\n // Enables assistive technologies to know which element the application regards as focused while DOM focus remains on the input element\n 'aria-activedescendant':\n currentIndex !== undefined && data[currentIndex] ? getId(listId, String(data[currentIndex].value)) : undefined,\n 'aria-labelledby': ariaLabelledBy,\n disabled,\n onBlur: !disabled && !readOnly ? handleInputBlur : undefined,\n onChange: !disabled && !readOnly ? handleInputChange : undefined,\n onClick: !disabled && !readOnly ? handleInputClick : undefined,\n onKeyDown: !disabled && !readOnly ? handleInputKeyDown : undefined,\n readOnly,\n ref: inputRef,\n type: 'text',\n value: inputValue || '',\n };\n\n const list: ScrollableListPropsWithRef = {\n 'aria-labelledby': ariaLabelledBy,\n data,\n disabled,\n id: listId,\n onChange: handleListboxChange,\n onClick: handleListboxClick,\n ref: listRef,\n scrollOnFocus: false,\n tabIndex: -1,\n value: currentIndex,\n };\n\n return {\n combobox,\n input,\n list,\n popover: {\n ...popover,\n visible: !data.length ? false : popover.visible,\n container: {\n tabIndex: -1,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n unstable_initialFocusRef: inputRef,\n },\n },\n };\n};\n"],"names":["convertToInputValue","value","String","useCombobox","ref","ariaLabel","ariaLabelledBy","data","unfilteredData","defaultValue","disabled","inline","onChange","onClick","onKeyDown","readOnly","props","inputRef","useProxiedRef","listRef","React","popover","usePopoverState","gutter","placement","listId","uuid","inputValue","setInputValue","shouldFilterData","flattenedData","useFlattenedData","filterData","undefined","getIndexFromValue","currentIndex","setCurrentIndex","setInputValueByIndex","index","option","setInputValueByRef","current","setCurrentValue","isCurrentValue","length","visible","show","hide","handleInputBlur","event","persist","relatedTarget","preventDefault","target","item","findByValue","detail","sanitizeItem","parents","getOptionParents","path","onBlur","handleInputChange","handleInputClick","handleInputKeyDown","keyCode","keycode","dispatchEvent","createCustomKeyboardEvent","initialIndex","isDefaultPrevented","handleListboxChange","handleListboxClick","combobox","role","input","getId","type","list","id","scrollOnFocus","tabIndex","container","unstable_initialFocusRef"],"mappings":";;;;;;;;;;;;AAkBA,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACC,KAAD;AAAA,SAAgDC,MAAM,CAACD,KAAD,aAACA,KAAD,cAACA,KAAD,GAAU,EAAV,CAAtD;AAAA,CAA5B;;IASaE,WAAW,GAAG,SAAdA,WAAc,OAiBvBC,GAjBuB;MAELC,iBAAd;MACmBC,sBAAnB;uBACAC;MAAMC,wCAAiB;MACvBC,oBAAAA;MACAC,gBAAAA;MAEAC,cAAAA;MAEAC,gBAAAA;MACAC,eAAAA;MACAC,iBAAAA;MACAC,gBAAAA;MACAd,aAAAA;MACGe;;AAIP,MAAMC,QAAQ,GAAGC,aAAa,CA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AE,KARsB;AASrCC,IAAAA,QAAQ,EAAE,CAAC,CAT0B;AAUrChF,IAAAA,KAAK,EAAEkC;AAV8B,GAAzC;AAaA,SAAO;AACHsC,IAAAA,QAAQ,EAARA,QADG;AAEHE,IAAAA,KAAK,EAALA,KAFG;AAGHG,IAAAA,IAAI,EAAJA,IAHG;AAIHzD,IAAAA,OAAO,eACAA,OADA;AAEHwB,MAAAA,OAAO,EAAE,CAACtC,IAAI,CAACqC,MAAN,GAAe,KAAf,GAAuBvB,OAAO,CAACwB,OAFrC;AAGHqC,MAAAA,SAAS,EAAE;AACPD,QAAAA,QAAQ,EAAE,CAAC,CADJ;AAEP,sBAAc5E,SAFP;AAGP,2BAAmBC,cAHZ;AAIP6E,QAAAA,wBAAwB,EAAElE;AAJnB;AAHR;AAJJ,GAAP;AAeH;;;;"}
|
1
|
+
{"version":3,"file":"useCombobox.js","sources":["../../../../../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport keycode from 'keycode';\nimport { v4 as uuid } from 'uuid';\nimport { ComboboxProps } from './Combobox';\nimport {\n setInputValueByRef,\n getIndexFromValue,\n findByValue,\n useFlattenedData,\n sanitizeItem,\n getOptionParents,\n filterData,\n} from '../Listbox/util';\nimport { createCustomKeyboardEvent } from '../../utils/input';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { getId, ScrollableListItemValue, ScrollableListPropsWithRef } from '../Listbox/ScrollableList';\n\nconst convertToInputValue = (value: ScrollableListItemValue | undefined) => String(value ?? '');\n\ntype useCombobox = React.HTMLAttributes<HTMLDivElement> & {\n combobox: React.HTMLAttributes<HTMLSpanElement>;\n input: Omit<React.HTMLAttributes<HTMLInputElement>, 'defaultValue'> & { ref: React.RefObject<HTMLInputElement> };\n list: ScrollableListPropsWithRef;\n popover: { open: boolean; onOpenChange: (open: boolean) => void };\n};\n\nexport const useCombobox = (\n {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data: unfilteredData = [],\n defaultValue,\n disabled,\n id: nativeId,\n inline,\n loading: __,\n onChange,\n onClick,\n onKeyDown,\n readOnly,\n value,\n ...props\n }: ComboboxProps,\n ref: React.Ref<HTMLInputElement>\n): useCombobox => {\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const listRef = React.useRef<HTMLUListElement>(null);\n const [open, setOpen] = React.useState(false);\n const listId = React.useMemo(() => uuid(), []);\n const [inputValue, setInputValue] = React.useState<string>(convertToInputValue(value));\n const shouldFilterData = !inline || (inline && inputValue !== convertToInputValue(value));\n const flattenedData = useFlattenedData(unfilteredData);\n const data = React.useMemo(\n () => (shouldFilterData ? filterData(flattenedData, inputValue) : flattenedData),\n [shouldFilterData, inputValue, flattenedData]\n );\n // listbox/select change value _with_ the index, but combobox changes on select of an index (click/enter), so we need state\n const [currentIndex, setCurrentIndex] = React.useState<number | undefined>(\n inputValue !== undefined ? getIndexFromValue(data, inputValue) : undefined\n );\n\n const setInputValueByIndex = (index: number | undefined): void => {\n if (index !== undefined) {\n const option = data[index];\n\n if (option && !option.disabled) {\n setInputValueByRef(inputRef.current, option.value, 'focusout');\n }\n }\n };\n\n const setCurrentValue = (index: number | undefined) => {\n if (index === undefined) {\n return;\n }\n\n const option = data[index];\n\n // if the selected option is not already selected, trigger blur event\n if (option.value !== value) {\n setInputValueByIndex(index);\n } else {\n // if the selected option is already selected, refill input with its value\n setInputValue(convertToInputValue(value));\n }\n };\n\n // ensure the external value is synced with the internal value when mounting, e.g. incase a default value was set\n React.useEffect(() => {\n if (defaultValue && !value) {\n setInputValueByIndex(getIndexFromValue(data, defaultValue));\n }\n }, [data]);\n\n // update input value if it changed 'externally', e.g. clicking/entering an item in the listbox, from a modal etc\n React.useEffect(() => {\n if (value !== undefined && value !== inputValue) {\n setInputValue(convertToInputValue(value));\n }\n }, [value]);\n\n // show listbox based on input value\n React.useEffect(() => {\n // don't show the popover if the internal (input) value already is the current value\n // this prevents the popover showing after selecting a value or pressing escape\n const isCurrentValue = value !== undefined && value !== null && inputValue === String(value);\n\n if (inputValue && data.length && !isCurrentValue) {\n setCurrentIndex(0);\n\n if (!open) {\n setOpen(true);\n }\n } else {\n setOpen(false);\n }\n }, [inputValue, data]);\n\n React.useEffect(() => {\n if (open) {\n setCurrentIndex(getIndexFromValue(data, inputValue) || 0);\n } else {\n setCurrentIndex(undefined);\n }\n }, [open]);\n\n // event handlers\n const handleInputBlur = (event: React.FocusEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (event.relatedTarget === listRef.current) {\n event.preventDefault();\n return;\n }\n\n if (onChange && event.target.value !== value) {\n const item = findByValue(flattenedData, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const parents = getOptionParents(flattenedData, item?.path);\n\n if (parents !== null && parents.length > 0) {\n (event as any).detail.parents = parents;\n }\n\n onChange(event);\n }\n\n if (props.onBlur) {\n props.onBlur(event);\n }\n };\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n setInputValue(event.target.value);\n };\n\n const handleInputClick = (event: React.MouseEvent<HTMLInputElement>): void => {\n if (inline || (!open && inputValue && data.length)) {\n setOpen(true);\n }\n\n if (onClick) {\n event.persist();\n onClick(event);\n }\n };\n\n const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {\n event.persist();\n\n switch (event.keyCode) {\n case keycode('backspace'): {\n return;\n }\n\n case keycode('escape'): {\n event.preventDefault();\n setInputValue(convertToInputValue(value));\n setOpen(false);\n return;\n }\n\n case keycode('tab'):\n case keycode('enter'): {\n if (event.keyCode !== keycode('tab')) {\n event.preventDefault();\n }\n\n setCurrentValue(currentIndex);\n setOpen(false);\n return;\n }\n\n case keycode('up'):\n case keycode('down'):\n case keycode('home'):\n case keycode('end'): {\n if (open) {\n event.preventDefault();\n }\n break;\n }\n\n default:\n }\n\n // we aren't focused on the list, so manually forward the keydown event to it\n if (listRef.current) {\n listRef.current.dispatchEvent(createCustomKeyboardEvent(event));\n }\n\n if (inline && !open) {\n if (event.keyCode === keycode('up') || event.keyCode === keycode('down')) {\n event.preventDefault();\n const initialIndex = event.keyCode === keycode('up') ? data.length - 1 : 0;\n setCurrentIndex(currentIndex !== undefined ? currentIndex : initialIndex);\n setOpen(true);\n }\n }\n\n if (!event.isDefaultPrevented() && onKeyDown) {\n event.persist();\n onKeyDown(event);\n }\n };\n\n const handleListboxChange = (index: number): void => {\n setCurrentIndex(index);\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>, index: number): void => {\n event.preventDefault();\n setCurrentValue(index);\n setOpen(false);\n };\n\n const combobox = {\n 'aria-expanded': open,\n 'aria-owns': listId,\n 'aria-haspopup': 'listbox' as const,\n role: 'combobox',\n };\n\n const input = {\n ...props,\n 'aria-controls': listId,\n // Indicates that the autocomplete behavior of the text input is to suggest a list of possible values in a popup and that the suggestions\n // are related to the string that is present in the textbox\n 'aria-autocomplete': 'list' as const,\n // Enables assistive technologies to know which element the application regards as focused while DOM focus remains on the input element\n 'aria-activedescendant':\n currentIndex !== undefined && data[currentIndex] ? getId(listId, String(data[currentIndex].value)) : undefined,\n 'aria-labelledby': ariaLabelledBy,\n disabled,\n onBlur: !disabled && !readOnly ? handleInputBlur : undefined,\n onChange: !disabled && !readOnly ? handleInputChange : undefined,\n onClick: !disabled && !readOnly ? handleInputClick : undefined,\n onKeyDown: !disabled && !readOnly ? handleInputKeyDown : undefined,\n readOnly,\n ref: inputRef,\n type: 'text',\n value: inputValue || '',\n };\n\n const list: ScrollableListPropsWithRef = {\n 'aria-labelledby': ariaLabelledBy,\n data,\n disabled,\n id: listId,\n onChange: handleListboxChange,\n onClick: handleListboxClick,\n ref: listRef,\n scrollOnFocus: false,\n tabIndex: -1,\n value: currentIndex,\n };\n\n return {\n combobox,\n input,\n list,\n popover: {\n open,\n onOpenChange: setOpen,\n //visible: !data.length ? false : open,\n },\n };\n};\n"],"names":["convertToInputValue","value","String","useCombobox","ref","ariaLabelledBy","data","unfilteredData","defaultValue","disabled","inline","onChange","onClick","onKeyDown","readOnly","props","inputRef","useProxiedRef","listRef","React","open","setOpen","listId","uuid","inputValue","setInputValue","shouldFilterData","flattenedData","useFlattenedData","filterData","undefined","getIndexFromValue","currentIndex","setCurrentIndex","setInputValueByIndex","index","option","setInputValueByRef","current","setCurrentValue","isCurrentValue","length","handleInputBlur","event","persist","relatedTarget","preventDefault","target","item","findByValue","detail","sanitizeItem","parents","getOptionParents","path","onBlur","handleInputChange","handleInputClick","handleInputKeyDown","keyCode","keycode","dispatchEvent","createCustomKeyboardEvent","initialIndex","isDefaultPrevented","handleListboxChange","handleListboxClick","combobox","role","input","getId","type","list","id","scrollOnFocus","tabIndex","popover","onOpenChange"],"mappings":";;;;;;;;;;;AAiBA,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACC,KAAD;AAAA,SAAgDC,MAAM,CAACD,KAAD,aAACA,KAAD,cAACA,KAAD,GAAU,EAAV,CAAtD;AAAA,CAA5B;;IASaE,WAAW,GAAG,SAAdA,WAAc,OAiBvBC,GAjBuB;MAGAC,sBAAnB;uBACAC;MAAMC,wCAAiB;MACvBC,oBAAAA;MACAC,gBAAAA;MAEAC,cAAAA;MAEAC,gBAAAA;MACAC,eAAAA;MACAC,iBAAAA;MACAC,gBAAAA;MACAb,aAAAA;MACGc;;AAIP,MAAMC,QAAQ,GAAGC,aAAa,CAAmBb,GAAnB,CAA9B;AACA,MAAMc,OAAO,GAAGC,MAAA,CAA+B,IAA/B,CAAhB;;AACA,wBAAwBA,QAAA,CAAe,KAAf,CAAxB;AAAA,MAAOC,IAAP;AAAA,MAAaC,OAAb;;AACA,MAAMC,MAAM,GAAGH,OAAA,CAAc;AAAA,WAAMI,EAAI,EAAV;AAAA,GAAd,EAA4B,EAA5B,CAAf;;AACA,yBAAoCJ,QAAA,CAAuBnB,mBAAmB,CAACC,KAAD,CAA1C,CAApC;AAAA,MAAOuB,UAAP;AAAA,MAAmBC,aAAnB;;AACA,MAAMC,gBAAgB,GAAG,CAAChB,MAAD,IAAYA,MAAM,IAA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AAa,CAACK,QAAd,GAAyB0C,iBAAzB,GAA6C1B,SAZhD;AAaPlB,IAAAA,OAAO,EAAE,CAACH,QAAD,IAAa,CAACK,QAAd,GAAyB2C,gBAAzB,GAA4C3B,SAb9C;AAcPjB,IAAAA,SAAS,EAAE,CAACJ,QAAD,IAAa,CAACK,QAAd,GAAyB4C,kBAAzB,GAA8C5B,SAdlD;AAePhB,IAAAA,QAAQ,EAARA,QAfO;AAgBPV,IAAAA,GAAG,EAAEY,QAhBE;AAiBPuD,IAAAA,IAAI,EAAE,MAjBC;AAkBPtE,IAAAA,KAAK,EAAEuB,UAAU,IAAI;AAlBd,IAAX;;AAqBA,MAAMgD,IAAI,GAA+B;AACrC,uBAAmBnE,cADkB;AAErCC,IAAAA,IAAI,EAAJA,IAFqC;AAGrCG,IAAAA,QAAQ,EAARA,QAHqC;AAIrCgE,IAAAA,EAAE,EAAEnD,MAJiC;AAKrCX,IAAAA,QAAQ,EAAEsD,mBAL2B;AAMrCrD,IAAAA,OAAO,EAAEsD,kBAN4B;AAOrC9D,IAAAA,GAAG,EAAEc,OAPgC;AAQrCwD,IAAAA,aAAa,EAAE,KARsB;AASrCC,IAAAA,QAAQ,EAAE,CAAC,CAT0B;AAUrC1E,IAAAA,KAAK,EAAE+B;AAV8B,GAAzC;AAaA,SAAO;AACHmC,IAAAA,QAAQ,EAARA,QADG;AAEHE,IAAAA,KAAK,EAALA,KAFG;AAGHG,IAAAA,IAAI,EAAJA,IAHG;AAIHI,IAAAA,OAAO,EAAE;AACLxD,MAAAA,IAAI,EAAJA,IADK;AAELyD,MAAAA,YAAY,EAAExD;AAFT;AAJN,GAAP;AAUH;;;;"}
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
2
2
|
import { forwardRef, createElement } from 'react';
|
3
3
|
import cn from 'classnames';
|
4
|
-
import { IconButton } from '../IconButton/IconButton.js';
|
5
4
|
import { useLocalization } from '../Provider/Provider.js';
|
5
|
+
import { Popover } from '../Popover/Popover.js';
|
6
|
+
import { IconButton } from '../IconButton/IconButton.js';
|
6
7
|
import { Calendar } from '../Calendar/Calendar.js';
|
7
8
|
import { Input } from '../Input/Input.js';
|
8
9
|
import { useDatepicker } from './useDatepicker.js';
|
9
|
-
import { Popover } from '../Popover/Popover.js';
|
10
10
|
|
11
11
|
var _excluded = ["className", "onReset", "style", "shortcuts", "shortcutsText"];
|
12
12
|
var Datepicker = /*#__PURE__*/forwardRef(function Datepicker(props, ref) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Context.js","sources":["../../../../../src/components/Dialog/Context.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-function */\nimport * as React from 'react';\nimport { DialogSize } from './types';\n\nexport type DialogContext = {\n draggable: boolean;\n drawer?: {\n open: boolean;\n toggle: () => void;\n };\n elements: {\n drawer?: React.ReactNode;\n extra?: React.ReactNode;\n };\n close: () => void;\n onClose?: () => void;\n props: {};\n size: DialogSize;\n};\n\nexport const DialogContext = React.createContext<DialogContext>({\n close: () => {},\n draggable: false,\n drawer: undefined,\n elements: {\n drawer: undefined,\n extra: undefined,\n },\n onClose: () => {},\n props: {},\n size: 'sm',\n});\n\nexport const useCurrentDialog = () => {\n return React.useContext(DialogContext);\n};\n"],"names":["DialogContext","React","close","draggable","drawer","undefined","elements","extra","onClose","props","size","useCurrentDialog"],"mappings":";;AAAA;
|
1
|
+
{"version":3,"file":"Context.js","sources":["../../../../../src/components/Dialog/Context.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-function */\nimport * as React from 'react';\nimport { DialogSize } from './types';\n\nexport type DialogContext = {\n draggable: boolean;\n drawer?: {\n open: boolean;\n toggle: () => void;\n };\n elements: {\n drawer?: React.ReactNode;\n extra?: React.ReactNode;\n };\n close: () => void;\n onClose?: () => void;\n props: {};\n ref: React.Ref<HTMLElement>;\n size: DialogSize;\n};\n\nexport const DialogContext = React.createContext<DialogContext>({\n close: () => {},\n draggable: false,\n drawer: undefined,\n elements: {\n drawer: undefined,\n extra: undefined,\n },\n onClose: () => {},\n props: {},\n ref: null,\n size: 'sm',\n});\n\nexport const useCurrentDialog = () => {\n return React.useContext(DialogContext);\n};\n"],"names":["DialogContext","React","close","draggable","drawer","undefined","elements","extra","onClose","props","ref","size","useCurrentDialog"],"mappings":";;AAAA;IAqBaA,aAAa,gBAAGC,aAAA,CAAmC;AAC5DC,EAAAA,KAAK,EAAE,mBADqD;AAE5DC,EAAAA,SAAS,EAAE,KAFiD;AAG5DC,EAAAA,MAAM,EAAEC,SAHoD;AAI5DC,EAAAA,QAAQ,EAAE;AACNF,IAAAA,MAAM,EAAEC,SADF;AAENE,IAAAA,KAAK,EAAEF;AAFD,GAJkD;AAQ5DG,EAAAA,OAAO,EAAE,qBARmD;AAS5DC,EAAAA,KAAK,EAAE,EATqD;AAU5DC,EAAAA,GAAG,EAAE,IAVuD;AAW5DC,EAAAA,IAAI,EAAE;AAXsD,CAAnC;IAchBC,gBAAgB,GAAG,SAAnBA,gBAAmB;AAC5B,SAAOX,UAAA,CAAiBD,aAAjB,CAAP;AACH;;;;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
2
|
-
import { useMemo, Children, useState, createElement } from 'react';
|
2
|
+
import { forwardRef, useMemo, Children, useState, createElement } from 'react';
|
3
3
|
import { Root } from '@radix-ui/react-dialog';
|
4
4
|
import { DialogContext } from './Context.js';
|
5
5
|
import { Trigger } from './components/Trigger.js';
|
@@ -27,7 +27,7 @@ var useSeparatedChildren = function useSeparatedChildren(initialChildren) {
|
|
27
27
|
}, [initialChildren]);
|
28
28
|
};
|
29
29
|
|
30
|
-
var Dialog = function
|
30
|
+
var Dialog = /*#__PURE__*/forwardRef(function (props, ref) {
|
31
31
|
var initialChildren = props.children,
|
32
32
|
_props$draggable = props.draggable,
|
33
33
|
draggable = _props$draggable === void 0 ? false : _props$draggable,
|
@@ -70,7 +70,8 @@ var Dialog = function Dialog(props) {
|
|
70
70
|
},
|
71
71
|
onClose: onClose,
|
72
72
|
props: otherProps,
|
73
|
-
size: size
|
73
|
+
size: size,
|
74
|
+
ref: ref
|
74
75
|
};
|
75
76
|
}, [open, drawerOpen, drawer, extra, otherProps]);
|
76
77
|
return createElement(DialogContext.Provider, {
|
@@ -80,7 +81,7 @@ var Dialog = function Dialog(props) {
|
|
80
81
|
open: open,
|
81
82
|
onOpenChange: setOpen
|
82
83
|
}));
|
83
|
-
};
|
84
|
+
});
|
84
85
|
Dialog.Trigger = Trigger;
|
85
86
|
Dialog.Content = Content;
|
86
87
|
Dialog.Title = Title;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Dialog.js","sources":["../../../../../src/components/Dialog/Dialog.tsx"],"sourcesContent":["import * as React from 'react';\nimport * as DialogPrimitive from '@radix-ui/react-dialog';\nimport './Dialog.css';\nimport { Trigger } from './components/Trigger';\nimport {
|
1
|
+
{"version":3,"file":"Dialog.js","sources":["../../../../../src/components/Dialog/Dialog.tsx"],"sourcesContent":["import * as React from 'react';\nimport * as DialogPrimitive from '@radix-ui/react-dialog';\nimport './Dialog.css';\nimport { DialogTriggerProps, Trigger } from './components/Trigger';\nimport {\n Content,\n Title,\n Footer,\n Close,\n DialogContentProps,\n DialogTitleProps,\n DialogFooterProps,\n DialogCloseProps,\n} from './components/Content';\nimport { DialogDrawerProps, Drawer } from './components/Drawer';\nimport { DialogExtraProps, Extra } from './components/Extra';\nimport { DialogContext } from './Context';\nimport { DialogSize } from './types';\n\nexport { DialogContentProps, DialogTitleProps, DialogFooterProps, DialogCloseProps };\n\nexport type DialogTexts = {\n /**\n * Aria-label for close icon button in dialog.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n close: string;\n drag: string;\n};\n\nexport type DialogProps = {\n children: React.ReactNode | React.ReactNode[];\n /** Allows dragging the dialog around the screen (window constrained) */\n draggable?: boolean;\n /** Handler called when dialog closes by user interaction */\n onClose?: () => void;\n /** Set whether the dialog is open by default or not, use when not providing a trigger */\n open?: boolean;\n /** Size of the dialog. This is the recommended way to set a size for dialog component. */\n size?: DialogSize;\n};\n\nconst useSeparatedChildren = initialChildren => {\n return React.useMemo(() => {\n const children: any[] = [];\n let drawer;\n let extra;\n\n React.Children.forEach(initialChildren, (child: any) => {\n if (child.type.displayName === 'Drawer') {\n drawer = child;\n } else if (child.type.displayName === 'Extra') {\n extra = child;\n } else {\n children.push(child);\n }\n });\n\n return [children, drawer, extra];\n }, [initialChildren]);\n};\n\nexport type ForwardedDialogWithStatics = React.ForwardRefExoticComponent<DialogProps & React.RefAttributes<HTMLElement>> & {\n Trigger: React.ForwardRefExoticComponent<DialogTriggerProps>;\n Content: React.ForwardRefExoticComponent<DialogContentProps>;\n Title: React.ForwardRefExoticComponent<DialogTitleProps>;\n Footer: React.ForwardRefExoticComponent<DialogFooterProps>;\n Extra: React.ForwardRefExoticComponent<DialogExtraProps>;\n Drawer: React.ForwardRefExoticComponent<DialogDrawerProps>;\n Close: React.ForwardRefExoticComponent<DialogCloseProps>;\n};\n\nexport const Dialog = React.forwardRef((props: DialogProps, ref: React.Ref<HTMLElement>): JSX.Element => {\n const { children: initialChildren, draggable = false, onClose, open: defaultOpen, size = 'sm', ...otherProps } = props;\n const [children, drawer, extra] = useSeparatedChildren(initialChildren);\n\n const [open, setOpen] = React.useState(defaultOpen);\n const [drawerOpen, setDrawerOpen] = React.useState(false);\n\n const context = React.useMemo(\n () => ({\n close: () => setOpen(false),\n draggable,\n drawer: {\n open: drawerOpen,\n toggle: () => setDrawerOpen(isDrawerOpen => !isDrawerOpen),\n },\n elements: {\n drawer,\n extra,\n },\n onClose,\n props: otherProps,\n size,\n ref,\n }),\n [open, drawerOpen, drawer, extra, otherProps]\n );\n\n return (\n <DialogContext.Provider value={context}>\n <DialogPrimitive.Root children={children} open={open} onOpenChange={setOpen} />\n </DialogContext.Provider>\n );\n}) as ForwardedDialogWithStatics;\n\nDialog.Trigger = Trigger;\nDialog.Content = Content;\nDialog.Title = Title;\nDialog.Footer = Footer;\nDialog.Extra = Extra;\nDialog.Drawer = Drawer;\nDialog.Close = Close;\n"],"names":["useSeparatedChildren","initialChildren","React","children","drawer","extra","forEach","child","type","displayName","push","Dialog","props","ref","draggable","onClose","defaultOpen","open","size","otherProps","setOpen","drawerOpen","setDrawerOpen","context","close","toggle","isDrawerOpen","elements","DialogContext","Provider","value","DialogPrimitive","onOpenChange","Trigger","Content","Title","Footer","Extra","Drawer","Close"],"mappings":";;;;;;;;;;;AA0CA,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAuB,CAAAC,eAAe;AACxC,SAAOC,OAAA,CAAc;AACjB,QAAMC,QAAQ,GAAU,EAAxB;AACA,QAAIC,MAAJ;AACA,QAAIC,KAAJ;AAEAH,IAAAA,QAAA,CAAeI,OAAf,CAAuBL,eAAvB,EAAwC,UAACM,KAAD;AACpC,UAAIA,KAAK,CAACC,IAAN,CAAWC,WAAX,KAA2B,QAA/B,EAAyC;AACrCL,QAAAA,MAAM,GAAGG,KAAT;AACH,OAFD,MAEO,IAAIA,KAAK,CAACC,IAAN,CAAWC,WAAX,KAA2B,OAA/B,EAAwC;AAC3CJ,QAAAA,KAAK,GAAGE,KAAR;AACH,OAFM,MAEA;AACHJ,QAAAA,QAAQ,CAACO,IAAT,CAAcH,KAAd;AACH;AACJ,KARD;AAUA,WAAO,CAACJ,QAAD,EAAWC,MAAX,EAAmBC,KAAnB,CAAP;AACH,GAhBM,EAgBJ,CAACJ,eAAD,CAhBI,CAAP;AAiBH,CAlBD;;IA8BaU,MAAM,gBAAGT,UAAA,CAAiB,UAACU,KAAD,EAAqBC,GAArB;AACnC,MAAkBZ,eAAlB,GAAiHW,KAAjH,CAAQT,QAAR;AAAA,yBAAiHS,KAAjH,CAAmCE,SAAnC;AAAA,MAAmCA,SAAnC,iCAA+C,KAA/C;AA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AwBC,IAAAA,KAAK,EAAEP;GAA/B,EACIrB,aAAA,CAAC6B,IAAD;AAAsB5B,IAAAA,QAAQ,EAAEA;AAAUc,IAAAA,IAAI,EAAEA;AAAMe,IAAAA,YAAY,EAAEZ;GAApE,CADJ,CADJ;AAKH,CAhCqB;AAkCtBT,MAAM,CAACsB,OAAP,GAAiBA,OAAjB;AACAtB,MAAM,CAACuB,OAAP,GAAiBA,OAAjB;AACAvB,MAAM,CAACwB,KAAP,GAAeA,KAAf;AACAxB,MAAM,CAACyB,MAAP,GAAgBA,MAAhB;AACAzB,MAAM,CAAC0B,KAAP,GAAeA,KAAf;AACA1B,MAAM,CAAC2B,MAAP,GAAgBA,MAAhB;AACA3B,MAAM,CAAC4B,KAAP,GAAeA,KAAf;;;;"}
|
@@ -1,14 +1,15 @@
|
|
1
1
|
import { extends as _extends } from '../../../../_virtual/_rollupPluginBabelHelpers.js';
|
2
2
|
import { forwardRef, createElement } from 'react';
|
3
3
|
import cn from 'classnames';
|
4
|
-
import {
|
4
|
+
import { Backdrop } from '../../Backdrop/Backdrop.js';
|
5
5
|
import { useLocalization } from '../../Provider/Provider.js';
|
6
|
-
import { useProxiedRef } from '../../../utils/hooks/useProxiedRef.js';
|
7
6
|
import { Title as Title$1, Close as Close$1, Portal, Overlay, Content as Content$1 } from '@radix-ui/react-dialog';
|
8
7
|
import { useCurrentDialog } from '../Context.js';
|
8
|
+
import { useProxiedRef } from '../../../utils/hooks/useProxiedRef.js';
|
9
9
|
import { useDraggable } from '../../../utils/hooks/useDraggable.js';
|
10
10
|
import { useCurrentMenu } from '../../Menu/Context.js';
|
11
11
|
import { Group } from '../../Group/Group.js';
|
12
|
+
import { IconButton } from '../../IconButton/IconButton.js';
|
12
13
|
|
13
14
|
var Title = /*#__PURE__*/forwardRef(function DialogTitle(props, ref) {
|
14
15
|
return createElement(Title$1, Object.assign({}, props, {
|
@@ -18,7 +19,7 @@ var Title = /*#__PURE__*/forwardRef(function DialogTitle(props, ref) {
|
|
18
19
|
});
|
19
20
|
var Footer = /*#__PURE__*/forwardRef(function DialogFooter(props, ref) {
|
20
21
|
return createElement("div", Object.assign({}, props, {
|
21
|
-
className: "flex justify-end
|
22
|
+
className: "mt-8 flex justify-end",
|
22
23
|
ref: ref
|
23
24
|
}), createElement(Group, null, props.children));
|
24
25
|
});
|
@@ -53,17 +54,16 @@ var Content = /*#__PURE__*/forwardRef(function DialogContent(props, ref) {
|
|
53
54
|
};
|
54
55
|
}
|
55
56
|
|
56
|
-
var className = cn('bg-white rounded
|
57
|
+
var className = cn('bg-white rounded mt-16 mx-auto', {
|
57
58
|
'w-128 text-center justify-center': dialog.size === 'dialog',
|
58
59
|
'w-xs': dialog.size === 'xs',
|
59
60
|
'w-sm': dialog.size === 'sm',
|
60
61
|
'w-md': dialog.size === 'md',
|
61
62
|
'w-lg': dialog.size === 'lg'
|
62
63
|
});
|
63
|
-
var containerClassName = cn('
|
64
|
+
var containerClassName = cn('bg-white p-6 rounded relative z-[999]', 'shadow-[0_6px_9px_0_rgba(89,85,98,0.3),0_0_1px_0_rgba(89,85,98,0.2)]', {
|
64
65
|
'rounded-b-none': !!dialog.elements.extra
|
65
|
-
}, props.className);
|
66
|
-
var overlayClassName = cn('fixed inset-0 cursor-default overflow-y-auto bg-[rgba(50,46,62,0.8)] animate-[fade-in_150ms] aria-hidden:hidden'); // the chosen behaviour in taco is that outside clicks do not close the dialog
|
66
|
+
}, props.className); // the chosen behaviour in taco is that outside clicks do not close the dialog
|
67
67
|
|
68
68
|
var handleInteractOutside = function handleInteractOutside(event) {
|
69
69
|
return event.preventDefault();
|
@@ -81,10 +81,9 @@ var Content = /*#__PURE__*/forwardRef(function DialogContent(props, ref) {
|
|
81
81
|
}
|
82
82
|
|
83
83
|
return createElement(Portal, null, createElement(Overlay, {
|
84
|
-
|
85
|
-
}, createElement(Content$1, Object.assign({}, props, {
|
84
|
+
asChild: true
|
85
|
+
}, createElement(Backdrop, null, createElement(Content$1, Object.assign({}, props, {
|
86
86
|
className: className,
|
87
|
-
"data-taco": "dialog",
|
88
87
|
onEscapeKeyDown: dialog.onClose,
|
89
88
|
onInteractOutside: handleInteractOutside,
|
90
89
|
onCloseAutoFocus: handleCloseAutoFocus,
|
@@ -94,10 +93,11 @@ var Content = /*#__PURE__*/forwardRef(function DialogContent(props, ref) {
|
|
94
93
|
top: dialog.draggable ? "calc(50% + " + position.y + "px)" : undefined
|
95
94
|
})
|
96
95
|
}), createElement("div", {
|
97
|
-
className: containerClassName
|
96
|
+
className: containerClassName,
|
97
|
+
"data-taco": "dialog"
|
98
98
|
}, output, dialog.draggable && createElement("div", Object.assign({}, dragHandleProps, {
|
99
99
|
"aria-label": texts.dialog.drag,
|
100
|
-
className: "yt-dialog__drag absolute-center-x
|
100
|
+
className: "yt-dialog__drag absolute-center-x bg-grey-light top-1.5 h-3 w-24 cursor-move rounded text-center"
|
101
101
|
})), createElement(Close$1, {
|
102
102
|
asChild: true,
|
103
103
|
onClick: dialog.onClose
|
@@ -106,7 +106,7 @@ var Content = /*#__PURE__*/forwardRef(function DialogContent(props, ref) {
|
|
106
106
|
"aria-label": texts.dialog.close,
|
107
107
|
className: "absolute top-0 right-0 mt-2 mr-2",
|
108
108
|
icon: "close"
|
109
|
-
}))), dialog.elements.drawer, dialog.elements.extra)));
|
109
|
+
}))), dialog.elements.drawer, dialog.elements.extra))));
|
110
110
|
});
|
111
111
|
|
112
112
|
export { Close, Content, Footer, Title };
|