react-native-ui-lib 7.38.1-snapshot.6312 → 7.38.1-snapshot.6326

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.38.1-snapshot.6312",
3
+ "version": "7.38.1-snapshot.6326",
4
4
  "main": "src/index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "author": "Ethan Sharabi <ethan.shar@gmail.com>",
@@ -10,8 +10,6 @@ import Image from "../image";
10
10
  import View from "../view";
11
11
  import Text from "../text";
12
12
  const LABEL_FORMATTER_VALUES = [1, 2, 3, 4];
13
- const DEFAULT_PIMPLE_SIZE = 10;
14
- const DEFAULT_BADGE_SIZE = 20;
15
13
  /**
16
14
  * @description: Round colored badge, typically used to show a number
17
15
  * @extends: View
@@ -39,14 +37,7 @@ class Badge extends PureComponent {
39
37
  };
40
38
  }
41
39
  get size() {
42
- const {
43
- size,
44
- label
45
- } = this.props;
46
- if (size !== undefined) {
47
- return size;
48
- }
49
- return label === undefined ? DEFAULT_PIMPLE_SIZE : DEFAULT_BADGE_SIZE;
40
+ return this.props.size || 20;
50
41
  }
51
42
  isSmallBadge() {
52
43
  return this.size <= 16;
@@ -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 PickerSelectionControlBar from "./PickerSelectionControlBar";
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
39
41
  } = props;
40
42
  const context = useContext(PickerContext);
41
43
  const [wheelPickerValue, setWheelPickerValue] = useState(context.value ?? items?.[0]?.value);
@@ -130,10 +132,18 @@ const PickerItemsList = props => {
130
132
  <ActivityIndicator />
131
133
  </View>;
132
134
  };
135
+ const renderSelectionStatus = useMemo(() => {
136
+ const props = {
137
+ ...selectionStatus,
138
+ items
139
+ };
140
+ return <PickerSelectionControlBar {...props} value={context?.value} toggleAllItemsSelection={context?.toggleAllItemsSelection} />;
141
+ }, [selectionStatus, items, context?.value, context?.toggleAllItemsSelection]);
133
142
  const renderContent = () => {
134
143
  return useWheelPicker ? renderWheel() : <>
135
144
  {renderSearchInput()}
136
145
  {renderCustomTopElement?.(context.value)}
146
+ {mode === PickerModes.MULTI && renderSelectionStatus}
137
147
  {renderList()}
138
148
  </>;
139
149
  };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { PickerItemProps, PickerProps, PickerContextProps, PickerMultiValue } from './types';
3
+ export type PickerSelectionControlBarProps = PickerProps['selectionStatus'] & Partial<PickerContextProps> & {
4
+ value?: PickerMultiValue;
5
+ items?: PickerItemProps[];
6
+ };
7
+ export default function PickerSelectionControlBar(props: PickerSelectionControlBarProps): React.JSX.Element;
@@ -0,0 +1,48 @@
1
+ import React, { useMemo, useCallback } from 'react';
2
+ import Button from "../button";
3
+ import Checkbox from "../checkbox";
4
+ import View from "../view";
5
+ import Text from "../text";
6
+ export default function PickerSelectionControlBar(props) {
7
+ const {
8
+ selectAllType = 'none',
9
+ buttonProps = {},
10
+ checkboxProps = {},
11
+ containerStyle,
12
+ value = [],
13
+ items = [],
14
+ toggleAllItemsSelection,
15
+ showLabel = true,
16
+ customLabel
17
+ } = props;
18
+ const availableItems = useMemo(() => items.filter(item => !item.disabled).map(item => item.value), [items]);
19
+ const isAllSelected = value.length === availableItems.length;
20
+ const checkboxIndeterminate = value.length > 0 && value.length < availableItems.length;
21
+ const defaultLabel = `${value.length} Selected ${isAllSelected ? '(All)' : ''}`;
22
+ const handlePress = useCallback(() => {
23
+ const newSelectionState = !isAllSelected;
24
+ toggleAllItemsSelection?.(availableItems, newSelectionState);
25
+ if (selectAllType === 'button') {
26
+ buttonProps.onPress?.(availableItems);
27
+ } else if (selectAllType === 'checkbox') {
28
+ checkboxProps.onValueChange?.(newSelectionState);
29
+ }
30
+ }, [isAllSelected, toggleAllItemsSelection, availableItems, selectAllType, buttonProps, checkboxProps]);
31
+ const renderSelectionStatus = () => {
32
+ if (selectAllType === 'button') {
33
+ return <Button label={isAllSelected ? 'Deselect All' : 'Select All'} link {...buttonProps} onPress={handlePress} />;
34
+ } else if (selectAllType === 'checkbox') {
35
+ return <Checkbox {...checkboxProps} value={value.length > 0} indeterminate={checkboxIndeterminate} onValueChange={handlePress} />;
36
+ }
37
+ };
38
+ const renderLabel = () => {
39
+ if (showLabel) {
40
+ return <Text>{customLabel || defaultLabel}</Text>;
41
+ }
42
+ return null;
43
+ };
44
+ return <View row spread centerV paddingH-page style={containerStyle}>
45
+ {renderLabel()}
46
+ {renderSelectionStatus()}
47
+ </View>;
48
+ }
@@ -9,5 +9,7 @@ declare const usePickerSelection: (props: UsePickerSelectionProps) => {
9
9
  onDoneSelecting: (item: PickerValue) => void;
10
10
  toggleItemSelection: (item: PickerSingleValue) => void;
11
11
  cancelSelect: () => void;
12
+ setMultiFinalValue: import("react").Dispatch<import("react").SetStateAction<PickerMultiValue>>;
13
+ toggleAllItemsSelection: (itemsToToggle: PickerMultiValue, select: boolean) => void;
12
14
  };
13
15
  export default usePickerSelection;
@@ -43,11 +43,16 @@ const usePickerSelection = props => {
43
43
  pickerExpandableRef.current?.closeExpandable?.();
44
44
  topBarProps?.onCancel?.();
45
45
  }, [multiFinalValue, topBarProps]);
46
+ const toggleAllItemsSelection = useCallback((itemsToToggle, select) => {
47
+ setMultiDraftValue(select ? itemsToToggle : []);
48
+ }, []);
46
49
  return {
47
50
  multiDraftValue,
48
51
  onDoneSelecting,
49
52
  toggleItemSelection,
50
- cancelSelect
53
+ cancelSelect,
54
+ setMultiFinalValue,
55
+ toggleAllItemsSelection
51
56
  };
52
57
  };
53
58
  export default usePickerSelection;
@@ -1,15 +1,16 @@
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, PickerSelectAllType } from './types';
5
5
  type PickerStatics = {
6
6
  Item: typeof PickerItem;
7
7
  modes: typeof PickerModes;
8
8
  fieldTypes: typeof PickerFieldTypes;
9
9
  extractPickerItems: typeof extractPickerItems;
10
+ selectAllType: typeof PickerSelectAllType;
10
11
  };
11
12
  declare const Picker: React.ForwardRefExoticComponent<PickerProps & React.RefAttributes<unknown>>;
12
- export { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods };
13
+ export { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods, PickerSelectAllType };
13
14
  export { Picker };
14
15
  declare const _default: React.ForwardRefExoticComponent<PickerProps & React.RefAttributes<unknown>> & PickerStatics;
15
16
  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, PickerSelectAllType } 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,8 @@ const Picker = React.forwardRef((props, ref) => {
101
102
  multiDraftValue,
102
103
  onDoneSelecting,
103
104
  toggleItemSelection,
104
- cancelSelect
105
+ cancelSelect,
106
+ toggleAllItemsSelection
105
107
  } = usePickerSelection({
106
108
  migrate,
107
109
  value,
@@ -154,9 +156,10 @@ const Picker = React.forwardRef((props, ref) => {
154
156
  getItemLabel,
155
157
  onSelectedLayout: onSelectedItemLayout,
156
158
  renderItem,
157
- selectionLimit
159
+ selectionLimit,
160
+ toggleAllItemsSelection
158
161
  };
159
- }, [migrate, mode, value, multiDraftValue, renderItem, getItemValue, getItemLabel, selectionLimit, onSelectedItemLayout, toggleItemSelection, onDoneSelecting]);
162
+ }, [migrate, mode, value, multiDraftValue, renderItem, getItemValue, getItemLabel, selectionLimit, onSelectedItemLayout, toggleItemSelection, onDoneSelecting, toggleAllItemsSelection]);
160
163
  const renderPickerItem = useCallback((item, index) => {
161
164
  return <PickerItem key={`${index}-${item.value}`} {...item} />;
162
165
  }, []);
@@ -201,7 +204,7 @@ const Picker = React.forwardRef((props, ref) => {
201
204
  ...topBarProps,
202
205
  onCancel: cancelSelect,
203
206
  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}>
207
+ }} 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
208
  {filteredItems}
206
209
  </PickerItemsList>;
207
210
  }, [testID, mode, useDialog, selectedItemPosition, topBarProps, cancelSelect, onDoneSelecting, multiDraftValue, showSearch, searchStyle, searchPlaceholder, _onSearchChange, renderCustomSearch, renderHeader, listProps, filteredItems, useSafeArea, useWheelPicker, items, showLoader]);
@@ -221,6 +224,8 @@ Picker.modes = PickerModes;
221
224
  Picker.fieldTypes = PickerFieldTypes;
222
225
  // @ts-expect-error
223
226
  Picker.extractPickerItems = extractPickerItems;
224
- export { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods };
227
+ //@ts-ignore
228
+ Picker.selectAllType = PickerSelectAllType;
229
+ export { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods, PickerSelectAllType };
225
230
  export { Picker }; // For tests
226
231
  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"
@@ -13,6 +15,11 @@ export declare enum PickerFieldTypes {
13
15
  filter = "filter",
14
16
  settings = "settings"
15
17
  }
18
+ export declare enum PickerSelectAllType {
19
+ none = "none",
20
+ button = "button",
21
+ checkbox = "checkbox"
22
+ }
16
23
  export type PickerSingleValue = string | number;
17
24
  export type PickerMultiValue = PickerSingleValue[];
18
25
  export type PickerValue = PickerSingleValue | PickerMultiValue | undefined;
@@ -147,6 +154,41 @@ type PickerExpandableOverlayProps = {
147
154
  */
