@economic/taco 1.22.9 → 1.23.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Alert/Alert.d.ts +12 -0
- package/dist/components/Alert/Alert.stories.d.ts +36 -0
- package/dist/components/Badge/Badge.d.ts +44 -13
- package/dist/components/BadgeIcon/BadgeIcon.d.ts +19 -0
- package/dist/components/BadgeIcon/BadgeIcon.stories.d.ts +12 -0
- package/dist/components/Button/Button.stories.d.ts +1 -1
- package/dist/components/Datepicker/Datepicker.stories.d.ts +1 -1
- package/dist/components/Select/Select.stories.d.ts +1 -1
- package/dist/components/Select/useSelect.d.ts +1 -1
- package/dist/components/Select2/Select2.d.ts +1 -2
- package/dist/components/Select2/Select2.stories.d.ts +0 -1
- package/dist/components/Select2/components/Context.d.ts +3 -1
- package/dist/components/Select2/components/Create.d.ts +1 -1
- package/dist/components/Select2/components/Edit.d.ts +2 -2
- package/dist/components/Select2/components/Option.d.ts +2 -2
- package/dist/components/Select2/utilities.d.ts +1 -1
- package/dist/components/Table2/components/row/Context.d.ts +3 -1
- package/dist/components/Tag/Tag.d.ts +3 -14
- package/dist/esm/index.css +14 -2
- package/dist/esm/packages/taco/src/components/Accordion/Accordion.js +1 -1
- package/dist/esm/packages/taco/src/components/Alert/Alert.js +49 -0
- package/dist/esm/packages/taco/src/components/Alert/Alert.js.map +1 -0
- package/dist/esm/packages/taco/src/components/AlertDialog/components/Content.js +1 -1
- package/dist/esm/packages/taco/src/components/Badge/Badge.js +28 -8
- package/dist/esm/packages/taco/src/components/Badge/Badge.js.map +1 -1
- package/dist/esm/packages/taco/src/components/BadgeIcon/BadgeIcon.js +30 -0
- package/dist/esm/packages/taco/src/components/BadgeIcon/BadgeIcon.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Hanger/Hanger.js +1 -1
- package/dist/esm/packages/taco/src/components/Popover/Popover.js +1 -1
- package/dist/esm/packages/taco/src/components/Select/useSelect.js +2 -0
- package/dist/esm/packages/taco/src/components/Select/useSelect.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/Select2.js +12 -3
- package/dist/esm/packages/taco/src/components/Select2/Select2.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/components/Context.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/components/Create.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/components/Edit.js +2 -3
- package/dist/esm/packages/taco/src/components/Select2/components/Edit.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/components/Option.js +2 -1
- package/dist/esm/packages/taco/src/components/Select2/components/Option.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/utilities.js +5 -1
- package/dist/esm/packages/taco/src/components/Select2/utilities.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table2/components/ColumnSettingsButton.js +7 -5
- package/dist/esm/packages/taco/src/components/Table2/components/ColumnSettingsButton.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table2/components/row/Context.js +5 -2
- package/dist/esm/packages/taco/src/components/Table2/components/row/Context.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table2/components/row/Row.js +2 -1
- package/dist/esm/packages/taco/src/components/Table2/components/row/Row.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table2/hooks/useColumnDefinitions.js +4 -3
- package/dist/esm/packages/taco/src/components/Table2/hooks/useColumnDefinitions.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table2/hooks/useTable.js +2 -2
- package/dist/esm/packages/taco/src/components/Table2/hooks/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table2/utilities/columns.js +3 -1
- package/dist/esm/packages/taco/src/components/Table2/utilities/columns.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Tag/Tag.js +3 -13
- package/dist/esm/packages/taco/src/components/Tag/Tag.js.map +1 -1
- package/dist/esm/packages/taco/src/hooks/useIsFormControl.js +1 -1
- package/dist/esm/packages/taco/src/hooks/useIsFormControl.js.map +1 -1
- package/dist/esm/packages/taco/src/{components/Table2/hooks/useShouldPauseHoverState.js → hooks/useIsHoverStatePaused.js} +3 -3
- package/dist/esm/packages/taco/src/hooks/useIsHoverStatePaused.js.map +1 -0
- package/dist/esm/packages/taco/src/index.js +5 -3
- package/dist/esm/packages/taco/src/index.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Collection/components/Root.js +6 -0
- package/dist/esm/packages/taco/src/primitives/Collection/components/Root.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Listbox2/components/Root.js +2 -2
- package/dist/esm/packages/taco/src/primitives/Listbox2/components/Root.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/taillwind.js +79 -20
- package/dist/esm/packages/taco/src/utils/taillwind.js.map +1 -1
- package/dist/hooks/useIsHoverStatePaused.d.ts +2 -0
- package/dist/index.css +14 -2
- package/dist/index.d.ts +2 -0
- package/dist/taco.cjs.development.js +370 -211
- 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/types.d.ts +2 -0
- package/dist/utils/taillwind.d.ts +6 -4
- package/package.json +2 -2
- package/tailwind.config.js +9 -11
- package/types.json +92 -30
- package/dist/components/Badge/Badge.stories.d.ts +0 -15
- package/dist/components/Table2/hooks/useShouldPauseHoverState.d.ts +0 -2
- package/dist/esm/packages/taco/src/components/Table2/hooks/useShouldPauseHoverState.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -12
@@ -0,0 +1,49 @@
|
|
1
|
+
import React__default from 'react';
|
2
|
+
import cn from 'classnames';
|
3
|
+
import { getSubtleColorShadeClasses, getColorByState } from '../../utils/taillwind.js';
|
4
|
+
import { Icon } from '../Icon/Icon.js';
|
5
|
+
import { BadgeIcon } from '../BadgeIcon/BadgeIcon.js';
|
6
|
+
|
7
|
+
const getIconName = state => {
|
8
|
+
switch (state) {
|
9
|
+
case 'information':
|
10
|
+
return 'info';
|
11
|
+
case 'warning':
|
12
|
+
return 'warning';
|
13
|
+
case 'error':
|
14
|
+
return 'close';
|
15
|
+
case 'success':
|
16
|
+
return 'tick';
|
17
|
+
default:
|
18
|
+
return 'refresh';
|
19
|
+
}
|
20
|
+
};
|
21
|
+
const Alert = /*#__PURE__*/React__default.forwardRef(function Alert(props, ref) {
|
22
|
+
const {
|
23
|
+
children,
|
24
|
+
title,
|
25
|
+
state,
|
26
|
+
onClose
|
27
|
+
} = props;
|
28
|
+
const className = cn(`flex w-full flex-row items-start gap-2 rounded-md border-transparent p-3 ${getSubtleColorShadeClasses(getColorByState(state))}`, props.className);
|
29
|
+
return /*#__PURE__*/React__default.createElement("div", Object.assign({}, props, {
|
30
|
+
ref: ref,
|
31
|
+
className: className,
|
32
|
+
role: "alert"
|
33
|
+
}), /*#__PURE__*/React__default.createElement(BadgeIcon, {
|
34
|
+
className: "flex-none",
|
35
|
+
icon: getIconName(state),
|
36
|
+
color: getColorByState(state)
|
37
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
38
|
+
className: "grow text-sm"
|
39
|
+
}, title && /*#__PURE__*/React__default.createElement("div", {
|
40
|
+
className: "font-bold"
|
41
|
+
}, title), children), onClose && /*#__PURE__*/React__default.createElement(Icon, {
|
42
|
+
className: "flex-none cursor-pointer",
|
43
|
+
name: "close",
|
44
|
+
onClick: onClose
|
45
|
+
}));
|
46
|
+
});
|
47
|
+
|
48
|
+
export { Alert };
|
49
|
+
//# sourceMappingURL=Alert.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Alert.js","sources":["../../../../../../../src/components/Alert/Alert.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { BadgeIcon } from '../BadgeIcon/BadgeIcon';\nimport { getColorByState, getSubtleColorShadeClasses } from '../../utils/taillwind';\nimport { Icon, IconName } from '../Icon/Icon';\nimport { State } from '../../types';\n\nexport type AlertProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> & {\n children: React.ReactNode;\n state?: State;\n onClose?: () => void;\n};\n\nconst getIconName = (state: State | undefined): IconName => {\n switch (state) {\n case 'information':\n return 'info';\n case 'warning':\n return 'warning';\n case 'error':\n return 'close';\n case 'success':\n return 'tick';\n default:\n return 'refresh';\n }\n};\n\nexport const Alert = React.forwardRef(function Alert(props: AlertProps, ref: React.Ref<HTMLDivElement>) {\n const { children, title, state, onClose } = props;\n\n const className = cn(\n `flex w-full flex-row items-start gap-2 rounded-md border-transparent p-3 ${getSubtleColorShadeClasses(\n getColorByState(state)\n )}`,\n props.className\n );\n\n return (\n <div {...props} ref={ref} className={className} role=\"alert\">\n <BadgeIcon className=\"flex-none\" icon={getIconName(state)} color={getColorByState(state)} />\n <div className=\"grow text-sm\">\n {title && <div className=\"font-bold\">{title}</div>}\n {children}\n </div>\n {onClose && <Icon className=\"flex-none cursor-pointer\" name=\"close\" onClick={onClose} />}\n </div>\n );\n});\n"],"names":["getIconName","state","Alert","React","forwardRef","props","ref","children","title","onClose","className","cn","getSubtleColorShadeClasses","getColorByState","role","BadgeIcon","icon","color","Icon","name","onClick"],"mappings":";;;;;;AAaA,MAAMA,WAAW,GAAIC,KAAwB;EACzC,QAAQA,KAAK;IACT,KAAK,aAAa;MACd,OAAO,MAAM;IACjB,KAAK,SAAS;MACV,OAAO,SAAS;IACpB,KAAK,OAAO;MACR,OAAO,OAAO;IAClB,KAAK,SAAS;MACV,OAAO,MAAM;IACjB;MACI,OAAO,SAAS;;AAE5B,CAAC;MAEYC,KAAK,gBAAGC,cAAK,CAACC,UAAU,CAAC,SAASF,KAAK,CAACG,KAAiB,EAAEC,GAA8B;EAClG,MAAM;IAAEC,QAAQ;IAAEC,KAAK;IAAEP,KAAK;IAAEQ;GAAS,GAAGJ,KAAK;EAEjD,MAAMK,SAAS,GAAGC,EAAE,6EAC4DC,0BAA0B,CAClGC,eAAe,CAACZ,KAAK,CAAC,GACvB,EACHI,KAAK,CAACK,SAAS,CAClB;EAED,oBACIP,sDAASE,KAAK;IAAEC,GAAG,EAAEA,GAAG;IAAEI,SAAS,EAAEA,SAAS;IAAEI,IAAI,EAAC;mBACjDX,6BAACY,SAAS;IAACL,SAAS,EAAC,WAAW;IAACM,IAAI,EAAEhB,WAAW,CAACC,KAAK,CAAC;IAAEgB,KAAK,EAAEJ,eAAe,CAACZ,KAAK;IAAK,eAC5FE;IAAKO,SAAS,EAAC;KACVF,KAAK,iBAAIL;IAAKO,SAAS,EAAC;KAAaF,KAAK,CAAO,EACjDD,QAAQ,CACP,EACLE,OAAO,iBAAIN,6BAACe,IAAI;IAACR,SAAS,EAAC,0BAA0B;IAACS,IAAI,EAAC,OAAO;IAACC,OAAO,EAAEX;IAAW,CACtF;AAEd,CAAC;;;;"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { forwardRef, createElement } from 'react';
|
2
|
-
import { Title as Title$1, Portal, Overlay, Content as Content$1 } from '@radix-ui/react-alert-dialog';
|
3
2
|
import cn from 'classnames';
|
3
|
+
import { Title as Title$1, Portal, Overlay, Content as Content$1 } from '@radix-ui/react-alert-dialog';
|
4
4
|
import { Backdrop } from '../../Backdrop/Backdrop.js';
|
5
5
|
import { getDialogPositionClassnames, getDialogStylingClassnames, getDialogSizeClassnames } from '../../Dialog/util.js';
|
6
6
|
|
@@ -1,22 +1,42 @@
|
|
1
|
-
import { forwardRef, createElement } from 'react';
|
1
|
+
import { forwardRef, createElement, Fragment } from 'react';
|
2
2
|
import cn from 'classnames';
|
3
|
+
import { getOutlineColorShadeClasses, getSubtleColorShadeClasses, getColorShadeClasses } from '../../utils/taillwind.js';
|
3
4
|
import { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden.js';
|
4
|
-
import { getOutlineClasses, getStateClasses } from '../../utils/taillwind.js';
|
5
5
|
|
6
6
|
const Badge = /*#__PURE__*/forwardRef(function Badge(props, ref) {
|
7
7
|
const {
|
8
8
|
children,
|
9
9
|
compact = false,
|
10
10
|
outline = false,
|
11
|
-
|
11
|
+
status = false,
|
12
|
+
subtle = false,
|
13
|
+
small = false,
|
14
|
+
color,
|
12
15
|
...otherProps
|
13
16
|
} = props;
|
14
|
-
const
|
15
|
-
|
16
|
-
[`border
|
17
|
+
const isTransparent = color === 'transparent';
|
18
|
+
const className = cn('rounded-full border overflow-hidden whitespace-nowrap inline-flex items-center justify-center', {
|
19
|
+
[`border ${getOutlineColorShadeClasses(color)}`]: outline,
|
20
|
+
[`border-transparent font-normal ${getSubtleColorShadeClasses(color)}`]: subtle,
|
21
|
+
[`border-transparent ${getColorShadeClasses(color)}`]: !outline && !subtle,
|
22
|
+
'h-4 min-w-0 py-0 px-1 text-xs': small,
|
17
23
|
'h-2 w-2 min-w-0': compact,
|
18
|
-
'
|
24
|
+
'font-bold': outline || !subtle,
|
25
|
+
'text-sm': !small,
|
26
|
+
'h-5 py-0 px-1.5': !compact && !small,
|
27
|
+
'!bg-grey-700': compact && isTransparent
|
19
28
|
}, props.className);
|
29
|
+
const content = () => {
|
30
|
+
if (compact) {
|
31
|
+
return /*#__PURE__*/createElement(VisuallyHidden, null, children);
|
32
|
+
}
|
33
|
+
if (status) {
|
34
|
+
return /*#__PURE__*/createElement(Fragment, null, /*#__PURE__*/createElement("div", {
|
35
|
+
className: cn('mr-1 h-2 w-2 rounded-full', getColorShadeClasses(color))
|
36
|
+
}), children);
|
37
|
+
}
|
38
|
+
return children;
|
39
|
+
};
|
20
40
|
return /*#__PURE__*/createElement("span", Object.assign({}, otherProps, {
|
21
41
|
"aria-atomic": "true",
|
22
42
|
"aria-live": "polite",
|
@@ -25,7 +45,7 @@ const Badge = /*#__PURE__*/forwardRef(function Badge(props, ref) {
|
|
25
45
|
ref: ref,
|
26
46
|
role: "status",
|
27
47
|
title: props['aria-label']
|
28
|
-
}),
|
48
|
+
}), content());
|
29
49
|
});
|
30
50
|
|
31
51
|
export { Badge };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Badge.js","sources":["../../../../../../../src/components/Badge/Badge.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden';\nimport {
|
1
|
+
{"version":3,"file":"Badge.js","sources":["../../../../../../../src/components/Badge/Badge.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden';\nimport { Color } from '../../types';\nimport { getSubtleColorShadeClasses, getColorShadeClasses, getOutlineColorShadeClasses } from '../../utils/taillwind';\nimport './Badge.css';\n\nexport type BadgeBaseProps = React.HTMLAttributes<HTMLSpanElement> & {\n /** Content should be a numerical value or tag/status like text **/\n children: React.ReactNode;\n /** Show small version of badge **/\n small?: boolean;\n /** Background color **/\n color?: Color;\n};\n\ninterface CompactBadgeProps extends BadgeBaseProps {\n /** Show compact version **/\n compact?: boolean;\n /** Show outlined version **/\n outline?: never;\n /** Show subtle version **/\n subtle?: never;\n /** Show status dot - can be used only in subtle badge **/\n status?: never;\n}\n\ninterface OutlineBadgeProps extends BadgeBaseProps {\n /** Show compact version **/\n compact?: never;\n /** Show outlined version **/\n outline?: boolean;\n /** Show subtle version **/\n subtle?: never;\n /** Show status dot - can be used only in subtle badge **/\n status?: never;\n}\n\ninterface SubtleBadgeProps extends BadgeBaseProps {\n /** Show compact version **/\n compact?: never;\n /** Show outlined version **/\n outline?: never;\n /** Show subtle version **/\n subtle?: boolean;\n /** Show status dot - can be used only in subtle badge **/\n status?: never;\n}\n\ninterface StatusBadgeProps extends BadgeBaseProps {\n /** Show compact version **/\n compact?: never;\n /** Show outlined version **/\n outline?: never;\n /** Show subtle version **/\n subtle?: boolean;\n /** Show status dot - can be used only in subtle badge **/\n status?: boolean;\n}\n\nexport type BadgeProps = CompactBadgeProps | OutlineBadgeProps | SubtleBadgeProps | StatusBadgeProps;\n\nexport const Badge = React.forwardRef(function Badge(props: BadgeProps, ref: React.Ref<HTMLSpanElement>) {\n const {\n children,\n compact = false,\n outline = false,\n status = false,\n subtle = false,\n small = false,\n color,\n ...otherProps\n } = props;\n const isTransparent = color === 'transparent';\n const className = cn(\n 'rounded-full border overflow-hidden whitespace-nowrap inline-flex items-center justify-center',\n {\n [`border ${getOutlineColorShadeClasses(color)}`]: outline,\n [`border-transparent font-normal ${getSubtleColorShadeClasses(color)}`]: subtle,\n [`border-transparent ${getColorShadeClasses(color)}`]: !outline && !subtle,\n 'h-4 min-w-0 py-0 px-1 text-xs': small,\n 'h-2 w-2 min-w-0': compact,\n 'font-bold': outline || !subtle,\n 'text-sm': !small,\n 'h-5 py-0 px-1.5': !compact && !small, // custom padding keeps single digits in a perfect circle\n '!bg-grey-700': compact && isTransparent,\n },\n props.className\n );\n\n const content = () => {\n if (compact) {\n return <VisuallyHidden>{children}</VisuallyHidden>;\n }\n if (status) {\n return (\n <>\n <div className={cn('mr-1 h-2 w-2 rounded-full', getColorShadeClasses(color))} />\n {children}\n </>\n );\n }\n return children;\n };\n\n return (\n <span\n {...otherProps}\n aria-atomic=\"true\"\n aria-live=\"polite\"\n className={className}\n data-taco=\"badge\"\n ref={ref}\n role=\"status\"\n title={props['aria-label']}>\n {content()}\n </span>\n );\n});\n"],"names":["Badge","React","props","ref","children","compact","outline","status","subtle","small","color","otherProps","isTransparent","className","cn","getOutlineColorShadeClasses","getSubtleColorShadeClasses","getColorShadeClasses","content","VisuallyHidden","role","title"],"mappings":";;;;;MA8DaA,KAAK,gBAAGC,UAAgB,CAAC,SAASD,KAAK,CAACE,KAAiB,EAAEC,GAA+B;EACnG,MAAM;IACFC,QAAQ;IACRC,OAAO,GAAG,KAAK;IACfC,OAAO,GAAG,KAAK;IACfC,MAAM,GAAG,KAAK;IACdC,MAAM,GAAG,KAAK;IACdC,KAAK,GAAG,KAAK;IACbC,KAAK;IACL,GAAGC;GACN,GAAGT,KAAK;EACT,MAAMU,aAAa,GAAGF,KAAK,KAAK,aAAa;EAC7C,MAAMG,SAAS,GAAGC,EAAE,CAChB,+FAA+F,EAC/F;IACI,WAAWC,2BAA2B,CAACL,KAAK,GAAG,GAAGJ,OAAO;IACzD,mCAAmCU,0BAA0B,CAACN,KAAK,GAAG,GAAGF,MAAM;IAC/E,uBAAuBS,oBAAoB,CAACP,KAAK,GAAG,GAAG,CAACJ,OAAO,IAAI,CAACE,MAAM;IAC1E,+BAA+B,EAAEC,KAAK;IACtC,iBAAiB,EAAEJ,OAAO;IAC1B,WAAW,EAAEC,OAAO,IAAI,CAACE,MAAM;IAC/B,SAAS,EAAE,CAACC,KAAK;IACjB,iBAAiB,EAAE,CAACJ,OAAO,IAAI,CAACI,KAAK;IACrC,cAAc,EAAEJ,OAAO,IAAIO;GAC9B,EACDV,KAAK,CAACW,SAAS,CAClB;EAED,MAAMK,OAAO,GAAG;IACZ,IAAIb,OAAO,EAAE;MACT,oBAAOJ,cAACkB,cAAc,QAAEf,QAAQ,CAAkB;;IAEtD,IAAIG,MAAM,EAAE;MACR,oBACIN,2CACIA;QAAKY,SAAS,EAAEC,EAAE,CAAC,2BAA2B,EAAEG,oBAAoB,CAACP,KAAK,CAAC;QAAK,EAC/EN,QAAQ,CACV;;IAGX,OAAOA,QAAQ;GAClB;EAED,oBACIH,wCACQU,UAAU;mBACF,MAAM;iBACR,QAAQ;IAClBE,SAAS,EAAEA,SAAS;iBACV,OAAO;IACjBV,GAAG,EAAEA,GAAG;IACRiB,IAAI,EAAC,QAAQ;IACbC,KAAK,EAAEnB,KAAK,CAAC,YAAY;MACxBgB,OAAO,EAAE,CACP;AAEf,CAAC;;;;"}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { forwardRef, createElement } from 'react';
|
2
|
+
import cn from 'classnames';
|
3
|
+
import { getSubtleColorShadeClasses, getColorShadeClasses } from '../../utils/taillwind.js';
|
4
|
+
import { Icon } from '../Icon/Icon.js';
|
5
|
+
|
6
|
+
const BadgeIcon = /*#__PURE__*/forwardRef(function Badge(props, ref) {
|
7
|
+
const {
|
8
|
+
color,
|
9
|
+
icon,
|
10
|
+
subtle,
|
11
|
+
...otherProps
|
12
|
+
} = props;
|
13
|
+
const className = cn(`rounded-full border overflow-hidden whitespace-nowrap inline-flex items-center justify-center w-5 h-5 border-transparent [&>*]:max-h-full`, {
|
14
|
+
[getSubtleColorShadeClasses(color)]: subtle,
|
15
|
+
[getColorShadeClasses(color)]: !subtle
|
16
|
+
}, props.className);
|
17
|
+
return /*#__PURE__*/createElement("span", Object.assign({}, otherProps, {
|
18
|
+
"aria-label": "icon",
|
19
|
+
className: className,
|
20
|
+
"data-taco": "badge-icon",
|
21
|
+
ref: ref,
|
22
|
+
role: "status",
|
23
|
+
title: props['aria-label']
|
24
|
+
}), /*#__PURE__*/createElement(Icon, {
|
25
|
+
name: icon
|
26
|
+
}));
|
27
|
+
});
|
28
|
+
|
29
|
+
export { BadgeIcon };
|
30
|
+
//# sourceMappingURL=BadgeIcon.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"BadgeIcon.js","sources":["../../../../../../../src/components/BadgeIcon/BadgeIcon.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { getSubtleColorShadeClasses, getColorShadeClasses } from '../../utils/taillwind';\nimport { Icon, IconName } from '../Icon/Icon';\nimport { Color } from '../../types';\n\nexport type BadgeIconProps = React.HTMLAttributes<HTMLSpanElement> & {\n /** Icon type **/\n icon: IconName;\n /** Background color **/\n color?: Color;\n /** Show subtle version **/\n subtle?: boolean;\n};\n\nexport const BadgeIcon = React.forwardRef(function Badge(props: BadgeIconProps, ref: React.Ref<HTMLSpanElement>) {\n const { color, icon, subtle, ...otherProps } = props;\n\n const className = cn(\n `rounded-full border overflow-hidden whitespace-nowrap inline-flex items-center justify-center w-5 h-5 border-transparent [&>*]:max-h-full`,\n { [getSubtleColorShadeClasses(color)]: subtle, [getColorShadeClasses(color)]: !subtle },\n props.className\n );\n\n return (\n <span\n {...otherProps}\n aria-label=\"icon\"\n className={className}\n data-taco=\"badge-icon\"\n ref={ref}\n role=\"status\"\n title={props['aria-label']}>\n <Icon name={icon} />\n </span>\n );\n});\n"],"names":["BadgeIcon","React","Badge","props","ref","color","icon","subtle","otherProps","className","cn","getSubtleColorShadeClasses","getColorShadeClasses","role","title","Icon","name"],"mappings":";;;;;MAeaA,SAAS,gBAAGC,UAAgB,CAAC,SAASC,KAAK,CAACC,KAAqB,EAAEC,GAA+B;EAC3G,MAAM;IAAEC,KAAK;IAAEC,IAAI;IAAEC,MAAM;IAAE,GAAGC;GAAY,GAAGL,KAAK;EAEpD,MAAMM,SAAS,GAAGC,EAAE,4IAC2H,EAC3I;IAAE,CAACC,0BAA0B,CAACN,KAAK,CAAC,GAAGE,MAAM;IAAE,CAACK,oBAAoB,CAACP,KAAK,CAAC,GAAG,CAACE;GAAQ,EACvFJ,KAAK,CAACM,SAAS,CAClB;EAED,oBACIR,wCACQO,UAAU;kBACH,MAAM;IACjBC,SAAS,EAAEA,SAAS;iBACV,YAAY;IACtBL,GAAG,EAAEA,GAAG;IACRS,IAAI,EAAC,QAAQ;IACbC,KAAK,EAAEX,KAAK,CAAC,YAAY;mBACzBF,cAACc,IAAI;IAACC,IAAI,EAAEV;IAAQ,CACjB;AAEf,CAAC;;;;"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { forwardRef, createElement, useMemo, useState, useEffect, createContext, useContext, isValidElement } from 'react';
|
2
|
-
import { mergeRefs } from '../../utils/mergeRefs.js';
|
3
2
|
import cn from 'classnames';
|
3
|
+
import { mergeRefs } from '../../utils/mergeRefs.js';
|
4
4
|
import { IconButton } from '../IconButton/IconButton.js';
|
5
5
|
import { useLocalization } from '../Provider/Localization.js';
|
6
6
|
import { Root, Anchor as Anchor$1, Portal, Content as Content$1, Close } from '@radix-ui/react-popover';
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { forwardRef, useMemo, createElement, createContext, useContext, isValidElement } from 'react';
|
2
|
-
import { mergeRefs } from '../../utils/mergeRefs.js';
|
3
2
|
import cn from 'classnames';
|
3
|
+
import { mergeRefs } from '../../utils/mergeRefs.js';
|
4
4
|
import { Root, Portal, Trigger as Trigger$1, Content as Content$1, Close as Close$1 } from '@radix-ui/react-popover';
|
5
5
|
import { UnstyledArrow } from './Primitives.js';
|
6
6
|
import { getPopoverStyleClassnames } from './util.js';
|
@@ -19,6 +19,7 @@ const useSelect = ({
|
|
19
19
|
onClick,
|
20
20
|
onChange,
|
21
21
|
readOnly,
|
22
|
+
tabIndex,
|
22
23
|
value,
|
23
24
|
...otherProps
|
24
25
|
}, ref) => {
|
@@ -146,6 +147,7 @@ const useSelect = ({
|
|
146
147
|
disabled: disabled || readOnly,
|
147
148
|
id: buttonId,
|
148
149
|
onKeyDown: !disabled && !readOnly ? handleButtonKeyDown : undefined,
|
150
|
+
tabIndex,
|
149
151
|
type: 'button'
|
150
152
|
};
|
151
153
|
const listbox = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useSelect.js","sources":["../../../../../../../src/components/Select/useSelect.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { v4 as uuid } from 'uuid';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { useLocalization } from '../Provider/Localization';\nimport { SelectProps } from './Select';\nimport { ListboxProps } from '../Listbox/Listbox';\nimport { useMergedRef } from '../../hooks/useMergedRef';\nimport { setInputValueByRef, findByValue, useFlattenedData, sanitizeItem } from '../Listbox/util';\nimport { ScrollableListItemValue } from '../Listbox/ScrollableList';\nimport { createCustomEvent } from '../../utils/input';\n\ntype InternalButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>;\ntype InternalListboxProps = ListboxProps & { ref: React.ForwardedRef<HTMLInputElement> };\ntype InternalInputProps = React.InputHTMLAttributes<HTMLInputElement> & { ref: React.ForwardedRef<HTMLInputElement> };\n\ntype useSelect = React.HtmlHTMLAttributes<HTMLDivElement> & {\n button: InternalButtonProps;\n listbox: InternalListboxProps;\n input: InternalInputProps;\n popover: Pick<PopoverPrimitive.PopoverProps, 'onOpenChange' | 'open'>;\n text: string | JSX.Element;\n more?: number;\n};\n\nexport const useSelect = (\n {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data = [],\n defaultValue,\n disabled,\n emptyValue,\n id: nativeId,\n multiselect,\n onBlur,\n onClick,\n onChange,\n readOnly,\n value,\n ...otherProps\n }: SelectProps,\n ref: React.Ref<HTMLInputElement>\n): useSelect => {\n const { texts } = useLocalization();\n const flattenedData = useFlattenedData(data);\n const listboxInputRef = useMergedRef<HTMLInputElement>(ref);\n const [open, setOpen] = React.useState(false);\n const id = React.useMemo(() => nativeId || `select_${uuid()}`, [nativeId]);\n const inputRef = React.useRef<HTMLInputElement>(null);\n const buttonId = `${id}-button`;\n // support 'escape' resetting to the value that was set when the listbox opened\n const [lastValue, setLastValue] = React.useState<ScrollableListItemValue | undefined>(value);\n\n React.useEffect(() => {\n setLastValue(value);\n }, [open]);\n\n React.useEffect(() => {\n if (value === undefined) {\n if (defaultValue !== undefined && findByValue(flattenedData, defaultValue)) {\n setInputValueByRef(inputRef.current, defaultValue);\n } else {\n if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0].value);\n }\n }\n } else {\n if (!multiselect && !findByValue(flattenedData, value)) {\n if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0].value);\n }\n }\n }\n }, []);\n\n // event handlers\n const handleButtonKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>): void => {\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\n switch (event.key) {\n case 'Escape': {\n event.preventDefault();\n if (lastValue !== undefined) {\n setInputValueByRef(listboxInputRef.current, lastValue);\n }\n\n setOpen(false);\n break;\n }\n\n case 'Tab':\n case 'Enter': {\n if (event.key !== 'Tab') {\n event.preventDefault();\n }\n setOpen(false);\n break;\n }\n\n default:\n }\n\n if (otherProps.onKeyDown) {\n otherProps.onKeyDown(event);\n }\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>): void => {\n event.preventDefault();\n if (!multiselect) {\n setOpen(false);\n if (onBlur) {\n onBlur(createCustomEvent('blur'));\n }\n }\n };\n\n let text: string | JSX.Element = '';\n let more = 0;\n\n if (value !== undefined) {\n if (multiselect) {\n const selectedValues = value?.toString().split(',') || [];\n\n if (selectedValues.length === flattenedData.filter(item => !item.disabled).length) {\n text = texts.select.allOptionsSelected;\n } else {\n text = findByValue(flattenedData, selectedValues[0])?.text ?? '';\n more = selectedValues.length > 1 ? selectedValues.length - 1 : 0;\n }\n } else {\n const item = findByValue(flattenedData, value);\n\n if (item) {\n text = item.icon ? (\n <>\n {React.cloneElement(item.icon, {\n className: cn(item.icon.props.className, 'mr-1 -mt-px'),\n })}\n {item.text}\n </>\n ) : (\n item.text\n );\n }\n }\n }\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (onChange) {\n const item = findByValue(flattenedData, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const indexes = item?.path?.split('.') ?? [];\n\n if (indexes.length > 1) {\n // we don't want to map the current item\n indexes.pop();\n // we need to rebuild the path as we map\n let lastPath: string;\n\n (event as any).detail.parents = indexes.map(i => {\n lastPath = lastPath ? [lastPath, i].join('.') : i;\n return sanitizeItem(flattenedData.find(i => i.path === lastPath));\n });\n }\n\n onChange(event);\n }\n };\n\n const button: InternalButtonProps = {\n 'aria-haspopup': 'listbox' as const,\n 'aria-label': ariaLabel ? `${ariaLabel} ${text}` : undefined,\n 'aria-labelledby': ariaLabelledBy ? `${ariaLabelledBy} ${buttonId}` : undefined,\n disabled: disabled || readOnly,\n id: buttonId,\n onKeyDown: !disabled && !readOnly ? handleButtonKeyDown : undefined,\n type: 'button',\n };\n\n const listbox: InternalListboxProps = {\n ...otherProps,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data,\n disabled,\n emptyValue,\n onBlur,\n onClick: handleListboxClick,\n onChange: event => {\n setInputValueByRef(inputRef.current, event.target.value);\n },\n onKeyDown: handleListboxKeyDown,\n ref: listboxInputRef,\n value,\n };\n\n const input: InternalInputProps = {\n onChange: handleInputChange,\n ref: inputRef,\n value: String(value ?? ''),\n };\n\n return {\n button,\n listbox,\n input,\n popover: {\n open,\n onOpenChange: open => {\n if (!open && onBlur) {\n onBlur(createCustomEvent('blur'));\n }\n setOpen(open);\n },\n },\n text,\n more,\n };\n};\n"],"names":["useSelect","ariaLabel","ariaLabelledBy","data","defaultValue","disabled","emptyValue","id","nativeId","multiselect","onBlur","onClick","onChange","readOnly","value","otherProps","ref","texts","useLocalization","flattenedData","useFlattenedData","listboxInputRef","useMergedRef","open","setOpen","React","uuid","inputRef","buttonId","lastValue","setLastValue","undefined","findByValue","setInputValueByRef","current","length","handleButtonKeyDown","event","key","preventDefault","handleListboxKeyDown","onKeyDown","handleListboxClick","createCustomEvent","text","more","selectedValues","toString","split","filter","item","select","allOptionsSelected","icon","className","cn","props","handleInputChange","persist","target","detail","sanitizeItem","indexes","path","pop","lastPath","parents","map","i","join","find","button","type","listbox","input","String","popover","onOpenChange"],"mappings":";;;;;;;;MAyBaA,SAAS,GAAG,CACrB;EACI,YAAY,EAAEC,SAAS;EACvB,iBAAiB,EAAEC,cAAc;EACjCC,IAAI,GAAG,EAAE;EACTC,YAAY;EACZC,QAAQ;EACRC,UAAU;EACVC,EAAE,EAAEC,QAAQ;EACZC,WAAW;EACXC,MAAM;EACNC,OAAO;EACPC,QAAQ;EACRC,QAAQ;EACRC,KAAK;EACL,GAAGC;CACO,EACdC,GAAgC;EAEhC,MAAM;IAAEC;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,aAAa,GAAGC,gBAAgB,CAACjB,IAAI,CAAC;EAC5C,MAAMkB,eAAe,GAAGC,YAAY,CAAmBN,GAAG,CAAC;EAC3D,MAAM,CAACO,IAAI,EAAEC,OAAO,CAAC,GAAGC,QAAc,CAAC,KAAK,CAAC;EAC7C,MAAMlB,EAAE,GAAGk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,MAAM;IACNE,OAAO;IACPC,KAAK;IACLE,OAAO,EAAE;MACLrD,IAAI;MACJsD,YAAY,EAAEtD,IAAI;QACd,IAAI,CAACA,IAAI,IAAIb,MAAM,EAAE;UACjBA,MAAM,CAACiC,iBAAiB,CAAC,MAAM,CAAC,CAAC;;QAErCnB,OAAO,CAACD,IAAI,CAAC;;KAEpB;IACDqB,IAAI;IACJC;GACH;AACL;;;;"}
|
1
|
+
{"version":3,"file":"useSelect.js","sources":["../../../../../../../src/components/Select/useSelect.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { v4 as uuid } from 'uuid';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { useLocalization } from '../Provider/Localization';\nimport { SelectProps } from './Select';\nimport { ListboxProps } from '../Listbox/Listbox';\nimport { useMergedRef } from '../../hooks/useMergedRef';\nimport { setInputValueByRef, findByValue, useFlattenedData, sanitizeItem } from '../Listbox/util';\nimport { ScrollableListItemValue } from '../Listbox/ScrollableList';\nimport { createCustomEvent } from '../../utils/input';\n\ntype InternalButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>;\ntype InternalListboxProps = ListboxProps & { ref: React.ForwardedRef<HTMLInputElement> };\ntype InternalInputProps = React.InputHTMLAttributes<HTMLInputElement> & { ref: React.ForwardedRef<HTMLInputElement> };\n\ntype useSelect = React.HtmlHTMLAttributes<HTMLDivElement> & {\n button: InternalButtonProps;\n listbox: InternalListboxProps;\n input: InternalInputProps;\n popover: Pick<PopoverPrimitive.PopoverProps, 'onOpenChange' | 'open'>;\n text: string | JSX.Element;\n more?: number;\n};\n\nexport const useSelect = (\n {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data = [],\n defaultValue,\n disabled,\n emptyValue,\n id: nativeId,\n multiselect,\n onBlur,\n onClick,\n onChange,\n readOnly,\n tabIndex,\n value,\n ...otherProps\n }: SelectProps,\n ref: React.Ref<HTMLInputElement>\n): useSelect => {\n const { texts } = useLocalization();\n const flattenedData = useFlattenedData(data);\n const listboxInputRef = useMergedRef<HTMLInputElement>(ref);\n const [open, setOpen] = React.useState(false);\n const id = React.useMemo(() => nativeId || `select_${uuid()}`, [nativeId]);\n const inputRef = React.useRef<HTMLInputElement>(null);\n const buttonId = `${id}-button`;\n // support 'escape' resetting to the value that was set when the listbox opened\n const [lastValue, setLastValue] = React.useState<ScrollableListItemValue | undefined>(value);\n\n React.useEffect(() => {\n setLastValue(value);\n }, [open]);\n\n React.useEffect(() => {\n if (value === undefined) {\n if (defaultValue !== undefined && findByValue(flattenedData, defaultValue)) {\n setInputValueByRef(inputRef.current, defaultValue);\n } else {\n if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0].value);\n }\n }\n } else {\n if (!multiselect && !findByValue(flattenedData, value)) {\n if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0].value);\n }\n }\n }\n }, []);\n\n // event handlers\n const handleButtonKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>): void => {\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\n switch (event.key) {\n case 'Escape': {\n event.preventDefault();\n if (lastValue !== undefined) {\n setInputValueByRef(listboxInputRef.current, lastValue);\n }\n\n setOpen(false);\n break;\n }\n\n case 'Tab':\n case 'Enter': {\n if (event.key !== 'Tab') {\n event.preventDefault();\n }\n setOpen(false);\n break;\n }\n\n default:\n }\n\n if (otherProps.onKeyDown) {\n otherProps.onKeyDown(event);\n }\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>): void => {\n event.preventDefault();\n if (!multiselect) {\n setOpen(false);\n if (onBlur) {\n onBlur(createCustomEvent('blur'));\n }\n }\n };\n\n let text: string | JSX.Element = '';\n let more = 0;\n\n if (value !== undefined) {\n if (multiselect) {\n const selectedValues = value?.toString().split(',') || [];\n\n if (selectedValues.length === flattenedData.filter(item => !item.disabled).length) {\n text = texts.select.allOptionsSelected;\n } else {\n text = findByValue(flattenedData, selectedValues[0])?.text ?? '';\n more = selectedValues.length > 1 ? selectedValues.length - 1 : 0;\n }\n } else {\n const item = findByValue(flattenedData, value);\n\n if (item) {\n text = item.icon ? (\n <>\n {React.cloneElement(item.icon, {\n className: cn(item.icon.props.className, 'mr-1 -mt-px'),\n })}\n {item.text}\n </>\n ) : (\n item.text\n );\n }\n }\n }\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (onChange) {\n const item = findByValue(flattenedData, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const indexes = item?.path?.split('.') ?? [];\n\n if (indexes.length > 1) {\n // we don't want to map the current item\n indexes.pop();\n // we need to rebuild the path as we map\n let lastPath: string;\n\n (event as any).detail.parents = indexes.map(i => {\n lastPath = lastPath ? [lastPath, i].join('.') : i;\n return sanitizeItem(flattenedData.find(i => i.path === lastPath));\n });\n }\n\n onChange(event);\n }\n };\n\n const button: InternalButtonProps = {\n 'aria-haspopup': 'listbox' as const,\n 'aria-label': ariaLabel ? `${ariaLabel} ${text}` : undefined,\n 'aria-labelledby': ariaLabelledBy ? `${ariaLabelledBy} ${buttonId}` : undefined,\n disabled: disabled || readOnly,\n id: buttonId,\n onKeyDown: !disabled && !readOnly ? handleButtonKeyDown : undefined,\n tabIndex,\n type: 'button',\n };\n\n const listbox: InternalListboxProps = {\n ...otherProps,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data,\n disabled,\n emptyValue,\n onBlur,\n onClick: handleListboxClick,\n onChange: event => {\n setInputValueByRef(inputRef.current, event.target.value);\n },\n onKeyDown: handleListboxKeyDown,\n ref: listboxInputRef,\n value,\n };\n\n const input: InternalInputProps = {\n onChange: handleInputChange,\n ref: inputRef,\n value: String(value ?? ''),\n };\n\n return {\n button,\n listbox,\n input,\n popover: {\n open,\n onOpenChange: open => {\n if (!open && onBlur) {\n onBlur(createCustomEvent('blur'));\n }\n setOpen(open);\n },\n },\n text,\n more,\n };\n};\n"],"names":["useSelect","ariaLabel","ariaLabelledBy","data","defaultValue","disabled","emptyValue","id","nativeId","multiselect","onBlur","onClick","onChange","readOnly","tabIndex","value","otherProps","ref","texts","useLocalization","flattenedData","useFlattenedData","listboxInputRef","useMergedRef","open","setOpen","React","uuid","inputRef","buttonId","lastValue","setLastValue","undefined","findByValue","setInputValueByRef","current","length","handleButtonKeyDown","event","key","preventDefault","handleListboxKeyDown","onKeyDown","handleListboxClick","createCustomEvent","text","more","selectedValues","toString","split","filter","item","select","allOptionsSelected","icon","className","cn","props","handleInputChange","persist","target","detail","sanitizeItem","indexes","path","pop","lastPath","parents","map","i","join","find","button","type","listbox","input","String","popover","onOpenChange"],"mappings":";;;;;;;;MAyBaA,SAAS,GAAG,CACrB;EACI,YAAY,EAAEC,SAAS;EACvB,iBAAiB,EAAEC,cAAc;EACjCC,IAAI,GAAG,EAAE;EACTC,YAAY;EACZC,QAAQ;EACRC,UAAU;EACVC,EAAE,EAAEC,QAAQ;EACZC,WAAW;EACXC,MAAM;EACNC,OAAO;EACPC,QAAQ;EACRC,QAAQ;EACRC,QAAQ;EACRC,KAAK;EACL,GAAGC;CACO,EACdC,GAAgC;EAEhC,MAAM;IAAEC;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,aAAa,GAAGC,gBAAgB,CAAClB,IAAI,CAAC;EAC5C,MAAMmB,eAAe,GAAGC,YAAY,CAAmBN,GAAG,CAAC;EAC3D,MAAM,CAACO,IAAI,EAAEC,OAAO,CAAC,GAAGC,QAAc,CAAC,KAAK,CAAC;EAC7C,MAAMnB,EAAE,GAAGmB,OAAa,CAAC,MAAMlB,QAAQ,cAAcmB,EAAI,IAAI,EAAE,CAACnB,QAAQ,CAAC,CAAC;EAC1E,MAAMoB,QAAQ,GAA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I;QACd,IAAI,CAACA,IAAI,IAAId,MAAM,EAAE;UACjBA,MAAM,CAACkC,iBAAiB,CAAC,MAAM,CAAC,CAAC;;QAErCnB,OAAO,CAACD,IAAI,CAAC;;KAEpB;IACDqB,IAAI;IACJC;GACH;AACL;;;;"}
|
@@ -6,6 +6,7 @@ import { useBoundingClientRectListener } from '../../hooks/useBoundingClientRect
|
|
6
6
|
import { useMergedRef } from '../../hooks/useMergedRef.js';
|
7
7
|
import { createCustomKeyboardEvent } from '../../utils/input.js';
|
8
8
|
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
9
|
+
import { isAriaDirectionKey } from '../../utils/aria.js';
|
9
10
|
import { Root as Root$1, createListboxValueSetter } from '../../primitives/Listbox2/components/Root.js';
|
10
11
|
import '../../primitives/Listbox2/components/Option.js';
|
11
12
|
import '../../primitives/Listbox2/components/Group.js';
|
@@ -22,13 +23,13 @@ import { Search } from './components/Search.js';
|
|
22
23
|
import { useChildren } from './hooks/useChildren.js';
|
23
24
|
import { Create } from './components/Create.js';
|
24
25
|
import { Collection } from './components/Collection.js';
|
26
|
+
import { useIsHoverStatePaused } from '../../hooks/useIsHoverStatePaused.js';
|
25
27
|
|
26
28
|
const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, ref) {
|
27
29
|
const {
|
28
30
|
children: initialChildren,
|
29
31
|
defaultValue: defaultProp,
|
30
32
|
disabled = false,
|
31
|
-
disableSearch = false,
|
32
33
|
emptyValue = undefined,
|
33
34
|
highlighted = false,
|
34
35
|
invalid = false,
|
@@ -39,7 +40,6 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
|
|
39
40
|
onDelete,
|
40
41
|
onEdit,
|
41
42
|
readOnly = false,
|
42
|
-
tabIndex = 0,
|
43
43
|
tags = false,
|
44
44
|
value: prop,
|
45
45
|
...otherProps
|
@@ -64,6 +64,7 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
|
|
64
64
|
});
|
65
65
|
const setValue = createListboxValueSetter(multiple, _setValue);
|
66
66
|
const [validationError, setValidationError] = React__default.useState();
|
67
|
+
const [shouldPauseHoverState, setShouldPauseHoverState] = useIsHoverStatePaused();
|
67
68
|
const {
|
68
69
|
flattenedChildren,
|
69
70
|
filteredChildren,
|
@@ -96,6 +97,8 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
|
|
96
97
|
setSearchQuery,
|
97
98
|
setValidationError,
|
98
99
|
setValue,
|
100
|
+
shouldPauseHoverState,
|
101
|
+
setShouldPauseHoverState,
|
99
102
|
tags,
|
100
103
|
validationError,
|
101
104
|
value
|
@@ -128,6 +131,11 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
|
|
128
131
|
}
|
129
132
|
};
|
130
133
|
}
|
134
|
+
const handleListboxKeyDown = event => {
|
135
|
+
if (isAriaDirectionKey(event)) {
|
136
|
+
setShouldPauseHoverState(true);
|
137
|
+
}
|
138
|
+
};
|
131
139
|
const className = cn('border-grey-300 rounded border bg-white py-1.5 shadow-md outline-none', createCollectionClassName());
|
132
140
|
return /*#__PURE__*/React__default.createElement(Select2Context.Provider, {
|
133
141
|
value: context
|
@@ -172,7 +180,7 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
|
|
172
180
|
style: {
|
173
181
|
minWidth: dimensions !== null && dimensions !== void 0 && dimensions.width ? `${dimensions.width}px` : undefined
|
174
182
|
}
|
175
|
-
},
|
183
|
+
}, flattenedChildren.length > 0 || onCreate ? /*#__PURE__*/React__default.createElement(Search, {
|
176
184
|
placeholder: onCreate ? texts.select2.searchOrCreate : texts.select2.search,
|
177
185
|
ref: searchRef
|
178
186
|
}) : null, flattenedChildren.length <= 0 ? /*#__PURE__*/React__default.createElement("div", {
|
@@ -183,6 +191,7 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
|
|
183
191
|
customSelector: ":scope > button",
|
184
192
|
disabled: disabled,
|
185
193
|
multiple: multiple,
|
194
|
+
onKeyDown: handleListboxKeyDown,
|
186
195
|
readOnly: readOnly,
|
187
196
|
ref: listboxRef,
|
188
197
|
setValue: setValue,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Select2.js","sources":["../../../../../../../src/components/Select2/Select2.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport * as ListboxPrimitive from '../../primitives/Listbox2/Listbox2';\nimport { Select2OptionValue, Select2Value } from './types';\nimport { Option, Select2OptionProps } from './components/Option';\nimport { Group, Select2GroupProps } from './components/Group';\nimport { Select2TitleProps, Title } from './components/Title';\nimport { Select2Context } from './components/Context';\nimport { createCollectionClassName } from './utilities';\nimport { useMergedRef } from '../../hooks/useMergedRef';\nimport { useBoundingClientRectListener } from '../../hooks/useBoundingClientRectListener';\nimport { createCustomKeyboardEvent } from '../../utils/input';\nimport { Trigger } from './components/Trigger';\nimport { useIsFormControl } from '../../hooks/useIsFormControl';\nimport { BubbleSelect } from '../../primitives/BubbleSelect';\nimport { Search } from './components/Search';\nimport { useChildren } from './hooks/useChildren';\nimport { Color } from '../../utils/colors';\nimport { Create } from './components/Create';\nimport { Collection } from './components/Collection';\nimport { CollectionRef } from '../../primitives/Collection/Collection';\nimport { useLocalization } from '../Provider/Localization';\n//import { All } from './components/All';\n\ntype Select2Texts = {\n allSelect: string;\n allDeselect: string;\n cancel: string;\n chooseColor: string;\n create: string;\n delete: string;\n save: string;\n search: string;\n searchOrCreate: string;\n};\n\ntype Select2Props = Omit<React.HTMLAttributes<HTMLButtonElement>, 'children' | 'defaultValue' | 'onChange' | 'value'> & {\n autoFocus?: boolean;\n children: Array<React.ReactElement<Select2OptionProps> | React.ReactElement<Select2GroupProps>>;\n defaultValue?: Select2Value;\n emptyValue?: Select2OptionValue;\n disabled?: boolean;\n disableSearch?: boolean;\n highlighted?: boolean;\n invalid?: boolean;\n multiple?: boolean;\n name?: string;\n onChange?: (value: Select2Value) => void;\n onCreate?: (name: string, color: Color | undefined) => Promise<Select2OptionProps>;\n onDelete?: (value: Select2OptionValue) => Promise<void>;\n onEdit?: (value: Select2OptionValue, text: string, color: Color | undefined) => Promise<void>;\n readOnly?: boolean;\n required?: boolean;\n tags?: boolean;\n value?: Select2Value;\n};\ntype Select2PropsWithStatics = React.ForwardRefExoticComponent<Select2Props & React.RefAttributes<HTMLButtonElement>> & {\n Option: React.ForwardRefExoticComponent<Select2OptionProps>;\n Group: React.ForwardRefExoticComponent<Select2GroupProps>;\n Title: React.ForwardRefExoticComponent<Select2TitleProps>;\n};\n\nconst Select2 = React.forwardRef<HTMLButtonElement, Select2Props>(function Select2(props, ref) {\n const {\n children: initialChildren,\n defaultValue: defaultProp,\n disabled = false,\n disableSearch = false,\n emptyValue = undefined,\n highlighted = false,\n invalid = false,\n multiple = false,\n name,\n onChange,\n onCreate,\n onDelete,\n onEdit,\n readOnly = false,\n tabIndex = 0,\n tags = false,\n value: prop,\n ...otherProps\n } = props;\n\n // refs\n const internalRef = useMergedRef<HTMLButtonElement>(ref);\n const listboxRef = React.useRef<CollectionRef>(null);\n const searchRef = React.useRef<HTMLInputElement>(null);\n const { texts } = useLocalization();\n // align the listbox min width with the width of the input - it should never be smaller\n const dimensions = useBoundingClientRectListener(internalRef);\n\n // state\n const [open, setOpen] = React.useState(false);\n const [value, _setValue] = useControllableState<Select2Value>({\n // uncontrolled\n defaultProp,\n // controlled\n onChange,\n prop,\n });\n const setValue = ListboxPrimitive.createListboxValueSetter(multiple, _setValue);\n const [validationError, setValidationError] = React.useState<Error | undefined>();\n\n const { flattenedChildren, filteredChildren, searchQuery, setSearchQuery } = useChildren({\n children: initialChildren,\n emptyValue,\n multiple,\n open,\n setValue,\n value,\n });\n\n // context\n const context = {\n disabled,\n highlighted,\n invalid,\n listboxRef,\n multiple,\n onCreate,\n onDelete,\n onEdit,\n open,\n readOnly,\n ref: internalRef,\n searchQuery,\n searchRef,\n setOpen,\n setSearchQuery,\n setValidationError,\n setValue,\n tags,\n validationError,\n value,\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {\n if (open) {\n event.preventDefault();\n } else if (event.key === 'ArrowDown') {\n setOpen(true);\n }\n\n // the focus should always remain on the input, so we forward events on to the listbox\n listboxRef.current?.dispatchEvent(createCustomKeyboardEvent(event as React.KeyboardEvent<HTMLInputElement>));\n };\n\n let handleBlur;\n\n if (otherProps.onBlur) {\n // we might be focusing on an input or something inside the dropdown that was triggered by the select\n // so see if the element gaining focus is inside a portal and look up its controller\n // if we don't do this, things like validate on blur occur while simply opening the select\n handleBlur = (event: React.FocusEvent<HTMLButtonElement>) => {\n const elementGainingFocus = event.relatedTarget;\n\n if (elementGainingFocus === undefined) {\n return;\n }\n\n const portalId = elementGainingFocus?.closest('[data-radix-popper-content-wrapper] > :first-child')?.id;\n\n if (!portalId || event.currentTarget.getAttribute(`aria-controls`) !== portalId) {\n otherProps.onBlur?.(event);\n }\n };\n }\n\n const className = cn('border-grey-300 rounded border bg-white py-1.5 shadow-md outline-none', createCollectionClassName());\n\n return (\n <Select2Context.Provider value={context}>\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n <ControlledHiddenField\n emptyValue={emptyValue}\n multiple={multiple || tags}\n name={name}\n options={flattenedChildren.map(child => child.props.value)}\n parentRef={internalRef}\n setValue={setValue}\n value={value}\n />\n <PopoverPrimitive.Trigger asChild data-taco=\"Select2\">\n <Trigger\n {...otherProps}\n aria-haspopup=\"listbox\"\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n ref={internalRef}>\n {flattenedChildren}\n </Trigger>\n </PopoverPrimitive.Trigger>\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n asChild\n align=\"start\"\n onOpenAutoFocus={event => {\n event.preventDefault();\n event.stopPropagation();\n internalRef.current?.focus();\n }}\n onCloseAutoFocus={event => {\n event.preventDefault();\n event.stopPropagation();\n internalRef.current?.focus();\n }}\n sideOffset={4}\n tabIndex={-1}>\n <div className={className} style={{ minWidth: dimensions?.width ? `${dimensions.width}px` : undefined }}>\n {!disableSearch && (flattenedChildren.length > 0 || onCreate) ? (\n <Search\n placeholder={onCreate ? texts.select2.searchOrCreate : texts.select2.search}\n ref={searchRef}\n />\n ) : null}\n {flattenedChildren.length <= 0 ? (\n <div className=\"text-grey-700 -mt-0.5 flex h-8 items-center px-2\" role=\"presentation\">\n No results found...\n </div>\n ) : (\n <ListboxPrimitive.Root\n className=\"flex flex-col gap-0.5\"\n customSelector=\":scope > button\"\n disabled={disabled}\n multiple={multiple}\n readOnly={readOnly}\n ref={listboxRef}\n setValue={setValue}\n tabIndex={-1}\n value={value}>\n {/*multiple && !searchQuery && Array.isArray(value) ? (\n <All\n children={flattenedChildren}\n onToggle={_setValue}\n selected={value.length === flattenedChildren.length}\n />\n ) : null*/}\n <Collection>{filteredChildren}</Collection>\n {onCreate ? <Create onCreate={onCreate} options={flattenedChildren} /> : null}\n </ListboxPrimitive.Root>\n )}\n </div>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n </Select2Context.Provider>\n );\n}) as Select2PropsWithStatics;\nSelect2.Option = Option;\nSelect2.Group = Group;\nSelect2.Title = Title;\n\nconst ControlledHiddenField = props => {\n const { emptyValue, multiple, name, options, parentRef, value, setValue } = props;\n const isFormControl = useIsFormControl(parentRef, () => setValue(multiple ? [] : undefined));\n\n let bubbleValue;\n\n if (isFormControl) {\n if (value !== undefined) {\n if (multiple) {\n bubbleValue = Array.isArray(value) ? value.map(String) : [value === null ? '' : String(value)];\n } else {\n bubbleValue = value === null ? '' : String(value);\n }\n }\n\n return (\n <BubbleSelect aria-hidden key={String(bubbleValue)} multiple={multiple} name={name} value={bubbleValue}>\n {emptyValue !== undefined ? <option value={emptyValue} /> : null}\n {options.map(option => (\n <option key={String(option)} value={String(option)} />\n ))}\n </BubbleSelect>\n );\n }\n\n return null;\n};\nSelect2.displayName = 'Select2';\n\nexport { Select2 };\n\nexport type {\n Select2Texts,\n Select2GroupProps,\n Select2OptionProps,\n Select2OptionValue,\n Select2Value,\n Select2Props,\n Select2TitleProps,\n};\n"],"names":["Select2","React","forwardRef","props","ref","children","initialChildren","defaultValue","defaultProp","disabled","disableSearch","emptyValue","undefined","highlighted","invalid","multiple","name","onChange","onCreate","onDelete","onEdit","readOnly","tabIndex","tags","value","prop","otherProps","internalRef","useMergedRef","listboxRef","useRef","searchRef","texts","useLocalization","dimensions","useBoundingClientRectListener","open","setOpen","useState","_setValue","useControllableState","setValue","ListboxPrimitive","validationError","setValidationError","flattenedChildren","filteredChildren","searchQuery","setSearchQuery","useChildren","context","handleKeyDown","event","preventDefault","key","current","dispatchEvent","createCustomKeyboardEvent","handleBlur","onBlur","elementGainingFocus","relatedTarget","portalId","closest","id","currentTarget","getAttribute","className","cn","createCollectionClassName","Select2Context","Provider","PopoverPrimitive","onOpenChange","ControlledHiddenField","options","map","child","parentRef","asChild","Trigger","onKeyDown","align","onOpenAutoFocus","stopPropagation","focus","onCloseAutoFocus","sideOffset","style","minWidth","width","length","Search","placeholder","select2","searchOrCreate","search","role","customSelector","Collection","Create","Option","Group","Title","isFormControl","useIsFormControl","bubbleValue","Array","isArray","String","BubbleSelect","option","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;MAgEMA,OAAO,gBAAGC,cAAK,CAACC,UAAU,CAAkC,SAASF,OAAO,CAACG,KAAK,EAAEC,GAAG;EACzF,MAAM;IACFC,QAAQ,EAAEC,eAAe;IACzBC,YAAY,EAAEC,WAAW;IACzBC,QAAQ,GAAG,KAAK;IAChBC,aAAa,GAAG,KAAK;IACrBC,UAAU,GAAGC,SAAS;IACtBC,WAAW,GAAG,KAAK;IACnBC,OAAO,GAAG,KAAK;IACfC,QAAQ,GAAG,KAAK;IAChBC,IAAI;IACJC,QAAQ;IACRC,QAAQ;IACRC,QAAQ;IACRC,MAAM;IACNC,QAAQ,GAAG,KAAK;IAChBC,QAAQ,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E,GAAGqF,MAAM,CAACrF,KAAK,CAAC,CAAC;OACjG,MAAM;QACHkF,WAAW,GAAGlF,KAAK,KAAK,IAAI,GAAG,EAAE,GAAGqF,MAAM,CAACrF,KAAK,CAAC;;;IAIzD,oBACIvB,6BAAC6G,YAAY;;MAAaxD,GAAG,EAAEuD,MAAM,CAACH,WAAW,CAAC;MAAE3F,QAAQ,EAAEA,QAAQ;MAAEC,IAAI,EAAEA,IAAI;MAAEQ,KAAK,EAAEkF;OACtF/F,UAAU,KAAKC,SAAS,gBAAGX;MAAQuB,KAAK,EAAEb;MAAc,GAAG,IAAI,EAC/DgE,OAAO,CAACC,GAAG,CAACmC,MAAM,iBACf9G;MAAQqD,GAAG,EAAEuD,MAAM,CAACE,MAAM,CAAC;MAAEvF,KAAK,EAAEqF,MAAM,CAACE,MAAM;MACpD,CAAC,CACS;;EAIvB,OAAO,IAAI;AACf,CAAC;AACD/G,OAAO,CAACgH,WAAW,GAAG,SAAS;;;;"}
|
1
|
+
{"version":3,"file":"Select2.js","sources":["../../../../../../../src/components/Select2/Select2.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport * as ListboxPrimitive from '../../primitives/Listbox2/Listbox2';\nimport { Select2OptionValue, Select2Value } from './types';\nimport { Option, Select2OptionProps } from './components/Option';\nimport { Group, Select2GroupProps } from './components/Group';\nimport { Select2TitleProps, Title } from './components/Title';\nimport { Select2Context } from './components/Context';\nimport { createCollectionClassName } from './utilities';\nimport { useMergedRef } from '../../hooks/useMergedRef';\nimport { useBoundingClientRectListener } from '../../hooks/useBoundingClientRectListener';\nimport { createCustomKeyboardEvent } from '../../utils/input';\nimport { Trigger } from './components/Trigger';\nimport { useIsFormControl } from '../../hooks/useIsFormControl';\nimport { BubbleSelect } from '../../primitives/BubbleSelect';\nimport { Search } from './components/Search';\nimport { useChildren } from './hooks/useChildren';\n\nimport { Create } from './components/Create';\nimport { Collection } from './components/Collection';\nimport { CollectionRef } from '../../primitives/Collection/Collection';\nimport { useLocalization } from '../Provider/Localization';\nimport { Color } from '../../types';\nimport { useIsHoverStatePaused } from '../../hooks/useIsHoverStatePaused';\nimport { isAriaDirectionKey } from '../../utils/aria';\n//import { All } from './components/All';\n\ntype Select2Texts = {\n allSelect: string;\n allDeselect: string;\n cancel: string;\n chooseColor: string;\n create: string;\n delete: string;\n save: string;\n search: string;\n searchOrCreate: string;\n};\n\ntype Select2Props = Omit<React.HTMLAttributes<HTMLButtonElement>, 'children' | 'defaultValue' | 'onChange' | 'value'> & {\n autoFocus?: boolean;\n children: Array<React.ReactElement<Select2OptionProps> | React.ReactElement<Select2GroupProps>>;\n defaultValue?: Select2Value;\n emptyValue?: Select2OptionValue;\n disabled?: boolean;\n highlighted?: boolean;\n invalid?: boolean;\n multiple?: boolean;\n name?: string;\n onChange?: (value: Select2Value) => void;\n onCreate?: (name: string, color: Color | undefined) => Promise<Select2OptionProps>;\n onDelete?: (value: Select2OptionValue) => Promise<void>;\n onEdit?: (value: Select2OptionValue, text: string, color: Color | undefined) => Promise<void>;\n readOnly?: boolean;\n required?: boolean;\n tags?: boolean;\n value?: Select2Value;\n};\ntype Select2PropsWithStatics = React.ForwardRefExoticComponent<Select2Props & React.RefAttributes<HTMLButtonElement>> & {\n Option: React.ForwardRefExoticComponent<Select2OptionProps>;\n Group: React.ForwardRefExoticComponent<Select2GroupProps>;\n Title: React.ForwardRefExoticComponent<Select2TitleProps>;\n};\n\nconst Select2 = React.forwardRef<HTMLButtonElement, Select2Props>(function Select2(props, ref) {\n const {\n children: initialChildren,\n defaultValue: defaultProp,\n disabled = false,\n emptyValue = undefined,\n highlighted = false,\n invalid = false,\n multiple = false,\n name,\n onChange,\n onCreate,\n onDelete,\n onEdit,\n readOnly = false,\n tags = false,\n value: prop,\n ...otherProps\n } = props;\n\n // refs\n const internalRef = useMergedRef<HTMLButtonElement>(ref);\n const listboxRef = React.useRef<CollectionRef>(null);\n const searchRef = React.useRef<HTMLInputElement>(null);\n const { texts } = useLocalization();\n // align the listbox min width with the width of the input - it should never be smaller\n const dimensions = useBoundingClientRectListener(internalRef);\n\n // state\n const [open, setOpen] = React.useState(false);\n const [value, _setValue] = useControllableState<Select2Value>({\n // uncontrolled\n defaultProp,\n // controlled\n onChange,\n prop,\n });\n const setValue = ListboxPrimitive.createListboxValueSetter(multiple, _setValue);\n const [validationError, setValidationError] = React.useState<Error | undefined>();\n const [shouldPauseHoverState, setShouldPauseHoverState] = useIsHoverStatePaused();\n\n const { flattenedChildren, filteredChildren, searchQuery, setSearchQuery } = useChildren({\n children: initialChildren,\n emptyValue,\n multiple,\n open,\n setValue,\n value,\n });\n\n // context\n const context = {\n disabled,\n highlighted,\n invalid,\n listboxRef,\n multiple,\n onCreate,\n onDelete,\n onEdit,\n open,\n readOnly,\n ref: internalRef,\n searchQuery,\n searchRef,\n setOpen,\n setSearchQuery,\n setValidationError,\n setValue,\n shouldPauseHoverState,\n setShouldPauseHoverState,\n tags,\n validationError,\n value,\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {\n if (open) {\n event.preventDefault();\n } else if (event.key === 'ArrowDown') {\n setOpen(true);\n }\n\n // the focus should always remain on the input, so we forward events on to the listbox\n listboxRef.current?.dispatchEvent(createCustomKeyboardEvent(event as React.KeyboardEvent<HTMLInputElement>));\n };\n\n let handleBlur;\n\n if (otherProps.onBlur) {\n // we might be focusing on an input or something inside the dropdown that was triggered by the select\n // so see if the element gaining focus is inside a portal and look up its controller\n // if we don't do this, things like validate on blur occur while simply opening the select\n handleBlur = (event: React.FocusEvent<HTMLButtonElement>) => {\n const elementGainingFocus = event.relatedTarget;\n\n if (elementGainingFocus === undefined) {\n return;\n }\n\n const portalId = elementGainingFocus?.closest('[data-radix-popper-content-wrapper] > :first-child')?.id;\n\n if (!portalId || event.currentTarget.getAttribute(`aria-controls`) !== portalId) {\n otherProps.onBlur?.(event);\n }\n };\n }\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {\n if (isAriaDirectionKey(event)) {\n setShouldPauseHoverState(true);\n }\n };\n\n const className = cn('border-grey-300 rounded border bg-white py-1.5 shadow-md outline-none', createCollectionClassName());\n\n return (\n <Select2Context.Provider value={context}>\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n <ControlledHiddenField\n emptyValue={emptyValue}\n multiple={multiple || tags}\n name={name}\n options={flattenedChildren.map(child => child.props.value)}\n parentRef={internalRef}\n setValue={setValue}\n value={value}\n />\n <PopoverPrimitive.Trigger asChild data-taco=\"Select2\">\n <Trigger\n {...otherProps}\n aria-haspopup=\"listbox\"\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n ref={internalRef}>\n {flattenedChildren}\n </Trigger>\n </PopoverPrimitive.Trigger>\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n asChild\n align=\"start\"\n onOpenAutoFocus={event => {\n event.preventDefault();\n event.stopPropagation();\n internalRef.current?.focus();\n }}\n onCloseAutoFocus={event => {\n event.preventDefault();\n event.stopPropagation();\n internalRef.current?.focus();\n }}\n sideOffset={4}\n tabIndex={-1}>\n <div className={className} style={{ minWidth: dimensions?.width ? `${dimensions.width}px` : undefined }}>\n {flattenedChildren.length > 0 || onCreate ? (\n <Search\n placeholder={onCreate ? texts.select2.searchOrCreate : texts.select2.search}\n ref={searchRef}\n />\n ) : null}\n {flattenedChildren.length <= 0 ? (\n <div className=\"text-grey-700 -mt-0.5 flex h-8 items-center px-2\" role=\"presentation\">\n No results found...\n </div>\n ) : (\n <ListboxPrimitive.Root\n className=\"flex flex-col gap-0.5\"\n customSelector=\":scope > button\"\n disabled={disabled}\n multiple={multiple}\n onKeyDown={handleListboxKeyDown}\n readOnly={readOnly}\n ref={listboxRef}\n setValue={setValue}\n tabIndex={-1}\n value={value}>\n {/*multiple && !searchQuery && Array.isArray(value) ? (\n <All\n children={flattenedChildren}\n onToggle={_setValue}\n selected={value.length === flattenedChildren.length}\n />\n ) : null*/}\n <Collection>{filteredChildren}</Collection>\n {onCreate ? <Create onCreate={onCreate} options={flattenedChildren} /> : null}\n </ListboxPrimitive.Root>\n )}\n </div>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n </Select2Context.Provider>\n );\n}) as Select2PropsWithStatics;\nSelect2.Option = Option;\nSelect2.Group = Group;\nSelect2.Title = Title;\n\nconst ControlledHiddenField = props => {\n const { emptyValue, multiple, name, options, parentRef, value, setValue } = props;\n const isFormControl = useIsFormControl(parentRef, () => setValue(multiple ? [] : undefined));\n\n let bubbleValue;\n\n if (isFormControl) {\n if (value !== undefined) {\n if (multiple) {\n bubbleValue = Array.isArray(value) ? value.map(String) : [value === null ? '' : String(value)];\n } else {\n bubbleValue = value === null ? '' : String(value);\n }\n }\n\n return (\n <BubbleSelect aria-hidden key={String(bubbleValue)} multiple={multiple} name={name} value={bubbleValue}>\n {emptyValue !== undefined ? <option value={emptyValue} /> : null}\n {options.map(option => (\n <option key={String(option)} value={String(option)} />\n ))}\n </BubbleSelect>\n );\n }\n\n return null;\n};\nSelect2.displayName = 'Select2';\n\nexport { Select2 };\n\nexport type {\n Select2Texts,\n Select2GroupProps,\n Select2OptionProps,\n Select2OptionValue,\n Select2Value,\n Select2Props,\n Select2TitleProps,\n};\n"],"names":["Select2","React","forwardRef","props","ref","children","initialChildren","defaultValue","defaultProp","disabled","emptyValue","undefined","highlighted","invalid","multiple","name","onChange","onCreate","onDelete","onEdit","readOnly","tags","value","prop","otherProps","internalRef","useMergedRef","listboxRef","useRef","searchRef","texts","useLocalization","dimensions","useBoundingClientRectListener","open","setOpen","useState","_setValue","useControllableState","setValue","ListboxPrimitive","validationError","setValidationError","shouldPauseHoverState","setShouldPauseHoverState","useIsHoverStatePaused","flattenedChildren","filteredChildren","searchQuery","setSearchQuery","useChildren","context","handleKeyDown","event","preventDefault","key","current","dispatchEvent","createCustomKeyboardEvent","handleBlur","onBlur","elementGainingFocus","relatedTarget","portalId","closest","id","currentTarget","getAttribute","handleListboxKeyDown","isAriaDirectionKey","className","cn","createCollectionClassName","Select2Context","Provider","PopoverPrimitive","onOpenChange","ControlledHiddenField","options","map","child","parentRef","asChild","Trigger","onKeyDown","align","onOpenAutoFocus","stopPropagation","focus","onCloseAutoFocus","sideOffset","tabIndex","style","minWidth","width","length","Search","placeholder","select2","searchOrCreate","search","role","customSelector","Collection","Create","Option","Group","Title","isFormControl","useIsFormControl","bubbleValue","Array","isArray","String","BubbleSelect","option","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;MAkEMA,OAAO,gBAAGC,cAAK,CAACC,UAAU,CAAkC,SAASF,OAAO,CAACG,KAAK,EAAEC,GAAG;EACzF,MAAM;IACFC,QAAQ,EAAEC,eAAe;IACzBC,YAAY,EAAEC,WAAW;IACzBC,QAAQ,GAAG,KAAK;IAChBC,UAAU,GAAGC,SAAS;IACtBC,WAAW,GAAG,KAAK;IACnBC,OAAO,GAAG,KAAK;IACfC,QAAQ,GAAG,KAAK;IAChBC,IAAI;IACJC,QAAQ;IACRC,QAAQ;IACRC,QAAQ;IACRC,MAAM;IACNC,QAAQ,GAAG,KAAK;IAChBC,IAAI,GAAG,KAAK;IACZC,KAAK,EAAEC,IAAI;IACX,GAAGC;GACN,GAAGrB,KAAK;;EAGT,MAAMsB,WAAW,GAAGC,YAAY,CAAoBtB,GAAG,CAAC;EACxD,MAAMuB,UAAU,GAAG1B,cAAK,CAAC2B,MAAM,CAAgB,IAAI,CAAC;EACpD,MAAMC,SAAS,GAAG5B,cAAK,CAAC2B,MAAM,CAAmB,IAAI,CAAC;EACtD,MAAM;IAAEE;GAAO,GAAGC,eAAe,EAAE;;EAEnC,MAAMC,UAAU,GAAGC,6BAA6B,CAACR,WAAW,CAAC;;EAG7D,MAAM,CAACS,IAAI,EAAEC,OAAO,CAAC,GAAGlC,cAAK,CAACmC,QAAQ,CAAC,KAAK,CAAC;EAC7C,MAAM,CAACd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EAAEA,IAAI;MAAEO,KAAK,EAAEwF;OACtFpG,UAAU,KAAKC,SAAS,gBAAGV;MAAQqB,KAAK,EAAEZ;MAAc,GAAG,IAAI,EAC/DoE,OAAO,CAACC,GAAG,CAACoC,MAAM,iBACflH;MAAQsD,GAAG,EAAE0D,MAAM,CAACE,MAAM,CAAC;MAAE7F,KAAK,EAAE2F,MAAM,CAACE,MAAM;MACpD,CAAC,CACS;;EAIvB,OAAO,IAAI;AACf,CAAC;AACDnH,OAAO,CAACoH,WAAW,GAAG,SAAS;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Context.js","sources":["../../../../../../../../src/components/Select2/components/Context.tsx"],"sourcesContent":["import React from 'react';\nimport { CollectionRef } from '../../../primitives/Collection/Collection';\nimport {
|
1
|
+
{"version":3,"file":"Context.js","sources":["../../../../../../../../src/components/Select2/components/Context.tsx"],"sourcesContent":["import React from 'react';\nimport { CollectionRef } from '../../../primitives/Collection/Collection';\nimport { Select2OptionValue, Select2Value } from '../types';\nimport { Select2OptionProps } from './Option';\nimport { Color } from '../../../types';\n\nexport type Select2ContextProps = {\n disabled: boolean;\n highlighted: boolean;\n invalid: boolean;\n listboxRef: React.RefObject<CollectionRef>;\n multiple: boolean;\n onCreate?: (text: string, color: Color | undefined) => Promise<Select2OptionProps>;\n onDelete?: (value: Select2OptionValue) => Promise<void>;\n onEdit?: (value: Select2OptionValue, text: string, color: Color | undefined) => Promise<void>;\n open: boolean;\n readOnly: boolean;\n ref: React.RefObject<HTMLButtonElement>;\n searchQuery: string;\n searchRef?: React.RefObject<HTMLInputElement>;\n setOpen: (open: boolean) => void;\n setSearchQuery: (value: string) => void;\n setValidationError: (error: Error | undefined) => void;\n setValue: (value: Select2OptionValue) => void;\n shouldPauseHoverState: boolean;\n setShouldPauseHoverState: (pause: boolean) => void;\n tags?: boolean;\n validationError?: Error;\n value?: Select2Value;\n};\n\nexport const Select2Context = React.createContext({} as Select2ContextProps);\nexport const useSelect2Context = () => React.useContext(Select2Context);\n"],"names":["Select2Context","React","createContext","useSelect2Context","useContext"],"mappings":";;MA+BaA,cAAc,gBAAGC,cAAK,CAACC,aAAa,CAAC,EAAyB;MAC9DC,iBAAiB,GAAG,MAAMF,cAAK,CAACG,UAAU,CAACJ,cAAc;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Create.js","sources":["../../../../../../../../src/components/Select2/components/Create.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { isAriaSelectionKey } from '../../../utils/aria';\nimport {
|
1
|
+
{"version":3,"file":"Create.js","sources":["../../../../../../../../src/components/Select2/components/Create.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { isAriaSelectionKey } from '../../../utils/aria';\nimport { Tag } from '../../Tag/Tag';\nimport { createOptionClassName } from '../utilities';\nimport { useSelect2Context } from './Context';\nimport { Select2OptionProps } from './Option';\nimport { useLocalization } from '../../Provider/Localization';\nimport { Color } from '../../../types';\n\nexport type CreateProps = {\n onCreate: (name: string, color: Color | undefined) => Promise<Select2OptionProps>;\n options: React.ReactElement<Select2OptionProps>[];\n};\n\nexport const getNextColor = (options: React.ReactElement<Select2OptionProps>[]): Color | undefined => {\n const occurences = options.reduce((occurences, option) => {\n if (option.props.color) {\n occurences[option.props.color] = occurences[option.props.color] ? occurences[option.props.color] + 1 : 1;\n }\n return occurences;\n }, {});\n\n const colors = Object.keys(occurences);\n\n if (colors.length) {\n return colors.sort((a, b) => occurences[b] - occurences[a])[0] as Color;\n }\n\n return undefined;\n};\n\nexport const Create = (props: CreateProps) => {\n const { onCreate: handleCreate, options } = props;\n const { multiple, searchQuery, setOpen, setSearchQuery, setValidationError, setValue } = useSelect2Context();\n const { texts } = useLocalization();\n\n // determine what the next color tag should be based on color occurences\n const nextColor = React.useMemo(() => getNextColor(options), [options]);\n\n if (!searchQuery) {\n return null;\n }\n\n const handleClick = async () => {\n try {\n const item = await handleCreate(searchQuery, nextColor);\n setValue(item.value);\n\n if (multiple) {\n setSearchQuery('');\n } else {\n setOpen(false);\n }\n } catch (error) {\n setValidationError(error as Error);\n }\n };\n\n const handleKeyDown = event => {\n if (isAriaSelectionKey(event)) {\n event.currentTarget.click();\n }\n };\n\n const className = cn('!w-[calc(100%_-_theme(spacing.3))] ml-1.5', createOptionClassName());\n return (\n <button className={className} onClick={handleClick} onKeyDown={handleKeyDown}>\n <span className=\"flex items-center gap-1.5\">\n {texts.select2.create}\n <Tag color={nextColor} className=\"cursor-pointer\">\n {searchQuery}\n </Tag>\n </span>\n </button>\n );\n};\n"],"names":["getNextColor","options","occurences","reduce","option","props","color","colors","Object","keys","length","sort","a","b","undefined","Create","onCreate","handleCreate","multiple","searchQuery","setOpen","setSearchQuery","setValidationError","setValue","useSelect2Context","texts","useLocalization","nextColor","React","useMemo","handleClick","item","value","error","handleKeyDown","event","isAriaSelectionKey","currentTarget","click","className","cn","createOptionClassName","onClick","onKeyDown","select2","create","Tag"],"mappings":";;;;;;;;;MAeaA,YAAY,GAAIC,OAAiD;EAC1E,MAAMC,UAAU,GAAGD,OAAO,CAACE,MAAM,CAAC,CAACD,UAAU,EAAEE,MAAM;IACjD,IAAIA,MAAM,CAACC,KAAK,CAACC,KAAK,EAAE;MACpBJ,UAAU,CAACE,MAAM,CAACC,KAAK,CAACC,KAAK,CAAC,GAAGJ,UAAU,CAACE,MAAM,CAACC,KAAK,CAACC,KAAK,CAAC,GAAGJ,UAAU,CAACE,MAAM,CAACC,KAAK,CAACC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;;IAE5G,OAAOJ,UAAU;GACpB,EAAE,EAAE,CAAC;EAEN,MAAMK,MAAM,GAAGC,MAAM,CAACC,IAAI,CAACP,UAAU,CAAC;EAEtC,IAAIK,MAAM,CAACG,MAAM,EAAE;IACf,OAAOH,MAAM,CAACI,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKX,UAAU,CAACW,CAAC,CAAC,GAAGX,UAAU,CAACU,CAAC,CAAC,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CACV,CACH,CACF;AAEjB;;;;"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import React__default from 'react';
|
2
2
|
import cn from 'classnames';
|
3
|
+
import { AVAILABLE_COLORS, getSubtleColorShadeClasses } from '../../../utils/taillwind.js';
|
3
4
|
import { Icon } from '../../Icon/Icon.js';
|
4
5
|
import { useLocalization } from '../../Provider/Localization.js';
|
5
6
|
import { Button } from '../../Button/Button.js';
|
@@ -8,11 +9,9 @@ import { Popover } from '../../Popover/Popover.js';
|
|
8
9
|
import { Field } from '../../Field/Field.js';
|
9
10
|
import { Group } from '../../Group/Group.js';
|
10
11
|
import { Root, Item, Indicator } from '@radix-ui/react-radio-group';
|
11
|
-
import { TAG_COLORS } from '../../Tag/Tag.js';
|
12
12
|
import { useSelect2Context } from './Context.js';
|
13
13
|
import { _catch } from '../../../../../../node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js';
|
14
14
|
|
15
|
-
const AVAILABLE_COLORS = /*#__PURE__*/Object.keys(TAG_COLORS);
|
16
15
|
const EditPopover = props => {
|
17
16
|
const {
|
18
17
|
color: initialColor,
|
@@ -173,7 +172,7 @@ const Colours = props => {
|
|
173
172
|
value: color
|
174
173
|
}, AVAILABLE_COLORS.map(availableColor => /*#__PURE__*/React__default.createElement(Item, {
|
175
174
|
"aria-label": color,
|
176
|
-
className: cn('flex h-6 w-6 cursor-pointer items-center justify-center rounded',
|
175
|
+
className: cn('flex h-6 w-6 cursor-pointer items-center justify-center rounded', getSubtleColorShadeClasses(availableColor)),
|
177
176
|
key: availableColor,
|
178
177
|
onFocus: () => onChangeColor(availableColor),
|
179
178
|
value: availableColor
|