@codeleap/web 6.8.0 → 7.0.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/dist/components/ActivityIndicator/index.js +28 -0
- package/dist/components/ActivityIndicator/index.js.map +1 -0
- package/dist/components/ActivityIndicator/styles.js +2 -0
- package/dist/components/ActivityIndicator/styles.js.map +1 -0
- package/dist/components/ActivityIndicator/types.js +2 -0
- package/dist/components/ActivityIndicator/types.js.map +1 -0
- package/dist/components/Badge/index.js +68 -0
- package/dist/components/Badge/index.js.map +1 -0
- package/dist/components/Badge/styles.js +2 -0
- package/dist/components/Badge/styles.js.map +1 -0
- package/dist/components/Badge/types.js +2 -0
- package/dist/components/Badge/types.js.map +1 -0
- package/dist/components/Button/index.js +52 -0
- package/dist/components/Button/index.js.map +1 -0
- package/dist/components/Button/styles.js +2 -0
- package/dist/components/Button/styles.js.map +1 -0
- package/dist/components/Button/types.js +2 -0
- package/dist/components/Button/types.js.map +1 -0
- package/dist/components/Calendar/index.js +50 -0
- package/dist/components/Calendar/index.js.map +1 -0
- package/dist/components/Calendar/styles.js +2 -0
- package/dist/components/Calendar/styles.js.map +1 -0
- package/dist/components/Calendar/types.js +2 -0
- package/dist/components/Calendar/types.js.map +1 -0
- package/dist/components/Carousel/index.js +129 -0
- package/dist/components/Carousel/index.js.map +1 -0
- package/dist/components/Carousel/styles.js +2 -0
- package/dist/components/Carousel/styles.js.map +1 -0
- package/dist/components/Carousel/types.js +2 -0
- package/dist/components/Carousel/types.js.map +1 -0
- package/dist/components/Checkbox/index.js +44 -0
- package/dist/components/Checkbox/index.js.map +1 -0
- package/dist/components/Checkbox/styles.js +2 -0
- package/dist/components/Checkbox/styles.js.map +1 -0
- package/dist/components/Checkbox/types.js +2 -0
- package/dist/components/Checkbox/types.js.map +1 -0
- package/dist/components/Collapse/index.js +27 -0
- package/dist/components/Collapse/index.js.map +1 -0
- package/dist/components/Collapse/styles.js +2 -0
- package/dist/components/Collapse/styles.js.map +1 -0
- package/dist/components/Collapse/types.js +2 -0
- package/dist/components/Collapse/types.js.map +1 -0
- package/dist/components/ColorPicker/index.js +65 -0
- package/dist/components/ColorPicker/index.js.map +1 -0
- package/dist/components/ColorPicker/styles.js +2 -0
- package/dist/components/ColorPicker/styles.js.map +1 -0
- package/dist/components/ColorPicker/types.js +2 -0
- package/dist/components/ColorPicker/types.js.map +1 -0
- package/dist/components/CropPicker/hooks.js +130 -0
- package/dist/components/CropPicker/hooks.js.map +1 -0
- package/dist/components/CropPicker/index.js +38 -0
- package/dist/components/CropPicker/index.js.map +1 -0
- package/dist/components/CropPicker/styles.js +2 -0
- package/dist/components/CropPicker/styles.js.map +1 -0
- package/dist/components/CropPicker/types.js +2 -0
- package/dist/components/CropPicker/types.js.map +1 -0
- package/dist/components/CropPicker/utils.js +70 -0
- package/dist/components/CropPicker/utils.js.map +1 -0
- package/dist/components/DatePicker/index.js +70 -0
- package/dist/components/DatePicker/index.js.map +1 -0
- package/dist/components/DatePicker/styles.js +2 -0
- package/dist/components/DatePicker/styles.js.map +1 -0
- package/dist/components/DatePicker/types.js +2 -0
- package/dist/components/DatePicker/types.js.map +1 -0
- package/dist/components/Drawer/index.js +50 -0
- package/dist/components/Drawer/index.js.map +1 -0
- package/dist/components/Drawer/styles.js +2 -0
- package/dist/components/Drawer/styles.js.map +1 -0
- package/dist/components/Drawer/types.js +2 -0
- package/dist/components/Drawer/types.js.map +1 -0
- package/dist/components/Dropzone/context.js +39 -0
- package/dist/components/Dropzone/context.js.map +1 -0
- package/dist/components/Dropzone/elements.js +51 -0
- package/dist/components/Dropzone/elements.js.map +1 -0
- package/dist/components/Dropzone/index.js +71 -0
- package/dist/components/Dropzone/index.js.map +1 -0
- package/dist/components/Dropzone/styles.js +2 -0
- package/dist/components/Dropzone/styles.js.map +1 -0
- package/dist/components/Dropzone/types.js +2 -0
- package/dist/components/Dropzone/types.js.map +1 -0
- package/dist/components/Dropzone/useDropzone.js +17 -0
- package/dist/components/Dropzone/useDropzone.js.map +1 -0
- package/dist/components/EmptyPlaceholder/index.js +65 -0
- package/dist/components/EmptyPlaceholder/index.js.map +1 -0
- package/dist/components/EmptyPlaceholder/styles.js +2 -0
- package/dist/components/EmptyPlaceholder/styles.js.map +1 -0
- package/dist/components/EmptyPlaceholder/types.js +2 -0
- package/dist/components/EmptyPlaceholder/types.js.map +1 -0
- package/dist/components/Field/context.js +52 -0
- package/dist/components/Field/context.js.map +1 -0
- package/dist/components/Field/elements.js +84 -0
- package/dist/components/Field/elements.js.map +1 -0
- package/dist/components/Field/index.js +37 -0
- package/dist/components/Field/index.js.map +1 -0
- package/dist/components/Field/styles.js +2 -0
- package/dist/components/Field/styles.js.map +1 -0
- package/dist/components/Field/types.js +2 -0
- package/dist/components/Field/types.js.map +1 -0
- package/dist/components/Field/useFieldInput.js +47 -0
- package/dist/components/Field/useFieldInput.js.map +1 -0
- package/dist/components/FileInput/index.js +55 -0
- package/dist/components/FileInput/index.js.map +1 -0
- package/dist/components/FileInput/types.js +2 -0
- package/dist/components/FileInput/types.js.map +1 -0
- package/dist/components/Icon/index.js +51 -0
- package/dist/components/Icon/index.js.map +1 -0
- package/dist/components/Icon/styles.js +2 -0
- package/dist/components/Icon/styles.js.map +1 -0
- package/dist/components/Icon/types.js +2 -0
- package/dist/components/Icon/types.js.map +1 -0
- package/dist/components/List/context.js +76 -0
- package/dist/components/List/context.js.map +1 -0
- package/dist/components/List/elements.js +123 -0
- package/dist/components/List/elements.js.map +1 -0
- package/dist/components/List/index.js +35 -0
- package/dist/components/List/index.js.map +1 -0
- package/dist/components/List/scroll.js +75 -0
- package/dist/components/List/scroll.js.map +1 -0
- package/dist/components/List/styles.js +2 -0
- package/dist/components/List/styles.js.map +1 -0
- package/dist/components/List/types.js +2 -0
- package/dist/components/List/types.js.map +1 -0
- package/dist/components/LoadingOverlay/index.js +32 -0
- package/dist/components/LoadingOverlay/index.js.map +1 -0
- package/dist/components/LoadingOverlay/styles.js +2 -0
- package/dist/components/LoadingOverlay/styles.js.map +1 -0
- package/dist/components/LoadingOverlay/types.js +2 -0
- package/dist/components/LoadingOverlay/types.js.map +1 -0
- package/dist/components/MaskedTextInput/index.js +34 -0
- package/dist/components/MaskedTextInput/index.js.map +1 -0
- package/dist/components/MaskedTextInput/mask.js +34 -0
- package/dist/components/MaskedTextInput/mask.js.map +1 -0
- package/dist/components/MaskedTextInput/types.js +2 -0
- package/dist/components/MaskedTextInput/types.js.map +1 -0
- package/dist/components/Modal/context.js +36 -0
- package/dist/components/Modal/context.js.map +1 -0
- package/dist/components/Modal/elements.js +66 -0
- package/dist/components/Modal/elements.js.map +1 -0
- package/dist/components/Modal/index.js +34 -0
- package/dist/components/Modal/index.js.map +1 -0
- package/dist/components/Modal/styles.js +2 -0
- package/dist/components/Modal/styles.js.map +1 -0
- package/dist/components/Modal/types.js +2 -0
- package/dist/components/Modal/types.js.map +1 -0
- package/dist/components/NumberIncrement/index.js +65 -0
- package/dist/components/NumberIncrement/index.js.map +1 -0
- package/dist/components/NumberIncrement/styles.js +2 -0
- package/dist/components/NumberIncrement/styles.js.map +1 -0
- package/dist/components/NumberIncrement/types.js +2 -0
- package/dist/components/NumberIncrement/types.js.map +1 -0
- package/dist/components/NumberIncrement/useNumberIncrement.js +113 -0
- package/dist/components/NumberIncrement/useNumberIncrement.js.map +1 -0
- package/dist/components/Overlay/index.js +44 -0
- package/dist/components/Overlay/index.js.map +1 -0
- package/dist/components/Overlay/styles.js +2 -0
- package/dist/components/Overlay/styles.js.map +1 -0
- package/dist/components/Overlay/types.js +2 -0
- package/dist/components/Overlay/types.js.map +1 -0
- package/dist/components/PaginationButtons/index.js +100 -0
- package/dist/components/PaginationButtons/index.js.map +1 -0
- package/dist/components/PaginationButtons/styles.js +2 -0
- package/dist/components/PaginationButtons/styles.js.map +1 -0
- package/dist/components/PaginationButtons/types.js +2 -0
- package/dist/components/PaginationButtons/types.js.map +1 -0
- package/dist/components/PaginationIndicator/index.js +41 -0
- package/dist/components/PaginationIndicator/index.js.map +1 -0
- package/dist/components/PaginationIndicator/styles.js +2 -0
- package/dist/components/PaginationIndicator/styles.js.map +1 -0
- package/dist/components/PaginationIndicator/types.js +2 -0
- package/dist/components/PaginationIndicator/types.js.map +1 -0
- package/dist/components/Progress/Bar/Segmented.js +37 -0
- package/dist/components/Progress/Bar/Segmented.js.map +1 -0
- package/dist/components/Progress/Bar/index.js +44 -0
- package/dist/components/Progress/Bar/index.js.map +1 -0
- package/dist/components/Progress/Bar/styles.js +2 -0
- package/dist/components/Progress/Bar/styles.js.map +1 -0
- package/dist/components/Progress/Bar/types.js +2 -0
- package/dist/components/Progress/Bar/types.js.map +1 -0
- package/dist/components/Progress/Circle/Segmented.js +60 -0
- package/dist/components/Progress/Circle/Segmented.js.map +1 -0
- package/dist/components/Progress/Circle/index.js +65 -0
- package/dist/components/Progress/Circle/index.js.map +1 -0
- package/dist/components/Progress/Circle/styles.js +2 -0
- package/dist/components/Progress/Circle/styles.js.map +1 -0
- package/dist/components/Progress/Circle/types.js +2 -0
- package/dist/components/Progress/Circle/types.js.map +1 -0
- package/dist/components/Progress/index.js +3 -0
- package/dist/components/Progress/index.js.map +1 -0
- package/dist/components/Progress/utils.js +4 -0
- package/dist/components/Progress/utils.js.map +1 -0
- package/dist/components/RadioInput/index.js +47 -0
- package/dist/components/RadioInput/index.js.map +1 -0
- package/dist/components/RadioInput/styles.js +2 -0
- package/dist/components/RadioInput/styles.js.map +1 -0
- package/dist/components/RadioInput/types.js +2 -0
- package/dist/components/RadioInput/types.js.map +1 -0
- package/dist/components/SearchInput/index.js +61 -0
- package/dist/components/SearchInput/index.js.map +1 -0
- package/dist/components/SectionFilters/index.js +148 -0
- package/dist/components/SectionFilters/index.js.map +1 -0
- package/dist/components/SectionFilters/styles.js +2 -0
- package/dist/components/SectionFilters/styles.js.map +1 -0
- package/dist/components/SectionFilters/types.js +2 -0
- package/dist/components/SectionFilters/types.js.map +1 -0
- package/dist/components/Select/context.js +156 -0
- package/dist/components/Select/context.js.map +1 -0
- package/dist/components/Select/elements.js +47 -0
- package/dist/components/Select/elements.js.map +1 -0
- package/dist/components/Select/index.js +53 -0
- package/dist/components/Select/index.js.map +1 -0
- package/dist/components/Select/styles.js +2 -0
- package/dist/components/Select/styles.js.map +1 -0
- package/dist/components/Select/types.js +2 -0
- package/dist/components/Select/types.js.map +1 -0
- package/dist/components/Select/useTriggerWidth.js +27 -0
- package/dist/components/Select/useTriggerWidth.js.map +1 -0
- package/dist/components/Slider/index.js +139 -0
- package/dist/components/Slider/index.js.map +1 -0
- package/dist/components/Slider/styles.js +2 -0
- package/dist/components/Slider/styles.js.map +1 -0
- package/dist/components/Slider/types.js +2 -0
- package/dist/components/Slider/types.js.map +1 -0
- package/dist/components/Switch/index.js +48 -0
- package/dist/components/Switch/index.js.map +1 -0
- package/dist/components/Switch/styles.js +2 -0
- package/dist/components/Switch/styles.js.map +1 -0
- package/dist/components/Switch/types.js +2 -0
- package/dist/components/Switch/types.js.map +1 -0
- package/dist/components/Tag/index.js +53 -0
- package/dist/components/Tag/index.js.map +1 -0
- package/dist/components/Tag/styles.js +2 -0
- package/dist/components/Tag/styles.js.map +1 -0
- package/dist/components/Tag/types.js +2 -0
- package/dist/components/Tag/types.js.map +1 -0
- package/dist/components/Text/index.js +94 -0
- package/dist/components/Text/index.js.map +1 -0
- package/dist/components/Text/styles.js +2 -0
- package/dist/components/Text/styles.js.map +1 -0
- package/dist/components/Text/types.js +2 -0
- package/dist/components/Text/types.js.map +1 -0
- package/dist/components/TextEditor/index.js +90 -0
- package/dist/components/TextEditor/index.js.map +1 -0
- package/dist/components/TextEditor/styles.js +2 -0
- package/dist/components/TextEditor/styles.js.map +1 -0
- package/dist/components/TextEditor/types.js +2 -0
- package/dist/components/TextEditor/types.js.map +1 -0
- package/dist/components/TextInput/index.js +65 -0
- package/dist/components/TextInput/index.js.map +1 -0
- package/dist/components/TextInput/styles.js +2 -0
- package/dist/components/TextInput/styles.js.map +1 -0
- package/dist/components/TextInput/types.js +2 -0
- package/dist/components/TextInput/types.js.map +1 -0
- package/dist/components/TextInput/useTextInput.js +64 -0
- package/dist/components/TextInput/useTextInput.js.map +1 -0
- package/dist/components/Tooltip/index.js +94 -0
- package/dist/components/Tooltip/index.js.map +1 -0
- package/dist/components/Tooltip/styles.js +2 -0
- package/dist/components/Tooltip/styles.js.map +1 -0
- package/dist/components/Tooltip/types.js +2 -0
- package/dist/components/Tooltip/types.js.map +1 -0
- package/dist/components/Touchable/index.js +80 -0
- package/dist/components/Touchable/index.js.map +1 -0
- package/dist/components/Touchable/styles.js +2 -0
- package/dist/components/Touchable/styles.js.map +1 -0
- package/dist/components/Touchable/types.js +2 -0
- package/dist/components/Touchable/types.js.map +1 -0
- package/dist/components/View/index.js +39 -0
- package/dist/components/View/index.js.map +1 -0
- package/dist/components/View/styles.js +2 -0
- package/dist/components/View/styles.js.map +1 -0
- package/dist/components/View/types.js +2 -0
- package/dist/components/View/types.js.map +1 -0
- package/dist/components/components.js +42 -0
- package/dist/components/components.js.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/ListMasonry.js +86 -0
- package/dist/lib/ListMasonry.js.map +1 -0
- package/dist/lib/ThemeVariables.js +22 -0
- package/dist/lib/ThemeVariables.js.map +1 -0
- package/dist/lib/WebStyleRegistry.js +69 -0
- package/dist/lib/WebStyleRegistry.js.map +1 -0
- package/dist/lib/hooks/index.js +23 -0
- package/dist/lib/hooks/index.js.map +1 -0
- package/dist/lib/hooks/useAnimatedStyle.js +23 -0
- package/dist/lib/hooks/useAnimatedStyle.js.map +1 -0
- package/dist/lib/hooks/useAnimatedVariantStyles.js +20 -0
- package/dist/lib/hooks/useAnimatedVariantStyles.js.map +1 -0
- package/dist/lib/hooks/useAsyncSelect.js +57 -0
- package/dist/lib/hooks/useAsyncSelect.js.map +1 -0
- package/dist/lib/hooks/useBreakpointMatch.js +108 -0
- package/dist/lib/hooks/useBreakpointMatch.js.map +1 -0
- package/dist/lib/hooks/useClick.js +38 -0
- package/dist/lib/hooks/useClick.js.map +1 -0
- package/dist/lib/hooks/useClickOutside.js +31 -0
- package/dist/lib/hooks/useClickOutside.js.map +1 -0
- package/dist/lib/hooks/useFileInput.js +17 -0
- package/dist/lib/hooks/useFileInput.js.map +1 -0
- package/dist/lib/hooks/useIsomorphicEffect.js +7 -0
- package/dist/lib/hooks/useIsomorphicEffect.js.map +1 -0
- package/dist/lib/hooks/useKeydown.js +39 -0
- package/dist/lib/hooks/useKeydown.js.map +1 -0
- package/dist/lib/hooks/useListFocus.js +46 -0
- package/dist/lib/hooks/useListFocus.js.map +1 -0
- package/dist/lib/hooks/useMediaQuery.js +25 -0
- package/dist/lib/hooks/useMediaQuery.js.map +1 -0
- package/dist/lib/hooks/usePageExitBlocker.js +44 -0
- package/dist/lib/hooks/usePageExitBlocker.js.map +1 -0
- package/dist/lib/hooks/usePagination.js +90 -0
- package/dist/lib/hooks/usePagination.js.map +1 -0
- package/dist/lib/hooks/usePopState.js +31 -0
- package/dist/lib/hooks/usePopState.js.map +1 -0
- package/dist/lib/hooks/usePopoverDismiss.js +32 -0
- package/dist/lib/hooks/usePopoverDismiss.js.map +1 -0
- package/dist/lib/hooks/useRefresh.js +67 -0
- package/dist/lib/hooks/useRefresh.js.map +1 -0
- package/dist/lib/hooks/useScrollEffect.js +19 -0
- package/dist/lib/hooks/useScrollEffect.js.map +1 -0
- package/dist/lib/hooks/useSearchParams.js +48 -0
- package/dist/lib/hooks/useSearchParams.js.map +1 -0
- package/dist/lib/hooks/useStaticAnimationStyles.js +16 -0
- package/dist/lib/hooks/useStaticAnimationStyles.js.map +1 -0
- package/dist/lib/hooks/useStylesFor.js +36 -0
- package/dist/lib/hooks/useStylesFor.js.map +1 -0
- package/dist/lib/hooks/useTouchableEvents.js +34 -0
- package/dist/lib/hooks/useTouchableEvents.js.map +1 -0
- package/dist/lib/hooks/useWindowFocus.js +30 -0
- package/dist/lib/hooks/useWindowFocus.js.map +1 -0
- package/dist/lib/hooks/useWindowSize.js +29 -0
- package/dist/lib/hooks/useWindowSize.js.map +1 -0
- package/dist/lib/index.js +7 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/tools/index.js +4 -0
- package/dist/lib/tools/index.js.map +1 -0
- package/dist/lib/tools/localStorage.js +155 -0
- package/dist/lib/tools/localStorage.js.map +1 -0
- package/dist/lib/tools/mediaQuery.js +33 -0
- package/dist/lib/tools/mediaQuery.js.map +1 -0
- package/dist/lib/tools/modal.js +55 -0
- package/dist/lib/tools/modal.js.map +1 -0
- package/dist/lib/utils/attributes.js +23 -0
- package/dist/lib/utils/attributes.js.map +1 -0
- package/dist/lib/utils/cache.js +10 -0
- package/dist/lib/utils/cache.js.map +1 -0
- package/dist/lib/utils/index.js +6 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/pollyfils/scroll.js +66 -0
- package/dist/lib/utils/pollyfils/scroll.js.map +1 -0
- package/dist/lib/utils/stopPropagation.js +19 -0
- package/dist/lib/utils/stopPropagation.js.map +1 -0
- package/dist/lib/utils/test.js +14 -0
- package/dist/lib/utils/test.js.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/utility.js +2 -0
- package/dist/types/utility.js.map +1 -0
- package/package.json +18 -18
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useId, useImperativeHandle, useRef, useState } from 'react';
|
|
3
|
+
import { logger } from '@codeleap/logger';
|
|
4
|
+
import { TypeGuards } from '@codeleap/types';
|
|
5
|
+
import { useValidate } from '@codeleap/form';
|
|
6
|
+
import { useListFocus } from '../../lib/hooks/useListFocus';
|
|
7
|
+
import { usePopoverDismiss } from '../../lib/hooks/usePopoverDismiss';
|
|
8
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor';
|
|
9
|
+
import { useTriggerWidth } from './useTriggerWidth';
|
|
10
|
+
import { toDataAttrs } from '../../lib';
|
|
11
|
+
import { Field } from '../Field';
|
|
12
|
+
import { getFieldIds } from '../Field/context';
|
|
13
|
+
function joinLabels(values, options, separator) {
|
|
14
|
+
return (values ?? [])
|
|
15
|
+
.map(v => options?.find(o => o.value === v)?.label ?? String(v))
|
|
16
|
+
.join(separator);
|
|
17
|
+
}
|
|
18
|
+
/** React context that shares `SelectContextValue` across all sub-components of a `Select`. */
|
|
19
|
+
export const SelectContext = createContext(null);
|
|
20
|
+
/**
|
|
21
|
+
* Reads the nearest `SelectContext` value.
|
|
22
|
+
* Must be called inside a `SelectProvider` tree; throws if the context is absent.
|
|
23
|
+
*/
|
|
24
|
+
export const useSelectContext = () => {
|
|
25
|
+
const ctx = useContext(SelectContext);
|
|
26
|
+
if (!ctx)
|
|
27
|
+
throw new Error('useSelectContext must be used inside Select.Provider');
|
|
28
|
+
return ctx;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Derives the full `SelectContextValue` from `SelectProps`, encapsulating open/focus state, validation,
|
|
32
|
+
* key-based selection, display-label construction, and trigger-width measurement.
|
|
33
|
+
* Intended for use inside `SelectProvider`; consume the result via `useSelectContext` in sub-components.
|
|
34
|
+
*/
|
|
35
|
+
export function useSelectProvider(props) {
|
|
36
|
+
const { options = [], value, onValueChange, multiple, limit, placeholder, disabled, focused: _focused, error, validate, onBlur, onFocus, placement = 'bottom start', separatorMultiValue = ', ', listRef, onOpenChange: onOpenChangeProp, helper, debugName, style, } = props;
|
|
37
|
+
const validation = useValidate(value, validate);
|
|
38
|
+
const hasError = validation?.showError || !!error;
|
|
39
|
+
const errorMessage = validation?.message || error;
|
|
40
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
41
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
42
|
+
const triggerRef = useRef(null);
|
|
43
|
+
const popoverRef = useRef(null);
|
|
44
|
+
const listBoxDOMRef = useRef(null);
|
|
45
|
+
const listAutoFocusRef = useRef(undefined);
|
|
46
|
+
useImperativeHandle(props.ref, () => ({
|
|
47
|
+
focus: () => triggerRef.current?.focus(),
|
|
48
|
+
}), []);
|
|
49
|
+
const listFocus = useListFocus(listBoxDOMRef, listRef);
|
|
50
|
+
const focusList = useCallback((strategy) => {
|
|
51
|
+
if (!listBoxDOMRef.current) {
|
|
52
|
+
logger.warn('[Select] focusList called before list is mounted');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
listFocus.focus(strategy);
|
|
56
|
+
}, [listFocus]);
|
|
57
|
+
const handleOpenChange = useCallback((open) => {
|
|
58
|
+
setIsOpen(open);
|
|
59
|
+
onOpenChangeProp?.(open);
|
|
60
|
+
}, [onOpenChangeProp]);
|
|
61
|
+
usePopoverDismiss({ popoverRef, triggerRef, isOpen, onClose: () => handleOpenChange(false) });
|
|
62
|
+
const hasValue = multiple
|
|
63
|
+
? (value?.length ?? 0) > 0
|
|
64
|
+
: !TypeGuards.isNil(value);
|
|
65
|
+
const activeFocused = isFocused || !!_focused;
|
|
66
|
+
const fieldContext = {
|
|
67
|
+
disabled: !!disabled,
|
|
68
|
+
hasValue,
|
|
69
|
+
error: !!hasError,
|
|
70
|
+
focused: activeFocused,
|
|
71
|
+
multiple: !!multiple,
|
|
72
|
+
};
|
|
73
|
+
const styles = useStylesFor('Select', style, fieldContext);
|
|
74
|
+
const stateAttrs = toDataAttrs(fieldContext);
|
|
75
|
+
const handleFocus = useCallback(() => { setIsFocused(true); onFocus?.(); }, [onFocus]);
|
|
76
|
+
const handleBlur = useCallback(() => {
|
|
77
|
+
validation?.onInputBlurred();
|
|
78
|
+
setIsFocused(false);
|
|
79
|
+
onBlur?.();
|
|
80
|
+
}, [validation?.onInputBlurred, onBlur]);
|
|
81
|
+
const handleSelectionChange = useCallback((keys) => {
|
|
82
|
+
if (multiple) {
|
|
83
|
+
const newValues = [...keys].map(k => options.find(o => String(o.value) === String(k))?.value ?? k);
|
|
84
|
+
if (TypeGuards.isNumber(limit) && newValues.length > (value?.length ?? 0) && newValues.length > limit)
|
|
85
|
+
return;
|
|
86
|
+
onValueChange?.(newValues);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const key = [...keys][0];
|
|
90
|
+
if (!TypeGuards.isNil(key)) {
|
|
91
|
+
onValueChange?.(key);
|
|
92
|
+
setIsOpen(false);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, [multiple, options, limit, value, onValueChange]);
|
|
96
|
+
const openDropdown = useCallback((focus) => {
|
|
97
|
+
listAutoFocusRef.current = focus;
|
|
98
|
+
setIsOpen(true);
|
|
99
|
+
}, []);
|
|
100
|
+
const closeDropdown = useCallback(() => setIsOpen(false), []);
|
|
101
|
+
const fieldId = useId();
|
|
102
|
+
const { label: labelId, helper: helperId } = getFieldIds(fieldId);
|
|
103
|
+
const helperContent = hasError ? errorMessage : helper;
|
|
104
|
+
const selectedKeys = multiple
|
|
105
|
+
? new Set((value ?? []).map((v) => String(v)))
|
|
106
|
+
: hasValue ? new Set([String(value)]) : new Set();
|
|
107
|
+
const displayLabel = multiple
|
|
108
|
+
? (hasValue ? joinLabels(value, options, separatorMultiValue) : (placeholder ?? ''))
|
|
109
|
+
: (hasValue
|
|
110
|
+
? (options.find(o => String(o.value) === String(value))?.label ?? String(value))
|
|
111
|
+
: (placeholder ?? ''));
|
|
112
|
+
const triggerWidthStyle = useTriggerWidth(triggerRef);
|
|
113
|
+
return {
|
|
114
|
+
isOpen,
|
|
115
|
+
isFocused,
|
|
116
|
+
hasValue,
|
|
117
|
+
displayLabel,
|
|
118
|
+
selectedKeys,
|
|
119
|
+
fieldContext,
|
|
120
|
+
stateAttrs,
|
|
121
|
+
triggerRef,
|
|
122
|
+
popoverRef,
|
|
123
|
+
listBoxDOMRef,
|
|
124
|
+
listAutoFocusRef,
|
|
125
|
+
triggerWidthStyle,
|
|
126
|
+
handleFocus,
|
|
127
|
+
handleBlur,
|
|
128
|
+
handleOpenChange,
|
|
129
|
+
handleSelectionChange,
|
|
130
|
+
focusList,
|
|
131
|
+
openDropdown,
|
|
132
|
+
closeDropdown,
|
|
133
|
+
styles,
|
|
134
|
+
fieldId,
|
|
135
|
+
labelId,
|
|
136
|
+
helperId,
|
|
137
|
+
helperContent,
|
|
138
|
+
options,
|
|
139
|
+
value,
|
|
140
|
+
multiple: !!multiple,
|
|
141
|
+
disabled: !!disabled,
|
|
142
|
+
placement,
|
|
143
|
+
debugName,
|
|
144
|
+
listRef,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Wires up `Field.Provider` and `SelectContext.Provider` so that all `Select` sub-components
|
|
149
|
+
* receive both field layout state and select-specific state.
|
|
150
|
+
* Must wrap `SelectTrigger`, `SelectPopover`, and `SelectList` when composing a custom select UI.
|
|
151
|
+
*/
|
|
152
|
+
export const SelectProvider = ({ children, ...props }) => {
|
|
153
|
+
const value = useSelectProvider(props);
|
|
154
|
+
return (_jsx(Field.Provider, { id: value.fieldId, context: value.fieldContext, label: props.label, helper: value.helperContent, leftSection: props.leftSection, rightSection: props.rightSection, componentName: 'select', children: _jsx(SelectContext.Provider, { value: value, children: children }) }));
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/components/Select/context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAC5H,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,EAAE,YAAY,EAAgD,MAAM,8BAA8B,CAAA;AACzG,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EA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QACT,YAAY;QACZ,aAAa;QACb,MAAM;QACN,OAAO;QACP,OAAO;QACP,QAAQ;QACR,aAAa;QACb,OAAO;QACP,KAAK;QACL,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,SAAS;QACT,SAAS;QACT,OAAO;KACR,CAAA;AACH,CAAC;AAID;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAuB,EAAE,EAAE;IAC5E,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA;IACtC,OAAO,CACL,KAAC,KAAK,CAAC,QAAQ,IACb,EAAE,EAAE,KAAK,CAAC,OAAO,EACjB,OAAO,EAAE,KAAK,CAAC,YAAY,EAC3B,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,MAAM,EAAE,KAAK,CAAC,aAAa,EAC3B,WAAW,EAAE,KAAK,CAAC,WAAW,EAC9B,YAAY,EAAE,KAAK,CAAC,YAAY,EAChC,aAAa,EAAC,QAAQ,YAEtB,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACjC,QAAQ,GACc,GACV,CAClB,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { ListBox, ListBoxItem, Popover, } from 'react-aria-components';
|
|
4
|
+
import { Field } from '../Field';
|
|
5
|
+
import { View } from '../View';
|
|
6
|
+
import { Text } from '../Text';
|
|
7
|
+
import { Touchable } from '../Touchable';
|
|
8
|
+
import { useSelectContext } from './context';
|
|
9
|
+
/**
|
|
10
|
+
* Clickable trigger button that opens or closes the `SelectPopover`.
|
|
11
|
+
* Reads all state from `SelectContext`; must be rendered inside a `SelectProvider`.
|
|
12
|
+
* Uses: `Field.Box`, `Field.SectionSlot`, `Text`, `Touchable`
|
|
13
|
+
*/
|
|
14
|
+
export const SelectTrigger = () => {
|
|
15
|
+
const { styles, triggerRef, disabled, handleFocus, handleBlur, isOpen, handleOpenChange, labelId, helperId, helperContent, displayLabel, hasValue, stateAttrs, debugName, } = useSelectContext();
|
|
16
|
+
return (_jsxs(Field.Box, { component: Touchable, ref: triggerRef, style: styles.trigger, disabled: disabled, onPress: () => handleOpenChange(!isOpen), onFocus: handleFocus, onBlur: handleBlur, "aria-labelledby": labelId, "aria-describedby": helperContent ? helperId : undefined, ...stateAttrs, children: [_jsx(Field.SectionSlot, { position: 'left' }), _jsx(Text, { text: displayLabel, debugName: debugName, style: hasValue ? styles.value : styles.placeholder }), _jsx(Field.SectionSlot, { position: 'right' })] }));
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Non-modal `react-aria-components` `Popover` anchored to `SelectTrigger` and sized to match its width.
|
|
20
|
+
* Must be rendered inside a `SelectProvider`; wrap `SelectList` or custom list content as children.
|
|
21
|
+
*/
|
|
22
|
+
export const SelectPopover = ({ children }) => {
|
|
23
|
+
const { styles, isOpen, handleOpenChange, triggerRef, popoverRef, triggerWidthStyle, placement } = useSelectContext();
|
|
24
|
+
return (_jsx(Popover, { triggerRef: triggerRef, isOpen: isOpen, ref: popoverRef, onOpenChange: handleOpenChange, css: styles.popover, isNonModal: true, style: triggerWidthStyle, placement: placement, children: children }));
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Accessible list box that renders the selectable options, with support for single and multi-select modes.
|
|
28
|
+
* Accepts optional `renderItem` and `renderEmpty` overrides; falls back to default `Text`-based rendering.
|
|
29
|
+
* Must be rendered inside a `SelectProvider`.
|
|
30
|
+
* Uses: `Text`, `View`
|
|
31
|
+
*/
|
|
32
|
+
export const SelectList = ({ renderItem, renderEmpty, }) => {
|
|
33
|
+
const { styles, options, selectedKeys, handleSelectionChange, multiple, listBoxDOMRef, listAutoFocusRef, debugName, focusList, labelId, } = useSelectContext();
|
|
34
|
+
const renderListItem = useCallback((item) => (_jsx(ListBoxItem, { id: String(item.value), textValue: item.label, css: styles.listItem, children: ({ isSelected, isFocused: isItemFocused }) => {
|
|
35
|
+
const state = { isSelected, isFocused: isItemFocused };
|
|
36
|
+
if (renderItem)
|
|
37
|
+
return _jsx(_Fragment, { children: renderItem(item, state, focusList) });
|
|
38
|
+
return _jsx(Text, { text: item.label, debugName: debugName, style: styles.listItemText });
|
|
39
|
+
} }, String(item.value))), [renderItem, styles, debugName, focusList]);
|
|
40
|
+
const renderEmptyState = useCallback(() => {
|
|
41
|
+
if (renderEmpty)
|
|
42
|
+
return _jsx(_Fragment, { children: renderEmpty({ style: styles.emptyState, focusList }) });
|
|
43
|
+
return _jsx(View, { style: styles.emptyState, children: _jsx(Text, { text: 'No results', debugName: debugName }) });
|
|
44
|
+
}, [renderEmpty, styles, debugName, focusList]);
|
|
45
|
+
return (_jsx(ListBox, { ref: listBoxDOMRef, selectionMode: multiple ? 'multiple' : 'single', selectedKeys: selectedKeys, onSelectionChange: handleSelectionChange, items: options, autoFocus: listAutoFocusRef.current, css: styles.list, renderEmptyState: renderEmptyState, "aria-labelledby": labelId, children: renderListItem }));
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=elements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elements.js","sourceRoot":"","sources":["../../../src/components/Select/elements.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,OAAO,CAAA;AACnD,OAAO,EACL,OAAO,EACP,WAAW,EACX,OAAO,GAER,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC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EAAE,SAAS,CAAC,CAAC,CAAA;IAE9C,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE;QACxC,IAAI,WAAW;YAAE,OAAO,4BAAG,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,UAAkB,EAAE,SAAS,EAAE,CAAC,GAAI,CAAA;QAC3F,OAAO,KAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,UAAU,YAAE,KAAC,IAAI,IAAC,IAAI,EAAC,YAAY,EAAC,SAAS,EAAE,SAAS,GAAI,GAAO,CAAA;IAChG,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAA;IAE/C,OAAO,CACL,KAAC,OAAO,IACN,GAAG,EAAE,aAAa,EAClB,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAC/C,YAAY,EAAE,YAAY,EAC1B,iBAAiB,EAAE,qBAAqB,EACxC,KAAK,EAAE,OAAc,EACrB,SAAS,EAAE,gBAAgB,CAAC,OAAO,EACnC,GAAG,EAAG,MAAc,CAAC,IAAI,EACzB,gBAAgB,EAAE,gBAAgB,qBACjB,OAAO,YAEvB,cAAc,GACP,CACX,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Field } from '../Field';
|
|
3
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry';
|
|
4
|
+
import { SelectProvider, useSelectContext } from './context';
|
|
5
|
+
import { SelectTrigger, SelectPopover, SelectList } from './elements';
|
|
6
|
+
export * from './styles';
|
|
7
|
+
export * from './types';
|
|
8
|
+
export * from './context';
|
|
9
|
+
export * from './elements';
|
|
10
|
+
function SelectInner(props) {
|
|
11
|
+
const { styles } = useSelectContext();
|
|
12
|
+
return (_jsxs(Field.Wrapper, { style: styles.wrapper, children: [_jsx(Field.Heading, { style: styles.heading }), _jsx(SelectTrigger, {}), _jsx(SelectPopover, { children: _jsx(SelectList, { renderItem: props.renderItem, renderEmpty: props.renderEmpty }) }), _jsx(Field.Helper, { style: styles.helper })] }));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Accessible dropdown select field supporting both single and multi-select modes, field layout, and validation.
|
|
16
|
+
* Controlled via `value` / `onValueChange`; pass `multiple` to switch to array-based selection.
|
|
17
|
+
* Exposes sub-components as static properties (`Select.Trigger`, `Select.Popover`, `Select.List`, `Select.Provider`)
|
|
18
|
+
* and a typed factory `Select.of<T, Multi>()` for composing custom select UIs without casting.
|
|
19
|
+
* Uses: `SelectProvider`, `SelectTrigger`, `SelectPopover`, `SelectList`, `Field.Wrapper`, `Field.Heading`, `Field.Helper`
|
|
20
|
+
*/
|
|
21
|
+
export function Select(props) {
|
|
22
|
+
const allProps = {
|
|
23
|
+
...Select.defaultProps,
|
|
24
|
+
...props
|
|
25
|
+
};
|
|
26
|
+
return (_jsx(SelectProvider, { ...allProps, children: _jsx(SelectInner, { ...allProps }) }));
|
|
27
|
+
}
|
|
28
|
+
Select.displayName = 'Select';
|
|
29
|
+
Select.styleRegistryName = 'Select';
|
|
30
|
+
Select.elements = [
|
|
31
|
+
...Field.elements,
|
|
32
|
+
'trigger', 'value',
|
|
33
|
+
'popover', 'list', 'listItem', 'listItemText',
|
|
34
|
+
'emptyState', 'placeholder'
|
|
35
|
+
];
|
|
36
|
+
Select.rootElement = 'wrapper';
|
|
37
|
+
Select.defaultProps = {
|
|
38
|
+
separatorMultiValue: ', ',
|
|
39
|
+
options: [],
|
|
40
|
+
};
|
|
41
|
+
Select.Provider = SelectProvider;
|
|
42
|
+
Select.Trigger = SelectTrigger;
|
|
43
|
+
Select.Popover = SelectPopover;
|
|
44
|
+
Select.List = SelectList;
|
|
45
|
+
Select.useContext = useSelectContext;
|
|
46
|
+
Select.of = () => ({
|
|
47
|
+
Provider: SelectProvider,
|
|
48
|
+
List: SelectList,
|
|
49
|
+
Trigger: SelectTrigger,
|
|
50
|
+
Popover: SelectPopover,
|
|
51
|
+
});
|
|
52
|
+
WebStyleRegistry.registerComponent(Select);
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Select/index.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAErE,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAE1B,SAAS,WAAW,CAGlB,KAA4B;IAC5B,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAA;IACrC,OAAO,CACL,MAAC,KAAK,CAAC,OAAO,IAAC,KAAK,EAAE,MAAM,CAAC,OAAO,aAClC,KAAC,KAAK,CAAC,OAAO,IAAC,KAAK,EAAE,MAAM,CAAC,OAAO,GAAI,EACxC,KAAC,aAAa,KAAG,EACjB,KAAC,aAAa,cACZ,KAAC,UAAU,IACT,UAAU,EAAE,KAAK,CAAC,UAA8C,EAChE,WAAW,EAAE,KAAK,CAAC,WAAgD,GACnE,GACY,EAChB,KAAC,KAAK,CAAC,MAAM,IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,GAAI,IACxB,CACjB,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAGpB,KAA4B;IAC5B,MAAM,QAAQ,GAAG;QACf,GAAG,MAAM,CAAC,YAAY;QACtB,GAAG,KAAK;KACgB,CAAA;IAC1B,OAAO,CACL,KAAC,cAAc,OAAM,QAAgC,YACnD,KAAC,WAAW,OAAe,QAAQ,GAAI,GACxB,CAClB,CAAA;AACH,CAAC;AAED,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAA;AAC7B,MAAM,CAAC,iBAAiB,GAAG,QAAQ,CAAA;AACnC,MAAM,CAAC,QAAQ,GAAG;IAChB,GAAG,KAAK,CAAC,QAAQ;IACjB,SAAS,EAAE,OAAO;IAClB,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc;IAC7C,YAAY,EAAE,aAAa;CAC5B,CAAA;AACD,MAAM,CAAC,WAAW,GAAG,SAAS,CAAA;AAC9B,MAAM,CAAC,YAAY,GAAG;IACpB,mBAAmB,EAAE,IAAI;IACzB,OAAO,EAAE,EAAE;CACsB,CAAA;AAEnC,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAA;AAChC,MAAM,CAAC,OAAO,GAAG,aAAa,CAAA;AAC9B,MAAM,CAAC,OAAO,GAAG,aAAa,CAAA;AAC9B,MAAM,CAAC,IAAI,GAAG,UAAU,CAAA;AACxB,MAAM,CAAC,UAAU,GAAG,gBAAgB,CAAA;AAEpC,MAAM,CAAC,EAAE,GAAG,GAGR,EAAE,CAAC,CAAC;IACN,QAAQ,EAAE,cAA6F;IACvG,IAAI,EAAE,UAAqD;IAC3D,OAAO,EAAE,aAAa;IACtB,OAAO,EAAE,aAAa;CACvB,CAAC,CAAA;AAEF,gBAAgB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/components/Select/styles.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/Select/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useEffect, useState } from 'react';
|
|
2
|
+
// Workaround for https://github.com/adobe/react-spectrum/pull/9913
|
|
3
|
+
// RAC <=1.17 only sets --trigger-width in built-in trigger components, not standalone Popovers.
|
|
4
|
+
// Remove once upgraded to 1.18+.
|
|
5
|
+
/**
|
|
6
|
+
* Measures the width of the element at `ref` and returns a CSS-properties object containing
|
|
7
|
+
* `--trigger-width` so that `SelectPopover` can match the trigger's width.
|
|
8
|
+
* Uses a `ResizeObserver` to keep the value up-to-date on layout changes.
|
|
9
|
+
*/
|
|
10
|
+
export function useTriggerWidth(ref) {
|
|
11
|
+
const [width, setWidth] = useState(null);
|
|
12
|
+
const measure = useCallback(() => {
|
|
13
|
+
if (ref.current)
|
|
14
|
+
setWidth(ref.current.getBoundingClientRect().width + 'px');
|
|
15
|
+
}, [ref]);
|
|
16
|
+
useLayoutEffect(measure, [measure]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const el = ref.current;
|
|
19
|
+
if (!el || typeof ResizeObserver === 'undefined')
|
|
20
|
+
return;
|
|
21
|
+
const observer = new ResizeObserver(measure);
|
|
22
|
+
observer.observe(el);
|
|
23
|
+
return () => observer.unobserve(el);
|
|
24
|
+
}, [ref, measure]);
|
|
25
|
+
return { '--trigger-width': width };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=useTriggerWidth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTriggerWidth.js","sourceRoot":"","sources":["../../../src/components/Select/useTriggerWidth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAEzF,mEAAmE;AACnE,gGAAgG;AAChG,iCAAiC;AACjC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,GAA8B;IAC5D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAA;IAEvD,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;QAC/B,IAAI,GAAG,CAAC,OAAO;YAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;IAC7E,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;IAET,eAAe,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEnC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAA;QACtB,IAAI,CAAC,EAAE,IAAI,OAAO,cAAc,KAAK,WAAW;YAAE,OAAM;QACxD,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAA;QAC5C,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QACpB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;IACrC,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;IAElB,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAyB,CAAA;AAC5D,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { TypeGuards } from '@codeleap/types';
|
|
4
|
+
import { onMount, useRef } from '@codeleap/hooks';
|
|
5
|
+
import { View } from '../View';
|
|
6
|
+
import { Text } from '../Text';
|
|
7
|
+
import { Root as SliderContainer, Track as SliderTrack, Thumb as SliderThumb, Range as SliderRange, } from '@radix-ui/react-slider';
|
|
8
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor';
|
|
9
|
+
import { mergeStyles } from '@codeleap/styles';
|
|
10
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry';
|
|
11
|
+
import { useFieldInput } from '../Field';
|
|
12
|
+
import { fields } from '@codeleap/form';
|
|
13
|
+
import { Field } from '../Field';
|
|
14
|
+
export * from './styles';
|
|
15
|
+
export * from './types';
|
|
16
|
+
const DefaultSliderTrackMark = (props) => {
|
|
17
|
+
const { style } = props;
|
|
18
|
+
if (!TypeGuards.isString(props.content)) {
|
|
19
|
+
return _jsx(React.Fragment, { children: props.content });
|
|
20
|
+
}
|
|
21
|
+
return _jsx(Text, { text: props.content, style: style });
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Radix UI-backed range slider with `Field` layout, optional track marks, and a computed value indicator in the helper slot.
|
|
25
|
+
* Supports both single-thumb and multi-thumb (range) modes determined by whether `value` is a scalar or array.
|
|
26
|
+
* Uses: `Field.Provider`, `Field.Wrapper`, `Field.Heading`, `Field.Helper`, `View`, `Text`
|
|
27
|
+
*/
|
|
28
|
+
export const Slider = (props) => {
|
|
29
|
+
const allProps = {
|
|
30
|
+
...Slider.defaultProps,
|
|
31
|
+
...props,
|
|
32
|
+
};
|
|
33
|
+
const { onValueChange, onValueCommit, value: _value, field, label, helper, leftSection, rightSection, debugName, style, disabled, trackMarks, trackMarkComponent: SliderTrackMark = DefaultSliderTrackMark, max, min, defaultValue: defaultSliderValue, indicatorLabel, minStepsBetweenThumbs, step, onPressThumbSetValue, onPressThumb, ...sliderProps } = allProps;
|
|
34
|
+
const { wrapperRef, inputValue, onInputValueChange, validation, } = useFieldInput(field, fields.number, { value: _value, onValueChange });
|
|
35
|
+
const isUniqueValue = !TypeGuards.isArray(inputValue);
|
|
36
|
+
const value = isUniqueValue ? [inputValue] : inputValue;
|
|
37
|
+
const _defaultValue = TypeGuards.isArray(defaultSliderValue) ? defaultSliderValue : [defaultSliderValue];
|
|
38
|
+
const defaultValueRef = useRef(_defaultValue);
|
|
39
|
+
const defaultValue = defaultValueRef.current;
|
|
40
|
+
onMount(() => {
|
|
41
|
+
if (_defaultValue?.length <= 0) {
|
|
42
|
+
defaultValueRef.current = value;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const handleChange = (newValue) => {
|
|
46
|
+
onInputValueChange?.(isUniqueValue ? newValue?.[0] : newValue);
|
|
47
|
+
};
|
|
48
|
+
const handleValueCommit = (newValue) => {
|
|
49
|
+
onValueCommit?.(newValue);
|
|
50
|
+
};
|
|
51
|
+
const trackMarksHaveContent = !(TypeGuards.isArray(trackMarks) || TypeGuards.isNil(trackMarks));
|
|
52
|
+
const trackMarksProp = React.useMemo(() => {
|
|
53
|
+
if (!trackMarksHaveContent) {
|
|
54
|
+
return trackMarks;
|
|
55
|
+
}
|
|
56
|
+
return Object.keys(trackMarks).map((key) => Number(key));
|
|
57
|
+
}, [trackMarksHaveContent]);
|
|
58
|
+
const fieldContext = {
|
|
59
|
+
disabled: !!disabled,
|
|
60
|
+
hasValue: true,
|
|
61
|
+
error: !!validation?.showError,
|
|
62
|
+
focused: false,
|
|
63
|
+
};
|
|
64
|
+
const styles = useStylesFor(Slider.styleRegistryName, style, fieldContext);
|
|
65
|
+
const trackStyle = mergeStyles([styles.track, styles.unselectedTrack]);
|
|
66
|
+
const sliderHelper = React.useMemo(() => {
|
|
67
|
+
if (TypeGuards.isNil(indicatorLabel) || !indicatorLabel?.order && !indicatorLabel?.transformer) {
|
|
68
|
+
return helper;
|
|
69
|
+
}
|
|
70
|
+
if (TypeGuards.isFunction(indicatorLabel?.transformer)) {
|
|
71
|
+
const str = indicatorLabel?.transformer(value, defaultValue);
|
|
72
|
+
return str;
|
|
73
|
+
}
|
|
74
|
+
else if (TypeGuards.isArray(indicatorLabel?.order)) {
|
|
75
|
+
let str = '';
|
|
76
|
+
indicatorLabel?.order?.forEach((idx, i) => {
|
|
77
|
+
const valueLabel = value[idx];
|
|
78
|
+
if (TypeGuards.isNil(valueLabel))
|
|
79
|
+
return;
|
|
80
|
+
str = i === 0 ? String(valueLabel) : `${str}${indicatorLabel?.separator ?? ' - '}${valueLabel}`;
|
|
81
|
+
});
|
|
82
|
+
return str;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return helper;
|
|
86
|
+
}
|
|
87
|
+
}, [value]);
|
|
88
|
+
return (_jsx(Field.Provider, { context: fieldContext, label: label, helper: validation?.showError ? validation?.message : sliderHelper, leftSection: leftSection, rightSection: rightSection, componentName: 'slider', children: _jsxs(Field.Wrapper, { ref: wrapperRef, style: styles.wrapper, children: [_jsx(Field.Heading, { style: styles.heading }), _jsxs(SliderContainer, { ...sliderProps, step: step, min: min, max: max, disabled: disabled, defaultValue: defaultValue, onValueCommit: handleValueCommit, onValueChange: handleChange, css: styles.sliderContainer, value: value, minStepsBetweenThumbs: minStepsBetweenThumbs, children: [_jsx(SliderTrack, { css: trackStyle, children: _jsx(SliderRange, { css: styles.selectedTrack }) }), defaultValue.map((_, i) => (_jsx(SliderThumb, { css: styles.thumb, onClick: () => {
|
|
89
|
+
if (onPressThumbSetValue)
|
|
90
|
+
onInputValueChange?.(value);
|
|
91
|
+
if (TypeGuards.isFunction(onPressThumb))
|
|
92
|
+
onPressThumb?.(value, i);
|
|
93
|
+
} }, i)))] }), trackMarksProp ?
|
|
94
|
+
_jsx(View, { style: styles.trackMarkWrapper, children: trackMarksProp.map((_, idx) => {
|
|
95
|
+
let idxStyle = {};
|
|
96
|
+
const relativeValue = Number(trackMarksProp[idx]);
|
|
97
|
+
if (idx !== 0 && idx !== trackMarksProp.length - 1) {
|
|
98
|
+
const markerPosition = (relativeValue / max) * 100;
|
|
99
|
+
idxStyle = {
|
|
100
|
+
position: 'absolute',
|
|
101
|
+
left: `${markerPosition}%`,
|
|
102
|
+
top: '50%',
|
|
103
|
+
transform: `translate(-50%, -50%)`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const style = mergeStyles([styles.trackMark, idxStyle]);
|
|
107
|
+
if (!trackMarksHaveContent) {
|
|
108
|
+
return _jsx(SliderTrackMark, { index: idx, style: style }, idx);
|
|
109
|
+
}
|
|
110
|
+
const content = trackMarks[relativeValue];
|
|
111
|
+
return (_jsx(SliderTrackMark, { index: idx, content: content, style: style }, idx));
|
|
112
|
+
}) })
|
|
113
|
+
: null, _jsx(Field.Helper, { style: styles.helper })] }) }));
|
|
114
|
+
};
|
|
115
|
+
Slider.styleRegistryName = 'Slider';
|
|
116
|
+
Slider.elements = [
|
|
117
|
+
...Field.elements,
|
|
118
|
+
'thumb',
|
|
119
|
+
'track',
|
|
120
|
+
'selectedTrack',
|
|
121
|
+
'unselectedTrack',
|
|
122
|
+
'trackMark',
|
|
123
|
+
'trackMarkWrapper',
|
|
124
|
+
'sliderContainer',
|
|
125
|
+
];
|
|
126
|
+
Slider.rootElement = 'wrapper';
|
|
127
|
+
Slider.defaultProps = {
|
|
128
|
+
max: 100,
|
|
129
|
+
min: 0,
|
|
130
|
+
minStepsBetweenThumbs: 0,
|
|
131
|
+
defaultValue: [],
|
|
132
|
+
indicatorLabel: null,
|
|
133
|
+
helper: null,
|
|
134
|
+
step: 1,
|
|
135
|
+
onPressThumbSetValue: false,
|
|
136
|
+
onPressThumb: null,
|
|
137
|
+
};
|
|
138
|
+
WebStyleRegistry.registerComponent(Slider);
|
|
139
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Slider/index.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EACL,IAAI,IAAI,eAAe,EACvB,KAAK,IAAI,WAAW,EACpB,KAAK,IAAI,WAAW,EACpB,KAAK,IAAI,WAAW,GAErB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,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CACL,KAAC,eAAe,IACd,KAAK,EAAE,GAAG,EACV,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,IACP,GAAG,CACR,CACH,CAAA;wBACH,CAAC,CAAC,GAEC;oBACP,CAAC,CAAC,IAAI,EACR,KAAC,KAAK,CAAC,MAAM,IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,GAAI,IACxB,GACD,CAClB,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,iBAAiB,GAAG,QAAQ,CAAA;AAEnC,MAAM,CAAC,QAAQ,GAAG;IAChB,GAAG,KAAK,CAAC,QAAQ;IACjB,OAAO;IACP,OAAO;IACP,eAAe;IACf,iBAAiB;IACjB,WAAW;IACX,kBAAkB;IAClB,iBAAiB;CAClB,CAAA;AAED,MAAM,CAAC,WAAW,GAAG,SAAS,CAAA;AAE9B,MAAM,CAAC,YAAY,GAAG;IACpB,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,CAAC;IACN,qBAAqB,EAAE,CAAC;IACxB,YAAY,EAAE,EAAE;IAChB,cAAc,EAAE,IAAI;IACpB,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC;IACP,oBAAoB,EAAE,KAAK;IAC3B,YAAY,EAAE,IAAI;CACK,CAAA;AAEzB,gBAAgB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/components/Slider/styles.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/Slider/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry';
|
|
3
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor';
|
|
4
|
+
import { useFieldInput } from '../Field';
|
|
5
|
+
import { fields } from '@codeleap/form';
|
|
6
|
+
import { Field } from '../Field';
|
|
7
|
+
import { toDataAttrs } from '../../lib';
|
|
8
|
+
import { View } from '../View';
|
|
9
|
+
import { Touchable } from '../Touchable';
|
|
10
|
+
export * from './styles';
|
|
11
|
+
export * from './types';
|
|
12
|
+
/**
|
|
13
|
+
* Boolean toggle control rendered as a sliding track-and-thumb with `Field` layout support (label, helper, sections).
|
|
14
|
+
* Toggles on click or Enter keypress; `disabled` suppresses both.
|
|
15
|
+
* Uses: `Field.Provider`, `Field.Wrapper`, `Field.Heading`, `Field.Helper`, `Touchable`, `View`
|
|
16
|
+
*/
|
|
17
|
+
export const Switch = (props) => {
|
|
18
|
+
const allProps = {
|
|
19
|
+
...Switch.defaultProps,
|
|
20
|
+
...props,
|
|
21
|
+
};
|
|
22
|
+
const { style, disabled, debugName, label, helper, leftSection, rightSection, value, onChange, onValueChange, switchOnLeft, field, } = allProps;
|
|
23
|
+
const { wrapperRef, inputValue, onInputValueChange, validation, } = useFieldInput(field, fields.boolean, { value, onValueChange });
|
|
24
|
+
const handleChange = (e) => {
|
|
25
|
+
if (disabled)
|
|
26
|
+
return;
|
|
27
|
+
if (e?.type === 'click' || e?.keyCode === 13 || e?.key === 'Enter') {
|
|
28
|
+
onInputValueChange?.(!inputValue);
|
|
29
|
+
onChange?.(!inputValue);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const fieldContext = {
|
|
33
|
+
disabled: !!disabled,
|
|
34
|
+
hasValue: !!inputValue,
|
|
35
|
+
error: !!validation?.showError,
|
|
36
|
+
focused: false,
|
|
37
|
+
switchOnLeft: !!switchOnLeft,
|
|
38
|
+
};
|
|
39
|
+
const styles = useStylesFor(Switch.styleRegistryName, style, fieldContext);
|
|
40
|
+
const stateAttrs = toDataAttrs({ value: !!inputValue, disabled: !!disabled });
|
|
41
|
+
return (_jsx(Field.Provider, { context: fieldContext, label: label, helper: validation?.showError ? validation?.message : helper, leftSection: leftSection, rightSection: rightSection, componentName: 'switch', children: _jsxs(Field.Wrapper, { ref: wrapperRef, style: styles.wrapper, children: [_jsx(Field.Heading, { style: styles.heading }), _jsx(Touchable, { debugName: debugName, style: styles.track, ...stateAttrs, onClick: handleChange, onKeyDown: handleChange, tabIndex: 0, children: _jsx(View, { style: styles.thumb, ...stateAttrs }) }), _jsx(Field.Helper, { style: styles.helper })] }) }));
|
|
42
|
+
};
|
|
43
|
+
Switch.styleRegistryName = 'Switch';
|
|
44
|
+
Switch.elements = [...Field.elements, 'track', 'thumb'];
|
|
45
|
+
Switch.rootElement = 'wrapper';
|
|
46
|
+
Switch.defaultProps = {};
|
|
47
|
+
WebStyleRegistry.registerComponent(Switch);
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Switch/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AAEvB;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAkB,EAAE,EAAE;IAC3C,MAAM,QAAQ,GAAG;QACf,GAAG,MAAM,CAAC,YAAY;QACtB,GAAG,KAAK;KACT,CAAA;IAED,MAAM,EACJ,KAAK,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,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,EAC5D,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAC,QAAQ,YAEtB,MAAC,KAAK,CAAC,OAAO,IAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,aACnD,KAAC,KAAK,CAAC,OAAO,IAAC,KAAK,EAAE,MAAM,CAAC,OAAO,GAAI,EAExC,KAAC,SAAS,IACR,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,CAAC,KAAK,KACf,UAAU,EACd,OAAO,EAAE,YAAY,EACrB,SAAS,EAAE,YAAY,EACvB,QAAQ,EAAE,CAAC,YAEX,KAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,KAAK,KAAM,UAAU,GAAI,GACnC,EAEZ,KAAC,KAAK,CAAC,MAAM,IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,GAAI,IACxB,GACD,CAClB,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,iBAAiB,GAAG,QAAQ,CAAA;AACnC,MAAM,CAAC,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;AACvD,MAAM,CAAC,WAAW,GAAG,SAAS,CAAA;AAC9B,MAAM,CAAC,YAAY,GAAG,EAA0B,CAAA;AAEhD,gBAAgB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/components/Switch/styles.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/Switch/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { TypeGuards } from '@codeleap/types';
|
|
4
|
+
import { Icon } from '../Icon';
|
|
5
|
+
import { Text } from '../Text';
|
|
6
|
+
import { Touchable } from '../Touchable';
|
|
7
|
+
import { View } from '../View';
|
|
8
|
+
import { Badge } from '../Badge';
|
|
9
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor';
|
|
10
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry';
|
|
11
|
+
import { mergeStyles, useCompositionStyles } from '@codeleap/styles';
|
|
12
|
+
import { toDataAttrs } from '../../lib';
|
|
13
|
+
export * from './styles';
|
|
14
|
+
export * from './types';
|
|
15
|
+
/**
|
|
16
|
+
* Compact label chip that composes text, icons, badges, and arbitrary slot elements with pressable and disabled state variants.
|
|
17
|
+
* Renders as a `Touchable` (`<button>`) when `onPress` is provided, otherwise as a `View` (`<div>`); `:pressable` and `:disabled` style variants are applied accordingly.
|
|
18
|
+
* Uses: `Touchable`, `Icon`, `Text`, `Badge`
|
|
19
|
+
*/
|
|
20
|
+
export const Tag = (props) => {
|
|
21
|
+
const { rightComponent, leftComponent, style, leftIcon, text, textProps, rightIcon, rightIconProps, leftIconProps, leftBadgeProps, leftBadge, rightBadge, rightBadgeProps, children, onPress, disabled, context, ...touchableProps } = {
|
|
22
|
+
...Tag.defaultProps,
|
|
23
|
+
...props,
|
|
24
|
+
};
|
|
25
|
+
const styles = useStylesFor(Tag.styleRegistryName, style, context);
|
|
26
|
+
const compositionStyles = useCompositionStyles(['rightBadge', 'leftBadge'], styles);
|
|
27
|
+
const isPressable = TypeGuards.isFunction(onPress);
|
|
28
|
+
const Wrapper = isPressable ? Touchable : View;
|
|
29
|
+
const wrapperProps = isPressable ? { onPress, ...touchableProps } : touchableProps;
|
|
30
|
+
const getStylesByKey = (styleKey) => mergeStyles([
|
|
31
|
+
styles?.[styleKey],
|
|
32
|
+
isPressable && styles[`${styleKey}:pressable`],
|
|
33
|
+
disabled && styles[`${styleKey}:disabled`],
|
|
34
|
+
]);
|
|
35
|
+
const wrapperStyles = React.useMemo(() => getStylesByKey('wrapper'), [styles, disabled, isPressable, style]);
|
|
36
|
+
const textStyles = React.useMemo(() => getStylesByKey('text'), [styles, disabled, isPressable]);
|
|
37
|
+
const leftIconStyles = React.useMemo(() => getStylesByKey('leftIcon'), [styles, disabled, isPressable]);
|
|
38
|
+
const rightIconStyles = React.useMemo(() => getStylesByKey('rightIcon'), [styles, disabled, isPressable]);
|
|
39
|
+
const dataAttrs = toDataAttrs(context);
|
|
40
|
+
return (_jsxs(Wrapper, { component: isPressable ? 'button' : 'div', disabled: disabled, ...wrapperProps, style: wrapperStyles, className: 'tag__wrapper', ...dataAttrs, children: [leftComponent, leftBadge && (_jsx(Badge, { debugName: `${touchableProps?.debugName}:leftBadge`, style: compositionStyles.leftBadge, badge: leftBadge, disabled: disabled, className: 'tag__badge tag__left_badge', ...leftBadgeProps })), !TypeGuards.isNil(leftIcon) && (_jsx(Icon, { debugName: `${touchableProps?.debugName}:leftIcon`, style: leftIconStyles, icon: leftIcon, className: 'tag__icon tag__left_icon', ...leftIconProps })), TypeGuards.isString(text) ? _jsx(Text, { text: text, style: textStyles, ...textProps, className: 'tag__text' }) : text, children, !TypeGuards.isNil(rightIcon) && (_jsx(Icon, { debugName: `${touchableProps?.debugName}:rightIcon`, style: rightIconStyles, icon: rightIcon, className: 'tag__icon tag__right_icon', ...rightIconProps })), rightBadge && (_jsx(Badge, { debugName: `${touchableProps?.debugName}:rightBadge`, style: compositionStyles.rightBadge, badge: rightBadge, disabled: disabled, className: 'tag__badge tag__right_badge', ...rightBadgeProps })), rightComponent] }));
|
|
41
|
+
};
|
|
42
|
+
Tag.styleRegistryName = 'Tag';
|
|
43
|
+
Tag.elements = ['wrapper', 'text', 'leftIcon', 'rightIcon', 'leftBadge', 'rightBadge'];
|
|
44
|
+
Tag.rootElement = 'wrapper';
|
|
45
|
+
Tag.withVariantTypes = (styles) => {
|
|
46
|
+
return Tag;
|
|
47
|
+
};
|
|
48
|
+
Tag.defaultProps = {
|
|
49
|
+
debugName: 'Tag component',
|
|
50
|
+
disabled: false,
|
|
51
|
+
};
|
|
52
|
+
WebStyleRegistry.registerComponent(Tag);
|
|
53
|
+
//# sourceMappingURL=index.js.map
|