@economic/taco 0.0.31-alpha.2 → 0.0.32-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/esm/components/Menu/Menu.js +20 -43
- package/dist/esm/components/Menu/Menu.js.map +1 -1
- package/dist/esm/components/Navigation/Navigation.js +35 -44
- package/dist/esm/components/Navigation/Navigation.js.map +1 -1
- package/dist/esm/components/Pagination/Pagination.js +39 -56
- package/dist/esm/components/Pagination/Pagination.js.map +1 -1
- package/dist/esm/components/Popover/Popover.js +29 -34
- package/dist/esm/components/Popover/Popover.js.map +1 -1
- package/dist/esm/components/Progress/Progress.js +11 -15
- package/dist/esm/components/Progress/Progress.js.map +1 -1
- package/dist/esm/components/Provider/Provider.js +13 -18
- package/dist/esm/components/Provider/Provider.js.map +1 -1
- package/dist/esm/components/RadioGroup/RadioGroup.js +45 -57
- package/dist/esm/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/esm/components/Select/Select.js +30 -31
- package/dist/esm/components/Select/Select.js.map +1 -1
- package/dist/esm/components/Spinner/Spinner.js +12 -19
- package/dist/esm/components/Spinner/Spinner.js.map +1 -1
- package/dist/esm/components/Switch/Switch.js +9 -10
- package/dist/esm/components/Switch/Switch.js.map +1 -1
- package/dist/esm/components/Tabs/Tabs.js +25 -27
- package/dist/esm/components/Tabs/Tabs.js.map +1 -1
- package/dist/esm/components/Textarea/Textarea.js +11 -9
- package/dist/esm/components/Textarea/Textarea.js.map +1 -1
- package/dist/esm/components/Toast/Toaster.js +88 -118
- package/dist/esm/components/Toast/Toaster.js.map +1 -1
- package/dist/esm/components/Tooltip/Tooltip.js +7 -8
- package/dist/esm/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/esm/components/Treeview/Treeview.js +26 -36
- package/dist/esm/components/Treeview/Treeview.js.map +1 -1
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.js +1 -1
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.js.map +1 -1
- package/dist/taco.cjs.development.js +495 -611
- 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 +2 -2
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Spinner.js","sources":["../../../../src/components/Spinner/Spinner.tsx"],"sourcesContent":["import React from 'react';\r\nimport cn from 'classnames';\r\nimport './Spinner.css';\r\n\r\nexport type SpinnerProps = React.HTMLAttributes<HTMLDivElement> & {\r\n /**\r\n * Define a delay in milliseconds after which the spinner is shown.\r\n * Default value is `500`ms\r\n */\r\n delay?: number;\r\n /** Define a text that will be displayed below spinner */\r\n label?: string;\r\n};\r\n\r\nexport const Spinner = React.forwardRef(function Spinner(props: SpinnerProps, ref: React.Ref<HTMLDivElement>) {\r\n const { delay = 500, label, ...otherProps } = props;\r\n const [visible, setVisibility] = React.useState(!delay);\r\n\r\n React.useEffect(() => {\r\n let timeout: number;\r\n\r\n if (delay) {\r\n timeout = window.setTimeout(() => setVisibility(true), delay);\r\n }\r\n\r\n return () => {\r\n if (timeout) {\r\n clearTimeout(timeout);\r\n }\r\n };\r\n }, [delay]);\r\n\r\n if (!visible) {\r\n return null;\r\n }\r\n\r\n const className = cn('inline-flex flex-col relative items-center', otherProps.className);\r\n\r\n return (\r\n <div {...otherProps} className={className} data-taco=\"spinner\" ref={ref}>\r\n <svg\r\n className=\"h-10 w-10 animate-[spinnerRotation_2s_linear_infinite]\"\r\n viewBox=\"0 0 100 100\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n >\r\n <circle cx=\"50\" cy=\"50\" r=\"45\"></circle>\r\n </svg>\r\n {label && <span className=\"mt-4\">{label}</span>}\r\n </div>\r\n );\r\n});\r\n"],"names":["Spinner","React","forwardRef","props","ref","delay","label","otherProps","
|
1
|
+
{"version":3,"file":"Spinner.js","sources":["../../../../src/components/Spinner/Spinner.tsx"],"sourcesContent":["import React from 'react';\r\nimport cn from 'classnames';\r\nimport './Spinner.css';\r\n\r\nexport type SpinnerProps = React.HTMLAttributes<HTMLDivElement> & {\r\n /**\r\n * Define a delay in milliseconds after which the spinner is shown.\r\n * Default value is `500`ms\r\n */\r\n delay?: number;\r\n /** Define a text that will be displayed below spinner */\r\n label?: string;\r\n};\r\n\r\nexport const Spinner = React.forwardRef(function Spinner(props: SpinnerProps, ref: React.Ref<HTMLDivElement>) {\r\n const { delay = 500, label, ...otherProps } = props;\r\n const [visible, setVisibility] = React.useState(!delay);\r\n\r\n React.useEffect(() => {\r\n let timeout: number;\r\n\r\n if (delay) {\r\n timeout = window.setTimeout(() => setVisibility(true), delay);\r\n }\r\n\r\n return () => {\r\n if (timeout) {\r\n clearTimeout(timeout);\r\n }\r\n };\r\n }, [delay]);\r\n\r\n if (!visible) {\r\n return null;\r\n }\r\n\r\n const className = cn('inline-flex flex-col relative items-center', otherProps.className);\r\n\r\n return (\r\n <div {...otherProps} className={className} data-taco=\"spinner\" ref={ref}>\r\n <svg\r\n className=\"h-10 w-10 animate-[spinnerRotation_2s_linear_infinite]\"\r\n viewBox=\"0 0 100 100\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n >\r\n <circle cx=\"50\" cy=\"50\" r=\"45\"></circle>\r\n </svg>\r\n {label && <span className=\"mt-4\">{label}</span>}\r\n </div>\r\n );\r\n});\r\n"],"names":["Spinner","React","forwardRef","props","ref","delay","label","otherProps","visible","setVisibility","useState","useEffect","timeout","window","setTimeout","clearTimeout","className","cn","viewBox","xmlns","cx","cy","r"],"mappings":";;;MAcaA,OAAO,gBAAGC,cAAK,CAACC,UAAN,CAAiB,SAASF,OAAT,CAAiBG,KAAjB,EAAsCC,GAAtC;AACpC,QAAM;AAAEC,IAAAA,KAAK,GAAG,GAAV;AAAeC,IAAAA,KAAf;AAAsB,OAAGC;AAAzB,MAAwCJ,KAA9C;AACA,QAAM,CAACK,OAAD,EAAUC,aAAV,IAA2BR,cAAK,CAACS,QAAN,CAAe,CAACL,KAAhB,CAAjC;AAEAJ,EAAAA,cAAK,CAACU,SAAN,CAAgB;AACZ,QAAIC,OAAJ;;AAEA,QAAIP,KAAJ,EAAW;AACPO,MAAAA,OAAO,GAAGC,MAAM,CAACC,UAAP,CAAkB,MAAML,aAAa,CAAC,IAAD,CAArC,EAA6CJ,KAA7C,CAAV;AACH;;AAED,WAAO;AACH,UAAIO,OAAJ,EAAa;AACTG,QAAAA,YAAY,CAACH,OAAD,CAAZ;AACH;AACJ,KAJD;AAKH,GAZD,EAYG,CAACP,KAAD,CAZH;;AAcA,MAAI,CAACG,OAAL,EAAc;AACV,WAAO,IAAP;AACH;;AAED,QAAMQ,SAAS,GAAGC,EAAE,CAAC,4CAAD,EAA+CV,UAAU,CAACS,SAA1D,CAApB;AAEA,SACIf,4BAAA,MAAA,oBAASM;AAAYS,IAAAA,SAAS,EAAEA;iBAAqB;AAAUZ,IAAAA,GAAG,EAAEA;IAApE,EACIH,4BAAA,MAAA;AACIe,IAAAA,SAAS,EAAC;AACVE,IAAAA,OAAO,EAAC;AACRC,IAAAA,KAAK,EAAC;GAHV,EAKIlB,4BAAA,SAAA;AAAQmB,IAAAA,EAAE,EAAC;AAAKC,IAAAA,EAAE,EAAC;AAAKC,IAAAA,CAAC,EAAC;GAA1B,CALJ,CADJ,EAQKhB,KAAK,IAAIL,4BAAA,OAAA;AAAMe,IAAAA,SAAS,EAAC;GAAhB,EAAwBV,KAAxB,CARd,CADJ;AAYH,CApCsB;;;;"}
|
@@ -1,20 +1,19 @@
|
|
1
|
-
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
2
1
|
import { forwardRef, createElement } from 'react';
|
3
2
|
import cn from 'classnames';
|
4
3
|
import { Root, Thumb } from '@radix-ui/react-switch';
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
const Switch = /*#__PURE__*/forwardRef(function Switch(props, ref) {
|
6
|
+
const {
|
7
|
+
label,
|
8
|
+
onChange,
|
9
|
+
...otherProps
|
10
|
+
} = props;
|
11
|
+
const className = cn('group h-6 w-10 flex rounded-full inline-flex', {
|
13
12
|
'mr-2': !!label,
|
14
13
|
'bg-grey-darker aria-checked:bg-blue focus:yt-focus': !props.disabled,
|
15
14
|
'bg-grey-light cursor-not-allowed aria-checked:bg-blue-light': props.disabled
|
16
15
|
}, props.className);
|
17
|
-
|
16
|
+
const element = createElement(Root, Object.assign({}, otherProps, {
|
18
17
|
className: className,
|
19
18
|
onCheckedChange: onChange,
|
20
19
|
ref: ref
|
@@ -23,7 +22,7 @@ var Switch = /*#__PURE__*/forwardRef(function Switch(props, ref) {
|
|
23
22
|
}));
|
24
23
|
|
25
24
|
if (label) {
|
26
|
-
|
25
|
+
const labelClassName = cn('flex items-center cursor-pointer', {
|
27
26
|
'cursor-not-allowed text-grey-dark': props.disabled
|
28
27
|
});
|
29
28
|
return createElement("label", {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Switch.js","sources":["../../../../src/components/Switch/Switch.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport * as PrimitiveSwitch from '@radix-ui/react-switch';\r\n\r\ntype SwitchBaseProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'onChange'> & {\r\n /** Label for the switch */\r\n label?: React.ReactNode;\r\n /* Whether user input is required */\r\n required?: boolean;\r\n};\r\n\r\ninterface UncontrolledSwitchProps extends SwitchBaseProps {\r\n checked?: never;\r\n onChange?: never;\r\n /* The default checked state (uncontrolled) */\r\n defaultChecked?: boolean;\r\n}\r\n\r\ninterface ControlledSwitchProps extends SwitchBaseProps {\r\n defaultChecked?: never;\r\n /* The current checked state (controlled) */\r\n checked: boolean;\r\n /* Handler called when the checked state changes */\r\n onChange: (checked: boolean) => void;\r\n}\r\n\r\nexport type SwitchProps = UncontrolledSwitchProps | ControlledSwitchProps;\r\n\r\nexport const Switch = React.forwardRef(function Switch(props: SwitchProps, ref: React.Ref<HTMLButtonElement>) {\r\n const { label, onChange, ...otherProps } = props;\r\n\r\n const className = cn(\r\n 'group h-6 w-10 flex rounded-full inline-flex',\r\n {\r\n 'mr-2': !!label,\r\n 'bg-grey-darker aria-checked:bg-blue focus:yt-focus': !props.disabled,\r\n 'bg-grey-light cursor-not-allowed aria-checked:bg-blue-light': props.disabled,\r\n },\r\n props.className\r\n );\r\n\r\n const element = (\r\n <PrimitiveSwitch.Root {...otherProps} className={className} onCheckedChange={onChange} ref={ref}>\r\n <PrimitiveSwitch.Thumb className=\"'will-change-transform transition-transform translate-x-1 group-aria-checked:translate-x-5 h-4 w-4 mt-1 bg-white rounded-full\" />\r\n </PrimitiveSwitch.Root>\r\n );\r\n\r\n if (label) {\r\n const labelClassName = cn('flex items-center cursor-pointer', {\r\n 'cursor-not-allowed text-grey-dark': props.disabled,\r\n });\r\n\r\n return (\r\n <label className={labelClassName}>\r\n {element}\r\n {label}\r\n </label>\r\n );\r\n }\r\n\r\n return element;\r\n});\r\n"],"names":["Switch","React","props","ref","label","onChange","otherProps","className","cn","disabled","element","PrimitiveSwitch","onCheckedChange","labelClassName"],"mappings":"
|
1
|
+
{"version":3,"file":"Switch.js","sources":["../../../../src/components/Switch/Switch.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport * as PrimitiveSwitch from '@radix-ui/react-switch';\r\n\r\ntype SwitchBaseProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'onChange'> & {\r\n /** Label for the switch */\r\n label?: React.ReactNode;\r\n /* Whether user input is required */\r\n required?: boolean;\r\n};\r\n\r\ninterface UncontrolledSwitchProps extends SwitchBaseProps {\r\n checked?: never;\r\n onChange?: never;\r\n /* The default checked state (uncontrolled) */\r\n defaultChecked?: boolean;\r\n}\r\n\r\ninterface ControlledSwitchProps extends SwitchBaseProps {\r\n defaultChecked?: never;\r\n /* The current checked state (controlled) */\r\n checked: boolean;\r\n /* Handler called when the checked state changes */\r\n onChange: (checked: boolean) => void;\r\n}\r\n\r\nexport type SwitchProps = UncontrolledSwitchProps | ControlledSwitchProps;\r\n\r\nexport const Switch = React.forwardRef(function Switch(props: SwitchProps, ref: React.Ref<HTMLButtonElement>) {\r\n const { label, onChange, ...otherProps } = props;\r\n\r\n const className = cn(\r\n 'group h-6 w-10 flex rounded-full inline-flex',\r\n {\r\n 'mr-2': !!label,\r\n 'bg-grey-darker aria-checked:bg-blue focus:yt-focus': !props.disabled,\r\n 'bg-grey-light cursor-not-allowed aria-checked:bg-blue-light': props.disabled,\r\n },\r\n props.className\r\n );\r\n\r\n const element = (\r\n <PrimitiveSwitch.Root {...otherProps} className={className} onCheckedChange={onChange} ref={ref}>\r\n <PrimitiveSwitch.Thumb className=\"'will-change-transform transition-transform translate-x-1 group-aria-checked:translate-x-5 h-4 w-4 mt-1 bg-white rounded-full\" />\r\n </PrimitiveSwitch.Root>\r\n );\r\n\r\n if (label) {\r\n const labelClassName = cn('flex items-center cursor-pointer', {\r\n 'cursor-not-allowed text-grey-dark': props.disabled,\r\n });\r\n\r\n return (\r\n <label className={labelClassName}>\r\n {element}\r\n {label}\r\n </label>\r\n );\r\n }\r\n\r\n return element;\r\n});\r\n"],"names":["Switch","React","props","ref","label","onChange","otherProps","className","cn","disabled","element","PrimitiveSwitch","onCheckedChange","labelClassName"],"mappings":";;;;MA4BaA,MAAM,gBAAGC,UAAA,CAAiB,SAASD,MAAT,CAAgBE,KAAhB,EAAoCC,GAApC;AACnC,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA,QAAT;AAAmB,OAAGC;AAAtB,MAAqCJ,KAA3C;AAEA,QAAMK,SAAS,GAAGC,EAAE,CAChB,8CADgB,EAEhB;AACI,YAAQ,CAAC,CAACJ,KADd;AAEI,0DAAsD,CAACF,KAAK,CAACO,QAFjE;AAGI,mEAA+DP,KAAK,CAACO;AAHzE,GAFgB,EAOhBP,KAAK,CAACK,SAPU,CAApB;AAUA,QAAMG,OAAO,GACTT,aAAA,CAACU,IAAD,oBAA0BL;AAAYC,IAAAA,SAAS,EAAEA;AAAWK,IAAAA,eAAe,EAAEP;AAAUF,IAAAA,GAAG,EAAEA;IAA5F,EACIF,aAAA,CAACU,KAAD;AAAuBJ,IAAAA,SAAS,EAAC;GAAjC,CADJ,CADJ;;AAMA,MAAIH,KAAJ,EAAW;AACP,UAAMS,cAAc,GAAGL,EAAE,CAAC,kCAAD,EAAqC;AAC1D,2CAAqCN,KAAK,CAACO;AADe,KAArC,CAAzB;AAIA,WACIR,aAAA,QAAA;AAAOM,MAAAA,SAAS,EAAEM;KAAlB,EACKH,OADL,EAEKN,KAFL,CADJ;AAMH;;AAED,SAAOM,OAAP;AACH,CAjCqB;;;;"}
|
@@ -1,21 +1,17 @@
|
|
1
|
-
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
2
1
|
import { forwardRef, createElement } from 'react';
|
3
2
|
import cn from 'classnames';
|
4
3
|
import { Root, List, Trigger, Content } from '@radix-ui/react-tabs';
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
17
|
-
|
18
|
-
var className = cn('yt-tabs', "yt-tabs--" + orientation, {
|
5
|
+
const Tabs = /*#__PURE__*/forwardRef(function Tabs(props, ref) {
|
6
|
+
const {
|
7
|
+
id,
|
8
|
+
defaultId,
|
9
|
+
children,
|
10
|
+
onChange,
|
11
|
+
orientation = 'horizontal',
|
12
|
+
...otherProps
|
13
|
+
} = props;
|
14
|
+
const className = cn('yt-tabs', `yt-tabs--${orientation}`, {
|
19
15
|
'flex w-full': orientation === 'vertical'
|
20
16
|
}, props.className);
|
21
17
|
return createElement(Root, Object.assign({}, otherProps, {
|
@@ -29,19 +25,20 @@ var Tabs = /*#__PURE__*/forwardRef(function Tabs(props, ref) {
|
|
29
25
|
value: id
|
30
26
|
}), children);
|
31
27
|
});
|
32
|
-
|
33
|
-
|
28
|
+
const TabList = /*#__PURE__*/forwardRef(function Tab(props, ref) {
|
29
|
+
const className = cn('yt-tab__list border-b border-grey-light flex flex-row m-0 mb-4', props.className);
|
34
30
|
return createElement(List, Object.assign({}, props, {
|
35
31
|
className: className,
|
36
32
|
ref: ref
|
37
33
|
}));
|
38
34
|
});
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
35
|
+
const TabTrigger = /*#__PURE__*/forwardRef(function Tab(props, ref) {
|
36
|
+
const {
|
37
|
+
id,
|
38
|
+
disabled,
|
39
|
+
...otherProps
|
40
|
+
} = props;
|
41
|
+
const className = cn('yt-tab bg-transparent border-b-2 border-transparent text-grey-darkest m-0 py-2 px-4', disabled ? 'cursor-not-allowed !text-grey' : 'cursor-pointer rounded-t hover:border-grey-light hover:text-black active:yt-focus active:border-blue focus:yt-focus focus:border-blue', props.className);
|
45
42
|
return createElement(Trigger, Object.assign({}, otherProps, {
|
46
43
|
className: className,
|
47
44
|
disabled: disabled,
|
@@ -52,11 +49,12 @@ var TabTrigger = /*#__PURE__*/forwardRef(function Tab(props, ref) {
|
|
52
49
|
value: id
|
53
50
|
}));
|
54
51
|
});
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
const TabContent = /*#__PURE__*/forwardRef(function Tab(props, ref) {
|
53
|
+
const {
|
54
|
+
id,
|
55
|
+
...otherProps
|
56
|
+
} = props;
|
57
|
+
const className = cn('yt-tab__panel outline-none', props.className);
|
60
58
|
return createElement(Content, Object.assign({}, otherProps, {
|
61
59
|
className: className,
|
62
60
|
ref: ref,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Tabs.js","sources":["../../../../src/components/Tabs/Tabs.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport * as TabsPrimitive from '@radix-ui/react-tabs';\r\n\r\nimport { Orientation } from '../../types';\r\nimport './Tabs.css';\r\n\r\nexport type TabsProps = React.HTMLAttributes<HTMLDivElement> & {\r\n /**\r\n * The controlled value of the tab to activate. Should be used in conjunction with `onChange`.\r\n */\r\n id?: string;\r\n /**\r\n * Set which tab is selected on mount.\r\n * This has to be one of the existing ids provided for tabs\r\n */\r\n defaultId?: string;\r\n /**\r\n * Content should be one or an array of `Tabs.Trigger` components inside `Tabs.List` and then\r\n * followed by one or an array of `Tabs.Content`.\r\n * *Note* that there can also be tabs that are rendered conditionally.\r\n */\r\n children: React.ReactNode;\r\n /**\r\n * Define orientation of tabs.\r\n * @defaultValue horizontal\r\n */\r\n orientation?: Orientation;\r\n /**\r\n * Callback that is called when tab is changed.\r\n */\r\n onChange?: (id: string) => void;\r\n};\r\n\r\nexport type TabListProps = React.HTMLAttributes<HTMLDivElement>;\r\n\r\nexport type TabTriggerProps = React.HTMLAttributes<HTMLButtonElement> & {\r\n /**\r\n * A unique value that associates the trigger with a content.\r\n */\r\n id: string;\r\n /**\r\n * When true, prevents the user from interacting with the tab.\r\n */\r\n disabled?: boolean;\r\n};\r\n\r\nexport type TabContentProps = React.HTMLAttributes<HTMLDivElement> & {\r\n /**\r\n * A unique value that associates the content with a trigger.\r\n */\r\n id: string;\r\n};\r\n\r\nexport type ForwardedTabsWithStatics = React.ForwardRefExoticComponent<TabsProps & React.RefAttributes<HTMLDivElement>> & {\r\n /** Tab list component containing all tab triggers, rendered in a `Tabs` group component */\r\n List: React.ForwardRefExoticComponent<TabListProps & React.RefAttributes<HTMLDivElement>>;\r\n /** Tab trigger component rendered in a `Tabs.List` component */\r\n Trigger: React.ForwardRefExoticComponent<TabTriggerProps & React.RefAttributes<HTMLButtonElement>>;\r\n /** Tab content component rendered in a `Tabs` group component */\r\n Content: React.ForwardRefExoticComponent<TabContentProps & React.RefAttributes<HTMLDivElement>>;\r\n};\r\n\r\nexport const Tabs = React.forwardRef(function Tabs(props: TabsProps, ref: React.Ref<HTMLDivElement>) {\r\n const { id, defaultId, children, onChange, orientation = 'horizontal', ...otherProps } = props;\r\n const className = cn(\r\n 'yt-tabs',\r\n `yt-tabs--${orientation}`,\r\n {\r\n 'flex w-full': orientation === 'vertical',\r\n },\r\n props.className\r\n );\r\n\r\n return (\r\n <TabsPrimitive.Root\r\n {...otherProps}\r\n className={className}\r\n data-taco=\"tabs\"\r\n defaultValue={defaultId}\r\n dir=\"ltr\"\r\n onValueChange={onChange}\r\n orientation={orientation}\r\n ref={ref}\r\n value={id}\r\n >\r\n {children}\r\n </TabsPrimitive.Root>\r\n );\r\n}) as ForwardedTabsWithStatics;\r\n\r\nconst TabList = React.forwardRef(function Tab(props: TabListProps, ref: React.Ref<HTMLDivElement>) {\r\n const className = cn('yt-tab__list border-b border-grey-light flex flex-row m-0 mb-4', props.className);\r\n\r\n return <TabsPrimitive.List {...props} className={className} ref={ref} />;\r\n});\r\n\r\nconst TabTrigger = React.forwardRef(function Tab(props: TabTriggerProps, ref: React.Ref<HTMLButtonElement>) {\r\n const { id, disabled, ...otherProps } = props;\r\n const className = cn(\r\n 'yt-tab bg-transparent border-b-2 border-transparent text-grey-darkest m-0 py-2 px-4',\r\n disabled\r\n ? 'cursor-not-allowed !text-grey'\r\n : 'cursor-pointer rounded-t hover:border-grey-light hover:text-black active:yt-focus active:border-blue focus:yt-focus focus:border-blue',\r\n props.className\r\n );\r\n\r\n return (\r\n <TabsPrimitive.Trigger\r\n {...otherProps}\r\n className={className}\r\n disabled={disabled}\r\n ref={ref}\r\n style={{\r\n transition: 'border 0.2s ease-in',\r\n }}\r\n value={id}\r\n />\r\n );\r\n});\r\n\r\nconst TabContent = React.forwardRef(function Tab(props: TabContentProps, ref: React.Ref<HTMLDivElement>) {\r\n const { id, ...otherProps } = props;\r\n const className = cn('yt-tab__panel outline-none', props.className);\r\n\r\n return <TabsPrimitive.Content {...otherProps} className={className} ref={ref} value={id} />;\r\n});\r\n\r\nTabs.List = TabList;\r\nTabs.Trigger = TabTrigger;\r\nTabs.Content = TabContent;\r\n"],"names":["Tabs","React","props","ref","id","defaultId","children","onChange","orientation","otherProps","className","cn","TabsPrimitive","defaultValue","dir","onValueChange","value","TabList","Tab","TabTrigger","disabled","style","transition","TabContent","List","Trigger","Content"],"mappings":"
|
1
|
+
{"version":3,"file":"Tabs.js","sources":["../../../../src/components/Tabs/Tabs.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport * as TabsPrimitive from '@radix-ui/react-tabs';\r\n\r\nimport { Orientation } from '../../types';\r\nimport './Tabs.css';\r\n\r\nexport type TabsProps = React.HTMLAttributes<HTMLDivElement> & {\r\n /**\r\n * The controlled value of the tab to activate. Should be used in conjunction with `onChange`.\r\n */\r\n id?: string;\r\n /**\r\n * Set which tab is selected on mount.\r\n * This has to be one of the existing ids provided for tabs\r\n */\r\n defaultId?: string;\r\n /**\r\n * Content should be one or an array of `Tabs.Trigger` components inside `Tabs.List` and then\r\n * followed by one or an array of `Tabs.Content`.\r\n * *Note* that there can also be tabs that are rendered conditionally.\r\n */\r\n children: React.ReactNode;\r\n /**\r\n * Define orientation of tabs.\r\n * @defaultValue horizontal\r\n */\r\n orientation?: Orientation;\r\n /**\r\n * Callback that is called when tab is changed.\r\n */\r\n onChange?: (id: string) => void;\r\n};\r\n\r\nexport type TabListProps = React.HTMLAttributes<HTMLDivElement>;\r\n\r\nexport type TabTriggerProps = React.HTMLAttributes<HTMLButtonElement> & {\r\n /**\r\n * A unique value that associates the trigger with a content.\r\n */\r\n id: string;\r\n /**\r\n * When true, prevents the user from interacting with the tab.\r\n */\r\n disabled?: boolean;\r\n};\r\n\r\nexport type TabContentProps = React.HTMLAttributes<HTMLDivElement> & {\r\n /**\r\n * A unique value that associates the content with a trigger.\r\n */\r\n id: string;\r\n};\r\n\r\nexport type ForwardedTabsWithStatics = React.ForwardRefExoticComponent<TabsProps & React.RefAttributes<HTMLDivElement>> & {\r\n /** Tab list component containing all tab triggers, rendered in a `Tabs` group component */\r\n List: React.ForwardRefExoticComponent<TabListProps & React.RefAttributes<HTMLDivElement>>;\r\n /** Tab trigger component rendered in a `Tabs.List` component */\r\n Trigger: React.ForwardRefExoticComponent<TabTriggerProps & React.RefAttributes<HTMLButtonElement>>;\r\n /** Tab content component rendered in a `Tabs` group component */\r\n Content: React.ForwardRefExoticComponent<TabContentProps & React.RefAttributes<HTMLDivElement>>;\r\n};\r\n\r\nexport const Tabs = React.forwardRef(function Tabs(props: TabsProps, ref: React.Ref<HTMLDivElement>) {\r\n const { id, defaultId, children, onChange, orientation = 'horizontal', ...otherProps } = props;\r\n const className = cn(\r\n 'yt-tabs',\r\n `yt-tabs--${orientation}`,\r\n {\r\n 'flex w-full': orientation === 'vertical',\r\n },\r\n props.className\r\n );\r\n\r\n return (\r\n <TabsPrimitive.Root\r\n {...otherProps}\r\n className={className}\r\n data-taco=\"tabs\"\r\n defaultValue={defaultId}\r\n dir=\"ltr\"\r\n onValueChange={onChange}\r\n orientation={orientation}\r\n ref={ref}\r\n value={id}\r\n >\r\n {children}\r\n </TabsPrimitive.Root>\r\n );\r\n}) as ForwardedTabsWithStatics;\r\n\r\nconst TabList = React.forwardRef(function Tab(props: TabListProps, ref: React.Ref<HTMLDivElement>) {\r\n const className = cn('yt-tab__list border-b border-grey-light flex flex-row m-0 mb-4', props.className);\r\n\r\n return <TabsPrimitive.List {...props} className={className} ref={ref} />;\r\n});\r\n\r\nconst TabTrigger = React.forwardRef(function Tab(props: TabTriggerProps, ref: React.Ref<HTMLButtonElement>) {\r\n const { id, disabled, ...otherProps } = props;\r\n const className = cn(\r\n 'yt-tab bg-transparent border-b-2 border-transparent text-grey-darkest m-0 py-2 px-4',\r\n disabled\r\n ? 'cursor-not-allowed !text-grey'\r\n : 'cursor-pointer rounded-t hover:border-grey-light hover:text-black active:yt-focus active:border-blue focus:yt-focus focus:border-blue',\r\n props.className\r\n );\r\n\r\n return (\r\n <TabsPrimitive.Trigger\r\n {...otherProps}\r\n className={className}\r\n disabled={disabled}\r\n ref={ref}\r\n style={{\r\n transition: 'border 0.2s ease-in',\r\n }}\r\n value={id}\r\n />\r\n );\r\n});\r\n\r\nconst TabContent = React.forwardRef(function Tab(props: TabContentProps, ref: React.Ref<HTMLDivElement>) {\r\n const { id, ...otherProps } = props;\r\n const className = cn('yt-tab__panel outline-none', props.className);\r\n\r\n return <TabsPrimitive.Content {...otherProps} className={className} ref={ref} value={id} />;\r\n});\r\n\r\nTabs.List = TabList;\r\nTabs.Trigger = TabTrigger;\r\nTabs.Content = TabContent;\r\n"],"names":["Tabs","React","props","ref","id","defaultId","children","onChange","orientation","otherProps","className","cn","TabsPrimitive","defaultValue","dir","onValueChange","value","TabList","Tab","TabTrigger","disabled","style","transition","TabContent","List","Trigger","Content"],"mappings":";;;;MA+DaA,IAAI,gBAAGC,UAAA,CAAiB,SAASD,IAAT,CAAcE,KAAd,EAAgCC,GAAhC;AACjC,QAAM;AAAEC,IAAAA,EAAF;AAAMC,IAAAA,SAAN;AAAiBC,IAAAA,QAAjB;AAA2BC,IAAAA,QAA3B;AAAqCC,IAAAA,WAAW,GAAG,YAAnD;AAAiE,OAAGC;AAApE,MAAmFP,KAAzF;AACA,QAAMQ,SAAS,GAAGC,EAAE,CAChB,SADgB,cAEJH,aAFI,EAGhB;AACI,mBAAeA,WAAW,KAAK;AADnC,GAHgB,EAMhBN,KAAK,CAACQ,SANU,CAApB;AASA,SACIT,aAAA,CAACW,IAAD,oBACQH;AACJC,IAAAA,SAAS,EAAEA;iBACD;AACVG,IAAAA,YAAY,EAAER;AACdS,IAAAA,GAAG,EAAC;AACJC,IAAAA,aAAa,EAAER;AACfC,IAAAA,WAAW,EAAEA;AACbL,IAAAA,GAAG,EAAEA;AACLa,IAAAA,KAAK,EAAEZ;IATX,EAWKE,QAXL,CADJ;AAeH,CA1BmB;AA4BpB,MAAMW,OAAO,gBAAGhB,UAAA,CAAiB,SAASiB,GAAT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eN,UAAf;AACAnB,IAAI,CAAC0B,OAAL,GAAeH,UAAf;;;;"}
|
@@ -1,21 +1,23 @@
|
|
1
|
-
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
2
1
|
import { forwardRef, createElement } from 'react';
|
3
2
|
import cn from 'classnames';
|
4
3
|
import { getInputClasses } from '../Input/util.js';
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
const Textarea = /*#__PURE__*/forwardRef(function Textarea(props, ref) {
|
6
|
+
const {
|
7
|
+
defaultValue: _,
|
8
|
+
highlighted,
|
9
|
+
invalid,
|
10
|
+
onKeyDown,
|
11
|
+
...otherProps
|
12
|
+
} = props;
|
13
|
+
const classNames = cn(getInputClasses(props), 'py-1 min-h-[75px] disabled:resize-none', props.className); // home and end keys only navigate to the start/end of textarea value if the textarea container does not scroll
|
12
14
|
// if it has scroll height then the browser reverts to native scrolling behaviour only
|
13
15
|
// so we manually override it to ensure _our_ desired behaviour remains intact
|
14
16
|
|
15
|
-
|
17
|
+
const handleKeyDown = event => {
|
16
18
|
if (event.key === 'Home' || event.key === 'End') {
|
17
19
|
event.preventDefault();
|
18
|
-
|
20
|
+
const position = event.key === 'End' ? event.currentTarget.value.length : 0;
|
19
21
|
event.currentTarget.setSelectionRange(position, position);
|
20
22
|
event.currentTarget.scrollTop = event.key === 'End' ? event.currentTarget.scrollHeight : 0;
|
21
23
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Textarea.js","sources":["../../../../src/components/Textarea/Textarea.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport { getInputClasses } from '../Input/util';\r\n\r\nexport type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement> & {\r\n /** Draws attention to the textarea 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 /** Value of the textarea */\r\n value?: string;\r\n};\r\n\r\nexport const Textarea = React.forwardRef(function Textarea(props: TextareaProps, ref: React.Ref<HTMLTextAreaElement>) {\r\n const { defaultValue: _, highlighted, invalid, onKeyDown, ...otherProps } = props;\r\n const classNames = cn(getInputClasses(props), 'py-1 min-h-[75px] disabled:resize-none', props.className);\r\n\r\n // home and end keys only navigate to the start/end of textarea value if the textarea 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<HTMLTextAreaElement>) => {\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 event.currentTarget.scrollTop = event.key === 'End' ? event.currentTarget.scrollHeight : 0;\r\n }\r\n\r\n if (onKeyDown) {\r\n onKeyDown(event);\r\n }\r\n };\r\n\r\n return <textarea {...otherProps} className={classNames} data-taco=\"textarea\" onKeyDown={handleKeyDown} ref={ref} />;\r\n});\r\n"],"names":["Textarea","React","props","ref","onKeyDown","otherProps","classNames","cn","getInputClasses","className","handleKeyDown","event","key","preventDefault","position","currentTarget","value","length","setSelectionRange","scrollTop","scrollHeight"],"mappings":"
|
1
|
+
{"version":3,"file":"Textarea.js","sources":["../../../../src/components/Textarea/Textarea.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport cn from 'classnames';\r\nimport { getInputClasses } from '../Input/util';\r\n\r\nexport type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement> & {\r\n /** Draws attention to the textarea 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 /** Value of the textarea */\r\n value?: string;\r\n};\r\n\r\nexport const Textarea = React.forwardRef(function Textarea(props: TextareaProps, ref: React.Ref<HTMLTextAreaElement>) {\r\n const { defaultValue: _, highlighted, invalid, onKeyDown, ...otherProps } = props;\r\n const classNames = cn(getInputClasses(props), 'py-1 min-h-[75px] disabled:resize-none', props.className);\r\n\r\n // home and end keys only navigate to the start/end of textarea value if the textarea 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<HTMLTextAreaElement>) => {\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 event.currentTarget.scrollTop = event.key === 'End' ? event.currentTarget.scrollHeight : 0;\r\n }\r\n\r\n if (onKeyDown) {\r\n onKeyDown(event);\r\n }\r\n };\r\n\r\n return <textarea {...otherProps} className={classNames} data-taco=\"textarea\" onKeyDown={handleKeyDown} ref={ref} />;\r\n});\r\n"],"names":["Textarea","React","props","ref","defaultValue","_","highlighted","invalid","onKeyDown","otherProps","classNames","cn","getInputClasses","className","handleKeyDown","event","key","preventDefault","position","currentTarget","value","length","setSelectionRange","scrollTop","scrollHeight"],"mappings":";;;;MAaaA,QAAQ,gBAAGC,UAAA,CAAiB,SAASD,QAAT,CAAkBE,KAAlB,EAAwCC,GAAxC;AACrC,QAAM;AAAEC,IAAAA,YAAY,EAAEC,CAAhB;AAAmBC,IAAAA,WAAnB;AAAgCC,IAAAA,OAAhC;AAAyCC,IAAAA,SAAzC;AAAoD,OAAGC;AAAvD,MAAsEP,KAA5E;AACA,QAAMQ,UAAU,GAAGC,EAAE,CAACC,eAAe,CAACV,KAAD,CAAhB,EAAyB,wCAAzB,EAAmEA,KAAK,CAACW,SAAzE,CAArB;AAGA;AACA;;AACA,QAAMC,aAAa,GAAIC,KAAD;AAClB,QAAIA,KAAK,CAACC,GAAN,KAAc,MAAd,IAAwBD,KAAK,CAACC,GAAN,KAAc,KAA1C,EAAiD;AAC7CD,MAAAA,KAAK,CAACE,cAAN;AACA,YAAMC,QAAQ,GAAGH,KAAK,CAACC,GAAN,KAAc,KAAd,GAAsBD,KAAK,CAACI,aAAN,CAAoBC,KAApB,CAA0BC,MAAhD,GAAyD,CAA1E;AACAN,MAAAA,KAAK,CAACI,aAAN,CAAoBG,iBAApB,CAAsCJ,QAAtC,EAAgDA,QAAhD;AACAH,MAAAA,KAAK,CAACI,aAAN,CAAoBI,SAApB,GAAgCR,KAAK,CAACC,GAAN,KAAc,KAAd,GAAsBD,KAAK,CAACI,aAAN,CAAoBK,YAA1C,GAAyD,CAAzF;AACH;;AAED,QAAIhB,SAAJ,EAAe;AACXA,MAAAA,SAAS,CAACO,KAAD,CAAT;AACH;AACJ,GAXD;;AAaA,SAAOd,aAAA,WAAA,oBAAcQ;AAAYI,IAAAA,SAAS,EAAEH;iBAAsB;AAAWF,IAAAA,SAAS,EAAEM;AAAeX,IAAAA,GAAG,EAAEA;IAArG,CAAP;AACH,CArBuB;;;;"}
|
@@ -1,65 +1,51 @@
|
|
1
|
-
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
2
1
|
import { useState, useCallback, useEffect, createElement, useContext, createContext } from 'react';
|
3
2
|
import { v4 } from 'uuid';
|
4
3
|
import { AnimatePresence, motion } from 'framer-motion';
|
5
4
|
import { Toast } from './Toast.js';
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
var ToastContext = /*#__PURE__*/createContext({});
|
6
|
+
const DEFAULT_AUTO_CLOSE_TIMEOUT = 7500;
|
7
|
+
const ToastContext = /*#__PURE__*/createContext({});
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
return JSON.stringify(toast.content) === JSON.stringify(content);
|
15
|
-
});
|
9
|
+
const insertToastWithoutDuplicates = (currentToasts, id, content, options, close) => {
|
10
|
+
const nextToasts = [...currentToasts];
|
11
|
+
const existingToastIndex = currentToasts.findIndex(toast => JSON.stringify(toast.content) === JSON.stringify(content));
|
16
12
|
|
17
13
|
if (existingToastIndex > -1) {
|
18
14
|
nextToasts[existingToastIndex].lastDuplicateId = id;
|
19
15
|
nextToasts[existingToastIndex].lastUpdated = Date.now();
|
20
16
|
} else {
|
21
17
|
nextToasts.push({
|
22
|
-
id
|
18
|
+
id,
|
23
19
|
content: typeof content === 'function' ? content(close) : content,
|
24
|
-
options
|
20
|
+
options
|
25
21
|
});
|
26
22
|
}
|
27
23
|
|
28
24
|
return nextToasts;
|
29
25
|
};
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
const ToastProvider = ({
|
28
|
+
children,
|
29
|
+
...props
|
30
|
+
}) => {
|
31
|
+
const [toasts, setToasts] = useState([]);
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
setToasts = _React$useState[1];
|
38
|
-
|
39
|
-
var handleClose = function handleClose(id) {
|
40
|
-
setToasts(function (currentToasts) {
|
41
|
-
return currentToasts.filter(function (toast) {
|
42
|
-
return toast.id !== id;
|
43
|
-
});
|
44
|
-
});
|
33
|
+
const handleClose = id => {
|
34
|
+
setToasts(currentToasts => currentToasts.filter(toast => toast.id !== id));
|
45
35
|
}; // memoize (useCallback) this function,
|
46
36
|
// it is the value of the context provider and we don't want it to trigger state tree re-renders on provider children
|
47
37
|
|
48
38
|
|
49
|
-
|
50
|
-
|
39
|
+
const toaster = useCallback((content, options) => {
|
40
|
+
const id = v4();
|
51
41
|
|
52
|
-
|
53
|
-
return handleClose(id);
|
54
|
-
};
|
42
|
+
const close = () => handleClose(id);
|
55
43
|
|
56
|
-
setToasts(
|
57
|
-
return insertToastWithoutDuplicates(currentToasts, id, content, options, close);
|
58
|
-
});
|
44
|
+
setToasts(currentToasts => insertToastWithoutDuplicates(currentToasts, id, content, options, close));
|
59
45
|
|
60
|
-
|
61
|
-
setToasts(
|
62
|
-
|
46
|
+
const update = (content, options) => {
|
47
|
+
setToasts(currentToasts => {
|
48
|
+
const nextToasts = currentToasts.filter(toast => {
|
63
49
|
if (toast.lastDuplicateId) {
|
64
50
|
return toast.lastDuplicateId !== id;
|
65
51
|
}
|
@@ -70,80 +56,70 @@ var ToastProvider = function ToastProvider(_ref) {
|
|
70
56
|
});
|
71
57
|
};
|
72
58
|
|
73
|
-
|
74
|
-
update(content,
|
75
|
-
autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT
|
76
|
-
|
59
|
+
const success = (content, options) => {
|
60
|
+
update(content, {
|
61
|
+
autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT,
|
62
|
+
...options,
|
77
63
|
type: 'success'
|
78
|
-
})
|
64
|
+
});
|
79
65
|
};
|
80
66
|
|
81
|
-
|
82
|
-
update(content,
|
67
|
+
const error = (content, options) => {
|
68
|
+
update(content, { ...options,
|
83
69
|
type: 'error'
|
84
|
-
})
|
70
|
+
});
|
85
71
|
};
|
86
72
|
|
87
|
-
|
88
|
-
update(content,
|
73
|
+
const warning = (content, options) => {
|
74
|
+
update(content, { ...options,
|
89
75
|
type: 'warning'
|
90
|
-
})
|
76
|
+
});
|
91
77
|
};
|
92
78
|
|
93
|
-
|
94
|
-
update(content,
|
79
|
+
const information = (content, options) => {
|
80
|
+
update(content, { ...options,
|
95
81
|
type: 'information'
|
96
|
-
})
|
82
|
+
});
|
97
83
|
};
|
98
84
|
|
99
|
-
|
100
|
-
update(content,
|
85
|
+
const loading = (content, options) => {
|
86
|
+
update(content, { ...options,
|
101
87
|
type: 'loading'
|
102
|
-
})
|
88
|
+
});
|
103
89
|
};
|
104
90
|
|
105
91
|
return {
|
106
|
-
success
|
107
|
-
error
|
108
|
-
warning
|
109
|
-
information
|
110
|
-
loading
|
111
|
-
close
|
92
|
+
success,
|
93
|
+
error,
|
94
|
+
warning,
|
95
|
+
information,
|
96
|
+
loading,
|
97
|
+
close
|
112
98
|
};
|
113
99
|
}, []); // no need to rebind these every render, do them once in an effect
|
114
100
|
|
115
|
-
useEffect(
|
116
|
-
toaster.success =
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
}));
|
122
|
-
};
|
101
|
+
useEffect(() => {
|
102
|
+
toaster.success = (content, options) => toaster(content, {
|
103
|
+
autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT,
|
104
|
+
...options,
|
105
|
+
type: 'success'
|
106
|
+
});
|
123
107
|
|
124
|
-
toaster.error =
|
125
|
-
|
126
|
-
|
127
|
-
}));
|
128
|
-
};
|
108
|
+
toaster.error = (content, options) => toaster(content, { ...options,
|
109
|
+
type: 'error'
|
110
|
+
});
|
129
111
|
|
130
|
-
toaster.warning =
|
131
|
-
|
132
|
-
|
133
|
-
}));
|
134
|
-
};
|
112
|
+
toaster.warning = (content, options) => toaster(content, { ...options,
|
113
|
+
type: 'warning'
|
114
|
+
});
|
135
115
|
|
136
|
-
toaster.information =
|
137
|
-
|
138
|
-
|
139
|
-
}));
|
140
|
-
};
|
116
|
+
toaster.information = (content, options) => toaster(content, { ...options,
|
117
|
+
type: 'information'
|
118
|
+
});
|
141
119
|
|
142
|
-
toaster.loading =
|
143
|
-
|
144
|
-
|
145
|
-
}));
|
146
|
-
};
|
120
|
+
toaster.loading = (content, options) => toaster(content, { ...options,
|
121
|
+
type: 'loading'
|
122
|
+
});
|
147
123
|
}, []);
|
148
124
|
return createElement(ToastContext.Provider, Object.assign({}, props, {
|
149
125
|
value: toaster
|
@@ -153,41 +129,35 @@ var ToastProvider = function ToastProvider(_ref) {
|
|
153
129
|
role: "log"
|
154
130
|
}, createElement(AnimatePresence, {
|
155
131
|
initial: false
|
156
|
-
}, toasts.map(
|
157
|
-
|
158
|
-
|
132
|
+
}, toasts.map(toast => createElement(motion.div, {
|
133
|
+
key: toast.id,
|
134
|
+
transition: {
|
135
|
+
type: 'spring',
|
136
|
+
damping: 20,
|
137
|
+
stiffness: 300
|
138
|
+
},
|
139
|
+
initial: {
|
140
|
+
opacity: 0,
|
141
|
+
y: 10,
|
142
|
+
scale: 0.5
|
143
|
+
},
|
144
|
+
animate: {
|
145
|
+
opacity: 1,
|
146
|
+
y: 0,
|
147
|
+
scale: 1
|
148
|
+
},
|
149
|
+
exit: {
|
150
|
+
opacity: 0,
|
151
|
+
scale: 0.5,
|
159
152
|
transition: {
|
160
|
-
|
161
|
-
damping: 20,
|
162
|
-
stiffness: 300
|
163
|
-
},
|
164
|
-
initial: {
|
165
|
-
opacity: 0,
|
166
|
-
y: 10,
|
167
|
-
scale: 0.5
|
168
|
-
},
|
169
|
-
animate: {
|
170
|
-
opacity: 1,
|
171
|
-
y: 0,
|
172
|
-
scale: 1
|
173
|
-
},
|
174
|
-
exit: {
|
175
|
-
opacity: 0,
|
176
|
-
scale: 0.5,
|
177
|
-
transition: {
|
178
|
-
duration: 0.2
|
179
|
-
}
|
180
|
-
}
|
181
|
-
}, createElement(Toast, Object.assign({}, toast, {
|
182
|
-
onClose: function onClose() {
|
183
|
-
return handleClose(toast.id);
|
153
|
+
duration: 0.2
|
184
154
|
}
|
185
|
-
}
|
186
|
-
}
|
187
|
-
|
188
|
-
|
189
|
-
return useContext(ToastContext);
|
155
|
+
}
|
156
|
+
}, createElement(Toast, Object.assign({}, toast, {
|
157
|
+
onClose: () => handleClose(toast.id)
|
158
|
+
})))))));
|
190
159
|
};
|
160
|
+
const useToast = () => useContext(ToastContext);
|
191
161
|
|
192
162
|
export { ToastProvider, useToast };
|
193
163
|
//# sourceMappingURL=Toaster.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Toaster.js","sources":["../../../../src/components/Toast/Toaster.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport { v4 as uuid } from 'uuid';\r\nimport { AnimatePresence, motion } from 'framer-motion';\r\nimport { ToastOptions, Toast, ToastProps } from './Toast';\r\nimport './Toast.css';\r\n\r\nconst DEFAULT_AUTO_CLOSE_TIMEOUT = 7500;\r\n\r\ntype ToastCreator<T> = (content: React.ReactNode | ((close: () => void) => React.ReactNode), options?: ToastOptions) => T;\r\n\r\nexport interface Toaster<T> extends ToastCreator<T> {\r\n success: ToastCreator<T>;\r\n error: ToastCreator<T>;\r\n warning: ToastCreator<T>;\r\n information: ToastCreator<T>;\r\n loading: ToastCreator<T>;\r\n}\r\n\r\nexport interface ToastReference {\r\n /** Show a success toast */\r\n success: ToastCreator<void>;\r\n /** Show an error toast */\r\n error: ToastCreator<void>;\r\n /** Show a warning toast */\r\n warning: ToastCreator<void>;\r\n /** Show an information toast */\r\n information: ToastCreator<void>;\r\n /** Show a loading toast */\r\n loading: ToastCreator<void>;\r\n /**\r\n * Close an existing toast.\r\n * The toast function returns a reference to the active toast,\r\n * allowing you to programmatically close it when needed\r\n */\r\n close: () => void;\r\n}\r\n\r\nconst ToastContext = React.createContext<Toaster<ToastReference>>({} as Toaster<ToastReference>);\r\n\r\nexport interface ToastProviderProps {\r\n children: React.ReactNode;\r\n}\r\n\r\ntype InternalToast = Omit<ToastProps, 'onClose'>;\r\n\r\nconst insertToastWithoutDuplicates = (\r\n currentToasts: InternalToast[],\r\n id: string,\r\n content: React.ReactNode,\r\n options: ToastOptions,\r\n close: () => void\r\n): InternalToast[] => {\r\n const nextToasts = [...currentToasts];\r\n const existingToastIndex = currentToasts.findIndex(toast => JSON.stringify(toast.content) === JSON.stringify(content));\r\n\r\n if (existingToastIndex > -1) {\r\n nextToasts[existingToastIndex].lastDuplicateId = id;\r\n nextToasts[existingToastIndex].lastUpdated = Date.now();\r\n } else {\r\n nextToasts.push({\r\n id,\r\n content: typeof content === 'function' ? content(close) : content,\r\n options,\r\n });\r\n }\r\n\r\n return nextToasts;\r\n};\r\n\r\nexport const ToastProvider = ({ children, ...props }: ToastProviderProps): JSX.Element => {\r\n const [toasts, setToasts] = React.useState<InternalToast[]>([]);\r\n\r\n const handleClose = (id: string): void => {\r\n setToasts(currentToasts => currentToasts.filter(toast => toast.id !== id));\r\n };\r\n\r\n // memoize (useCallback) this function,\r\n // it is the value of the context provider and we don't want it to trigger state tree re-renders on provider children\r\n const toaster = React.useCallback((content: React.ReactNode, options: ToastOptions): ToastReference => {\r\n const id = uuid();\r\n const close = (): void => handleClose(id);\r\n\r\n setToasts(currentToasts => insertToastWithoutDuplicates(currentToasts, id, content, options, close));\r\n\r\n const update = (content: React.ReactNode, options: ToastOptions): void => {\r\n setToasts(currentToasts => {\r\n const nextToasts = currentToasts.filter(toast => {\r\n if (toast.lastDuplicateId) {\r\n return toast.lastDuplicateId !== id;\r\n }\r\n\r\n return toast.id !== id;\r\n });\r\n return insertToastWithoutDuplicates(nextToasts, uuid(), content, options, close);\r\n });\r\n };\r\n\r\n const success = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): void => {\r\n update(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\r\n };\r\n const error = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): void => {\r\n update(content, { ...options, type: 'error' });\r\n };\r\n const warning = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): void => {\r\n update(content, { ...options, type: 'warning' });\r\n };\r\n const information = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): void => {\r\n update(content, { ...options, type: 'information' });\r\n };\r\n const loading = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): void => {\r\n update(content, { ...options, type: 'loading' });\r\n };\r\n\r\n return {\r\n success,\r\n error,\r\n warning,\r\n information,\r\n loading,\r\n close,\r\n };\r\n }, []) as Toaster<ToastReference>;\r\n\r\n // no need to rebind these every render, do them once in an effect\r\n React.useEffect(() => {\r\n toaster.success = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): ToastReference =>\r\n toaster(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\r\n toaster.error = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): ToastReference =>\r\n toaster(content, { ...options, type: 'error' });\r\n toaster.warning = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): ToastReference =>\r\n toaster(content, { ...options, type: 'warning' });\r\n toaster.information = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): ToastReference =>\r\n toaster(content, { ...options, type: 'information' });\r\n toaster.loading = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): ToastReference =>\r\n toaster(content, { ...options, type: 'loading' });\r\n }, []);\r\n\r\n return (\r\n <ToastContext.Provider {...props} value={toaster}>\r\n {children}\r\n <div\r\n id=\"yt-toast__container\"\r\n className=\"pointer-events-all absolute bottom-0 right-0 !left-auto z-[1000] mb-4 mr-4 flex max-w-md flex-col items-end justify-end\"\r\n role=\"log\"\r\n >\r\n <AnimatePresence initial={false}>\r\n {toasts.map((toast: ToastProps) => (\r\n <motion.div\r\n key={toast.id}\r\n transition={{\r\n type: 'spring',\r\n damping: 20,\r\n stiffness: 300,\r\n }}\r\n initial={{ opacity: 0, y: 10, scale: 0.5 }}\r\n animate={{ opacity: 1, y: 0, scale: 1 }}\r\n exit={{ opacity: 0, scale: 0.5, transition: { duration: 0.2 } }}\r\n >\r\n <Toast {...toast} onClose={() => handleClose(toast.id)} />\r\n </motion.div>\r\n ))}\r\n </AnimatePresence>\r\n </div>\r\n </ToastContext.Provider>\r\n );\r\n};\r\n\r\nexport const useToast = (): Toaster<ToastReference> => React.useContext(ToastContext);\r\n"],"names":["DEFAULT_AUTO_CLOSE_TIMEOUT","ToastContext","React","insertToastWithoutDuplicates","currentToasts","id","content","options","close","nextToasts","existingToastIndex","findIndex","toast","JSON","stringify","lastDuplicateId","lastUpdated","Date","now","push","ToastProvider","children","props","toasts","setToasts","handleClose","filter","toaster","uuid","update","success","autoClose","type","error","warning","information","loading","Provider","value","className","role","AnimatePresence","initial","map","motion","div","key","transition","damping","stiffness","opacity","y","scale","animate","exit","duration","Toast","onClose","useToast"],"mappings":";;;;;;;AAMA,IAAMA,0BAA0B,GAAG,IAAnC;AA+BA,IAAMC,YAAY,gBAAGC,aAAA,CAA6C,EAA7C,CAArB;;AAQA,IAAMC,4BAA4B,GAAG,SAA/BA,4BAA+B,CACjCC,aADiC,EAEjCC,EAFiC,EAGjCC,OAHiC,EAIjCC,OAJiC,EAKjCC,KALiC;AAOj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AZ;AAAtC;KATV,EAWIrD,aAAA,CAACsD,KAAD,oBAAW5C;AAAO6C,MAAAA,OAAO,EAAE;AAAA,eAAMhC,WAAW,CAACb,KAAK,CAACP,EAAP,CAAjB;AAAA;MAA3B,CAXJ,CADQ;AAAA,GAAX,CADL,CALJ,CAFJ,CADJ;AA4BH;IAEYqD,QAAQ,GAAG,SAAXA,QAAW;AAAA,SAA+BxD,UAAA,CAAiBD,YAAjB,CAA/B;AAAA;;;;"}
|
1
|
+
{"version":3,"file":"Toaster.js","sources":["../../../../src/components/Toast/Toaster.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport { v4 as uuid } from 'uuid';\r\nimport { AnimatePresence, motion } from 'framer-motion';\r\nimport { ToastOptions, Toast, ToastProps } from './Toast';\r\nimport './Toast.css';\r\n\r\nconst DEFAULT_AUTO_CLOSE_TIMEOUT = 7500;\r\n\r\ntype ToastCreator<T> = (content: React.ReactNode | ((close: () => void) => React.ReactNode), options?: ToastOptions) => T;\r\n\r\nexport interface Toaster<T> extends ToastCreator<T> {\r\n success: ToastCreator<T>;\r\n error: ToastCreator<T>;\r\n warning: ToastCreator<T>;\r\n information: ToastCreator<T>;\r\n loading: ToastCreator<T>;\r\n}\r\n\r\nexport interface ToastReference {\r\n /** Show a success toast */\r\n success: ToastCreator<void>;\r\n /** Show an error toast */\r\n error: ToastCreator<void>;\r\n /** Show a warning toast */\r\n warning: ToastCreator<void>;\r\n /** Show an information toast */\r\n information: ToastCreator<void>;\r\n /** Show a loading toast */\r\n loading: ToastCreator<void>;\r\n /**\r\n * Close an existing toast.\r\n * The toast function returns a reference to the active toast,\r\n * allowing you to programmatically close it when needed\r\n */\r\n close: () => void;\r\n}\r\n\r\nconst ToastContext = React.createContext<Toaster<ToastReference>>({} as Toaster<ToastReference>);\r\n\r\nexport interface ToastProviderProps {\r\n children: React.ReactNode;\r\n}\r\n\r\ntype InternalToast = Omit<ToastProps, 'onClose'>;\r\n\r\nconst insertToastWithoutDuplicates = (\r\n currentToasts: InternalToast[],\r\n id: string,\r\n content: React.ReactNode,\r\n options: ToastOptions,\r\n close: () => void\r\n): InternalToast[] => {\r\n const nextToasts = [...currentToasts];\r\n const existingToastIndex = currentToasts.findIndex(toast => JSON.stringify(toast.content) === JSON.stringify(content));\r\n\r\n if (existingToastIndex > -1) {\r\n nextToasts[existingToastIndex].lastDuplicateId = id;\r\n nextToasts[existingToastIndex].lastUpdated = Date.now();\r\n } else {\r\n nextToasts.push({\r\n id,\r\n content: typeof content === 'function' ? content(close) : content,\r\n options,\r\n });\r\n }\r\n\r\n return nextToasts;\r\n};\r\n\r\nexport const ToastProvider = ({ children, ...props }: ToastProviderProps): JSX.Element => {\r\n const [toasts, setToasts] = React.useState<InternalToast[]>([]);\r\n\r\n const handleClose = (id: string): void => {\r\n setToasts(currentToasts => currentToasts.filter(toast => toast.id !== id));\r\n };\r\n\r\n // memoize (useCallback) this function,\r\n // it is the value of the context provider and we don't want it to trigger state tree re-renders on provider children\r\n const toaster = React.useCallback((content: React.ReactNode, options: ToastOptions): ToastReference => {\r\n const id = uuid();\r\n const close = (): void => handleClose(id);\r\n\r\n setToasts(currentToasts => insertToastWithoutDuplicates(currentToasts, id, content, options, close));\r\n\r\n const update = (content: React.ReactNode, options: ToastOptions): void => {\r\n setToasts(currentToasts => {\r\n const nextToasts = currentToasts.filter(toast => {\r\n if (toast.lastDuplicateId) {\r\n return toast.lastDuplicateId !== id;\r\n }\r\n\r\n return toast.id !== id;\r\n });\r\n return insertToastWithoutDuplicates(nextToasts, uuid(), content, options, close);\r\n });\r\n };\r\n\r\n const success = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): void => {\r\n update(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\r\n };\r\n const error = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): void => {\r\n update(content, { ...options, type: 'error' });\r\n };\r\n const warning = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): void => {\r\n update(content, { ...options, type: 'warning' });\r\n };\r\n const information = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): void => {\r\n update(content, { ...options, type: 'information' });\r\n };\r\n const loading = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): void => {\r\n update(content, { ...options, type: 'loading' });\r\n };\r\n\r\n return {\r\n success,\r\n error,\r\n warning,\r\n information,\r\n loading,\r\n close,\r\n };\r\n }, []) as Toaster<ToastReference>;\r\n\r\n // no need to rebind these every render, do them once in an effect\r\n React.useEffect(() => {\r\n toaster.success = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): ToastReference =>\r\n toaster(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\r\n toaster.error = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): ToastReference =>\r\n toaster(content, { ...options, type: 'error' });\r\n toaster.warning = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): ToastReference =>\r\n toaster(content, { ...options, type: 'warning' });\r\n toaster.information = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): ToastReference =>\r\n toaster(content, { ...options, type: 'information' });\r\n toaster.loading = (content: React.ReactNode, options?: Omit<ToastOptions, 'type'>): ToastReference =>\r\n toaster(content, { ...options, type: 'loading' });\r\n }, []);\r\n\r\n return (\r\n <ToastContext.Provider {...props} value={toaster}>\r\n {children}\r\n <div\r\n id=\"yt-toast__container\"\r\n className=\"pointer-events-all absolute bottom-0 right-0 !left-auto z-[1000] mb-4 mr-4 flex max-w-md flex-col items-end justify-end\"\r\n role=\"log\"\r\n >\r\n <AnimatePresence initial={false}>\r\n {toasts.map((toast: ToastProps) => (\r\n <motion.div\r\n key={toast.id}\r\n transition={{\r\n type: 'spring',\r\n damping: 20,\r\n stiffness: 300,\r\n }}\r\n initial={{ opacity: 0, y: 10, scale: 0.5 }}\r\n animate={{ opacity: 1, y: 0, scale: 1 }}\r\n exit={{ opacity: 0, scale: 0.5, transition: { duration: 0.2 } }}\r\n >\r\n <Toast {...toast} onClose={() => handleClose(toast.id)} />\r\n </motion.div>\r\n ))}\r\n </AnimatePresence>\r\n </div>\r\n </ToastContext.Provider>\r\n );\r\n};\r\n\r\nexport const useToast = (): Toaster<ToastReference> => React.useContext(ToastContext);\r\n"],"names":["DEFAULT_AUTO_CLOSE_TIMEOUT","ToastContext","React","insertToastWithoutDuplicates","currentToasts","id","content","options","close","nextToasts","existingToastIndex","findIndex","toast","JSON","stringify","lastDuplicateId","lastUpdated","Date","now","push","ToastProvider","children","props","toasts","setToasts","handleClose","filter","toaster","uuid","update","success","autoClose","type","error","warning","information","loading","Provider","value","className","role","AnimatePresence","initial","map","motion","div","key","transition","damping","stiffness","opacity","y","scale","animate","exit","duration","Toast","onClose","useToast"],"mappings":";;;;;AAMA,MAAMA,0BAA0B,GAAG,IAAnC;AA+BA,MAAMC,YAAY,gBAAGC,aAAA,CAA6C,EAA7C,CAArB;;AAQA,MAAMC,4BAA4B,GAAG,CACjCC,aADiC,EAEjCC,EAFiC,EAGjCC,OAHiC,EAIjCC,OAJiC,EAKjCC,KALiC;AAOjC,QAAMC,UAAU,GAAG,CAAC,GAAGL,aAAJ,CAAnB;AACA,QAAMM,kBAAkB,GAAGN,aAAa,CAACO,SAAd,CAAwBC,KAAK,IAAIC,IAAI,CAACC,SAAL,CAAeF,KAAK,CAACN,OAArB,MAAkCO,IAAI,CAACC,SAAL,CAAeR,OAAf,CAAnE,CAA3B;;AAEA,MAAII,kBAAkB,GAAG,CAAC,CAA1B,EAA6B;AACzBD,IAAAA,UAAU,CAACC,kBAAD,CAAV,CAA+BK,eAA/B,GAAiDV,EAAjD;AACAI,IAAAA,UAAU,CAACC,kBAAD,CAAV,CAA+BM,WAA/B,GAA6CC,IAAI,CAACC,GAAL,EAA7C;AACH,GAHD,MAGO;AACHT,IAAAA,UAAU,CAACU,IAAX,CAAgB;AACZd,MAAAA,EADY;AAEZC,MAAAA,OAAO,EAAE,OAAOA,OAAP,KAAmB,UAAnB,GAAgCA,OAAO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H;AAKZP,IAAAA,OAAO,EAAE;AAAEQ,MAAAA,OAAO,EAAE,CAAX;AAAcC,MAAAA,CAAC,EAAE,EAAjB;AAAqBC,MAAAA,KAAK,EAAE;AAA5B;AACTC,IAAAA,OAAO,EAAE;AAAEH,MAAAA,OAAO,EAAE,CAAX;AAAcC,MAAAA,CAAC,EAAE,CAAjB;AAAoBC,MAAAA,KAAK,EAAE;AAA3B;AACTE,IAAAA,IAAI,EAAE;AAAEJ,MAAAA,OAAO,EAAE,CAAX;AAAcE,MAAAA,KAAK,EAAE,GAArB;AAA0BL,MAAAA,UAAU,EAAE;AAAEQ,QAAAA,QAAQ,EAAE;AAAZ;AAAtC;GATV,EAWIrD,aAAA,CAACsD,KAAD,oBAAW5C;AAAO6C,IAAAA,OAAO,EAAE,MAAMhC,WAAW,CAACb,KAAK,CAACP,EAAP;IAA5C,CAXJ,CADH,CADL,CALJ,CAFJ,CADJ;AA4BH;MAEYqD,QAAQ,GAAG,MAA+BxD,UAAA,CAAiBD,YAAjB;;;;"}
|
@@ -1,14 +1,13 @@
|
|
1
|
-
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
2
1
|
import { forwardRef, createElement } from 'react';
|
3
2
|
import { Root, Trigger, Content, Arrow } from '@radix-ui/react-tooltip';
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
const Tooltip = /*#__PURE__*/forwardRef(function Tooltip(props, ref) {
|
5
|
+
const {
|
6
|
+
title,
|
7
|
+
children,
|
8
|
+
placement,
|
9
|
+
...otherProps
|
10
|
+
} = props;
|
12
11
|
return createElement(Root, {
|
13
12
|
delayDuration: 50
|
14
13
|
}, createElement(Trigger, {
|