@spaced-out/ui-design-system 0.3.38-beta.0 → 0.3.39-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cspell/custom-words.txt +4 -0
- package/.github/workflows/publish_to_npm.yml +32 -4
- package/CHANGELOG.md +16 -0
- package/dts-generator/.editorconfig +10 -0
- package/dts-generator/.gitattributes +4 -0
- package/dts-generator/README.md +63 -0
- package/dts-generator/convert.js +101 -0
- package/dts-generator/package.json +16 -0
- package/gulpfile.js +20 -1
- package/lib/components/Avatar/Avatar.d.ts +264 -0
- package/lib/components/Avatar/index.d.ts +1 -0
- package/lib/components/AvatarGroup/AvatarGroup.d.ts +161 -0
- package/lib/components/AvatarGroup/index.d.ts +1 -0
- package/lib/components/Badge/Badge.d.ts +138 -0
- package/lib/components/Badge/index.d.ts +1 -0
- package/lib/components/Banner/Banner.d.ts +52 -0
- package/lib/components/Banner/index.d.ts +1 -0
- package/lib/components/Breadcrumbs/BreadcrumbLink/BreadcrumbLink.d.ts +50 -0
- package/lib/components/Breadcrumbs/BreadcrumbLink/index.d.ts +1 -0
- package/lib/components/Breadcrumbs/Breadcrumbs.d.ts +64 -0
- package/lib/components/Breadcrumbs/index.d.ts +2 -0
- package/lib/components/Button/Button.d.ts +288 -0
- package/lib/components/Button/index.d.ts +14 -0
- package/lib/components/ButtonDropdown/ButtonDropdown.d.ts +192 -0
- package/lib/components/ButtonDropdown/SimpleButtonDropdown.d.ts +148 -0
- package/lib/components/ButtonDropdown/index.d.ts +2 -0
- package/lib/components/ButtonTabs/ButtonTab/ButtonTab.d.ts +82 -0
- package/lib/components/ButtonTabs/ButtonTab/index.d.ts +1 -0
- package/lib/components/ButtonTabs/ButtonTabDropdown.d.ts +118 -0
- package/lib/components/ButtonTabs/ButtonTabs.d.ts +113 -0
- package/lib/components/ButtonTabs/index.d.ts +2 -0
- package/lib/components/Card/Card.d.ts +163 -0
- package/lib/components/Card/index.d.ts +1 -0
- package/lib/components/Charts/ChartTooltip/index.d.ts +10 -0
- package/lib/components/Charts/ChartWrapper/ChartWrapper.d.ts +184 -0
- package/lib/components/Charts/ChartWrapper/index.d.ts +1 -0
- package/lib/components/Charts/ColumnChart/ColumnChart.d.ts +111 -0
- package/lib/components/Charts/ColumnChart/index.d.ts +1 -0
- package/lib/components/Charts/DonutChart/DonutChart.d.ts +142 -0
- package/lib/components/Charts/DonutChart/index.d.ts +1 -0
- package/lib/components/Charts/FunnelChart/FunnelChart.d.ts +99 -0
- package/lib/components/Charts/FunnelChart/index.d.ts +1 -0
- package/lib/components/Charts/LineChart/LineChart.d.ts +97 -0
- package/lib/components/Charts/LineChart/index.d.ts +1 -0
- package/lib/components/Charts/SpiderChart/SpiderChart.d.ts +95 -0
- package/lib/components/Charts/SpiderChart/index.d.ts +1 -0
- package/lib/components/Charts/index.d.ts +7 -0
- package/lib/components/ChatBubble/ChatBubble.d.ts +203 -0
- package/lib/components/ChatBubble/index.d.ts +1 -0
- package/lib/components/Checkbox/Checkbox.d.ts +165 -0
- package/lib/components/Checkbox/CheckboxGroup.d.ts +113 -0
- package/lib/components/Checkbox/index.d.ts +2 -0
- package/lib/components/Chip/Chip.d.ts +181 -0
- package/lib/components/Chip/index.d.ts +2 -0
- package/lib/components/CircularLoader/CircularLoader.d.ts +56 -0
- package/lib/components/CircularLoader/index.d.ts +1 -0
- package/lib/components/CollapsibleCard/CollapsibleCard.d.ts +134 -0
- package/lib/components/CollapsibleCard/index.d.ts +1 -0
- package/lib/components/Combobox/Combobox.d.ts +292 -0
- package/lib/components/Combobox/helper.d.ts +205 -0
- package/lib/components/Combobox/index.d.ts +1 -0
- package/lib/components/ConditionalWrapper/ConditionalWrapper.d.ts +12 -0
- package/lib/components/ConditionalWrapper/index.d.ts +1 -0
- package/lib/components/DateRangePicker/Calendar.d.ts +119 -0
- package/lib/components/DateRangePicker/DateRangePicker.d.ts +196 -0
- package/lib/components/DateRangePicker/DateRangeWrapper.d.ts +311 -0
- package/lib/components/DateRangePicker/Day.d.ts +70 -0
- package/lib/components/DateRangePicker/index.d.ts +1 -0
- package/lib/components/Dialog/Dialog.d.ts +208 -0
- package/lib/components/Dialog/index.d.ts +1 -0
- package/lib/components/Disclaimer/Disclaimer.d.ts +32 -0
- package/lib/components/Disclaimer/index.d.ts +1 -0
- package/lib/components/Dropdown/Dropdown.d.ts +145 -0
- package/lib/components/Dropdown/SimpleDropdown.d.ts +142 -0
- package/lib/components/Dropdown/index.d.ts +2 -0
- package/lib/components/EmptyState/EmptyImages/CalendarEmptyImage.d.ts +108 -0
- package/lib/components/EmptyState/EmptyImages/ChartEmptyImage.d.ts +194 -0
- package/lib/components/EmptyState/EmptyImages/DataEmptyImage.d.ts +116 -0
- package/lib/components/EmptyState/EmptyImages/FileEmptyImage.d.ts +133 -0
- package/lib/components/EmptyState/EmptyImages/MessageEmptyImage.d.ts +64 -0
- package/lib/components/EmptyState/EmptyImages/UploadEmptyImage.d.ts +67 -0
- package/lib/components/EmptyState/EmptyImages/index.d.ts +6 -0
- package/lib/components/EmptyState/EmptyState.d.ts +82 -0
- package/lib/components/EmptyState/index.d.ts +1 -0
- package/lib/components/ErrorMessage/ErrorImages/ForbiddenImage.d.ts +85 -0
- package/lib/components/ErrorMessage/ErrorImages/NotFoundImage.d.ts +117 -0
- package/lib/components/ErrorMessage/ErrorImages/ServerErrorImage.d.ts +237 -0
- package/lib/components/ErrorMessage/ErrorImages/UnauthorizedImage.d.ts +73 -0
- package/lib/components/ErrorMessage/ErrorImages/index.d.ts +4 -0
- package/lib/components/ErrorMessage/ErrorMessage.d.ts +86 -0
- package/lib/components/ErrorMessage/index.d.ts +1 -0
- package/lib/components/FileUpload/FileBlock/FileBlock.d.ts +137 -0
- package/lib/components/FileUpload/FileBlock/index.d.ts +1 -0
- package/lib/components/FileUpload/FileUpload.d.ts +190 -0
- package/lib/components/FileUpload/index.d.ts +2 -0
- package/lib/components/FocusManager/FocusManager.d.ts +52 -0
- package/lib/components/FocusManager/index.d.ts +1 -0
- package/lib/components/FocusManagerWithArrowKeyNavigation/FocusManagerWithArrowKeyNavigation.d.ts +137 -0
- package/lib/components/FocusManagerWithArrowKeyNavigation/index.d.ts +1 -0
- package/lib/components/FormTitleWrapper/FormTitleWrapper.d.ts +62 -0
- package/lib/components/FormTitleWrapper/index.d.ts +1 -0
- package/lib/components/Grid/Grid.d.ts +104 -0
- package/lib/components/Grid/index.d.ts +1 -0
- package/lib/components/Icon/ClickableIcon.d.ts +101 -0
- package/lib/components/Icon/Icon.d.ts +71 -0
- package/lib/components/Icon/Icon.docs.d.ts +138 -0
- package/lib/components/Icon/SemanticIcon.d.ts +42 -0
- package/lib/components/Icon/index.d.ts +3 -0
- package/lib/components/InContextAlert/InContextAlert.d.ts +210 -0
- package/lib/components/InContextAlert/index.d.ts +1 -0
- package/lib/components/InlineDropdown/InlineDropdown.d.ts +146 -0
- package/lib/components/InlineDropdown/SimpleInlineDropdown.d.ts +145 -0
- package/lib/components/InlineDropdown/index.d.ts +2 -0
- package/lib/components/Input/Input.d.ts +327 -0
- package/lib/components/Input/index.d.ts +1 -0
- package/lib/components/KPIBox/KPIBox.d.ts +89 -0
- package/lib/components/KPIBox/index.d.ts +1 -0
- package/lib/components/LinearLoader/LinearLoader.d.ts +44 -0
- package/lib/components/LinearLoader/index.d.ts +1 -0
- package/lib/components/Link/Link.d.ts +225 -0
- package/lib/components/Link/index.d.ts +1 -0
- package/lib/components/Menu/Menu.d.ts +379 -0
- package/lib/components/Menu/MenuOptionButton.d.ts +199 -0
- package/lib/components/Menu/index.d.ts +2 -0
- package/lib/components/Modal/Modal.d.ts +354 -0
- package/lib/components/Modal/index.d.ts +14 -0
- package/lib/components/Notification/Notification.d.ts +147 -0
- package/lib/components/Notification/index.d.ts +1 -0
- package/lib/components/OptionButton/OptionButton.d.ts +150 -0
- package/lib/components/OptionButton/SimpleOptionButton.d.ts +150 -0
- package/lib/components/OptionButton/index.d.ts +2 -0
- package/lib/components/PageTitle/PageTitle.d.ts +256 -0
- package/lib/components/PageTitle/index.d.ts +1 -0
- package/lib/components/Pagination/Pagination.d.ts +144 -0
- package/lib/components/Pagination/PaginationItem.d.ts +136 -0
- package/lib/components/Pagination/index.d.ts +1 -0
- package/lib/components/Panel/Panel.d.ts +168 -0
- package/lib/components/Panel/index.d.ts +9 -0
- package/lib/components/ProgressDonut/ProgressDonut.d.ts +102 -0
- package/lib/components/ProgressDonut/index.d.ts +1 -0
- package/lib/components/PromptChip/PromptChip.d.ts +167 -0
- package/lib/components/PromptChip/index.d.ts +1 -0
- package/lib/components/PromptInput/PromptInput.d.ts +189 -0
- package/lib/components/PromptInput/index.d.ts +1 -0
- package/lib/components/RadioButton/RadioButton.d.ts +132 -0
- package/lib/components/RadioButton/RadioGroup.d.ts +88 -0
- package/lib/components/RadioButton/index.d.ts +2 -0
- package/lib/components/RadioTile/RadioTile.d.ts +109 -0
- package/lib/components/RadioTile/index.d.ts +1 -0
- package/lib/components/RangeSlider/RangeSlider.d.ts +207 -0
- package/lib/components/RangeSlider/index.d.ts +1 -0
- package/lib/components/Rating/Rating.d.ts +131 -0
- package/lib/components/Rating/index.d.ts +1 -0
- package/lib/components/ScoreBar/ScoreBar.d.ts +122 -0
- package/lib/components/ScoreBar/index.d.ts +1 -0
- package/lib/components/SearchInput/SearchInput.d.ts +79 -0
- package/lib/components/SearchInput/index.d.ts +2 -0
- package/lib/components/Separator/Separator.d.ts +51 -0
- package/lib/components/Separator/index.d.ts +1 -0
- package/lib/components/Shimmer/Shimmer.d.ts +131 -0
- package/lib/components/Shimmer/index.d.ts +1 -0
- package/lib/components/SideMenuLink/SideMenuLink.d.ts +336 -0
- package/lib/components/SideMenuLink/index.d.ts +1 -0
- package/lib/components/StatusIndicator/StatusIndicator.d.ts +60 -0
- package/lib/components/StatusIndicator/index.d.ts +1 -0
- package/lib/components/Stepper/Step/Step.d.ts +119 -0
- package/lib/components/Stepper/Step/StepContent.d.ts +35 -0
- package/lib/components/Stepper/Step/StepLabel.d.ts +35 -0
- package/lib/components/Stepper/Step/index.d.ts +3 -0
- package/lib/components/Stepper/Stepper.d.ts +60 -0
- package/lib/components/Stepper/index.d.ts +2 -0
- package/lib/components/StickyBar/StickyBar.d.ts +55 -0
- package/lib/components/StickyBar/index.d.ts +1 -0
- package/lib/components/SubMenu/SubMenu.d.ts +89 -0
- package/lib/components/SubMenu/SubMenuGroup.d.ts +156 -0
- package/lib/components/SubMenu/SubMenuItem.d.ts +161 -0
- package/lib/components/SubMenu/SubMenuLink.d.ts +81 -0
- package/lib/components/SubMenu/index.d.ts +4 -0
- package/lib/components/Table/Cell.d.ts +107 -0
- package/lib/components/Table/DefaultRow.d.ts +144 -0
- package/lib/components/Table/DefaultTableHeader.d.ts +236 -0
- package/lib/components/Table/StaticTable.d.ts +198 -0
- package/lib/components/Table/Table.d.ts +113 -0
- package/lib/components/Table/Table.docs.d.ts +532 -0
- package/lib/components/Table/TableActionBar.d.ts +48 -0
- package/lib/components/Table/TableBottomBar.d.ts +20 -0
- package/lib/components/Table/TableTopBar.d.ts +20 -0
- package/lib/components/Table/dummyTableData.d.ts +2189 -0
- package/lib/components/Table/hooks.d.ts +98 -0
- package/lib/components/Table/index.d.ts +8 -0
- package/lib/components/Tabs/Tab/Tab.d.ts +146 -0
- package/lib/components/Tabs/Tab/index.d.ts +1 -0
- package/lib/components/Tabs/TabList/TabDropdown.d.ts +100 -0
- package/lib/components/Tabs/TabList/TabList.d.ts +157 -0
- package/lib/components/Tabs/TabList/index.d.ts +1 -0
- package/lib/components/Tabs/index.d.ts +2 -0
- package/lib/components/Text/Text.d.ts +1021 -0
- package/lib/components/Text/index.d.ts +30 -0
- package/lib/components/TextTile/TextTile.d.ts +40 -0
- package/lib/components/TextTile/index.d.ts +1 -0
- package/lib/components/Textarea/Textarea.d.ts +132 -0
- package/lib/components/Textarea/index.d.ts +2 -0
- package/lib/components/Timeline/Timeline.d.ts +40 -0
- package/lib/components/Timeline/TimelineItem/TimelineItem.d.ts +121 -0
- package/lib/components/Timeline/TimelineItem/index.d.ts +1 -0
- package/lib/components/Timeline/index.d.ts +2 -0
- package/lib/components/Toast/Toast.d.ts +248 -0
- package/lib/components/Toast/ToastContainer.d.ts +140 -0
- package/lib/components/Toast/ToastManager.d.ts +58 -0
- package/lib/components/Toast/index.d.ts +10 -0
- package/lib/components/Toggle/Toggle.d.ts +111 -0
- package/lib/components/Toggle/index.d.ts +1 -0
- package/lib/components/TokenListInput/TokenListInput.d.ts +333 -0
- package/lib/components/TokenListInput/TokenValueChips.d.ts +64 -0
- package/lib/components/TokenListInput/index.d.ts +1 -0
- package/lib/components/Tooltip/Tooltip.d.ts +186 -0
- package/lib/components/Tooltip/index.d.ts +1 -0
- package/lib/components/Truncate/Truncate.d.ts +87 -0
- package/lib/components/Truncate/index.d.ts +2 -0
- package/lib/components/TruncatedTextWithTooltip/TruncatedTextWithTooltip.d.ts +95 -0
- package/lib/components/TruncatedTextWithTooltip/index.d.ts +1 -0
- package/lib/components/Typeahead/SimpleTypeahead.d.ts +141 -0
- package/lib/components/Typeahead/Typeahead.d.ts +217 -0
- package/lib/components/Typeahead/index.d.ts +2 -0
- package/lib/components/WeekdayPicker/WeekdayPicker.d.ts +242 -0
- package/lib/components/WeekdayPicker/index.d.ts +1 -0
- package/lib/components/index.d.ts +71 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/useArbitraryOptionAddition/index.d.ts +1 -0
- package/lib/hooks/useArbitraryOptionAddition/useArbitraryOptionAddition.d.ts +124 -0
- package/lib/hooks/useCopyToClipboard/index.d.ts +1 -0
- package/lib/hooks/useCopyToClipboard/useCopyToClipboard.d.ts +27 -0
- package/lib/hooks/useFileUpload/index.d.ts +1 -0
- package/lib/hooks/useFileUpload/useFileUpload.d.ts +342 -0
- package/lib/hooks/useFilteredOptions/index.d.ts +1 -0
- package/lib/hooks/useFilteredOptions/useFilteredOptions.d.ts +87 -0
- package/lib/hooks/useInputState/index.d.ts +1 -0
- package/lib/hooks/useInputState/useInputState.d.ts +22 -0
- package/lib/hooks/useLockedBody/index.d.ts +1 -0
- package/lib/hooks/useLockedBody/useLockedBody.d.ts +46 -0
- package/lib/hooks/useModal/index.d.ts +1 -0
- package/lib/hooks/useModal/useModal.d.ts +32 -0
- package/lib/hooks/useMountTransition/index.d.ts +24 -0
- package/lib/hooks/usePagination/index.d.ts +1 -0
- package/lib/hooks/usePagination/usePagination.d.ts +140 -0
- package/lib/hooks/useToastPortal/index.d.ts +1 -0
- package/lib/hooks/useToastPortal/useToastPortal.d.ts +31 -0
- package/lib/hooks/useToggle/index.d.ts +1 -0
- package/lib/hooks/useToggle/useToggle.d.ts +11 -0
- package/lib/hooks/useWindowSize/index.d.ts +1 -0
- package/lib/hooks/useWindowSize/useWindowSize.d.ts +28 -0
- package/lib/index.d.ts +5 -0
- package/lib/styles/index.d.ts +267 -0
- package/lib/styles/variables/_border.d.ts +12 -0
- package/lib/styles/variables/_color.d.ts +104 -0
- package/lib/styles/variables/_elevation.d.ts +7 -0
- package/lib/styles/variables/_font.d.ts +30 -0
- package/lib/styles/variables/_motion.d.ts +6 -0
- package/lib/styles/variables/_opacity.d.ts +15 -0
- package/lib/styles/variables/_shadow.d.ts +24 -0
- package/lib/styles/variables/_size.d.ts +57 -0
- package/lib/styles/variables/_space.d.ts +12 -0
- package/lib/types/charts.d.ts +225 -0
- package/lib/types/common.d.ts +10 -0
- package/lib/types/date-range-picker.d.ts +17 -0
- package/lib/types/date-range-picker.js.flow +2 -3
- package/lib/types/index.d.ts +6 -0
- package/lib/types/menu.d.ts +13 -0
- package/lib/types/toast.d.ts +32 -0
- package/lib/types/typography.d.ts +17 -0
- package/lib/utils/array/are-arrays-equal.d.ts +11 -0
- package/lib/utils/array/index.d.ts +1 -0
- package/lib/utils/charts/charts.d.ts +102 -0
- package/lib/utils/charts/columnChart.d.ts +51 -0
- package/lib/utils/charts/donutChart.d.ts +116 -0
- package/lib/utils/charts/funnelChart.d.ts +94 -0
- package/lib/utils/charts/helpers.d.ts +44 -0
- package/lib/utils/charts/index.d.ts +7 -0
- package/lib/utils/charts/lineChart.d.ts +44 -0
- package/lib/utils/charts/spiderChart.d.ts +46 -0
- package/lib/utils/charts/typography.d.ts +42 -0
- package/lib/utils/classify/index.d.ts +27 -0
- package/lib/utils/click-away/click-away.d.ts +194 -0
- package/lib/utils/click-away/index.d.ts +1 -0
- package/lib/utils/date-range-picker/date-range-picker.d.ts +391 -0
- package/lib/utils/date-range-picker/index.d.ts +2 -0
- package/lib/utils/date-range-picker/timezones.d.ts +262 -0
- package/lib/utils/dom/dom.d.ts +245 -0
- package/lib/utils/dom/index.d.ts +1 -0
- package/lib/utils/helpers/helpers.d.ts +48 -0
- package/lib/utils/helpers/index.d.ts +1 -0
- package/lib/utils/index.d.ts +14 -0
- package/lib/utils/makeClassNameComponent/index.d.ts +1 -0
- package/lib/utils/makeClassNameComponent/makeClassNameComponent.d.ts +73 -0
- package/lib/utils/menu/index.d.ts +1 -0
- package/lib/utils/merge-refs/index.d.ts +1 -0
- package/lib/utils/merge-refs/merge-refs.d.ts +15 -0
- package/lib/utils/rating/index.d.ts +1 -0
- package/lib/utils/rating/rating.d.ts +31 -0
- package/lib/utils/score-bar/index.d.ts +1 -0
- package/lib/utils/score-bar/score-bar.d.ts +54 -0
- package/lib/utils/string/index.d.ts +1 -0
- package/lib/utils/string/string.d.ts +30 -0
- package/lib/utils/token-list-input/token-list-input.d.ts +32 -0
- package/lib/utils/tokens/index.d.ts +1 -0
- package/lib/utils/tokens/tokens.d.ts +230 -0
- package/package.json +5 -5
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import {$ReadOnly} from 'utility-types';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
// $FlowFixMe[untyped-import]
|
|
5
|
+
autoUpdate, // $FlowFixMe[untyped-import]
|
|
6
|
+
flip, // $FlowFixMe[untyped-import]
|
|
7
|
+
offset, // $FlowFixMe[untyped-import]
|
|
8
|
+
useFloating,
|
|
9
|
+
} from '@floating-ui/react';
|
|
10
|
+
import {sizeFluid} from '../../styles/variables/_size';
|
|
11
|
+
import {spaceNone, spaceXXSmall} from '../../styles/variables/_space';
|
|
12
|
+
import {classify} from '../../utils/classify';
|
|
13
|
+
import type {ClickAwayRefType} from '../../utils/click-away';
|
|
14
|
+
import {ClickAway} from '../../utils/click-away';
|
|
15
|
+
import {mergeRefs} from '../../utils/merge-refs';
|
|
16
|
+
import type {InputProps} from '../Input';
|
|
17
|
+
import type {MenuOption, MenuProps} from '../Menu';
|
|
18
|
+
import {Menu} from '../Menu';
|
|
19
|
+
import {SearchInput} from '../SearchInput';
|
|
20
|
+
import css from './Typeahead.module.css';
|
|
21
|
+
type ClassNames = $ReadOnly<{
|
|
22
|
+
wrapper?: string;
|
|
23
|
+
box?: string;
|
|
24
|
+
}>;
|
|
25
|
+
type BaseTypeaheadProps = InputProps & {
|
|
26
|
+
classNames?: ClassNames;
|
|
27
|
+
onSelect?: (
|
|
28
|
+
option: MenuOption,
|
|
29
|
+
arg1: React.SyntheticEvent<HTMLElement> | null | undefined,
|
|
30
|
+
) => unknown;
|
|
31
|
+
onSearch?: (evt: React.SyntheticEvent<HTMLInputElement>) => unknown;
|
|
32
|
+
onMenuOpen?: () => unknown;
|
|
33
|
+
onMenuClose?: () => unknown;
|
|
34
|
+
typeaheadInputText?: string;
|
|
35
|
+
menu?: MenuProps;
|
|
36
|
+
onClear?: () => void;
|
|
37
|
+
isLoading?: boolean;
|
|
38
|
+
menuOpenOffset?: number;
|
|
39
|
+
clickAwayRef?: ClickAwayRefType;
|
|
40
|
+
};
|
|
41
|
+
export type TypeaheadProps = BaseTypeaheadProps & {
|
|
42
|
+
allowInternalFilter?: boolean;
|
|
43
|
+
};
|
|
44
|
+
const BaseTypeahead: React$AbstractComponent<
|
|
45
|
+
BaseTypeaheadProps,
|
|
46
|
+
HTMLInputElement
|
|
47
|
+
> = React.forwardRef<BaseTypeaheadProps, HTMLInputElement>(
|
|
48
|
+
(
|
|
49
|
+
{
|
|
50
|
+
size = 'medium',
|
|
51
|
+
classNames,
|
|
52
|
+
placeholder = 'Select...',
|
|
53
|
+
onSelect,
|
|
54
|
+
onSearch,
|
|
55
|
+
onClear,
|
|
56
|
+
menu,
|
|
57
|
+
onMenuOpen,
|
|
58
|
+
onMenuClose,
|
|
59
|
+
typeaheadInputText = '',
|
|
60
|
+
isLoading,
|
|
61
|
+
menuOpenOffset = 1,
|
|
62
|
+
onFocus,
|
|
63
|
+
clickAwayRef,
|
|
64
|
+
...inputProps
|
|
65
|
+
}: BaseTypeaheadProps,
|
|
66
|
+
ref,
|
|
67
|
+
): React.ReactNode => {
|
|
68
|
+
const menuOptions = menu?.options;
|
|
69
|
+
const {x, y, refs, strategy} = useFloating({
|
|
70
|
+
open: true,
|
|
71
|
+
strategy: 'absolute',
|
|
72
|
+
placement: 'bottom-start',
|
|
73
|
+
whileElementsMounted: autoUpdate,
|
|
74
|
+
middleware: [flip(), offset(parseInt(spaceXXSmall))],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const onMenuToggle = (isOpen: boolean) => {
|
|
78
|
+
isOpen ? onMenuOpen && onMenuOpen() : onMenuClose && onMenuClose();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<ClickAway onChange={onMenuToggle} clickAwayRef={clickAwayRef}>
|
|
83
|
+
{({isOpen, onOpen, clickAway, boundaryRef, triggerRef}) => (
|
|
84
|
+
<div
|
|
85
|
+
data-testid="Typeahead"
|
|
86
|
+
className={classify(css.typeaheadContainer, classNames?.wrapper)}
|
|
87
|
+
ref={boundaryRef}
|
|
88
|
+
>
|
|
89
|
+
<SearchInput
|
|
90
|
+
{...inputProps}
|
|
91
|
+
ref={ref}
|
|
92
|
+
boxRef={mergeRefs([refs.setReference, triggerRef])}
|
|
93
|
+
size={size}
|
|
94
|
+
placeholder={placeholder}
|
|
95
|
+
value={typeaheadInputText}
|
|
96
|
+
classNames={{
|
|
97
|
+
box: classNames?.box,
|
|
98
|
+
}}
|
|
99
|
+
isLoading={isLoading}
|
|
100
|
+
onChange={(e) => {
|
|
101
|
+
e.stopPropagation();
|
|
102
|
+
onSearch && onSearch(e);
|
|
103
|
+
|
|
104
|
+
if (e.target.value.length >= menuOpenOffset) {
|
|
105
|
+
!isOpen && onOpen();
|
|
106
|
+
} else {
|
|
107
|
+
clickAway();
|
|
108
|
+
}
|
|
109
|
+
}}
|
|
110
|
+
onFocus={(_e) => {
|
|
111
|
+
if (typeaheadInputText.length >= menuOpenOffset) {
|
|
112
|
+
!isOpen && onOpen();
|
|
113
|
+
} else {
|
|
114
|
+
clickAway();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
onFocus?.(_e);
|
|
118
|
+
}}
|
|
119
|
+
onClear={(_e) => {
|
|
120
|
+
onClear?.();
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
{isOpen &&
|
|
124
|
+
!isLoading &&
|
|
125
|
+
menu &&
|
|
126
|
+
menuOptions &&
|
|
127
|
+
!!menuOptions.length && (
|
|
128
|
+
<div
|
|
129
|
+
ref={refs.setFloating}
|
|
130
|
+
style={{
|
|
131
|
+
position: strategy,
|
|
132
|
+
top: y ?? spaceNone,
|
|
133
|
+
left: x ?? spaceNone,
|
|
134
|
+
width: sizeFluid,
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
<Menu
|
|
138
|
+
{...menu}
|
|
139
|
+
options={menuOptions}
|
|
140
|
+
onSelect={(option, e) => {
|
|
141
|
+
onSelect && onSelect(option, e);
|
|
142
|
+
|
|
143
|
+
if (
|
|
144
|
+
// option.keepMenuOpenOnOptionSelect - to allow the menu persist its open stat upon option selection in normal variant
|
|
145
|
+
!option.keepMenuOpenOnOptionSelect &&
|
|
146
|
+
(!menu.optionsVariant ||
|
|
147
|
+
menu.optionsVariant === 'normal')
|
|
148
|
+
) {
|
|
149
|
+
clickAway();
|
|
150
|
+
}
|
|
151
|
+
}}
|
|
152
|
+
size={menu.size || size}
|
|
153
|
+
onTabOut={clickAway}
|
|
154
|
+
/>
|
|
155
|
+
</div>
|
|
156
|
+
)}
|
|
157
|
+
</div>
|
|
158
|
+
)}
|
|
159
|
+
</ClickAway>
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
);
|
|
163
|
+
const StatefulTypeahead: React$AbstractComponent<
|
|
164
|
+
BaseTypeaheadProps,
|
|
165
|
+
HTMLInputElement
|
|
166
|
+
> = React.forwardRef<BaseTypeaheadProps, HTMLInputElement>(
|
|
167
|
+
({menu, ...props}: BaseTypeaheadProps, ref): React.ReactNode => {
|
|
168
|
+
const {typeaheadInputText = ''} = props;
|
|
169
|
+
const [filteredOptions, setFilteredOptions] = React.useState(menu?.options);
|
|
170
|
+
React.useEffect(() => {
|
|
171
|
+
const optionsFiltered =
|
|
172
|
+
menu?.options &&
|
|
173
|
+
menu.options.filter((option) => {
|
|
174
|
+
if (!option.label || !typeaheadInputText) {
|
|
175
|
+
return true;
|
|
176
|
+
} else {
|
|
177
|
+
return (
|
|
178
|
+
option.label
|
|
179
|
+
.toLowerCase()
|
|
180
|
+
.indexOf(typeaheadInputText.toLowerCase()) !== -1
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
setFilteredOptions(optionsFiltered || []);
|
|
185
|
+
}, [typeaheadInputText, menu?.options]);
|
|
186
|
+
return (
|
|
187
|
+
<BaseTypeahead
|
|
188
|
+
{...props}
|
|
189
|
+
menu={{...menu, options: filteredOptions}}
|
|
190
|
+
ref={ref}
|
|
191
|
+
/>
|
|
192
|
+
);
|
|
193
|
+
},
|
|
194
|
+
);
|
|
195
|
+
const StatelessTypeahead: React$AbstractComponent<
|
|
196
|
+
BaseTypeaheadProps,
|
|
197
|
+
HTMLInputElement
|
|
198
|
+
> = React.forwardRef<BaseTypeaheadProps, HTMLInputElement>(
|
|
199
|
+
(props: BaseTypeaheadProps, ref): React.ReactNode => (
|
|
200
|
+
<BaseTypeahead {...props} ref={ref} />
|
|
201
|
+
),
|
|
202
|
+
);
|
|
203
|
+
export const Typeahead: React$AbstractComponent<
|
|
204
|
+
TypeaheadProps,
|
|
205
|
+
HTMLInputElement
|
|
206
|
+
> = React.forwardRef<TypeaheadProps, HTMLInputElement>(
|
|
207
|
+
(
|
|
208
|
+
{allowInternalFilter = true, ...props}: TypeaheadProps,
|
|
209
|
+
ref,
|
|
210
|
+
): React.ReactNode => {
|
|
211
|
+
if (allowInternalFilter) {
|
|
212
|
+
return <StatefulTypeahead {...props} ref={ref} />;
|
|
213
|
+
} else {
|
|
214
|
+
return <StatelessTypeahead {...props} ref={ref} />;
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
);
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import {$ReadOnly, $Values} from 'utility-types';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import classify from '../../utils/classify';
|
|
4
|
+
import {UnstyledButton} from '../Button';
|
|
5
|
+
import css from './WeekdayPicker.module.css';
|
|
6
|
+
const DEFAULT_WEEKDAYS = [
|
|
7
|
+
{
|
|
8
|
+
key: 'sun',
|
|
9
|
+
label: 'S',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
key: 'mon',
|
|
13
|
+
label: 'M',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
key: 'tue',
|
|
17
|
+
label: 'T',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
key: 'wed',
|
|
21
|
+
label: 'W',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: 'thu',
|
|
25
|
+
label: 'T',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: 'fri',
|
|
29
|
+
label: 'F',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: 'sat',
|
|
33
|
+
label: 'S',
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
const WEEKEND_KEYS = ['sat', 'sun'];
|
|
37
|
+
export const WEEKDAY_PICKER_SIZE = Object.freeze({
|
|
38
|
+
small: 'small',
|
|
39
|
+
medium: 'medium',
|
|
40
|
+
});
|
|
41
|
+
type ClassNames = $ReadOnly<{
|
|
42
|
+
wrapper?: string;
|
|
43
|
+
button?: string;
|
|
44
|
+
label?: string;
|
|
45
|
+
helperText?: string;
|
|
46
|
+
}>;
|
|
47
|
+
type WeekdayPickerSize = $Values<typeof WEEKDAY_PICKER_SIZE>;
|
|
48
|
+
type Weekday = {
|
|
49
|
+
key: string;
|
|
50
|
+
label: string;
|
|
51
|
+
secondaryLabel?: string;
|
|
52
|
+
};
|
|
53
|
+
export type WeekdayPickerProps = {
|
|
54
|
+
size?: WeekdayPickerSize;
|
|
55
|
+
selectedWeekDays?: Array<Weekday>;
|
|
56
|
+
hiddenWeekDays?: Array<string>;
|
|
57
|
+
disabledWeekDays?: Array<string>;
|
|
58
|
+
customDayLabels?: Array<Weekday>;
|
|
59
|
+
onChange?: (
|
|
60
|
+
selectedDays: Array<Weekday>,
|
|
61
|
+
arg1: React.SyntheticEvent<HTMLElement> | null | undefined,
|
|
62
|
+
) => unknown;
|
|
63
|
+
readOnly?: boolean;
|
|
64
|
+
classNames?: ClassNames;
|
|
65
|
+
showWeekends?: boolean;
|
|
66
|
+
ariaLabel?: string;
|
|
67
|
+
label?: React.ReactNode;
|
|
68
|
+
helperText?: React.ReactNode;
|
|
69
|
+
disableMultiSelect?: boolean;
|
|
70
|
+
};
|
|
71
|
+
type DayButtonProps = {
|
|
72
|
+
day: Weekday;
|
|
73
|
+
isSelected: boolean;
|
|
74
|
+
isDisabled: boolean;
|
|
75
|
+
onClick?:
|
|
76
|
+
| ((arg0: React.SyntheticEvent<HTMLElement>) => unknown)
|
|
77
|
+
| null
|
|
78
|
+
| undefined;
|
|
79
|
+
className?: string;
|
|
80
|
+
size: WeekdayPickerSize;
|
|
81
|
+
readOnly?: boolean;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const DayButton = ({
|
|
85
|
+
day,
|
|
86
|
+
isSelected,
|
|
87
|
+
isDisabled,
|
|
88
|
+
onClick,
|
|
89
|
+
className,
|
|
90
|
+
size,
|
|
91
|
+
readOnly,
|
|
92
|
+
}: DayButtonProps) => (
|
|
93
|
+
<UnstyledButton
|
|
94
|
+
key={day.key}
|
|
95
|
+
className={classify(
|
|
96
|
+
css.weekdayButton,
|
|
97
|
+
{
|
|
98
|
+
[css.weekdayButtonMedium]: size === WEEKDAY_PICKER_SIZE.medium,
|
|
99
|
+
[css.weekdayButtonSmall]: size === WEEKDAY_PICKER_SIZE.small,
|
|
100
|
+
[css.weekdayButtonSelected]: isSelected,
|
|
101
|
+
[css.weekdayButtonDisabled]: isDisabled,
|
|
102
|
+
},
|
|
103
|
+
className,
|
|
104
|
+
)}
|
|
105
|
+
onClick={onClick}
|
|
106
|
+
disabled={isDisabled}
|
|
107
|
+
aria-label={`Select ${day.label}`}
|
|
108
|
+
tabIndex={isDisabled || readOnly ? -1 : 0}
|
|
109
|
+
role="checkbox"
|
|
110
|
+
>
|
|
111
|
+
{day.secondaryLabel && (
|
|
112
|
+
<div
|
|
113
|
+
className={classify(css.secondaryLabel, {
|
|
114
|
+
[css.secondaryLabelSelected]: isSelected,
|
|
115
|
+
[css.secondaryLabelDisabled]: isDisabled,
|
|
116
|
+
})}
|
|
117
|
+
>
|
|
118
|
+
{day.secondaryLabel}
|
|
119
|
+
</div>
|
|
120
|
+
)}
|
|
121
|
+
{day.label}
|
|
122
|
+
</UnstyledButton>
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
export const WeekdayPicker: React$AbstractComponent<
|
|
126
|
+
WeekdayPickerProps,
|
|
127
|
+
HTMLDivElement
|
|
128
|
+
> = React.forwardRef<WeekdayPickerProps, HTMLDivElement>(
|
|
129
|
+
(
|
|
130
|
+
{
|
|
131
|
+
size = 'medium',
|
|
132
|
+
selectedWeekDays = [],
|
|
133
|
+
disabledWeekDays = [],
|
|
134
|
+
hiddenWeekDays = [],
|
|
135
|
+
customDayLabels = DEFAULT_WEEKDAYS,
|
|
136
|
+
onChange,
|
|
137
|
+
readOnly = false,
|
|
138
|
+
classNames = {},
|
|
139
|
+
showWeekends = true,
|
|
140
|
+
ariaLabel = 'Select weekdays',
|
|
141
|
+
label,
|
|
142
|
+
helperText,
|
|
143
|
+
disableMultiSelect = false,
|
|
144
|
+
}: WeekdayPickerProps,
|
|
145
|
+
ref,
|
|
146
|
+
) => {
|
|
147
|
+
const [selectedDays, setSelectedDays] =
|
|
148
|
+
React.useState<Array<Weekday>>(selectedWeekDays);
|
|
149
|
+
|
|
150
|
+
const handleDayToggle = (
|
|
151
|
+
day: Weekday,
|
|
152
|
+
event: React.SyntheticEvent<HTMLElement>,
|
|
153
|
+
) => {
|
|
154
|
+
if (readOnly || disabledWeekDays.includes(day.key)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let updatedSelectedDays = selectedDays;
|
|
159
|
+
|
|
160
|
+
if (disableMultiSelect) {
|
|
161
|
+
if (selectedDays.some((selected) => selected.key === day.key)) {
|
|
162
|
+
updatedSelectedDays = [];
|
|
163
|
+
} else {
|
|
164
|
+
updatedSelectedDays = [day];
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
const isSelected = selectedDays.some(
|
|
168
|
+
(selected) => selected.key === day.key,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
if (isSelected) {
|
|
172
|
+
updatedSelectedDays = selectedDays.filter(
|
|
173
|
+
(selected) => selected.key !== day.key,
|
|
174
|
+
);
|
|
175
|
+
} else {
|
|
176
|
+
updatedSelectedDays = [...selectedDays, day];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
setSelectedDays(updatedSelectedDays);
|
|
181
|
+
onChange?.(updatedSelectedDays, event);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<div
|
|
186
|
+
data-testid="Weekday-Picker"
|
|
187
|
+
ref={ref}
|
|
188
|
+
className={classify(css.weekdayPickerContainer, classNames.wrapper, {
|
|
189
|
+
[css.weekdayReadOnly]: readOnly,
|
|
190
|
+
})}
|
|
191
|
+
aria-label={ariaLabel}
|
|
192
|
+
role="group"
|
|
193
|
+
>
|
|
194
|
+
{!!label && (
|
|
195
|
+
<div className={classify(css.weekdayLabel, classNames.label)}>
|
|
196
|
+
{label}
|
|
197
|
+
</div>
|
|
198
|
+
)}
|
|
199
|
+
<div className={css.weekdayPickerDays}>
|
|
200
|
+
{customDayLabels.map((day) => {
|
|
201
|
+
const isWeekend = WEEKEND_KEYS.includes(day.key);
|
|
202
|
+
const isHidden = hiddenWeekDays.includes(day.key);
|
|
203
|
+
|
|
204
|
+
if ((!showWeekends && isWeekend) || isHidden) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const isSelected = selectedDays.some(
|
|
209
|
+
(selected) => selected.key === day.key,
|
|
210
|
+
);
|
|
211
|
+
const isDisabled = disabledWeekDays.includes(day.key);
|
|
212
|
+
return (
|
|
213
|
+
<DayButton
|
|
214
|
+
key={day.key}
|
|
215
|
+
day={day}
|
|
216
|
+
isSelected={isSelected}
|
|
217
|
+
isDisabled={isDisabled}
|
|
218
|
+
onClick={(event) => {
|
|
219
|
+
if (isDisabled) {
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
} else {
|
|
222
|
+
handleDayToggle(day, event);
|
|
223
|
+
}
|
|
224
|
+
}}
|
|
225
|
+
className={classNames.button}
|
|
226
|
+
size={size}
|
|
227
|
+
readOnly={readOnly}
|
|
228
|
+
/>
|
|
229
|
+
);
|
|
230
|
+
})}
|
|
231
|
+
</div>
|
|
232
|
+
{!!helperText && (
|
|
233
|
+
<div
|
|
234
|
+
className={classify(css.weekdayHelperText, classNames.helperText)}
|
|
235
|
+
>
|
|
236
|
+
{helperText}
|
|
237
|
+
</div>
|
|
238
|
+
)}
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
},
|
|
242
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './WeekdayPicker';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export * from './Avatar';
|
|
2
|
+
export * from './AvatarGroup';
|
|
3
|
+
export * from './Badge';
|
|
4
|
+
export * from './Banner';
|
|
5
|
+
export * from './Breadcrumbs';
|
|
6
|
+
export * from './Button';
|
|
7
|
+
export * from './ButtonDropdown';
|
|
8
|
+
export * from './ButtonTabs';
|
|
9
|
+
export * from './Card';
|
|
10
|
+
export * from './Charts';
|
|
11
|
+
export * from './ChatBubble';
|
|
12
|
+
export * from './Checkbox';
|
|
13
|
+
export * from './Chip';
|
|
14
|
+
export * from './CircularLoader';
|
|
15
|
+
export * from './CollapsibleCard';
|
|
16
|
+
export * from './Combobox';
|
|
17
|
+
export * from './ConditionalWrapper';
|
|
18
|
+
export * from './DateRangePicker';
|
|
19
|
+
export * from './Dialog';
|
|
20
|
+
export * from './Disclaimer';
|
|
21
|
+
export * from './Dropdown';
|
|
22
|
+
export * from './EmptyState';
|
|
23
|
+
export * from './ErrorMessage';
|
|
24
|
+
export * from './FileUpload';
|
|
25
|
+
export * from './FocusManager';
|
|
26
|
+
export * from './FocusManagerWithArrowKeyNavigation';
|
|
27
|
+
export * from './FormTitleWrapper';
|
|
28
|
+
export * from './Grid';
|
|
29
|
+
export * from './Icon';
|
|
30
|
+
export * from './InContextAlert';
|
|
31
|
+
export * from './InlineDropdown';
|
|
32
|
+
export * from './Input';
|
|
33
|
+
export * from './KPIBox';
|
|
34
|
+
export * from './LinearLoader';
|
|
35
|
+
export * from './Link';
|
|
36
|
+
export * from './Menu';
|
|
37
|
+
export * from './Modal';
|
|
38
|
+
export * from './Notification';
|
|
39
|
+
export * from './OptionButton';
|
|
40
|
+
export * from './PageTitle';
|
|
41
|
+
export * from './Pagination';
|
|
42
|
+
export * from './Panel';
|
|
43
|
+
export * from './ProgressDonut';
|
|
44
|
+
export * from './PromptChip';
|
|
45
|
+
export * from './PromptInput';
|
|
46
|
+
export * from './RadioButton';
|
|
47
|
+
export * from './RadioTile';
|
|
48
|
+
export * from './RangeSlider';
|
|
49
|
+
export * from './Rating';
|
|
50
|
+
export * from './ScoreBar';
|
|
51
|
+
export * from './SearchInput';
|
|
52
|
+
export * from './Separator';
|
|
53
|
+
export * from './Shimmer';
|
|
54
|
+
export * from './SideMenuLink';
|
|
55
|
+
export * from './StatusIndicator';
|
|
56
|
+
export * from './Stepper';
|
|
57
|
+
export * from './StickyBar';
|
|
58
|
+
export * from './SubMenu';
|
|
59
|
+
export * from './Table';
|
|
60
|
+
export * from './Tabs';
|
|
61
|
+
export * from './Text';
|
|
62
|
+
export * from './Textarea';
|
|
63
|
+
export * from './TextTile';
|
|
64
|
+
export * from './Toast';
|
|
65
|
+
export * from './Toggle';
|
|
66
|
+
export * from './TokenListInput';
|
|
67
|
+
export * from './Tooltip';
|
|
68
|
+
export * from './Truncate';
|
|
69
|
+
export * from './TruncatedTextWithTooltip';
|
|
70
|
+
export * from './Typeahead';
|
|
71
|
+
export * from './WeekdayPicker';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './useArbitraryOptionAddition';
|
|
2
|
+
export * from './useCopyToClipboard';
|
|
3
|
+
export * from './useFileUpload';
|
|
4
|
+
export * from './useFilteredOptions';
|
|
5
|
+
export * from './useInputState';
|
|
6
|
+
export * from './useLockedBody';
|
|
7
|
+
export * from './useModal';
|
|
8
|
+
export * from './useMountTransition';
|
|
9
|
+
export * from './usePagination';
|
|
10
|
+
export * from './useToastPortal';
|
|
11
|
+
export * from './useToggle';
|
|
12
|
+
export * from './useWindowSize';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useArbitraryOptionAddition';
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type {GroupTitleOption} from '../useFilteredOptions';
|
|
2
|
+
import {useFilteredOptions} from '../useFilteredOptions';
|
|
3
|
+
export type ArbitraryOption = {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
arbitrary?: boolean;
|
|
7
|
+
multiArbitrary?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export function useArbitraryOptionAddition<V>({
|
|
10
|
+
searchTerm,
|
|
11
|
+
options = [],
|
|
12
|
+
excludedKeys = [],
|
|
13
|
+
allowArbitraryValues = true,
|
|
14
|
+
allowMultiArbitraryValues = false,
|
|
15
|
+
validateArbitraryValue = (value: string): boolean => value.trim() !== '',
|
|
16
|
+
// $FlowFixMe[incompatible-return] - Object literal is compatible with V due to type constraint
|
|
17
|
+
makeArbitraryValue = (searchTerm): V => ({
|
|
18
|
+
key: searchTerm,
|
|
19
|
+
label: searchTerm,
|
|
20
|
+
arbitrary: true,
|
|
21
|
+
}),
|
|
22
|
+
// $FlowFixMe[incompatible-return] - Object literal is compatible with V due to type constraint
|
|
23
|
+
makeMultiArbitraryValue = (searchTerm): V => {
|
|
24
|
+
const regex = /^(?=.*[,\n]).+$/s;
|
|
25
|
+
|
|
26
|
+
if (regex.test(searchTerm)) {
|
|
27
|
+
// $FlowFixMe - Object literal is compatible with V due to type constraint
|
|
28
|
+
return {
|
|
29
|
+
key: searchTerm,
|
|
30
|
+
label: searchTerm,
|
|
31
|
+
multiArbitrary: true,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
groupTitleOptions = [],
|
|
36
|
+
arbitraryGroup = {
|
|
37
|
+
groupTitle: '',
|
|
38
|
+
showLineDivider: false,
|
|
39
|
+
options: [],
|
|
40
|
+
},
|
|
41
|
+
searchOptionsBy = (option: V, searchTerm: string): boolean => {
|
|
42
|
+
// $FlowFixMe
|
|
43
|
+
const {
|
|
44
|
+
label,
|
|
45
|
+
key,
|
|
46
|
+
}: {
|
|
47
|
+
label: string;
|
|
48
|
+
key: string;
|
|
49
|
+
} = option;
|
|
50
|
+
return (
|
|
51
|
+
key.toLowerCase().includes(searchTerm) ||
|
|
52
|
+
label.toLowerCase().includes(searchTerm)
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
}: {
|
|
56
|
+
searchTerm: string;
|
|
57
|
+
options?: V[];
|
|
58
|
+
excludedKeys?: string[];
|
|
59
|
+
allowArbitraryValues?: boolean;
|
|
60
|
+
allowMultiArbitraryValues?: boolean;
|
|
61
|
+
validateArbitraryValue?: (arg0: string) => boolean;
|
|
62
|
+
makeArbitraryValue?: (arg0: string) => V;
|
|
63
|
+
makeMultiArbitraryValue?: (arg0: string) => V;
|
|
64
|
+
groupTitleOptions?: GroupTitleOption<V>[];
|
|
65
|
+
arbitraryGroup?: GroupTitleOption<V>;
|
|
66
|
+
searchOptionsBy?: (option: V, searchTerm: string) => boolean;
|
|
67
|
+
}): {
|
|
68
|
+
optionsWithArbitrary: Array<V>;
|
|
69
|
+
groupTitleOptionsWithArbitrary: Array<GroupTitleOption<V>>;
|
|
70
|
+
} {
|
|
71
|
+
const trimmedSearchTerm = (searchTerm || '').trim().toLowerCase();
|
|
72
|
+
const {filteredOptions, filteredGroupTitleOptions} = useFilteredOptions({
|
|
73
|
+
searchTerm: trimmedSearchTerm,
|
|
74
|
+
options,
|
|
75
|
+
// $FlowFixMe[incompatible-call]
|
|
76
|
+
groupTitleOptions,
|
|
77
|
+
searchOptionsBy,
|
|
78
|
+
});
|
|
79
|
+
// Find if an arbitrary option should be added
|
|
80
|
+
const arbitraryOption =
|
|
81
|
+
allowArbitraryValues &&
|
|
82
|
+
trimmedSearchTerm && // $FlowFixMe - Array methods are valid here
|
|
83
|
+
!filteredOptions.some((option) => option.key === trimmedSearchTerm) && // $FlowFixMe - Array methods are valid here
|
|
84
|
+
!filteredGroupTitleOptions.some(
|
|
85
|
+
(group) =>
|
|
86
|
+
Array.isArray(group.options) && // $FlowFixMe- option has key property
|
|
87
|
+
group.options.some((option) => option.key === trimmedSearchTerm),
|
|
88
|
+
) &&
|
|
89
|
+
!excludedKeys.includes(trimmedSearchTerm) &&
|
|
90
|
+
validateArbitraryValue(trimmedSearchTerm) &&
|
|
91
|
+
makeArbitraryValue(trimmedSearchTerm);
|
|
92
|
+
// Find if a multi-arbitrary option should be added
|
|
93
|
+
const multiArbitraryOption =
|
|
94
|
+
allowMultiArbitraryValues &&
|
|
95
|
+
trimmedSearchTerm &&
|
|
96
|
+
makeMultiArbitraryValue(trimmedSearchTerm);
|
|
97
|
+
// Compose the results
|
|
98
|
+
let optionsWithArbitrary = filteredOptions;
|
|
99
|
+
let groupTitleOptionsWithArbitrary = groupTitleOptions;
|
|
100
|
+
|
|
101
|
+
if (arbitraryOption) {
|
|
102
|
+
// $FlowFixMe[incompatible-type] - Array spread is valid here
|
|
103
|
+
optionsWithArbitrary = [arbitraryOption, ...optionsWithArbitrary];
|
|
104
|
+
groupTitleOptionsWithArbitrary = [
|
|
105
|
+
{...arbitraryGroup, options: [arbitraryOption]},
|
|
106
|
+
...groupTitleOptionsWithArbitrary,
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (multiArbitraryOption) {
|
|
111
|
+
// $FlowFixMe[incompatible-type] - Array spread is valid here
|
|
112
|
+
optionsWithArbitrary = [multiArbitraryOption, ...optionsWithArbitrary];
|
|
113
|
+
groupTitleOptionsWithArbitrary = [
|
|
114
|
+
{...arbitraryGroup, options: [multiArbitraryOption]},
|
|
115
|
+
...groupTitleOptionsWithArbitrary,
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// $FlowFixMe[incompatible-return]
|
|
120
|
+
return {
|
|
121
|
+
optionsWithArbitrary,
|
|
122
|
+
groupTitleOptionsWithArbitrary,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useCopyToClipboard';
|