148
155
  enableModalBlur?: boolean;
149
156
  };
157
+ interface getLabelOptions {
158
+ selectedCount?: number;
159
+ value?: PickerItemProps[];
160
+ isSelectedAll?: boolean;
161
+ }
162
+ type PickerSelectionStatusProps = {
163
+ /**
164
+ * A function that returns the label to show for the selected Picker value
165
+ */
166
+ getLabel?: (options?: getLabelOptions) => string;
167
+ /**
168
+ * Select all element type
169
+ */
170
+ selectAllType?: PickerSelectAllType | `${PickerSelectAllType}`;
171
+ /**
172
+ * Button props
173
+ */
174
+ buttonProps?: ButtonProps;
175
+ /**
176
+ * Checkbox props
177
+ */
178
+ checkboxProps?: CheckboxProps;
179
+ /**
180
+ * Custom container style
181
+ */
182
+ containerStyle?: StyleProp<ViewStyle>;
183
+ /**
184
+ * Control weather to show the label or not
185
+ */
186
+ showLabel?: boolean;
187
+ /**
188
+ * Custom label to show next to the selection element.
189
+ */
190
+ customLabel?: string;
191
+ };
150
192
  export type PickerBaseProps = Omit<TextFieldProps, 'value' | 'onChange'> & PickerPropsDeprecation & PickerExpandableOverlayProps & PickerListProps & {
151
193
  /**
152
194
  * Use dialog instead of modal picker
@@ -193,6 +235,10 @@ export type PickerBaseProps = Omit<TextFieldProps, 'value' | 'onChange'> & Picke
193
235
  * Render custom top element
194
236
  */
195
237
  renderCustomTopElement?: (value?: PickerValue) => React.ReactElement;
238
+ /**
239
+ *
240
+ */
241
+ selectionStatus?: PickerSelectionStatusProps;
196
242
  /**
197
243
  * Add onPress callback for when pressing the picker
198
244
  */
@@ -286,8 +332,9 @@ export interface PickerContextProps extends Pick<PickerProps, 'migrate' | 'value
286
332
  isMultiMode: boolean;
287
333
  onSelectedLayout: (event: any) => any;
288
334
  selectionLimit: PickerProps['selectionLimit'];
335
+ toggleAllItemsSelection?: (itemsToToggle: PickerMultiValue, select: 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;
@@ -10,6 +10,12 @@ export let PickerFieldTypes = /*#__PURE__*/function (PickerFieldTypes) {
10
10
  PickerFieldTypes["settings"] = "settings";
11
11
  return PickerFieldTypes;
12
12
  }({});
13
+ export let PickerSelectAllType = /*#__PURE__*/function (PickerSelectAllType) {
14
+ PickerSelectAllType["none"] = "none";
15
+ PickerSelectAllType["button"] = "button";
16
+ PickerSelectAllType["checkbox"] = "checkbox";
17
+ return PickerSelectAllType;
18
+ }({});
13
19
 
14
20
  // TODO: Remove type
15
21
  // type PickerValueDeprecated = {value: string | number; label: string};
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, PickerSelectAllType } 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
+ PickerSelectAllType: 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, "PickerSelectAllType", {
1115
+ enumerable: true,
1116
+ get: function () {
1117
+ return _picker().PickerSelectAllType;
1118
+ }
1119
+ });
1113
1120
  Object.defineProperty(exports, "PickerValue", {
1114
1121
  enumerable: true,
1115
1122
  get: function () {