@codeleap/mobile 7.0.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Registry.js +47 -0
- package/dist/Registry.js.map +1 -0
- 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/Autocomplete/index.js +150 -0
- package/dist/components/Autocomplete/index.js.map +1 -0
- package/dist/components/Autocomplete/styles.js +2 -0
- package/dist/components/Autocomplete/styles.js.map +1 -0
- package/dist/components/Autocomplete/types.js +2 -0
- package/dist/components/Autocomplete/types.js.map +1 -0
- package/dist/components/Avatar/components/Badge.js +13 -0
- package/dist/components/Avatar/components/Badge.js.map +1 -0
- package/dist/components/Avatar/components/Content.js +19 -0
- package/dist/components/Avatar/components/Content.js.map +1 -0
- package/dist/components/Avatar/components/Illustration.js +11 -0
- package/dist/components/Avatar/components/Illustration.js.map +1 -0
- package/dist/components/Avatar/components/OverlayIcon.js +11 -0
- package/dist/components/Avatar/components/OverlayIcon.js.map +1 -0
- package/dist/components/Avatar/components/Text.js +19 -0
- package/dist/components/Avatar/components/Text.js.map +1 -0
- package/dist/components/Avatar/components/Wrapper.js +30 -0
- package/dist/components/Avatar/components/Wrapper.js.map +1 -0
- package/dist/components/Avatar/context.js +13 -0
- package/dist/components/Avatar/context.js.map +1 -0
- package/dist/components/Avatar/index.js +35 -0
- package/dist/components/Avatar/index.js.map +1 -0
- package/dist/components/Avatar/styles.js +2 -0
- package/dist/components/Avatar/styles.js.map +1 -0
- package/dist/components/Avatar/types.js +2 -0
- package/dist/components/Avatar/types.js.map +1 -0
- package/dist/components/AvatarGroup/index.js +36 -0
- package/dist/components/AvatarGroup/index.js.map +1 -0
- package/dist/components/AvatarGroup/styles.js +2 -0
- package/dist/components/AvatarGroup/styles.js.map +1 -0
- package/dist/components/AvatarGroup/types.js +2 -0
- package/dist/components/AvatarGroup/types.js.map +1 -0
- package/dist/components/Backdrop/index.js +34 -0
- package/dist/components/Backdrop/index.js.map +1 -0
- package/dist/components/Backdrop/styles.js +2 -0
- package/dist/components/Backdrop/styles.js.map +1 -0
- package/dist/components/Backdrop/types.js +2 -0
- package/dist/components/Backdrop/types.js.map +1 -0
- package/dist/components/Badge/index.js +66 -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 +73 -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 +100 -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/CalendarInput/index.js +67 -0
- package/dist/components/CalendarInput/index.js.map +1 -0
- package/dist/components/CalendarInput/styles.js +2 -0
- package/dist/components/CalendarInput/styles.js.map +1 -0
- package/dist/components/CalendarInput/types.js +2 -0
- package/dist/components/CalendarInput/types.js.map +1 -0
- package/dist/components/Checkbox/index.js +85 -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 +45 -0
- package/dist/components/Collapse/index.js.map +1 -0
- package/dist/components/Collapse/types.js +2 -0
- package/dist/components/Collapse/types.js.map +1 -0
- package/dist/components/DatePickerModal/index.js +107 -0
- package/dist/components/DatePickerModal/index.js.map +1 -0
- package/dist/components/DatePickerModal/styles.js +2 -0
- package/dist/components/DatePickerModal/styles.js.map +1 -0
- package/dist/components/DatePickerModal/types.js +2 -0
- package/dist/components/DatePickerModal/types.js.map +1 -0
- package/dist/components/EmptyPlaceholder/components/Button.js +15 -0
- package/dist/components/EmptyPlaceholder/components/Button.js.map +1 -0
- package/dist/components/EmptyPlaceholder/components/Content.js +36 -0
- package/dist/components/EmptyPlaceholder/components/Content.js.map +1 -0
- package/dist/components/EmptyPlaceholder/components/Illustration.js +9 -0
- package/dist/components/EmptyPlaceholder/components/Illustration.js.map +1 -0
- package/dist/components/EmptyPlaceholder/components/Info.js +9 -0
- package/dist/components/EmptyPlaceholder/components/Info.js.map +1 -0
- package/dist/components/EmptyPlaceholder/components/Loading.js +20 -0
- package/dist/components/EmptyPlaceholder/components/Loading.js.map +1 -0
- package/dist/components/EmptyPlaceholder/context.js +13 -0
- package/dist/components/EmptyPlaceholder/context.js.map +1 -0
- package/dist/components/EmptyPlaceholder/index.js +38 -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/FileInput/index.js +126 -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/Grid/index.js +65 -0
- package/dist/components/Grid/index.js.map +1 -0
- package/dist/components/Grid/styles.js +2 -0
- package/dist/components/Grid/styles.js.map +1 -0
- package/dist/components/Grid/types.js +2 -0
- package/dist/components/Grid/types.js.map +1 -0
- package/dist/components/Icon/index.js +59 -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/Image/index.js +108 -0
- package/dist/components/Image/index.js.map +1 -0
- package/dist/components/Image/styles.js +2 -0
- package/dist/components/Image/styles.js.map +1 -0
- package/dist/components/Image/types.js +2 -0
- package/dist/components/Image/types.js.map +1 -0
- package/dist/components/ImageView/Spotlight.js +139 -0
- package/dist/components/ImageView/Spotlight.js.map +1 -0
- package/dist/components/ImageView/component.js +17 -0
- package/dist/components/ImageView/component.js.map +1 -0
- package/dist/components/ImageView/index.js +3 -0
- package/dist/components/ImageView/index.js.map +1 -0
- package/dist/components/InputBase/index.js +37 -0
- package/dist/components/InputBase/index.js.map +1 -0
- package/dist/components/InputBase/styles.js +98 -0
- package/dist/components/InputBase/styles.js.map +1 -0
- package/dist/components/InputBase/types.js +2 -0
- package/dist/components/InputBase/types.js.map +1 -0
- package/dist/components/InputBase/useInputBase.js +48 -0
- package/dist/components/InputBase/useInputBase.js.map +1 -0
- package/dist/components/InputBase/useInputBasePartialStyles.js +35 -0
- package/dist/components/InputBase/useInputBasePartialStyles.js.map +1 -0
- package/dist/components/InputBase/utils.js +31 -0
- package/dist/components/InputBase/utils.js.map +1 -0
- package/dist/components/InputOverlay/index.js +68 -0
- package/dist/components/InputOverlay/index.js.map +1 -0
- package/dist/components/InputOverlay/store.js +49 -0
- package/dist/components/InputOverlay/store.js.map +1 -0
- package/dist/components/InputOverlay/types.js +2 -0
- package/dist/components/InputOverlay/types.js.map +1 -0
- package/dist/components/List/index.js +66 -0
- package/dist/components/List/index.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 +51 -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/Modal/index.js +76 -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 +120 -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 +116 -0
- package/dist/components/NumberIncrement/useNumberIncrement.js.map +1 -0
- package/dist/components/Pager/PagerDots.js +19 -0
- package/dist/components/Pager/PagerDots.js.map +1 -0
- package/dist/components/Pager/PagerItem.js +14 -0
- package/dist/components/Pager/PagerItem.js.map +1 -0
- package/dist/components/Pager/index.js +78 -0
- package/dist/components/Pager/index.js.map +1 -0
- package/dist/components/Pager/styles.js +2 -0
- package/dist/components/Pager/styles.js.map +1 -0
- package/dist/components/Pager/types.js +2 -0
- package/dist/components/Pager/types.js.map +1 -0
- package/dist/components/PaginationIndicator/index.js +36 -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/PlacesAutocomplete/index.js +71 -0
- package/dist/components/PlacesAutocomplete/index.js.map +1 -0
- package/dist/components/PlacesAutocomplete/styles.js +2 -0
- package/dist/components/PlacesAutocomplete/styles.js.map +1 -0
- package/dist/components/PlacesAutocomplete/types.js +2 -0
- package/dist/components/PlacesAutocomplete/types.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/RefreshControl/index.js +27 -0
- package/dist/components/RefreshControl/index.js.map +1 -0
- package/dist/components/RefreshControl/styles.js +2 -0
- package/dist/components/RefreshControl/styles.js.map +1 -0
- package/dist/components/RefreshControl/types.js +2 -0
- package/dist/components/RefreshControl/types.js.map +1 -0
- package/dist/components/Scroll/index.js +40 -0
- package/dist/components/Scroll/index.js.map +1 -0
- package/dist/components/Scroll/styles.js +2 -0
- package/dist/components/Scroll/styles.js.map +1 -0
- package/dist/components/Scroll/types.js +2 -0
- package/dist/components/Scroll/types.js.map +1 -0
- package/dist/components/SearchInput/index.js +48 -0
- package/dist/components/SearchInput/index.js.map +1 -0
- package/dist/components/SectionFilters/context.js +6 -0
- package/dist/components/SectionFilters/context.js.map +1 -0
- package/dist/components/SectionFilters/index.js +47 -0
- package/dist/components/SectionFilters/index.js.map +1 -0
- package/dist/components/SectionFilters/types.js +2 -0
- package/dist/components/SectionFilters/types.js.map +1 -0
- package/dist/components/SectionFilters/useSectionFilters.js +148 -0
- package/dist/components/SectionFilters/useSectionFilters.js.map +1 -0
- package/dist/components/Sections/index.js +105 -0
- package/dist/components/Sections/index.js.map +1 -0
- package/dist/components/Sections/styles.js +2 -0
- package/dist/components/Sections/styles.js.map +1 -0
- package/dist/components/Sections/types.js +2 -0
- package/dist/components/Sections/types.js.map +1 -0
- package/dist/components/SegmentedControl/Option.js +20 -0
- package/dist/components/SegmentedControl/Option.js.map +1 -0
- package/dist/components/SegmentedControl/index.js +130 -0
- package/dist/components/SegmentedControl/index.js.map +1 -0
- package/dist/components/SegmentedControl/styles.js +2 -0
- package/dist/components/SegmentedControl/styles.js.map +1 -0
- package/dist/components/SegmentedControl/types.js +2 -0
- package/dist/components/SegmentedControl/types.js.map +1 -0
- package/dist/components/Select/index.js +204 -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/Slider/index.js +99 -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/SortablePhotos/index.js +85 -0
- package/dist/components/SortablePhotos/index.js.map +1 -0
- package/dist/components/SortablePhotos/styles.js +2 -0
- package/dist/components/SortablePhotos/styles.js.map +1 -0
- package/dist/components/SortablePhotos/types.js +2 -0
- package/dist/components/SortablePhotos/types.js.map +1 -0
- package/dist/components/SortablePhotos/useSortablePhotos.js +143 -0
- package/dist/components/SortablePhotos/useSortablePhotos.js.map +1 -0
- package/dist/components/Switch/index.js +81 -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/Tabs/Context.js +44 -0
- package/dist/components/Tabs/Context.js.map +1 -0
- package/dist/components/Tabs/Panel.js +21 -0
- package/dist/components/Tabs/Panel.js.map +1 -0
- package/dist/components/Tabs/Tab.js +28 -0
- package/dist/components/Tabs/Tab.js.map +1 -0
- package/dist/components/Tabs/TabList.js +16 -0
- package/dist/components/Tabs/TabList.js.map +1 -0
- package/dist/components/Tabs/index.js +34 -0
- package/dist/components/Tabs/index.js.map +1 -0
- package/dist/components/Tabs/styles.js +2 -0
- package/dist/components/Tabs/styles.js.map +1 -0
- package/dist/components/Tabs/types.js +2 -0
- package/dist/components/Tabs/types.js.map +1 -0
- package/dist/components/Text/index.js +82 -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/TextInput/index.js +99 -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 +66 -0
- package/dist/components/TextInput/useTextInput.js.map +1 -0
- package/dist/components/TimeInput/index.js +50 -0
- package/dist/components/TimeInput/index.js.map +1 -0
- package/dist/components/TimeInput/styles.js +2 -0
- package/dist/components/TimeInput/styles.js.map +1 -0
- package/dist/components/TimeInput/types.js +2 -0
- package/dist/components/TimeInput/types.js.map +1 -0
- package/dist/components/Touchable/index.js +170 -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 +28 -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 +46 -0
- package/dist/components/components.js.map +1 -0
- package/dist/hooks/index.js +6 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useAnimatedState.js +28 -0
- package/dist/hooks/useAnimatedState.js.map +1 -0
- package/dist/hooks/useAppState.js +16 -0
- package/dist/hooks/useAppState.js.map +1 -0
- package/dist/hooks/useKeyboardController.js +22 -0
- package/dist/hooks/useKeyboardController.js.map +1 -0
- package/dist/hooks/useStatusBar.js +18 -0
- package/dist/hooks/useStatusBar.js.map +1 -0
- package/dist/hooks/useStylesFor.js +13 -0
- package/dist/hooks/useStylesFor.js.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/PressableRipple/index.js +3 -0
- package/dist/modules/PressableRipple/index.js.map +1 -0
- package/dist/modules/PressableRipple/ripple.js +168 -0
- package/dist/modules/PressableRipple/ripple.js.map +1 -0
- package/dist/modules/PressableRipple/styles.js +18 -0
- package/dist/modules/PressableRipple/styles.js.map +1 -0
- package/dist/modules/PressableRipple/type.js +2 -0
- package/dist/modules/PressableRipple/type.js.map +1 -0
- package/dist/modules/backgroundTimer.js +33 -0
- package/dist/modules/backgroundTimer.js.map +1 -0
- package/dist/modules/formConfig.js +26 -0
- package/dist/modules/formConfig.js.map +1 -0
- package/dist/modules/index.js +3 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/reactNavigation.js +39 -0
- package/dist/modules/reactNavigation.js.map +1 -0
- package/dist/modules/scroll.js +59 -0
- package/dist/modules/scroll.js.map +1 -0
- package/dist/modules/textInputMask.js +7 -0
- package/dist/modules/textInputMask.js.map +1 -0
- package/dist/modules/types/textInputMask.js +2 -0
- package/dist/modules/types/textInputMask.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/dist/utils/NotificationManager/index.js +170 -0
- package/dist/utils/NotificationManager/index.js.map +1 -0
- package/dist/utils/NotificationManager/types.js +2 -0
- package/dist/utils/NotificationManager/types.js.map +1 -0
- package/dist/utils/OSAlert.js +128 -0
- package/dist/utils/OSAlert.js.map +1 -0
- package/dist/utils/StorageManager.js +84 -0
- package/dist/utils/StorageManager.js.map +1 -0
- package/dist/utils/Subscription.js +48 -0
- package/dist/utils/Subscription.js.map +1 -0
- package/dist/utils/hooks.js +199 -0
- package/dist/utils/hooks.js.map +1 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/input.js +45 -0
- package/dist/utils/input.js.map +1 -0
- package/dist/utils/locale.js +11 -0
- package/dist/utils/locale.js.map +1 -0
- package/dist/utils/misc.js +111 -0
- package/dist/utils/misc.js.map +1 -0
- package/dist/utils/theme.js +37 -0
- package/dist/utils/theme.js.map +1 -0
- package/dist/utils/useQueryListRefresh.js +33 -0
- package/dist/utils/useQueryListRefresh.js.map +1 -0
- package/package.json +19 -19
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable max-lines */
|
|
3
|
+
import { TypeGuards } from '@codeleap/types';
|
|
4
|
+
import { onMount, onUpdate, usePrevious, useSearch, useConditionalState, } from '@codeleap/hooks';
|
|
5
|
+
import { useCallback, useMemo } from 'react';
|
|
6
|
+
import { List } from '../List';
|
|
7
|
+
import { TextInput } from '../TextInput';
|
|
8
|
+
import { Button } from '../Button';
|
|
9
|
+
import { useCompositionStyles } from '@codeleap/styles';
|
|
10
|
+
import { Modal } from '../Modal';
|
|
11
|
+
import { MobileStyleRegistry } from '../../Registry';
|
|
12
|
+
import { SearchInput } from '../SearchInput';
|
|
13
|
+
import { useStylesFor } from '../../hooks';
|
|
14
|
+
import { fields } from '@codeleap/form';
|
|
15
|
+
import { useInputBase } from '../InputBase/useInputBase';
|
|
16
|
+
export * from './styles';
|
|
17
|
+
export * from './types';
|
|
18
|
+
/** Client-side only — skipped entirely when `loadOptions` is provided, since server search supersedes local filtering. */
|
|
19
|
+
const defaultFilterFunction = (search, options) => {
|
|
20
|
+
return options.filter((option) => {
|
|
21
|
+
if (TypeGuards.isString(option.label)) {
|
|
22
|
+
return option.label.toLowerCase().includes(search.toLowerCase());
|
|
23
|
+
}
|
|
24
|
+
return option.label === search;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const defaultGetLabel = (option) => {
|
|
28
|
+
if (TypeGuards.isArray(option)) {
|
|
29
|
+
if (option?.length === 0)
|
|
30
|
+
return null;
|
|
31
|
+
const labels = option?.map(option => option?.label)?.filter(value => !!value);
|
|
32
|
+
return labels?.join(', ');
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (!option)
|
|
36
|
+
return null;
|
|
37
|
+
return option?.label;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The TextInput here is intentionally non-editable — `onValueChange` returns the current label
|
|
42
|
+
* to prevent the native keyboard from mutating the display value directly. Editing is done via the modal.
|
|
43
|
+
*/
|
|
44
|
+
const OuterInput = (props) => {
|
|
45
|
+
const { currentValueLabel, debugName, clearIcon, label, toggle, style, placeholder, disabled = false, inputProps = {}, } = props;
|
|
46
|
+
return _jsx(TextInput, { value: TypeGuards.isString(currentValueLabel) ? currentValueLabel : null, onValueChange: () => currentValueLabel, rightIcon: clearIcon, onPress: disabled ? null : () => toggle(), disabled: disabled, label: label, debugName: debugName, style: style, innerWrapperProps: {
|
|
47
|
+
rippleDisabled: true,
|
|
48
|
+
}, placeholder: placeholder, ...inputProps });
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Dropdown is always rendered inside a Modal — there is no native ActionSheet or platform-specific
|
|
52
|
+
* picker. Keyboard is not auto-dismissed on open; pass `keyboardShouldPersistTaps` via `listProps`
|
|
53
|
+
* if the modal appears beneath a focused input.
|
|
54
|
+
*/
|
|
55
|
+
export const Select = (selectProps) => {
|
|
56
|
+
const allProps = {
|
|
57
|
+
...Select.defaultProps,
|
|
58
|
+
...selectProps,
|
|
59
|
+
};
|
|
60
|
+
const { label, options = [], style, description, renderItem: Item, listProps, debugName, placeholder, arrowIconName, clearIconName, clearable, selectedIcon, inputProps = {}, hideInput, itemProps = {}, searchable, loadOptions, multiple, closeOnSelect = !multiple, limit = null, defaultOptions = options, visible: _visible, toggle: _toggle, ListHeaderComponent, ListComponent, onLoadOptionsError, loadOptionsOnMount = defaultOptions.length === 0, loadOptionsOnOpen, filterItems, getLabel, searchInputProps, outerInputComponent, disabled, field, value, onValueChange, onSelect, ...modalProps } = allProps;
|
|
61
|
+
const { inputValue, onInputValueChange, } = useInputBase(field, fields.selectable, { value, onValueChange });
|
|
62
|
+
const isValueArray = TypeGuards.isArray(inputValue) && multiple;
|
|
63
|
+
const { loading, setLoading, labelOptions, setLabelOptions, filteredOptions, load, onChangeSearch, } = useSearch({
|
|
64
|
+
value: inputValue,
|
|
65
|
+
multiple,
|
|
66
|
+
options,
|
|
67
|
+
filterItems,
|
|
68
|
+
debugName,
|
|
69
|
+
defaultOptions,
|
|
70
|
+
loadOptions,
|
|
71
|
+
onLoadOptionsError,
|
|
72
|
+
});
|
|
73
|
+
const [visible, toggle] = useConditionalState(_visible, _toggle, { initialValue: false, isBooleanToggle: true });
|
|
74
|
+
const currentValueLabel = useMemo(() => {
|
|
75
|
+
const _options = (multiple ? labelOptions : labelOptions?.[0]);
|
|
76
|
+
const label = getLabel(_options);
|
|
77
|
+
return label;
|
|
78
|
+
}, [labelOptions]);
|
|
79
|
+
onMount(() => {
|
|
80
|
+
if (loadOptionsOnMount && !!loadOptions) {
|
|
81
|
+
load();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const prevVisible = usePrevious(visible);
|
|
85
|
+
onUpdate(() => {
|
|
86
|
+
if (visible && !prevVisible && loadOptionsOnOpen && !!loadOptions) {
|
|
87
|
+
load();
|
|
88
|
+
}
|
|
89
|
+
}, [visible, prevVisible]);
|
|
90
|
+
const styles = useStylesFor(Select.styleRegistryName, style);
|
|
91
|
+
const compositionStyles = useCompositionStyles(['item', 'list', 'input', 'searchInput'], styles);
|
|
92
|
+
const currentOptions = searchable ? filteredOptions : defaultOptions;
|
|
93
|
+
const close = () => toggle?.();
|
|
94
|
+
const select = useCallback((selectedValue) => {
|
|
95
|
+
let newValue = null;
|
|
96
|
+
let newOption = null;
|
|
97
|
+
let removedIndex = null;
|
|
98
|
+
if (multiple && isValueArray) {
|
|
99
|
+
if (inputValue.includes(selectedValue)) {
|
|
100
|
+
removedIndex = inputValue.findIndex(v => v === selectedValue);
|
|
101
|
+
newValue = inputValue.filter((v, i) => i !== removedIndex);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (TypeGuards.isNumber(limit) && inputValue.length >= limit) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
newOption = currentOptions.find(o => o.value === selectedValue);
|
|
108
|
+
newValue = [...inputValue, selectedValue];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
newValue = selectedValue;
|
|
113
|
+
newOption = currentOptions.find(o => o.value === selectedValue);
|
|
114
|
+
}
|
|
115
|
+
onInputValueChange(newValue);
|
|
116
|
+
onSelect?.(newValue);
|
|
117
|
+
if (isValueArray) {
|
|
118
|
+
if (removedIndex !== null) {
|
|
119
|
+
const newOptions = [...labelOptions];
|
|
120
|
+
newOptions.splice(removedIndex, 1);
|
|
121
|
+
setLabelOptions(newOptions);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const newLabels = [...labelOptions, newOption];
|
|
125
|
+
setLabelOptions(newLabels);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
setLabelOptions([newOption]);
|
|
130
|
+
}
|
|
131
|
+
if (closeOnSelect) {
|
|
132
|
+
close?.();
|
|
133
|
+
}
|
|
134
|
+
}, [isValueArray, (isValueArray ? inputValue : [inputValue]), limit, multiple, labelOptions, currentOptions]);
|
|
135
|
+
const renderListItem = useCallback(({ item, index }) => {
|
|
136
|
+
let selected = false;
|
|
137
|
+
if (multiple && isValueArray) {
|
|
138
|
+
selected = inputValue?.includes(item.value);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
selected = inputValue === item.value;
|
|
142
|
+
}
|
|
143
|
+
return (_jsx(Item, { debugName: `${debugName} item ${item.value}`, selected: selected, text: item.label, item: item, onPress: () => select(item.value),
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
icon: selectedIcon,
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
rightIcon: selectedIcon, style: compositionStyles?.item, index: index, ...itemProps }));
|
|
148
|
+
}, [inputValue, select, multiple]);
|
|
149
|
+
const isEmpty = TypeGuards.isNil(inputValue);
|
|
150
|
+
const showClearIcon = !isEmpty && clearable;
|
|
151
|
+
const inputIcon = showClearIcon ? clearIconName : arrowIconName;
|
|
152
|
+
const onPressInputIcon = () => {
|
|
153
|
+
if (showClearIcon) {
|
|
154
|
+
onInputValueChange(null);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
close?.();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
/** Debounce is only applied when `loadOptions` is provided; local filtering runs synchronously. */
|
|
161
|
+
const searchHeader = searchable ? _jsx(SearchInput, { debugName: debugName, onTypingChange: (isTyping) => {
|
|
162
|
+
if (searchable && !!loadOptions) {
|
|
163
|
+
setLoading(isTyping);
|
|
164
|
+
}
|
|
165
|
+
}, debounce: !!loadOptions ? 800 : null, onSearchChange: onChangeSearch, style: compositionStyles?.searchInput, ...searchInputProps }) : null;
|
|
166
|
+
const _ListHeaderComponent = useMemo(() => {
|
|
167
|
+
if (ListHeaderComponent) {
|
|
168
|
+
return _jsx(ListHeaderComponent, { searchComponent: searchHeader });
|
|
169
|
+
}
|
|
170
|
+
return searchHeader;
|
|
171
|
+
}, [searchable, ListHeaderComponent]);
|
|
172
|
+
const Input = outerInputComponent;
|
|
173
|
+
return _jsxs(_Fragment, { children: [!hideInput ? (_jsx(Input, { clearIcon: {
|
|
174
|
+
icon: inputIcon,
|
|
175
|
+
onPress: disabled ? null : onPressInputIcon,
|
|
176
|
+
}, currentValueLabel: currentValueLabel, debugName: `${debugName} select input`, style: compositionStyles?.input, ...allProps, ...inputProps, visible: visible, toggle: toggle })) : null, _jsx(Modal, { title: label, description: description, ...modalProps, debugName: `${debugName} modal`, style: styles, id: null, visible: visible, toggle: toggle, children: _jsx(ListComponent, { data: searchable ? filteredOptions : options, scrollEnabled: true, showsHorizontalScrollIndicator: false, style: compositionStyles?.list, keyExtractor: (i) => i.value, renderItem: renderListItem, fakeEmpty: loading, separators: true, keyboardAware: false, ...listProps, ListHeaderComponent: _ListHeaderComponent, placeholder: {
|
|
177
|
+
loading,
|
|
178
|
+
} }) })] });
|
|
179
|
+
};
|
|
180
|
+
Select.styleRegistryName = 'Select';
|
|
181
|
+
Select.elements = [...Modal.elements, 'input', 'list', 'item', 'searchInput'];
|
|
182
|
+
Select.rootElement = 'inputWrapper';
|
|
183
|
+
Select.withVariantTypes = (styles) => {
|
|
184
|
+
return Select;
|
|
185
|
+
};
|
|
186
|
+
Select.defaultProps = {
|
|
187
|
+
getLabel: defaultGetLabel,
|
|
188
|
+
outerInputComponent: OuterInput,
|
|
189
|
+
searchInputProps: {},
|
|
190
|
+
arrowIconName: 'chevrons-up-down',
|
|
191
|
+
clearIconName: 'x',
|
|
192
|
+
placeholder: 'Select',
|
|
193
|
+
clearable: false,
|
|
194
|
+
selectedIcon: 'check',
|
|
195
|
+
hideInput: false,
|
|
196
|
+
multiple: false,
|
|
197
|
+
loadOptionsOnOpen: false,
|
|
198
|
+
disabled: false,
|
|
199
|
+
filterItems: defaultFilterFunction,
|
|
200
|
+
renderItem: Button,
|
|
201
|
+
ListComponent: List,
|
|
202
|
+
};
|
|
203
|
+
MobileStyleRegistry.registerComponent(Select);
|
|
204
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Select/index.tsx"],"names":[],"mappings":";AAAA,8BAA8B;AAC9B,OAAO,EAAmB,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EACL,OAAO,EACP,QAAQ,EACR,WAAW,EACX,SAAS,EACT,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AACxB,OAAc,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,WA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a,EAAE,GAAc;IAC7B,WAAW,EAAE,QAAQ;IACrB,SAAS,EAAE,KAAK;IAChB,YAAY,EAAE,OAAkB;IAChC,SAAS,EAAE,KAAK;IAChB,QAAQ,EAAE,KAAK;IACf,iBAAiB,EAAE,KAAK;IACxB,QAAQ,EAAE,KAAK;IACf,WAAW,EAAE,qBAAqB;IAClC,UAAU,EAAE,MAAM;IAClB,aAAa,EAAE,IAAI;CACkB,CAAA;AAEvC,mBAAmB,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,99 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Slider as RNSlider } from '@miblanchard/react-native-slider';
|
|
4
|
+
import { TypeGuards } from '@codeleap/types';
|
|
5
|
+
import { onUpdate } from '@codeleap/hooks';
|
|
6
|
+
import { InputBase, selectInputBaseProps } from '../InputBase';
|
|
7
|
+
import { Text } from '../Text';
|
|
8
|
+
import { View } from '../View';
|
|
9
|
+
import { Touchable } from '../Touchable';
|
|
10
|
+
import { MobileStyleRegistry } from '../../Registry';
|
|
11
|
+
import { useStylesFor } from '../../hooks';
|
|
12
|
+
import { useInputBase } from '../InputBase/useInputBase';
|
|
13
|
+
import { fields } from '@codeleap/form';
|
|
14
|
+
import { useInputBasePartialStyles } from '../InputBase/useInputBasePartialStyles';
|
|
15
|
+
export * from './styles';
|
|
16
|
+
export * from './types';
|
|
17
|
+
const DefaultSliderTrackMark = (props) => {
|
|
18
|
+
const { style, onPress } = props;
|
|
19
|
+
if (!TypeGuards.isString(props.content)) {
|
|
20
|
+
return _jsx(_Fragment, { children: props.content });
|
|
21
|
+
}
|
|
22
|
+
return _jsx(Text, { text: props.content, style: style, onPress: onPress });
|
|
23
|
+
};
|
|
24
|
+
const minimumValue = 0;
|
|
25
|
+
const maximumValue = 100;
|
|
26
|
+
export const Slider = (props) => {
|
|
27
|
+
const { inputBaseProps: { label: _label, description: _description, ..._inputBaseProps }, others, } = selectInputBaseProps({
|
|
28
|
+
...Slider.defaultProps,
|
|
29
|
+
...props,
|
|
30
|
+
});
|
|
31
|
+
const { debounce = null, field, label, description, debugName, style, disabled, trackMarks, trackMarksClickable, labelClickable, updateImmediately = false, trackMarkComponent: SliderTrackMark, value, onValueChange, ...sliderProps } = others;
|
|
32
|
+
const { wrapperRef, inputValue, onInputValueChange, } = useInputBase(field, fields.number, { value, onValueChange });
|
|
33
|
+
/**
|
|
34
|
+
* When `updateImmediately` is false, the committed value is only written on `onSlidingComplete`
|
|
35
|
+
* to avoid flooding the form/state store with every pixel of movement; `_value` is the local
|
|
36
|
+
* thumb position and `inputValue` is the last committed value.
|
|
37
|
+
*/
|
|
38
|
+
const [_value, _setValue] = updateImmediately ? [inputValue, onInputValueChange] : React.useState(0);
|
|
39
|
+
onUpdate(() => {
|
|
40
|
+
if (updateImmediately)
|
|
41
|
+
return;
|
|
42
|
+
if (inputValue !== _value) {
|
|
43
|
+
_setValue(inputValue);
|
|
44
|
+
}
|
|
45
|
+
}, [inputValue]);
|
|
46
|
+
const styles = useStylesFor(Slider.styleRegistryName, style);
|
|
47
|
+
const partialStyles = useInputBasePartialStyles(styles, ['thumb', 'track', 'selectedTrack', 'unselectedTrack', 'sliderContainer', 'trackMark'], { disabled });
|
|
48
|
+
const trackMarksHaveContent = !(TypeGuards.isArray(trackMarks) || TypeGuards.isNil(trackMarks));
|
|
49
|
+
const trackMarksProp = React.useMemo(() => {
|
|
50
|
+
if (!trackMarksHaveContent) {
|
|
51
|
+
return trackMarks;
|
|
52
|
+
}
|
|
53
|
+
return Object.keys(trackMarks).map((key) => Number(key));
|
|
54
|
+
}, [trackMarksHaveContent]);
|
|
55
|
+
return (_jsxs(InputBase, { ..._inputBaseProps, ref: wrapperRef, disabled: disabled, style: styles, labelAsRow: true, children: [label || description ? (_jsxs(View, { style: styles.labelRow, children: [label ? (_jsx(Touchable, { onPress: () => labelClickable ? onInputValueChange(sliderProps?.minimumValue || minimumValue) : null, style: styles.labelBtn, debugName: 'slider title', children: _jsx(Text, { style: styles?.label, text: label }) })) : null, description ? (_jsx(Touchable, { onPress: () => labelClickable ? onInputValueChange(sliderProps?.maximumValue || maximumValue) : null, style: styles?.descriptionBtn, debugName: 'slider description', children: _jsx(Text, { style: styles?.description, text: description }) })) : null] })) : null, _jsx(RNSlider, { value: _value, onValueChange: _setValue, thumbStyle: partialStyles?.thumb, trackStyle: partialStyles?.track, minimumTrackStyle: partialStyles?.selectedTrack, maximumTrackStyle: partialStyles?.unselectedTrack, containerStyle: partialStyles?.sliderContainer, minimumValue: minimumValue, maximumValue: maximumValue, onSlidingComplete: () => {
|
|
56
|
+
if (updateImmediately)
|
|
57
|
+
return;
|
|
58
|
+
onInputValueChange(_value);
|
|
59
|
+
}, disabled: disabled, ...sliderProps, trackMarks: trackMarksProp }), trackMarksProp ? (_jsx(View, { style: styles?.trackMarkWrapper, children: trackMarksProp.map((_, idx) => {
|
|
60
|
+
let idxStyle = {};
|
|
61
|
+
if (idx === 0) {
|
|
62
|
+
idxStyle = styles?.firstTrackMark;
|
|
63
|
+
}
|
|
64
|
+
else if (idx === trackMarksProp.length - 1) {
|
|
65
|
+
idxStyle = styles?.lastTrackMark;
|
|
66
|
+
}
|
|
67
|
+
const style = [partialStyles?.trackMark, idxStyle];
|
|
68
|
+
if (!trackMarksHaveContent) {
|
|
69
|
+
return _jsx(SliderTrackMark, { index: idx, style: style, onPress: () => trackMarksClickable ? onInputValueChange(trackMarksProp[idx]) : null }, idx);
|
|
70
|
+
}
|
|
71
|
+
const relativeValue = trackMarksProp[idx];
|
|
72
|
+
const content = trackMarks[relativeValue];
|
|
73
|
+
return _jsx(SliderTrackMark, { index: idx, content: content, style: style, onPress: () => trackMarksClickable ? onInputValueChange(trackMarksProp[idx]) : null }, idx);
|
|
74
|
+
}) })) : null] }));
|
|
75
|
+
};
|
|
76
|
+
Slider.styleRegistryName = 'Slider';
|
|
77
|
+
Slider.rootElement = 'wrapper';
|
|
78
|
+
Slider.elements = [
|
|
79
|
+
...InputBase.elements,
|
|
80
|
+
'thumb',
|
|
81
|
+
'track',
|
|
82
|
+
'selectedTrack',
|
|
83
|
+
'unselectedTrack',
|
|
84
|
+
'firstTrackMark',
|
|
85
|
+
'lastTrackMark',
|
|
86
|
+
'sliderContainer',
|
|
87
|
+
'labelBtn',
|
|
88
|
+
'descriptionBtn',
|
|
89
|
+
];
|
|
90
|
+
Slider.withVariantTypes = (styles) => {
|
|
91
|
+
return Slider;
|
|
92
|
+
};
|
|
93
|
+
Slider.defaultProps = {
|
|
94
|
+
trackMarksClickable: false,
|
|
95
|
+
labelClickable: false,
|
|
96
|
+
trackMarkComponent: DefaultSliderTrackMark,
|
|
97
|
+
};
|
|
98
|
+
MobileStyleRegistry.registerComponent(Slider);
|
|
99
|
+
//# 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,MAAM,IAAI,QAAQ,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE1C,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CA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AAC,CAAA;oBAEzC,OAAO,KAAC,eAAe,IACrB,KAAK,EAAE,GAAG,EACV,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,EAEZ,OAAO,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC,kBAAkB,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAD9E,GAAG,CAER,CAAA;gBACJ,CAAC,CAAC,GAEC,CACR,CAAC,CAAC,CAAC,IAAI,IAEA,CACb,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,iBAAiB,GAAG,QAAQ,CAAA;AACnC,MAAM,CAAC,WAAW,GAAG,SAAS,CAAA;AAC9B,MAAM,CAAC,QAAQ,GAAG;IAChB,GAAG,SAAS,CAAC,QAAQ;IACrB,OAAO;IACP,OAAO;IACP,eAAe;IACf,iBAAiB;IACjB,gBAAgB;IAChB,eAAe;IACf,iBAAiB;IACjB,UAAU;IACV,gBAAgB;CACjB,CAAA;AAED,MAAM,CAAC,gBAAgB,GAAG,CAAsB,MAAS,EAAE,EAAE;IAC3D,OAAO,MAA2E,CAAA;AACpF,CAAC,CAAA;AAED,MAAM,CAAC,YAAY,GAAG;IACpB,mBAAmB,EAAE,KAAK;IAC1B,cAAc,EAAE,KAAK;IACrB,kBAAkB,EAAE,sBAAsB;CACnB,CAAA;AAEzB,mBAAmB,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,85 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useNestedStylesByKey } from '@codeleap/styles';
|
|
3
|
+
import { FileInput } from '../FileInput';
|
|
4
|
+
import { Icon } from '../Icon';
|
|
5
|
+
import { Image } from '../Image';
|
|
6
|
+
import { View } from 'react-native';
|
|
7
|
+
import { useSortablePhotos } from './useSortablePhotos';
|
|
8
|
+
import { useStylesFor } from '../../hooks';
|
|
9
|
+
import { MobileStyleRegistry } from '../../Registry';
|
|
10
|
+
import { ActivityIndicator } from '../ActivityIndicator';
|
|
11
|
+
import Sortable from 'react-native-sortables';
|
|
12
|
+
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
13
|
+
import { useCallback } from 'react';
|
|
14
|
+
export * from './styles';
|
|
15
|
+
export * from './types';
|
|
16
|
+
const DefaultItem = (props) => {
|
|
17
|
+
const { photo, styles, emptyIcon } = props;
|
|
18
|
+
return (_jsx(View, { style: styles.photoWrapper, children: !!photo?.filename
|
|
19
|
+
? _jsx(Image, { resizeMode: 'cover', source: { uri: photo?.file }, style: styles.photoImage })
|
|
20
|
+
: _jsx(Icon, { name: emptyIcon, style: styles.photoEmptyIcon }) }));
|
|
21
|
+
};
|
|
22
|
+
const defaultGetFilename = (file) => {
|
|
23
|
+
if (!file)
|
|
24
|
+
return null;
|
|
25
|
+
const filenameWithExtension = file?.split?.('/').pop();
|
|
26
|
+
if (filenameWithExtension) {
|
|
27
|
+
return filenameWithExtension?.split('.').slice(0, -1).join('.');
|
|
28
|
+
}
|
|
29
|
+
return new Date().toISOString();
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Must be wrapped in its own GestureHandlerRootView to avoid gesture conflicts with any
|
|
33
|
+
* parent ScrollView or gesture handler; nesting GestureHandlerRootView is intentional here.
|
|
34
|
+
*/
|
|
35
|
+
export const SortablePhotos = (props) => {
|
|
36
|
+
const allProps = {
|
|
37
|
+
...SortablePhotos.defaultProps,
|
|
38
|
+
...props,
|
|
39
|
+
};
|
|
40
|
+
const { numColumns, renderPhoto: RenderItem, gap, multiple, pickerConfig, emptyIcon, style, loading, ...rest } = allProps;
|
|
41
|
+
const styles = useStylesFor(SortablePhotos.styleRegistryName, style);
|
|
42
|
+
const loaderStyles = useNestedStylesByKey('loader', styles);
|
|
43
|
+
const { input, handlePressPhoto, numberPhotosMissing, enabledDragDrop, onChangePhotosOrder, data, } = useSortablePhotos(allProps);
|
|
44
|
+
const fileInputPickerOptions = {
|
|
45
|
+
...SortablePhotos.defaultProps.pickerConfig,
|
|
46
|
+
...pickerConfig,
|
|
47
|
+
multiple,
|
|
48
|
+
maxFiles: numberPhotosMissing,
|
|
49
|
+
};
|
|
50
|
+
/** useCallback is required — Sortable.Grid re-renders every item when renderItem identity changes, causing visible flicker during drag. */
|
|
51
|
+
const renderItem = useCallback(({ item, index }) => (_jsx(Sortable.Pressable, { onPress: () => handlePressPhoto(item, index), children: _jsx(RenderItem, { photo: item, order: index, styles: styles, emptyIcon: emptyIcon }) })), [handlePressPhoto]);
|
|
52
|
+
if (loading) {
|
|
53
|
+
return (_jsx(View, { style: [styles.wrapper, styles['wrapper:loading']], children: _jsx(ActivityIndicator, { style: loaderStyles }) }));
|
|
54
|
+
}
|
|
55
|
+
return _jsx(GestureHandlerRootView, { children: _jsxs(View, { style: styles.wrapper, children: [_jsx(FileInput, { mode: 'hidden', ref: input.ref, pickerOptions: fileInputPickerOptions }), _jsx(Sortable.Grid, { columns: numColumns, columnGap: gap, rowGap: gap, sortEnabled: enabledDragDrop, showDropIndicator: true, ...rest, data: data, renderItem: renderItem, onDragEnd: ({ data }) => onChangePhotosOrder(data) })] }) });
|
|
56
|
+
};
|
|
57
|
+
SortablePhotos.styleRegistryName = 'SortablePhotos';
|
|
58
|
+
SortablePhotos.elements = ['wrapper', 'photo', 'loader'];
|
|
59
|
+
SortablePhotos.rootElement = 'wrapper';
|
|
60
|
+
SortablePhotos.withVariantTypes = (styles) => {
|
|
61
|
+
return SortablePhotos;
|
|
62
|
+
};
|
|
63
|
+
SortablePhotos.defaultProps = {
|
|
64
|
+
numPhotos: 9,
|
|
65
|
+
numColumns: 3,
|
|
66
|
+
renderPhoto: DefaultItem,
|
|
67
|
+
multiple: true,
|
|
68
|
+
gap: 8,
|
|
69
|
+
emptyIcon: 'plus',
|
|
70
|
+
modalTitle: 'Photos',
|
|
71
|
+
modalBody: null,
|
|
72
|
+
modalLibraryText: 'Choose from gallery',
|
|
73
|
+
modalCameraText: 'Take a photo',
|
|
74
|
+
modalDeleteText: 'Remove photo',
|
|
75
|
+
getFilename: defaultGetFilename,
|
|
76
|
+
pickerConfig: {
|
|
77
|
+
cropping: true,
|
|
78
|
+
showCropFrame: true,
|
|
79
|
+
compressImageMaxHeight: 1700,
|
|
80
|
+
compressImageMaxWidth: 1700,
|
|
81
|
+
compressImageQuality: 0.8,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
MobileStyleRegistry.registerComponent(SortablePhotos);
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/SortablePhotos/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAyC,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAC9F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAa,IAAI,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,QAAyC,MAAM,wBAAwB,CAAA;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE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AAC,cAAc,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/components/SortablePhotos/styles.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/SortablePhotos/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { alert } from '@codeleap/portals';
|
|
2
|
+
import { useEffect, useMemo, useState } from '@codeleap/hooks';
|
|
3
|
+
import { useFileInput } from '../FileInput';
|
|
4
|
+
import { logger } from '@codeleap/logger';
|
|
5
|
+
export const useSortablePhotos = (props) => {
|
|
6
|
+
const { onChangePhotos, onPressPhoto, modalBody, modalTitle, modalCameraText, modalDeleteText, modalLibraryText, getFilename, numPhotos, loading, photos: currentPhotos } = props;
|
|
7
|
+
const input = useFileInput();
|
|
8
|
+
const [data, setData] = useState([]);
|
|
9
|
+
const onChange = (photos) => {
|
|
10
|
+
const { newPhotos, sortedPhotos } = sortPhotos(photos);
|
|
11
|
+
setData(sortedPhotos);
|
|
12
|
+
onChangePhotos(newPhotos);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Runs only when `loading` transitions to false so the grid initialises with the full fixed
|
|
16
|
+
* number of slots (real photos + empty placeholders) in a single synchronous commit, avoiding
|
|
17
|
+
* a visible layout jump that would occur if empty slots were appended separately.
|
|
18
|
+
*/
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!loading && data?.length < numPhotos) {
|
|
21
|
+
const currentLength = currentPhotos?.length ?? 0;
|
|
22
|
+
const length = Math.abs(numPhotos - currentLength);
|
|
23
|
+
const fillPhotos = Array(length).fill({ filename: null, file: null });
|
|
24
|
+
const newPhotos = currentPhotos.concat(fillPhotos).map((photo, idx) => ({ ...photo, key: idx + '-photo' }));
|
|
25
|
+
setData(newPhotos);
|
|
26
|
+
onChangePhotos(assignOrder(currentPhotos));
|
|
27
|
+
}
|
|
28
|
+
}, [loading]);
|
|
29
|
+
/** Drag-and-drop is disabled when only one photo is filled; there is nothing meaningful to reorder. */
|
|
30
|
+
const { emptyIndexes, numberPhotosMissing, enabledDragDrop } = useMemo(() => {
|
|
31
|
+
const copyPhotos = [...data];
|
|
32
|
+
const emptyIndexes = copyPhotos.reduce((indexes, photo, index) => {
|
|
33
|
+
if (!photo?.filename) {
|
|
34
|
+
indexes.push(index);
|
|
35
|
+
}
|
|
36
|
+
return indexes;
|
|
37
|
+
}, []);
|
|
38
|
+
const numberPhotosMissing = emptyIndexes?.length;
|
|
39
|
+
const enabledDragDrop = numberPhotosMissing < numPhotos - 1;
|
|
40
|
+
return {
|
|
41
|
+
emptyIndexes,
|
|
42
|
+
numberPhotosMissing,
|
|
43
|
+
enabledDragDrop,
|
|
44
|
+
};
|
|
45
|
+
}, [JSON.stringify(data)]);
|
|
46
|
+
const assignOrder = (photos) => {
|
|
47
|
+
return photos.map((photo, idx) => ({ ...photo, order: idx }));
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* After a drag the Sortable.Grid emits all slots in their new visual order, including empty
|
|
51
|
+
* slots. This re-packs filled photos to the front while preserving the per-slot `key` values
|
|
52
|
+
* so the grid layout stays stable and empty slots don't accumulate at random positions.
|
|
53
|
+
*/
|
|
54
|
+
const sortPhotos = (_unorderedPhotos) => {
|
|
55
|
+
const unorderedPhotos = [..._unorderedPhotos];
|
|
56
|
+
const newPhotos = unorderedPhotos.filter(photo => !!photo?.filename);
|
|
57
|
+
const sortedPhotos = unorderedPhotos.map((photo, index) => ({
|
|
58
|
+
...(newPhotos[index] ?? { file: null, filename: null }),
|
|
59
|
+
key: photo?.key
|
|
60
|
+
}));
|
|
61
|
+
return {
|
|
62
|
+
sortedPhotos,
|
|
63
|
+
newPhotos: assignOrder(newPhotos),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const handleOpenPicker = async (pickerType, photo, order) => {
|
|
67
|
+
let files = [];
|
|
68
|
+
const isEdit = !!photo?.filename;
|
|
69
|
+
try {
|
|
70
|
+
files = await input?.openFilePicker(pickerType, {
|
|
71
|
+
multiple: isEdit ? false : props?.multiple
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
logger.error('Error opening file picker:', error);
|
|
76
|
+
}
|
|
77
|
+
if (files?.length <= 0)
|
|
78
|
+
return null;
|
|
79
|
+
const isMultiple = files?.length > 1 && !isEdit;
|
|
80
|
+
const newPhotos = [...data];
|
|
81
|
+
if (isMultiple) {
|
|
82
|
+
for (const fileIndex in files) {
|
|
83
|
+
const file = files?.[fileIndex];
|
|
84
|
+
const order = emptyIndexes[fileIndex];
|
|
85
|
+
const uri = file?.file?.uri;
|
|
86
|
+
const filename = getFilename(uri);
|
|
87
|
+
newPhotos[order] = {
|
|
88
|
+
...newPhotos[order],
|
|
89
|
+
filename,
|
|
90
|
+
file: uri,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const file = files?.[0];
|
|
96
|
+
const uri = file?.file?.uri;
|
|
97
|
+
const filename = getFilename(uri);
|
|
98
|
+
newPhotos[order] = {
|
|
99
|
+
...newPhotos[order],
|
|
100
|
+
filename,
|
|
101
|
+
file: uri,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
onChange(newPhotos);
|
|
105
|
+
};
|
|
106
|
+
const handleDeletePhoto = (photo, order) => {
|
|
107
|
+
const newPhotos = [...data];
|
|
108
|
+
newPhotos[order] = {
|
|
109
|
+
...newPhotos[order],
|
|
110
|
+
filename: null,
|
|
111
|
+
file: null,
|
|
112
|
+
};
|
|
113
|
+
onChange(newPhotos);
|
|
114
|
+
};
|
|
115
|
+
const handlePressPhoto = (photo, order) => {
|
|
116
|
+
alert.ask({
|
|
117
|
+
title: modalTitle,
|
|
118
|
+
body: modalBody,
|
|
119
|
+
options: [
|
|
120
|
+
{ text: modalLibraryText, onPress: () => handleOpenPicker('library', photo, order) },
|
|
121
|
+
{ text: modalCameraText, onPress: () => handleOpenPicker('camera', photo, order) },
|
|
122
|
+
!!photo?.filename && { text: modalDeleteText, onPress: () => handleDeletePhoto(photo, order) },
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
onPressPhoto?.(data, photo, order);
|
|
126
|
+
};
|
|
127
|
+
const onChangePhotosOrder = (newData) => {
|
|
128
|
+
onChange(newData);
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
input,
|
|
132
|
+
handlePressPhoto,
|
|
133
|
+
handleDeletePhoto,
|
|
134
|
+
handleOpenPicker,
|
|
135
|
+
sortPhotos,
|
|
136
|
+
numberPhotosMissing,
|
|
137
|
+
onChangePhotosOrder,
|
|
138
|
+
emptyIndexes,
|
|
139
|
+
data,
|
|
140
|
+
enabledDragDrop,
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=useSortablePhotos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSortablePhotos.js","sourceRoot":"","sources":["../../../src/components/SortablePhotos/useSortablePhotos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAwB,YAAY,EAAE,MAAM,cAAc,CAAA;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAA0B,KAA6B,EAAE,EAAE;IAC1F,MAAM,EACJ,cAAc,EACd,YAAY,EACZ,SAAS,EACT,UAAU,EACV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EAAE,aAAa,EACtB,GAAG,KAAK,CAAA;IAET,MAAM,KAAK,GAAG,YAAY,EAA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