@uva-glass/component-library 1.3.1 → 1.3.3
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/SelectListbox.module-1nd3xIGj.js +25 -0
- package/dist/SelectListbox.module-1nd3xIGj.js.map +1 -0
- package/dist/assets/SelectListbox.css +1 -1
- package/dist/components/SelectListbox/SelectListBox.stories.js +41 -24
- package/dist/components/SelectListbox/SelectListBox.stories.js.map +1 -1
- package/dist/components/SelectListbox/SelectListbox.d.ts +5 -28
- package/dist/components/SelectListbox/SelectListbox.js +35 -35
- package/dist/components/SelectListbox/SelectListbox.js.map +1 -1
- package/dist/components/SelectListbox/SelectProvider.js +18 -20
- package/dist/components/SelectListbox/SelectProvider.js.map +1 -1
- package/dist/components/SelectListbox/components/SelectButton.d.ts +1 -0
- package/dist/components/SelectListbox/components/SelectButton.js +27 -27
- package/dist/components/SelectListbox/components/SelectButton.js.map +1 -1
- package/dist/components/SelectListbox/components/SelectContainer.js +1 -1
- package/dist/components/SelectListbox/components/SelectOption.js +1 -1
- package/dist/components/SelectListbox/components/SelectOptionBox.js +20 -9
- package/dist/components/SelectListbox/components/SelectOptionBox.js.map +1 -1
- package/dist/components/hooks/useDebounce.d.ts +3 -0
- package/dist/components/hooks/useDebounce.js +17 -0
- package/dist/components/hooks/useDebounce.js.map +1 -0
- package/dist/components/hooks/usePositionedFloaters.d.ts +1 -5
- package/dist/components/hooks/usePositionedFloaters.js +37 -36
- package/dist/components/hooks/usePositionedFloaters.js.map +1 -1
- package/dist/components/hooks/useResponsive.d.ts +19 -0
- package/dist/components/hooks/useResponsive.js +33 -0
- package/dist/components/hooks/useResponsive.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +9 -6
- package/dist/components/index.js.map +1 -1
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/SelectListbox.module-iJtzAajj.js +0 -23
- package/dist/SelectListbox.module-iJtzAajj.js.map +0 -1
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { OptionValue, SelectValue } from './SelectProvider';
|
|
3
|
-
import { SelectButton } from './components/SelectButton';
|
|
4
|
-
import { SelectContainer } from './components/SelectContainer';
|
|
5
|
-
import { SelectOptionBox } from './components/SelectOptionBox';
|
|
6
|
-
import { SelectOption } from './components/SelectOption';
|
|
7
3
|
|
|
8
|
-
interface
|
|
4
|
+
export interface SelectListboxProps {
|
|
9
5
|
options: OptionValue[];
|
|
10
6
|
defaultValue?: SelectValue;
|
|
11
7
|
maxOptionHeight?: `${number}${'px' | 'rem'}`;
|
|
@@ -13,31 +9,12 @@ interface ISelect {
|
|
|
13
9
|
buttonLabelProp?: string;
|
|
14
10
|
buttonLabelBold?: boolean;
|
|
15
11
|
variant?: 'noborder' | 'pill' | 'pillLeft' | 'pillRight';
|
|
12
|
+
size?: 'small' | 'default';
|
|
16
13
|
optionPositionRight?: boolean;
|
|
14
|
+
mobileBreakpoint?: `${number}${'px' | 'rem'}`;
|
|
17
15
|
onChange?: (option: OptionValue) => void;
|
|
18
|
-
children?: ReactNode;
|
|
19
16
|
}
|
|
20
|
-
export interface SelectListboxProps extends ISelect {
|
|
21
|
-
SelectOption?: typeof SelectOption;
|
|
22
|
-
SelectOptionBox?: typeof SelectOptionBox;
|
|
23
|
-
SelectButton: typeof SelectButton;
|
|
24
|
-
SelectContainer: typeof SelectContainer;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* SelectListbox component
|
|
28
|
-
* Options can be a component or just a label, it should be wrapped in SelectListbox.SelectOption
|
|
29
|
-
* NOTE: If you want to use a custom component, you should add [aria-hidden="true"]
|
|
30
|
-
* on the root element so the screen reader will ignore it
|
|
31
|
-
*
|
|
32
|
-
* TODO: Buttonlabel should take a component aswell zo the bold prop can be removed
|
|
33
|
-
*/
|
|
34
17
|
export declare const SelectListbox: {
|
|
35
|
-
({ options, variant, optionPositionRight, defaultValue, maxOptionHeight, disabled, buttonLabelProp, buttonLabelBold, onChange, children, }: PropsWithChildren<SelectListboxProps>): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
({ options, variant, size, optionPositionRight, defaultValue, maxOptionHeight, disabled, buttonLabelProp, buttonLabelBold, onChange, children, }: PropsWithChildren<SelectListboxProps>): import("react/jsx-runtime").JSX.Element;
|
|
36
19
|
SelectOption: ({ option, index, children }: import('./components/SelectOption').SelectOptionProps) => import("react/jsx-runtime").JSX.Element;
|
|
37
|
-
SelectButton: import('react').ForwardRefExoticComponent<import('./components/SelectButton').SelectButtonProps & import('react').RefAttributes<HTMLButtonElement>>;
|
|
38
|
-
SelectContainer: ({ children }: {
|
|
39
|
-
children?: ReactNode;
|
|
40
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
41
|
-
SelectOptionBox: import('react').ForwardRefExoticComponent<import('./components/SelectOptionBox').SelectOptionBoxProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
42
20
|
};
|
|
43
|
-
export {};
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { SelectButton as
|
|
4
|
-
import { SelectContainer as
|
|
5
|
-
import { SelectOptionBox as
|
|
6
|
-
import { SelectOption as
|
|
1
|
+
import { jsx as e, jsxs as E } from "react/jsx-runtime";
|
|
2
|
+
import { useState as t } from "react";
|
|
3
|
+
import { SelectButton as b } from "./components/SelectButton.js";
|
|
4
|
+
import { SelectContainer as P } from "./components/SelectContainer.js";
|
|
5
|
+
import { SelectOptionBox as B } from "./components/SelectOptionBox.js";
|
|
6
|
+
import { SelectOption as O } from "./components/SelectOption.js";
|
|
7
7
|
import { SelectProvider as g } from "./SelectProvider.js";
|
|
8
8
|
import { usePositionedFloaters as j } from "../hooks/usePositionedFloaters.js";
|
|
9
|
-
const
|
|
10
|
-
options:
|
|
11
|
-
variant:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
const k = ({
|
|
10
|
+
options: o,
|
|
11
|
+
variant: i,
|
|
12
|
+
size: r = "default",
|
|
13
|
+
optionPositionRight: n,
|
|
14
|
+
defaultValue: l = -1,
|
|
15
|
+
maxOptionHeight: m,
|
|
16
|
+
disabled: s,
|
|
17
|
+
buttonLabelProp: c = "label",
|
|
18
|
+
buttonLabelBold: f,
|
|
19
|
+
onChange: p,
|
|
20
|
+
children: S
|
|
20
21
|
}) => {
|
|
21
|
-
const [
|
|
22
|
+
const [a, u] = t(null), [x, d] = t(null), { style: h } = j(a, x, {
|
|
22
23
|
mouseEvent: "click",
|
|
23
24
|
position: "bottomLeft",
|
|
24
25
|
offset: 4,
|
|
25
|
-
maxFixedHeight:
|
|
26
|
-
horizontalPosition:
|
|
26
|
+
maxFixedHeight: m,
|
|
27
|
+
horizontalPosition: n ? "right" : "left",
|
|
28
|
+
mobileBreakpoint: "28rem"
|
|
27
29
|
});
|
|
28
|
-
return /* @__PURE__ */
|
|
29
|
-
/* @__PURE__ */
|
|
30
|
-
|
|
30
|
+
return /* @__PURE__ */ e(g, { options: o, defaultValue: l, children: /* @__PURE__ */ E(P, { children: [
|
|
31
|
+
/* @__PURE__ */ e(
|
|
32
|
+
b,
|
|
31
33
|
{
|
|
32
|
-
disabled:
|
|
33
|
-
buttonLabelProp:
|
|
34
|
-
buttonLabelBold:
|
|
35
|
-
variant:
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
disabled: s,
|
|
35
|
+
buttonLabelProp: c,
|
|
36
|
+
buttonLabelBold: f,
|
|
37
|
+
variant: i,
|
|
38
|
+
size: r,
|
|
39
|
+
onChange: p,
|
|
40
|
+
ref: d
|
|
38
41
|
}
|
|
39
42
|
),
|
|
40
|
-
/* @__PURE__ */
|
|
43
|
+
/* @__PURE__ */ e(B, { ref: u, ...h, children: S })
|
|
41
44
|
] }) });
|
|
42
45
|
};
|
|
43
|
-
|
|
44
|
-
e.SelectButton = i;
|
|
45
|
-
e.SelectContainer = n;
|
|
46
|
-
e.SelectOptionBox = r;
|
|
46
|
+
k.SelectOption = O;
|
|
47
47
|
export {
|
|
48
|
-
|
|
48
|
+
k as SelectListbox
|
|
49
49
|
};
|
|
50
50
|
//# sourceMappingURL=SelectListbox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectListbox.js","sources":["../../../src/components/SelectListbox/SelectListbox.tsx"],"sourcesContent":["import { useState } from 'react';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"SelectListbox.js","sources":["../../../src/components/SelectListbox/SelectListbox.tsx"],"sourcesContent":["import { useState } from 'react';\n\nimport type { PropsWithChildren } from 'react';\nimport type { OptionValue, SelectValue } from './SelectProvider';\n\nimport { SelectButton } from './components/SelectButton';\nimport { SelectContainer } from './components/SelectContainer';\nimport { SelectOptionBox } from './components/SelectOptionBox';\nimport { SelectOption } from './components/SelectOption';\nimport { SelectProvider } from './SelectProvider';\n\nimport { usePositionedFloaters } from 'components/hooks/usePositionedFloaters';\n\nexport interface SelectListboxProps {\n options: OptionValue[];\n defaultValue?: SelectValue;\n maxOptionHeight?: `${number}${'px' | 'rem'}`;\n disabled?: boolean;\n buttonLabelProp?: string;\n buttonLabelBold?: boolean;\n variant?: 'noborder' | 'pill' | 'pillLeft' | 'pillRight';\n size?: 'small' | 'default';\n optionPositionRight?: boolean;\n mobileBreakpoint?: `${number}${'px' | 'rem'}`;\n onChange?: (option: OptionValue) => void;\n}\n\nexport const SelectListbox = ({\n options,\n variant,\n size = 'default',\n optionPositionRight,\n defaultValue = -1,\n maxOptionHeight,\n disabled,\n buttonLabelProp = 'label',\n buttonLabelBold,\n onChange,\n children,\n}: PropsWithChildren<SelectListboxProps>) => {\n const [positionElement, setPositionElement] = useState<HTMLElement | null>(null);\n const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null);\n const { style: positionStyle } = usePositionedFloaters(positionElement, referenceElement, {\n mouseEvent: 'click',\n position: 'bottomLeft',\n offset: 4,\n maxFixedHeight: maxOptionHeight,\n horizontalPosition: optionPositionRight ? 'right' : 'left',\n mobileBreakpoint: '28rem',\n });\n\n return (\n <SelectProvider options={options} defaultValue={defaultValue}>\n <SelectContainer>\n <SelectButton\n disabled={disabled}\n buttonLabelProp={buttonLabelProp}\n buttonLabelBold={buttonLabelBold}\n variant={variant}\n size={size}\n onChange={onChange}\n ref={setReferenceElement}\n />\n\n <SelectOptionBox ref={setPositionElement} {...positionStyle}>\n {children}\n </SelectOptionBox>\n </SelectContainer>\n </SelectProvider>\n );\n};\n\nSelectListbox.SelectOption = SelectOption;\n"],"names":["SelectListbox","options","variant","size","optionPositionRight","defaultValue","maxOptionHeight","disabled","buttonLabelProp","buttonLabelBold","onChange","children","positionElement","setPositionElement","useState","referenceElement","setReferenceElement","positionStyle","usePositionedFloaters","jsx","SelectProvider","SelectContainer","SelectButton","SelectOptionBox","SelectOption"],"mappings":";;;;;;;;AA2BO,MAAMA,IAAgB,CAAC;AAAA,EAC5B,SAAAC;AAAA,EACA,SAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,qBAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,iBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,iBAAAC,IAAkB;AAAA,EAClB,iBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AACF,MAA6C;AAC3C,QAAM,CAACC,GAAiBC,CAAkB,IAAIC,EAA6B,IAAI,GACzE,CAACC,GAAkBC,CAAmB,IAAIF,EAA6B,IAAI,GAC3E,EAAE,OAAOG,EAAA,IAAkBC,EAAsBN,GAAiBG,GAAkB;AAAA,IACxF,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,gBAAgBT;AAAA,IAChB,oBAAoBF,IAAsB,UAAU;AAAA,IACpD,kBAAkB;AAAA,EAAA,CACnB;AAED,SACG,gBAAAe,EAAAC,GAAA,EAAe,SAAAnB,GAAkB,cAAAI,GAChC,4BAACgB,GACC,EAAA,UAAA;AAAA,IAAA,gBAAAF;AAAA,MAACG;AAAA,MAAA;AAAA,QACC,UAAAf;AAAA,QACA,iBAAAC;AAAA,QACA,iBAAAC;AAAA,QACA,SAAAP;AAAA,QACA,MAAAC;AAAA,QACA,UAAAO;AAAA,QACA,KAAKM;AAAA,MAAA;AAAA,IACP;AAAA,sBAECO,GAAgB,EAAA,KAAKV,GAAqB,GAAGI,GAC3C,UAAAN,GACH;AAAA,EAAA,EACF,CAAA,EACF,CAAA;AAEJ;AAEAX,EAAc,eAAewB;"}
|
|
@@ -1,38 +1,36 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
4
|
-
const [
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as g, useState as l, useRef as p, useId as C, useContext as P } from "react";
|
|
3
|
+
const d = g({}), L = ({ options: e, defaultValue: o, children: i }) => {
|
|
4
|
+
const [c, v] = l({ value: "", label: "" }), [x, s] = l(!1), [f, r] = l(-1), I = p(C()), b = () => {
|
|
5
5
|
s((t) => !t);
|
|
6
|
-
},
|
|
6
|
+
}, u = (t) => e.find((n) => n.value === t) || {
|
|
7
7
|
value: -1,
|
|
8
8
|
label: "",
|
|
9
9
|
selectedLabel: "-"
|
|
10
|
-
},
|
|
11
|
-
const
|
|
12
|
-
|
|
10
|
+
}, a = (t) => {
|
|
11
|
+
const n = e.findIndex((S) => S.value === t.value);
|
|
12
|
+
r(n), v(t), s(!1);
|
|
13
13
|
};
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
}, [n]), /* @__PURE__ */ g(
|
|
17
|
-
i.Provider,
|
|
14
|
+
return o !== -1 && !c.value && a(u(o)), /* @__PURE__ */ m(
|
|
15
|
+
d.Provider,
|
|
18
16
|
{
|
|
19
17
|
value: {
|
|
20
18
|
options: e,
|
|
21
|
-
selectedValue:
|
|
22
|
-
setSelectedValue:
|
|
23
|
-
isOpen:
|
|
19
|
+
selectedValue: c,
|
|
20
|
+
setSelectedValue: a,
|
|
21
|
+
isOpen: x,
|
|
24
22
|
setIsOpen: s,
|
|
25
23
|
toggleListbox: b,
|
|
26
|
-
getValue:
|
|
27
|
-
activeIndex:
|
|
28
|
-
setActiveIndex:
|
|
24
|
+
getValue: u,
|
|
25
|
+
activeIndex: f,
|
|
26
|
+
setActiveIndex: r,
|
|
29
27
|
listboxId: I.current
|
|
30
28
|
},
|
|
31
|
-
children:
|
|
29
|
+
children: i
|
|
32
30
|
}
|
|
33
31
|
);
|
|
34
32
|
}, O = () => {
|
|
35
|
-
const e =
|
|
33
|
+
const e = P(d);
|
|
36
34
|
if (e === void 0)
|
|
37
35
|
throw new Error("useSelect can only be used in an SelectProvider");
|
|
38
36
|
return e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectProvider.js","sources":["../../../src/components/SelectListbox/SelectProvider.tsx"],"sourcesContent":["import { createContext, useContext, useState, useId, useRef
|
|
1
|
+
{"version":3,"file":"SelectProvider.js","sources":["../../../src/components/SelectListbox/SelectProvider.tsx"],"sourcesContent":["import { createContext, useContext, useState, useId, useRef } from 'react';\n\nimport type { PropsWithChildren } from 'react';\n\nexport type SelectValue = string | number | null;\n\nexport type OptionValue = {\n value: SelectValue;\n label: string;\n selectedLabel?: string;\n disabled?: boolean;\n};\nexport interface SelectListboxContext {\n options: OptionValue[];\n selectedValue: OptionValue;\n setSelectedValue: (v: OptionValue) => void;\n isOpen: boolean;\n setIsOpen: (v: boolean) => void;\n toggleListbox: () => void;\n getValue: (value: SelectValue) => OptionValue;\n activeIndex: number;\n setActiveIndex: (v: number) => void;\n listboxId: string;\n}\n\nconst SelectContext = createContext<SelectListboxContext>({} as SelectListboxContext);\n\ninterface Props {\n options: OptionValue[];\n defaultValue: SelectValue;\n}\n\nexport const SelectProvider = ({ options, defaultValue, children }: PropsWithChildren<Props>) => {\n const [value, setValue] = useState<OptionValue>({ value: '', label: '' });\n const [isOpen, setIsOpen] = useState(false);\n const [activeIndex, setActiveIndex] = useState(-1);\n const listboxId = useRef<string>(useId());\n\n const toggleListbox = () => {\n setIsOpen((status) => !status);\n };\n\n const getValue = (value: SelectValue) => {\n return (\n options.find((option) => option.value === value) || {\n value: -1,\n label: '',\n selectedLabel: '-',\n }\n );\n };\n\n const setSelectedValue = (value: OptionValue) => {\n const selectedIndex = options.findIndex((option) => option.value === value.value);\n setActiveIndex(selectedIndex);\n setValue(value);\n setIsOpen(false);\n };\n\n if (defaultValue !== -1 && !value.value) {\n setSelectedValue(getValue(defaultValue));\n }\n\n return (\n <SelectContext.Provider\n value={{\n options,\n selectedValue: value,\n setSelectedValue,\n isOpen,\n setIsOpen,\n toggleListbox,\n getValue,\n activeIndex,\n setActiveIndex,\n listboxId: listboxId.current,\n }}\n >\n {children}\n </SelectContext.Provider>\n );\n};\n\nexport const useSelect = () => {\n const context = useContext(SelectContext);\n\n if (context === undefined) throw new Error('useSelect can only be used in an SelectProvider');\n\n return context;\n};\n"],"names":["SelectContext","createContext","SelectProvider","options","defaultValue","children","value","setValue","useState","isOpen","setIsOpen","activeIndex","setActiveIndex","listboxId","useRef","useId","toggleListbox","status","getValue","option","setSelectedValue","selectedIndex","jsx","useSelect","context","useContext"],"mappings":";;AAyBA,MAAMA,IAAgBC,EAAoC,CAAA,CAA0B,GAOvEC,IAAiB,CAAC,EAAE,SAAAC,GAAS,cAAAC,GAAc,UAAAC,QAAyC;AACzF,QAAA,CAACC,GAAOC,CAAQ,IAAIC,EAAsB,EAAE,OAAO,IAAI,OAAO,GAAA,CAAI,GAClE,CAACC,GAAQC,CAAS,IAAIF,EAAS,EAAK,GACpC,CAACG,GAAaC,CAAc,IAAIJ,EAAS,EAAE,GAC3CK,IAAYC,EAAeC,EAAA,CAAO,GAElCC,IAAgB,MAAM;AAChB,IAAAN,EAAA,CAACO,MAAW,CAACA,CAAM;AAAA,EAAA,GAGzBC,IAAW,CAACZ,MAEdH,EAAQ,KAAK,CAACgB,MAAWA,EAAO,UAAUb,CAAK,KAAK;AAAA,IAClD,OAAO;AAAA,IACP,OAAO;AAAA,IACP,eAAe;AAAA,EAAA,GAKfc,IAAmB,CAACd,MAAuB;AACzC,UAAAe,IAAgBlB,EAAQ,UAAU,CAACgB,MAAWA,EAAO,UAAUb,EAAM,KAAK;AAChF,IAAAM,EAAeS,CAAa,GAC5Bd,EAASD,CAAK,GACdI,EAAU,EAAK;AAAA,EAAA;AAGjB,SAAIN,MAAiB,MAAM,CAACE,EAAM,SACfc,EAAAF,EAASd,CAAY,CAAC,GAIvC,gBAAAkB;AAAA,IAACtB,EAAc;AAAA,IAAd;AAAA,MACC,OAAO;AAAA,QACL,SAAAG;AAAA,QACA,eAAeG;AAAA,QACf,kBAAAc;AAAA,QACA,QAAAX;AAAA,QACA,WAAAC;AAAA,QACA,eAAAM;AAAA,QACA,UAAAE;AAAA,QACA,aAAAP;AAAA,QACA,gBAAAC;AAAA,QACA,WAAWC,EAAU;AAAA,MACvB;AAAA,MAEC,UAAAR;AAAA,IAAA;AAAA,EAAA;AAGP,GAEakB,IAAY,MAAM;AACvB,QAAAC,IAAUC,EAAWzB,CAAa;AAExC,MAAIwB,MAAY;AAAiB,UAAA,IAAI,MAAM,iDAAiD;AAErF,SAAAA;AACT;"}
|
|
@@ -2,6 +2,7 @@ import { OptionValue } from 'components/SelectListbox/SelectProvider';
|
|
|
2
2
|
|
|
3
3
|
export interface SelectButtonProps {
|
|
4
4
|
variant?: 'noborder' | 'pill' | 'pillLeft' | 'pillRight';
|
|
5
|
+
size?: 'small' | 'default';
|
|
5
6
|
onChange?: (option: OptionValue) => void;
|
|
6
7
|
buttonLabelProp?: string;
|
|
7
8
|
buttonLabelBold?: boolean;
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { jsx as a, jsxs as
|
|
1
|
+
import { jsx as a, jsxs as C } from "react/jsx-runtime";
|
|
2
2
|
import { c as f } from "../../../clsx-DB4S2d7J.js";
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import { s as
|
|
5
|
-
import { Icon as
|
|
6
|
-
import { useSelect as
|
|
7
|
-
const
|
|
8
|
-
const { variant: b, onChange: n, buttonLabelProp: m = "label", buttonLabelBold:
|
|
9
|
-
switch (
|
|
3
|
+
import { forwardRef as E, useRef as g, useEffect as c } from "react";
|
|
4
|
+
import { s as t } from "../../../SelectListbox.module-1nd3xIGj.js";
|
|
5
|
+
import { Icon as L } from "../../Icon/Icon.js";
|
|
6
|
+
import { useSelect as N } from "../SelectProvider.js";
|
|
7
|
+
const O = E((d, u) => {
|
|
8
|
+
const { variant: b, size: x = "default", onChange: n, buttonLabelProp: m = "label", buttonLabelBold: h, disabled: w = !1 } = d, l = g(null), i = g(!0), { listboxId: y, isOpen: r, selectedValue: e, toggleListbox: I, setIsOpen: p, setActiveIndex: k, options: v } = N() || {}, D = (s) => {
|
|
9
|
+
switch (s.key) {
|
|
10
10
|
case "Enter":
|
|
11
|
-
if (
|
|
11
|
+
if (s.preventDefault(), !r) {
|
|
12
12
|
p(!0);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
break;
|
|
16
16
|
case "Escape":
|
|
17
|
-
|
|
17
|
+
r && (s.stopPropagation(), k(v.findIndex((o) => o.value === (e == null ? void 0 : e.value))), p(!1));
|
|
18
18
|
break;
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
return c(() => {
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
}, [
|
|
22
|
+
var s, o;
|
|
23
|
+
r ? ((s = l.current) == null ? void 0 : s.children[0]).blur() : !i.current && ((o = l.current) == null ? void 0 : o.children[0]).focus();
|
|
24
|
+
}, [r]), c(() => (i.current = !1, () => {
|
|
25
25
|
i.current = !0;
|
|
26
26
|
}), []), c(() => {
|
|
27
27
|
n && n(e);
|
|
28
|
-
}, [n, e]), /* @__PURE__ */ a("span", { ref: l, children: /* @__PURE__ */
|
|
28
|
+
}, [n, e]), /* @__PURE__ */ a("span", { ref: l, children: /* @__PURE__ */ C(
|
|
29
29
|
"button",
|
|
30
30
|
{
|
|
31
|
-
className: f(
|
|
32
|
-
[
|
|
33
|
-
[
|
|
31
|
+
className: f(t["select-listbox-trigger"], t[`select-listbox-trigger--${x}`], {
|
|
32
|
+
[t[`select-listbox-trigger--${b}`]]: b,
|
|
33
|
+
[t["select-listbox-trigger--bold"]]: h
|
|
34
34
|
}),
|
|
35
35
|
type: "button",
|
|
36
|
-
onClick:
|
|
37
|
-
onKeyDown:
|
|
38
|
-
"aria-expanded":
|
|
36
|
+
onClick: I,
|
|
37
|
+
onKeyDown: D,
|
|
38
|
+
"aria-expanded": r,
|
|
39
39
|
"aria-haspopup": "listbox",
|
|
40
40
|
"aria-label": `${e.label}`,
|
|
41
|
-
disabled:
|
|
42
|
-
"aria-controls":
|
|
41
|
+
disabled: w,
|
|
42
|
+
"aria-controls": y,
|
|
43
43
|
...u && { ref: u },
|
|
44
44
|
children: [
|
|
45
|
-
/* @__PURE__ */ a("span", { className:
|
|
45
|
+
/* @__PURE__ */ a("span", { className: t["select-listbox-trigger-label"], children: e[m] }),
|
|
46
46
|
/* @__PURE__ */ a(
|
|
47
|
-
|
|
47
|
+
L,
|
|
48
48
|
{
|
|
49
|
-
className: f(
|
|
50
|
-
[
|
|
49
|
+
className: f(t["select-listbox-trigger-icon"], {
|
|
50
|
+
[t["select-listbox-trigger-icon--open"]]: r
|
|
51
51
|
}),
|
|
52
52
|
name: "CheveronDown",
|
|
53
53
|
size: 16
|
|
@@ -58,6 +58,6 @@ const P = C((d, u) => {
|
|
|
58
58
|
) });
|
|
59
59
|
});
|
|
60
60
|
export {
|
|
61
|
-
|
|
61
|
+
O as SelectButton
|
|
62
62
|
};
|
|
63
63
|
//# sourceMappingURL=SelectButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectButton.js","sources":["../../../../src/components/SelectListbox/components/SelectButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useEffect, useRef, forwardRef } from 'react';\n\nimport type { KeyboardEvent } from 'react';\nimport type { OptionValue, SelectValue } from 'components/SelectListbox/SelectProvider';\n\nimport styles from 'components/SelectListbox/SelectListbox.module.css';\nimport { Icon } from 'components/Icon';\nimport { useSelect } from 'components/SelectListbox/SelectProvider';\n\nexport interface SelectButtonProps {\n variant?: 'noborder' | 'pill' | 'pillLeft' | 'pillRight';\n onChange?: (option: OptionValue) => void;\n buttonLabelProp?: string;\n buttonLabelBold?: boolean;\n disabled?: boolean;\n}\n\nexport const SelectButton = forwardRef<HTMLButtonElement, SelectButtonProps>((props, ref) => {\n const { variant, onChange, buttonLabelProp = 'label', buttonLabelBold, disabled = false } = props;\n const buttonWrapper = useRef<HTMLSpanElement>(null);\n const isFirstRender = useRef(true);\n const { listboxId, isOpen, selectedValue, toggleListbox, setIsOpen, setActiveIndex, options } = useSelect() || {};\n\n const onTriggerKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n switch (event.key) {\n case 'Enter':\n event.preventDefault();\n if (!isOpen) {\n setIsOpen(true);\n return;\n }\n break;\n case 'Escape':\n if (isOpen) {\n event.stopPropagation();\n setActiveIndex(options.findIndex((option) => option.value === selectedValue?.value));\n setIsOpen(false);\n }\n break;\n }\n };\n\n useEffect(() => {\n isOpen\n ? (buttonWrapper.current?.children[0] as HTMLButtonElement).blur()\n : !isFirstRender.current && (buttonWrapper.current?.children[0] as HTMLButtonElement).focus();\n }, [isOpen]);\n\n useEffect(() => {\n isFirstRender.current = false;\n\n return () => {\n isFirstRender.current = true;\n };\n }, []);\n\n useEffect(() => {\n if (onChange) onChange(selectedValue);\n }, [onChange, selectedValue]);\n\n return (\n <span ref={buttonWrapper}>\n <button\n className={clsx(styles['select-listbox-trigger'], {\n [styles[`select-listbox-trigger--${variant}`]]: variant,\n [styles['select-listbox-trigger--bold']]: buttonLabelBold,\n })}\n type=\"button\"\n onClick={toggleListbox}\n onKeyDown={onTriggerKeyDown}\n aria-expanded={isOpen}\n aria-haspopup=\"listbox\"\n aria-label={`${selectedValue.label}`}\n disabled={disabled}\n aria-controls={listboxId}\n {...(ref && { ref: ref })}\n >\n <span className={styles['select-listbox-trigger-label']}>\n {selectedValue[buttonLabelProp as keyof SelectValue]}\n </span>\n\n <Icon\n className={clsx(styles['select-listbox-trigger-icon'], {\n [styles['select-listbox-trigger-icon--open']]: isOpen,\n })}\n name=\"CheveronDown\"\n size={16}\n />\n </button>\n </span>\n );\n});\n"],"names":["SelectButton","forwardRef","props","ref","variant","onChange","buttonLabelProp","buttonLabelBold","disabled","buttonWrapper","useRef","isFirstRender","listboxId","isOpen","selectedValue","toggleListbox","setIsOpen","setActiveIndex","options","useSelect","onTriggerKeyDown","event","option","useEffect","_a","_b","jsx","jsxs","clsx","styles","Icon"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"SelectButton.js","sources":["../../../../src/components/SelectListbox/components/SelectButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useEffect, useRef, forwardRef } from 'react';\n\nimport type { KeyboardEvent } from 'react';\nimport type { OptionValue, SelectValue } from 'components/SelectListbox/SelectProvider';\n\nimport styles from 'components/SelectListbox/SelectListbox.module.css';\nimport { Icon } from 'components/Icon';\nimport { useSelect } from 'components/SelectListbox/SelectProvider';\n\nexport interface SelectButtonProps {\n variant?: 'noborder' | 'pill' | 'pillLeft' | 'pillRight';\n size?: 'small' | 'default';\n onChange?: (option: OptionValue) => void;\n buttonLabelProp?: string;\n buttonLabelBold?: boolean;\n disabled?: boolean;\n}\n\nexport const SelectButton = forwardRef<HTMLButtonElement, SelectButtonProps>((props, ref) => {\n const { variant, size = 'default', onChange, buttonLabelProp = 'label', buttonLabelBold, disabled = false } = props;\n const buttonWrapper = useRef<HTMLSpanElement>(null);\n const isFirstRender = useRef(true);\n const { listboxId, isOpen, selectedValue, toggleListbox, setIsOpen, setActiveIndex, options } = useSelect() || {};\n\n const onTriggerKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n switch (event.key) {\n case 'Enter':\n event.preventDefault();\n if (!isOpen) {\n setIsOpen(true);\n return;\n }\n break;\n case 'Escape':\n if (isOpen) {\n event.stopPropagation();\n setActiveIndex(options.findIndex((option) => option.value === selectedValue?.value));\n setIsOpen(false);\n }\n break;\n }\n };\n\n useEffect(() => {\n isOpen\n ? (buttonWrapper.current?.children[0] as HTMLButtonElement).blur()\n : !isFirstRender.current && (buttonWrapper.current?.children[0] as HTMLButtonElement).focus();\n }, [isOpen]);\n\n useEffect(() => {\n isFirstRender.current = false;\n\n return () => {\n isFirstRender.current = true;\n };\n }, []);\n\n useEffect(() => {\n if (onChange) onChange(selectedValue);\n }, [onChange, selectedValue]);\n\n return (\n <span ref={buttonWrapper}>\n <button\n className={clsx(styles['select-listbox-trigger'], styles[`select-listbox-trigger--${size}`], {\n [styles[`select-listbox-trigger--${variant}`]]: variant,\n [styles['select-listbox-trigger--bold']]: buttonLabelBold,\n })}\n type=\"button\"\n onClick={toggleListbox}\n onKeyDown={onTriggerKeyDown}\n aria-expanded={isOpen}\n aria-haspopup=\"listbox\"\n aria-label={`${selectedValue.label}`}\n disabled={disabled}\n aria-controls={listboxId}\n {...(ref && { ref: ref })}\n >\n <span className={styles['select-listbox-trigger-label']}>\n {selectedValue[buttonLabelProp as keyof SelectValue]}\n </span>\n\n <Icon\n className={clsx(styles['select-listbox-trigger-icon'], {\n [styles['select-listbox-trigger-icon--open']]: isOpen,\n })}\n name=\"CheveronDown\"\n size={16}\n />\n </button>\n </span>\n );\n});\n"],"names":["SelectButton","forwardRef","props","ref","variant","size","onChange","buttonLabelProp","buttonLabelBold","disabled","buttonWrapper","useRef","isFirstRender","listboxId","isOpen","selectedValue","toggleListbox","setIsOpen","setActiveIndex","options","useSelect","onTriggerKeyDown","event","option","useEffect","_a","_b","jsx","jsxs","clsx","styles","Icon"],"mappings":";;;;;;AAmBO,MAAMA,IAAeC,EAAiD,CAACC,GAAOC,MAAQ;AACrF,QAAA,EAAE,SAAAC,GAAS,MAAAC,IAAO,WAAW,UAAAC,GAAU,iBAAAC,IAAkB,SAAS,iBAAAC,GAAiB,UAAAC,IAAW,GAAA,IAAUP,GACxGQ,IAAgBC,EAAwB,IAAI,GAC5CC,IAAgBD,EAAO,EAAI,GAC3B,EAAE,WAAAE,GAAW,QAAAC,GAAQ,eAAAC,GAAe,eAAAC,GAAe,WAAAC,GAAW,gBAAAC,GAAgB,SAAAC,EAAQ,IAAIC,EAAU,KAAK,CAAA,GAEzGC,IAAmB,CAACC,MAA4C;AACpE,YAAQA,EAAM,KAAK;AAAA,MACjB,KAAK;AAEH,YADAA,EAAM,eAAe,GACjB,CAACR,GAAQ;AACX,UAAAG,EAAU,EAAI;AACd;AAAA,QACF;AACA;AAAA,MACF,KAAK;AACH,QAAIH,MACFQ,EAAM,gBAAgB,GACPJ,EAAAC,EAAQ,UAAU,CAACI,MAAWA,EAAO,WAAUR,KAAA,gBAAAA,EAAe,MAAK,CAAC,GACnFE,EAAU,EAAK;AAEjB;AAAA,IACJ;AAAA,EAAA;AAGF,SAAAO,EAAU,MAAM;;AACd,IAAAV,MACKW,IAAAf,EAAc,YAAd,gBAAAe,EAAuB,SAAS,IAAyB,SAC1D,CAACb,EAAc,aAAYc,IAAAhB,EAAc,YAAd,gBAAAgB,EAAuB,SAAS,IAAyB;EAAM,GAC7F,CAACZ,CAAM,CAAC,GAEXU,EAAU,OACRZ,EAAc,UAAU,IAEjB,MAAM;AACX,IAAAA,EAAc,UAAU;AAAA,EAAA,IAEzB,CAAE,CAAA,GAELY,EAAU,MAAM;AACV,IAAAlB,KAAUA,EAASS,CAAa;AAAA,EAAA,GACnC,CAACT,GAAUS,CAAa,CAAC,GAG1B,gBAAAY,EAAC,QAAK,EAAA,KAAKjB,GACT,UAAA,gBAAAkB;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWC,EAAKC,EAAO,wBAAwB,GAAGA,EAAO,2BAA2BzB,CAAI,EAAE,GAAG;AAAA,QAC3F,CAACyB,EAAO,2BAA2B1B,CAAO,EAAE,CAAC,GAAGA;AAAA,QAChD,CAAC0B,EAAO,8BAA8B,CAAC,GAAGtB;AAAA,MAAA,CAC3C;AAAA,MACD,MAAK;AAAA,MACL,SAASQ;AAAA,MACT,WAAWK;AAAA,MACX,iBAAeP;AAAA,MACf,iBAAc;AAAA,MACd,cAAY,GAAGC,EAAc,KAAK;AAAA,MAClC,UAAAN;AAAA,MACA,iBAAeI;AAAA,MACd,GAAIV,KAAO,EAAE,KAAAA,EAAS;AAAA,MAEvB,UAAA;AAAA,QAAA,gBAAAwB,EAAC,UAAK,WAAWG,EAAO,8BAA8B,GACnD,UAAAf,EAAcR,CAAoC,GACrD;AAAA,QAEA,gBAAAoB;AAAA,UAACI;AAAA,UAAA;AAAA,YACC,WAAWF,EAAKC,EAAO,6BAA6B,GAAG;AAAA,cACrD,CAACA,EAAO,mCAAmC,CAAC,GAAGhB;AAAA,YAAA,CAChD;AAAA,YACD,MAAK;AAAA,YACL,MAAM;AAAA,UAAA;AAAA,QACR;AAAA,MAAA;AAAA,IAAA;AAAA,EAEJ,EAAA,CAAA;AAEJ,CAAC;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as c } from "react/jsx-runtime";
|
|
2
2
|
import { useRef as i, useCallback as u, useEffect as l } from "react";
|
|
3
3
|
import { useSelect as m } from "../SelectProvider.js";
|
|
4
|
-
import { s as f } from "../../../SelectListbox.module-
|
|
4
|
+
import { s as f } from "../../../SelectListbox.module-1nd3xIGj.js";
|
|
5
5
|
const E = ({ children: o }) => {
|
|
6
6
|
const { isOpen: r, setIsOpen: n } = m(), t = i(null), e = u(
|
|
7
7
|
({ target: s }) => {
|
|
@@ -2,7 +2,7 @@ import { jsx as d } from "react/jsx-runtime";
|
|
|
2
2
|
import { c as v } from "../../../clsx-DB4S2d7J.js";
|
|
3
3
|
import { useRef as D, useEffect as p } from "react";
|
|
4
4
|
import { useSelect as y } from "../SelectProvider.js";
|
|
5
|
-
import { s as b } from "../../../SelectListbox.module-
|
|
5
|
+
import { s as b } from "../../../SelectListbox.module-1nd3xIGj.js";
|
|
6
6
|
const S = ({ option: t, index: l, children: m }) => {
|
|
7
7
|
const o = D(null), { isOpen: r, activeIndex: s, setActiveIndex: c, selectedValue: f, setSelectedValue: u, setIsOpen: i, options: a } = y(), w = (e) => {
|
|
8
8
|
u(a[e]), i(!1);
|
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
import { jsx as s } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef as m, useRef as
|
|
3
|
-
import { s as
|
|
4
|
-
import { useSelect as
|
|
5
|
-
const
|
|
6
|
-
const { style:
|
|
2
|
+
import { forwardRef as m, useRef as x } from "react";
|
|
3
|
+
import { s as i } from "../../../SelectListbox.module-1nd3xIGj.js";
|
|
4
|
+
import { useSelect as a } from "../SelectProvider.js";
|
|
5
|
+
const h = m((l, e) => {
|
|
6
|
+
const { style: t, children: o } = l, { listboxId: r, isOpen: c } = a(), n = x(null);
|
|
7
7
|
return /* @__PURE__ */ s(
|
|
8
8
|
"div",
|
|
9
9
|
{
|
|
10
|
-
className:
|
|
11
|
-
style: { ...
|
|
10
|
+
className: i["select-listbox__wrapper"],
|
|
11
|
+
style: { ...t, visibility: c ? "visible" : "hidden" },
|
|
12
12
|
...e && { ref: e },
|
|
13
|
-
children: /* @__PURE__ */ s(
|
|
13
|
+
children: /* @__PURE__ */ s(
|
|
14
|
+
"ul",
|
|
15
|
+
{
|
|
16
|
+
className: i["select-listbox"],
|
|
17
|
+
role: "listbox",
|
|
18
|
+
ref: n,
|
|
19
|
+
id: r,
|
|
20
|
+
tabIndex: -1,
|
|
21
|
+
style: { maxHeight: t.maxHeight },
|
|
22
|
+
children: o
|
|
23
|
+
}
|
|
24
|
+
)
|
|
14
25
|
}
|
|
15
26
|
);
|
|
16
27
|
});
|
|
17
28
|
export {
|
|
18
|
-
|
|
29
|
+
h as SelectOptionBox
|
|
19
30
|
};
|
|
20
31
|
//# sourceMappingURL=SelectOptionBox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectOptionBox.js","sources":["../../../../src/components/SelectListbox/components/SelectOptionBox.tsx"],"sourcesContent":["import { useRef, forwardRef } from 'react';\n\nimport type { CSSProperties, ReactNode } from 'react';\n\nimport styles from 'components/SelectListbox/SelectListbox.module.css';\nimport { useSelect } from 'components/SelectListbox/SelectProvider';\n\nexport interface SelectOptionBoxProps {\n style: CSSProperties;\n children: ReactNode;\n}\n\nexport const SelectOptionBox = forwardRef<HTMLDivElement, SelectOptionBoxProps>((props, ref) => {\n const { style, children } = props;\n const { listboxId, isOpen } = useSelect();\n const selectOptionBoxRef = useRef<HTMLUListElement>(null);\n\n return (\n <div\n className={styles['select-listbox__wrapper']}\n style={{ ...style, visibility: isOpen ? 'visible' : 'hidden' }}\n {...(ref && { ref: ref })}\n >\n <ul
|
|
1
|
+
{"version":3,"file":"SelectOptionBox.js","sources":["../../../../src/components/SelectListbox/components/SelectOptionBox.tsx"],"sourcesContent":["import { useRef, forwardRef } from 'react';\n\nimport type { CSSProperties, ReactNode } from 'react';\n\nimport styles from 'components/SelectListbox/SelectListbox.module.css';\nimport { useSelect } from 'components/SelectListbox/SelectProvider';\n\nexport interface SelectOptionBoxProps {\n style: CSSProperties;\n children: ReactNode;\n}\n\nexport const SelectOptionBox = forwardRef<HTMLDivElement, SelectOptionBoxProps>((props, ref) => {\n const { style, children } = props;\n const { listboxId, isOpen } = useSelect();\n const selectOptionBoxRef = useRef<HTMLUListElement>(null);\n\n return (\n <div\n className={styles['select-listbox__wrapper']}\n style={{ ...style, visibility: isOpen ? 'visible' : 'hidden' }}\n {...(ref && { ref: ref })}\n >\n <ul\n className={styles['select-listbox']}\n role=\"listbox\"\n ref={selectOptionBoxRef}\n id={listboxId}\n tabIndex={-1}\n style={{ maxHeight: style.maxHeight }}\n >\n {children}\n </ul>\n </div>\n );\n});\n"],"names":["SelectOptionBox","forwardRef","props","ref","style","children","listboxId","isOpen","useSelect","selectOptionBoxRef","useRef","jsx","styles"],"mappings":";;;;AAYO,MAAMA,IAAkBC,EAAiD,CAACC,GAAOC,MAAQ;AACxF,QAAA,EAAE,OAAAC,GAAO,UAAAC,EAAa,IAAAH,GACtB,EAAE,WAAAI,GAAW,QAAAC,EAAO,IAAIC,EAAU,GAClCC,IAAqBC,EAAyB,IAAI;AAGtD,SAAA,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWC,EAAO,yBAAyB;AAAA,MAC3C,OAAO,EAAE,GAAGR,GAAO,YAAYG,IAAS,YAAY,SAAS;AAAA,MAC5D,GAAIJ,KAAO,EAAE,KAAAA,EAAS;AAAA,MAEvB,UAAA,gBAAAQ;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAWC,EAAO,gBAAgB;AAAA,UAClC,MAAK;AAAA,UACL,KAAKH;AAAA,UACL,IAAIH;AAAA,UACJ,UAAU;AAAA,UACV,OAAO,EAAE,WAAWF,EAAM,UAAU;AAAA,UAEnC,UAAAC;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAGN,CAAC;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useRef as c, useEffect as o } from "react";
|
|
2
|
+
const i = 200;
|
|
3
|
+
function f(t, n = i) {
|
|
4
|
+
const e = c();
|
|
5
|
+
return o(() => () => {
|
|
6
|
+
e.current && clearTimeout(e.current);
|
|
7
|
+
}, []), (...r) => {
|
|
8
|
+
const u = setTimeout(() => {
|
|
9
|
+
t(...r);
|
|
10
|
+
}, n);
|
|
11
|
+
clearTimeout(e.current), e.current = u;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
f as useDebounce
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=useDebounce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebounce.js","sources":["../../../src/components/hooks/useDebounce.ts"],"sourcesContent":["import { useRef, useEffect } from 'react';\n\ntype Timer = ReturnType<typeof setTimeout>;\ntype SomeFunction = (...args: unknown[]) => void;\n\nconst DELAY = 200;\n\nexport function useDebounce<Func extends SomeFunction>(callBack: Func, delay = DELAY) {\n const timer = useRef<Timer>();\n\n useEffect(() => {\n return () => {\n if (!timer.current) return;\n clearTimeout(timer.current);\n };\n }, []);\n\n const debouncedFunction = ((...args) => {\n const newTimer = setTimeout(() => {\n callBack(...args);\n }, delay);\n clearTimeout(timer.current);\n timer.current = newTimer;\n }) as Func;\n\n return debouncedFunction;\n}\n"],"names":["DELAY","useDebounce","callBack","delay","timer","useRef","useEffect","args","newTimer"],"mappings":";AAKA,MAAMA,IAAQ;AAEE,SAAAC,EAAuCC,GAAgBC,IAAQH,GAAO;AACpF,QAAMI,IAAQC;AAEd,SAAAC,EAAU,MACD,MAAM;AACX,IAAKF,EAAM,WACX,aAAaA,EAAM,OAAO;AAAA,EAAA,GAE3B,CAAE,CAAA,GAEsB,IAAIG,MAAS;AAChC,UAAAC,IAAW,WAAW,MAAM;AAChC,MAAAN,EAAS,GAAGK,CAAI;AAAA,OACfJ,CAAK;AACR,iBAAaC,EAAM,OAAO,GAC1BA,EAAM,UAAUI;AAAA,EAAA;AAIpB;"}
|
|
@@ -4,11 +4,6 @@ interface positionProps {
|
|
|
4
4
|
inset: string;
|
|
5
5
|
};
|
|
6
6
|
};
|
|
7
|
-
buttonStyle: {
|
|
8
|
-
buttonStyle: {
|
|
9
|
-
width: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
7
|
status: boolean;
|
|
13
8
|
}
|
|
14
9
|
interface optionProps {
|
|
@@ -17,6 +12,7 @@ interface optionProps {
|
|
|
17
12
|
offset: number;
|
|
18
13
|
maxFixedHeight?: `${number}${'px' | 'rem'}`;
|
|
19
14
|
horizontalPosition?: 'left' | 'right';
|
|
15
|
+
mobileBreakpoint?: `${number}${'px' | 'rem'}`;
|
|
20
16
|
}
|
|
21
17
|
export declare function usePositionedFloaters<T extends HTMLElement = HTMLElement>(positionedElement: T | null, referenceElement: T | null, options: optionProps): positionProps;
|
|
22
18
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { useState as L, useEffect as F } from "react";
|
|
2
|
+
import { useDebounce as y } from "./useDebounce.js";
|
|
3
|
+
const a = 10, B = 45, l = 300, W = 0, k = 768, D = 2;
|
|
4
|
+
function S(d, e, n) {
|
|
5
|
+
const [m, H] = L(!1), v = {
|
|
5
6
|
inset: "0 auto auto 0",
|
|
6
7
|
opacity: 0,
|
|
7
8
|
maxHeight: "100%",
|
|
@@ -9,60 +10,60 @@ function p(d, i, e) {
|
|
|
9
10
|
overflowX: "hidden",
|
|
10
11
|
overflowY: "auto",
|
|
11
12
|
margin: "0rem"
|
|
12
|
-
}, [c,
|
|
13
|
+
}, [c, w] = L(v), h = (t) => {
|
|
13
14
|
const o = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
14
15
|
return t.indexOf("rem") !== -1 ? parseFloat(t) * o : parseFloat(t);
|
|
15
|
-
},
|
|
16
|
+
}, b = (t, o) => {
|
|
16
17
|
if (!t)
|
|
17
18
|
return 0;
|
|
18
|
-
const
|
|
19
|
-
return !
|
|
20
|
-
},
|
|
19
|
+
const i = o === "bottom" ? window.innerHeight - t.bottom - n.offset - a : t.top - n.offset - a;
|
|
20
|
+
return !n.maxFixedHeight || h(n.maxFixedHeight) > i ? i : h(n.maxFixedHeight);
|
|
21
|
+
}, p = (t, o) => {
|
|
21
22
|
if (!t)
|
|
22
23
|
return 0;
|
|
23
|
-
const
|
|
24
|
-
return
|
|
25
|
-
},
|
|
26
|
-
const t = d == null ? void 0 : d.getBoundingClientRect(), o =
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
const i = o === "left" ? window.innerWidth - t.left - a : t.right - a;
|
|
25
|
+
return i <= l ? l : i;
|
|
26
|
+
}, P = (t, o, i) => i ? `${t.left - Math.abs(o.width - t.width) / D}px` : `${t.left}px`, x = () => {
|
|
27
|
+
const t = d == null ? void 0 : d.getBoundingClientRect(), o = e == null ? void 0 : e.getBoundingClientRect();
|
|
28
|
+
let i = "bottom", u = "left";
|
|
29
|
+
const f = window.matchMedia(
|
|
30
|
+
`(max-width: ${n.mobileBreakpoint ? h(n.mobileBreakpoint) : k}px)`
|
|
31
|
+
).matches;
|
|
32
|
+
return !o || !t ? v : (window.innerHeight - o.bottom - a < B && (i = "top"), (window.innerWidth - o.left - a < l || n.horizontalPosition === "right") && !f && (u = "right"), {
|
|
33
|
+
inset: `${i === "bottom" ? o[i] + "px" : "auto"}
|
|
34
|
+
${u === "right" ? window.innerWidth - o[u] + "px" : "auto"}
|
|
35
|
+
${i === "top" ? window.innerHeight - o[i] + "px" : "auto"}
|
|
36
|
+
${u === "left" ? P(o, t, f) : "auto"}`,
|
|
37
|
+
maxHeight: `${b(o, i)}px`,
|
|
38
|
+
maxWidth: `${p(o, u)}px`,
|
|
35
39
|
overflowX: "hidden",
|
|
36
40
|
overflowY: "auto",
|
|
37
41
|
opacity: 1,
|
|
38
|
-
margin: `${
|
|
42
|
+
margin: `${n.offset}px 0`
|
|
39
43
|
});
|
|
40
44
|
}, r = () => {
|
|
41
|
-
|
|
45
|
+
w({
|
|
42
46
|
...c,
|
|
43
|
-
...
|
|
47
|
+
...x()
|
|
44
48
|
}), H(!0);
|
|
45
|
-
},
|
|
46
|
-
|
|
49
|
+
}, $ = () => {
|
|
50
|
+
m && w({
|
|
47
51
|
...c,
|
|
48
|
-
...
|
|
52
|
+
...x()
|
|
49
53
|
});
|
|
50
54
|
}, s = (t) => {
|
|
51
|
-
!
|
|
52
|
-
};
|
|
53
|
-
return F(() => (
|
|
54
|
-
|
|
55
|
+
!e || e.contains(t.target) || !d || d.contains(t.target);
|
|
56
|
+
}, g = y($, W);
|
|
57
|
+
return F(() => (e !== null && (n.mouseEvent === "click" ? e.addEventListener("click", r) : (e.addEventListener("mouseenter", r), e.addEventListener("mouseleave", s)), document.addEventListener("mousedown", s), document.addEventListener("touchstart", s), window.addEventListener("resize", g)), () => {
|
|
58
|
+
e !== null && (n.mouseEvent === "click" ? e.removeEventListener("click", r) : (e.removeEventListener("mouseenter", r), e.removeEventListener("mouseleave", s)), document.removeEventListener("mousedown", s), document.removeEventListener("touchstart", s), window.removeEventListener("resize", g));
|
|
55
59
|
})), {
|
|
56
60
|
style: {
|
|
57
61
|
style: c
|
|
58
62
|
},
|
|
59
|
-
|
|
60
|
-
buttonStyle: L
|
|
61
|
-
},
|
|
62
|
-
status: v
|
|
63
|
+
status: m
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
export {
|
|
66
|
-
|
|
67
|
+
S as usePositionedFloaters
|
|
67
68
|
};
|
|
68
69
|
//# sourceMappingURL=usePositionedFloaters.js.map
|