@hero-design/rn-work-uikit 1.1.0 → 1.2.0-alpha.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.
Files changed (49) hide show
  1. package/.cursorrules +57 -0
  2. package/CHANGELOG.md +16 -0
  3. package/DEVELOPMENT.md +118 -0
  4. package/assets/fonts/BeVietnamPro-Bold.ttf +0 -0
  5. package/assets/fonts/BeVietnamPro-Light.ttf +0 -0
  6. package/assets/fonts/BeVietnamPro-Regular.ttf +0 -0
  7. package/assets/fonts/BeVietnamPro-SemiBold.ttf +0 -0
  8. package/assets/fonts/Saiga-Light.otf +0 -0
  9. package/assets/fonts/Saiga-Medium.otf +0 -0
  10. package/assets/fonts/Saiga-Regular.otf +0 -0
  11. package/assets/fonts/hero-icons-mobile.ttf +0 -0
  12. package/eslint.config.js +20 -0
  13. package/lib/index.js +871 -5
  14. package/package.json +4 -1
  15. package/rollup.config.mjs +2 -2
  16. package/src/__tests__/__snapshots__/index.spec.tsx.snap +90 -115
  17. package/src/__tests__/theme-export-override.spec.ts +6 -0
  18. package/src/components/TextInput/ErrorOrHelpText.tsx +58 -0
  19. package/src/components/TextInput/FloatingLabel.tsx +120 -0
  20. package/src/components/TextInput/InputComponent.tsx +61 -0
  21. package/src/components/TextInput/InputRow.tsx +103 -0
  22. package/src/components/TextInput/MaxLengthMessage.tsx +66 -0
  23. package/src/components/TextInput/PrefixComponent.tsx +77 -0
  24. package/src/components/TextInput/StyledTextInput.tsx +134 -0
  25. package/src/components/TextInput/SuffixComponent.tsx +73 -0
  26. package/src/components/TextInput/__tests__/ErrorOrHelpText.spec.tsx +20 -0
  27. package/src/components/TextInput/__tests__/FloatingLabel.spec.tsx +203 -0
  28. package/src/components/TextInput/__tests__/InputComponent.spec.tsx +39 -0
  29. package/src/components/TextInput/__tests__/InputRow.spec.tsx +275 -0
  30. package/src/components/TextInput/__tests__/MaxLengthMessage.spec.tsx +17 -0
  31. package/src/components/TextInput/__tests__/PrefixComponent.spec.tsx +14 -0
  32. package/src/components/TextInput/__tests__/StyledTextInput.spec.tsx +114 -0
  33. package/src/components/TextInput/__tests__/SuffixComponent.spec.tsx +20 -0
  34. package/src/components/TextInput/__tests__/__snapshots__/StyledTextInput.spec.tsx.snap +571 -0
  35. package/src/components/TextInput/__tests__/__snapshots__/index.spec.tsx.snap +5671 -0
  36. package/src/components/TextInput/__tests__/getState.spec.tsx +89 -0
  37. package/src/components/TextInput/__tests__/index.spec.tsx +699 -0
  38. package/src/components/TextInput/constants.ts +1 -0
  39. package/src/components/TextInput/index.tsx +327 -0
  40. package/src/components/TextInput/types.ts +95 -0
  41. package/src/emotion.d.ts +15 -0
  42. package/src/index.ts +3 -0
  43. package/src/jest.d.ts +24 -0
  44. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +15 -8
  45. package/src/theme/components/textInput.ts +33 -0
  46. package/src/utils/__tests__/helpers.spec.ts +92 -0
  47. package/src/utils/helpers.ts +113 -0
  48. package/testUtils/renderWithTheme.tsx +6 -3
  49. package/stats/1.1.0/rn-work-uikit-stats.html +0 -4842
