@semcore/select 17.3.0 → 17.4.0-prerelease.1
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/CHANGELOG.md +6 -0
- package/lib/cjs/InputSearch.js +6 -6
- package/lib/cjs/Select.js +8 -8
- package/lib/cjs/components/AutoSuggest/AutoSuggest.js +506 -0
- package/lib/cjs/components/AutoSuggest/AutoSuggest.js.map +1 -0
- package/lib/cjs/components/AutoSuggest/AutoSuggest.type.js +2 -0
- package/lib/cjs/components/AutoSuggest/AutoSuggest.type.js.map +1 -0
- package/lib/cjs/components/AutoSuggest/Highlight.js +49 -0
- package/lib/cjs/components/AutoSuggest/Highlight.js.map +1 -0
- package/lib/cjs/index.d.js.map +1 -1
- package/lib/cjs/index.js +9 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/translations/en.json +2 -1
- package/lib/es6/InputSearch.js +6 -6
- package/lib/es6/Select.js +8 -8
- package/lib/es6/components/AutoSuggest/AutoSuggest.js +504 -0
- package/lib/es6/components/AutoSuggest/AutoSuggest.js.map +1 -0
- package/lib/es6/components/AutoSuggest/AutoSuggest.type.js +2 -0
- package/lib/es6/components/AutoSuggest/AutoSuggest.type.js.map +1 -0
- package/lib/es6/components/AutoSuggest/Highlight.js +42 -0
- package/lib/es6/components/AutoSuggest/Highlight.js.map +1 -0
- package/lib/es6/index.d.js.map +1 -1
- package/lib/es6/index.js +1 -0
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/translations/en.json +2 -1
- package/lib/esm/InputSearch.mjs +7 -7
- package/lib/esm/Select.mjs +9 -9
- package/lib/esm/components/AutoSuggest/AutoSuggest.mjs +500 -0
- package/lib/esm/components/AutoSuggest/Highlight.mjs +44 -0
- package/lib/esm/index.mjs +2 -0
- package/lib/esm/translations/en.json.mjs +2 -1
- package/lib/types/components/AutoSuggest/AutoSuggest.d.ts +2 -0
- package/lib/types/components/AutoSuggest/AutoSuggest.type.d.ts +126 -0
- package/lib/types/components/AutoSuggest/Highlight.d.ts +7 -0
- package/lib/types/index.d.ts +6 -3
- package/lib/types/translations/__intergalactic-dynamic-locales.d.ts +87 -0
- package/package.json +7 -6
package/lib/es6/index.d.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import type { BoxProps, Flex } from '@semcore/base-components';\nimport type { ButtonTrigger, BaseTriggerProps, ButtonTriggerProps, LinkTriggerProps } from '@semcore/base-trigger';\nimport type { PropGetterFn, Intergalactic } from '@semcore/core';\nimport type Divider from '@semcore/divider';\nimport type Dropdown from '@semcore/dropdown';\nimport type { StatusItemComponent } from '@semcore/dropdown';\nimport type {\n DropdownMenuContext,\n DropdownMenuItemProps,\n DropdownMenuProps,\n DropdownMenuHandlers,\n DropdownMenuTriggerProps,\n} from '@semcore/dropdown-menu';\nimport type DropdownMenu from '@semcore/dropdown-menu';\nimport type {
|
|
1
|
+
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import type { BoxProps, Flex } from '@semcore/base-components';\nimport type { ButtonTrigger, BaseTriggerProps, ButtonTriggerProps, LinkTriggerProps } from '@semcore/base-trigger';\nimport type { PropGetterFn, Intergalactic } from '@semcore/core';\nimport type Divider from '@semcore/divider';\nimport type Dropdown from '@semcore/dropdown';\nimport type { StatusItemComponent } from '@semcore/dropdown';\nimport type {\n DropdownMenuContext,\n DropdownMenuItemProps,\n DropdownMenuProps,\n DropdownMenuHandlers,\n DropdownMenuTriggerProps,\n} from '@semcore/dropdown-menu';\nimport type DropdownMenu from '@semcore/dropdown-menu';\nimport type { NSInput } from '@semcore/input';\nimport type Input from '@semcore/input';\nimport type { Text } from '@semcore/typography';\nimport type React from 'react';\n\nexport type SelectInputSearch = NSInput.Value.Props & {};\nimport type { NSAutoSuggest } from './components/AutoSuggest/AutoSuggest.type';\n\nexport type OptionValue = string | number;\nexport type SelectValue = string | number | Array<string | number> | null;\n\nexport type SelectOption = {\n value: OptionValue;\n children?: React.ReactNode;\n label?: React.ReactNode;\n};\n\nexport type SelectProps<T extends SelectValue = SelectValue> = Intergalactic.InternalTypings.EfficientOmit<DropdownMenuProps, 'size'> &\n Intergalactic.InternalTypings.EfficientOmit<BaseTriggerProps, 'size'> & {\n /**\n * Options array\n */\n options?: SelectOption[];\n /**\n * The value or values array selected by default when using multiselect\n * @type SelectValue\n */\n defaultValue?: T;\n /**\n * The selected value or values array when using multiselect\n * @type SelectValue\n */\n value?: T;\n /**\n * Callback on value change\n * @type (value: SelectValue, e: React.SyntheticEvent) => boolean | void\n */\n onChange?:\n | ((value: T, e: React.SyntheticEvent) => boolean | void)\n | React.Dispatch<React.SetStateAction<T>>;\n /**\n * Trigger placeholder at not selected value\n */\n placeholder?: React.ReactNode;\n /**\n * Trigger state\n */\n state?: 'normal' | 'valid' | 'invalid';\n /**\n * Disables select\n */\n disabled?: boolean;\n /**\n * If provided, adds a hidden <input /> tag with the given name for enhancing accessibility.\n */\n name?: string;\n /** Specifies the locale for i18n support */\n locale?: string;\n /**\n * If enabled, after opening select popper view will be scrolled to selected option or, if there are multiple selected options, to the first selected option.\n * @default true\n */\n scrollToSelected?: boolean;\n } & ({\n tag?: never;\n /**\n * Default type for size from BaseTriggerProps if there is no customization via `tag`.\n */\n size?: BaseTriggerProps['size'];\n } | {});\n\nexport type SelectOptionProps = DropdownMenuItemProps & {\n /**\n * Enables selected state\n */\n selected?: boolean;\n /** Value of the option */\n value: string | number;\n};\n\nexport type SelectOptionCheckboxProps = BoxProps & {\n /** Checkbox theme */\n theme?: string;\n /** Visual indeterminate state */\n indeterminate?: boolean;\n /** Controls the selected state */\n selected?: boolean;\n};\n\ndeclare const InputSearch: Intergalactic.Component<'div', SelectInputSearch> & {\n SearchIcon: typeof Input.Addon;\n Value: typeof Input.Value;\n Clear: typeof Input.Addon;\n};\n\nexport type SelectContext = DropdownMenuContext & {\n getOptionProps: PropGetterFn;\n getOptionCheckboxProps: PropGetterFn;\n getDividerProps: PropGetterFn;\n};\n\nexport type SelectHandlers = DropdownMenuHandlers & {\n value: (index: SelectValue) => void;\n};\n\ntype IntergalacticSelectComponent<PropsExtending = {}> = (<\n Value extends SelectValue,\n Tag extends Intergalactic.Tag = 'div',\n>(\n props: Intergalactic.InternalTypings.ComponentProps<\n Tag,\n 'div',\n SelectProps<Value>,\n SelectContext,\n [handlers: SelectHandlers]\n > &\n PropsExtending,\n) => Intergalactic.InternalTypings.ComponentRenderingResults) &\nIntergalactic.InternalTypings.ComponentAdditive<'div', 'div', SelectProps>;\n\ndeclare const Select: IntergalacticSelectComponent & {\n Trigger: Intergalactic.Component<\n typeof Dropdown.Trigger,\n DropdownMenuTriggerProps & (ButtonTriggerProps | LinkTriggerProps),\n {},\n [handlers: SelectHandlers]\n > & {\n Addon: typeof ButtonTrigger.Addon;\n Text: typeof ButtonTrigger.Text;\n };\n Popper: typeof DropdownMenu.Popper;\n List: typeof DropdownMenu.List;\n Menu: typeof DropdownMenu.Menu;\n Group: typeof Dropdown.Group;\n StatusItem: StatusItemComponent;\n Option: Intergalactic.Component<\n 'option',\n SelectOptionProps,\n SelectContext,\n [handlers: SelectHandlers]\n > & {\n Addon: typeof DropdownMenu.Item.Addon;\n Checkbox: Intergalactic.Component<'div', SelectOptionCheckboxProps>;\n Content: typeof Flex;\n Text: typeof Text;\n Hint: typeof Flex;\n };\n Divider: typeof Divider;\n InputSearch: typeof InputSearch;\n Input: typeof InputSearch;\n};\n\ndeclare const wrapSelect: <PropsExtending extends {}>(\n wrapper: (\n props: Intergalactic.InternalTypings.UntypeRefAndTag<\n Intergalactic.InternalTypings.ComponentPropsNesting<IntergalacticSelectComponent>\n > &\n PropsExtending,\n ) => React.ReactNode,\n) => IntergalacticSelectComponent<PropsExtending>;\n\ndeclare const AutoSuggest: NSAutoSuggest.Component;\n\nexport { InputSearch, wrapSelect, AutoSuggest, NSAutoSuggest };\nexport default Select;\n"],"mappings":"","ignoreList":[]}
|
package/lib/es6/index.js
CHANGED
package/lib/es6/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["default","InputSearch"],"sources":["../../src/index.js"],"sourcesContent":["export { default as InputSearch } from './InputSearch';\nexport { default } from './Select';\nexport * from './Select';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAAW,QAAQ,eAAe;AACtD,SAASD,OAAO,QAAQ,UAAU;AAClC,cAAc,UAAU","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","InputSearch","AutoSuggest"],"sources":["../../src/index.js"],"sourcesContent":["export { default as InputSearch } from './InputSearch';\nexport { default } from './Select';\nexport * from './Select';\nexport { AutoSuggest } from './components/AutoSuggest/AutoSuggest';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAAW,QAAQ,eAAe;AACtD,SAASD,OAAO,QAAQ,UAAU;AAClC,cAAc,UAAU;AACxB,SAASE,WAAW,QAAQ,sCAAsC","ignoreList":[]}
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
"clearSearch": "Clear search field",
|
|
3
3
|
"selectPlaceholder": "Select option",
|
|
4
4
|
"Select.InputSearch.Value:placeholder": "Search",
|
|
5
|
-
"Select.InputSearch.Value:aria-label": "Search"
|
|
5
|
+
"Select.InputSearch.Value:aria-label": "Search",
|
|
6
|
+
"AutoSuggest.Popper.placeholderText": "Start typing to see options"
|
|
6
7
|
}
|
package/lib/esm/InputSearch.mjs
CHANGED
|
@@ -13,16 +13,16 @@ const style = (
|
|
|
13
13
|
/*__reshadow_css_start__*/
|
|
14
14
|
(sstyled.insert(
|
|
15
15
|
/*__inner_css_start__*/
|
|
16
|
-
".
|
|
16
|
+
".___SInputSearch_1m3u8_gg_._size_m_1m3u8_gg_{height:32px}.___SSearchClear_1m3u8_gg_{padding:0 var(--intergalactic-spacing-2x,8px)}.___SSearchClear_1m3u8_gg_.__hide_1m3u8_gg_{visibility:hidden}.___SOutline_1m3u8_gg_{top:-1px;left:-1px;width:100%;border-radius:var(--intergalactic-control-rounded,6px) var(--intergalactic-control-rounded,6px) 0 0;box-sizing:initial}",
|
|
17
17
|
/*__inner_css_end__*/
|
|
18
|
-
"
|
|
18
|
+
"1m3u8_gg_"
|
|
19
19
|
), /*__reshadow_css_end__*/
|
|
20
20
|
{
|
|
21
|
-
"__SInputSearch": "
|
|
22
|
-
"_size_m": "
|
|
23
|
-
"__SSearchClear": "
|
|
24
|
-
"_hide": "
|
|
25
|
-
"__SOutline": "
|
|
21
|
+
"__SInputSearch": "___SInputSearch_1m3u8_gg_",
|
|
22
|
+
"_size_m": "_size_m_1m3u8_gg_",
|
|
23
|
+
"__SSearchClear": "___SSearchClear_1m3u8_gg_",
|
|
24
|
+
"_hide": "__hide_1m3u8_gg_",
|
|
25
|
+
"__SOutline": "___SOutline_1m3u8_gg_"
|
|
26
26
|
})
|
|
27
27
|
);
|
|
28
28
|
class InputSearchRoot extends Component {
|
package/lib/esm/Select.mjs
CHANGED
|
@@ -22,18 +22,18 @@ const style = (
|
|
|
22
22
|
/*__reshadow_css_start__*/
|
|
23
23
|
(sstyled.insert(
|
|
24
24
|
/*__inner_css_start__*/
|
|
25
|
-
'.
|
|
25
|
+
'.___SOptionCheckbox_nu0ok_gg_{margin-top:var(--intergalactic-spacing-05x,2px);margin-right:var(--intergalactic-spacing-2x,8px);margin-bottom:auto;position:relative;flex-shrink:0;width:16px;height:16px}.___SOptionCheckbox_nu0ok_gg_:before{content:"";position:absolute;top:0;left:0;right:0;bottom:0;background:var(--intergalactic-bg-primary-neutral,oklch(1 0 0));border:1px solid;border-radius:var(--intergalactic-addon-rounded,4px);border-color:var(--intergalactic-border-primary,#000c0829)}@media (color-gamut:p3){.___SOptionCheckbox_nu0ok_gg_:before{border-color:var(--intergalactic-border-primary,oklch(.137 .026 175.7/.161))}}.___SOptionCheckbox_nu0ok_gg_:after{content:"";position:absolute;top:0;left:0;right:0;bottom:0;margin:0 var(--intergalactic-spacing-05x,2px);background-repeat:no-repeat;background-position:50%}.___SOptionCheckbox_nu0ok_gg_.__selected_nu0ok_gg_:after{background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMCIgaGVpZ2h0PSI3IiBmaWxsPSJub25lIiB2aWV3Qm94PSIwIDAgMTAgNyI+PHBhdGggc3Ryb2tlPSIjZmZmIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS13aWR0aD0iMiIgZD0iTTguMjUgMSA0IDUuMjUgMS43NSAzIi8+PC9zdmc+")}.___SOptionCheckbox_nu0ok_gg_._size_l_nu0ok_gg_{width:20px;height:20px}.___SOptionCheckbox_nu0ok_gg_._size_l_nu0ok_gg_.__selected_nu0ok_gg_:after{background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMiIgaGVpZ2h0PSI5IiBmaWxsPSJub25lIiB2aWV3Qm94PSIwIDAgMTIgOSI+PHBhdGggc3Ryb2tlPSIjZmZmIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS13aWR0aD0iMiIgZD0iTTExIDEuNSA0Ljc1IDcuNzUgMSA0Ii8+PC9zdmc+")}.___SOptionCheckbox_nu0ok_gg_.__indeterminate_nu0ok_gg_:before,.___SOptionCheckbox_nu0ok_gg_.__selected_nu0ok_gg_:before{background-color:var(--intergalactic-control-primary-info,oklch(.23 .01 140));border-color:var(--intergalactic-control-primary-info,oklch(.23 .01 140))}.___SOptionCheckbox_nu0ok_gg_.__theme_nu0ok_gg_:before{border-color:var(--theme_nu0ok)}.___SOptionCheckbox_nu0ok_gg_.__theme_nu0ok_gg_.__indeterminate_nu0ok_gg_:before,.___SOptionCheckbox_nu0ok_gg_.__theme_nu0ok_gg_.__selected_nu0ok_gg_:before{background-color:var(--theme_nu0ok);border-color:var(--theme_nu0ok)}.___SOptionCheckbox_nu0ok_gg_.__selected_nu0ok_gg_{background-color:var(--intergalactic-dropdown-menu-item-selected,#0050ff14)}@media (color-gamut:p3){.___SOptionCheckbox_nu0ok_gg_.__selected_nu0ok_gg_{background-color:var(--intergalactic-dropdown-menu-item-selected,oklch(.525 .265 263/.077))}}@media (hover:hover){.___SOptionCheckbox_nu0ok_gg_.__selected_nu0ok_gg_:hover{background-color:var(--intergalactic-dropdown-menu-item-selected-hover,#004dff31)}@media (color-gamut:p3){.___SOptionCheckbox_nu0ok_gg_.__selected_nu0ok_gg_:hover{background-color:var(--intergalactic-dropdown-menu-item-selected-hover,oklch(.52 .268 263.2/.191))}}}.___SOptionCheckbox_nu0ok_gg_.__indeterminate_nu0ok_gg_:after{background-color:#fff;background-image:none;margin:auto;border-radius:1px}.___SOptionCheckbox_nu0ok_gg_.__indeterminate_nu0ok_gg_._size_l_nu0ok_gg_:after{width:12px;height:2px}.___SOptionCheckbox_nu0ok_gg_.__indeterminate_nu0ok_gg_._size_m_nu0ok_gg_:after{width:8px;height:2px}',
|
|
26
26
|
/*__inner_css_end__*/
|
|
27
|
-
"
|
|
27
|
+
"nu0ok_gg_"
|
|
28
28
|
), /*__reshadow_css_end__*/
|
|
29
29
|
{
|
|
30
|
-
"__SOptionCheckbox": "
|
|
31
|
-
"_selected": "
|
|
32
|
-
"_size_l": "
|
|
33
|
-
"_indeterminate": "
|
|
34
|
-
"_theme": "
|
|
35
|
-
"--theme": "--
|
|
36
|
-
"_size_m": "
|
|
30
|
+
"__SOptionCheckbox": "___SOptionCheckbox_nu0ok_gg_",
|
|
31
|
+
"_selected": "__selected_nu0ok_gg_",
|
|
32
|
+
"_size_l": "_size_l_nu0ok_gg_",
|
|
33
|
+
"_indeterminate": "__indeterminate_nu0ok_gg_",
|
|
34
|
+
"_theme": "__theme_nu0ok_gg_",
|
|
35
|
+
"--theme": "--theme_nu0ok",
|
|
36
|
+
"_size_m": "_size_m_nu0ok_gg_"
|
|
37
37
|
})
|
|
38
38
|
);
|
|
39
39
|
function isSelectedOption(value, valueOption) {
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import { Component, assignProps, createComponent } from "@semcore/core";
|
|
3
|
+
import i18nEnhance from "@semcore/core/lib/utils/enhances/i18nEnhance";
|
|
4
|
+
import { getAccessibleName } from "@semcore/core/lib/utils/getAccessibleName";
|
|
5
|
+
import { forkRef } from "@semcore/core/lib/utils/ref";
|
|
6
|
+
import uniqueIDEnhancement from "@semcore/core/lib/utils/uniqueID";
|
|
7
|
+
import { isFocusInside } from "@semcore/core/lib/utils/use/useFocusLock";
|
|
8
|
+
import { cssVariableEnhance } from "@semcore/core/lib/utils/useCssVariable";
|
|
9
|
+
import Input from "@semcore/input";
|
|
10
|
+
import Spin from "@semcore/spin";
|
|
11
|
+
import React from "react";
|
|
12
|
+
import { Highlight } from "./Highlight.mjs";
|
|
13
|
+
import "../../index.mjs";
|
|
14
|
+
import { localizedMessages } from "../../translations/__intergalactic-dynamic-locales.mjs";
|
|
15
|
+
import Select from "../../Select.mjs";
|
|
16
|
+
class AutoSuggestRoot extends Component {
|
|
17
|
+
constructor(...args) {
|
|
18
|
+
super(...args);
|
|
19
|
+
_defineProperty(this, "abortController", void 0);
|
|
20
|
+
_defineProperty(this, "changeDebounce", null);
|
|
21
|
+
_defineProperty(this, "triggerRef", /* @__PURE__ */ React.createRef());
|
|
22
|
+
_defineProperty(this, "popperRef", /* @__PURE__ */ React.createRef());
|
|
23
|
+
_defineProperty(this, "state", {
|
|
24
|
+
isVisible: false,
|
|
25
|
+
highlightedIndex: -1,
|
|
26
|
+
suggestions: Array.isArray(this.props.suggestions) ? this.props.suggestions : [],
|
|
27
|
+
openOnChanges: true,
|
|
28
|
+
isLoading: false
|
|
29
|
+
});
|
|
30
|
+
_defineProperty(this, "handleChange", (value, event) => {
|
|
31
|
+
this.handlers.value(value, event);
|
|
32
|
+
if (this.changeDebounce) {
|
|
33
|
+
clearTimeout(this.changeDebounce);
|
|
34
|
+
}
|
|
35
|
+
if (this.abortController) {
|
|
36
|
+
this.abortController.abort();
|
|
37
|
+
}
|
|
38
|
+
if (value !== this.asProps.value) {
|
|
39
|
+
const {
|
|
40
|
+
suggestions,
|
|
41
|
+
duration
|
|
42
|
+
} = this.asProps;
|
|
43
|
+
if (value === "") {
|
|
44
|
+
this.setState({
|
|
45
|
+
isLoading: false
|
|
46
|
+
});
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
if (document.activeElement === this.triggerRef.current) {
|
|
49
|
+
this.setState({
|
|
50
|
+
suggestions: [],
|
|
51
|
+
isVisible: true
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}, Number(duration));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (!Array.isArray(suggestions) && this.state.openOnChanges) {
|
|
58
|
+
this.setState({
|
|
59
|
+
isLoading: true,
|
|
60
|
+
isVisible: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
this.changeDebounce = setTimeout(async () => {
|
|
64
|
+
const {
|
|
65
|
+
openOnChanges
|
|
66
|
+
} = this.state;
|
|
67
|
+
if (Array.isArray(suggestions)) {
|
|
68
|
+
const filteredSuggestions = value === "" ? [] : suggestions.filter((s) => s.toLowerCase().includes(value.toLowerCase()));
|
|
69
|
+
this.setState({
|
|
70
|
+
suggestions: filteredSuggestions,
|
|
71
|
+
isVisible: filteredSuggestions.length > 0 && openOnChanges
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
this.abortController = new AbortController();
|
|
75
|
+
const abortSignal = this.abortController.signal;
|
|
76
|
+
const filteredSuggestions = await suggestions(value, abortSignal);
|
|
77
|
+
if (!this.abortController.signal.aborted) {
|
|
78
|
+
this.setState({
|
|
79
|
+
suggestions: filteredSuggestions,
|
|
80
|
+
isLoading: false,
|
|
81
|
+
isVisible: filteredSuggestions.length > 0 && openOnChanges
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}, 300);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
_defineProperty(this, "handleChangeVisible", (isVisible) => {
|
|
89
|
+
this.setState({
|
|
90
|
+
isVisible
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
_defineProperty(this, "handleChangeHighlightedIndex", (index) => {
|
|
94
|
+
this.setState({
|
|
95
|
+
highlightedIndex: index ?? -1
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
_defineProperty(this, "handleKeyDown", (e) => {
|
|
99
|
+
if (!e.key.startsWith("Arrow")) {
|
|
100
|
+
this.setState({
|
|
101
|
+
highlightedIndex: -1
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (e.key === "Escape") {
|
|
105
|
+
this.setState({
|
|
106
|
+
openOnChanges: false,
|
|
107
|
+
isLoading: false
|
|
108
|
+
});
|
|
109
|
+
this.abortController?.abort();
|
|
110
|
+
}
|
|
111
|
+
const {
|
|
112
|
+
value
|
|
113
|
+
} = this.asProps;
|
|
114
|
+
const {
|
|
115
|
+
isVisible,
|
|
116
|
+
suggestions
|
|
117
|
+
} = this.state;
|
|
118
|
+
if (!isVisible) {
|
|
119
|
+
const filteredSuggestions = suggestions.filter((s) => {
|
|
120
|
+
return value !== "" && s.toLowerCase().includes(value.toLowerCase());
|
|
121
|
+
});
|
|
122
|
+
if (e.key === "ArrowDown") {
|
|
123
|
+
this.setState({
|
|
124
|
+
suggestions: filteredSuggestions,
|
|
125
|
+
highlightedIndex: 0
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (e.key === "ArrowUp") {
|
|
129
|
+
this.setState({
|
|
130
|
+
suggestions: filteredSuggestions,
|
|
131
|
+
highlightedIndex: filteredSuggestions.length - 1
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (e.key === "Enter") {
|
|
135
|
+
this.setState({
|
|
136
|
+
suggestions: filteredSuggestions,
|
|
137
|
+
highlightedIndex: -1,
|
|
138
|
+
isVisible: true,
|
|
139
|
+
openOnChanges: true
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
_defineProperty(this, "handleChangeSelect", (value, e) => {
|
|
145
|
+
this.handlers.value(value, e);
|
|
146
|
+
});
|
|
147
|
+
_defineProperty(this, "handleFocus", () => {
|
|
148
|
+
const {
|
|
149
|
+
value,
|
|
150
|
+
statusItemPlaceholder
|
|
151
|
+
} = this.asProps;
|
|
152
|
+
const {
|
|
153
|
+
suggestions
|
|
154
|
+
} = this.state;
|
|
155
|
+
this.setState({
|
|
156
|
+
openOnChanges: true,
|
|
157
|
+
isVisible: statusItemPlaceholder === "" ? value !== "" : true,
|
|
158
|
+
suggestions: suggestions.filter((s) => {
|
|
159
|
+
return value !== "" && s.toLowerCase().includes(value.toLowerCase());
|
|
160
|
+
}),
|
|
161
|
+
highlightedIndex: -1
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
_defineProperty(this, "handleBlur", () => {
|
|
165
|
+
setTimeout(() => {
|
|
166
|
+
const popperElement = this.popperRef.current;
|
|
167
|
+
if (!popperElement || !isFocusInside(popperElement)) {
|
|
168
|
+
this.handleChangeVisible(false);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
uncontrolledProps() {
|
|
174
|
+
return {
|
|
175
|
+
value: null
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
componentDidMount() {
|
|
179
|
+
const {
|
|
180
|
+
value,
|
|
181
|
+
suggestions
|
|
182
|
+
} = this.asProps;
|
|
183
|
+
if (value && !Array.isArray(suggestions)) {
|
|
184
|
+
this.changeDebounce = setTimeout(async () => {
|
|
185
|
+
this.abortController = new AbortController();
|
|
186
|
+
const abortSignal = this.abortController.signal;
|
|
187
|
+
const filteredSuggestions = await suggestions(value, abortSignal);
|
|
188
|
+
if (!this.abortController.signal.aborted) {
|
|
189
|
+
this.setState({
|
|
190
|
+
suggestions: filteredSuggestions,
|
|
191
|
+
isLoading: false
|
|
192
|
+
});
|
|
193
|
+
this.changeDebounce = null;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
get id() {
|
|
199
|
+
const {
|
|
200
|
+
uid,
|
|
201
|
+
id
|
|
202
|
+
} = this.asProps;
|
|
203
|
+
return id ?? `${uid}_autosuggest-trigger`;
|
|
204
|
+
}
|
|
205
|
+
get isStartTypingState() {
|
|
206
|
+
const {
|
|
207
|
+
suggestions
|
|
208
|
+
} = this.state;
|
|
209
|
+
const {
|
|
210
|
+
statusItemPlaceholder,
|
|
211
|
+
value
|
|
212
|
+
} = this.asProps;
|
|
213
|
+
return value === "" && statusItemPlaceholder !== "" && suggestions.length === 0;
|
|
214
|
+
}
|
|
215
|
+
get isAriaExpanded() {
|
|
216
|
+
const {
|
|
217
|
+
isVisible,
|
|
218
|
+
isLoading,
|
|
219
|
+
suggestions
|
|
220
|
+
} = this.state;
|
|
221
|
+
return isVisible && suggestions.length > 0 && !isLoading && !this.isStartTypingState;
|
|
222
|
+
}
|
|
223
|
+
get isVisiblePopper() {
|
|
224
|
+
const {
|
|
225
|
+
isVisible,
|
|
226
|
+
isLoading,
|
|
227
|
+
suggestions
|
|
228
|
+
} = this.state;
|
|
229
|
+
return isVisible && (suggestions.length > 0 || isLoading || this.isStartTypingState);
|
|
230
|
+
}
|
|
231
|
+
get neighborLocation() {
|
|
232
|
+
const {
|
|
233
|
+
addonLeft: AddonLeft,
|
|
234
|
+
addonRight: AddonRight
|
|
235
|
+
} = this.asProps;
|
|
236
|
+
let neighborLocation = void 0;
|
|
237
|
+
if (AddonLeft && AddonRight) {
|
|
238
|
+
neighborLocation = "both";
|
|
239
|
+
} else if (AddonLeft) {
|
|
240
|
+
neighborLocation = "left";
|
|
241
|
+
} else if (AddonRight) {
|
|
242
|
+
neighborLocation = "right";
|
|
243
|
+
}
|
|
244
|
+
return neighborLocation;
|
|
245
|
+
}
|
|
246
|
+
getTriggerProps() {
|
|
247
|
+
const {
|
|
248
|
+
size,
|
|
249
|
+
getI18nText,
|
|
250
|
+
neighborLocation,
|
|
251
|
+
addonLeft,
|
|
252
|
+
addonRight,
|
|
253
|
+
uid
|
|
254
|
+
} = this.asProps;
|
|
255
|
+
const {
|
|
256
|
+
isLoading
|
|
257
|
+
} = this.state;
|
|
258
|
+
return {
|
|
259
|
+
"tag": Input,
|
|
260
|
+
"onFocus": this.handleFocus,
|
|
261
|
+
"onBlur": this.handleBlur,
|
|
262
|
+
"aria-haspopup": "listbox",
|
|
263
|
+
"aria-expanded": this.isAriaExpanded ? "true" : "false",
|
|
264
|
+
"aria-controls": `igc-${uid}-list`,
|
|
265
|
+
isLoading,
|
|
266
|
+
size,
|
|
267
|
+
getI18nText,
|
|
268
|
+
neighborLocation,
|
|
269
|
+
addonLeft,
|
|
270
|
+
addonRight
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
getTriggerValueProps() {
|
|
274
|
+
const {
|
|
275
|
+
value,
|
|
276
|
+
forwardRef,
|
|
277
|
+
autoComplete,
|
|
278
|
+
role,
|
|
279
|
+
onChange,
|
|
280
|
+
ref,
|
|
281
|
+
id,
|
|
282
|
+
...props
|
|
283
|
+
} = this.asProps;
|
|
284
|
+
return {
|
|
285
|
+
autoComplete: "off",
|
|
286
|
+
onChange: this.handleChange,
|
|
287
|
+
onKeyDown: this.handleKeyDown,
|
|
288
|
+
role: "combobox",
|
|
289
|
+
value,
|
|
290
|
+
ref: forwardRef ? forkRef(forwardRef, this.triggerRef) : this.triggerRef,
|
|
291
|
+
id: this.id,
|
|
292
|
+
...props,
|
|
293
|
+
neighborLocation: this.neighborLocation
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
getPopperProps() {
|
|
297
|
+
return {
|
|
298
|
+
"aria-labelledby": this.id,
|
|
299
|
+
"ref": this.popperRef
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
getPopperLoadingStateProps() {
|
|
303
|
+
const {
|
|
304
|
+
isLoading
|
|
305
|
+
} = this.state;
|
|
306
|
+
return {
|
|
307
|
+
isLoading
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
getPopperStartTypingStateProps() {
|
|
311
|
+
const {
|
|
312
|
+
getI18nText,
|
|
313
|
+
statusItemPlaceholder
|
|
314
|
+
} = this.asProps;
|
|
315
|
+
const {
|
|
316
|
+
isLoading
|
|
317
|
+
} = this.state;
|
|
318
|
+
return {
|
|
319
|
+
isLoading,
|
|
320
|
+
isStartTypingState: this.isStartTypingState,
|
|
321
|
+
children: statusItemPlaceholder ?? getI18nText("AutoSuggest.Popper.placeholderText")
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
getPopperListProps() {
|
|
325
|
+
const {
|
|
326
|
+
value
|
|
327
|
+
} = this.asProps;
|
|
328
|
+
const {
|
|
329
|
+
isLoading,
|
|
330
|
+
suggestions
|
|
331
|
+
} = this.state;
|
|
332
|
+
const triggerElement = this.triggerRef.current;
|
|
333
|
+
return {
|
|
334
|
+
value,
|
|
335
|
+
isLoading,
|
|
336
|
+
suggestions,
|
|
337
|
+
"isStartTypingState": this.isStartTypingState,
|
|
338
|
+
"aria-label": getAccessibleName(triggerElement)
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
getPopperSuggestionItemProps(_, index) {
|
|
342
|
+
const {
|
|
343
|
+
suggestions
|
|
344
|
+
} = this.state;
|
|
345
|
+
const {
|
|
346
|
+
value
|
|
347
|
+
} = this.asProps;
|
|
348
|
+
const option = suggestions[index];
|
|
349
|
+
return {
|
|
350
|
+
value: option,
|
|
351
|
+
selected: false,
|
|
352
|
+
onClick: (e) => this.handleChangeSelect(option, e),
|
|
353
|
+
children: /* @__PURE__ */ React.createElement(Highlight, {
|
|
354
|
+
highlight: value
|
|
355
|
+
}, option)
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
render() {
|
|
359
|
+
var _ref = this.asProps;
|
|
360
|
+
const {
|
|
361
|
+
highlightedIndex
|
|
362
|
+
} = this.state;
|
|
363
|
+
return /* @__PURE__ */ React.createElement(Select, assignProps({
|
|
364
|
+
"interaction": "none",
|
|
365
|
+
"visible": this.isVisiblePopper,
|
|
366
|
+
"onVisibleChange": this.handleChangeVisible,
|
|
367
|
+
"highlightedIndex": highlightedIndex,
|
|
368
|
+
"onHighlightedIndexChange": this.handleChangeHighlightedIndex
|
|
369
|
+
}, _ref));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
_defineProperty(AutoSuggestRoot, "displayName", "AutoSuggest");
|
|
373
|
+
_defineProperty(AutoSuggestRoot, "defaultProps", () => {
|
|
374
|
+
return {
|
|
375
|
+
defaultValue: "",
|
|
376
|
+
placeholder: "",
|
|
377
|
+
children: /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(AutoSuggest.Trigger, null), /* @__PURE__ */ React.createElement(AutoSuggest.Popper, null))
|
|
378
|
+
};
|
|
379
|
+
});
|
|
380
|
+
_defineProperty(AutoSuggestRoot, "enhance", [uniqueIDEnhancement(), i18nEnhance(localizedMessages), cssVariableEnhance({
|
|
381
|
+
variable: "--intergalactic-duration-popper",
|
|
382
|
+
fallback: "200",
|
|
383
|
+
map: (v) => Number.parseInt(v, 10).toString(),
|
|
384
|
+
prop: "duration"
|
|
385
|
+
})]);
|
|
386
|
+
class TriggerRoot extends Component {
|
|
387
|
+
render() {
|
|
388
|
+
var _ref2 = this.asProps;
|
|
389
|
+
const {
|
|
390
|
+
isLoading,
|
|
391
|
+
size,
|
|
392
|
+
addonLeft: AddonLeft,
|
|
393
|
+
addonRight: AddonRight,
|
|
394
|
+
Children
|
|
395
|
+
} = this.asProps;
|
|
396
|
+
return /* @__PURE__ */ React.createElement(Select.Trigger, assignProps({}, _ref2), AddonLeft ? /* @__PURE__ */ React.createElement(Input.Addon, {
|
|
397
|
+
pl: size === "l" ? 3 : 2
|
|
398
|
+
}, /* @__PURE__ */ React.createElement(AddonLeft, null)) : null, /* @__PURE__ */ React.createElement(Children, null), AddonRight ? /* @__PURE__ */ React.createElement(Input.Addon, {
|
|
399
|
+
pr: isLoading ? void 0 : size === "l" ? 3 : 2
|
|
400
|
+
}, /* @__PURE__ */ React.createElement(AddonRight, null)) : null, isLoading && /* @__PURE__ */ React.createElement(Input.Addon, {
|
|
401
|
+
pr: size === "l" ? 3 : 2
|
|
402
|
+
}, /* @__PURE__ */ React.createElement(Spin, {
|
|
403
|
+
size: size === "l" ? "s" : "xs"
|
|
404
|
+
})));
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
_defineProperty(TriggerRoot, "displayName", "Trigger");
|
|
408
|
+
_defineProperty(TriggerRoot, "defaultProps", () => {
|
|
409
|
+
return {
|
|
410
|
+
children: /* @__PURE__ */ React.createElement(AutoSuggest.Trigger.Value, null)
|
|
411
|
+
};
|
|
412
|
+
});
|
|
413
|
+
class ValueRoot extends Component {
|
|
414
|
+
render() {
|
|
415
|
+
var _ref3 = this.asProps;
|
|
416
|
+
return /* @__PURE__ */ React.createElement(Input.Value, assignProps({}, _ref3));
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
_defineProperty(ValueRoot, "displayName", "Value");
|
|
420
|
+
class PopperRoot extends Component {
|
|
421
|
+
render() {
|
|
422
|
+
var _ref4 = this.asProps;
|
|
423
|
+
return /* @__PURE__ */ React.createElement(Select.Popper, assignProps({}, _ref4));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
_defineProperty(PopperRoot, "defaultProps", () => {
|
|
427
|
+
return {
|
|
428
|
+
children: /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(AutoSuggest.Popper.LoadingState, {
|
|
429
|
+
itemsCount: 0
|
|
430
|
+
}), /* @__PURE__ */ React.createElement(AutoSuggest.Popper.StartTypingState, {
|
|
431
|
+
itemsCount: 0
|
|
432
|
+
}), /* @__PURE__ */ React.createElement(AutoSuggest.Popper.List, null))
|
|
433
|
+
};
|
|
434
|
+
});
|
|
435
|
+
function LoadingStateRoot(props) {
|
|
436
|
+
const {
|
|
437
|
+
Children,
|
|
438
|
+
isLoading,
|
|
439
|
+
children
|
|
440
|
+
} = props;
|
|
441
|
+
if (!isLoading) return null;
|
|
442
|
+
return children === void 0 ? /* @__PURE__ */ React.createElement(Select.StatusItem, {
|
|
443
|
+
state: "loading",
|
|
444
|
+
itemsCount: 0
|
|
445
|
+
}) : /* @__PURE__ */ React.createElement(Select.StatusItem, {
|
|
446
|
+
state: "loading",
|
|
447
|
+
itemsCount: 0
|
|
448
|
+
}, /* @__PURE__ */ React.createElement(Children, null));
|
|
449
|
+
}
|
|
450
|
+
function StartTypingStateRoot(props) {
|
|
451
|
+
const {
|
|
452
|
+
Children,
|
|
453
|
+
isLoading,
|
|
454
|
+
isStartTypingState
|
|
455
|
+
} = props;
|
|
456
|
+
if (isLoading || !isStartTypingState) return null;
|
|
457
|
+
return /* @__PURE__ */ React.createElement(Select.StatusItem, {
|
|
458
|
+
itemsCount: 0
|
|
459
|
+
}, /* @__PURE__ */ React.createElement(Children, null));
|
|
460
|
+
}
|
|
461
|
+
class ListRoot extends Component {
|
|
462
|
+
render() {
|
|
463
|
+
var _ref5 = this.asProps;
|
|
464
|
+
const {
|
|
465
|
+
suggestions,
|
|
466
|
+
isLoading,
|
|
467
|
+
isStartTypingState,
|
|
468
|
+
Children
|
|
469
|
+
} = this.asProps;
|
|
470
|
+
if (isLoading || isStartTypingState) return null;
|
|
471
|
+
return /* @__PURE__ */ React.createElement(Select.List, assignProps({}, _ref5), suggestions.map((option) => /* @__PURE__ */ React.createElement(Children, {
|
|
472
|
+
key: option
|
|
473
|
+
})));
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
_defineProperty(ListRoot, "defaultProps", () => {
|
|
477
|
+
return {
|
|
478
|
+
children: /* @__PURE__ */ React.createElement(AutoSuggest.Popper.SuggestionItem, {
|
|
479
|
+
itemsCount: 0
|
|
480
|
+
})
|
|
481
|
+
};
|
|
482
|
+
});
|
|
483
|
+
function SuggestionItemRoot() {
|
|
484
|
+
var _ref6 = arguments[0];
|
|
485
|
+
return /* @__PURE__ */ React.createElement(Select.Option, assignProps({}, _ref6));
|
|
486
|
+
}
|
|
487
|
+
const AutoSuggest = createComponent(AutoSuggestRoot, {
|
|
488
|
+
Trigger: [TriggerRoot, {
|
|
489
|
+
Value: ValueRoot
|
|
490
|
+
}],
|
|
491
|
+
Popper: [PopperRoot, {
|
|
492
|
+
LoadingState: LoadingStateRoot,
|
|
493
|
+
StartTypingState: StartTypingStateRoot,
|
|
494
|
+
List: ListRoot,
|
|
495
|
+
SuggestionItem: SuggestionItemRoot
|
|
496
|
+
}]
|
|
497
|
+
});
|
|
498
|
+
export {
|
|
499
|
+
AutoSuggest
|
|
500
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
function Highlight({
|
|
3
|
+
highlight,
|
|
4
|
+
children
|
|
5
|
+
}) {
|
|
6
|
+
const ref = React.useRef(null);
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
const child = document.createElement("span");
|
|
9
|
+
if (highlight) {
|
|
10
|
+
const regexp = new RegExp(RegExp.escape(highlight.toLowerCase()), "ig");
|
|
11
|
+
const results = [...children.matchAll(regexp)];
|
|
12
|
+
let cursor = 0;
|
|
13
|
+
for (const result of results) {
|
|
14
|
+
const foundStr = result[0];
|
|
15
|
+
const index = result.index;
|
|
16
|
+
const before = children.slice(cursor, index);
|
|
17
|
+
const bold = children.slice(index, index + foundStr.length);
|
|
18
|
+
cursor = index + foundStr.length;
|
|
19
|
+
const beforeNode = document.createTextNode(before);
|
|
20
|
+
const boldNode = document.createElement("strong");
|
|
21
|
+
boldNode.textContent = bold;
|
|
22
|
+
child.appendChild(beforeNode);
|
|
23
|
+
child.appendChild(boldNode);
|
|
24
|
+
}
|
|
25
|
+
if (cursor < children.length) {
|
|
26
|
+
const after = children.slice(cursor);
|
|
27
|
+
const afterNode = document.createTextNode(after);
|
|
28
|
+
child.appendChild(afterNode);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
child.textContent = children;
|
|
32
|
+
}
|
|
33
|
+
ref.current?.appendChild(child);
|
|
34
|
+
return () => {
|
|
35
|
+
child.remove();
|
|
36
|
+
};
|
|
37
|
+
}, [highlight, children]);
|
|
38
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
39
|
+
ref
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
Highlight
|
|
44
|
+
};
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { default as default2 } from "./InputSearch.mjs";
|
|
2
2
|
import { default as default3, wrapSelect } from "./Select.mjs";
|
|
3
|
+
import { AutoSuggest } from "./components/AutoSuggest/AutoSuggest.mjs";
|
|
3
4
|
export {
|
|
5
|
+
AutoSuggest,
|
|
4
6
|
default2 as InputSearch,
|
|
5
7
|
default3 as default,
|
|
6
8
|
wrapSelect
|
|
@@ -4,7 +4,8 @@ const en = {
|
|
|
4
4
|
clearSearch,
|
|
5
5
|
selectPlaceholder,
|
|
6
6
|
"Select.InputSearch.Value:placeholder": "Search",
|
|
7
|
-
"Select.InputSearch.Value:aria-label": "Search"
|
|
7
|
+
"Select.InputSearch.Value:aria-label": "Search",
|
|
8
|
+
"AutoSuggest.Popper.placeholderText": "Start typing to see options"
|
|
8
9
|
};
|
|
9
10
|
export {
|
|
10
11
|
clearSearch,
|