@snack-uikit/calendar 0.6.5 → 0.7.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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 0.7.0 (2024-02-06)
7
+
8
+
9
+ ### Features
10
+
11
+ * **FF-4166:** add locale usage in calendar ([03ff7a6](https://github.com/cloud-ru-tech/snack-uikit/commit/03ff7a6983fef794665828434e1faa8b61bd102d))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.6.5 (2024-02-05)
7
18
 
8
19
  ### Only dependencies have been changed
@@ -14,7 +25,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
14
25
 
15
26
  ## 0.6.4 (2024-02-02)
16
27
 
17
- **Note:** Version bump only for package @snack-uikit/calendar
28
+ ### Only dependencies have been changed
29
+ * [@snack-uikit/locale@0.1.0](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/locale/CHANGELOG.md)
18
30
 
19
31
 
20
32
 
@@ -13,6 +13,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
14
  import { useCallback, useMemo, useRef, useState } from 'react';
15
15
  import { useUncontrolledProp } from 'uncontrollable';
16
+ import { useLocale } from '@snack-uikit/locale';
16
17
  import { extractSupportProps } from '@snack-uikit/utils';
17
18
  import { AUTOFOCUS, SIZE, VIEW_MODE } from '../../constants';
18
19
  import { getEndOfTheDay, getLocale, getTestIdBuilder, sortDates } from '../../utils';
@@ -57,7 +58,8 @@ export function CalendarBase(_a) {
57
58
  }
58
59
  }, [preselectedRange, setValue]);
59
60
  const getTestId = useMemo(() => getTestIdBuilder(testId), [testId]);
60
- const locale = useMemo(() => getLocale(localeProp), [localeProp]);
61
+ const [, ctxLocale] = useLocale();
62
+ const locale = useMemo(() => getLocale({ localeProp, ctxLocale }), [ctxLocale, localeProp]);
61
63
  const firstNotDisableCell = useRef([0, 0]);
