@economic/taco 0.0.28-alpha.0 → 0.0.30-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/Combobox/Combobox.d.ts +0 -3
- package/dist/components/Datepicker/Datepicker.d.ts +1 -1
- package/dist/components/Field/Field.d.ts +2 -5
- package/dist/components/Input/Input.d.ts +2 -5
- package/dist/components/Input/util.d.ts +1 -3
- package/dist/components/Listbox/Listbox.d.ts +3 -7
- package/dist/components/Listbox/ScrollableList.d.ts +2 -5
- package/dist/components/Listbox/useListbox.d.ts +1 -1
- package/dist/components/SearchInput/SearchInput.d.ts +1 -1
- package/dist/components/Select/Select.d.ts +1 -1
- package/dist/components/Textarea/Textarea.d.ts +2 -5
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +19 -1
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/dist/esm/components/Badge/Badge.js +14 -14
- package/dist/esm/components/Badge/Badge.js.map +1 -1
- package/dist/esm/components/Banner/Banner.js +5 -7
- package/dist/esm/components/Banner/Banner.js.map +1 -1
- package/dist/esm/components/Button/Button.js +13 -12
- package/dist/esm/components/Button/Button.js.map +1 -1
- package/dist/esm/components/Calendar/Calendar.js +71 -56
- package/dist/esm/components/Calendar/Calendar.js.map +1 -1
- package/dist/esm/components/Checkbox/Checkbox.js +18 -15
- package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Combobox/Combobox.js +25 -23
- package/dist/esm/components/Combobox/Combobox.js.map +1 -1
- package/dist/esm/components/Dialog/Dialog.js +58 -39
- package/dist/esm/components/Dialog/Dialog.js.map +1 -1
- package/dist/esm/components/Field/Field.js +15 -16
- package/dist/esm/components/Field/Field.js.map +1 -1
- package/dist/esm/components/Input/Input.js +2 -2
- package/dist/esm/components/Input/Input.js.map +1 -1
- package/dist/esm/components/Input/util.js +8 -36
- package/dist/esm/components/Input/util.js.map +1 -1
- package/dist/esm/components/Listbox/Listbox.js.map +1 -1
- package/dist/esm/components/Listbox/ScrollableList.js +1 -1
- package/dist/esm/components/Listbox/ScrollableList.js.map +1 -1
- package/dist/esm/components/Listbox/useListbox.js +2 -0
- package/dist/esm/components/Listbox/useListbox.js.map +1 -1
- package/dist/esm/components/Select/Select.js +2 -1
- package/dist/esm/components/Select/Select.js.map +1 -1
- package/dist/esm/components/Select/useSelect.js +4 -1
- package/dist/esm/components/Select/useSelect.js.map +1 -1
- package/dist/esm/components/Table/components/BaseTable.js +1 -1
- package/dist/esm/components/Table/components/BaseTable.js.map +1 -1
- package/dist/esm/components/Textarea/Textarea.js +1 -1
- package/dist/esm/components/Textarea/Textarea.js.map +1 -1
- package/dist/esm/index.css +19 -0
- package/dist/index.css +19 -0
- package/dist/taco.cjs.development.js +252 -226
- 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/tailwind.d.ts +1 -1
- package/package.json +16 -16
- package/types.json +17 -33
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Dialog.js","sources":["../../../../src/components/Dialog/Dialog.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport * as DialogPrimitive from '@radix-ui/react-dialog';\r\nimport './Dialog.css';\r\nimport { DialogTriggerProps, Trigger } from './components/Trigger';\r\nimport {\r\n Content,\r\n Title,\r\n Footer,\r\n Close,\r\n DialogContentProps,\r\n DialogContentRenderProps,\r\n DialogContentDrawerRenderProps,\r\n DialogTitleProps,\r\n DialogFooterProps,\r\n DialogCloseProps,\r\n} from './components/Content';\r\nimport { DialogDrawerProps, DialogDrawerRenderProps, Drawer } from './components/Drawer';\r\nimport { DialogExtraProps, Extra } from './components/Extra';\r\nimport { DialogContext } from './Context';\r\nimport { DialogSize } from './types';\r\n\r\nexport {\r\n DialogCloseProps,\r\n DialogContentDrawerRenderProps,\r\n DialogContentProps,\r\n DialogContentRenderProps,\r\n DialogDrawerProps,\r\n DialogDrawerRenderProps,\r\n DialogFooterProps,\r\n DialogSize,\r\n DialogTitleProps,\r\n};\r\n\r\nexport type DialogTexts = {\r\n /**\r\n * Aria-label for close icon button in dialog.\r\n * To read more about how to provide the text, see [Provider](component:provider) component\r\n */\r\n close: string;\r\n drag: string;\r\n};\r\n\r\nexport type DialogProps = {\r\n children: React.ReactNode | React.ReactNode[];\r\n /** When `true`, pressing escape will close the dialog */\r\n closeOnEscape?: boolean;\r\n /** Set whether the dialog is open by default or not, use when not providing a trigger */\r\n defaultOpen?: boolean;\r\n /** Allows dragging the dialog around the screen (window constrained) */\r\n draggable?: boolean;\r\n /** Handler called when dialog closes by user interaction */\r\n onClose?: () => void;\r\n /** Called when the dialog opens or closes, must be used in conjunction with open */\r\n onChange?: (open: boolean) => void;\r\n /** Control the open state of the dialog from outside the component */\r\n open?: boolean;\r\n /** Shows the close icon button of the dialog */\r\n showCloseButton?: boolean;\r\n /** Size of the dialog. This is the recommended way to set a size for dialog component. */\r\n size?: DialogSize;\r\n /** A trigger to be used for the dialog, should not be set if `children` already contains a trigger */\r\n trigger?: JSX.Element;\r\n};\r\n\r\nconst useSeparatedChildren = initialChildren => {\r\n return React.useMemo(() => {\r\n const children: any[] = [];\r\n let drawer;\r\n let extra;\r\n\r\n React.Children.toArray(initialChildren).forEach((child: any) => {\r\n if (child.type?.displayName === Drawer.displayName) {\r\n drawer = child;\r\n } else if (child.type?.displayName === Extra.displayName) {\r\n extra = child;\r\n } else {\r\n children.push(child);\r\n }\r\n });\r\n\r\n return [children, drawer, extra];\r\n }, [initialChildren]);\r\n};\r\n\r\nexport type ForwardedDialogWithStatics = React.ForwardRefExoticComponent<DialogProps & React.RefAttributes<HTMLElement>> & {\r\n Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>;\r\n Content: React.ForwardRefExoticComponent<DialogContentProps & React.RefAttributes<HTMLDivElement>>;\r\n Title: React.ForwardRefExoticComponent<DialogTitleProps & React.RefAttributes<HTMLHeadingElement>>;\r\n Footer: React.ForwardRefExoticComponent<DialogFooterProps & React.RefAttributes<HTMLDivElement>>;\r\n Extra: React.ForwardRefExoticComponent<DialogExtraProps & React.RefAttributes<HTMLDivElement>>;\r\n Drawer: React.ForwardRefExoticComponent<DialogDrawerProps & React.RefAttributes<HTMLDivElement>>;\r\n Close: React.ForwardRefExoticComponent<DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;\r\n};\r\n\r\nexport const Dialog = React.forwardRef(function Dialog(props: DialogProps, ref: React.Ref<HTMLElement>) {\r\n const {\r\n children: initialChildren,\r\n closeOnEscape = true,\r\n defaultOpen,\r\n draggable = false,\r\n onChange,\r\n onClose,\r\n open,\r\n showCloseButton = true,\r\n size = 'sm',\r\n trigger,\r\n ...otherProps\r\n } = props;\r\n const [children, drawer, extra] = useSeparatedChildren(initialChildren);\r\n const [drawerOpen, setDrawerOpen] = React.useState(false);\r\n\r\n const context = React.useMemo(\r\n () => ({\r\n closeOnEscape,\r\n draggable,\r\n drawer: {\r\n open: drawerOpen,\r\n toggle: () => setDrawerOpen(isDrawerOpen => !isDrawerOpen),\r\n },\r\n elements: {\r\n drawer,\r\n extra,\r\n },\r\n onClose,\r\n props: otherProps,\r\n showCloseButton,\r\n size,\r\n ref,\r\n }),\r\n [closeOnEscape, drawerOpen, draggable, drawer, extra, open, otherProps, showCloseButton]\r\n );\r\n\r\n return (\r\n <DialogContext.Provider value={context}>\r\n <DialogPrimitive.Root defaultOpen={defaultOpen} open={open} onOpenChange={onChange}>\r\n {trigger && <Trigger>{trigger}</Trigger>}\r\n {children}\r\n </DialogPrimitive.Root>\r\n </DialogContext.Provider>\r\n );\r\n}) as ForwardedDialogWithStatics;\r\n\r\nDialog.Trigger = Trigger;\r\nDialog.Content = Content;\r\nDialog.Title = Title;\r\nDialog.Footer = Footer;\r\nDialog.Extra = Extra;\r\nDialog.Drawer = Drawer;\r\nDialog.Close = Close;\r\n"],"names":["useSeparatedChildren","initialChildren","React","children","drawer","extra","toArray","forEach","child","type","displayName","Drawer","Extra","push","Dialog","props","ref","closeOnEscape","defaultOpen","draggable","onChange","onClose","open","showCloseButton","size","trigger","otherProps","drawerOpen","setDrawerOpen","context","toggle","isDrawerOpen","elements","DialogContext","Provider","value","DialogPrimitive","onOpenChange","Trigger","Content","Title","Footer","Close"],"mappings":"
|
1
|
+
{"version":3,"file":"Dialog.js","sources":["../../../../src/components/Dialog/Dialog.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport * as DialogPrimitive from '@radix-ui/react-dialog';\r\nimport './Dialog.css';\r\nimport { DialogTriggerProps, Trigger } from './components/Trigger';\r\nimport {\r\n Content,\r\n Title,\r\n Footer,\r\n Close,\r\n DialogContentProps,\r\n DialogContentRenderProps,\r\n DialogContentDrawerRenderProps,\r\n DialogTitleProps,\r\n DialogFooterProps,\r\n DialogCloseProps,\r\n} from './components/Content';\r\nimport { DialogDrawerProps, DialogDrawerRenderProps, Drawer } from './components/Drawer';\r\nimport { DialogExtraProps, Extra } from './components/Extra';\r\nimport { DialogContext } from './Context';\r\nimport { DialogSize } from './types';\r\n\r\nexport {\r\n DialogCloseProps,\r\n DialogContentDrawerRenderProps,\r\n DialogContentProps,\r\n DialogContentRenderProps,\r\n DialogDrawerProps,\r\n DialogDrawerRenderProps,\r\n DialogFooterProps,\r\n DialogSize,\r\n DialogTitleProps,\r\n};\r\n\r\nexport type DialogTexts = {\r\n /**\r\n * Aria-label for close icon button in dialog.\r\n * To read more about how to provide the text, see [Provider](component:provider) component\r\n */\r\n close: string;\r\n drag: string;\r\n};\r\n\r\nexport type DialogProps = {\r\n children: React.ReactNode | React.ReactNode[];\r\n /** When `true`, pressing escape will close the dialog */\r\n closeOnEscape?: boolean;\r\n /** Set whether the dialog is open by default or not, use when not providing a trigger */\r\n defaultOpen?: boolean;\r\n /** Allows dragging the dialog around the screen (window constrained) */\r\n draggable?: boolean;\r\n /** Handler called when dialog closes by user interaction */\r\n onClose?: () => void;\r\n /** Called when the dialog opens or closes, must be used in conjunction with open */\r\n onChange?: (open: boolean) => void;\r\n /** Control the open state of the dialog from outside the component */\r\n open?: boolean;\r\n /** Shows the close icon button of the dialog */\r\n showCloseButton?: boolean;\r\n /** Size of the dialog. This is the recommended way to set a size for dialog component. */\r\n size?: DialogSize;\r\n /** A trigger to be used for the dialog, should not be set if `children` already contains a trigger */\r\n trigger?: JSX.Element;\r\n};\r\n\r\nconst useSeparatedChildren = initialChildren => {\r\n return React.useMemo(() => {\r\n const children: any[] = [];\r\n let drawer;\r\n let extra;\r\n\r\n React.Children.toArray(initialChildren).forEach((child: any) => {\r\n if (child.type?.displayName === Drawer.displayName) {\r\n drawer = child;\r\n } else if (child.type?.displayName === Extra.displayName) {\r\n extra = child;\r\n } else {\r\n children.push(child);\r\n }\r\n });\r\n\r\n return [children, drawer, extra];\r\n }, [initialChildren]);\r\n};\r\n\r\nexport type ForwardedDialogWithStatics = React.ForwardRefExoticComponent<DialogProps & React.RefAttributes<HTMLElement>> & {\r\n Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>;\r\n Content: React.ForwardRefExoticComponent<DialogContentProps & React.RefAttributes<HTMLDivElement>>;\r\n Title: React.ForwardRefExoticComponent<DialogTitleProps & React.RefAttributes<HTMLHeadingElement>>;\r\n Footer: React.ForwardRefExoticComponent<DialogFooterProps & React.RefAttributes<HTMLDivElement>>;\r\n Extra: React.ForwardRefExoticComponent<DialogExtraProps & React.RefAttributes<HTMLDivElement>>;\r\n Drawer: React.ForwardRefExoticComponent<DialogDrawerProps & React.RefAttributes<HTMLDivElement>>;\r\n Close: React.ForwardRefExoticComponent<DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;\r\n};\r\n\r\nexport const Dialog = React.forwardRef(function Dialog(props: DialogProps, ref: React.Ref<HTMLElement>) {\r\n const {\r\n children: initialChildren,\r\n closeOnEscape = true,\r\n defaultOpen,\r\n draggable = false,\r\n onChange,\r\n onClose,\r\n open,\r\n showCloseButton = true,\r\n size = 'sm',\r\n trigger,\r\n ...otherProps\r\n } = props;\r\n const [children, drawer, extra] = useSeparatedChildren(initialChildren);\r\n const [drawerOpen, setDrawerOpen] = React.useState(false);\r\n\r\n const context = React.useMemo(\r\n () => ({\r\n closeOnEscape,\r\n draggable,\r\n drawer: {\r\n open: drawerOpen,\r\n toggle: () => setDrawerOpen(isDrawerOpen => !isDrawerOpen),\r\n },\r\n elements: {\r\n drawer,\r\n extra,\r\n },\r\n onClose,\r\n props: otherProps,\r\n showCloseButton,\r\n size,\r\n ref,\r\n }),\r\n [closeOnEscape, drawerOpen, draggable, drawer, extra, open, otherProps, showCloseButton]\r\n );\r\n\r\n return (\r\n <DialogContext.Provider value={context}>\r\n <DialogPrimitive.Root defaultOpen={defaultOpen} open={open} onOpenChange={onChange}>\r\n {trigger && <Trigger>{trigger}</Trigger>}\r\n {children}\r\n </DialogPrimitive.Root>\r\n </DialogContext.Provider>\r\n );\r\n}) as ForwardedDialogWithStatics;\r\n\r\nDialog.Trigger = Trigger;\r\nDialog.Content = Content;\r\nDialog.Title = Title;\r\nDialog.Footer = Footer;\r\nDialog.Extra = Extra;\r\nDialog.Drawer = Drawer;\r\nDialog.Close = Close;\r\n"],"names":["useSeparatedChildren","initialChildren","React","children","drawer","extra","toArray","forEach","child","type","displayName","Drawer","Extra","push","Dialog","props","ref","closeOnEscape","defaultOpen","draggable","onChange","onClose","open","showCloseButton","size","trigger","otherProps","drawerOpen","setDrawerOpen","context","toggle","isDrawerOpen","elements","DialogContext","Provider","value","DialogPrimitive","onOpenChange","Trigger","Content","Title","Footer","Close"],"mappings":";;;;;;;;;;;AAgEA,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,EAAwCM,OAAxC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iBA,OAAjB;AACAzB,MAAM,CAAC0B,KAAP,GAAeA,KAAf;AACA1B,MAAM,CAAC2B,MAAP,GAAgBA,MAAhB;AACA3B,MAAM,CAACF,KAAP,GAAeA,KAAf;AACAE,MAAM,CAACH,MAAP,GAAgBA,MAAhB;AACAG,MAAM,CAAC4B,KAAP,GAAeA,KAAf;;;;"}
|
@@ -1,23 +1,22 @@
|
|
1
|
+
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
1
2
|
import { forwardRef, createElement } from 'react';
|
2
3
|
import cn from 'classnames';
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
var _excluded = ["disabled", "children", "invalid", "message"];
|
6
|
+
var Field = /*#__PURE__*/forwardRef(function Field(props, ref) {
|
7
|
+
var disabled = props.disabled,
|
8
|
+
children = props.children,
|
9
|
+
_props$invalid = props.invalid,
|
10
|
+
invalid = _props$invalid === void 0 ? false : _props$invalid,
|
11
|
+
message = props.message,
|
12
|
+
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
13
|
+
|
14
|
+
var className = cn('flex flex-col font-bold text-xs leading-loose pb-4 min-h-[theme(spacing.18)]', {
|
13
15
|
'text-grey-dark': disabled
|
14
16
|
}, props.className);
|
15
|
-
|
16
|
-
'text-grey-darkest': !
|
17
|
-
'text-red':
|
18
|
-
'text-green': state === 'success',
|
19
|
-
'text-blue': state === 'information',
|
20
|
-
'text-yellow-dark': state === 'warning',
|
17
|
+
var messageClassName = cn('h-4 text-xs text-left leading-normal font-normal truncate -mb-4', {
|
18
|
+
'text-grey-darkest': !invalid,
|
19
|
+
'text-red': invalid,
|
21
20
|
'opacity-50': disabled
|
22
21
|
}, props.className);
|
23
22
|
return createElement("label", Object.assign({}, otherProps, {
|
@@ -26,7 +25,7 @@ const Field = /*#__PURE__*/forwardRef(function Field(props, ref) {
|
|
26
25
|
ref: ref
|
27
26
|
}), children, message && createElement("span", {
|
28
27
|
className: messageClassName,
|
29
|
-
role:
|
28
|
+
role: invalid ? 'alert' : undefined
|
30
29
|
}, message));
|
31
30
|
});
|
32
31
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Field.js","sources":["../../../../src/components/Field/Field.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\n\r\nimport
|
1
|
+
{"version":3,"file":"Field.js","sources":["../../../../src/components/Field/Field.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\n\r\nimport './Field.css';\r\n\r\nexport type FieldProps = React.LabelHTMLAttributes<HTMLLabelElement> & {\r\n /** Content of the field */\r\n children: React.ReactNode;\r\n /**\tChanges the style to indicate the element is disabled */\r\n disabled?: boolean;\r\n /* Whether the input is in an invalid state */\r\n invalid?: boolean;\r\n /**\r\n * Text displayed below the children of Field.\r\n * Should be a short text that indicates feedback for user.\r\n */\r\n message?: string;\r\n};\r\n\r\nexport const Field = React.forwardRef(function Field(props: FieldProps, ref: React.Ref<HTMLLabelElement>) {\r\n const { disabled, children, invalid = false, message, ...otherProps } = props;\r\n const className = cn(\r\n 'flex flex-col font-bold text-xs leading-loose pb-4 min-h-[theme(spacing.18)]',\r\n {\r\n 'text-grey-dark': disabled,\r\n },\r\n props.className\r\n );\r\n const messageClassName = cn(\r\n 'h-4 text-xs text-left leading-normal font-normal truncate -mb-4',\r\n {\r\n 'text-grey-darkest': !invalid,\r\n 'text-red': invalid,\r\n 'opacity-50': disabled,\r\n },\r\n props.className\r\n );\r\n\r\n return (\r\n <label {...otherProps} className={className} data-taco=\"label\" ref={ref}>\r\n {children}\r\n {message && (\r\n <span className={messageClassName} role={invalid ? 'alert' : undefined}>\r\n {message}\r\n </span>\r\n )}\r\n </label>\r\n );\r\n});\r\n"],"names":["Field","React","props","ref","disabled","children","invalid","message","otherProps","className","cn","messageClassName","role","undefined"],"mappings":";;;;;IAmBaA,KAAK,gBAAGC,UAAA,CAAiB,SAASD,KAAT,CAAeE,KAAf,EAAkCC,GAAlC;AAClC,MAAQC,QAAR,GAAwEF,KAAxE,CAAQE,QAAR;AAAA,MAAkBC,QAAlB,GAAwEH,KAAxE,CAAkBG,QAAlB;AAAA,uBAAwEH,KAAxE,CAA4BI,OAA5B;AAAA,MAA4BA,OAA5B,+BAAsC,KAAtC;AAAA,MAA6CC,OAA7C,GAAwEL,KAAxE,CAA6CK,OAA7C;AAAA,MAAyDC,UAAzD,iCAAwEN,KAAxE;;AACA,MAAMO,SAAS,GAAGC,EAAE,CAChB,8EADgB,EAEhB;AACI,sBAAkBN;AADtB,GAFgB,EAKhBF,KAAK,CAACO,SALU,CAApB;AAOA,MAAME,gBAAgB,GAAGD,EAAE,CACvB,iEADuB,EAEvB;AACI,yBAAqB,CAACJ,OAD1B;AAEI,gBAAYA,OAFhB;AAGI,kBAAcF;AAHlB,GAFuB,EAOvBF,KAAK,CAACO,SAPiB,CAA3B;AAUA,SACIR,aAAA,QAAA,oBAAWO;AAAYC,IAAAA,SAAS,EAAEA;iBAAqB;AAAQN,IAAAA,GAAG,EAAEA;IAApE,EACKE,QADL,EAEKE,OAAO,IACJN,aAAA,OAAA;AAAMQ,IAAAA,SAAS,EAAEE;AAAkBC,IAAAA,IAAI,EAAEN,OAAO,GAAG,OAAH,GAAaO;GAA7D,EACKN,OADL,CAHR,CADJ;AAUH,CA7BoB;;;;"}
|
@@ -9,8 +9,8 @@ const Input = /*#__PURE__*/forwardRef(function Input(props, ref) {
|
|
9
9
|
button,
|
10
10
|
icon,
|
11
11
|
highlighted,
|
12
|
+
invalid,
|
12
13
|
onKeyDown,
|
13
|
-
state,
|
14
14
|
autoFocus,
|
15
15
|
...otherProps
|
16
16
|
} = props;
|
@@ -54,7 +54,7 @@ const Input = /*#__PURE__*/forwardRef(function Input(props, ref) {
|
|
54
54
|
|
55
55
|
const disabled = (_button$props$disable = button.props.disabled) !== null && _button$props$disable !== void 0 ? _button$props$disable : otherProps.disabled;
|
56
56
|
const buttonClassName = cn('items-center flex justify-center border absolute rounded-l-none rounded-r right-0 h-full focus:rounded focus:outline-none', {
|
57
|
-
[getButtonStateClasses(
|
57
|
+
[getButtonStateClasses(invalid)]: !props.disabled
|
58
58
|
}, button.props.className);
|
59
59
|
extra = cloneElement(button, {
|
60
60
|
className: buttonClassName,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Input.js","sources":["../../../../src/components/Input/Input.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport {
|
1
|
+
{"version":3,"file":"Input.js","sources":["../../../../src/components/Input/Input.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport { Icon, IconName } from '../Icon/Icon';\r\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\r\nimport { getButtonStateClasses, getInputClasses } from './util';\r\n\r\nexport type InputProps = React.InputHTMLAttributes<HTMLInputElement> & {\r\n /** Shows a button within the input field */\r\n button?: React.ReactElement;\r\n /** Shows an icon within the input field */\r\n icon?: IconName | JSX.Element;\r\n /** Draws attention to the input by changing its style and making it visually prominent */\r\n highlighted?: boolean;\r\n /* Whether the input is in an invalid state */\r\n invalid?: boolean;\r\n};\r\n\r\nexport const Input = React.forwardRef(function Input(props: InputProps, ref: React.Ref<HTMLInputElement>) {\r\n const { button, icon, highlighted, invalid, onKeyDown, autoFocus, ...otherProps } = props;\r\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\r\n const hasContainer = button || icon;\r\n const className = cn(\r\n getInputClasses(props),\r\n 'min-h-[theme(spacing.8)] pointer-events-all',\r\n {\r\n 'pr-8': !!hasContainer,\r\n },\r\n !hasContainer && otherProps.className\r\n );\r\n\r\n React.useEffect(() => {\r\n if (autoFocus && inputRef.current) {\r\n inputRef.current.focus();\r\n }\r\n }, []);\r\n\r\n // home and end keys only navigate to the start/end of input value if the input container does not scroll\r\n // if it has scroll height then the browser reverts to native scrolling behaviour only\r\n // so we manually override it to ensure _our_ desired behaviour remains intact\r\n const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\r\n if (event.key === 'Home' || event.key === 'End') {\r\n event.preventDefault();\r\n const position = event.key === 'End' ? event.currentTarget.value.length : 0;\r\n event.currentTarget.setSelectionRange(position, position);\r\n }\r\n\r\n if (onKeyDown) {\r\n onKeyDown(event);\r\n }\r\n };\r\n\r\n const input = <input {...otherProps} className={className} data-taco=\"input\" onKeyDown={handleKeyDown} ref={inputRef} />;\r\n\r\n if (hasContainer) {\r\n let extra: any;\r\n\r\n if (button) {\r\n const disabled = button.props.disabled ?? otherProps.disabled;\r\n const buttonClassName = cn(\r\n 'items-center flex justify-center border absolute rounded-l-none rounded-r right-0 h-full focus:rounded focus:outline-none',\r\n {\r\n [getButtonStateClasses(invalid)]: !props.disabled,\r\n },\r\n button.props.className\r\n );\r\n extra = React.cloneElement(button, {\r\n className: buttonClassName,\r\n disabled,\r\n });\r\n } else if (icon) {\r\n const iconClassName = cn(\r\n 'items-center flex justify-center absolute pointer-events-none mr-1 p-px right-0 w-5 top-1/2 -translate-y-1/2',\r\n {\r\n 'text-grey-dark': props.disabled,\r\n 'text-grey-darkest': !props.disabled,\r\n }\r\n );\r\n extra =\r\n typeof icon === 'string' ? (\r\n <Icon className={iconClassName} name={icon} />\r\n ) : (\r\n React.cloneElement(icon, { className: cn(iconClassName, icon.props.className) })\r\n );\r\n }\r\n\r\n const containerClassName = cn('bg-white inline-flex relative rounded w-full', otherProps.className);\r\n\r\n return (\r\n <div className={containerClassName} data-taco=\"input-container\">\r\n {input}\r\n {extra}\r\n </div>\r\n );\r\n }\r\n\r\n return input;\r\n});\r\n"],"names":["Input","React","props","ref","button","icon","highlighted","invalid","onKeyDown","autoFocus","otherProps","inputRef","useProxiedRef","hasContainer","className","cn","getInputClasses","current","focus","handleKeyDown","event","key","preventDefault","position","currentTarget","value","length","setSelectionRange","input","extra","disabled","buttonClassName","getButtonStateClasses","iconClassName","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8B;KAA9C,EACKR,KADL,EAEKC,KAFL,CADJ;AAMH;;AAED,SAAOD,KAAP;AACH,CA/EoB;;;;"}
|
@@ -4,47 +4,19 @@ const getInputClasses = props => {
|
|
4
4
|
return cn('peer bg-white text-black text-sm border font-normal not-italic no-underline rounded inline-flex leading-6 px-2 relative w-full text-ellipsis flex items-center', {
|
5
5
|
'cursor-not-allowed text-black bg-grey': props.readOnly,
|
6
6
|
'border-grey text-opacity-25 cursor-not-allowed': props.disabled,
|
7
|
-
[getStateClasses(props.state)]: !props.disabled,
|
8
7
|
'bg-[rgba(255,255,0,0.075)]': props.highlighted && props.disabled,
|
9
|
-
'bg-[rgba(255,255,0,0.2)]': props.highlighted && !props.disabled
|
8
|
+
'bg-[rgba(255,255,0,0.2)]': props.highlighted && !props.disabled,
|
9
|
+
'border-grey-dark hover:shadow-[0_0_0.1rem_theme(colors.grey.darker)] focus:border-blue-light focus:yt-focus active:border-blue-dark': !props.invalid,
|
10
|
+
'border-red hover:shadow-[0_0_0.15rem_theme(colors.red.DEFAULT)] focus:border-red-light focus:yt-focus-red active:border-red-dark': props.invalid
|
10
11
|
});
|
11
12
|
};
|
12
|
-
const
|
13
|
-
|
14
|
-
|
15
|
-
return 'border-green hover:shadow-[0_0_0.15rem_theme(colors.green.DEFAULT)] focus:border-green-light focus:yt-focus-green active:border-green-dark';
|
16
|
-
|
17
|
-
case 'error':
|
18
|
-
return 'border-red hover:shadow-[0_0_0.15rem_theme(colors.red.DEFAULT)] focus:border-red-light focus:yt-focus-red active:border-red-dark';
|
19
|
-
|
20
|
-
case 'warning':
|
21
|
-
return 'border-yellow-dark hover:shadow-[0_0_0.15rem_theme(colors.yellow.dark)] focus:yt-focus-yellow active:border-yellow-dark';
|
22
|
-
|
23
|
-
case 'information':
|
24
|
-
return 'border-blue hover:shadow-[0_0_0.15rem_theme(colors.blue.dark)] focus:border-blue-light focus:yt-focus active:border-blue-dark';
|
25
|
-
|
26
|
-
default:
|
27
|
-
return 'border-grey-dark hover:shadow-[0_0_0.1rem_theme(colors.grey.darker)] focus:border-blue-light focus:yt-focus active:border-blue-dark';
|
13
|
+
const getButtonStateClasses = invalid => {
|
14
|
+
if (invalid) {
|
15
|
+
return '!border-red focus:!border-red-light focus:yt-focus-red peer-focus:!border-red-light peer-focus:peer-active:!border-red-dark';
|
28
16
|
}
|
29
|
-
};
|
30
|
-
const getButtonStateClasses = value => {
|
31
|
-
switch (value) {
|
32
|
-
case 'success':
|
33
|
-
return '!border-green focus:!border-green-light focus:yt-focus-green peer-focus:!border-green-light peer-focus:peer-active:!border-green-dark';
|
34
17
|
|
35
|
-
|
36
|
-
return '!border-red focus:!border-red-light focus:yt-focus-red peer-focus:!border-red-light peer-focus:peer-active:!border-red-dark';
|
37
|
-
|
38
|
-
case 'warning':
|
39
|
-
return '!border-yellow-dark focus:!border-yellow-dark focus:yt-focus-yellow peer-focus:peer-active:!border-yellow-dark';
|
40
|
-
|
41
|
-
case 'information':
|
42
|
-
return '!border-blue focus:!border-blue-light peer-focus:!border-blue-light peer-focus:peer-active:!border-blue-dark';
|
43
|
-
|
44
|
-
default:
|
45
|
-
return '!border-grey-dark focus:!border-blue-light peer-focus:!border-blue-light peer-focus:peer-active:!border-blue-dark';
|
46
|
-
}
|
18
|
+
return '!border-grey-dark focus:!border-blue-light peer-focus:!border-blue-light peer-focus:peer-active:!border-blue-dark';
|
47
19
|
};
|
48
20
|
|
49
|
-
export { getButtonStateClasses, getInputClasses
|
21
|
+
export { getButtonStateClasses, getInputClasses };
|
50
22
|
//# sourceMappingURL=util.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"util.js","sources":["../../../../src/components/Input/util.ts"],"sourcesContent":["import cn from 'classnames';\r\
|
1
|
+
{"version":3,"file":"util.js","sources":["../../../../src/components/Input/util.ts"],"sourcesContent":["import cn from 'classnames';\r\n\r\nexport const getInputClasses = props => {\r\n return cn(\r\n 'peer bg-white text-black text-sm border font-normal not-italic no-underline rounded inline-flex leading-6 px-2 relative w-full text-ellipsis flex items-center',\r\n {\r\n 'cursor-not-allowed text-black bg-grey': props.readOnly,\r\n 'border-grey text-opacity-25 cursor-not-allowed': props.disabled,\r\n 'bg-[rgba(255,255,0,0.075)]': props.highlighted && props.disabled,\r\n 'bg-[rgba(255,255,0,0.2)]': props.highlighted && !props.disabled,\r\n 'border-grey-dark hover:shadow-[0_0_0.1rem_theme(colors.grey.darker)] focus:border-blue-light focus:yt-focus active:border-blue-dark':\r\n !props.invalid,\r\n 'border-red hover:shadow-[0_0_0.15rem_theme(colors.red.DEFAULT)] focus:border-red-light focus:yt-focus-red active:border-red-dark':\r\n props.invalid,\r\n }\r\n );\r\n};\r\n\r\nexport const getButtonStateClasses = (invalid: boolean | undefined): string => {\r\n if (invalid) {\r\n return '!border-red focus:!border-red-light focus:yt-focus-red peer-focus:!border-red-light peer-focus:peer-active:!border-red-dark';\r\n }\r\n\r\n return '!border-grey-dark focus:!border-blue-light peer-focus:!border-blue-light peer-focus:peer-active:!border-blue-dark';\r\n};\r\n"],"names":["getInputClasses","props","cn","readOnly","disabled","highlighted","invalid","getButtonStateClasses"],"mappings":";;MAEaA,eAAe,GAAGC,KAAK;AAChC,SAAOC,EAAE,CACL,gKADK,EAEL;AACI,6CAAyCD,KAAK,CAACE,QADnD;AAEI,sDAAkDF,KAAK,CAACG,QAF5D;AAGI,kCAA8BH,KAAK,CAACI,WAAN,IAAqBJ,KAAK,CAACG,QAH7D;AAII,gCAA4BH,KAAK,CAACI,WAAN,IAAqB,CAACJ,KAAK,CAACG,QAJ5D;AAKI,2IACI,CAACH,KAAK,CAACK,OANf;AAOI,wIACIL,KAAK,CAACK;AARd,GAFK,CAAT;AAaH;MAEYC,qBAAqB,GAAID,OAAD;AACjC,MAAIA,OAAJ,EAAa;AACT,WAAO,6HAAP;AACH;;AAED,SAAO,mHAAP;AACH;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Listbox.js","sources":["../../../../src/components/Listbox/Listbox.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport { useListbox } from './useListbox';\r\nimport { useMultiListbox } from './useMultiListbox';\r\nimport { ScrollableList, ScrollableListItemValue, ScrollableListItem } from './ScrollableList';\r\
|
1
|
+
{"version":3,"file":"Listbox.js","sources":["../../../../src/components/Listbox/Listbox.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport { useListbox } from './useListbox';\r\nimport { useMultiListbox } from './useMultiListbox';\r\nimport { ScrollableList, ScrollableListItemValue, ScrollableListItem } from './ScrollableList';\r\n\r\nexport type ListboxItem = ScrollableListItem;\r\nexport type ListboxValue = ScrollableListItemValue;\r\n\r\nexport type ListboxTexts = {\r\n /**\r\n * Text displayed in the listbox if no data provided.\r\n * To read more about how to provide the text, see [Provider](component:provider) component\r\n */\r\n empty: string;\r\n /**\r\n * Text displayed in the listbox to indicate the data is loading.\r\n * Read more about how to provide the text in [Provider](component:provider) component\r\n */\r\n loading: string;\r\n /**\r\n * The first option displayed in a multiselect listbox that selects all available options.\r\n * Read more about how to provide the text in [Provider](component:provider) component\r\n */\r\n allOption: string;\r\n};\r\n\r\nexport type ListboxProps = Pick<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'onFocus'> &\r\n Omit<React.InputHTMLAttributes<HTMLElement>, 'defaultValue' | 'onChange' | 'value'> & {\r\n /** Data indicating the options in listbox */\r\n data?: ListboxItem[];\r\n /**\r\n * Initial value of the listbox.\r\n * This is used when listbox is mounted, if no value is provided.\r\n * *Note* that listbox is a controlled component, setting this will also trigger the `onChange` event\r\n */\r\n defaultValue?: ListboxValue;\r\n /** Set what value should have an empty option in listbox */\r\n emptyValue?: ListboxValue;\r\n /** Draws attention to the listbox by changing its style and making it visually prominent */\r\n highlighted?: boolean;\r\n /* Whether the input is in an invalid state */\r\n invalid?: boolean;\r\n /**\r\n * Shows a loading indicator with a text next to it.\r\n * Read more about how to provide the text in [Provider](component:provider) component\r\n */\r\n loading?: boolean;\r\n /**\r\n * Value of the listbox representing the selected item.\r\n * It needs to be an existing value from the provided data\r\n */\r\n value?: ListboxValue;\r\n };\r\n\r\nexport const Listbox = React.forwardRef(function Listbox(props: ListboxProps, ref: React.Ref<HTMLInputElement>) {\r\n const { className: externalClassName, ...otherProps } = props;\r\n const { list, input } = useListbox(otherProps, ref);\r\n const className = cn('bg-white inline-flex relative w-full', externalClassName);\r\n\r\n return (\r\n <span data-taco=\"listbox\" className={className}>\r\n <ScrollableList\r\n {...list}\r\n style={{ ...list.style, maxHeight: 'calc(12rem + 2px)' /* (6 * option height) + listbox border */ }}\r\n />\r\n <input {...input} className=\"hidden\" type=\"text\" />\r\n </span>\r\n );\r\n});\r\n\r\nexport const MultiListbox = React.forwardRef(function Listbox(props: ListboxProps, ref: React.Ref<HTMLInputElement>) {\r\n const { className: externalClassName, ...otherProps } = props;\r\n const { list, input } = useMultiListbox(otherProps, ref);\r\n const className = cn('bg-white inline-flex relative w-full', externalClassName);\r\n\r\n return (\r\n <span data-taco=\"listbox\" className={className}>\r\n <ScrollableList\r\n {...list}\r\n style={{\r\n ...list.style,\r\n maxHeight: 'calc(12rem + 2px + 2px)' /* (6 * option height) + listbox border + ALL_OPTIONS bottom border */,\r\n }}\r\n />\r\n <input {...input} className=\"hidden\" type=\"text\" />\r\n </span>\r\n );\r\n});\r\n"],"names":["Listbox","React","props","ref","className","externalClassName","otherProps","list","input","useListbox","cn","ScrollableList","style","maxHeight","type","MultiListbox","useMultiListbox"],"mappings":";;;;;;MAuDaA,OAAO,gBAAGC,UAAA,CAAiB,SAASD,OAAT,CAAiBE,KAAjB,EAAsCC,GAAtC;AACpC,QAAM;AAAEC,IAAAA,SAAS,EAAEC,iBAAb;AAAgC,OAAGC;AAAnC,MAAkDJ,KAAxD;AACA,QAAM;AAAEK,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAkBC,UAAU,CAACH,UAAD,EAAaH,GAAb,CAAlC;AACA,QAAMC,SAAS,GAAGM,EAAE,CAAC,sCAAD,EAAyCL,iBAAzC,CAApB;AAEA,SACIJ,aAAA,OAAA;iBAAgB;AAAUG,IAAAA,SAAS,EAAEA;GAArC,EACIH,aAAA,CAACU,cAAD,oBACQJ;AACJK,IAAAA,KAAK,EAAE,EAAE,GAAGL,IAAI,CAACK,KAAV;AAAiBC,MAAAA,SAAS,EAAE;AAAoB;;AAAhD;IAFX,CADJ,EAKIZ,aAAA,QAAA,oBAAWO;AAAOJ,IAAAA,SAAS,EAAC;AAASU,IAAAA,IAAI,EAAC;IAA1C,CALJ,CADJ;AASH,CAdsB;MAgBVC,YAAY,gBAAGd,UAAA,CAAiB,SAASD,OAAT,CAAiBE,KAAjB,EAAsCC,GAAtC;AACzC,QAAM;AAAEC,IAAAA,SAAS,EAAEC,iBAAb;AAAgC,OAAGC;AAAnC,MAAkDJ,KAAxD;AACA,QAAM;AAAEK,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAkBQ,eAAe,CAACV,UAAD,EAAaH,GAAb,CAAvC;AACA,QAAMC,SAAS,GAAGM,EAAE,CAAC,sCAAD,EAAyCL,iBAAzC,CAApB;AAEA,SACIJ,aAAA,OAAA;iBAAgB;AAAUG,IAAAA,SAAS,EAAEA;GAArC,EACIH,aAAA,CAACU,cAAD,oBACQJ;AACJK,IAAAA,KAAK,EAAE,EACH,GAAGL,IAAI,CAACK,KADL;AAEHC,MAAAA,SAAS,EAAE;AAA0B;;AAFlC;IAFX,CADJ,EAQIZ,aAAA,QAAA,oBAAWO;AAAOJ,IAAAA,SAAS,EAAC;AAASU,IAAAA,IAAI,EAAC;IAA1C,CARJ,CADJ;AAYH,CAjB2B;;;;"}
|
@@ -30,6 +30,7 @@ const ScrollableList = /*#__PURE__*/forwardRef(function ScrollableList(props, re
|
|
30
30
|
disabled,
|
31
31
|
highlighted,
|
32
32
|
id,
|
33
|
+
invalid: _,
|
33
34
|
loading,
|
34
35
|
onChange: setCurrentIndex,
|
35
36
|
onClick,
|
@@ -37,7 +38,6 @@ const ScrollableList = /*#__PURE__*/forwardRef(function ScrollableList(props, re
|
|
37
38
|
onKeyDown,
|
38
39
|
readOnly,
|
39
40
|
scrollOnFocus = false,
|
40
|
-
state,
|
41
41
|
value: currentIndex,
|
42
42
|
multiselect,
|
43
43
|
selectedIndexes = [],
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ScrollableList.js","sources":["../../../../src/components/Listbox/ScrollableList.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\r\nimport { getNextIndexFromKeycode } from '../../utils/hooks/useListKeyboardNavigation';\r\nimport { useListScrollTo } from '../../utils/hooks/useListScrollTo';\r\nimport './ScrollableList.css';\r\nimport { Spinner } from '../Spinner/Spinner';\r\nimport { useLocalization } from '../Provider/Provider';\r\nimport { State } from '../../types';\r\nimport { Checkbox } from '../Checkbox/Checkbox';\r\nimport { getInputClasses } from '../Input/util';\r\n\r\nexport type ScrollableListItemValue = string | number | boolean | null;\r\n\r\nexport type ScrollableListItem = {\r\n /**\r\n * Set whether the item is disabled.\r\n * This will both change the style and make the item unselectable\r\n */\r\n disabled?: boolean;\r\n /* Specifies whether the item has child items -- intended for internal use only */\r\n hasChildren?: boolean;\r\n /** Place an icon before the item's text */\r\n icon?: React.ReactElement;\r\n /* The index path to the item -- intended for internal use only */\r\n path?: string;\r\n /** Text describing the item */\r\n text: string | JSX.Element;\r\n /** Value of the item */\r\n value: ScrollableListItemValue;\r\n /** Child items to show hierarchical data */\r\n children?: ScrollableListItem[];\r\n};\r\n\r\n/** @internal */\r\nexport type ScrollableListProps = Omit<\r\n React.HTMLAttributes<HTMLUListElement>,\r\n 'defaultValue' | 'id' | 'onChange' | 'onClick' | 'onKeyDown'\r\n> & {\r\n /** Data indicating the options in scrollable list */\r\n data: ScrollableListItem[];\r\n /** Sets the list to be disabled */\r\n disabled?: boolean;\r\n /** Draws attention to the scrollable list by changing its style and making it visually prominent */\r\n highlighted?: boolean;\r\n /** Set an id for the scrollable list */\r\n id: string;\r\n /**\r\n * Shows a loading indicator with a text next to it.\r\n * Read more about how to provide the text in `Provider` component.\r\n */\r\n loading?: boolean;\r\n /**\r\n * Handler called when current active/selected option changes in a scrollable list.\r\n * @param index indicates the index of the current active option\r\n */\r\n onChange: (index: number) => void;\r\n /** Handler called when option is clicked */\r\n onClick?: (event: React.MouseEvent<HTMLLIElement>, index: number) => void;\r\n /**\r\n * Set whether the selected item should be scrolled into view when listbox is focused.\r\n * Default value is `false`\r\n */\r\n scrollOnFocus?: boolean;\r\n /** Handler called when a key is pressed */\r\n onKeyDown?: (event: React.KeyboardEvent<HTMLUListElement>, index: number | undefined) => void;\r\n /* Sets the list to read only mode */\r\n readOnly?: boolean;\r\n /** State will change the style of the scrollable list */\r\n state?: State;\r\n /**\r\n * Value of the scrollable list representing the selected item.\r\n * It needs to be an existing value from the provided data.\r\n */\r\n value: number | undefined;\r\n /**\r\n * Allows to select multiple items from the list\r\n */\r\n multiselect?: boolean;\r\n /**\r\n * Contains the currently selected values when multiselect mode is ON.\r\n */\r\n selectedIndexes?: number[];\r\n /**\r\n * True when all available (not disabled) options are selected\r\n */\r\n allOptionsSelected?: boolean;\r\n};\r\n\r\n/** @internal */\r\nexport type ScrollableListPropsWithRef = ScrollableListProps & React.RefAttributes<HTMLUListElement>;\r\n\r\nexport const getId = (id: string, value: ScrollableListItemValue): string => `${id}_${value}`;\r\n\r\nconst getNextEnabledItem = (\r\n event: React.KeyboardEvent<HTMLElement>,\r\n data: ScrollableListItem[],\r\n index: number | undefined\r\n): number | undefined => {\r\n const nextIndex = getNextIndexFromKeycode(event.keyCode, data.length, index);\r\n\r\n if (nextIndex) {\r\n if (nextIndex === index) {\r\n return index;\r\n } else if (data[nextIndex] && data[nextIndex].disabled) {\r\n return getNextEnabledItem(event, data, nextIndex);\r\n }\r\n }\r\n\r\n return nextIndex;\r\n};\r\n\r\nexport const ScrollableList = React.forwardRef(function ScrollableList(\r\n props: ScrollableListProps,\r\n ref: React.Ref<HTMLUListElement>\r\n) {\r\n const {\r\n data,\r\n disabled,\r\n highlighted,\r\n id,\r\n loading,\r\n onChange: setCurrentIndex,\r\n onClick,\r\n onFocus,\r\n onKeyDown,\r\n readOnly,\r\n scrollOnFocus = false,\r\n state,\r\n value: currentIndex,\r\n multiselect,\r\n selectedIndexes = [],\r\n allOptionsSelected = false,\r\n ...otherProps\r\n } = props;\r\n const listRef = useProxiedRef<HTMLUListElement>(ref);\r\n const itemRefs = React.useMemo(() => data.map(() => React.createRef<HTMLLIElement>()), [data]);\r\n const { texts } = useLocalization();\r\n const { scrollTo } = useListScrollTo(listRef, itemRefs);\r\n\r\n React.useEffect(() => {\r\n if (currentIndex && itemRefs[currentIndex]?.current) {\r\n itemRefs[currentIndex].current?.scrollIntoView({\r\n block: 'center',\r\n });\r\n }\r\n }, []);\r\n\r\n React.useEffect(() => {\r\n scrollTo(currentIndex);\r\n }, [currentIndex]);\r\n\r\n const handleKeyDown = (event: React.KeyboardEvent<HTMLUListElement>): void => {\r\n const nextIndex = getNextEnabledItem(event, data, currentIndex);\r\n\r\n if (nextIndex !== undefined && nextIndex !== currentIndex) {\r\n event.preventDefault();\r\n scrollTo(nextIndex);\r\n setCurrentIndex(nextIndex);\r\n }\r\n\r\n if (onKeyDown) {\r\n event.persist();\r\n const index = nextIndex !== undefined ? nextIndex : currentIndex;\r\n onKeyDown(event, index);\r\n }\r\n };\r\n\r\n const handleClick = (index: number) => (event: React.MouseEvent<HTMLLIElement>) => {\r\n setCurrentIndex(index);\r\n\r\n if (onClick) {\r\n event.persist();\r\n onClick(event, index);\r\n }\r\n };\r\n\r\n const handleFocus = (event: React.FocusEvent<HTMLUListElement>): void => {\r\n if (scrollOnFocus) {\r\n scrollTo(currentIndex);\r\n }\r\n\r\n if (onFocus) {\r\n event.persist();\r\n onFocus(event);\r\n }\r\n };\r\n\r\n const getOptionCheckedState = (optionValue: string, index: number): boolean => {\r\n if (optionValue === '#ALL-OPTIONS#') {\r\n return allOptionsSelected;\r\n } else if (!optionValue || !selectedIndexes) {\r\n return false;\r\n } else {\r\n return selectedIndexes.findIndex(i => i === index) !== -1;\r\n }\r\n };\r\n\r\n const list: React.HTMLAttributes<HTMLUListElement> &\r\n React.RefAttributes<HTMLUListElement> & { disabled?: boolean; readOnly?: boolean } = {\r\n ...otherProps,\r\n className: cn(\r\n 'inline-flex flex-col list-none !p-0 m-0 overflow-y-auto h-auto',\r\n getInputClasses(props),\r\n {\r\n 'yt-list--multiselect': multiselect,\r\n 'pointer-events-none': disabled,\r\n 'cursor-not-allowed': disabled || readOnly,\r\n },\r\n otherProps.className\r\n ),\r\n disabled,\r\n id,\r\n onFocus: !disabled && !readOnly ? handleFocus : undefined,\r\n onKeyDown: !disabled && !readOnly ? handleKeyDown : undefined,\r\n readOnly,\r\n ref: listRef,\r\n role: 'listbox',\r\n tabIndex: otherProps.tabIndex || 0,\r\n };\r\n\r\n const options = data.map((option, index) => {\r\n const depth = option.path ? option.path.split('.').length - 1 : 0;\r\n\r\n return {\r\n 'aria-selected': multiselect ? getOptionCheckedState(String(option.value), index) : currentIndex === index,\r\n 'data-focused': currentIndex === index,\r\n children: option.text,\r\n className: cn(\r\n 'flex items-center px-3 w-full cursor-pointer bg-white flex-[0_0_2rem] focus:wcag-blue focus:border-blue',\r\n {\r\n 'sticky top-0 font-bold': depth === 0 && !!option.hasChildren,\r\n }\r\n ),\r\n disabled: option.disabled,\r\n icon: option.icon,\r\n id: getId(id, option.value),\r\n key: getId(id, option.value),\r\n onClick: !disabled && !readOnly ? handleClick(index) : undefined,\r\n ref: itemRefs[index],\r\n role: 'option',\r\n style:\r\n depth > 0\r\n ? {\r\n paddingLeft: `${depth + 1}rem`,\r\n }\r\n : undefined,\r\n };\r\n });\r\n\r\n return (\r\n <ul {...list} data-taco=\"scrollable-list\">\r\n {loading ? (\r\n <li className=\"yt-list__empty\">\r\n <span>\r\n <Spinner delay={0} />\r\n </span>\r\n <span>{texts.listbox.loading}</span>\r\n </li>\r\n ) : options.length ? (\r\n options.map(({ children, icon, ...optionProps }) => (\r\n <li {...optionProps}>\r\n {icon}\r\n <span className=\"flex-grow truncate text-left\">{children}</span>\r\n {multiselect && (\r\n <Checkbox\r\n checked={optionProps['aria-selected']}\r\n onChange={() => null}\r\n className=\"pointer-events-none ml-2 flex items-center justify-end overflow-visible p-px\"\r\n />\r\n )}\r\n </li>\r\n ))\r\n ) : (\r\n <li className=\"yt-list__empty\">\r\n <span>{texts.listbox.empty}</span>\r\n </li>\r\n )}\r\n </ul>\r\n );\r\n});\r\n"],"names":["getId","id","value","getNextEnabledItem","event","data","index","nextIndex","getNextIndexFromKeycode","keyCode","length","disabled","ScrollableList","React","props","ref","highlighted","loading","onChange","setCurrentIndex","onClick","onFocus","onKeyDown","readOnly","scrollOnFocus","state","currentIndex","multiselect","selectedIndexes","allOptionsSelected","otherProps","listRef","useProxiedRef","itemRefs","map","texts","useLocalization","scrollTo","useListScrollTo","current","scrollIntoView","block","handleKeyDown","undefined","preventDefault","persist","handleClick","handleFocus","getOptionCheckedState","optionValue","findIndex","i","list","className","cn","getInputClasses","role","tabIndex","options","option","depth","path","split","String","children","text","hasChildren","icon","key","style","paddingLeft","Spinner","delay","listbox","optionProps","Checkbox","checked","empty"],"mappings":";;;;;;;;;;MA4FaA,KAAK,GAAG,CAACC,EAAD,EAAaC,KAAb,QAA2DD,MAAMC;;AAEtF,MAAMC,kBAAkB,GAAG,CACvBC,KADuB,EAEvBC,IAFuB,EAGvBC,KAHuB;AAKvB,QAAMC,SAAS,GAAGC,uBAAuB,CAACJ,KAAK,CAACK,OAAP,EAAgBJ,IAAI,CAACK,MAArB,EAA6BJ,KAA7B,CAAzC;;AAEA,MAAIC,SAAJ,EAAe;AACX,QAAIA,SAAS,KAAKD,KAAlB,EAAyB;AACrB,aAAOA,KAAP;AACH,KAFD,MAEO,IAAID,IAAI,CAACE,SAAD,CAAJ,IAAmBF,IAAI,CAACE,SAAD,CAAJ,CAAgBI,Q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AD,KACR7D,aAAA,KAAA,oBAAQ6D,YAAR,EACKP,IADL,EAEItD,aAAA,OAAA;AAAMwC,IAAAA,SAAS,EAAC;GAAhB,EAAgDW,QAAhD,CAFJ,EAGKrC,WAAW,IACRd,aAAA,CAAC8D,QAAD;AACIC,IAAAA,OAAO,EAAEF,WAAW,CAAC,eAAD;AACpBxD,IAAAA,QAAQ,EAAE,MAAM;AAChBmC,IAAAA,SAAS,EAAC;GAHd,CAJR,CADJ,CADA,GAeAxC,aAAA,KAAA;AAAIwC,IAAAA,SAAS,EAAC;GAAd,EACIxC,aAAA,OAAA,MAAA,EAAOsB,KAAK,CAACsC,OAAN,CAAcI,KAArB,CADJ,CAvBR,CADJ;AA8BH,CAxK6B;;;;"}
|
1
|
+
{"version":3,"file":"ScrollableList.js","sources":["../../../../src/components/Listbox/ScrollableList.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\r\nimport { getNextIndexFromKeycode } from '../../utils/hooks/useListKeyboardNavigation';\r\nimport { useListScrollTo } from '../../utils/hooks/useListScrollTo';\r\nimport './ScrollableList.css';\r\nimport { Spinner } from '../Spinner/Spinner';\r\nimport { useLocalization } from '../Provider/Provider';\r\nimport { Checkbox } from '../Checkbox/Checkbox';\r\nimport { getInputClasses } from '../Input/util';\r\n\r\nexport type ScrollableListItemValue = string | number | boolean | null;\r\n\r\nexport type ScrollableListItem = {\r\n /**\r\n * Set whether the item is disabled.\r\n * This will both change the style and make the item unselectable\r\n */\r\n disabled?: boolean;\r\n /* Specifies whether the item has child items -- intended for internal use only */\r\n hasChildren?: boolean;\r\n /** Place an icon before the item's text */\r\n icon?: React.ReactElement;\r\n /* The index path to the item -- intended for internal use only */\r\n path?: string;\r\n /** Text describing the item */\r\n text: string | JSX.Element;\r\n /** Value of the item */\r\n value: ScrollableListItemValue;\r\n /** Child items to show hierarchical data */\r\n children?: ScrollableListItem[];\r\n};\r\n\r\n/** @internal */\r\nexport type ScrollableListProps = Omit<\r\n React.HTMLAttributes<HTMLUListElement>,\r\n 'defaultValue' | 'id' | 'onChange' | 'onClick' | 'onKeyDown'\r\n> & {\r\n /** Data indicating the options in scrollable list */\r\n data: ScrollableListItem[];\r\n /** Sets the list to be disabled */\r\n disabled?: boolean;\r\n /** Draws attention to the scrollable list by changing its style and making it visually prominent */\r\n highlighted?: boolean;\r\n /** Set an id for the scrollable list */\r\n id: string;\r\n /* Whether the input is in an invalid state */\r\n invalid?: boolean;\r\n /**\r\n * Shows a loading indicator with a text next to it.\r\n * Read more about how to provide the text in `Provider` component.\r\n */\r\n loading?: boolean;\r\n /**\r\n * Handler called when current active/selected option changes in a scrollable list.\r\n * @param index indicates the index of the current active option\r\n */\r\n onChange: (index: number) => void;\r\n /** Handler called when option is clicked */\r\n onClick?: (event: React.MouseEvent<HTMLLIElement>, index: number) => void;\r\n /**\r\n * Set whether the selected item should be scrolled into view when listbox is focused.\r\n * Default value is `false`\r\n */\r\n scrollOnFocus?: boolean;\r\n /** Handler called when a key is pressed */\r\n onKeyDown?: (event: React.KeyboardEvent<HTMLUListElement>, index: number | undefined) => void;\r\n /* Sets the list to read only mode */\r\n readOnly?: boolean;\r\n /**\r\n * Value of the scrollable list representing the selected item.\r\n * It needs to be an existing value from the provided data.\r\n */\r\n value: number | undefined;\r\n /**\r\n * Allows to select multiple items from the list\r\n */\r\n multiselect?: boolean;\r\n /**\r\n * Contains the currently selected values when multiselect mode is ON.\r\n */\r\n selectedIndexes?: number[];\r\n /**\r\n * True when all available (not disabled) options are selected\r\n */\r\n allOptionsSelected?: boolean;\r\n};\r\n\r\n/** @internal */\r\nexport type ScrollableListPropsWithRef = ScrollableListProps & React.RefAttributes<HTMLUListElement>;\r\n\r\nexport const getId = (id: string, value: ScrollableListItemValue): string => `${id}_${value}`;\r\n\r\nconst getNextEnabledItem = (\r\n event: React.KeyboardEvent<HTMLElement>,\r\n data: ScrollableListItem[],\r\n index: number | undefined\r\n): number | undefined => {\r\n const nextIndex = getNextIndexFromKeycode(event.keyCode, data.length, index);\r\n\r\n if (nextIndex) {\r\n if (nextIndex === index) {\r\n return index;\r\n } else if (data[nextIndex] && data[nextIndex].disabled) {\r\n return getNextEnabledItem(event, data, nextIndex);\r\n }\r\n }\r\n\r\n return nextIndex;\r\n};\r\n\r\nexport const ScrollableList = React.forwardRef(function ScrollableList(\r\n props: ScrollableListProps,\r\n ref: React.Ref<HTMLUListElement>\r\n) {\r\n const {\r\n data,\r\n disabled,\r\n highlighted,\r\n id,\r\n invalid: _,\r\n loading,\r\n onChange: setCurrentIndex,\r\n onClick,\r\n onFocus,\r\n onKeyDown,\r\n readOnly,\r\n scrollOnFocus = false,\r\n value: currentIndex,\r\n multiselect,\r\n selectedIndexes = [],\r\n allOptionsSelected = false,\r\n ...otherProps\r\n } = props;\r\n const listRef = useProxiedRef<HTMLUListElement>(ref);\r\n const itemRefs = React.useMemo(() => data.map(() => React.createRef<HTMLLIElement>()), [data]);\r\n const { texts } = useLocalization();\r\n const { scrollTo } = useListScrollTo(listRef, itemRefs);\r\n\r\n React.useEffect(() => {\r\n if (currentIndex && itemRefs[currentIndex]?.current) {\r\n itemRefs[currentIndex].current?.scrollIntoView({\r\n block: 'center',\r\n });\r\n }\r\n }, []);\r\n\r\n React.useEffect(() => {\r\n scrollTo(currentIndex);\r\n }, [currentIndex]);\r\n\r\n const handleKeyDown = (event: React.KeyboardEvent<HTMLUListElement>): void => {\r\n const nextIndex = getNextEnabledItem(event, data, currentIndex);\r\n\r\n if (nextIndex !== undefined && nextIndex !== currentIndex) {\r\n event.preventDefault();\r\n scrollTo(nextIndex);\r\n setCurrentIndex(nextIndex);\r\n }\r\n\r\n if (onKeyDown) {\r\n event.persist();\r\n const index = nextIndex !== undefined ? nextIndex : currentIndex;\r\n onKeyDown(event, index);\r\n }\r\n };\r\n\r\n const handleClick = (index: number) => (event: React.MouseEvent<HTMLLIElement>) => {\r\n setCurrentIndex(index);\r\n\r\n if (onClick) {\r\n event.persist();\r\n onClick(event, index);\r\n }\r\n };\r\n\r\n const handleFocus = (event: React.FocusEvent<HTMLUListElement>): void => {\r\n if (scrollOnFocus) {\r\n scrollTo(currentIndex);\r\n }\r\n\r\n if (onFocus) {\r\n event.persist();\r\n onFocus(event);\r\n }\r\n };\r\n\r\n const getOptionCheckedState = (optionValue: string, index: number): boolean => {\r\n if (optionValue === '#ALL-OPTIONS#') {\r\n return allOptionsSelected;\r\n } else if (!optionValue || !selectedIndexes) {\r\n return false;\r\n } else {\r\n return selectedIndexes.findIndex(i => i === index) !== -1;\r\n }\r\n };\r\n\r\n const list: React.HTMLAttributes<HTMLUListElement> &\r\n React.RefAttributes<HTMLUListElement> & { disabled?: boolean; readOnly?: boolean } = {\r\n ...otherProps,\r\n className: cn(\r\n 'inline-flex flex-col list-none !p-0 m-0 overflow-y-auto h-auto',\r\n getInputClasses(props),\r\n {\r\n 'yt-list--multiselect': multiselect,\r\n 'pointer-events-none': disabled,\r\n 'cursor-not-allowed': disabled || readOnly,\r\n },\r\n otherProps.className\r\n ),\r\n disabled,\r\n id,\r\n onFocus: !disabled && !readOnly ? handleFocus : undefined,\r\n onKeyDown: !disabled && !readOnly ? handleKeyDown : undefined,\r\n readOnly,\r\n ref: listRef,\r\n role: 'listbox',\r\n tabIndex: otherProps.tabIndex || 0,\r\n };\r\n\r\n const options = data.map((option, index) => {\r\n const depth = option.path ? option.path.split('.').length - 1 : 0;\r\n\r\n return {\r\n 'aria-selected': multiselect ? getOptionCheckedState(String(option.value), index) : currentIndex === index,\r\n 'data-focused': currentIndex === index,\r\n children: option.text,\r\n className: cn(\r\n 'flex items-center px-3 w-full cursor-pointer bg-white flex-[0_0_2rem] focus:wcag-blue focus:border-blue',\r\n {\r\n 'sticky top-0 font-bold': depth === 0 && !!option.hasChildren,\r\n }\r\n ),\r\n disabled: option.disabled,\r\n icon: option.icon,\r\n id: getId(id, option.value),\r\n key: getId(id, option.value),\r\n onClick: !disabled && !readOnly ? handleClick(index) : undefined,\r\n ref: itemRefs[index],\r\n role: 'option',\r\n style:\r\n depth > 0\r\n ? {\r\n paddingLeft: `${depth + 1}rem`,\r\n }\r\n : undefined,\r\n };\r\n });\r\n\r\n return (\r\n <ul {...list} data-taco=\"scrollable-list\">\r\n {loading ? (\r\n <li className=\"yt-list__empty\">\r\n <span>\r\n <Spinner delay={0} />\r\n </span>\r\n <span>{texts.listbox.loading}</span>\r\n </li>\r\n ) : options.length ? (\r\n options.map(({ children, icon, ...optionProps }) => (\r\n <li {...optionProps}>\r\n {icon}\r\n <span className=\"flex-grow truncate text-left\">{children}</span>\r\n {multiselect && (\r\n <Checkbox\r\n checked={optionProps['aria-selected']}\r\n onChange={() => null}\r\n className=\"pointer-events-none ml-2 flex items-center justify-end overflow-visible p-px\"\r\n />\r\n )}\r\n </li>\r\n ))\r\n ) : (\r\n <li className=\"yt-list__empty\">\r\n <span>{texts.listbox.empty}</span>\r\n </li>\r\n )}\r\n </ul>\r\n );\r\n});\r\n"],"names":["getId","id","value","getNextEnabledItem","event","data","index","nextIndex","getNextIndexFromKeycode","keyCode","length","disabled","ScrollableList","React","props","ref","highlighted","invalid","_","loading","onChange","setCurrentIndex","onClick","onFocus","onKeyDown","readOnly","scrollOnFocus","currentIndex","multiselect","selectedIndexes","allOptionsSelected","otherProps","listRef","useProxiedRef","itemRefs","map","texts","useLocalization","scrollTo","useListScrollTo","current","scrollIntoView","block","handleKeyDown","undefined","preventDefault","persist","handleClick","handleFocus","getOptionCheckedState","optionValue","findIndex","i","list","className","cn","getInputClasses","role","tabIndex","options","option","depth","path","split","String","children","text","hasChildren","icon","key","style","paddingLeft","Spinner","delay","listbox","optionProps","Checkbox","checked","empty"],"mappings":";;;;;;;;;;MA2FaA,KAAK,GAAG,CAACC,EAAD,EAAaC,KAAb,QAA2DD,MAAMC;;AAEtF,MAAMC,kBAAkB,GAAG,CACvBC,KADuB,EAEvBC,IAFuB,EAGvBC,KAHuB;AAKvB,QAAMC,SAAS,GAAGC,uBA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AA,EACIA,aAAA,CAAC2D,OAAD;AAASC,IAAAA,KAAK,EAAE;GAAhB,CADJ,CADJ,EAII5D,aAAA,OAAA,MAAA,EAAOuB,KAAK,CAACsC,OAAN,CAAcvD,OAArB,CAJJ,CADI,GAOJwC,OAAO,CAACjD,MAAR,GACAiD,OAAO,CAACxB,GAAR,CAAY,CAAC;AAAE8B,IAAAA,QAAF;AAAYG,IAAAA,IAAZ;AAAkB,OAAGO;AAArB,GAAD,KACR9D,aAAA,KAAA,oBAAQ8D,YAAR,EACKP,IADL,EAEIvD,aAAA,OAAA;AAAMyC,IAAAA,SAAS,EAAC;GAAhB,EAAgDW,QAAhD,CAFJ,EAGKrC,WAAW,IACRf,aAAA,CAAC+D,QAAD;AACIC,IAAAA,OAAO,EAAEF,WAAW,CAAC,eAAD;AACpBvD,IAAAA,QAAQ,EAAE,MAAM;AAChBkC,IAAAA,SAAS,EAAC;GAHd,CAJR,CADJ,CADA,GAeAzC,aAAA,KAAA;AAAIyC,IAAAA,SAAS,EAAC;GAAd,EACIzC,aAAA,OAAA,MAAA,EAAOuB,KAAK,CAACsC,OAAN,CAAcI,KAArB,CADJ,CAvBR,CADJ;AA8BH,CAxK6B;;;;"}
|
@@ -10,6 +10,7 @@ const useListbox = ({
|
|
10
10
|
disabled,
|
11
11
|
emptyValue,
|
12
12
|
id: nativeId,
|
13
|
+
invalid,
|
13
14
|
name,
|
14
15
|
onChange,
|
15
16
|
onFocus,
|
@@ -119,6 +120,7 @@ const useListbox = ({
|
|
119
120
|
data,
|
120
121
|
disabled,
|
121
122
|
id,
|
123
|
+
invalid,
|
122
124
|
onChange: handleListboxChange,
|
123
125
|
onFocus: handleListboxFocus,
|
124
126
|
onKeyDown: handleListboxKeyDown,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useListbox.js","sources":["../../../../src/components/Listbox/useListbox.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport { v4 as uuid } from 'uuid';\r\nimport { ListboxProps } from './Listbox';\r\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\r\nimport { setInputValueByRef, getIndexFromValue, findByValue, getActiveDescendant, useFlattenedData, sanitizeItem } from './util';\r\nimport { ScrollableListProps } from './ScrollableList';\r\nimport { useTypeahead } from './useTypeahead';\r\n\r\ntype useListbox = {\r\n list: ScrollableListProps;\r\n input: Omit<React.HTMLAttributes<HTMLInputElement>, 'defaultValue'>;\r\n};\r\n\r\nexport const useListbox = (\r\n {\r\n data: externalData = [],\r\n defaultValue,\r\n disabled,\r\n emptyValue,\r\n id: nativeId,\r\n name,\r\n onChange,\r\n onFocus,\r\n onKeyDown,\r\n value = emptyValue,\r\n ...otherProps\r\n }: ListboxProps,\r\n ref: React.Ref<HTMLInputElement>\r\n): useListbox => {\r\n const data = useFlattenedData(emptyValue !== undefined ? [{ text: '', value: emptyValue }, ...externalData] : externalData);\r\n const id = React.useMemo(() => nativeId || uuid(), [nativeId]);\r\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\r\n const currentIndex = value !== undefined ? getIndexFromValue(data, value) : undefined;\r\n const { getNextIndex } = useTypeahead({ data, currentIndex });\r\n\r\n const setInputValueByIndex = (index: number | undefined): void => {\r\n if (index !== undefined) {\r\n const option = data[index];\r\n\r\n if (option && !option.disabled) {\r\n setInputValueByRef(inputRef.current, option.value);\r\n }\r\n }\r\n };\r\n\r\n const handleListboxChange = (index: number): void => {\r\n setInputValueByIndex(index);\r\n };\r\n\r\n React.useEffect(() => {\r\n if (data.length && currentIndex === undefined) {\r\n if (defaultValue !== undefined) {\r\n const defaultValueIndex = getIndexFromValue(data, defaultValue);\r\n\r\n if (defaultValueIndex !== undefined) {\r\n setInputValueByIndex(defaultValueIndex);\r\n }\r\n } else {\r\n setInputValueByIndex(0);\r\n }\r\n }\r\n }, [data]);\r\n\r\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\r\n const charKey = String.fromCharCode(event.keyCode);\r\n\r\n if (charKey.match(/(\\w)/g)) {\r\n const nextIndex = getNextIndex(charKey);\r\n\r\n if (nextIndex > -1 && nextIndex !== currentIndex) {\r\n setInputValueByIndex(nextIndex);\r\n }\r\n return;\r\n }\r\n\r\n if (onKeyDown) {\r\n event.persist();\r\n onKeyDown(event);\r\n }\r\n };\r\n\r\n const handleListboxFocus = (event: React.FocusEvent<HTMLElement>): void => {\r\n if (currentIndex === undefined && data.length) {\r\n setInputValueByIndex(0);\r\n }\r\n\r\n if (onFocus) {\r\n event.persist();\r\n onFocus(event);\r\n }\r\n };\r\n\r\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\r\n event.persist();\r\n\r\n if (onChange) {\r\n const item = findByValue(data, event.target.value);\r\n (event as any).detail = sanitizeItem(item);\r\n\r\n const indexes = item?.path?.split('.') ?? [];\r\n\r\n if (indexes.length > 1) {\r\n // we don't want to map the current item\r\n indexes.pop();\r\n // we need to rebuild the path as we map\r\n let lastPath: string;\r\n\r\n (event as any).detail.parents = indexes.map(i => {\r\n lastPath = lastPath ? [lastPath, i].join('.') : i;\r\n return sanitizeItem(data.find(i => i.path === lastPath));\r\n });\r\n }\r\n\r\n onChange(event);\r\n }\r\n };\r\n\r\n const list: ScrollableListProps = {\r\n ...otherProps,\r\n 'aria-activedescendant': getActiveDescendant(data, currentIndex, id),\r\n data,\r\n disabled,\r\n id,\r\n onChange: handleListboxChange,\r\n onFocus: handleListboxFocus,\r\n onKeyDown: handleListboxKeyDown,\r\n scrollOnFocus: true,\r\n tabIndex: disabled ? -1 : otherProps.tabIndex ? otherProps.tabIndex : 0,\r\n value: currentIndex,\r\n };\r\n\r\n const input = {\r\n name,\r\n onChange: handleInputChange,\r\n ref: inputRef,\r\n tabIndex: -1,\r\n value: value === undefined || value === null ? '' : value,\r\n };\r\n\r\n return { list, input };\r\n};\r\n"],"names":["useListbox","data","externalData","defaultValue","disabled","emptyValue","id","nativeId","name","onChange","onFocus","onKeyDown","value","otherProps","ref","useFlattenedData","undefined","text","React","uuid","inputRef","useProxiedRef","currentIndex","getIndexFromValue","getNextIndex","useTypeahead","setInputValueByIndex","index","option","setInputValueByRef","current","handleListboxChange","length","defaultValueIndex","handleListboxKeyDown","event","charKey","String","fromCharCode","keyCode","match","nextIndex","persist","handleListboxFocus","handleInputChange","item","findByValue","target","detail","sanitizeItem","indexes","path","split","pop","lastPath","parents","map","i","join","find","list","getActiveDescendant","scrollOnFocus","tabIndex","input"],"mappings":";;;;;;MAaaA,UAAU,GAAG,CACtB;AACIC,EAAAA,IAAI,EAAEC,YAAY,GAAG,EADzB;AAEIC,EAAAA,YAFJ;AAGIC,EAAAA,QAHJ;AAIIC,EAAAA,UAJJ;AAKIC,EAAAA,EAAE,EAAEC,QALR;AAMIC,EAAAA,
|
1
|
+
{"version":3,"file":"useListbox.js","sources":["../../../../src/components/Listbox/useListbox.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport { v4 as uuid } from 'uuid';\r\nimport { ListboxProps } from './Listbox';\r\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\r\nimport { setInputValueByRef, getIndexFromValue, findByValue, getActiveDescendant, useFlattenedData, sanitizeItem } from './util';\r\nimport { ScrollableListProps } from './ScrollableList';\r\nimport { useTypeahead } from './useTypeahead';\r\n\r\ntype useListbox = {\r\n list: ScrollableListProps;\r\n input: Omit<React.HTMLAttributes<HTMLInputElement>, 'defaultValue'>;\r\n};\r\n\r\nexport const useListbox = (\r\n {\r\n data: externalData = [],\r\n defaultValue,\r\n disabled,\r\n emptyValue,\r\n id: nativeId,\r\n invalid,\r\n name,\r\n onChange,\r\n onFocus,\r\n onKeyDown,\r\n value = emptyValue,\r\n ...otherProps\r\n }: ListboxProps,\r\n ref: React.Ref<HTMLInputElement>\r\n): useListbox => {\r\n const data = useFlattenedData(emptyValue !== undefined ? [{ text: '', value: emptyValue }, ...externalData] : externalData);\r\n const id = React.useMemo(() => nativeId || uuid(), [nativeId]);\r\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\r\n const currentIndex = value !== undefined ? getIndexFromValue(data, value) : undefined;\r\n const { getNextIndex } = useTypeahead({ data, currentIndex });\r\n\r\n const setInputValueByIndex = (index: number | undefined): void => {\r\n if (index !== undefined) {\r\n const option = data[index];\r\n\r\n if (option && !option.disabled) {\r\n setInputValueByRef(inputRef.current, option.value);\r\n }\r\n }\r\n };\r\n\r\n const handleListboxChange = (index: number): void => {\r\n setInputValueByIndex(index);\r\n };\r\n\r\n React.useEffect(() => {\r\n if (data.length && currentIndex === undefined) {\r\n if (defaultValue !== undefined) {\r\n const defaultValueIndex = getIndexFromValue(data, defaultValue);\r\n\r\n if (defaultValueIndex !== undefined) {\r\n setInputValueByIndex(defaultValueIndex);\r\n }\r\n } else {\r\n setInputValueByIndex(0);\r\n }\r\n }\r\n }, [data]);\r\n\r\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\r\n const charKey = String.fromCharCode(event.keyCode);\r\n\r\n if (charKey.match(/(\\w)/g)) {\r\n const nextIndex = getNextIndex(charKey);\r\n\r\n if (nextIndex > -1 && nextIndex !== currentIndex) {\r\n setInputValueByIndex(nextIndex);\r\n }\r\n return;\r\n }\r\n\r\n if (onKeyDown) {\r\n event.persist();\r\n onKeyDown(event);\r\n }\r\n };\r\n\r\n const handleListboxFocus = (event: React.FocusEvent<HTMLElement>): void => {\r\n if (currentIndex === undefined && data.length) {\r\n setInputValueByIndex(0);\r\n }\r\n\r\n if (onFocus) {\r\n event.persist();\r\n onFocus(event);\r\n }\r\n };\r\n\r\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\r\n event.persist();\r\n\r\n if (onChange) {\r\n const item = findByValue(data, event.target.value);\r\n (event as any).detail = sanitizeItem(item);\r\n\r\n const indexes = item?.path?.split('.') ?? [];\r\n\r\n if (indexes.length > 1) {\r\n // we don't want to map the current item\r\n indexes.pop();\r\n // we need to rebuild the path as we map\r\n let lastPath: string;\r\n\r\n (event as any).detail.parents = indexes.map(i => {\r\n lastPath = lastPath ? [lastPath, i].join('.') : i;\r\n return sanitizeItem(data.find(i => i.path === lastPath));\r\n });\r\n }\r\n\r\n onChange(event);\r\n }\r\n };\r\n\r\n const list: ScrollableListProps = {\r\n ...otherProps,\r\n 'aria-activedescendant': getActiveDescendant(data, currentIndex, id),\r\n data,\r\n disabled,\r\n id,\r\n invalid,\r\n onChange: handleListboxChange,\r\n onFocus: handleListboxFocus,\r\n onKeyDown: handleListboxKeyDown,\r\n scrollOnFocus: true,\r\n tabIndex: disabled ? -1 : otherProps.tabIndex ? otherProps.tabIndex : 0,\r\n value: currentIndex,\r\n };\r\n\r\n const input = {\r\n name,\r\n onChange: handleInputChange,\r\n ref: inputRef,\r\n tabIndex: -1,\r\n value: value === undefined || value === null ? '' : value,\r\n };\r\n\r\n return { list, input };\r\n};\r\n"],"names":["useListbox","data","externalData","defaultValue","disabled","emptyValue","id","nativeId","invalid","name","onChange","onFocus","onKeyDown","value","otherProps","ref","useFlattenedData","undefined","text","React","uuid","inputRef","useProxiedRef","currentIndex","getIndexFromValue","getNextIndex","useTypeahead","setInputValueByIndex","index","option","setInputValueByRef","current","handleListboxChange","length","defaultValueIndex","handleListboxKeyDown","event","charKey","String","fromCharCode","keyCode","match","nextIndex","persist","handleListboxFocus","handleInputChange","item","findByValue","target","detail","sanitizeItem","indexes","path","split","pop","lastPath","parents","map","i","join","find","list","getActiveDescendant","scrollOnFocus","tabIndex","input"],"mappings":";;;;;;MAaaA,UAAU,GAAG,CACtB;AACIC,EAAAA,IAAI,EAAEC,YAAY,GAAG,EADzB;AAEIC,EAAAA,YAFJ;AAGIC,EAAAA,QAHJ;AAIIC,EAAAA,UAJJ;AAKIC,EAAAA,EAAE,EAAEC,QALR;AAMIC,EAAAA,OANJ;AAOIC,EAAAA,IAPJ;AAQIC,EAAAA,QARJ;AASIC,EAAAA,OATJ;AAUIC,EAAAA,SAVJ;AAWIC,EAAAA,KAAK,GAAGR,UAXZ;AAYI,KAAGS;AAZP,CADsB,EAetBC,GAfsB;AAiBtB,QAAMd,IA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AHK;AAIV2C,IAAAA,QAAQ,EAAE,CAAC,CAJD;AAKVnD,IAAAA,KAAK,EAAEA,KAAK,KAAKI,SAAV,IAAuBJ,KAAK,KAAK,IAAjC,GAAwC,EAAxC,GAA6CA;AAL1C,GAAd;AAQA,SAAO;AAAEgD,IAAAA,IAAF;AAAQI,IAAAA;AAAR,GAAP;AACH;;;;"}
|
@@ -30,7 +30,7 @@ const BaseSelect = /*#__PURE__*/forwardRef(function BaseSelect(props, ref) {
|
|
30
30
|
const className = cn('inline-flex relative w-full', {
|
31
31
|
'yt-select--readonly': props.readOnly
|
32
32
|
}, externalClassName);
|
33
|
-
const inputClassname = cn(getInputClasses(props), 'text-left pr-0', {
|
33
|
+
const inputClassname = cn(getInputClasses(props), 'h-8 text-left pr-0', {
|
34
34
|
'border-blue': popover.open
|
35
35
|
});
|
36
36
|
useEffect(() => {
|
@@ -49,6 +49,7 @@ const BaseSelect = /*#__PURE__*/forwardRef(function BaseSelect(props, ref) {
|
|
49
49
|
|
50
50
|
const commonListboxProps = { ...listbox,
|
51
51
|
className: 'w-auto',
|
52
|
+
invalid: undefined,
|
52
53
|
style: {
|
53
54
|
minWidth: selectDimensions === null || selectDimensions === void 0 ? void 0 : selectDimensions.width
|
54
55
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Select.js","sources":["../../../../src/components/Select/Select.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\r\nimport { Icon } from '../Icon/Icon';\r\nimport { Listbox, MultiListbox, ListboxProps } from '../Listbox/Listbox';\r\nimport { useBoundingClientRectListener } from '../../utils/hooks/useBoundingClientRectListener';\r\nimport { useSelect } from './useSelect';\r\nimport { Combobox, ComboboxProps } from '../Combobox/Combobox';\r\nimport { Badge } from '../Badge/Badge';\r\nimport { getInputClasses } from '../Input/util';\r\n\r\nexport type SelectTexts = {\r\n /**\r\n * The text displayed when all options are selected when multiselect mode in on.\r\n */\r\n allOptionsSelected: string;\r\n};\r\n\r\nexport type BaseSelectProps = Omit<ListboxProps, 'dialog'> &\r\n Omit<ComboboxProps, 'inline'> & {\r\n /**\r\n * Allows to select multiple values.\r\n * All the selected values will be combined in a comma-seperated string as the value of the input.\r\n */\r\n multiselect?: boolean;\r\n };\r\n\r\nexport type SelectProps = BaseSelectProps & {\r\n /**\r\n * Creates an editable select.\r\n * Setting this will render a inline Combobox which will display the provided data on click/focus,\r\n * even if there is no value in the input.\r\n * After user starts typing, matching data will be displayed.\r\n */\r\n editable?: boolean;\r\n};\r\n\r\nconst BaseSelect = React.forwardRef(function BaseSelect(props: BaseSelectProps, ref: React.Ref<HTMLInputElement>) {\r\n const { autoFocus, className: externalClassName, highlighted, style, ...otherProps } = props;\r\n const { button, listbox, popover, input, text, more = 0 } = useSelect(otherProps, ref);\r\n const internalRef = React.useRef<HTMLButtonElement>(null);\r\n const selectDimensions = useBoundingClientRectListener(internalRef);\r\n const className = cn('inline-flex relative w-full', { 'yt-select--readonly': props.readOnly }, externalClassName);\r\n const inputClassname = cn(getInputClasses(props), 'text-left pr-0', {\r\n 'border-blue': popover.open,\r\n });\r\n\r\n React.useEffect(() => {\r\n if (autoFocus && internalRef.current) {\r\n internalRef.current.focus();\r\n }\r\n }, []);\r\n\r\n const renderMultiSelection = (): React.ReactNode => {\r\n return (\r\n <>\r\n <span className=\"flex-grow truncate text-left\">{text}</span>\r\n {more > 0 && <Badge className=\"ml-2\">{`+${more}`}</Badge>}\r\n </>\r\n );\r\n };\r\n\r\n const commonListboxProps = {\r\n ...listbox,\r\n className: 'w-auto',\r\n style: { minWidth: selectDimensions?.width },\r\n tabIndex: popover.open ? 0 : -1,\r\n };\r\n\r\n return (\r\n <span className={className} data-taco=\"select\" style={style}>\r\n <PopoverPrimitive.Root {...popover}>\r\n <PopoverPrimitive.Trigger {...button} className={inputClassname} ref={internalRef}>\r\n {props.multiselect ? renderMultiSelection() : <span className=\"flex-grow truncate text-left\">{text}</span>}\r\n <span className=\"flex h-8 w-8 items-center justify-center\">\r\n <Icon className=\"pointer-events-none\" name={popover.open ? 'chevron-up' : 'chevron-down'} />\r\n </span>\r\n </PopoverPrimitive.Trigger>\r\n <PopoverPrimitive.Content align=\"start\" sideOffset={4}>\r\n {props.multiselect ? <MultiListbox {...commonListboxProps} /> : <Listbox {...commonListboxProps} />}\r\n </PopoverPrimitive.Content>\r\n <input {...input} className=\"hidden\" type=\"text\" />\r\n </PopoverPrimitive.Root>\r\n </span>\r\n );\r\n});\r\n\r\nexport const Select = React.forwardRef(function Select(props: SelectProps, ref: React.Ref<HTMLInputElement>) {\r\n const { editable, ...otherProps } = props;\r\n\r\n if (editable) {\r\n return <Combobox {...otherProps} dialog={undefined} inline ref={ref} />;\r\n }\r\n\r\n return <BaseSelect {...otherProps} ref={ref} />;\r\n});\r\n"],"names":["BaseSelect","React","props","ref","autoFocus","className","externalClassName","highlighted","style","otherProps","button","listbox","popover","input","text","more","useSelect","internalRef","selectDimensions","useBoundingClientRectListener","cn","readOnly","inputClassname","getInputClasses","open","current","focus","renderMultiSelection","Badge","commonListboxProps","minWidth","width","tabIndex","PopoverPrimitive","multiselect","Icon","name","align","sideOffset","MultiListbox","Listbox","type","Select","editable","Combobox","dialog","
|
1
|
+
{"version":3,"file":"Select.js","sources":["../../../../src/components/Select/Select.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\r\nimport { Icon } from '../Icon/Icon';\r\nimport { Listbox, MultiListbox, ListboxProps } from '../Listbox/Listbox';\r\nimport { useBoundingClientRectListener } from '../../utils/hooks/useBoundingClientRectListener';\r\nimport { useSelect } from './useSelect';\r\nimport { Combobox, ComboboxProps } from '../Combobox/Combobox';\r\nimport { Badge } from '../Badge/Badge';\r\nimport { getInputClasses } from '../Input/util';\r\n\r\nexport type SelectTexts = {\r\n /**\r\n * The text displayed when all options are selected when multiselect mode in on.\r\n */\r\n allOptionsSelected: string;\r\n};\r\n\r\nexport type BaseSelectProps = Omit<ListboxProps, 'dialog'> &\r\n Omit<ComboboxProps, 'inline'> & {\r\n /**\r\n * Allows to select multiple values.\r\n * All the selected values will be combined in a comma-seperated string as the value of the input.\r\n */\r\n multiselect?: boolean;\r\n };\r\n\r\nexport type SelectProps = BaseSelectProps & {\r\n /**\r\n * Creates an editable select.\r\n * Setting this will render a inline Combobox which will display the provided data on click/focus,\r\n * even if there is no value in the input.\r\n * After user starts typing, matching data will be displayed.\r\n */\r\n editable?: boolean;\r\n};\r\n\r\nconst BaseSelect = React.forwardRef(function BaseSelect(props: BaseSelectProps, ref: React.Ref<HTMLInputElement>) {\r\n const { autoFocus, className: externalClassName, highlighted, style, ...otherProps } = props;\r\n const { button, listbox, popover, input, text, more = 0 } = useSelect(otherProps, ref);\r\n const internalRef = React.useRef<HTMLButtonElement>(null);\r\n const selectDimensions = useBoundingClientRectListener(internalRef);\r\n const className = cn('inline-flex relative w-full', { 'yt-select--readonly': props.readOnly }, externalClassName);\r\n const inputClassname = cn(getInputClasses(props), 'h-8 text-left pr-0', {\r\n 'border-blue': popover.open,\r\n });\r\n\r\n React.useEffect(() => {\r\n if (autoFocus && internalRef.current) {\r\n internalRef.current.focus();\r\n }\r\n }, []);\r\n\r\n const renderMultiSelection = (): React.ReactNode => {\r\n return (\r\n <>\r\n <span className=\"flex-grow truncate text-left\">{text}</span>\r\n {more > 0 && <Badge className=\"ml-2\">{`+${more}`}</Badge>}\r\n </>\r\n );\r\n };\r\n\r\n const commonListboxProps = {\r\n ...listbox,\r\n className: 'w-auto',\r\n invalid: undefined,\r\n style: { minWidth: selectDimensions?.width },\r\n tabIndex: popover.open ? 0 : -1,\r\n };\r\n\r\n return (\r\n <span className={className} data-taco=\"select\" style={style}>\r\n <PopoverPrimitive.Root {...popover}>\r\n <PopoverPrimitive.Trigger {...button} className={inputClassname} ref={internalRef}>\r\n {props.multiselect ? renderMultiSelection() : <span className=\"flex-grow truncate text-left\">{text}</span>}\r\n <span className=\"flex h-8 w-8 items-center justify-center\">\r\n <Icon className=\"pointer-events-none\" name={popover.open ? 'chevron-up' : 'chevron-down'} />\r\n </span>\r\n </PopoverPrimitive.Trigger>\r\n <PopoverPrimitive.Content align=\"start\" sideOffset={4}>\r\n {props.multiselect ? <MultiListbox {...commonListboxProps} /> : <Listbox {...commonListboxProps} />}\r\n </PopoverPrimitive.Content>\r\n <input {...input} className=\"hidden\" type=\"text\" />\r\n </PopoverPrimitive.Root>\r\n </span>\r\n );\r\n});\r\n\r\nexport const Select = React.forwardRef(function Select(props: SelectProps, ref: React.Ref<HTMLInputElement>) {\r\n const { editable, ...otherProps } = props;\r\n\r\n if (editable) {\r\n return <Combobox {...otherProps} dialog={undefined} inline ref={ref} />;\r\n }\r\n\r\n return <BaseSelect {...otherProps} ref={ref} />;\r\n});\r\n"],"names":["BaseSelect","React","props","ref","autoFocus","className","externalClassName","highlighted","style","otherProps","button","listbox","popover","input","text","more","useSelect","internalRef","selectDimensions","useBoundingClientRectListener","cn","readOnly","inputClassname","getInputClasses","open","current","focus","renderMultiSelection","Badge","commonListboxProps","invalid","undefined","minWidth","width","tabIndex","PopoverPrimitive","multiselect","Icon","name","align","sideOffset","MultiListbox","Listbox","type","Select","editable","Combobox","dialog","inline"],"mappings":";;;;;;;;;;;AAqCA,MAAMA,UAAU,gBAAGC,UAAA,CAAiB,SAASD,UAAT,CAAoBE,KAApB,EAA4CC,GAA5C;AAChC,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,SAAS,EAAEC,iBAAxB;AAA2CC,IAAAA,WAA3C;AAAwDC,IAAAA,KAAxD;AAA+D,OAAGC;AAAlE,MAAiFP,KAAvF;AACA,QAAM;AAAEQ,IAAAA,MAAF;AAAUC,IAAAA,OAAV;AAAmBC,IAAAA,OAAnB;AAA4BC,IAAAA,KAA5B;AAAmCC,IAAAA,IAAnC;AAAyCC,IAAAA,IAAI,GAAG;AAAhD,MAAsDC,SAAS,CAACP,UAAD,EAAaN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B;;;;"}
|
@@ -41,7 +41,10 @@ const useSelect = ({
|
|
41
41
|
}
|
42
42
|
}, [defaultValue]);
|
43
43
|
useEffect(() => {
|
44
|
-
|
44
|
+
// If emptyValue is defined, then set emptyValue
|
45
|
+
if (emptyValue !== undefined && value === emptyValue) {
|
46
|
+
setInputValueByRef(internalInputRef.current, value);
|
47
|
+
} else if (value !== undefined && data.some(option => option.value === value)) {
|
45
48
|
setInputValueByRef(internalInputRef.current, value);
|
46
49
|
} else if (data.length && defaultValue === undefined) {
|
47
50
|
setInputValueByRef(internalInputRef.current, data[0].value);
|