@@ -0,0 +1,92 @@
1
+ import { deepCompareValue, omit, pick } from '../helpers';
2
+
3
+ describe('pick', () => {
4
+ it('works', () => {
5
+ const props = { a: 1, b: true, c: 'outline', d: null, f: 'whatever' };
6
+
7
+ expect(pick(['a', 'b', 'f'], props)).toEqual({
8
+ a: 1,
9
+ b: true,
10
+ f: 'whatever',
11
+ });
12
+ });
13
+
14
+ it('work with unknown object type', () => {
15
+ const props: Record<string, unknown> = {
16
+ a: 1,
17
+ b: true,
18
+ c: 'outline',
19
+ d: null,
20
+ f: 'whatever',
21
+ };
22
+
23
+ expect(pick(['a', 'b', 'f'], props)).toEqual({
24
+ a: 1,
25
+ b: true,
26
+ f: 'whatever',
27
+ });
28
+ });
29
+ });
30
+
31
+ describe('omit', () => {
32
+ it('works', () => {
33
+ const props = { a: 1, b: true, c: 'outline', d: null, f: 'whatever' };
34
+
35
+ expect(omit(['a', 'b'], props)).toEqual({
36
+ c: 'outline',
37
+ d: null,
38
+ f: 'whatever',
39
+ });
40
+ });
41
+
42
+ it('work with unknown object type', () => {
43
+ const props: Record<string, unknown> = {
44
+ a: 1,
45
+ b: true,
46
+ c: 'outline',
47
+ d: null,
48
+ f: 'whatever',
49
+ };
50
+
51
+ expect(omit(['a', 'b'], props)).toEqual({
52
+ c: 'outline',
53
+ d: null,
54
+ f: 'whatever',
55
+ });
56
+ });
57
+ });
58
+
59
+ describe('deepCompareValue', () => {
60
+ it.each`
61
+ a | b | expected
62
+ ${1} | ${1} | ${true}
63
+ ${'test'} | ${'test'} | ${true}
64
+ ${true} | ${true} | ${true}
65
+ ${null} | ${null} | ${true}
66
+ ${undefined} | ${undefined} | ${true}
67
+ ${1} | ${2} | ${false}
68
+ ${'test'} | ${'other'} | ${false}
69
+ ${true} | ${false} | ${false}
70
+ ${null} | ${undefined} | ${false}
71
+ ${NaN} | ${NaN} | ${false}
72
+ ${1} | ${NaN} | ${false}
73
+ ${[1, 2, 3]} | ${[1, 2, 3]} | ${true}
74
+ ${['a', 'b']} | ${['a', 'b']} | ${true}
75
+ ${[]} | ${[]} | ${true}
76
+ ${[1, 2]} | ${[1, 2, 3]} | ${false}
77
+ ${[1, 2]} | ${[2, 1]} | ${false}
78
+ ${[1, [2, 3]]} | ${[1, [2, 3]]} | ${true}
79
+ ${[1, [2, 3]]} | ${[1, [2, 4]]} | ${false}
80
+ ${{ a: 1, b: 2 }} | ${{ a: 1, b: 2 }} | ${true}
81
+ ${{}} | ${{}} | ${true}
82
+ ${{ a: 1 }} | ${{ a: 2 }} | ${false}
83
+ ${{ a: 1 }} | ${{ b: 1 }} | ${false}
84
+ ${{ a: 1 }} | ${{ a: 1, b: 2 }} | ${false}
85
+ ${{ a: { b: 1 } }} | ${{ a: { b: 1 } }} | ${true}
86
+ ${{ a: { b: 1 } }} | ${{ a: { b: 2 } }} | ${false}
87
+ ${1} | ${'1'} | ${false}
88
+ ${[]} | ${{}} | ${false}
89
+ `('should compare $a and $b correctly', ({ a, b, expected }) => {
90
+ expect(deepCompareValue(a, b)).toBe(expected);
91
+ });
92
+ });
@@ -0,0 +1,113 @@
1
+ import { Platform, Keyboard } from 'react-native';
2
+
3
+ import { useEffect, useState } from 'react';
4
+
5
+ export const isIOS = Platform.OS === 'ios';
6
+ export const isAndroid = Platform.OS === 'android';
7
+
8
+ export function pick<O extends object, T extends keyof O>(
9
+ keys: T[],
10
+ obj: O
11
+ ): Pick<O, T> {
12
+ return keys
13
+ .filter((key) => key in obj)
14
+ .reduce<Partial<O>>(
15
+ (result, cur) => ({
16
+ ...result,
17
+ [cur]: obj[cur],
18
+ }),
19
+ {}
20
+ ) as Pick<O, T>;
21
+ }
22
+
23
+ export function omit<O, T extends keyof O>(keys: T[], obj: O): Omit<O, T> {
24
+ const result = { ...obj };
25
+
26
+ keys.forEach((key) => {
27
+ delete result[key];
28
+ });
29
+
30
+ return result;
31
+ }
32
+
33
+ export function hexToRgba(hex: string, a: number) {
34
+ const arrBuff = new ArrayBuffer(4);
35
+ const vw = new DataView(arrBuff);
36
+ vw.setUint32(0, parseInt(hex, 16), false);
37
+ const arrByte = new Uint8Array(arrBuff);
38
+ const [r, g, b] = arrByte;
39
+ return `rgba(${r},${g},${b},${a})`;
40
+ }
41
+
42
+ export const deepCompareValue = <V>(a: V, b: V): boolean => {
43
+ // Handle strict equality first (handles primitives, null, undefined)
44
+ if (a === b) return true;
45
+
46
+ // Special handling for NaN (NaN !== NaN in JS)
47
+ if (
48
+ typeof a === 'number' &&
49
+ typeof b === 'number' &&
50
+ Number.isNaN(a) &&
51
+ Number.isNaN(b)
52
+ ) {
53
+ return false;
54
+ }
55
+
56
+ // If either is null or undefined (but they are not strictly equal), return false
57
+ if (a == null || b == null) return false;
58
+
59
+ // If types don't match, they can't be equal
60
+ if (typeof a !== typeof b) return false;
61
+
62
+ // Handle array comparison
63
+ if (Array.isArray(a) && Array.isArray(b)) {
64
+ if (a.length !== b.length) return false;
65
+ return a.every((val, index) => deepCompareValue(val, b[index]));
66
+ }
67
+
68
+ // If one is array and the other isn't, return false
69
+ if (Array.isArray(a) !== Array.isArray(b)) return false;
70
+
71
+ // Handle object comparison
72
+ if (typeof a === 'object' && typeof b === 'object') {
73
+ const keysA = Object.keys(a) as (keyof V)[];
74
+ const keysB = Object.keys(b) as (keyof V)[];
75
+
76
+ if (keysA.length !== keysB.length) return false;
77
+
78
+ return keysA.every(
79
+ (key) => keysB.includes(key) && deepCompareValue(a[key], b[key])
80
+ );
81
+ }
82
+
83
+ // If none of the above conditions matched, they're not equal
84
+ return false;
85
+ };
86
+
87
+ export const useKeyboard = () => {
88
+ const [isKeyboardVisible, setKeyboardVisible] = useState(false);
89
+ const [keyboardHeight, setKeyboardHeight] = useState(0);
90
+
91
+ useEffect(() => {
92
+ const keyboardWillShowListener = Keyboard.addListener(
93
+ 'keyboardWillShow',
94
+ (e) => {
95
+ setKeyboardVisible(true);
96
+ setKeyboardHeight(e.endCoordinates.height);
97
+ }
98
+ );
99
+ const keyboardWillHideListener = Keyboard.addListener(
100
+ 'keyboardWillHide',
101
+ () => {
102
+ setKeyboardVisible(false);
103
+ }
104
+ );
105
+
106
+ return () => {
107
+ keyboardWillShowListener.remove();
108
+ keyboardWillHideListener.remove();
109
+ };
110
+ }, []);
111
+
112
+ return { isKeyboardVisible, keyboardHeight };
113
+ };
@@ -1,9 +1,12 @@
1
1
  import React from 'react';
2
2
  import { render } from '@testing-library/react-native'; // eslint-disable-line import/no-extraneous-dependencies
3
3
  import type { RenderOptions } from '@testing-library/react-native';
4
- import { HeroDesignProvider, theme } from '../src';
4
+ import { getTheme, ThemeProvider } from '../src';
5
5
 
6
- const renderWithTheme = (ui: JSX.Element, options?: RenderOptions) =>
7
- render(<HeroDesignProvider theme={theme}>{ui}</HeroDesignProvider>, options);
6
+ const theme = getTheme();
7
+
8
+ const renderWithTheme = (ui: JSX.Element, options?: RenderOptions) => {
9
+ return render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>, options);
10
+ };
8
11
 
9
12
  export default renderWithTheme;