@tcn/ui 0.12.1 → 0.12.2
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/inputs/phone_number_input/phone_number_input_adapter.d.ts.map +1 -1
- package/dist/inputs/phone_number_input/phone_number_input_adapter.js +39 -34
- package/dist/inputs/phone_number_input/phone_number_input_adapter.js.map +1 -1
- package/dist/inputs/phone_number_input/sip_input.d.ts.map +1 -1
- package/dist/inputs/phone_number_input/sip_input.js +57 -52
- package/dist/inputs/phone_number_input/sip_input.js.map +1 -1
- package/dist/inputs/suggestions/suggestion_list.d.ts +8 -1
- package/dist/inputs/suggestions/suggestion_list.d.ts.map +1 -1
- package/dist/inputs/suggestions/suggestion_list.js +121 -111
- package/dist/inputs/suggestions/suggestion_list.js.map +1 -1
- package/package.json +1 -1
- package/src/inputs/phone_number_input/phone_number_input.stories.tsx +7 -0
- package/src/inputs/phone_number_input/phone_number_input_adapter.tsx +5 -0
- package/src/inputs/phone_number_input/sip_input.tsx +5 -0
- package/src/inputs/select/select.stories.tsx +34 -11
- package/src/inputs/suggestions/suggestion_list.tsx +23 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone_number_input_adapter.d.ts","sourceRoot":"","sources":["../../../src/inputs/phone_number_input/phone_number_input_adapter.tsx"],"names":[],"mappings":"AAUA;;;GAGG;AACH,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"phone_number_input_adapter.d.ts","sourceRoot":"","sources":["../../../src/inputs/phone_number_input/phone_number_input_adapter.tsx"],"names":[],"mappings":"AAUA;;;GAGG;AACH,eAAO,MAAM,uBAAuB,oJAiHlC,CAAC"}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { NotebookIcon as
|
|
1
|
+
import { jsxs as S, Fragment as A, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { NotebookIcon as C } from "@tcn/icons/notebook_icon.js";
|
|
3
3
|
import f from "clsx";
|
|
4
|
-
import { forwardRef as
|
|
4
|
+
import { forwardRef as F, useState as R, useRef as y, useCallback as z, useLayoutEffect as E } from "react";
|
|
5
5
|
import "../../actions/button/base_button/base_button.js";
|
|
6
6
|
import "../../actions/button/button_group/button_group.js";
|
|
7
7
|
import "../../actions/button/slim_button/slim_button.js";
|
|
8
|
-
import { Button as
|
|
8
|
+
import { Button as L } from "../../actions/button/button/button.js";
|
|
9
9
|
import "../../actions/button/select_group/select_group.js";
|
|
10
10
|
import "../../actions/button/select_group/single_select_group.js";
|
|
11
11
|
import "../../actions/toggle/toggle.js";
|
|
12
12
|
import { SuggestionList as w } from "../suggestions/suggestion_list.js";
|
|
13
|
-
import { usePhoneContext as
|
|
13
|
+
import { usePhoneContext as j } from "./phone_number_context.js";
|
|
14
14
|
import { getCountryFromValue as T } from "./phone_number_country_select_adapter.js";
|
|
15
15
|
import { Input as V } from "../input/input.js";
|
|
16
16
|
import { useForkRef as q } from "../../utils/hooks/use_fork_ref.js";
|
|
17
|
-
const
|
|
17
|
+
const eo = F(function({ onChange: e, value: t = "", className: a, ...h }, g) {
|
|
18
18
|
t = t.toString();
|
|
19
|
-
const [
|
|
19
|
+
const [s, r] = R(
|
|
20
20
|
null
|
|
21
|
-
), u =
|
|
22
|
-
phoneBook:
|
|
23
|
-
setValue:
|
|
21
|
+
), u = s != null, c = y(null), d = q(g, c), {
|
|
22
|
+
phoneBook: l,
|
|
23
|
+
setValue: k,
|
|
24
24
|
ariaPhoneBookButtonLabel: b,
|
|
25
25
|
disabled: B,
|
|
26
26
|
setFocusNumberInput: P,
|
|
27
|
-
focusNumberInput:
|
|
28
|
-
} =
|
|
27
|
+
focusNumberInput: p
|
|
28
|
+
} = j(), x = l.length > 0;
|
|
29
29
|
function I(o) {
|
|
30
30
|
r(u ? null : o.currentTarget);
|
|
31
31
|
}
|
|
@@ -33,63 +33,68 @@ const no = y(function({ onChange: n, value: t = "", className: a, ...h }, g) {
|
|
|
33
33
|
r(null);
|
|
34
34
|
}
|
|
35
35
|
function N(o) {
|
|
36
|
-
m(), P(!0),
|
|
36
|
+
m(), P(!0), k(o);
|
|
37
37
|
}
|
|
38
|
-
const
|
|
39
|
-
(o,
|
|
40
|
-
if (!
|
|
41
|
-
|
|
38
|
+
const O = z(
|
|
39
|
+
(o, i) => {
|
|
40
|
+
if (!e) return;
|
|
41
|
+
e(i ?? {
|
|
42
42
|
target: { value: o },
|
|
43
43
|
currentTarget: { value: o }
|
|
44
44
|
});
|
|
45
45
|
},
|
|
46
|
-
[
|
|
46
|
+
[e]
|
|
47
47
|
);
|
|
48
48
|
if (t.startsWith("+")) {
|
|
49
|
-
const
|
|
50
|
-
t = t.substring(
|
|
49
|
+
const i = T(t)?.prefix?.length || 0;
|
|
50
|
+
t = t.substring(i);
|
|
51
51
|
}
|
|
52
|
-
return
|
|
53
|
-
const o =
|
|
54
|
-
o == null || !
|
|
52
|
+
return E(() => {
|
|
53
|
+
const o = c?.current;
|
|
54
|
+
o == null || !p || requestAnimationFrame(() => {
|
|
55
55
|
o.value.length > 0 ? o.select() : o.focus();
|
|
56
56
|
});
|
|
57
|
-
}, [
|
|
58
|
-
/* @__PURE__ */
|
|
57
|
+
}, [p]), /* @__PURE__ */ S(A, { children: [
|
|
58
|
+
/* @__PURE__ */ n(
|
|
59
59
|
V,
|
|
60
60
|
{
|
|
61
|
-
ref:
|
|
61
|
+
ref: d,
|
|
62
62
|
value: t,
|
|
63
63
|
...h,
|
|
64
64
|
className: f(a, "tcn-input-group-slot"),
|
|
65
|
-
onChange:
|
|
65
|
+
onChange: O
|
|
66
66
|
}
|
|
67
67
|
),
|
|
68
|
-
x && /* @__PURE__ */
|
|
69
|
-
|
|
68
|
+
x && /* @__PURE__ */ n(
|
|
69
|
+
L,
|
|
70
70
|
{
|
|
71
71
|
disabled: B,
|
|
72
72
|
className: f("tcn-input-group-slot", "tcn-phone-number-phone-book"),
|
|
73
73
|
"aria-label": b,
|
|
74
74
|
onClick: I,
|
|
75
75
|
size: "md",
|
|
76
|
-
children: /* @__PURE__ */
|
|
76
|
+
children: /* @__PURE__ */ n(C, { size: "md" })
|
|
77
77
|
}
|
|
78
78
|
),
|
|
79
|
-
/* @__PURE__ */
|
|
79
|
+
/* @__PURE__ */ n(
|
|
80
80
|
w,
|
|
81
81
|
{
|
|
82
82
|
open: u,
|
|
83
|
-
anchorElement:
|
|
83
|
+
anchorElement: s,
|
|
84
|
+
horizontalAnchor: "end",
|
|
85
|
+
horizontalOrigin: "end",
|
|
86
|
+
verticalAnchor: "top",
|
|
87
|
+
verticalOrigin: "top",
|
|
88
|
+
width: "300px",
|
|
84
89
|
onOptionSelect: N,
|
|
85
90
|
onClose: m,
|
|
86
91
|
noSuggestionMessage: "No phone numbers found",
|
|
87
|
-
children:
|
|
92
|
+
children: l
|
|
88
93
|
}
|
|
89
94
|
)
|
|
90
95
|
] });
|
|
91
96
|
});
|
|
92
97
|
export {
|
|
93
|
-
|
|
98
|
+
eo as PhoneNumberInputAdapter
|
|
94
99
|
};
|
|
95
100
|
//# sourceMappingURL=phone_number_input_adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone_number_input_adapter.js","sources":["../../../src/inputs/phone_number_input/phone_number_input_adapter.tsx"],"sourcesContent":["import { NotebookIcon } from '@tcn/icons/notebook_icon.js';\nimport clsx from 'clsx';\nimport { forwardRef, useState, useCallback, useLayoutEffect, useRef } from 'react';\nimport { Button } from '../../actions/index.js';\nimport { SuggestionList } from '../suggestions/suggestion_list.js';\nimport { usePhoneContext } from './phone_number_context.js';\nimport { getCountryFromValue } from './phone_number_country_select_adapter.js';\nimport { Input } from '../input/input.js';\nimport { useForkRef } from '../../utils/hooks/use_fork_ref.js';\n\n/**\n * Bridges `@tcn/ui/inputs` Input (onChange: (value, event?) => void)\n * with react-phone-number-input's expectation (onChange: (event) => void).\n */\nexport const PhoneNumberInputAdapter = forwardRef<\n HTMLInputElement,\n React.InputHTMLAttributes<HTMLInputElement>\n>(function InputAdapter({ onChange, value = '', className, ...rest }, ref) {\n value = value.toString();\n const [phoneBookElement, setPhoneBookElement] = useState<HTMLButtonElement | null>(\n null\n );\n const isPhoneBookOpen = phoneBookElement != null;\n const internalInputRef = useRef<HTMLInputElement | null>(null);\n const forkedRef = useForkRef(ref, internalInputRef);\n\n const {\n phoneBook: phoneBookOptions,\n setValue,\n ariaPhoneBookButtonLabel,\n disabled,\n setFocusNumberInput,\n focusNumberInput,\n } = usePhoneContext();\n\n const showPhoneBook = phoneBookOptions.length > 0;\n\n function togglePhoneBook(e: React.MouseEvent<HTMLButtonElement>) {\n if (isPhoneBookOpen) {\n setPhoneBookElement(null);\n } else {\n setPhoneBookElement(e.currentTarget);\n }\n }\n\n function closePhoneBook() {\n setPhoneBookElement(null);\n }\n\n function handlePhoneBookOptionSelect(value: string) {\n closePhoneBook();\n setFocusNumberInput(true);\n setValue(value);\n }\n\n const handleChange = useCallback(\n (value: string, event?: React.ChangeEvent<HTMLInputElement>) => {\n if (!onChange) return;\n const e =\n event ??\n ({\n target: { value },\n currentTarget: { value },\n } as React.ChangeEvent<HTMLInputElement>);\n onChange(e);\n },\n [onChange]\n );\n\n if (value.startsWith('+')) {\n const country = getCountryFromValue(value);\n const prefixLength = country?.prefix?.length || 0;\n value = value.substring(prefixLength);\n }\n\n useLayoutEffect(() => {\n const input = internalInputRef?.current;\n\n if (input == null || !focusNumberInput) {\n return;\n }\n\n requestAnimationFrame(() => {\n if (input.value.length > 0) {\n input.select();\n } else {\n input.focus();\n }\n });\n }, [focusNumberInput]);\n\n return (\n <>\n <Input\n ref={forkedRef}\n value={value}\n {...(rest as any)}\n className={clsx(className, 'tcn-input-group-slot')}\n onChange={handleChange}\n />\n {showPhoneBook && (\n <Button\n disabled={disabled}\n className={clsx('tcn-input-group-slot', 'tcn-phone-number-phone-book')}\n aria-label={ariaPhoneBookButtonLabel}\n onClick={togglePhoneBook}\n size=\"md\"\n >\n <NotebookIcon size=\"md\" />\n </Button>\n )}\n <SuggestionList\n open={isPhoneBookOpen}\n anchorElement={phoneBookElement}\n onOptionSelect={handlePhoneBookOptionSelect}\n onClose={closePhoneBook}\n noSuggestionMessage=\"No phone numbers found\"\n >\n {phoneBookOptions}\n </SuggestionList>\n </>\n );\n});\n"],"names":["PhoneNumberInputAdapter","forwardRef","onChange","value","className","rest","ref","phoneBookElement","setPhoneBookElement","useState","isPhoneBookOpen","internalInputRef","useRef","forkedRef","useForkRef","phoneBookOptions","setValue","ariaPhoneBookButtonLabel","disabled","setFocusNumberInput","focusNumberInput","usePhoneContext","showPhoneBook","togglePhoneBook","e","closePhoneBook","handlePhoneBookOptionSelect","handleChange","useCallback","event","prefixLength","getCountryFromValue","useLayoutEffect","input","jsxs","Fragment","jsx","Input","clsx","Button","NotebookIcon","SuggestionList"],"mappings":";;;;;;;;;;;;;;;;AAcO,MAAMA,KAA0BC,EAGrC,SAAsB,EAAE,UAAAC,GAAU,OAAAC,IAAQ,IAAI,WAAAC,GAAW,GAAGC,EAAA,GAAQC,GAAK;AACzE,EAAAH,IAAQA,EAAM,SAAA;AACd,QAAM,CAACI,GAAkBC,CAAmB,IAAIC;AAAA,IAC9C;AAAA,EAAA,GAEIC,IAAkBH,KAAoB,MACtCI,IAAmBC,EAAgC,IAAI,GACvDC,IAAYC,EAAWR,GAAKK,CAAgB,GAE5C;AAAA,IACJ,WAAWI;AAAA,IACX,UAAAC;AAAA,IACA,0BAAAC;AAAA,IACA,UAAAC;AAAA,IACA,qBAAAC;AAAA,IACA,kBAAAC;AAAA,EAAA,IACEC,EAAA,GAEEC,IAAgBP,EAAiB,SAAS;AAEhD,WAASQ,EAAgBC,GAAwC;AAC/D,IACEhB,EADEE,IACkB,OAEAc,EAAE,aAFE;AAAA,EAI5B;AAEA,WAASC,IAAiB;AACxB,IAAAjB,EAAoB,IAAI;AAAA,EAC1B;AAEA,WAASkB,EAA4BvB,GAAe;AAClD,IAAAsB,EAAA,GACAN,EAAoB,EAAI,GACxBH,EAASb,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AgBmB;AAAA,QAChB,SAASD;AAAA,QACT,qBAAoB;AAAA,QAEnB,UAAAV;AAAA,MAAA;AAAA,IAAA;AAAA,EACH,GACF;AAEJ,CAAC;"}
|
|
1
|
+
{"version":3,"file":"phone_number_input_adapter.js","sources":["../../../src/inputs/phone_number_input/phone_number_input_adapter.tsx"],"sourcesContent":["import { NotebookIcon } from '@tcn/icons/notebook_icon.js';\nimport clsx from 'clsx';\nimport { forwardRef, useState, useCallback, useLayoutEffect, useRef } from 'react';\nimport { Button } from '../../actions/index.js';\nimport { SuggestionList } from '../suggestions/suggestion_list.js';\nimport { usePhoneContext } from './phone_number_context.js';\nimport { getCountryFromValue } from './phone_number_country_select_adapter.js';\nimport { Input } from '../input/input.js';\nimport { useForkRef } from '../../utils/hooks/use_fork_ref.js';\n\n/**\n * Bridges `@tcn/ui/inputs` Input (onChange: (value, event?) => void)\n * with react-phone-number-input's expectation (onChange: (event) => void).\n */\nexport const PhoneNumberInputAdapter = forwardRef<\n HTMLInputElement,\n React.InputHTMLAttributes<HTMLInputElement>\n>(function InputAdapter({ onChange, value = '', className, ...rest }, ref) {\n value = value.toString();\n const [phoneBookElement, setPhoneBookElement] = useState<HTMLButtonElement | null>(\n null\n );\n const isPhoneBookOpen = phoneBookElement != null;\n const internalInputRef = useRef<HTMLInputElement | null>(null);\n const forkedRef = useForkRef(ref, internalInputRef);\n\n const {\n phoneBook: phoneBookOptions,\n setValue,\n ariaPhoneBookButtonLabel,\n disabled,\n setFocusNumberInput,\n focusNumberInput,\n } = usePhoneContext();\n\n const showPhoneBook = phoneBookOptions.length > 0;\n\n function togglePhoneBook(e: React.MouseEvent<HTMLButtonElement>) {\n if (isPhoneBookOpen) {\n setPhoneBookElement(null);\n } else {\n setPhoneBookElement(e.currentTarget);\n }\n }\n\n function closePhoneBook() {\n setPhoneBookElement(null);\n }\n\n function handlePhoneBookOptionSelect(value: string) {\n closePhoneBook();\n setFocusNumberInput(true);\n setValue(value);\n }\n\n const handleChange = useCallback(\n (value: string, event?: React.ChangeEvent<HTMLInputElement>) => {\n if (!onChange) return;\n const e =\n event ??\n ({\n target: { value },\n currentTarget: { value },\n } as React.ChangeEvent<HTMLInputElement>);\n onChange(e);\n },\n [onChange]\n );\n\n if (value.startsWith('+')) {\n const country = getCountryFromValue(value);\n const prefixLength = country?.prefix?.length || 0;\n value = value.substring(prefixLength);\n }\n\n useLayoutEffect(() => {\n const input = internalInputRef?.current;\n\n if (input == null || !focusNumberInput) {\n return;\n }\n\n requestAnimationFrame(() => {\n if (input.value.length > 0) {\n input.select();\n } else {\n input.focus();\n }\n });\n }, [focusNumberInput]);\n\n return (\n <>\n <Input\n ref={forkedRef}\n value={value}\n {...(rest as any)}\n className={clsx(className, 'tcn-input-group-slot')}\n onChange={handleChange}\n />\n {showPhoneBook && (\n <Button\n disabled={disabled}\n className={clsx('tcn-input-group-slot', 'tcn-phone-number-phone-book')}\n aria-label={ariaPhoneBookButtonLabel}\n onClick={togglePhoneBook}\n size=\"md\"\n >\n <NotebookIcon size=\"md\" />\n </Button>\n )}\n <SuggestionList\n open={isPhoneBookOpen}\n anchorElement={phoneBookElement}\n horizontalAnchor=\"end\"\n horizontalOrigin=\"end\"\n verticalAnchor=\"top\"\n verticalOrigin=\"top\"\n width=\"300px\"\n onOptionSelect={handlePhoneBookOptionSelect}\n onClose={closePhoneBook}\n noSuggestionMessage=\"No phone numbers found\"\n >\n {phoneBookOptions}\n </SuggestionList>\n </>\n );\n});\n"],"names":["PhoneNumberInputAdapter","forwardRef","onChange","value","className","rest","ref","phoneBookElement","setPhoneBookElement","useState","isPhoneBookOpen","internalInputRef","useRef","forkedRef","useForkRef","phoneBookOptions","setValue","ariaPhoneBookButtonLabel","disabled","setFocusNumberInput","focusNumberInput","usePhoneContext","showPhoneBook","togglePhoneBook","e","closePhoneBook","handlePhoneBookOptionSelect","handleChange","useCallback","event","prefixLength","getCountryFromValue","useLayoutEffect","input","jsxs","Fragment","jsx","Input","clsx","Button","NotebookIcon","Suggest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QAAQ,CAACb,KAItB,sBAAsB,MAAM;AAC1B,MAAIa,EAAM,MAAM,SAAS,IACvBA,EAAM,OAAA,IAENA,EAAM,MAAA;AAAA,IAEV,CAAC;AAAA,EACH,GAAG,CAACb,CAAgB,CAAC,GAGnB,gBAAAc,EAAAC,GAAA,EACE,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAACC;AAAA,MAAA;AAAA,QACC,KAAKxB;AAAA,QACL,OAAAV;AAAA,QACC,GAAIE;AAAA,QACL,WAAWiC,EAAKlC,GAAW,sBAAsB;AAAA,QACjD,UAAUuB;AAAA,MAAA;AAAA,IAAA;AAAA,IAEXL,KACC,gBAAAc;AAAA,MAACG;AAAA,MAAA;AAAA,QACC,UAAArB;AAAA,QACA,WAAWoB,EAAK,wBAAwB,6BAA6B;AAAA,QACrE,cAAYrB;AAAA,QACZ,SAASM;AAAA,QACT,MAAK;AAAA,QAEL,UAAA,gBAAAa,EAACI,GAAA,EAAa,MAAK,KAAA,CAAK;AAAA,MAAA;AAAA,IAAA;AAAA,IAG5B,gBAAAJ;AAAA,MAACK;AAAA,MAAA;AAAA,QACC,MAAM/B;AAAA,QACN,eAAeH;AAAA,QACf,kBAAiB;AAAA,QACjB,kBAAiB;AAAA,QACjB,gBAAe;AAAA,QACf,gBAAe;AAAA,QACf,OAAM;AAAA,QACN,gBAAgBmB;AAAA,QAChB,SAASD;AAAA,QACT,qBAAoB;AAAA,QAEnB,UAAAV;AAAA,MAAA;AAAA,IAAA;AAAA,EACH,GACF;AAEJ,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sip_input.d.ts","sourceRoot":"","sources":["../../../src/inputs/phone_number_input/sip_input.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOrD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,QAAQ,CAAC,EACvB,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,YAAY,EAAE,SAAS,EACvB,SAAS,EACT,WAAW,GACZ,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"sip_input.d.ts","sourceRoot":"","sources":["../../../src/inputs/phone_number_input/sip_input.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOrD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,QAAQ,CAAC,EACvB,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,YAAY,EAAE,SAAS,EACvB,SAAS,EACT,WAAW,GACZ,EAAE,aAAa,2CAwHf"}
|
|
@@ -1,106 +1,111 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import g, { useLayoutEffect as
|
|
3
|
-
import { NotebookIcon as
|
|
4
|
-
import { Input as
|
|
1
|
+
import { jsxs as f, Fragment as z, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import g, { useLayoutEffect as E } from "react";
|
|
3
|
+
import { NotebookIcon as F } from "@tcn/icons/notebook_icon.js";
|
|
4
|
+
import { Input as L } from "../input/input.js";
|
|
5
5
|
import "../../actions/button/base_button/base_button.js";
|
|
6
6
|
import "../../actions/button/button_group/button_group.js";
|
|
7
7
|
import "../../actions/button/slim_button/slim_button.js";
|
|
8
|
-
import { Button as
|
|
8
|
+
import { Button as R } from "../../actions/button/button/button.js";
|
|
9
9
|
import "../../actions/button/select_group/select_group.js";
|
|
10
10
|
import "../../actions/button/select_group/single_select_group.js";
|
|
11
11
|
import "../../actions/toggle/toggle.js";
|
|
12
|
-
import { InputGroup as
|
|
13
|
-
import
|
|
14
|
-
import { usePhoneContext as
|
|
15
|
-
import { PhoneNumberCountrySelectAdapter as
|
|
16
|
-
import { SuggestionList as
|
|
12
|
+
import { InputGroup as j } from "../input_group/input_group.js";
|
|
13
|
+
import w from "clsx";
|
|
14
|
+
import { usePhoneContext as y } from "./phone_number_context.js";
|
|
15
|
+
import { PhoneNumberCountrySelectAdapter as V } from "./phone_number_country_select_adapter.js";
|
|
16
|
+
import { SuggestionList as _ } from "../suggestions/suggestion_list.js";
|
|
17
17
|
function eo({
|
|
18
18
|
disabled: n,
|
|
19
|
-
countries:
|
|
20
|
-
name:
|
|
21
|
-
"aria-label":
|
|
22
|
-
autoFocus:
|
|
23
|
-
placeholder:
|
|
19
|
+
countries: d,
|
|
20
|
+
name: k,
|
|
21
|
+
"aria-label": B,
|
|
22
|
+
autoFocus: S,
|
|
23
|
+
placeholder: P
|
|
24
24
|
}) {
|
|
25
|
-
const
|
|
26
|
-
phoneBook:
|
|
25
|
+
const i = g.useRef(null), [u, t] = g.useState(null), l = u != null, {
|
|
26
|
+
phoneBook: p,
|
|
27
27
|
setValue: r,
|
|
28
|
-
setCountry:
|
|
28
|
+
setCountry: b,
|
|
29
29
|
ariaPhoneBookButtonLabel: I,
|
|
30
|
-
sipAddress:
|
|
30
|
+
sipAddress: s,
|
|
31
31
|
setSipAddress: m,
|
|
32
32
|
focusNumberInput: c,
|
|
33
33
|
setFocusNumberInput: a
|
|
34
|
-
} =
|
|
35
|
-
function
|
|
34
|
+
} = y(), C = p.length > 0;
|
|
35
|
+
function x(o) {
|
|
36
36
|
t(l ? null : o.currentTarget);
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function h() {
|
|
39
39
|
t(null);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
41
|
+
function A(o) {
|
|
42
|
+
h(), a(!0), r(o);
|
|
43
43
|
}
|
|
44
|
-
const
|
|
44
|
+
const N = d?.map((o) => ({
|
|
45
45
|
value: o,
|
|
46
46
|
label: o
|
|
47
47
|
})) || [];
|
|
48
|
-
function E(o) {
|
|
49
|
-
o !== "SIP" && (m(p), a(!0), r(""), d(o || "US"));
|
|
50
|
-
}
|
|
51
48
|
function O(o) {
|
|
49
|
+
o !== "SIP" && (m(s), a(!0), r(""), b(o || "US"));
|
|
50
|
+
}
|
|
51
|
+
function v(o) {
|
|
52
52
|
m(o), r(`sip:${o}`);
|
|
53
53
|
}
|
|
54
|
-
return
|
|
55
|
-
const o =
|
|
54
|
+
return E(() => {
|
|
55
|
+
const o = i.current;
|
|
56
56
|
o == null || !c || requestAnimationFrame(() => {
|
|
57
57
|
o.value.length > 0 ? o.select() : o.focus();
|
|
58
58
|
});
|
|
59
|
-
}, [c]), /* @__PURE__ */
|
|
60
|
-
/* @__PURE__ */
|
|
59
|
+
}, [c]), /* @__PURE__ */ f(z, { children: [
|
|
60
|
+
/* @__PURE__ */ f(j, { children: [
|
|
61
61
|
/* @__PURE__ */ e(
|
|
62
|
-
|
|
62
|
+
V,
|
|
63
63
|
{
|
|
64
64
|
value: "SIP",
|
|
65
|
-
onChange:
|
|
66
|
-
options:
|
|
65
|
+
onChange: O,
|
|
66
|
+
options: N,
|
|
67
67
|
disabled: n
|
|
68
68
|
}
|
|
69
69
|
),
|
|
70
70
|
/* @__PURE__ */ e(
|
|
71
|
-
|
|
71
|
+
L,
|
|
72
72
|
{
|
|
73
|
-
ref:
|
|
74
|
-
value:
|
|
73
|
+
ref: i,
|
|
74
|
+
value: s,
|
|
75
75
|
disabled: n,
|
|
76
|
-
onChange:
|
|
77
|
-
name:
|
|
78
|
-
"aria-label":
|
|
79
|
-
autoFocus:
|
|
80
|
-
placeholder:
|
|
76
|
+
onChange: v,
|
|
77
|
+
name: k,
|
|
78
|
+
"aria-label": B,
|
|
79
|
+
autoFocus: S,
|
|
80
|
+
placeholder: P
|
|
81
81
|
}
|
|
82
82
|
),
|
|
83
83
|
C && /* @__PURE__ */ e(
|
|
84
|
-
|
|
84
|
+
R,
|
|
85
85
|
{
|
|
86
86
|
disabled: n,
|
|
87
|
-
className:
|
|
87
|
+
className: w("tcn-input-group-slot", "tcn-phone-number-phone-book"),
|
|
88
88
|
"aria-label": I,
|
|
89
|
-
onClick:
|
|
89
|
+
onClick: x,
|
|
90
90
|
size: "md",
|
|
91
|
-
children: /* @__PURE__ */ e(
|
|
91
|
+
children: /* @__PURE__ */ e(F, { size: "md" })
|
|
92
92
|
}
|
|
93
93
|
)
|
|
94
94
|
] }),
|
|
95
95
|
/* @__PURE__ */ e(
|
|
96
|
-
|
|
96
|
+
_,
|
|
97
97
|
{
|
|
98
98
|
open: l,
|
|
99
|
-
anchorElement:
|
|
100
|
-
onOptionSelect:
|
|
101
|
-
onClose:
|
|
99
|
+
anchorElement: u,
|
|
100
|
+
onOptionSelect: A,
|
|
101
|
+
onClose: h,
|
|
102
|
+
width: "300px",
|
|
102
103
|
noSuggestionMessage: "No phone numbers found",
|
|
103
|
-
|
|
104
|
+
horizontalAnchor: "end",
|
|
105
|
+
horizontalOrigin: "end",
|
|
106
|
+
verticalAnchor: "top",
|
|
107
|
+
verticalOrigin: "top",
|
|
108
|
+
children: p
|
|
104
109
|
}
|
|
105
110
|
)
|
|
106
111
|
] });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sip_input.js","sources":["../../../src/inputs/phone_number_input/sip_input.tsx"],"sourcesContent":["import React, { useLayoutEffect } from 'react';\nimport { NotebookIcon } from '@tcn/icons/notebook_icon.js';\nimport { Input } from '../input/input.js';\nimport { Button } from '../../actions/index.js';\nimport { InputGroup } from '../input_group/input_group.js';\nimport clsx from 'clsx';\nimport { usePhoneContext } from './phone_number_context.js';\nimport type { CountryCode } from 'libphonenumber-js';\nimport {\n PhoneNumberCountrySelectAdapter,\n type CountryOption,\n} from './phone_number_country_select_adapter.js';\nimport { SuggestionList } from '../suggestions/suggestion_list.js';\n\nexport interface SipInputProps {\n onChange: (value: string) => void;\n countries?: CountryCode[];\n disabled?: boolean;\n name?: string;\n 'aria-label'?: string;\n autoFocus?: boolean;\n placeholder?: string;\n}\n\nexport function SipInput({\n disabled,\n countries,\n name,\n 'aria-label': ariaLabel,\n autoFocus,\n placeholder,\n}: SipInputProps) {\n const inputRef = React.useRef<HTMLInputElement>(null);\n const [phoneBookElement, setPhoneBookElement] =\n React.useState<HTMLButtonElement | null>(null);\n const isPhoneBookOpen = phoneBookElement != null;\n\n const {\n phoneBook: phoneBookOptions,\n setValue,\n setCountry,\n ariaPhoneBookButtonLabel,\n sipAddress,\n setSipAddress,\n focusNumberInput,\n setFocusNumberInput,\n } = usePhoneContext();\n\n const showPhoneBook = phoneBookOptions.length > 0;\n\n function togglePhoneBook(e: React.MouseEvent<HTMLButtonElement>) {\n if (isPhoneBookOpen) {\n setPhoneBookElement(null);\n } else {\n setPhoneBookElement(e.currentTarget);\n }\n }\n\n function closePhoneBook() {\n setPhoneBookElement(null);\n }\n\n function handlePhoneBookOptionSelect(value: string) {\n closePhoneBook();\n setFocusNumberInput(true);\n setValue(value);\n }\n\n const options: CountryOption[] =\n countries?.map(country => ({\n value: country,\n label: country,\n })) || [];\n\n function selectCountry(countryCode?: string) {\n if (countryCode !== 'SIP') {\n setSipAddress(sipAddress);\n setFocusNumberInput(true);\n setValue('');\n setCountry((countryCode as CountryCode) || 'US');\n }\n }\n\n function updateSipValue(value: string) {\n setSipAddress(value);\n setValue(`sip:${value}`);\n }\n\n useLayoutEffect(() => {\n const input = inputRef.current;\n\n if (input == null || !focusNumberInput) {\n return;\n }\n\n requestAnimationFrame(() => {\n if (input.value.length > 0) {\n input.select();\n } else {\n input.focus();\n }\n });\n }, [focusNumberInput]);\n\n return (\n <>\n <InputGroup>\n <PhoneNumberCountrySelectAdapter\n value=\"SIP\"\n onChange={selectCountry}\n options={options}\n disabled={disabled}\n />\n <Input\n ref={inputRef}\n value={sipAddress}\n disabled={disabled}\n onChange={updateSipValue}\n name={name}\n aria-label={ariaLabel}\n autoFocus={autoFocus}\n placeholder={placeholder}\n />\n {showPhoneBook && (\n <Button\n disabled={disabled}\n className={clsx('tcn-input-group-slot', 'tcn-phone-number-phone-book')}\n aria-label={ariaPhoneBookButtonLabel}\n onClick={togglePhoneBook}\n size=\"md\"\n >\n <NotebookIcon size=\"md\" />\n </Button>\n )}\n </InputGroup>\n <SuggestionList\n open={isPhoneBookOpen}\n anchorElement={phoneBookElement}\n onOptionSelect={handlePhoneBookOptionSelect}\n onClose={closePhoneBook}\n noSuggestionMessage=\"No phone numbers found\"\n >\n {phoneBookOptions}\n </SuggestionList>\n </>\n );\n}\n"],"names":["SipInput","disabled","countries","name","ariaLabel","autoFocus","placeholder","inputRef","React","phoneBookElement","setPhoneBookElement","isPhoneBookOpen","phoneBookOptions","setValue","setCountry","ariaPhoneBookButtonLabel","sipAddress","setSipAddress","focusNumberInput","setFocusNumberInput","usePhoneContext","showPhoneBook","togglePhoneBook","e","closePhoneBook","handlePhoneBookOptionSelect","value","options","country","selectCountry","countryCode","updateSipValue","useLayoutEffect","input","jsxs","Fragment","InputGroup","jsx","PhoneNumberCountrySelectAdapter","Input","Button","clsx","NotebookIcon","SuggestionList"],"mappings":";;;;;;;;;;;;;;;;AAwBO,SAASA,GAAS;AAAA,EACvB,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,MAAAC;AAAA,EACA,cAAcC;AAAA,EACd,WAAAC;AAAA,EACA,aAAAC;AACF,GAAkB;AAChB,QAAMC,IAAWC,EAAM,OAAyB,IAAI,GAC9C,CAACC,GAA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A;AAAA,UACC,OAAM;AAAA,UACN,UAAUT;AAAA,UACV,SAAAF;AAAA,UACA,UAAA1B;AAAA,QAAA;AAAA,MAAA;AAAA,MAEF,gBAAAoC;AAAA,QAACE;AAAA,QAAA;AAAA,UACC,KAAKhC;AAAA,UACL,OAAOS;AAAA,UACP,UAAAf;AAAA,UACA,UAAU8B;AAAA,UACV,MAAA5B;AAAA,UACA,cAAYC;AAAA,UACZ,WAAAC;AAAA,UACA,aAAAC;AAAA,QAAA;AAAA,MAAA;AAAA,MAEDe,KACC,gBAAAgB;AAAA,QAACG;AAAA,QAAA;AAAA,UACC,UAAAvC;AAAA,UACA,WAAWwC,EAAK,wBAAwB,6BAA6B;AAAA,UACrE,cAAY1B;AAAA,UACZ,SAASO;AAAA,UACT,MAAK;AAAA,UAEL,UAAA,gBAAAe,EAACK,GAAA,EAAa,MAAK,KAAA,CAAK;AAAA,QAAA;AAAA,MAAA;AAAA,IAC1B,GAEJ;AAAA,IACA,gBAAAL;AAAA,MAACM;AAAA,MAAA;AAAA,QACC,MAAMhC;AAAA,QACN,eAAeF;AAAA,QACf,gBAAgBgB;AAAA,QAChB,SAASD;AAAA,QACT,qBAAoB;AAAA,
|
|
1
|
+
{"version":3,"file":"sip_input.js","sources":["../../../src/inputs/phone_number_input/sip_input.tsx"],"sourcesContent":["import React, { useLayoutEffect } from 'react';\nimport { NotebookIcon } from '@tcn/icons/notebook_icon.js';\nimport { Input } from '../input/input.js';\nimport { Button } from '../../actions/index.js';\nimport { InputGroup } from '../input_group/input_group.js';\nimport clsx from 'clsx';\nimport { usePhoneContext } from './phone_number_context.js';\nimport type { CountryCode } from 'libphonenumber-js';\nimport {\n PhoneNumberCountrySelectAdapter,\n type CountryOption,\n} from './phone_number_country_select_adapter.js';\nimport { SuggestionList } from '../suggestions/suggestion_list.js';\n\nexport interface SipInputProps {\n onChange: (value: string) => void;\n countries?: CountryCode[];\n disabled?: boolean;\n name?: string;\n 'aria-label'?: string;\n autoFocus?: boolean;\n placeholder?: string;\n}\n\nexport function SipInput({\n disabled,\n countries,\n name,\n 'aria-label': ariaLabel,\n autoFocus,\n placeholder,\n}: SipInputProps) {\n const inputRef = React.useRef<HTMLInputElement>(null);\n const [phoneBookElement, setPhoneBookElement] =\n React.useState<HTMLButtonElement | null>(null);\n const isPhoneBookOpen = phoneBookElement != null;\n\n const {\n phoneBook: phoneBookOptions,\n setValue,\n setCountry,\n ariaPhoneBookButtonLabel,\n sipAddress,\n setSipAddress,\n focusNumberInput,\n setFocusNumberInput,\n } = usePhoneContext();\n\n const showPhoneBook = phoneBookOptions.length > 0;\n\n function togglePhoneBook(e: React.MouseEvent<HTMLButtonElement>) {\n if (isPhoneBookOpen) {\n setPhoneBookElement(null);\n } else {\n setPhoneBookElement(e.currentTarget);\n }\n }\n\n function closePhoneBook() {\n setPhoneBookElement(null);\n }\n\n function handlePhoneBookOptionSelect(value: string) {\n closePhoneBook();\n setFocusNumberInput(true);\n setValue(value);\n }\n\n const options: CountryOption[] =\n countries?.map(country => ({\n value: country,\n label: country,\n })) || [];\n\n function selectCountry(countryCode?: string) {\n if (countryCode !== 'SIP') {\n setSipAddress(sipAddress);\n setFocusNumberInput(true);\n setValue('');\n setCountry((countryCode as CountryCode) || 'US');\n }\n }\n\n function updateSipValue(value: string) {\n setSipAddress(value);\n setValue(`sip:${value}`);\n }\n\n useLayoutEffect(() => {\n const input = inputRef.current;\n\n if (input == null || !focusNumberInput) {\n return;\n }\n\n requestAnimationFrame(() => {\n if (input.value.length > 0) {\n input.select();\n } else {\n input.focus();\n }\n });\n }, [focusNumberInput]);\n\n return (\n <>\n <InputGroup>\n <PhoneNumberCountrySelectAdapter\n value=\"SIP\"\n onChange={selectCountry}\n options={options}\n disabled={disabled}\n />\n <Input\n ref={inputRef}\n value={sipAddress}\n disabled={disabled}\n onChange={updateSipValue}\n name={name}\n aria-label={ariaLabel}\n autoFocus={autoFocus}\n placeholder={placeholder}\n />\n {showPhoneBook && (\n <Button\n disabled={disabled}\n className={clsx('tcn-input-group-slot', 'tcn-phone-number-phone-book')}\n aria-label={ariaPhoneBookButtonLabel}\n onClick={togglePhoneBook}\n size=\"md\"\n >\n <NotebookIcon size=\"md\" />\n </Button>\n )}\n </InputGroup>\n <SuggestionList\n open={isPhoneBookOpen}\n anchorElement={phoneBookElement}\n onOptionSelect={handlePhoneBookOptionSelect}\n onClose={closePhoneBook}\n width=\"300px\"\n noSuggestionMessage=\"No phone numbers found\"\n horizontalAnchor=\"end\"\n horizontalOrigin=\"end\"\n verticalAnchor=\"top\"\n verticalOrigin=\"top\"\n >\n {phoneBookOptions}\n </SuggestionList>\n </>\n );\n}\n"],"names":["SipInput","disabled","countries","name","ariaLabel","autoFocus","placeholder","inputRef","React","phoneBookElement","setPhoneBookElement","isPhoneBookOpen","phoneBookOptions","setValue","setCountry","ariaPhoneBookButtonLabel","sipAddress","setSipAddress","focusNumberInput","setFocusNumberInput","usePhoneContext","showPhoneBook","togglePhoneBook","e","closePhoneBook","handlePhoneBookOptionSelect","value","options","country","selectCountry","countryCode","updateSipValue","useLayoutEffect","input","jsxs","Fragment","InputGroup","jsx","PhoneNumberCountrySelectAdapter","Input","Button","clsx","NotebookIcon","SuggestionList"],"mappings":";;;;;;;;;;;;;;;;AAwBO,SAASA,GAAS;AAAA,EACvB,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,MAAAC;AAAA,EACA,cAAcC;AAAA,EACd,WAAAC;AAAA,EACA,aAAAC;AACF,GAAkB;AAChB,QAAMC,IAAWC,EAAM,OAAyB,IAAI,GAC9C,CAACC,GAAkBC,CAAmB,IAC1CF,EAAM,SAAmC,IAAI,GACzCG,IAAkBF,KAAoB,MAEtC;AAAA,IACJ,WAAWG;AAAA,IACX,UAAAC;AAAA,IACA,YAAAC;AAAA,IACA,0BAAAC;AAAA,IACA,YAAAC;AAAA,IACA,eAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,qBAAAC;AAAA,EAAA,IACEC,EAAA,GAEEC,IAAgBT,EAAiB,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,WAAAC;AAAA,UACA,aAAAC;AAAA,QAAA;AAAA,MAAA;AAAA,MAEDe,KACC,gBAAAgB;AAAA,QAACG;AAAA,QAAA;AAAA,UACC,UAAAvC;AAAA,UACA,WAAWwC,EAAK,wBAAwB,6BAA6B;AAAA,UACrE,cAAY1B;AAAA,UACZ,SAASO;AAAA,UACT,MAAK;AAAA,UAEL,UAAA,gBAAAe,EAACK,GAAA,EAAa,MAAK,KAAA,CAAK;AAAA,QAAA;AAAA,MAAA;AAAA,IAC1B,GAEJ;AAAA,IACA,gBAAAL;AAAA,MAACM;AAAA,MAAA;AAAA,QACC,MAAMhC;AAAA,QACN,eAAeF;AAAA,QACf,gBAAgBgB;AAAA,QAChB,SAASD;AAAA,QACT,OAAM;AAAA,QACN,qBAAoB;AAAA,QACpB,kBAAiB;AAAA,QACjB,kBAAiB;AAAA,QACjB,gBAAe;AAAA,QACf,gBAAe;AAAA,QAEd,UAAAZ;AAAA,MAAA;AAAA,IAAA;AAAA,EACH,GACF;AAEJ;"}
|
|
@@ -7,12 +7,19 @@ export interface SuggestionListProps extends Omit<React.HTMLAttributes<HTMLInput
|
|
|
7
7
|
open?: boolean;
|
|
8
8
|
children?: React.ReactNode;
|
|
9
9
|
onChange?: (value: string) => void;
|
|
10
|
+
width?: string;
|
|
10
11
|
onOptionSelect?: (value: string, label: string | undefined, isSuggestion: boolean, obfuscate: boolean) => void;
|
|
11
12
|
noSuggestionMessage?: React.ReactNode;
|
|
12
13
|
trimCustomInput?: boolean;
|
|
13
14
|
haveValueAsOption?: boolean;
|
|
14
15
|
restoreFocus?: boolean;
|
|
15
16
|
onClose?: (inputValue: string, cursorStartPosition: number | null, cursorEndPosition: number | null) => void;
|
|
17
|
+
verticalAnchor?: 'top' | 'center' | 'bottom';
|
|
18
|
+
verticalOrigin?: 'top' | 'center' | 'bottom';
|
|
19
|
+
verticalOffset?: number;
|
|
20
|
+
horizontalAnchor?: 'start' | 'center' | 'end';
|
|
21
|
+
horizontalOrigin?: 'start' | 'center' | 'end';
|
|
22
|
+
horizontalOffset?: number;
|
|
16
23
|
}
|
|
17
|
-
export declare function SuggestionList({ value, initialSearchValue: searchValue, scrollToValue, anchorElement, open, children, onOptionSelect, noSuggestionMessage, onClose, onChange, onKeyUp, onKeyDown, trimCustomInput, haveValueAsOption, restoreFocus, ...props }: SuggestionListProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export declare function SuggestionList({ value, initialSearchValue: searchValue, scrollToValue, anchorElement, open, width, children, onOptionSelect, noSuggestionMessage, onClose, onChange, onKeyUp, onKeyDown, trimCustomInput, haveValueAsOption, restoreFocus, verticalAnchor, verticalOrigin, verticalOffset, horizontalAnchor, horizontalOrigin, horizontalOffset, ...props }: SuggestionListProps): import("react/jsx-runtime").JSX.Element;
|
|
18
25
|
//# sourceMappingURL=suggestion_list.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suggestion_list.d.ts","sourceRoot":"","sources":["../../../src/inputs/suggestions/suggestion_list.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAoD,MAAM,OAAO,CAAC;AAazE,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC;IAClC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,cAAc,CAAC,EAAE,CACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,YAAY,EAAE,OAAO,EACrB,SAAS,EAAE,OAAO,KACf,IAAI,C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EAAE,MAAM,EAClB,mBAAmB,EAAE,MAAM,GAAG,IAAI,EAClC,iBAAiB,EAAE,MAAM,GAAG,IAAI,KAC7B,IAAI,CAAC;IACV,cAAc,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC7C,cAAc,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC7C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC9C,gBAAgB,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC9C,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,cAAc,CAAC,EAC7B,KAAU,EACV,kBAAkB,EAAE,WAAW,EAC/B,aAAa,EACb,aAAa,EACb,IAAY,EACZ,KAAc,EACd,QAAQ,EACR,cAAc,EACd,mBAAwC,EACxC,OAAO,EACP,QAAQ,EACR,OAAO,EACP,SAAS,EACT,eAAuB,EACvB,iBAAyB,EACzB,YAAmB,EACnB,cAAsB,EACtB,cAAsB,EACtB,cAAmB,EACnB,gBAA0B,EAC1B,gBAA0B,EAC1B,gBAAoB,EACpB,GAAG,KAAK,EACT,EAAE,mBAAmB,2CA+ZrB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as r, jsxs as j, Fragment as
|
|
2
|
-
import { BodyText as
|
|
1
|
+
import { jsx as r, jsxs as j, Fragment as ke } from "react/jsx-runtime";
|
|
2
|
+
import { BodyText as Le } from "../../typography/body_text/body_text.js";
|
|
3
3
|
import "../../typography/callout/callout.js";
|
|
4
4
|
import "../../typography/caption/caption.js";
|
|
5
5
|
import "../../typography/footnote/footnote.js";
|
|
@@ -7,89 +7,96 @@ import "../../typography/headline/headline.js";
|
|
|
7
7
|
import "../../typography/subheadline/subheadline.js";
|
|
8
8
|
import "../../typography/title/title.js";
|
|
9
9
|
import { VStack as q } from "../../stacks/v_stack.js";
|
|
10
|
-
import { ZStack as
|
|
11
|
-
import { clsx as
|
|
12
|
-
import
|
|
10
|
+
import { ZStack as ye } from "../../stacks/z_stack.js";
|
|
11
|
+
import { clsx as F } from "clsx";
|
|
12
|
+
import O, { Children as Se, isValidElement as Me, useState as a, useRef as H, useLayoutEffect as m } from "react";
|
|
13
13
|
import "../../utils/click_away_listener.js";
|
|
14
|
-
import { FocusRedirect as
|
|
14
|
+
import { FocusRedirect as Ie } from "../../utils/focus_redirect.js";
|
|
15
15
|
import "../../utils/scroll_away_listener.js";
|
|
16
16
|
import "../../utils/hooks/use_resize_observer.js";
|
|
17
17
|
import "../../utils/dnd/context.js";
|
|
18
18
|
import "../../draggable.module-BgelQsuJ.js";
|
|
19
|
-
import { SuggestionItem as
|
|
20
|
-
import { Option as
|
|
19
|
+
import { SuggestionItem as Ce } from "./suggestion_item.js";
|
|
20
|
+
import { Option as Z } from "../options/option.js";
|
|
21
21
|
import "../../actions/button/base_button/base_button.js";
|
|
22
22
|
import "../../actions/button/button_group/button_group.js";
|
|
23
23
|
import "../../actions/button/slim_button/slim_button.js";
|
|
24
|
-
import { Button as
|
|
24
|
+
import { Button as Re } from "../../actions/button/button/button.js";
|
|
25
25
|
import "../../actions/button/select_group/select_group.js";
|
|
26
26
|
import "../../actions/button/select_group/single_select_group.js";
|
|
27
27
|
import "../../actions/toggle/toggle.js";
|
|
28
|
-
import { Popper as
|
|
29
|
-
import '../../suggestion_list.css';const
|
|
30
|
-
function
|
|
31
|
-
value:
|
|
32
|
-
initialSearchValue:
|
|
33
|
-
scrollToValue:
|
|
28
|
+
import { Popper as ve } from "../../overlay/popper/legacy/popper.js";
|
|
29
|
+
import '../../suggestion_list.css';const _e = "_suggestion-list_711fb17", Ae = "_input_a0df060", B = { "suggestion-list": _e, input: Ae }, C = 50, De = 50;
|
|
30
|
+
function rt({
|
|
31
|
+
value: X = "",
|
|
32
|
+
initialSearchValue: K,
|
|
33
|
+
scrollToValue: w,
|
|
34
34
|
anchorElement: l,
|
|
35
|
-
open:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
open: R = !1,
|
|
36
|
+
width: z = "auto",
|
|
37
|
+
children: E,
|
|
38
|
+
onOptionSelect: b,
|
|
39
|
+
noSuggestionMessage: G = "-- No Matches --",
|
|
39
40
|
onClose: L,
|
|
40
|
-
onChange:
|
|
41
|
+
onChange: N,
|
|
41
42
|
onKeyUp: T,
|
|
42
43
|
onKeyDown: U,
|
|
43
|
-
trimCustomInput:
|
|
44
|
+
trimCustomInput: J = !1,
|
|
44
45
|
haveValueAsOption: P = !1,
|
|
45
|
-
restoreFocus:
|
|
46
|
-
|
|
46
|
+
restoreFocus: Q = !0,
|
|
47
|
+
verticalAnchor: Y = "top",
|
|
48
|
+
verticalOrigin: ee = "top",
|
|
49
|
+
verticalOffset: te = -4,
|
|
50
|
+
horizontalAnchor: se = "start",
|
|
51
|
+
horizontalOrigin: ne = "start",
|
|
52
|
+
horizontalOffset: oe = 0,
|
|
53
|
+
...ie
|
|
47
54
|
}) {
|
|
48
|
-
const
|
|
49
|
-
() =>
|
|
50
|
-
(e) =>
|
|
55
|
+
const x = O.useMemo(
|
|
56
|
+
() => Se.toArray(E).filter(
|
|
57
|
+
(e) => Me(e) && e.type === Z
|
|
51
58
|
),
|
|
52
|
-
[
|
|
53
|
-
), [y,
|
|
54
|
-
if (
|
|
55
|
-
const e =
|
|
59
|
+
[E]
|
|
60
|
+
), [y, re] = a(() => {
|
|
61
|
+
if (w != null) {
|
|
62
|
+
const e = x.findIndex((o) => o.props.value === w);
|
|
56
63
|
if (e !== -1)
|
|
57
64
|
return e;
|
|
58
65
|
}
|
|
59
66
|
return -1;
|
|
60
|
-
}),
|
|
67
|
+
}), v = H(""), _ = H(!1), [le, V] = a(C), [g, S] = a(y), [u, W] = a(X), c = H(null), [ce, ae] = a(x.length), [n, A] = a(
|
|
61
68
|
() => []
|
|
62
|
-
), [
|
|
63
|
-
function
|
|
69
|
+
), [ue, pe] = a(), [de, fe] = a();
|
|
70
|
+
function ge(e) {
|
|
64
71
|
if (!_.current)
|
|
65
72
|
return;
|
|
66
73
|
_.current = !1;
|
|
67
|
-
const o = e.key, t = e.currentTarget, s =
|
|
68
|
-
if (
|
|
74
|
+
const o = e.key, t = e.currentTarget, s = v.current = o;
|
|
75
|
+
if (v.current = "", s)
|
|
69
76
|
switch (o) {
|
|
70
77
|
case "Enter": {
|
|
71
|
-
if (n[
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
78
|
+
if (n[g] == null) {
|
|
79
|
+
const p = J ? t.value.trim() : t.value;
|
|
80
|
+
if (p === "")
|
|
74
81
|
return;
|
|
75
|
-
const k =
|
|
76
|
-
(
|
|
77
|
-
),
|
|
82
|
+
const k = p.toLocaleLowerCase(), h = x.find(
|
|
83
|
+
(D) => D.props.value.toLocaleLowerCase() === k || D.props.label != null && D.props.label.toLocaleLowerCase() === k
|
|
84
|
+
), d = h != null, $ = h?.props.label || p, f = h?.props.value || p;
|
|
78
85
|
requestAnimationFrame(() => {
|
|
79
|
-
|
|
86
|
+
b && b(
|
|
80
87
|
f,
|
|
81
88
|
$,
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
d,
|
|
90
|
+
h?.props.obfuscate ?? !1
|
|
84
91
|
);
|
|
85
92
|
});
|
|
86
93
|
break;
|
|
87
94
|
}
|
|
88
|
-
const i = n[
|
|
95
|
+
const i = n[g].props;
|
|
89
96
|
if (i.disabled)
|
|
90
97
|
break;
|
|
91
98
|
requestAnimationFrame(() => {
|
|
92
|
-
|
|
99
|
+
b && b(
|
|
93
100
|
i.value,
|
|
94
101
|
i.label,
|
|
95
102
|
!0,
|
|
@@ -105,11 +112,11 @@ function Ye({
|
|
|
105
112
|
}
|
|
106
113
|
T && T(e);
|
|
107
114
|
}
|
|
108
|
-
function
|
|
115
|
+
function he(e) {
|
|
109
116
|
const o = e.key;
|
|
110
|
-
switch (
|
|
117
|
+
switch (v.current = o, _.current = !0, o) {
|
|
111
118
|
case "ArrowDown": {
|
|
112
|
-
let t =
|
|
119
|
+
let t = g + 1;
|
|
113
120
|
for (; t < n.length && n[t]?.props.disabled; )
|
|
114
121
|
t++;
|
|
115
122
|
if (t === n.length) {
|
|
@@ -123,7 +130,7 @@ function Ye({
|
|
|
123
130
|
case "Tab": {
|
|
124
131
|
let t = 1;
|
|
125
132
|
e.shiftKey && (t = -1);
|
|
126
|
-
let s =
|
|
133
|
+
let s = g + t;
|
|
127
134
|
if (t > 0)
|
|
128
135
|
for (; s < n.length && n[s]?.props.disabled; )
|
|
129
136
|
s++;
|
|
@@ -143,7 +150,7 @@ function Ye({
|
|
|
143
150
|
break;
|
|
144
151
|
}
|
|
145
152
|
case "ArrowUp": {
|
|
146
|
-
let t =
|
|
153
|
+
let t = g - 1;
|
|
147
154
|
for (; t >= 0 && n[t]?.props.disabled; )
|
|
148
155
|
t--;
|
|
149
156
|
if (t === -1) {
|
|
@@ -157,124 +164,127 @@ function Ye({
|
|
|
157
164
|
}
|
|
158
165
|
U && U(e);
|
|
159
166
|
}
|
|
160
|
-
const M =
|
|
167
|
+
const M = O.useCallback(
|
|
161
168
|
function(o, t) {
|
|
162
|
-
const s =
|
|
163
|
-
const i = I.props,
|
|
164
|
-
return i.obfuscate ?? !1 ?
|
|
169
|
+
const s = x.filter((I) => {
|
|
170
|
+
const i = I.props, p = String(i.label).toLocaleLowerCase(), k = i.keywords?.map((f) => f.toLocaleLowerCase()) || [], h = String(i.value).toLocaleLowerCase(), d = o.toLocaleLowerCase();
|
|
171
|
+
return i.obfuscate ?? !1 ? p.includes(d) || k.some((f) => f.includes(d)) : p.includes(d) || k.some((f) => f.includes(d)) || h.includes(d);
|
|
165
172
|
});
|
|
166
173
|
return P && o.trim().length > 0 && !s.some((I) => I.props.value === o) && s.unshift(
|
|
167
|
-
/* @__PURE__ */ r(
|
|
168
|
-
),
|
|
174
|
+
/* @__PURE__ */ r(Z, { value: o, label: o, keywords: [o], children: o }, "value")
|
|
175
|
+
), ae(s.length), s.slice(0, t);
|
|
169
176
|
},
|
|
170
|
-
[
|
|
177
|
+
[x, P]
|
|
171
178
|
);
|
|
172
|
-
function
|
|
179
|
+
function me() {
|
|
173
180
|
const e = c.current;
|
|
174
181
|
e?.focus();
|
|
175
182
|
}
|
|
176
|
-
function
|
|
183
|
+
function we() {
|
|
177
184
|
const e = c.current;
|
|
178
185
|
e != null && L && L(e.value, e.selectionStart, e.selectionEnd);
|
|
179
186
|
}
|
|
180
|
-
function
|
|
187
|
+
function be(e) {
|
|
181
188
|
const o = e.currentTarget;
|
|
182
189
|
V(C), W(e.target.value);
|
|
183
190
|
const t = M(o.value, C);
|
|
184
|
-
|
|
191
|
+
A(t), N && N(e.target.value);
|
|
185
192
|
}
|
|
186
|
-
function
|
|
187
|
-
const e =
|
|
193
|
+
function xe() {
|
|
194
|
+
const e = le + De;
|
|
188
195
|
V(e);
|
|
189
|
-
const o = M(
|
|
190
|
-
|
|
196
|
+
const o = M(u, e);
|
|
197
|
+
A(o);
|
|
191
198
|
}
|
|
192
|
-
return
|
|
199
|
+
return m(() => {
|
|
193
200
|
const e = c.current;
|
|
194
|
-
|
|
195
|
-
}, [
|
|
201
|
+
R && (e != null && e.value.length > 0 ? e.select() : e?.focus());
|
|
202
|
+
}, [R]), m(() => {
|
|
196
203
|
if (l != null) {
|
|
197
204
|
const e = l.getBoundingClientRect();
|
|
198
|
-
|
|
205
|
+
pe(`${e.width}px`), fe(`${e.height}px`), c.current != null && l instanceof HTMLInputElement && (c.current.value = l.value, c.current.selectionStart = l.selectionStart, c.current.selectionEnd = l.selectionEnd);
|
|
199
206
|
}
|
|
200
|
-
}, [l]),
|
|
201
|
-
if (
|
|
207
|
+
}, [l]), m(() => {
|
|
208
|
+
if (w != null) {
|
|
202
209
|
const e = n.findIndex(
|
|
203
|
-
(o) => o.props.value ===
|
|
210
|
+
(o) => o.props.value === w
|
|
204
211
|
);
|
|
205
|
-
|
|
212
|
+
re(e);
|
|
206
213
|
}
|
|
207
|
-
}, [n,
|
|
208
|
-
S(
|
|
209
|
-
}, [
|
|
210
|
-
W(
|
|
211
|
-
}, [
|
|
212
|
-
const e = M(
|
|
213
|
-
|
|
214
|
-
}, [
|
|
215
|
-
|
|
214
|
+
}, [n, w]), m(() => {
|
|
215
|
+
S(u === "" ? y : -1);
|
|
216
|
+
}, [u, y]), m(() => {
|
|
217
|
+
W(K ?? "");
|
|
218
|
+
}, [K]), m(() => {
|
|
219
|
+
const e = M(u, C);
|
|
220
|
+
A(e);
|
|
221
|
+
}, [M, u]), /* @__PURE__ */ r(
|
|
222
|
+
ve,
|
|
216
223
|
{
|
|
217
|
-
open:
|
|
224
|
+
open: R,
|
|
218
225
|
anchorElement: l,
|
|
219
|
-
onClose:
|
|
220
|
-
verticalAnchor:
|
|
221
|
-
verticalOrigin:
|
|
222
|
-
verticalOffset:
|
|
223
|
-
|
|
226
|
+
onClose: we,
|
|
227
|
+
verticalAnchor: Y,
|
|
228
|
+
verticalOrigin: ee,
|
|
229
|
+
verticalOffset: te,
|
|
230
|
+
horizontalAnchor: se,
|
|
231
|
+
horizontalOrigin: ne,
|
|
232
|
+
horizontalOffset: oe,
|
|
233
|
+
restoreFocus: Q,
|
|
224
234
|
children: /* @__PURE__ */ j(
|
|
225
235
|
q,
|
|
226
236
|
{
|
|
227
|
-
minHeight: `calc(${
|
|
237
|
+
minHeight: `calc(${de}, 8px)`,
|
|
228
238
|
maxHeight: "300px",
|
|
229
|
-
minWidth:
|
|
230
|
-
width:
|
|
239
|
+
minWidth: ue,
|
|
240
|
+
width: z,
|
|
231
241
|
hAlign: "start",
|
|
232
|
-
className:
|
|
242
|
+
className: F(B["suggestion-list"], "tcn-suggestion-list"),
|
|
233
243
|
children: [
|
|
234
244
|
/* @__PURE__ */ r(
|
|
235
245
|
"input",
|
|
236
246
|
{
|
|
237
247
|
ref: c,
|
|
238
|
-
value:
|
|
239
|
-
onKeyUp:
|
|
240
|
-
onKeyDown:
|
|
241
|
-
onChange:
|
|
242
|
-
className:
|
|
243
|
-
...
|
|
248
|
+
value: u,
|
|
249
|
+
onKeyUp: ge,
|
|
250
|
+
onKeyDown: he,
|
|
251
|
+
onChange: be,
|
|
252
|
+
className: F(B.input, "tcn-suggestion-list-search-input"),
|
|
253
|
+
...ie
|
|
244
254
|
},
|
|
245
255
|
-1
|
|
246
256
|
),
|
|
247
257
|
/* @__PURE__ */ j(q, { children: [
|
|
248
258
|
n.map((e, o) => /* @__PURE__ */ r(
|
|
249
|
-
|
|
259
|
+
Ce,
|
|
250
260
|
{
|
|
251
261
|
option: e,
|
|
252
|
-
isSelected: o === y &&
|
|
253
|
-
isFocused: o ===
|
|
254
|
-
onClick:
|
|
262
|
+
isSelected: o === y && u !== "",
|
|
263
|
+
isFocused: o === g,
|
|
264
|
+
onClick: b
|
|
255
265
|
},
|
|
256
266
|
o
|
|
257
267
|
)),
|
|
258
|
-
|
|
259
|
-
|
|
268
|
+
ce > n.length && /* @__PURE__ */ r(ke, { children: /* @__PURE__ */ r(
|
|
269
|
+
Re,
|
|
260
270
|
{
|
|
261
271
|
marginBlock: "8px",
|
|
262
272
|
hierarchy: "tertiary",
|
|
263
|
-
onClick:
|
|
273
|
+
onClick: xe,
|
|
264
274
|
children: "Show More"
|
|
265
275
|
},
|
|
266
276
|
"show-more"
|
|
267
277
|
) })
|
|
268
278
|
] }),
|
|
269
279
|
n.length === 0 && /* @__PURE__ */ r(
|
|
270
|
-
|
|
280
|
+
ye,
|
|
271
281
|
{
|
|
272
282
|
padding: "8px",
|
|
273
|
-
className:
|
|
274
|
-
children: /* @__PURE__ */ r(
|
|
283
|
+
className: F(B["no-results"], "tcn-suggestion-list-no-results"),
|
|
284
|
+
children: /* @__PURE__ */ r(Le, { children: G })
|
|
275
285
|
}
|
|
276
286
|
),
|
|
277
|
-
/* @__PURE__ */ r(
|
|
287
|
+
/* @__PURE__ */ r(Ie, { onRedirect: me }, n.length + 1)
|
|
278
288
|
]
|
|
279
289
|
}
|
|
280
290
|
)
|
|
@@ -282,6 +292,6 @@ function Ye({
|
|
|
282
292
|
);
|
|
283
293
|
}
|
|
284
294
|
export {
|
|
285
|
-
|
|
295
|
+
rt as SuggestionList
|
|
286
296
|
};
|
|
287
297
|
//# sourceMappingURL=suggestion_list.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suggestion_list.js","sources":["../../../src/inputs/suggestions/suggestion_list.tsx"],"sourcesContent":["import { BodyText } from '../../typography/index.js';\nimport { VStack } from '../../stacks/v_stack.js';\nimport { ZStack } from '../../stacks/z_stack.js';\nimport { clsx } from 'clsx';\nimport React, { useLayoutEffect, Children, isValidElement } from 'react';\nimport { useRef, useState } from 'react';\nimport { FocusRedirect } from '../../utils/index.js';\nimport { SuggestionItem } from './suggestion_item.js';\nimport { OptionProps, Option } from '../options/option.js';\nimport styles from './suggestion_list.module.css';\n\nimport { Button } from '../../actions/index.js';\nimport { Popper } from '../../overlay/popper/legacy/popper.js';\n\nconst MAX_RESULTS = 50;\nconst BATCH_SIZE = 50;\n\nexport interface SuggestionListProps\n extends Omit<React.HTMLAttributes<HTMLInputElement>, 'onChange'> {\n value?: string;\n initialSearchValue?: string;\n scrollToValue?: string;\n anchorElement: HTMLElement | null;\n open?: boolean;\n children?: React.ReactNode;\n onChange?: (value: string) => void;\n onOptionSelect?: (\n value: string,\n label: string | undefined,\n isSuggestion: boolean,\n obfuscate: boolean\n ) => void;\n noSuggestionMessage?: React.ReactNode;\n trimCustomInput?: boolean;\n haveValueAsOption?: boolean;\n restoreFocus?: boolean;\n onClose?: (\n inputValue: string,\n cursorStartPosition: number | null,\n cursorEndPosition: number | null\n ) => void;\n}\n\nexport function SuggestionList({\n value = '',\n initialSearchValue: searchValue,\n scrollToValue,\n anchorElement,\n open = false,\n children,\n onOptionSelect,\n noSuggestionMessage = '-- No Matches --',\n onClose,\n onChange,\n onKeyUp,\n onKeyDown,\n trimCustomInput = false,\n haveValueAsOption = false,\n restoreFocus = true,\n ...props\n}: SuggestionListProps) {\n // Extract valid Option components from children\n const suggestions = React.useMemo(\n () =>\n Children.toArray(children).filter(\n (child): child is React.ReactElement<OptionProps> =>\n isValidElement(child) && child.type === Option\n ),\n [children]\n );\n\n const [selectedIndex, setSelectedIndex] = useState(() => {\n if (scrollToValue != null) {\n const index = suggestions.findIndex(option => option.props.value === scrollToValue);\n if (index !== -1) {\n return index;\n }\n }\n return -1;\n });\n\n const keyPressedDownRef = useRef('');\n const KeyDownRegistered = useRef(false);\n const [maxResults, setMaxResults] = useState(MAX_RESULTS);\n const [focusedIndex, setFocusedIndex] = useState(selectedIndex);\n const [internalValue, setInternalValue] = useState(value);\n const internalInputRef = useRef<HTMLInputElement | null>(null);\n const [totalMatchedLength, setTotalMatchedLength] = useState(suggestions.length);\n const [matchedOptions, setMatchedOptions] = useState<React.ReactElement<OptionProps>[]>(\n () => []\n );\n const [suggestionsWidth, setSuggestionsWidth] = useState<string | undefined>();\n const [suggestionsHeight, setSuggestionsHeight] = useState<string | undefined>();\n\n function handleKeyUp(event: React.KeyboardEvent<HTMLInputElement>) {\n if (!KeyDownRegistered.current) {\n return;\n }\n KeyDownRegistered.current = false;\n\n const key = event.key;\n const input = event.currentTarget;\n\n const isSameKey = (keyPressedDownRef.current = key);\n keyPressedDownRef.current = '';\n\n // Enter and Escape remove the popover, so we want to handle this on keyup.\n // This prevents from another element from getting the key events.\n if (isSameKey) {\n switch (key) {\n case 'Enter': {\n if (matchedOptions[focusedIndex] == null) {\n const value = trimCustomInput ? input.value.trim() : input.value;\n\n if (value === '') {\n return;\n }\n\n const lowercaseValue = value.toLocaleLowerCase();\n const option = suggestions.find(\n option =>\n option.props.value.toLocaleLowerCase() === lowercaseValue ||\n (option.props.label != null &&\n option.props.label.toLocaleLowerCase() === lowercaseValue)\n );\n\n const isSuggestion = option != null;\n const label = option?.props.label || value;\n const optionValue = option?.props.value || value;\n\n requestAnimationFrame(() => {\n onOptionSelect &&\n onOptionSelect(\n optionValue,\n label,\n isSuggestion,\n option?.props.obfuscate ?? false\n );\n });\n\n break;\n }\n const selectedOption = matchedOptions[focusedIndex];\n const optionProps = selectedOption.props;\n\n // Don't select disabled options\n if (optionProps.disabled) {\n break;\n }\n\n requestAnimationFrame(() => {\n onOptionSelect &&\n onOptionSelect(\n optionProps.value,\n optionProps.label,\n true,\n optionProps.obfuscate ?? false\n );\n });\n break;\n }\n case 'Escape': {\n onClose && onClose(input.value, input.selectionStart, input.selectionEnd);\n break;\n }\n }\n }\n\n onKeyUp && onKeyUp(event);\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {\n const key = event.key;\n keyPressedDownRef.current = key;\n KeyDownRegistered.current = true;\n // We handle these key events on keydown to be responsive navigation.\n switch (key) {\n case 'ArrowDown': {\n let newIndex = focusedIndex + 1;\n\n // Skip disabled options\n while (\n newIndex < matchedOptions.length &&\n matchedOptions[newIndex]?.props.disabled\n ) {\n newIndex++;\n }\n\n if (newIndex === matchedOptions.length) {\n // Wrap around to first non-disabled option\n newIndex = 0;\n while (\n newIndex < matchedOptions.length &&\n matchedOptions[newIndex]?.props.disabled\n ) {\n newIndex++;\n }\n // If all options are disabled, stay at -1\n if (newIndex === matchedOptions.length) {\n newIndex = -1;\n }\n }\n\n setFocusedIndex(newIndex);\n event.preventDefault();\n break;\n }\n case 'Tab': {\n let step = 1;\n if (event.shiftKey) {\n step = -1;\n }\n let newIndex = focusedIndex + step;\n // Skip disabled options\n if (step > 0) {\n while (\n newIndex < matchedOptions.length &&\n matchedOptions[newIndex]?.props.disabled\n ) {\n newIndex++;\n }\n } else {\n while (newIndex >= 0 && matchedOptions[newIndex]?.props.disabled) {\n newIndex--;\n }\n }\n\n if (newIndex === matchedOptions.length) {\n // Wrap around to first non-disabled option\n newIndex = 0;\n while (\n newIndex < matchedOptions.length &&\n matchedOptions[newIndex]?.props.disabled\n ) {\n newIndex++;\n }\n // If all options are disabled, stay at -1\n if (newIndex === matchedOptions.length) {\n newIndex = -1;\n }\n } else if (newIndex <= -1) {\n // Wrap around to last non-disabled option\n newIndex = matchedOptions.length - 1;\n while (newIndex >= 0 && matchedOptions[newIndex]?.props.disabled) {\n newIndex--;\n }\n // If all options are disabled, stay at -1\n if (newIndex === -1) {\n newIndex = -1;\n }\n }\n\n setFocusedIndex(newIndex);\n event.preventDefault();\n break;\n }\n case 'ArrowUp': {\n let newIndex = focusedIndex - 1;\n\n // Skip disabled options\n while (newIndex >= 0 && matchedOptions[newIndex]?.props.disabled) {\n newIndex--;\n }\n\n if (newIndex === -1) {\n // Wrap around to last non-disabled option\n newIndex = matchedOptions.length - 1;\n while (newIndex >= 0 && matchedOptions[newIndex]?.props.disabled) {\n newIndex--;\n }\n // If all options are disabled, stay at -1\n if (newIndex === -1) {\n newIndex = -1;\n }\n }\n\n setFocusedIndex(newIndex);\n event.preventDefault();\n break;\n }\n }\n onKeyDown && onKeyDown(event);\n }\n\n const getMatchedOptions = React.useCallback(\n function getMatchedOptions(value: string, maxResults: number) {\n const results = suggestions.filter(option => {\n const props = option.props;\n const label = String(props.label).toLocaleLowerCase();\n const keywords = props.keywords?.map(k => k.toLocaleLowerCase()) || [];\n const optionValue = String(props.value).toLocaleLowerCase();\n const searchValue = value.toLocaleLowerCase();\n const obfuscate = props.obfuscate ?? false;\n\n // Obfuscated options can only be searched by label or keywords, not by value\n if (obfuscate) {\n return (\n label.includes(searchValue) || keywords.some(k => k.includes(searchValue))\n );\n }\n\n return (\n label.includes(searchValue) ||\n keywords.some(k => k.includes(searchValue)) ||\n optionValue.includes(searchValue)\n );\n });\n\n if (\n haveValueAsOption &&\n value.trim().length > 0 &&\n !results.some(r => r.props.value === value)\n ) {\n results.unshift(\n <Option key=\"value\" value={value} label={value} keywords={[value]}>\n {value}\n </Option>\n );\n }\n\n setTotalMatchedLength(results.length);\n return results.slice(0, maxResults);\n },\n [suggestions, haveValueAsOption]\n );\n\n function focusInput() {\n const input = internalInputRef.current;\n if (input != null) {\n input.focus();\n }\n }\n\n function handleUseClose() {\n const input = internalInputRef.current;\n if (input != null) {\n onClose && onClose(input.value, input.selectionStart, input.selectionEnd);\n }\n }\n\n function handleChange(event: React.ChangeEvent<HTMLInputElement>) {\n const input = event.currentTarget;\n\n setMaxResults(MAX_RESULTS);\n setInternalValue(event.target.value);\n\n const newMatches = getMatchedOptions(input.value, MAX_RESULTS);\n setMatchedOptions(newMatches);\n\n onChange && onChange(event.target.value);\n }\n\n function handleShowMore() {\n const newMaxResults = maxResults + BATCH_SIZE;\n setMaxResults(newMaxResults);\n const newMatches = getMatchedOptions(internalValue, newMaxResults);\n setMatchedOptions(newMatches);\n }\n\n useLayoutEffect(() => {\n const input = internalInputRef.current;\n\n if (!open) {\n return;\n }\n\n if (input != null && input.value.length > 0) {\n input.select();\n } else if (input != null) {\n input.focus();\n }\n }, [open]);\n\n useLayoutEffect(() => {\n if (anchorElement != null) {\n const rect = anchorElement.getBoundingClientRect();\n setSuggestionsWidth(`${rect.width}px`);\n setSuggestionsHeight(`${rect.height}px`);\n\n if (internalInputRef.current != null && anchorElement instanceof HTMLInputElement) {\n internalInputRef.current.value = anchorElement.value;\n internalInputRef.current.selectionStart = anchorElement.selectionStart;\n internalInputRef.current.selectionEnd = anchorElement.selectionEnd;\n }\n }\n }, [anchorElement]);\n\n useLayoutEffect(() => {\n if (scrollToValue != null) {\n const index = matchedOptions.findIndex(\n option => option.props.value === scrollToValue\n );\n setSelectedIndex(index);\n }\n }, [matchedOptions, scrollToValue]);\n\n useLayoutEffect(() => {\n setFocusedIndex(internalValue === '' ? selectedIndex : -1);\n }, [internalValue, selectedIndex]);\n\n useLayoutEffect(() => {\n setInternalValue(searchValue ?? '');\n }, [searchValue]);\n\n useLayoutEffect(() => {\n const newMatches = getMatchedOptions(value, MAX_RESULTS);\n setMatchedOptions(newMatches);\n }, [value, getMatchedOptions]);\n\n return (\n <Popper\n open={open}\n anchorElement={anchorElement}\n onClose={handleUseClose}\n verticalAnchor=\"top\"\n verticalOrigin=\"top\"\n verticalOffset={-4}\n restoreFocus={restoreFocus}\n >\n <VStack\n minHeight={`calc(${suggestionsHeight}, 8px)`}\n maxHeight=\"300px\"\n minWidth={suggestionsWidth}\n width=\"auto\"\n hAlign=\"start\"\n className={clsx(styles['suggestion-list'], 'tcn-suggestion-list')}\n >\n <input\n ref={internalInputRef}\n key={-1}\n value={internalValue}\n onKeyUp={handleKeyUp}\n onKeyDown={handleKeyDown}\n onChange={handleChange}\n className={clsx(styles.input, 'tcn-suggestion-list-search-input')}\n {...props}\n />\n <VStack>\n {matchedOptions.map((option, index) => (\n <SuggestionItem\n key={index}\n option={option}\n isSelected={index === selectedIndex && internalValue !== ''}\n isFocused={index === focusedIndex}\n onClick={onOptionSelect}\n />\n ))}\n {totalMatchedLength > matchedOptions.length && (\n <>\n <Button\n key=\"show-more\"\n marginBlock=\"8px\"\n hierarchy=\"tertiary\"\n onClick={handleShowMore}\n >\n Show More\n </Button>\n </>\n )}\n </VStack>\n {matchedOptions.length === 0 && (\n <ZStack\n padding=\"8px\"\n className={clsx(styles['no-results'], 'tcn-suggestion-list-no-results')}\n >\n <BodyText>{noSuggestionMessage}</BodyText>\n </ZStack>\n )}\n <FocusRedirect key={matchedOptions.length + 1} onRedirect={focusInput} />\n </VStack>\n </Popper>\n );\n}\n"],"names":["MAX_RESULTS","BATCH_SIZE","SuggestionList","value","searchValue","scrollToValue","anchorElement","open","children","onOptionSelect","noSuggestionMessage","onClose","onChange","onKeyUp","onKeyDown","trimCustomInput","haveValueAsOption","restoreFocus","props","suggestions","React","Children","child","isValidElement","Option","selectedIndex","setSelectedIndex","useState","index","option","keyPressedDownRef","useRef","KeyDownRegistered","maxResults","setMaxResults","focusedIndex","setFocusedIndex","internalValue","setInternalValue","internalInputRef","totalMatchedLength","setTotalMatchedLength","matchedOptions","setMatchedOptions","suggestionsWidth","setSuggestionsWidth","suggestionsHeight","setSuggestionsHeight","handleKeyUp","event","key","input","isSameKey","lowercaseValue","isSuggestion","label","optionValue","optionProps","handleKeyDown","newIndex","step","getMatchedOptions","results","keywords","k","r","jsx","focusInput","handleUseClose","handleChange","newMatches","handleShowMore","newMaxResults","useLayoutEffect","rect","Popper","jsxs","VStack","clsx","styles","SuggestionItem","Fragment","Button","ZStack","BodyText","FocusRedirect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;wGAcMA,IAAc,IACdC,KAAa;AA4BZ,SAASC,GAAe;AAAA,EAC7B,OAAAC,IAAQ;AAAA,EACR,oBAAoBC;AAAA,EACpB,eAAAC;AAAA,EACA,eAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,UAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,qBAAAC,IAAsB;AAAA,EACtB,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,WAAAC;AAAA,EACA,iBAAAC,IAAkB;AAAA,EAClB,mBAAAC,IAAoB;AAAA,EACpB,cAAAC,IAAe;AAAA,EACf,GAAGC;AACL,GAAwB;AAEtB,QAAMC,IAAcC,EAAM;AAAA,IACxB,MACEC,GAAS,QAAQb,CAAQ,EAAE;AAAA,MACzB,CAACc,MACCC,GAAeD,CAAK,KAAKA,EAAM,SAASE;AAAA,IAAA;AAAA,IAE9C,CAAChB,CAAQ;AAAA,EAAA,GAGL,CAACiB,GAAeC,CAAgB,IAAIC,EAAS,MAAM;AACvD,QAAItB,KAAiB,MAAM;AACzB,YAAMuB,IAAQT,EAAY,UAAU,OAAUU,EAAO,MAAM,UAAUxB,CAAa;AAClF,UAAIuB,MAAU;AACZ,eAAOA;AAAA,IAEX;AACA,WAAO;AAAA,EACT,CAAC,GAEKE,IAAoBC,EAAO,EAAE,GAC7BC,IAAoBD,EAAO,EAAK,GAChC,CAACE,IAAYC,CAAa,IAAIP,EAAS3B,CAAW,GAClD,CAACmC,GAAcC,CAAe,IAAIT,EAASF,CAAa,GACxD,CAACY,GAAeC,CAAgB,IAAIX,EAASxB,CAAK,GAClDoC,IAAmBR,EAAgC,IAAI,GACvD,CAACS,IAAoBC,EAAqB,I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list.tsx"],"sourcesContent":["import { BodyText } from '../../typography/index.js';\nimport { VStack } from '../../stacks/v_stack.js';\nimport { ZStack } from '../../stacks/z_stack.js';\nimport { clsx } from 'clsx';\nimport React, { useLayoutEffect, Children, isValidElement } from 'react';\nimport { useRef, useState } from 'react';\nimport { FocusRedirect } from '../../utils/index.js';\nimport { SuggestionItem } from './suggestion_item.js';\nimport { OptionProps, Option } from '../options/option.js';\nimport styles from './suggestion_list.module.css';\n\nimport { Button } from '../../actions/index.js';\nimport { Popper } from '../../overlay/popper/legacy/popper.js';\n\nconst MAX_RESULTS = 50;\nconst BATCH_SIZE = 50;\n\nexport interface SuggestionListProps\n extends Omit<React.HTMLAttributes<HTMLInputElement>, 'onChange'> {\n value?: string;\n initialSearchValue?: string;\n scrollToValue?: string;\n anchorElement: HTMLElement | null;\n open?: boolean;\n children?: React.ReactNode;\n onChange?: (value: string) => void;\n width?: string;\n onOptionSelect?: (\n value: string,\n label: string | undefined,\n isSuggestion: boolean,\n obfuscate: boolean\n ) => void;\n noSuggestionMessage?: React.ReactNode;\n trimCustomInput?: boolean;\n haveValueAsOption?: boolean;\n restoreFocus?: boolean;\n onClose?: (\n inputValue: string,\n cursorStartPosition: number | null,\n cursorEndPosition: number | null\n ) => void;\n verticalAnchor?: 'top' | 'center' | 'bottom';\n verticalOrigin?: 'top' | 'center' | 'bottom';\n verticalOffset?: number;\n horizontalAnchor?: 'start' | 'center' | 'end';\n horizontalOrigin?: 'start' | 'center' | 'end';\n horizontalOffset?: number;\n}\n\nexport function SuggestionList({\n value = '',\n initialSearchValue: searchValue,\n scrollToValue,\n anchorElement,\n open = false,\n width = 'auto',\n children,\n onOptionSelect,\n noSuggestionMessage = '-- No Matches --',\n onClose,\n onChange,\n onKeyUp,\n onKeyDown,\n trimCustomInput = false,\n haveValueAsOption = false,\n restoreFocus = true,\n verticalAnchor = 'top',\n verticalOrigin = 'top',\n verticalOffset = -4,\n horizontalAnchor = 'start',\n horizontalOrigin = 'start',\n horizontalOffset = 0,\n ...props\n}: SuggestionListProps) {\n // Extract valid Option components from children\n const suggestions = React.useMemo(\n () =>\n Children.toArray(children).filter(\n (child): child is React.ReactElement<OptionProps> =>\n isValidElement(child) && child.type === Option\n ),\n [children]\n );\n\n const [selectedIndex, setSelectedIndex] = useState(() => {\n if (scrollToValue != null) {\n const index = suggestions.findIndex(option => option.props.value === scrollToValue);\n if (index !== -1) {\n return index;\n }\n }\n return -1;\n });\n\n const keyPressedDownRef = useRef('');\n const KeyDownRegistered = useRef(false);\n const [maxResults, setMaxResults] = useState(MAX_RESULTS);\n const [focusedIndex, setFocusedIndex] = useState(selectedIndex);\n const [internalValue, setInternalValue] = useState(value);\n const internalInputRef = useRef<HTMLInputElement | null>(null);\n const [totalMatchedLength, setTotalMatchedLength] = useState(suggestions.length);\n const [matchedOptions, setMatchedOptions] = useState<React.ReactElement<OptionProps>[]>(\n () => []\n );\n const [suggestionsWidth, setSuggestionsWidth] = useState<string | undefined>();\n const [suggestionsHeight, setSuggestionsHeight] = useState<string | undefined>();\n\n function handleKeyUp(event: React.KeyboardEvent<HTMLInputElement>) {\n if (!KeyDownRegistered.current) {\n return;\n }\n KeyDownRegistered.current = false;\n\n const key = event.key;\n const input = event.currentTarget;\n\n const isSameKey = (keyPressedDownRef.current = key);\n keyPressedDownRef.current = '';\n\n // Enter and Escape remove the popover, so we want to handle this on keyup.\n // This prevents from another element from getting the key events.\n if (isSameKey) {\n switch (key) {\n case 'Enter': {\n if (matchedOptions[focusedIndex] == null) {\n const value = trimCustomInput ? input.value.trim() : input.value;\n\n if (value === '') {\n return;\n }\n\n const lowercaseValue = value.toLocaleLowerCase();\n const option = suggestions.find(\n option =>\n option.props.value.toLocaleLowerCase() === lowercaseValue ||\n (option.props.label != null &&\n option.props.label.toLocaleLowerCase() === lowercaseValue)\n );\n\n const isSuggestion = option != null;\n const label = option?.props.label || value;\n const optionValue = option?.props.value || value;\n\n requestAnimationFrame(() => {\n onOptionSelect &&\n onOptionSelect(\n optionValue,\n label,\n isSuggestion,\n option?.props.obfuscate ?? false\n );\n });\n\n break;\n }\n const selectedOption = matchedOptions[focusedIndex];\n const optionProps = selectedOption.props;\n\n // Don't select disabled options\n if (optionProps.disabled) {\n break;\n }\n\n requestAnimationFrame(() => {\n onOptionSelect &&\n onOptionSelect(\n optionProps.value,\n optionProps.label,\n true,\n optionProps.obfuscate ?? false\n );\n });\n break;\n }\n case 'Escape': {\n onClose && onClose(input.value, input.selectionStart, input.selectionEnd);\n break;\n }\n }\n }\n\n onKeyUp && onKeyUp(event);\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {\n const key = event.key;\n keyPressedDownRef.current = key;\n KeyDownRegistered.current = true;\n // We handle these key events on keydown to be responsive navigation.\n switch (key) {\n case 'ArrowDown': {\n let newIndex = focusedIndex + 1;\n\n // Skip disabled options\n while (\n newIndex < matchedOptions.length &&\n matchedOptions[newIndex]?.props.disabled\n ) {\n newIndex++;\n }\n\n if (newIndex === matchedOptions.length) {\n // Wrap around to first non-disabled option\n newIndex = 0;\n while (\n newIndex < matchedOptions.length &&\n matchedOptions[newIndex]?.props.disabled\n ) {\n newIndex++;\n }\n // If all options are disabled, stay at -1\n if (newIndex === matchedOptions.length) {\n newIndex = -1;\n }\n }\n\n setFocusedIndex(newIndex);\n event.preventDefault();\n break;\n }\n case 'Tab': {\n let step = 1;\n if (event.shiftKey) {\n step = -1;\n }\n let newIndex = focusedIndex + step;\n // Skip disabled options\n if (step > 0) {\n while (\n newIndex < matchedOptions.length &&\n matchedOptions[newIndex]?.props.disabled\n ) {\n newIndex++;\n }\n } else {\n while (newIndex >= 0 && matchedOptions[newIndex]?.props.disabled) {\n newIndex--;\n }\n }\n\n if (newIndex === matchedOptions.length) {\n // Wrap around to first non-disabled option\n newIndex = 0;\n while (\n newIndex < matchedOptions.length &&\n matchedOptions[newIndex]?.props.disabled\n ) {\n newIndex++;\n }\n // If all options are disabled, stay at -1\n if (newIndex === matchedOptions.length) {\n newIndex = -1;\n }\n } else if (newIndex <= -1) {\n // Wrap around to last non-disabled option\n newIndex = matchedOptions.length - 1;\n while (newIndex >= 0 && matchedOptions[newIndex]?.props.disabled) {\n newIndex--;\n }\n // If all options are disabled, stay at -1\n if (newIndex === -1) {\n newIndex = -1;\n }\n }\n\n setFocusedIndex(newIndex);\n event.preventDefault();\n break;\n }\n case 'ArrowUp': {\n let newIndex = focusedIndex - 1;\n\n // Skip disabled options\n while (newIndex >= 0 && matchedOptions[newIndex]?.props.disabled) {\n newIndex--;\n }\n\n if (newIndex === -1) {\n // Wrap around to last non-disabled option\n newIndex = matchedOptions.length - 1;\n while (newIndex >= 0 && matchedOptions[newIndex]?.props.disabled) {\n newIndex--;\n }\n // If all options are disabled, stay at -1\n if (newIndex === -1) {\n newIndex = -1;\n }\n }\n\n setFocusedIndex(newIndex);\n event.preventDefault();\n break;\n }\n }\n onKeyDown && onKeyDown(event);\n }\n\n const getMatchedOptions = React.useCallback(\n function getMatchedOptions(value: string, maxResults: number) {\n const results = suggestions.filter(option => {\n const props = option.props;\n const label = String(props.label).toLocaleLowerCase();\n const keywords = props.keywords?.map(k => k.toLocaleLowerCase()) || [];\n const optionValue = String(props.value).toLocaleLowerCase();\n const searchValue = value.toLocaleLowerCase();\n const obfuscate = props.obfuscate ?? false;\n\n // Obfuscated options can only be searched by label or keywords, not by value\n if (obfuscate) {\n return (\n label.includes(searchValue) || keywords.some(k => k.includes(searchValue))\n );\n }\n\n return (\n label.includes(searchValue) ||\n keywords.some(k => k.includes(searchValue)) ||\n optionValue.includes(searchValue)\n );\n });\n\n if (\n haveValueAsOption &&\n value.trim().length > 0 &&\n !results.some(r => r.props.value === value)\n ) {\n results.unshift(\n <Option key=\"value\" value={value} label={value} keywords={[value]}>\n {value}\n </Option>\n );\n }\n\n setTotalMatchedLength(results.length);\n return results.slice(0, maxResults);\n },\n [suggestions, haveValueAsOption]\n );\n\n function focusInput() {\n const input = internalInputRef.current;\n if (input != null) {\n input.focus();\n }\n }\n\n function handleUseClose() {\n const input = internalInputRef.current;\n if (input != null) {\n onClose && onClose(input.value, input.selectionStart, input.selectionEnd);\n }\n }\n\n function handleChange(event: React.ChangeEvent<HTMLInputElement>) {\n const input = event.currentTarget;\n\n setMaxResults(MAX_RESULTS);\n setInternalValue(event.target.value);\n\n const newMatches = getMatchedOptions(input.value, MAX_RESULTS);\n setMatchedOptions(newMatches);\n\n onChange && onChange(event.target.value);\n }\n\n function handleShowMore() {\n const newMaxResults = maxResults + BATCH_SIZE;\n setMaxResults(newMaxResults);\n const newMatches = getMatchedOptions(internalValue, newMaxResults);\n setMatchedOptions(newMatches);\n }\n\n useLayoutEffect(() => {\n const input = internalInputRef.current;\n\n if (!open) {\n return;\n }\n\n if (input != null && input.value.length > 0) {\n input.select();\n } else if (input != null) {\n input.focus();\n }\n }, [open]);\n\n useLayoutEffect(() => {\n if (anchorElement != null) {\n const rect = anchorElement.getBoundingClientRect();\n setSuggestionsWidth(`${rect.width}px`);\n setSuggestionsHeight(`${rect.height}px`);\n\n if (internalInputRef.current != null && anchorElement instanceof HTMLInputElement) {\n internalInputRef.current.value = anchorElement.value;\n internalInputRef.current.selectionStart = anchorElement.selectionStart;\n internalInputRef.current.selectionEnd = anchorElement.selectionEnd;\n }\n }\n }, [anchorElement]);\n\n useLayoutEffect(() => {\n if (scrollToValue != null) {\n const index = matchedOptions.findIndex(\n option => option.props.value === scrollToValue\n );\n setSelectedIndex(index);\n }\n }, [matchedOptions, scrollToValue]);\n\n useLayoutEffect(() => {\n setFocusedIndex(internalValue === '' ? selectedIndex : -1);\n }, [internalValue, selectedIndex]);\n\n useLayoutEffect(() => {\n setInternalValue(searchValue ?? '');\n }, [searchValue]);\n\n useLayoutEffect(() => {\n const newMatches = getMatchedOptions(internalValue, MAX_RESULTS);\n setMatchedOptions(newMatches);\n }, [getMatchedOptions, internalValue]);\n\n return (\n <Popper\n open={open}\n anchorElement={anchorElement}\n onClose={handleUseClose}\n verticalAnchor={verticalAnchor}\n verticalOrigin={verticalOrigin}\n verticalOffset={verticalOffset}\n horizontalAnchor={horizontalAnchor}\n horizontalOrigin={horizontalOrigin}\n horizontalOffset={horizontalOffset}\n restoreFocus={restoreFocus}\n >\n <VStack\n minHeight={`calc(${suggestionsHeight}, 8px)`}\n maxHeight=\"300px\"\n minWidth={suggestionsWidth}\n width={width}\n hAlign=\"start\"\n className={clsx(styles['suggestion-list'], 'tcn-suggestion-list')}\n >\n <input\n ref={internalInputRef}\n key={-1}\n value={internalValue}\n onKeyUp={handleKeyUp}\n onKeyDown={handleKeyDown}\n onChange={handleChange}\n className={clsx(styles.input, 'tcn-suggestion-list-search-input')}\n {...props}\n />\n <VStack>\n {matchedOptions.map((option, index) => (\n <SuggestionItem\n key={index}\n option={option}\n isSelected={index === selectedIndex && internalValue !== ''}\n isFocused={index === focusedIndex}\n onClick={onOptionSelect}\n />\n ))}\n {totalMatchedLength > matchedOptions.length && (\n <>\n <Button\n key=\"show-more\"\n marginBlock=\"8px\"\n hierarchy=\"tertiary\"\n onClick={handleShowMore}\n >\n Show More\n </Button>\n </>\n )}\n </VStack>\n {matchedOptions.length === 0 && (\n <ZStack\n padding=\"8px\"\n className={clsx(styles['no-results'], 'tcn-suggestion-list-no-results')}\n >\n <BodyText>{noSuggestionMessage}</BodyText>\n </ZStack>\n )}\n <FocusRedirect key={matchedOptions.length + 1} onRedirect={focusInput} />\n </VStack>\n </Popper>\n );\n}\n"],"names":["MAX_RESULTS","BATCH_SIZE","SuggestionList","value","searchValue","scrollToValue","anchorElement","open","width","children","onOptionSelect","noSuggestionMessage","onClose","onChange","onKeyUp","onKeyDown","trimCustomInput","haveValueAsOption","restoreFocus","verticalAnchor","verticalOrigin","verticalOffset","horizontalAnchor","horizontalOrigin","horizontalOffset","props","suggestions","React","Children","child","isValidElement","Option","selectedIndex","setSelectedIndex","useState","index","option","keyPressedDownRef","useRef","KeyDownRegistered","maxResults","setMaxResults","focusedIndex","setFocusedIndex","internalValue","setInternalValue","internalInputRef","totalMatchedLength","setTotalMatchedLength","matchedOptions","setMatchedOptions","suggestionsWidth","setSuggestionsWidth","suggestionsHeight","setSuggestionsHeight","handleKeyUp","event","key","input","isSameKey","lowercaseValue","isSuggestion","label","optionValue","optionProps","handleKeyDown","newIndex","step","getMatchedOptions","results","keywords","k","r","jsx","focusInput","handleUseClose","handleChange","newMatches","handleShowMore","newMaxResults","useLayoutEffect","rect","Popper","jsxs","VStack","clsx","styles","SuggestionItem","Fragment","Button","ZStack","BodyText","FocusRedirect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;wGAcMA,IAAc,IACdC,KAAa;AAmCZ,SAASC,GAAe;AAAA,EAC7B,OAAAC,IAAQ;AAAA,EACR,oBAAoBC;AAAA,EACpB,eAAAC;AAAA,EACA,eAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,OAAAC,IAAQ;AAAA,EACR,UAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,qBAAAC,IAAsB;AAAA,EACtB,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,WAAAC;AAAA,EACA,iBAAAC,IAAkB;AAAA,EAClB,mBAAAC,IAAoB;AAAA,EACpB,cAAAC,IAAe;AAAA,EACf,gBAAAC,IAAiB;AAAA,EACjB,gBAAAC,KAAiB;AAAA,EACjB,gBAAAC,KAAiB;AAAA,EACjB,kBAAAC,KAAmB;AAAA,EACnB,kBAAAC,KAAmB;AAAA,EACnB,kBAAAC,KAAmB;AAAA,EACnB,GAAGC;AACL,GAAwB;AAEtB,QAAMC,IAAcC,EAAM;AAAA,IACxB,MACEC,GAAS,QAAQnB,CAAQ,EAAE;AAAA,MACzB,CAACoB,MACCC,GAAeD,CAAK,KAAKA,EAAM,SAASE;AAAA,IAAA;AAAA,IAE9C,CAACtB,CAAQ;AAAA,EAAA,GAGL,CAACuB,GAAeC,EAAgB,IAAIC,EAAS,MAAM;AACvD,QAAI7B,KAAiB,MAAM;AACzB,YAAM8B,IAAQT,EAAY,UAA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;AAAA,YACC7B,EAAe,WAAW,KACzB,gBAAAwB;AAAA,cAACiB;AAAA,cAAA;AAAA,gBACC,SAAQ;AAAA,gBACR,WAAWL,EAAKC,EAAO,YAAY,GAAG,gCAAgC;AAAA,gBAEtE,UAAA,gBAAAb,EAACkB,MAAU,UAAAhF,EAAA,CAAoB;AAAA,cAAA;AAAA,YAAA;AAAA,8BAGlCiF,IAAA,EAA8C,YAAYlB,GAAA,GAAvCzB,EAAe,SAAS,CAA2B;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACzE;AAAA,EAAA;AAGN;"}
|
package/package.json
CHANGED
|
@@ -139,6 +139,13 @@ export const WithPhoneBook = () => {
|
|
|
139
139
|
<Option value="+14355865955" label="Bob Johnson" keywords={['bob', 'johnson']}>
|
|
140
140
|
Bob Johnson - +1 (435) 586-5955
|
|
141
141
|
</Option>
|
|
142
|
+
<Option
|
|
143
|
+
value="+14355865950"
|
|
144
|
+
label="A Really Really Really Really Really Long Label For Jack"
|
|
145
|
+
keywords={['jack', 'johnson']}
|
|
146
|
+
>
|
|
147
|
+
A Really Really Really Really Reall Long Label - +1 (435) 586-5955
|
|
148
|
+
</Option>
|
|
142
149
|
<Option
|
|
143
150
|
value="sip:foo@bar.com"
|
|
144
151
|
label="Foo Sip"
|
|
@@ -112,6 +112,11 @@ export const PhoneNumberInputAdapter = forwardRef<
|
|
|
112
112
|
<SuggestionList
|
|
113
113
|
open={isPhoneBookOpen}
|
|
114
114
|
anchorElement={phoneBookElement}
|
|
115
|
+
horizontalAnchor="end"
|
|
116
|
+
horizontalOrigin="end"
|
|
117
|
+
verticalAnchor="top"
|
|
118
|
+
verticalOrigin="top"
|
|
119
|
+
width="300px"
|
|
115
120
|
onOptionSelect={handlePhoneBookOptionSelect}
|
|
116
121
|
onClose={closePhoneBook}
|
|
117
122
|
noSuggestionMessage="No phone numbers found"
|
|
@@ -138,7 +138,12 @@ export function SipInput({
|
|
|
138
138
|
anchorElement={phoneBookElement}
|
|
139
139
|
onOptionSelect={handlePhoneBookOptionSelect}
|
|
140
140
|
onClose={closePhoneBook}
|
|
141
|
+
width="300px"
|
|
141
142
|
noSuggestionMessage="No phone numbers found"
|
|
143
|
+
horizontalAnchor="end"
|
|
144
|
+
horizontalOrigin="end"
|
|
145
|
+
verticalAnchor="top"
|
|
146
|
+
verticalOrigin="top"
|
|
142
147
|
>
|
|
143
148
|
{phoneBookOptions}
|
|
144
149
|
</SuggestionList>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { Option, type OptionProps } from '../options/option.js';
|
|
3
3
|
import { Select as SelectComponent, SelectProps } from './select.js';
|
|
4
4
|
import { HStack } from '../../stacks/h_stack.js';
|
|
5
5
|
import { VStack } from '../../stacks/v_stack.js';
|
|
6
6
|
import { Headline } from '../../typography/headline/headline.js';
|
|
7
7
|
import { BodyText } from '../../typography/body_text/body_text.js';
|
|
8
|
+
import { Button } from '../../actions/button/button/button.js';
|
|
8
9
|
|
|
9
10
|
export default {
|
|
10
11
|
title: 'Inputs/Select',
|
|
@@ -124,23 +125,45 @@ export function CustomWidth(_: Omit<SelectProps, 'children'>) {
|
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
export function DelayedOptions() {
|
|
128
|
+
const timeoutRef = useRef<number | null>(null);
|
|
127
129
|
const [value, setValue] = useState<string>('');
|
|
128
130
|
const [options, setOptions] = useState<React.ReactElement<OptionProps>[]>([]);
|
|
129
131
|
|
|
130
132
|
useEffect(() => {
|
|
131
|
-
window.setTimeout(() => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
134
|
+
const length = options.length;
|
|
135
|
+
const newOptions = [
|
|
136
|
+
...options,
|
|
137
|
+
<Option
|
|
138
|
+
key={length}
|
|
139
|
+
value={String(length)}
|
|
140
|
+
label={String(length)}
|
|
141
|
+
keywords={[String(length)]}
|
|
142
|
+
>
|
|
143
|
+
{String(length)}
|
|
135
144
|
</Option>,
|
|
136
|
-
]
|
|
137
|
-
|
|
138
|
-
|
|
145
|
+
];
|
|
146
|
+
setOptions(newOptions);
|
|
147
|
+
}, 2000);
|
|
148
|
+
|
|
149
|
+
return () => {
|
|
150
|
+
window.clearTimeout(timeoutRef?.current || 0);
|
|
151
|
+
};
|
|
152
|
+
}, [options]);
|
|
139
153
|
|
|
140
154
|
return (
|
|
141
|
-
|
|
142
|
-
{
|
|
143
|
-
|
|
155
|
+
<>
|
|
156
|
+
<SelectComponent value={value} onChange={setValue} width="100px">
|
|
157
|
+
{options}
|
|
158
|
+
</SelectComponent>
|
|
159
|
+
<Button
|
|
160
|
+
onClick={() => {
|
|
161
|
+
window.clearInterval(timeoutRef.current ?? 0);
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
Stop
|
|
165
|
+
</Button>
|
|
166
|
+
</>
|
|
144
167
|
);
|
|
145
168
|
}
|
|
146
169
|
|
|
@@ -24,6 +24,7 @@ export interface SuggestionListProps
|
|
|
24
24
|
open?: boolean;
|
|
25
25
|
children?: React.ReactNode;
|
|
26
26
|
onChange?: (value: string) => void;
|
|
27
|
+
width?: string;
|
|
27
28
|
onOptionSelect?: (
|
|
28
29
|
value: string,
|
|
29
30
|
label: string | undefined,
|
|
@@ -39,6 +40,12 @@ export interface SuggestionListProps
|
|
|
39
40
|
cursorStartPosition: number | null,
|
|
40
41
|
cursorEndPosition: number | null
|
|
41
42
|
) => void;
|
|
43
|
+
verticalAnchor?: 'top' | 'center' | 'bottom';
|
|
44
|
+
verticalOrigin?: 'top' | 'center' | 'bottom';
|
|
45
|
+
verticalOffset?: number;
|
|
46
|
+
horizontalAnchor?: 'start' | 'center' | 'end';
|
|
47
|
+
horizontalOrigin?: 'start' | 'center' | 'end';
|
|
48
|
+
horizontalOffset?: number;
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
export function SuggestionList({
|
|
@@ -47,6 +54,7 @@ export function SuggestionList({
|
|
|
47
54
|
scrollToValue,
|
|
48
55
|
anchorElement,
|
|
49
56
|
open = false,
|
|
57
|
+
width = 'auto',
|
|
50
58
|
children,
|
|
51
59
|
onOptionSelect,
|
|
52
60
|
noSuggestionMessage = '-- No Matches --',
|
|
@@ -57,6 +65,12 @@ export function SuggestionList({
|
|
|
57
65
|
trimCustomInput = false,
|
|
58
66
|
haveValueAsOption = false,
|
|
59
67
|
restoreFocus = true,
|
|
68
|
+
verticalAnchor = 'top',
|
|
69
|
+
verticalOrigin = 'top',
|
|
70
|
+
verticalOffset = -4,
|
|
71
|
+
horizontalAnchor = 'start',
|
|
72
|
+
horizontalOrigin = 'start',
|
|
73
|
+
horizontalOffset = 0,
|
|
60
74
|
...props
|
|
61
75
|
}: SuggestionListProps) {
|
|
62
76
|
// Extract valid Option components from children
|
|
@@ -403,25 +417,28 @@ export function SuggestionList({
|
|
|
403
417
|
}, [searchValue]);
|
|
404
418
|
|
|
405
419
|
useLayoutEffect(() => {
|
|
406
|
-
const newMatches = getMatchedOptions(
|
|
420
|
+
const newMatches = getMatchedOptions(internalValue, MAX_RESULTS);
|
|
407
421
|
setMatchedOptions(newMatches);
|
|
408
|
-
}, [
|
|
422
|
+
}, [getMatchedOptions, internalValue]);
|
|
409
423
|
|
|
410
424
|
return (
|
|
411
425
|
<Popper
|
|
412
426
|
open={open}
|
|
413
427
|
anchorElement={anchorElement}
|
|
414
428
|
onClose={handleUseClose}
|
|
415
|
-
verticalAnchor=
|
|
416
|
-
verticalOrigin=
|
|
417
|
-
verticalOffset={
|
|
429
|
+
verticalAnchor={verticalAnchor}
|
|
430
|
+
verticalOrigin={verticalOrigin}
|
|
431
|
+
verticalOffset={verticalOffset}
|
|
432
|
+
horizontalAnchor={horizontalAnchor}
|
|
433
|
+
horizontalOrigin={horizontalOrigin}
|
|
434
|
+
horizontalOffset={horizontalOffset}
|
|
418
435
|
restoreFocus={restoreFocus}
|
|
419
436
|
>
|
|
420
437
|
<VStack
|
|
421
438
|
minHeight={`calc(${suggestionsHeight}, 8px)`}
|
|
422
439
|
maxHeight="300px"
|
|
423
440
|
minWidth={suggestionsWidth}
|
|
424
|
-
width=
|
|
441
|
+
width={width}
|
|
425
442
|
hAlign="start"
|
|
426
443
|
className={clsx(styles['suggestion-list'], 'tcn-suggestion-list')}
|
|
427
444
|
>
|