@hero-design/rn-work-uikit 1.1.0-alpha.0 → 1.2.0-alpha.0

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 (56) hide show
  1. package/.cursorrules +57 -0
  2. package/CHANGELOG.md +8 -3
  3. package/DEVELOPMENT.md +118 -0
  4. package/THEME_OVERRIDE.md +52 -0
  5. package/eslint.config.js +20 -0
  6. package/lib/index.js +1000 -4
  7. package/locales/en_AU.js +10 -0
  8. package/locales/en_AU.mjs +8 -0
  9. package/locales/en_CA.js +10 -0
  10. package/locales/en_CA.mjs +8 -0
  11. package/locales/index.js +11 -0
  12. package/locales/index.mjs +9 -0
  13. package/locales/types.js +2 -0
  14. package/locales/types.mjs +1 -0
  15. package/package.json +8 -4
  16. package/rollup.config.mjs +18 -2
  17. package/src/__tests__/__snapshots__/index.spec.tsx.snap +91 -116
  18. package/src/__tests__/index.spec.tsx +15 -0
  19. package/src/__tests__/theme-export-override.spec.ts +96 -0
  20. package/src/components/TextInput/ErrorOrHelpText.tsx +58 -0
  21. package/src/components/TextInput/FloatingLabel.tsx +120 -0
  22. package/src/components/TextInput/InputComponent.tsx +61 -0
  23. package/src/components/TextInput/InputRow.tsx +103 -0
  24. package/src/components/TextInput/MaxLengthMessage.tsx +66 -0
  25. package/src/components/TextInput/PrefixComponent.tsx +77 -0
  26. package/src/components/TextInput/StyledTextInput.tsx +134 -0
  27. package/src/components/TextInput/SuffixComponent.tsx +73 -0
  28. package/src/components/TextInput/__tests__/ErrorOrHelpText.spec.tsx +20 -0
  29. package/src/components/TextInput/__tests__/FloatingLabel.spec.tsx +203 -0
  30. package/src/components/TextInput/__tests__/InputComponent.spec.tsx +39 -0
  31. package/src/components/TextInput/__tests__/InputRow.spec.tsx +275 -0
  32. package/src/components/TextInput/__tests__/MaxLengthMessage.spec.tsx +17 -0
  33. package/src/components/TextInput/__tests__/PrefixComponent.spec.tsx +14 -0
  34. package/src/components/TextInput/__tests__/StyledTextInput.spec.tsx +114 -0
  35. package/src/components/TextInput/__tests__/SuffixComponent.spec.tsx +20 -0
  36. package/src/components/TextInput/__tests__/__snapshots__/StyledTextInput.spec.tsx.snap +571 -0
  37. package/src/components/TextInput/__tests__/__snapshots__/index.spec.tsx.snap +5671 -0
  38. package/src/components/TextInput/__tests__/getState.spec.tsx +89 -0
  39. package/src/components/TextInput/__tests__/index.spec.tsx +699 -0
  40. package/src/components/TextInput/constants.ts +1 -0
  41. package/src/components/TextInput/index.tsx +327 -0
  42. package/src/components/TextInput/types.ts +95 -0
  43. package/src/emotion.d.ts +15 -0
  44. package/src/index.ts +16 -1
  45. package/src/jest.d.ts +24 -0
  46. package/src/theme/ThemeProvider.ts +20 -0
  47. package/src/theme/ThemeSwitcher.tsx +76 -0
  48. package/src/theme/__tests__/ThemeProvider.spec.tsx +32 -0
  49. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +1851 -0
  50. package/src/theme/__tests__/index.spec.ts +7 -0
  51. package/src/theme/components/textInput.ts +92 -0
  52. package/src/theme/getTheme.ts +32 -0
  53. package/src/theme/index.ts +17 -0
  54. package/src/utils/__tests__/helpers.spec.ts +92 -0
  55. package/src/utils/helpers.ts +113 -0
  56. package/testUtils/renderWithTheme.tsx +6 -3
