@hero-design/rn 8.92.0 → 8.92.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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +6 -0
- package/es/index.js +34 -2
- package/lib/index.js +34 -2
- package/package.json +1 -1
- package/src/components/Select/SingleSelect/OptionList.tsx +6 -5
- package/src/components/Select/SingleSelect/__tests__/OptionList.spec.tsx +24 -0
- package/src/components/Select/SingleSelect/__tests__/__snapshots__/OptionList.spec.tsx.snap +594 -0
- package/src/components/Select/SingleSelect/__tests__/index.spec.tsx +26 -0
- package/src/components/Select/SingleSelect/index.tsx +5 -1
- package/src/components/Select/__tests__/helpers.spec.tsx +36 -0
- package/src/components/Select/helpers.tsx +45 -0
- package/stats/8.92.1/rn-stats.html +4844 -0
- package/types/components/Select/SingleSelect/OptionList.d.ts +1 -1
- package/types/components/Select/helpers.d.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(node:
|
|
1
|
+
(node:3004) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
|
|
2
2
|
(Use `node --trace-warnings ...` to show where the warning was created)
|
|
3
3
|
[36m
|
|
4
4
|
[1msrc/index.ts[22m → [1mlib/index.js, es/index.js[22m...[39m
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~[0m
|
|
11
11
|
[39m
|
|
12
12
|
[1m[33m(!) [plugin node-resolve] preferring built-in module 'events' over local alternative at '/home/runner/work/hero-design/hero-design/node_modules/events/events.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning.or passing a function to 'preferBuiltins' to provide more fine-grained control over which built-in modules to prefer.[39m[22m
|
|
13
|
-
[32mcreated [1mlib/index.js, es/index.js[22m in [
|
|
13
|
+
[32mcreated [1mlib/index.js, es/index.js[22m in [1m53.1s[22m[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @hero-design/rn
|
|
2
2
|
|
|
3
|
+
## 8.92.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3731](https://github.com/Thinkei/hero-design/pull/3731) [`65b0238dcab7d2397c913fd36aec5690171f950b`](https://github.com/Thinkei/hero-design/commit/65b0238dcab7d2397c913fd36aec5690171f950b) Thanks [@vinhphan-eh](https://github.com/vinhphan-eh)! - [SingleSelect] Support rendering display value with object
|
|
8
|
+
|
|
3
9
|
## 8.92.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/es/index.js
CHANGED
|
@@ -18710,6 +18710,38 @@ var useKeyboard = function useKeyboard() {
|
|
|
18710
18710
|
keyboardHeight: keyboardHeight
|
|
18711
18711
|
};
|
|
18712
18712
|
};
|
|
18713
|
+
var deepCompareValue = function deepCompareValue(a, b) {
|
|
18714
|
+
// Handle strict equality first (handles primitives, null, undefined)
|
|
18715
|
+
if (a === b) return true;
|
|
18716
|
+
// Special handling for NaN (NaN !== NaN in JS)
|
|
18717
|
+
if (typeof a === 'number' && typeof b === 'number' && Number.isNaN(a) && Number.isNaN(b)) {
|
|
18718
|
+
return false;
|
|
18719
|
+
}
|
|
18720
|
+
// If either is null or undefined (but they are not strictly equal), return false
|
|
18721
|
+
if (a == null || b == null) return false;
|
|
18722
|
+
// If types don't match, they can't be equal
|
|
18723
|
+
if (_typeof(a) !== _typeof(b)) return false;
|
|
18724
|
+
// Handle array comparison
|
|
18725
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
18726
|
+
if (a.length !== b.length) return false;
|
|
18727
|
+
return a.every(function (val, index) {
|
|
18728
|
+
return deepCompareValue(val, b[index]);
|
|
18729
|
+
});
|
|
18730
|
+
}
|
|
18731
|
+
// If one is array and the other isn't, return false
|
|
18732
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
18733
|
+
// Handle object comparison
|
|
18734
|
+
if (_typeof(a) === 'object' && _typeof(b) === 'object') {
|
|
18735
|
+
var keysA = Object.keys(a);
|
|
18736
|
+
var keysB = Object.keys(b);
|
|
18737
|
+
if (keysA.length !== keysB.length) return false;
|
|
18738
|
+
return keysA.every(function (key) {
|
|
18739
|
+
return keysB.includes(key) && deepCompareValue(a[key], b[key]);
|
|
18740
|
+
});
|
|
18741
|
+
}
|
|
18742
|
+
// If none of the above conditions matched, they're not equal
|
|
18743
|
+
return false;
|
|
18744
|
+
};
|
|
18713
18745
|
|
|
18714
18746
|
var SectionSpacer = index$a(View)(function (_ref) {
|
|
18715
18747
|
var theme = _ref.theme;
|
|
@@ -19038,7 +19070,7 @@ var OptionList = function OptionList(_ref) {
|
|
|
19038
19070
|
rest = _objectWithoutProperties(_ref, _excluded$c);
|
|
19039
19071
|
var renderItem = function renderItem(info) {
|
|
19040
19072
|
var item = info.item;
|
|
19041
|
-
var selected = item.value
|
|
19073
|
+
var selected = deepCompareValue(item.value, value);
|
|
19042
19074
|
var onItemPress = function onItemPress() {
|
|
19043
19075
|
if (value === item.value) {
|
|
19044
19076
|
onPress(null);
|
|
@@ -19109,7 +19141,7 @@ var SingleSelect = function SingleSelect(_ref) {
|
|
|
19109
19141
|
var sections = toSections(options);
|
|
19110
19142
|
var flatOptions = toFlatOptions(options);
|
|
19111
19143
|
var displayedValue = (_flatOptions$find = flatOptions.find(function (opt) {
|
|
19112
|
-
return
|
|
19144
|
+
return deepCompareValue(opt.value, value);
|
|
19113
19145
|
})) === null || _flatOptions$find === void 0 ? void 0 : _flatOptions$find.text;
|
|
19114
19146
|
var rawValue = value ? String(value) : undefined;
|
|
19115
19147
|
var bottomSheetVariant = bottomSheetConfig.variant,
|
package/lib/index.js
CHANGED
|
@@ -18738,6 +18738,38 @@ var useKeyboard = function useKeyboard() {
|
|
|
18738
18738
|
keyboardHeight: keyboardHeight
|
|
18739
18739
|
};
|
|
18740
18740
|
};
|
|
18741
|
+
var deepCompareValue = function deepCompareValue(a, b) {
|
|
18742
|
+
// Handle strict equality first (handles primitives, null, undefined)
|
|
18743
|
+
if (a === b) return true;
|
|
18744
|
+
// Special handling for NaN (NaN !== NaN in JS)
|
|
18745
|
+
if (typeof a === 'number' && typeof b === 'number' && Number.isNaN(a) && Number.isNaN(b)) {
|
|
18746
|
+
return false;
|
|
18747
|
+
}
|
|
18748
|
+
// If either is null or undefined (but they are not strictly equal), return false
|
|
18749
|
+
if (a == null || b == null) return false;
|
|
18750
|
+
// If types don't match, they can't be equal
|
|
18751
|
+
if (_typeof(a) !== _typeof(b)) return false;
|
|
18752
|
+
// Handle array comparison
|
|
18753
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
18754
|
+
if (a.length !== b.length) return false;
|
|
18755
|
+
return a.every(function (val, index) {
|
|
18756
|
+
return deepCompareValue(val, b[index]);
|
|
18757
|
+
});
|
|
18758
|
+
}
|
|
18759
|
+
// If one is array and the other isn't, return false
|
|
18760
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
18761
|
+
// Handle object comparison
|
|
18762
|
+
if (_typeof(a) === 'object' && _typeof(b) === 'object') {
|
|
18763
|
+
var keysA = Object.keys(a);
|
|
18764
|
+
var keysB = Object.keys(b);
|
|
18765
|
+
if (keysA.length !== keysB.length) return false;
|
|
18766
|
+
return keysA.every(function (key) {
|
|
18767
|
+
return keysB.includes(key) && deepCompareValue(a[key], b[key]);
|
|
18768
|
+
});
|
|
18769
|
+
}
|
|
18770
|
+
// If none of the above conditions matched, they're not equal
|
|
18771
|
+
return false;
|
|
18772
|
+
};
|
|
18741
18773
|
|
|
18742
18774
|
var SectionSpacer = index$a(reactNative.View)(function (_ref) {
|
|
18743
18775
|
var theme = _ref.theme;
|
|
@@ -19066,7 +19098,7 @@ var OptionList = function OptionList(_ref) {
|
|
|
19066
19098
|
rest = _objectWithoutProperties(_ref, _excluded$c);
|
|
19067
19099
|
var renderItem = function renderItem(info) {
|
|
19068
19100
|
var item = info.item;
|
|
19069
|
-
var selected = item.value
|
|
19101
|
+
var selected = deepCompareValue(item.value, value);
|
|
19070
19102
|
var onItemPress = function onItemPress() {
|
|
19071
19103
|
if (value === item.value) {
|
|
19072
19104
|
onPress(null);
|
|
@@ -19137,7 +19169,7 @@ var SingleSelect = function SingleSelect(_ref) {
|
|
|
19137
19169
|
var sections = toSections(options);
|
|
19138
19170
|
var flatOptions = toFlatOptions(options);
|
|
19139
19171
|
var displayedValue = (_flatOptions$find = flatOptions.find(function (opt) {
|
|
19140
|
-
return
|
|
19172
|
+
return deepCompareValue(opt.value, value);
|
|
19141
19173
|
})) === null || _flatOptions$find === void 0 ? void 0 : _flatOptions$find.text;
|
|
19142
19174
|
var rawValue = value ? String(value) : undefined;
|
|
19143
19175
|
var bottomSheetVariant = bottomSheetConfig.variant,
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import {
|
|
3
|
-
SectionListRenderItemInfo,
|
|
4
|
-
SectionList,
|
|
5
3
|
Dimensions,
|
|
4
|
+
SectionList,
|
|
5
|
+
SectionListRenderItemInfo,
|
|
6
6
|
} from 'react-native';
|
|
7
|
-
import Option from './Option';
|
|
8
7
|
import type { SingleSelectProps } from '.';
|
|
8
|
+
import { BaseOptionListProps } from '../BaseOptionList';
|
|
9
|
+
import { deepCompareValue } from '../helpers';
|
|
9
10
|
import type { OptionType, SectionType } from '../types';
|
|
11
|
+
import Option from './Option';
|
|
10
12
|
import { StyledOptionList } from './StyledSingleSelect';
|
|
11
|
-
import { BaseOptionListProps } from '../BaseOptionList';
|
|
12
13
|
|
|
13
14
|
type OptionListProps<V, T extends OptionType<V>> = Pick<
|
|
14
15
|
SingleSelectProps<V, T>,
|
|
@@ -37,7 +38,7 @@ const OptionList = <V, T extends OptionType<V>>({
|
|
|
37
38
|
}: OptionListProps<V, T>) => {
|
|
38
39
|
const renderItem = (info: SectionListRenderItemInfo<T, SectionType>) => {
|
|
39
40
|
const { item } = info;
|
|
40
|
-
const selected = item.value
|
|
41
|
+
const selected = deepCompareValue(item.value, value);
|
|
41
42
|
const onItemPress = () => {
|
|
42
43
|
if (value === item.value) {
|
|
43
44
|
onPress(null);
|
|
@@ -58,4 +58,28 @@ describe('OptionList', () => {
|
|
|
58
58
|
);
|
|
59
59
|
expect(toJSON()).toMatchSnapshot();
|
|
60
60
|
});
|
|
61
|
+
|
|
62
|
+
it('render object value correctly', () => {
|
|
63
|
+
const sectionsWithObjectValue = [
|
|
64
|
+
{
|
|
65
|
+
category: 'A',
|
|
66
|
+
data: [{ text: 'Item 1', value: { id: '1', label: 'Item 1' } }],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
category: 'B',
|
|
70
|
+
data: [{ text: 'Item 2', value: { id: '2', label: 'Item 2' } }],
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
const pressFn = jest.fn();
|
|
74
|
+
const { toJSON, getByText } = renderWithTheme(
|
|
75
|
+
<OptionList
|
|
76
|
+
sections={sectionsWithObjectValue}
|
|
77
|
+
value={sectionsWithObjectValue[0].data[0].value}
|
|
78
|
+
onPress={pressFn}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
expect(toJSON()).toMatchSnapshot();
|
|
82
|
+
expect(getByText('Item 1')).toBeTruthy();
|
|
83
|
+
expect(getByText('Item 2')).toBeTruthy();
|
|
84
|
+
});
|
|
61
85
|
});
|