62
64
  return (_jsx("div", Object.assign({}, extractSupportProps(rest), { className: cn(styles.calendar, className, CONTAINER_SIZE_MAP[size]), style: style, "data-size": size, "data-fit-to-container": fitToContainer || undefined, "data-test-id": testId, children: _jsxs(CalendarContext.Provider, { value: {
63
65
  locale,
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { LocaleLang } from '@snack-uikit/locale';
1
2
  import { InRangePosition, Range, ViewMode } from './types';
2
3
  export declare const isTheSameDecade: (date1: Date, date2: Date) => boolean;
3
4
  export declare const isTheSameYear: (date1: Date, date2: Date) => boolean;
@@ -15,6 +16,9 @@ export declare const sortDates: (dates: Date[]) => Date[];
15
16
  export declare const getInRangePosition: (date: Date, viewMode: ViewMode, range?: Range) => InRangePosition;
16
17
  export declare const getEndOfTheDay: (date: Date) => Date;
17
18
  export declare const getTestIdBuilder: (testId?: string) => (prefix: string) => string | undefined;
18
- export declare const getLocale: (localeProp?: Intl.Locale) => Intl.Locale;
19
+ export declare const getLocale: ({ localeProp, ctxLocale }?: {
20
+ localeProp?: Intl.Locale | undefined;
21
+ ctxLocale?: `${string}_${string}` | undefined;
22
+ }) => Intl.Locale;
19
23
  export declare const getStartOfWeek: (locale: Intl.Locale) => import("weekstart").DayOfWeek;
20
24
  export declare const isWeekend: (date: Date, viewMode: ViewMode) => boolean;
package/dist/utils.js CHANGED
@@ -51,8 +51,8 @@ export const getInRangePosition = (date, viewMode, range) => {
51
51
  return date.valueOf() >= start && date.valueOf() <= end ? IN_RANGE_POSITION.In : IN_RANGE_POSITION.Out;
52
52
  };
53
53
  export const getEndOfTheDay = (date) => new Date(new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1).valueOf() - 1);
54
- export const getTestIdBuilder = (testId) => (prefix) => testId ? `${prefix}-${testId}` : undefined;
55
- export const getLocale = (localeProp) => localeProp || new Intl.Locale((navigator === null || navigator === void 0 ? void 0 : navigator.language) || 'ru-RU');
54
+ export const getTestIdBuilder = (testId) => (prefix) => (testId ? `${prefix}-${testId}` : undefined);
55
+ export const getLocale = ({ localeProp, ctxLocale } = {}) => { var _a; return localeProp || new Intl.Locale(ctxLocale ? ctxLocale.replace('_', '-') : (_a = navigator === null || navigator === void 0 ? void 0 : navigator.language) !== null && _a !== void 0 ? _a : 'ru-RU'); };
56
56
  export const getStartOfWeek = (locale) => getWeekStartByLocale(locale.language);
57
57
  export const isWeekend = (date, viewMode) => {
58
58
  if (viewMode === 'month') {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Calendar",
7
- "version": "0.6.5",
7
+ "version": "0.7.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -33,10 +33,11 @@
33
33
  "scripts": {},
34
34
  "dependencies": {
35
35
  "@snack-uikit/icons": "0.20.1",
36
+ "@snack-uikit/locale": "0.1.0",
36
37
  "@snack-uikit/utils": "3.2.0",
37
38
  "classnames": "2.3.2",
38
39
  "uncontrollable": "8.0.2",
39
40
  "weekstart": "2.0.0"
40
41
  },
41
- "gitHead": "b1acc8128bdab6f23b534d7c464208069e59ed8c"
42
+ "gitHead": "e38849932e4595cfeaf19733fcd296ffcfc7322e"
42
43
  }
@@ -2,6 +2,7 @@ import cn from 'classnames';
2
2
  import { CSSProperties, RefCallback, useCallback, useMemo, useRef, useState } from 'react';
3
3
  import { useUncontrolledProp } from 'uncontrollable';
4
4
 
5
+ import { useLocale } from '@snack-uikit/locale';
5
6
  import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
6
7
 
7
8
  import { AUTOFOCUS, SIZE, VIEW_MODE } from '../../constants';
@@ -98,7 +99,9 @@ export function CalendarBase({
98
99
 
99
100
  const getTestId = useMemo(() => getTestIdBuilder(testId), [testId]);
100
101
 
101
- const locale = useMemo(() => getLocale(localeProp), [localeProp]);
102
+ const [, ctxLocale] = useLocale();
103
+
104
+ const locale = useMemo(() => getLocale({ localeProp, ctxLocale }), [ctxLocale, localeProp]);
102
105
 
103
106
  const firstNotDisableCell = useRef<[number, number]>([0, 0]);
104
107
 
package/src/utils.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { getWeekStartByLocale } from 'weekstart';
2
2
 
3
+ import { LocaleLang } from '@snack-uikit/locale';
4
+
3
5
  import { IN_RANGE_POSITION, VIEW_MODE } from './constants';
4
6
  import { InRangePosition, Range, ViewMode } from './types';
5
7
 
@@ -81,9 +83,10 @@ export const getInRangePosition = (date: Date, viewMode: ViewMode, range?: Range
81
83
  export const getEndOfTheDay = (date: Date) =>
82
84
  new Date(new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1).valueOf() - 1);
83
85
 
84
- export const getTestIdBuilder = (testId?: string) => (prefix: string) => testId ? `${prefix}-${testId}` : undefined;
86
+ export const getTestIdBuilder = (testId?: string) => (prefix: string) => (testId ? `${prefix}-${testId}` : undefined);
85
87
 
86
- export const getLocale = (localeProp?: Intl.Locale) => localeProp || new Intl.Locale(navigator?.language || 'ru-RU');
88
+ export const getLocale = ({ localeProp, ctxLocale }: { localeProp?: Intl.Locale; ctxLocale?: LocaleLang } = {}) =>
89
+ localeProp || new Intl.Locale(ctxLocale ? ctxLocale.replace('_', '-') : navigator?.language ?? 'ru-RU');
87
90
 
88
91
  export const getStartOfWeek = (locale: Intl.Locale) => getWeekStartByLocale(locale.language);
89
92