@@ -0,0 +1,7 @@
1
+ import theme from '..';
2
+
3
+ describe('theme', () => {
4
+ it('returns correct theme object', () => {
5
+ expect(theme).toMatchSnapshot();
6
+ });
7
+ });
@@ -0,0 +1,92 @@
1
+ import type { Theme } from '@hero-design/rn';
2
+
3
+ const getTextInputTheme = (theme: Theme) => {
4
+ const baseTextInputTheme = theme.__hd__.textInput;
5
+
6
+ // Override specific values here as needed
7
+ const colors = {
8
+ ...baseTextInputTheme.colors,
9
+ // Example: override specific colors
10
+ // text: theme.colors.customTextColor,
11
+ borders: {
12
+ default: theme.colors.secondaryOutline,
13
+ error: theme.colors.onErrorSurface,
14
+ disabled: theme.colors.disabledOutline,
15
+ readonly: theme.colors.disabledOutline,
16
+ filled: theme.colors.secondaryOutline,
17
+ focused: theme.colors.primaryOutline,
18
+ },
19
+ labels: {
20
+ default: theme.colors.inactiveOnDefaultGlobalSurface,
21
+ error: theme.colors.onErrorSurface,
22
+ disabled: theme.colors.disabledOnDefaultGlobalSurface,
23
+ readonly: theme.colors.inactiveOnDefaultGlobalSurface,
24
+ filled: theme.colors.inactiveOnDefaultGlobalSurface,
25
+ focused: theme.colors.onDefaultGlobalSurface,
26
+ },
27
+ maxLengthLabels: {
28
+ default: theme.colors.onDefaultGlobalSurface,
29
+ error: theme.colors.onErrorSurface,
30
+ disabled: theme.colors.disabledOnDefaultGlobalSurface,
31
+ readonly: theme.colors.inactiveOnDefaultGlobalSurface,
32
+ filled: theme.colors.onDefaultGlobalSurface,
33
+ focused: theme.colors.onDefaultGlobalSurface,
34
+ },
35
+ };
36
+
37
+ const space = {
38
+ ...baseTextInputTheme.space,
39
+ // Example: override specific spacing
40
+ // containerPadding: theme.space.large,
41
+ inputWrapperMarginVertical: theme.space.small,
42
+ prefixAndInputContainerGap: theme.space.xsmall,
43
+ };
44
+
45
+ const fonts = {
46
+ ...baseTextInputTheme.fonts,
47
+ // Example: override fonts
48
+ // text: theme.fonts.custom.bold,
49
+ };
50
+
51
+ const fontSizes = {
52
+ ...baseTextInputTheme.fontSizes,
53
+ // Example: override font sizes
54
+ // text: theme.fontSizes.xlarge,
55
+ };
56
+
57
+ const borderWidths = {
58
+ ...baseTextInputTheme.borderWidths,
59
+ container: {
60
+ ...baseTextInputTheme.borderWidths.container,
61
+ normal: theme.borderWidths.medium,
62
+ },
63
+ };
64
+
65
+ const radii = {
66
+ ...baseTextInputTheme.radii,
67
+ };
68
+
69
+ const sizes = {
70
+ ...baseTextInputTheme.sizes,
71
+ containerMinHeight: theme.sizes.xxxxlarge,
72
+ errorAndHelpTextContainerHeight: 0,
73
+ textInputMinHeight: baseTextInputTheme.fontSizes.text + theme.space.small,
74
+ };
75
+
76
+ const lineHeights = {
77
+ ...baseTextInputTheme.lineHeights,
78
+ };
79
+
80
+ return {
81
+ colors,
82
+ space,
83
+ fonts,
84
+ fontSizes,
85
+ borderWidths,
86
+ radii,
87
+ sizes,
88
+ lineHeights,
89
+ };
90
+ };
91
+
92
+ export default getTextInputTheme;
@@ -0,0 +1,32 @@
1
+ import {
2
+ getTheme as getBaseTheme,
3
+ Theme as BaseTheme,
4
+ swagSystemPalette,
5
+ } from '@hero-design/rn';
6
+ import type { Scale, SystemPalette } from '@hero-design/rn';
7
+ import getTextInputTheme from './components/textInput';
8
+
9
+ // Work-specific theme type that includes textInput overrides
10
+ type Theme = BaseTheme & {
11
+ __hd__: BaseTheme['__hd__'] & {
12
+ textInput: ReturnType<typeof getTextInputTheme>;
13
+ };
14
+ };
15
+
16
+ const getTheme = (
17
+ scale?: Scale,
18
+ systemPalette: SystemPalette = swagSystemPalette
19
+ ): Theme => {
20
+ const baseTheme = getBaseTheme(scale, systemPalette);
21
+
22
+ return {
23
+ ...baseTheme,
24
+ __hd__: {
25
+ ...baseTheme.__hd__,
26
+ textInput: getTextInputTheme(baseTheme),
27
+ },
28
+ };
29
+ };
30
+
31
+ export default getTheme;
32
+ export type { Theme };
@@ -0,0 +1,17 @@
1
+ import getTheme from './getTheme';
2
+ import type { Theme } from './getTheme';
3
+ import { WorkThemeProvider, useWorkTheme } from './ThemeProvider';
4
+ import WorkThemeSwitcher, { withWorkTheme } from './ThemeSwitcher';
5
+
6
+ const defaultTheme = getTheme();
7
+
8
+ // Export with generic names to hide "Work" terminology from external consumers
9
+ export type { Theme };
10
+ export {
11
+ getTheme,
12
+ WorkThemeProvider as ThemeProvider,
13
+ WorkThemeSwitcher as ThemeSwitcher,
14
+ useWorkTheme as useTheme,
15
+ withWorkTheme as withTheme,
16
+ };
17
+ export default defaultTheme;
@@ -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;