@hero-design/rn 8.93.0 → 8.96.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.
- package/.turbo/turbo-build.log +7 -2
- package/CHANGELOG.md +18 -0
- package/es/index.js +2128 -1023
- package/lib/index.js +2127 -1021
- package/locales/en_AU.js +10 -0
- package/locales/en_AU.mjs +8 -0
- package/locales/en_CA.js +10 -0
- package/locales/en_CA.mjs +8 -0
- package/locales/index.js +11 -0
- package/locales/index.mjs +9 -0
- package/locales/types.js +2 -0
- package/locales/types.mjs +1 -0
- package/package.json +4 -3
- package/rollup.config.mjs +97 -58
- package/src/components/DatePicker/DatePickerAndroid.tsx +27 -7
- package/src/components/DatePicker/DatePickerCalendar.tsx +23 -4
- package/src/components/DatePicker/DatePickerIOS.tsx +27 -8
- package/src/components/DatePicker/__tests__/DatePicker.spec.tsx +30 -1
- package/src/components/DatePicker/__tests__/DatePickerAndroid.spec.tsx +27 -0
- package/src/components/DatePicker/__tests__/DatePickerCalendar.spec.tsx +27 -0
- package/src/components/DatePicker/__tests__/DatePickerIOS.spec.tsx +28 -1
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +1 -0
- package/src/components/DatePicker/hooks/__tests__/useFormatDate.spec.ts +61 -0
- package/src/components/DatePicker/{useCalculateDate.tsx → hooks/useCalculateDate.tsx} +1 -1
- package/src/components/DatePicker/hooks/useFormatDate.ts +25 -0
- package/src/components/DatePicker/hooks/utils.ts +30 -0
- package/src/components/DatePicker/types.ts +15 -1
- package/src/components/HeroDesignProvider/index.tsx +19 -6
- package/src/components/LocaleProvider/__tests__/utils.specs.ts +12 -0
- package/src/components/LocaleProvider/context.ts +7 -0
- package/src/components/LocaleProvider/hooks.ts +19 -0
- package/src/components/LocaleProvider/index.tsx +27 -0
- package/src/components/LocaleProvider/utils.ts +14 -0
- package/src/components/{Empty → StatusScreens/Empty}/StyledEmpty.tsx +11 -2
- package/src/components/StatusScreens/Empty/__tests__/__snapshots__/index.spec.tsx.snap +468 -0
- package/src/components/{Empty → StatusScreens/Empty}/__tests__/index.spec.tsx +16 -2
- package/src/components/StatusScreens/Empty/index.tsx +97 -0
- package/src/components/{Error → StatusScreens/Error}/StyledError.tsx +4 -4
- package/src/components/{Error → StatusScreens/Error}/__tests__/__snapshots__/index.spec.tsx.snap +300 -0
- package/src/components/{Error → StatusScreens/Error}/__tests__/index.spec.tsx +13 -3
- package/src/components/{Error → StatusScreens/Error}/index.tsx +39 -7
- package/src/components/StatusScreens/StatusIcon/__tests__/index.spec.tsx +31 -0
- package/src/components/StatusScreens/StatusIcon/assets/Add.tsx +49 -0
- package/src/components/StatusScreens/StatusIcon/assets/Boom.tsx +61 -0
- package/src/components/StatusScreens/StatusIcon/assets/Build.tsx +45 -0
- package/src/components/StatusScreens/StatusIcon/assets/Clock.tsx +38 -0
- package/src/components/StatusScreens/StatusIcon/assets/Confetti.tsx +78 -0
- package/src/components/StatusScreens/StatusIcon/assets/Connections.tsx +57 -0
- package/src/components/StatusScreens/StatusIcon/assets/Error.tsx +55 -0
- package/src/components/StatusScreens/StatusIcon/assets/Info.tsx +35 -0
- package/src/components/StatusScreens/StatusIcon/assets/List.tsx +37 -0
- package/src/components/StatusScreens/StatusIcon/assets/Location.tsx +37 -0
- package/src/components/StatusScreens/StatusIcon/assets/Merge.tsx +59 -0
- package/src/components/StatusScreens/StatusIcon/assets/Notifications.tsx +26 -0
- package/src/components/StatusScreens/StatusIcon/assets/Search.tsx +36 -0
- package/src/components/StatusScreens/StatusIcon/assets/Star.tsx +37 -0
- package/src/components/StatusScreens/StatusIcon/assets/Success.tsx +41 -0
- package/src/components/StatusScreens/StatusIcon/assets/User.tsx +43 -0
- package/src/components/StatusScreens/StatusIcon/index.tsx +63 -0
- package/src/components/StatusScreens/StatusIcon/types.ts +5 -0
- package/src/components/{Success → StatusScreens/Success}/StyledSuccess.tsx +4 -4
- package/src/components/{Success → StatusScreens/Success}/__tests__/__snapshots__/index.spec.tsx.snap +263 -0
- package/src/components/{Success → StatusScreens/Success}/__tests__/index.spec.tsx +13 -4
- package/src/components/{Success → StatusScreens/Success}/index.tsx +38 -7
- package/src/index.ts +5 -3
- package/src/locales/en_AU.ts +10 -0
- package/src/locales/en_CA.ts +10 -0
- package/src/locales/index.ts +7 -0
- package/src/locales/types.ts +12 -0
- package/src/testHelpers/renderWithTheme.tsx +7 -1
- package/src/types.ts +4 -0
- package/stats/8.94.0/rn-stats.html +4842 -0
- package/stats/8.95.0/rn-stats.html +4842 -0
- package/stats/8.96.0/rn-stats.html +4842 -0
- package/types/components/DatePicker/DatePickerAndroid.d.ts +1 -1
- package/types/components/DatePicker/DatePickerCalendar.d.ts +1 -1
- package/types/components/DatePicker/DatePickerIOS.d.ts +1 -1
- package/types/components/DatePicker/{useCalculateDate.d.ts → hooks/useCalculateDate.d.ts} +1 -1
- package/types/components/DatePicker/hooks/useFormatDate.d.ts +10 -0
- package/types/components/DatePicker/hooks/utils.d.ts +6 -0
- package/types/components/DatePicker/types.d.ts +8 -1
- package/types/components/HeroDesignProvider/index.d.ts +5 -1
- package/types/components/LocaleProvider/__tests__/utils.specs.d.ts +1 -0
- package/types/components/LocaleProvider/context.d.ts +3 -0
- package/types/components/LocaleProvider/hooks.d.ts +5 -0
- package/types/components/LocaleProvider/index.d.ts +7 -0
- package/types/components/LocaleProvider/utils.d.ts +3 -0
- package/types/components/{Empty → StatusScreens/Empty}/StyledEmpty.d.ts +9 -3
- package/types/components/{Empty → StatusScreens/Empty}/index.d.ts +8 -3
- package/types/components/{Error → StatusScreens/Error}/StyledError.d.ts +6 -6
- package/types/components/{Error → StatusScreens/Error}/index.d.ts +6 -1
- package/types/components/StatusScreens/StatusIcon/assets/Add.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Boom.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Build.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Clock.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Confetti.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Connections.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Error.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Info.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/List.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Location.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Merge.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Notifications.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Search.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Star.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/Success.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/assets/User.d.ts +4 -0
- package/types/components/StatusScreens/StatusIcon/index.d.ts +26 -0
- package/types/components/StatusScreens/StatusIcon/types.d.ts +5 -0
- package/types/components/{Success → StatusScreens/Success}/StyledSuccess.d.ts +5 -5
- package/types/components/{Success → StatusScreens/Success}/index.d.ts +6 -1
- package/types/index.d.ts +5 -4
- package/types/locales/en_AU.d.ts +3 -0
- package/types/locales/en_CA.d.ts +3 -0
- package/types/locales/index.d.ts +5 -0
- package/types/locales/types.d.ts +10 -0
- package/types/types.d.ts +2 -1
- package/src/components/Empty/__tests__/__snapshots__/index.spec.tsx.snap +0 -218
- package/src/components/Empty/index.tsx +0 -73
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react-hooks';
|
|
2
|
+
import formatDate from 'date-fns/fp/format';
|
|
3
|
+
import useFormatDate from '../useFormatDate';
|
|
4
|
+
import { useDateTimeFormat } from '../../../LocaleProvider/hooks';
|
|
5
|
+
|
|
6
|
+
// Mock dependencies
|
|
7
|
+
jest.mock('../../../LocaleProvider/hooks', () => ({
|
|
8
|
+
useDateTimeFormat: jest.fn(),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
jest.mock('date-fns/fp/format', () => {
|
|
12
|
+
return jest.fn((format, date) => {
|
|
13
|
+
return `Formatted: ${format}, Date: ${date.toISOString()}`;
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('useFormatDate', () => {
|
|
18
|
+
const testDate = new Date('2023-04-15');
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
(useDateTimeFormat as jest.Mock).mockReturnValue({
|
|
23
|
+
localizeDateTime: () => 'MM/dd/yyyy',
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should return empty string when no date is provided', () => {
|
|
28
|
+
const { result } = renderHook(() => useFormatDate({}));
|
|
29
|
+
expect(result.current.displayValue).toBe('');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should format date with provided format', () => {
|
|
33
|
+
const { result } = renderHook(() =>
|
|
34
|
+
useFormatDate({
|
|
35
|
+
value: testDate,
|
|
36
|
+
displayFormat: 'yyyy-MM-dd',
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
expect(formatDate).toHaveBeenCalledWith('yyyy-MM-dd', testDate);
|
|
41
|
+
expect(result.current.format).toBe('yyyy-MM-dd');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should use locale format when no displayFormat provided', () => {
|
|
45
|
+
const { result } = renderHook(() =>
|
|
46
|
+
useFormatDate({
|
|
47
|
+
value: testDate,
|
|
48
|
+
locale: 'en-US',
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(formatDate).toHaveBeenCalledWith('MM/dd/yyyy', testDate);
|
|
53
|
+
expect(result.current.format).toBe('MM/dd/yyyy');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should use default format when no displayFormat or locale provided', () => {
|
|
57
|
+
const { result } = renderHook(() => useFormatDate({ value: testDate }));
|
|
58
|
+
expect(formatDate).toHaveBeenCalledWith('MM/dd/yyyy', testDate);
|
|
59
|
+
expect(result.current.format).toBe('MM/dd/yyyy');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import formatDate from 'date-fns/fp/format';
|
|
2
|
+
import { useDateTimeFormat } from '../../LocaleProvider/hooks';
|
|
3
|
+
import { getDateFormat } from './utils';
|
|
4
|
+
|
|
5
|
+
type UseFormatDateProps = {
|
|
6
|
+
displayFormat?: string;
|
|
7
|
+
locale?: string;
|
|
8
|
+
value?: Date;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const useFormatDate = ({
|
|
12
|
+
displayFormat,
|
|
13
|
+
locale,
|
|
14
|
+
value,
|
|
15
|
+
}: UseFormatDateProps) => {
|
|
16
|
+
const { localizeDateTime } = useDateTimeFormat();
|
|
17
|
+
|
|
18
|
+
const format = getDateFormat({ displayFormat, locale, localizeDateTime });
|
|
19
|
+
|
|
20
|
+
const displayValue = value ? formatDate(format, value) : '';
|
|
21
|
+
|
|
22
|
+
return { displayValue, format };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default useFormatDate;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DateTimeFormats, LocaleCode } from '../../../types';
|
|
2
|
+
import locales from '../../../locales';
|
|
3
|
+
|
|
4
|
+
// Function to get the date format based on the displayFormat and locale,
|
|
5
|
+
// if no displayFormat or locale is provided, use the default fullDate format
|
|
6
|
+
export const getDateFormat = ({
|
|
7
|
+
displayFormat,
|
|
8
|
+
locale,
|
|
9
|
+
localizeDateTime,
|
|
10
|
+
}: {
|
|
11
|
+
displayFormat?: string;
|
|
12
|
+
locale?: string;
|
|
13
|
+
localizeDateTime: (key: keyof DateTimeFormats) => string;
|
|
14
|
+
}) => {
|
|
15
|
+
// Prioritise displayFormat
|
|
16
|
+
if (displayFormat) {
|
|
17
|
+
return displayFormat;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// If locale is provided, find the corresponding locale in the locales object
|
|
21
|
+
if (locale && locales[locale as LocaleCode]) {
|
|
22
|
+
const localeObject = locales[locale as LocaleCode];
|
|
23
|
+
if (localeObject) {
|
|
24
|
+
return localeObject.dateTimeFormats.fullDate;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// If no displayFormat or locale is provided, use the default fullDate format
|
|
29
|
+
return localizeDateTime('fullDate');
|
|
30
|
+
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
TextInputProps as NativeTextInputProps,
|
|
3
|
+
StyleProp,
|
|
4
|
+
ViewStyle,
|
|
5
|
+
} from 'react-native';
|
|
2
6
|
|
|
3
7
|
export interface DatePickerProps {
|
|
4
8
|
/**
|
|
@@ -85,4 +89,14 @@ export interface DatePickerProps {
|
|
|
85
89
|
* [Android only] autoTheme will automatically set the theme based on the device's light mode or dark mode.
|
|
86
90
|
* */
|
|
87
91
|
autoTheme?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Custom renderer for the selected value. The function provides the current date object and the formatted date string for the current display format.
|
|
94
|
+
*/
|
|
95
|
+
renderSelectedValue?: (
|
|
96
|
+
value: {
|
|
97
|
+
date: Date;
|
|
98
|
+
formattedDateString: string;
|
|
99
|
+
},
|
|
100
|
+
props?: NativeTextInputProps
|
|
101
|
+
) => React.ReactNode;
|
|
88
102
|
}
|
|
@@ -2,13 +2,26 @@ import React from 'react';
|
|
|
2
2
|
import ThemeProvider, { ThemeProviderProps } from '../../theme/ThemeProvider';
|
|
3
3
|
import Toast from '../Toast';
|
|
4
4
|
import Portal from '../Portal';
|
|
5
|
+
import LocaleProvider from '../LocaleProvider';
|
|
6
|
+
import { LocaleValues } from '../../locales/types';
|
|
7
|
+
import enAULocale from '../../locales/en_AU';
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
interface HeroDesignProviderProps extends ThemeProviderProps {
|
|
10
|
+
locale?: LocaleValues;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const HeroDesignProvider = ({
|
|
14
|
+
theme,
|
|
15
|
+
locale = enAULocale,
|
|
16
|
+
children,
|
|
17
|
+
}: HeroDesignProviderProps) => (
|
|
18
|
+
<LocaleProvider locale={locale}>
|
|
19
|
+
<ThemeProvider theme={theme}>
|
|
20
|
+
<Toast.Provider>
|
|
21
|
+
<Portal.Provider>{children}</Portal.Provider>
|
|
22
|
+
</Toast.Provider>
|
|
23
|
+
</ThemeProvider>
|
|
24
|
+
</LocaleProvider>
|
|
12
25
|
);
|
|
13
26
|
|
|
14
27
|
export default HeroDesignProvider;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import enAU from 'date-fns/locale/en-AU';
|
|
2
|
+
import enCA from 'date-fns/locale/en-CA';
|
|
3
|
+
import { getDateFnsLocale } from '../utils';
|
|
4
|
+
|
|
5
|
+
describe('getDateFnsLocale', () => {
|
|
6
|
+
it('should find en-AU', () => {
|
|
7
|
+
expect(getDateFnsLocale('en-AU')).toBe(enAU);
|
|
8
|
+
});
|
|
9
|
+
it('should find en-CA', () => {
|
|
10
|
+
expect(getDateFnsLocale('en-CA')).toBe(enCA);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useCallback, useContext } from 'react';
|
|
2
|
+
import { LocaleContext } from './context';
|
|
3
|
+
import enAUTranslations from '../../locales/en_AU';
|
|
4
|
+
import type { DateTimeFormats } from '../../locales/types';
|
|
5
|
+
|
|
6
|
+
export const useLocale = () => {
|
|
7
|
+
const context = useContext(LocaleContext);
|
|
8
|
+
if (!context) return enAUTranslations;
|
|
9
|
+
return context;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const useDateTimeFormat = () => {
|
|
13
|
+
const { dateTimeFormats } = useLocale();
|
|
14
|
+
const localizeDateTime = useCallback(
|
|
15
|
+
(key: keyof DateTimeFormats) => dateTimeFormats?.[key],
|
|
16
|
+
[dateTimeFormats]
|
|
17
|
+
);
|
|
18
|
+
return { localizeDateTime };
|
|
19
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import setDefaultOptions from 'date-fns/setDefaultOptions';
|
|
3
|
+
import { LocaleContext } from './context';
|
|
4
|
+
import { getDateFnsLocale } from './utils';
|
|
5
|
+
import { LocaleValues } from '../../locales/types';
|
|
6
|
+
|
|
7
|
+
interface LocaleProviderProps {
|
|
8
|
+
locale: LocaleValues;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const LocaleProvider = (
|
|
12
|
+
props: React.PropsWithChildren<LocaleProviderProps>
|
|
13
|
+
) => {
|
|
14
|
+
const { locale, children } = props;
|
|
15
|
+
const code = locale?.['lang'] || 'en-AU';
|
|
16
|
+
// setDefaultOptions here instead of inside useEffect for first rendering
|
|
17
|
+
setDefaultOptions({ locale: getDateFnsLocale(code) });
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
return () => setDefaultOptions({ locale: getDateFnsLocale('en-AU') });
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<LocaleContext.Provider value={locale}>{children}</LocaleContext.Provider>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default LocaleProvider;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import enAU from 'date-fns/locale/en-AU';
|
|
2
|
+
import enCA from 'date-fns/locale/en-CA';
|
|
3
|
+
import type { Locale } from 'date-fns';
|
|
4
|
+
import { LocaleCode } from '../../locales/types';
|
|
5
|
+
|
|
6
|
+
const Locales = {
|
|
7
|
+
'en-AU': enAU,
|
|
8
|
+
'en-CA': enCA,
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export function getDateFnsLocale(locale: LocaleCode): Locale {
|
|
12
|
+
const fallbackLocale = Locales['en-AU'];
|
|
13
|
+
return Locales[locale] || fallbackLocale;
|
|
14
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { View } from 'react-native';
|
|
2
2
|
import styled from '@emotion/native';
|
|
3
|
-
import Typography from '
|
|
3
|
+
import Typography from '../../Typography';
|
|
4
4
|
|
|
5
5
|
type ThemeVariant = 'light' | 'dark';
|
|
6
6
|
|
|
@@ -34,4 +34,13 @@ const StyledDescription = styled(Typography.Body)<{
|
|
|
34
34
|
: theme.__hd__.empty.colors.subduedText,
|
|
35
35
|
}));
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const StyledEmptyImageContainer = styled(View)(({ theme }) => ({
|
|
38
|
+
marginBottom: theme.__hd__.empty.space.imageMargin,
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
StyledWrapper,
|
|
43
|
+
StyledTitle,
|
|
44
|
+
StyledDescription,
|
|
45
|
+
StyledEmptyImageContainer,
|
|
46
|
+
};
|