@hero-design/rn 8.94.0 → 8.97.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 +1744 -1322
- package/lib/index.js +1747 -1324
- 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 +34 -40
- package/src/components/DatePicker/DatePickerCalendar.tsx +23 -4
- package/src/components/DatePicker/DatePickerIOS.tsx +36 -67
- package/src/components/DatePicker/Dialog/AndroidDialog.tsx +68 -0
- package/src/components/DatePicker/Dialog/IOSDialog.tsx +91 -0
- package/src/components/DatePicker/Dialog/__tests__/AndroidDialog.spec.tsx +70 -0
- package/src/components/DatePicker/Dialog/__tests__/IOSDialog.spec.tsx +114 -0
- package/src/components/DatePicker/Dialog/type.ts +50 -0
- 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__/DatePickerAndroid.spec.tsx.snap +18 -9
- 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/index.tsx +12 -1
- 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/index.ts +2 -0
- 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.95.0/rn-stats.html +4842 -0
- package/stats/8.96.0/rn-stats.html +4842 -0
- package/stats/8.97.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/Dialog/AndroidDialog.d.ts +5 -0
- package/types/components/DatePicker/Dialog/IOSDialog.d.ts +4 -0
- package/types/components/DatePicker/Dialog/type.d.ts +50 -0
- 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/index.d.ts +5 -2
- 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/index.d.ts +2 -1
- 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
|
@@ -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
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -76,6 +76,7 @@ import {
|
|
|
76
76
|
} from './components/AnimatedScroller';
|
|
77
77
|
import Search from './components/Search';
|
|
78
78
|
import FloatingIsland from './components/FloatingIsland';
|
|
79
|
+
import LocaleProvider from './components/LocaleProvider';
|
|
79
80
|
|
|
80
81
|
export {
|
|
81
82
|
theme,
|
|
@@ -153,6 +154,7 @@ export {
|
|
|
153
154
|
RefreshControl,
|
|
154
155
|
RichTextEditor,
|
|
155
156
|
FloatingIsland,
|
|
157
|
+
LocaleProvider,
|
|
156
158
|
};
|
|
157
159
|
|
|
158
160
|
export * from './types';
|
|
@@ -3,8 +3,14 @@ import { render } from '@testing-library/react-native'; // eslint-disable-line i
|
|
|
3
3
|
import type { RenderOptions } from '@testing-library/react-native';
|
|
4
4
|
import { theme } from '../index';
|
|
5
5
|
import HeroDesignProvider from '../components/HeroDesignProvider';
|
|
6
|
+
import enAU from '../locales/en_AU';
|
|
6
7
|
|
|
7
8
|
const renderWithTheme = (ui: JSX.Element, options?: RenderOptions) =>
|
|
8
|
-
render(
|
|
9
|
+
render(
|
|
10
|
+
<HeroDesignProvider theme={theme} locale={enAU}>
|
|
11
|
+
{ui}
|
|
12
|
+
</HeroDesignProvider>,
|
|
13
|
+
options
|
|
14
|
+
);
|
|
9
15
|
|
|
10
16
|
export default renderWithTheme;
|
package/src/types.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { FABHandles } from './components/FAB/FAB';
|
|
|
19
19
|
import { ActionGroupHandles } from './components/FAB/ActionGroup';
|
|
20
20
|
import type { SliderRangeValue } from './components/Slider/RangeSlider';
|
|
21
21
|
import type { CalendarDateRange } from './components/Calendar/CalendarRange';
|
|
22
|
+
import { LocaleCode, LocaleValues, DateTimeFormats } from './locales/types';
|
|
22
23
|
|
|
23
24
|
export type {
|
|
24
25
|
BottomNavigationTabType,
|
|
@@ -40,4 +41,7 @@ export type {
|
|
|
40
41
|
ActionGroupHandles,
|
|
41
42
|
SliderRangeValue,
|
|
42
43
|
CalendarDateRange,
|
|
44
|
+
LocaleCode,
|
|
45
|
+
LocaleValues,
|
|
46
|
+
DateTimeFormats,
|
|
43
47
|
};
|