react-native-ui-lib 7.39.0 → 7.39.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ui-lib",
3
- "version": "7.39.0",
3
+ "version": "7.39.1",
4
4
  "main": "src/index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "author": "Ethan Sharabi <ethan.shar@gmail.com>",
@@ -15,6 +15,7 @@ import { PickerModes } from "./types";
15
15
  import PickerContext from "./PickerContext";
16
16
  import PickerItem from "./PickerItem";
17
17
  import { Constants } from "../../commons/new";
18
+ import PickerSelectionStatusBar from "./PickerSelectionStatusBar";
18
19
  const keyExtractor = (_item, index) => index.toString();
19
20
  const PickerItemsList = props => {
20
21
  const {
@@ -35,7 +36,8 @@ const PickerItemsList = props => {
35
36
  testID,
36
37
  showLoader,
37
38
  customLoaderElement,
38
- renderCustomTopElement
39
+ renderCustomTopElement,
40
+ selectionStatus: selectionStatusProps
39
41
  } = props;
40
42
  const context = useContext(PickerContext);
41
43
  const [wheelPickerValue, setWheelPickerValue] = useState(context.value ?? items?.[0]?.value);
@@ -130,10 +132,12 @@ const PickerItemsList = props => {
130
132
  <ActivityIndicator />
131
133
  </View>;
132
134
  };
135
+ const selectionStatus = useMemo(() => mode === PickerModes.MULTI && selectionStatusProps && <PickerSelectionStatusBar {...selectionStatusProps} />, [selectionStatusProps, mode]);
133
136
  const renderContent = () => {
134
137
  return useWheelPicker ? renderWheel() : <>
135
138
  {renderSearchInput()}
136
139
  {renderCustomTopElement?.(context.value)}
140
+ {selectionStatus}
137
141
  {renderList()}
138
142
  </>;
139
143
  };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { PickerSelectionStatusProps } from './types';
3
+ export default function PickerSelectionStatusBar(props: PickerSelectionStatusProps): React.JSX.Element;
@@ -0,0 +1,60 @@
1
+ import React, { useCallback, useContext } from 'react';
2
+ import { StyleSheet } from 'react-native';
3
+ import Button from "../button";
4
+ import Checkbox from "../checkbox";
5
+ import View from "../view";
6
+ import Text from "../text";
7
+ import Dividers from "../../style/dividers";
8
+ import PickerContext from "./PickerContext";
9
+ export default function PickerSelectionStatusBar(props) {
10
+ const {
11
+ containerStyle,
12
+ getLabel,
13
+ showLabel = true
14
+ } = props;
15
+ const context = useContext(PickerContext);
16
+ const {
17
+ toggleAllItemsSelection,
18
+ selectedCount,
19
+ areAllItemsSelected
20
+ } = context;
21
+ const checkboxIndeterminate = selectedCount > 0 && !areAllItemsSelected;
22
+ const label = getLabel?.({
23
+ selectedCount,
24
+ areAllItemsSelected
25
+ }) ?? `${selectedCount} Selected ${areAllItemsSelected ? '(All)' : ''}`;
26
+ const handlePress = useCallback(() => {
27
+ const newSelectionState = !areAllItemsSelected;
28
+ toggleAllItemsSelection?.(newSelectionState);
29
+ if (props.selectAllType === 'button') {
30
+ props?.buttonProps?.onPress?.({
31
+ customValue: newSelectionState
32
+ });
33
+ } else if (props.selectAllType === 'checkbox') {
34
+ props?.checkboxProps?.onValueChange?.(newSelectionState);
35
+ }
36
+ // eslint-disable-next-line react-hooks/exhaustive-deps
37
+ }, [areAllItemsSelected, toggleAllItemsSelection]);
38
+ const renderSelectionStatus = () => {
39
+ return <View flexG={!showLabel} style={!showLabel && styles.componentContainer}>
40
+ {props.selectAllType === 'button' ? <Button label={areAllItemsSelected ? 'Deselect All' : 'Select All'} link {...props?.buttonProps} onPress={handlePress} /> : props.selectAllType === 'checkbox' && <Checkbox {...props.checkboxProps} value={selectedCount > 0} indeterminate={checkboxIndeterminate} onValueChange={handlePress} />}
41
+ </View>;
42
+ };
43
+ const renderLabel = () => {
44
+ if (showLabel) {
45
+ return <Text>{label}</Text>;
46
+ }
47
+ };
48
+ return <View>
49
+ <View row spread paddingH-page marginV-s4 style={containerStyle}>
50
+ {renderLabel()}
51
+ {renderSelectionStatus()}
52
+ </View>
53
+ <View style={Dividers.d20} />
54
+ </View>;
55
+ }
56
+ const styles = StyleSheet.create({
57
+ componentContainer: {
58
+ alignItems: 'flex-end'
59
+ }
60
+ });
@@ -1,6 +1,6 @@
1
1
  import { RefObject } from 'react';
2
2
  import { PickerProps, PickerValue, PickerSingleValue, PickerMultiValue } from '../types';
3
- interface UsePickerSelectionProps extends Pick<PickerProps, 'migrate' | 'value' | 'onChange' | 'getItemValue' | 'topBarProps' | 'mode'> {
3
+ interface UsePickerSelectionProps extends Pick<PickerProps, 'migrate' | 'value' | 'onChange' | 'getItemValue' | 'topBarProps' | 'mode' | 'items'> {
4
4
  pickerExpandableRef: RefObject<any>;
5
5
  setSearchValue: (searchValue: string) => void;
6
6
  }
@@ -9,5 +9,8 @@ declare const usePickerSelection: (props: UsePickerSelectionProps) => {
9
9
  onDoneSelecting: (item: PickerValue) => void;
10
10
  toggleItemSelection: (item: PickerSingleValue) => void;
11
11
  cancelSelect: () => void;
12
+ areAllItemsSelected: boolean;
13
+ selectedCount: number;
14
+ toggleAllItemsSelection: (selectAll: boolean) => void;
12
15
  };
13
16
  export default usePickerSelection;
@@ -1,6 +1,6 @@
1
1
  import _xor from "lodash/xor";
2
2
  import _xorBy from "lodash/xorBy";
3
- import { useCallback, useState, useEffect } from 'react';
3
+ import { useCallback, useState, useEffect, useMemo } from 'react';
4
4
  import { PickerModes } from "../types";
5
5
  const usePickerSelection = props => {
6
6
  const {
@@ -11,7 +11,8 @@ const usePickerSelection = props => {
11
11
  pickerExpandableRef,
12
12
  getItemValue,
13
13
  setSearchValue,
14
- mode
14
+ mode,
15
+ items
15
16
  } = props;
16
17
  const [multiDraftValue, setMultiDraftValue] = useState(value);
17
18
  const [multiFinalValue, setMultiFinalValue] = useState(value);
@@ -43,11 +44,26 @@ const usePickerSelection = props => {
43
44
  pickerExpandableRef.current?.closeExpandable?.();
44
45
  topBarProps?.onCancel?.();
45
46
  }, [multiFinalValue, topBarProps]);
47
+ const availableItems = useMemo(() => {
48
+ return items?.filter(item => !item.disabled).map(item => item.value) || [];
49
+ }, [items]);
50
+ const areAllItemsSelected = useMemo(() => {
51
+ return multiDraftValue?.length === availableItems.length;
52
+ }, [multiDraftValue, availableItems]);
53
+ const selectedCount = useMemo(() => {
54
+ return multiDraftValue?.length;
55
+ }, [multiDraftValue]);
56
+ const toggleAllItemsSelection = useCallback(selectAll => {
57
+ setMultiDraftValue(selectAll ? availableItems : []);
58
+ }, [availableItems]);
46
59
  return {
47
60
  multiDraftValue,
48
61
  onDoneSelecting,
49
62
  toggleItemSelection,
50
- cancelSelect
63
+ cancelSelect,
64
+ areAllItemsSelected,
65
+ selectedCount,
66
+ toggleAllItemsSelection
51
67
  };
52
68
  };
53
69
  export default usePickerSelection;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import PickerItem from './PickerItem';
3
3
  import { extractPickerItems } from './PickerPresenter';
4
- import { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods } from './types';
4
+ import { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods, PickerSelectionStatusProps } from './types';
5
5
  type PickerStatics = {
6
6
  Item: typeof PickerItem;
7
7
  modes: typeof PickerModes;
@@ -9,7 +9,7 @@ type PickerStatics = {
9
9
  extractPickerItems: typeof extractPickerItems;
10
10
  };
11
11
  declare const Picker: React.ForwardRefExoticComponent<PickerProps & React.RefAttributes<unknown>>;
12
- export { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods };
12
+ export { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods, PickerSelectionStatusProps };
13
13
  export { Picker };
14
14
  declare const _default: React.ForwardRefExoticComponent<PickerProps & React.RefAttributes<unknown>> & PickerStatics;
15
15
  export default _default;
@@ -18,7 +18,7 @@ import useFieldType from "./helpers/useFieldType";
18
18
  import useNewPickerProps from "./helpers/useNewPickerProps";
19
19
  // import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
20
20
  import { extractPickerItems } from "./PickerPresenter";
21
- import { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods } from "./types";
21
+ import { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods, PickerSelectionStatusProps } from "./types";
22
22
  const DEFAULT_DIALOG_PROPS = {
23
23
  bottom: true,
24
24
  width: '100%'
@@ -58,6 +58,7 @@ const Picker = React.forwardRef((props, ref) => {
58
58
  showLoader,
59
59
  customLoaderElement,
60
60
  renderCustomTopElement,
61
+ selectionStatus,
61
62
  ...others
62
63
  } = themeProps;
63
64
  const {
@@ -101,7 +102,10 @@ const Picker = React.forwardRef((props, ref) => {
101
102
  multiDraftValue,
102
103
  onDoneSelecting,
103
104
  toggleItemSelection,
104
- cancelSelect
105
+ cancelSelect,
106
+ areAllItemsSelected,
107
+ selectedCount,
108
+ toggleAllItemsSelection
105
109
  } = usePickerSelection({
106
110
  migrate,
107
111
  value,
@@ -110,7 +114,8 @@ const Picker = React.forwardRef((props, ref) => {
110
114
  getItemValue,
111
115
  topBarProps,
112
116
  setSearchValue,
113
- mode
117
+ mode,
118
+ items
114
119
  });
115
120
  const {
116
121
  label,
@@ -154,9 +159,12 @@ const Picker = React.forwardRef((props, ref) => {
154
159
  getItemLabel,
155
160
  onSelectedLayout: onSelectedItemLayout,
156
161
  renderItem,
157
- selectionLimit
162
+ selectionLimit,
163
+ areAllItemsSelected,
164
+ selectedCount,
165
+ toggleAllItemsSelection
158
166
  };
159
- }, [migrate, mode, value, multiDraftValue, renderItem, getItemValue, getItemLabel, selectionLimit, onSelectedItemLayout, toggleItemSelection, onDoneSelecting]);
167
+ }, [migrate, mode, value, multiDraftValue, renderItem, getItemValue, getItemLabel, selectionLimit, onSelectedItemLayout, toggleItemSelection, onDoneSelecting, areAllItemsSelected, selectedCount, toggleAllItemsSelection]);
160
168
  const renderPickerItem = useCallback((item, index) => {
161
169
  return <PickerItem key={`${index}-${item.value}`} {...item} />;
162
170
  }, []);
@@ -201,7 +209,7 @@ const Picker = React.forwardRef((props, ref) => {
201
209
  ...topBarProps,
202
210
  onCancel: cancelSelect,
203
211
  onDone: mode === PickerModes.MULTI ? () => onDoneSelecting(multiDraftValue) : undefined
204
- }} showSearch={showSearch} searchStyle={searchStyle} searchPlaceholder={searchPlaceholder} onSearchChange={_onSearchChange} renderCustomSearch={renderCustomSearch} renderHeader={renderHeader} listProps={listProps} useSafeArea={useSafeArea} showLoader={showLoader} customLoaderElement={customLoaderElement} renderCustomTopElement={renderCustomTopElement}>
212
+ }} showSearch={showSearch} searchStyle={searchStyle} searchPlaceholder={searchPlaceholder} onSearchChange={_onSearchChange} renderCustomSearch={renderCustomSearch} renderHeader={renderHeader} listProps={listProps} useSafeArea={useSafeArea} showLoader={showLoader} customLoaderElement={customLoaderElement} renderCustomTopElement={renderCustomTopElement} selectionStatus={selectionStatus}>
205
213
  {filteredItems}
206
214
  </PickerItemsList>;
207
215
  }, [testID, mode, useDialog, selectedItemPosition, topBarProps, cancelSelect, onDoneSelecting, multiDraftValue, showSearch, searchStyle, searchPlaceholder, _onSearchChange, renderCustomSearch, renderHeader, listProps, filteredItems, useSafeArea, useWheelPicker, items, showLoader]);
@@ -221,6 +229,6 @@ Picker.modes = PickerModes;
221
229
  Picker.fieldTypes = PickerFieldTypes;
222
230
  // @ts-expect-error
223
231
  Picker.extractPickerItems = extractPickerItems;
224
- export { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods };
232
+ export { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods, PickerSelectionStatusProps };
225
233
  export { Picker }; // For tests
226
234
  export default Picker;
@@ -4,6 +4,8 @@ import { ExpandableOverlayProps, ExpandableOverlayMethods } from '../../incubato
4
4
  import { ModalTopBarProps } from '../modal/TopBar';
5
5
  import { TextFieldMethods, TextFieldProps } from '../textField';
6
6
  import { TouchableOpacityProps } from '../touchableOpacity';
7
+ import { ButtonProps } from '../button';
8
+ import { CheckboxProps } from '../checkbox';
7
9
  export declare enum PickerModes {
8
10
  SINGLE = "SINGLE",
9
11
  MULTI = "MULTI"
@@ -147,6 +149,44 @@ type PickerExpandableOverlayProps = {
147
149
  */
148
150
  enableModalBlur?: boolean;
149
151
  };
152
+ interface PickerSelectionStatusLabelData {
153
+ selectedCount: number;
154
+ areAllItemsSelected: boolean;
155
+ }
156
+ export type ButtonSelectionStatus = {
157
+ /**
158
+ * Select all element type
159
+ */
160
+ selectAllType?: 'button';
161
+ /**
162
+ * Button props
163
+ */
164
+ buttonProps?: ButtonProps;
165
+ };
166
+ export type CheckboxSelectionStatus = {
167
+ /**
168
+ * Select all element type
169
+ */
170
+ selectAllType?: 'checkbox';
171
+ /**
172
+ * Checkbox props
173
+ */
174
+ checkboxProps?: CheckboxProps;
175
+ };
176
+ export type PickerSelectionStatusProps = {
177
+ /**
178
+ * A function that generates a label based on the selected items' count and status
179
+ */
180
+ getLabel?: (data: PickerSelectionStatusLabelData) => string;
181
+ /**
182
+ * Custom container style
183
+ */
184
+ containerStyle?: StyleProp<ViewStyle>;
185
+ /**
186
+ * Control weather to show the label or not
187
+ */
188
+ showLabel?: boolean;
189
+ } & (ButtonSelectionStatus | CheckboxSelectionStatus);
150
190
  export type PickerBaseProps = Omit<TextFieldProps, 'value' | 'onChange'> & PickerPropsDeprecation & PickerExpandableOverlayProps & PickerListProps & {
151
191
  /**
152
192
  * Use dialog instead of modal picker
@@ -193,6 +233,10 @@ export type PickerBaseProps = Omit<TextFieldProps, 'value' | 'onChange'> & Picke
193
233
  * Render custom top element
194
234
  */
195
235
  renderCustomTopElement?: (value?: PickerValue) => React.ReactElement;
236
+ /**
237
+ * Selection status bar props
238
+ */
239
+ selectionStatus?: PickerSelectionStatusProps;
196
240
  /**
197
241
  * Add onPress callback for when pressing the picker
198
242
  */
@@ -286,8 +330,11 @@ export interface PickerContextProps extends Pick<PickerProps, 'migrate' | 'value
286
330
  isMultiMode: boolean;
287
331
  onSelectedLayout: (event: any) => any;
288
332
  selectionLimit: PickerProps['selectionLimit'];
333
+ areAllItemsSelected: boolean;
334
+ selectedCount: number;
335
+ toggleAllItemsSelection?: (selectAll: boolean) => void;
289
336
  }
290
- export type PickerItemsListProps = Pick<PropsWithChildren<PickerProps>, 'topBarProps' | 'listProps' | 'renderHeader' | 'useSafeArea' | 'showLoader' | 'customLoaderElement' | 'renderCustomTopElement' | 'showSearch' | 'searchStyle' | 'searchPlaceholder' | 'onSearchChange' | 'renderCustomSearch' | 'children' | 'useWheelPicker' | 'useDialog' | 'mode' | 'testID'> & {
337
+ export type PickerItemsListProps = Pick<PropsWithChildren<PickerProps>, 'topBarProps' | 'listProps' | 'renderHeader' | 'useSafeArea' | 'showLoader' | 'customLoaderElement' | 'renderCustomTopElement' | 'selectionStatus' | 'showSearch' | 'searchStyle' | 'searchPlaceholder' | 'onSearchChange' | 'renderCustomSearch' | 'children' | 'useWheelPicker' | 'useDialog' | 'mode' | 'testID'> & {
291
338
  items?: {
292
339
  value: any;
293
340
  label: any;
package/src/index.d.ts CHANGED
@@ -67,7 +67,7 @@ export { default as PanningContext } from './components/panningViews/panningCont
67
67
  export { default as PanningProvider, PanningDirections, PanLocationProps, PanAmountsProps, PanDirectionsProps } from './components/panningViews/panningProvider';
68
68
  export { default as PanResponderView, PanResponderViewProps } from './components/panningViews/panResponderView';
69
69
  export { default as asPanViewConsumer } from './components/panningViews/asPanViewConsumer';
70
- export { default as Picker, PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods } from './components/picker';
70
+ export { default as Picker, PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods, PickerSelectionStatusProps } from './components/picker';
71
71
  export { default as PieChart, type PieChartProps, PieChartSegmentProps } from './components/pieChart';
72
72
  export { default as ProgressBar, ProgressBarProps } from './components/progressBar';
73
73
  export { default as ProgressiveImage, ProgressiveImageProps } from './components/progressiveImage';
package/src/index.js CHANGED
@@ -166,6 +166,7 @@ var _exportNames = {
166
166
  RenderCustomModalProps: true,
167
167
  PickerItemsListProps: true,
168
168
  PickerMethods: true,
169
+ PickerSelectionStatusProps: true,
169
170
  PieChart: true,
170
171
  PieChartSegmentProps: true,
171
172
  ProgressBar: true,
@@ -1110,6 +1111,12 @@ Object.defineProperty(exports, "PickerSearchStyle", {
1110
1111
  return _picker().PickerSearchStyle;
1111
1112
  }
1112
1113
  });
1114
+ Object.defineProperty(exports, "PickerSelectionStatusProps", {
1115
+ enumerable: true,
1116
+ get: function () {
1117
+ return _picker().PickerSelectionStatusProps;
1118
+ }
1119
+ });
1113
1120
  Object.defineProperty(exports, "PickerValue", {
1114
1121
  enumerable: true,
1115
1122
  get: function () {