@snack-uikit/fields 0.11.6 → 0.12.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.12.0 (2024-02-02)
7
+
8
+
9
+ ### Features
10
+
11
+ * **FF-4150:** add ability to disable specific dates ([0bcd8da](https://github.com/cloud-ru-tech/snack-uikit/commit/0bcd8da03cfce91996cd61b2b6f065af6597e89b))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.11.6 (2024-02-01)
7
18
 
8
19
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -265,6 +265,10 @@ const [isOpen, setIsOpen] = useState(false);
265
265
  | showHintIcon | `boolean` | - | Отображать иконку подсказки |
266
266
  | ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
267
267
  | key | `Key` | - | |
268
+ ## parseDate
269
+ `helper`
270
+
271
+ Преобразует строковое значение поля FieldDate в тип Date
268
272
  ## FieldDate
269
273
  ### Props
270
274
  | name | type | default value | description |
@@ -276,6 +280,7 @@ const [isOpen, setIsOpen] = useState(false);
276
280
  | showCopyButton | `boolean` | - | Отображение кнопки копирования |
277
281
  | showClearButton | `boolean` | true | Отображение кнопки Очистки поля |
278
282
  | locale | `Locale` | new Intl.Locale('ru-RU') | Текущая локаль календаря |
283
+ | buildCellProps | `(date: Date, viewMode: ViewMode) => { isDisabled?: boolean; isHoliday?: boolean };` | - | Колбек установки свойств ячеек календаря. Вызывается на построение каждой ячейки. Принимает два параметра: <br> `Date` - дата ячейки <br> `ViewMode`: <br> - `month` отображение месяца, каждая ячейка - 1 день <br> - `year` отображение года, каждая ячейка - 1 месяц <br> - `decade` отображение декады, каждая ячейка - 1 год <br><br> Колбек должен возвращать объект с полями, отвечающими за отключение и подкраску ячейки. |
279
284
  | disabled | `boolean` | - | Является ли поле деактивированным |
280
285
  | readonly | `boolean` | - | Является ли поле доступным только для чтения |
281
286
  | id | `string` | - | Значение html-атрибута id |
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import { CalendarProps } from '@snack-uikit/calendar';
2
3
  import { InputPrivateProps } from '@snack-uikit/input-private';
3
4
  import { WithSupportProps } from '@snack-uikit/utils';
4
5
  import { FieldDecoratorProps } from '../FieldDecorator';
@@ -20,9 +21,25 @@ type FieldDateOwnProps = {
20
21
  showClearButton?: boolean;
21
22
  /** Текущая локаль календаря */
22
23
  locale?: Intl.Locale;
23
- };
24
+ } & Pick<CalendarProps, 'buildCellProps'>;
24
25
  export type FieldDateProps = WithSupportProps<FieldDateOwnProps & InputProps & WrapperProps>;
25
26
  export declare const FieldDate: import("react").ForwardRefExoticComponent<{
26
27
  'data-test-id'?: string | undefined;
27
- } & import("react").AriaAttributes & FieldDateOwnProps & InputProps & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
28
+ } & import("react").AriaAttributes & {
29
+ /** Открыт date-picker */
30
+ open?: boolean | undefined;
31
+ /** Колбек открытия пикера */
32
+ onOpenChange?(value: boolean): void;
33
+ /** Колбек смены значения */
34
+ onChange?(value: string): void;
35
+ /** Отображение кнопки копирования */
36
+ showCopyButton?: boolean | undefined;
37
+ /**
38
+ * Отображение кнопки Очистки поля
39
+ * @default true
40
+ */
41
+ showClearButton?: boolean | undefined;
42
+ /** Текущая локаль календаря */
43
+ locale?: Intl.Locale | undefined;
44
+ } & Pick<CalendarProps, "buildCellProps"> & InputProps & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
28
45
  export {};
@@ -34,7 +34,7 @@ const CALENDAR_SIZE_MAP = {
34
34
  [SIZE.L]: 'm',
35
35
  };
36
36
  export const FieldDate = forwardRef((_a, ref) => {
37
- var { id, name, value: valueProp, disabled = false, readonly = false, showCopyButton: showCopyButtonProp = true, showClearButton: showClearButtonProp = true, open, onOpenChange, onChange, onFocus, onBlur: onBlurProp, className, label, labelTooltip, labelTooltipPlacement, required = false, hint, showHintIcon, size = SIZE.S, validationState = VALIDATION_STATE.Default, locale = DEFAULT_LOCALE } = _a, rest = __rest(_a, ["id", "name", "value", "disabled", "readonly", "showCopyButton", "showClearButton", "open", "onOpenChange", "onChange", "onFocus", "onBlur", "className", "label", "labelTooltip", "labelTooltipPlacement", "required", "hint", "showHintIcon", "size", "validationState", "locale"]);
37
+ var { id, name, value: valueProp, disabled = false, readonly = false, showCopyButton: showCopyButtonProp = true, showClearButton: showClearButtonProp = true, open, onOpenChange, onChange, onFocus, onBlur: onBlurProp, className, label, labelTooltip, labelTooltipPlacement, required = false, hint, showHintIcon, size = SIZE.S, validationState = VALIDATION_STATE.Default, locale = DEFAULT_LOCALE, buildCellProps } = _a, rest = __rest(_a, ["id", "name", "value", "disabled", "readonly", "showCopyButton", "showClearButton", "open", "onOpenChange", "onChange", "onFocus", "onBlur", "className", "label", "labelTooltip", "labelTooltipPlacement", "required", "hint", "showHintIcon", "size", "validationState", "locale", "buildCellProps"]);
38
38
  const [isOpen, setIsOpen] = useUncontrolledProp(open, false, onOpenChange);
39
39
  const [pickerAutofocus, setPickerAutofocus] = useState(false);
40
40
  const localRef = useRef(null);
@@ -138,7 +138,7 @@ export const FieldDate = forwardRef((_a, ref) => {
138
138
  : {
139
139
  open: showDropList,
140
140
  onOpenChange: setIsOpen,
141
- }), { content: _jsx("div", { className: styles.calendarWrapper, "data-size": size, children: _jsx(Calendar, { mode: 'date', size: CALENDAR_SIZE_MAP[size], value: valueProp ? parseDate(valueProp) : undefined, onChangeValue: handleSelectDate, navigationStartRef: element => {
141
+ }), { content: _jsx("div", { className: styles.calendarWrapper, "data-size": size, children: _jsx(Calendar, { mode: 'date', size: CALENDAR_SIZE_MAP[size], value: valueProp ? parseDate(valueProp) : undefined, onChangeValue: handleSelectDate, buildCellProps: buildCellProps, navigationStartRef: element => {
142
142
  if (pickerAutofocus) {
143
143
  element === null || element === void 0 ? void 0 : element.focus();
144
144
  setPickerAutofocus(false);
@@ -1 +1,2 @@
1
1
  export * from './FieldDate';
2
+ export { parseDate } from './utils';
@@ -1 +1,2 @@
1
1
  export * from './FieldDate';
2
+ export { parseDate } from './utils';
@@ -2,4 +2,8 @@ import { SlotKey } from './constants';
2
2
  export declare function getSlotKey(index: number | null): string | null;
3
3
  export declare function getNextSlotKey(slotKey: string | null): SlotKey.Month | SlotKey.Year;
4
4
  export declare function getPrevSlotKey(slotKey: string | null): SlotKey.Day | SlotKey.Month;
5
+ /**
6
+ * Преобразует строковое значение поля FieldDate в тип Date
7
+ * @function helper
8
+ */
5
9
  export declare function parseDate(date: string): Date;
@@ -33,6 +33,10 @@ export function getPrevSlotKey(slotKey) {
33
33
  }
34
34
  }
35
35
  }
36
+ /**
37
+ * Преобразует строковое значение поля FieldDate в тип Date
38
+ * @function helper
39
+ */
36
40
  export function parseDate(date) {
37
41
  const values = date.split('.');
38
42
  return new Date(Number(values[2]), Number(values[1]) - 1, Number(values[0]));
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Fields",
7
- "version": "0.11.6",
7
+ "version": "0.12.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -32,7 +32,7 @@
32
32
  "license": "Apache-2.0",
33
33
  "scripts": {},
34
34
  "dependencies": {
35
- "@snack-uikit/calendar": "0.6.3",
35
+ "@snack-uikit/calendar": "0.6.4",
36
36
  "@snack-uikit/droplist": "0.13.2",
37
37
  "@snack-uikit/icons": "0.20.0",
38
38
  "@snack-uikit/input-private": "3.0.3",
@@ -49,5 +49,5 @@
49
49
  "devDependencies": {
50
50
  "@types/merge-refs": "1.0.0"
51
51
  },
52
- "gitHead": "0726752996aeaf01f58b892fef581c38c1528ea1"
52
+ "gitHead": "0f69ec168f27621a8bd9a4336b85602d64c24072"
53
53
  }
@@ -69,7 +69,7 @@ type FieldDateOwnProps = {
69
69
  showClearButton?: boolean;
70
70
  /** Текущая локаль календаря */
71
71
  locale?: Intl.Locale;
72
- };
72
+ } & Pick<CalendarProps, 'buildCellProps'>;
73
73
 
74
74
  export type FieldDateProps = WithSupportProps<FieldDateOwnProps & InputProps & WrapperProps>;
75
75
 
@@ -104,6 +104,7 @@ export const FieldDate = forwardRef<HTMLInputElement, FieldDateProps>(
104
104
  size = SIZE.S,
105
105
  validationState = VALIDATION_STATE.Default,
106
106
  locale = DEFAULT_LOCALE,
107
+ buildCellProps,
107
108
  ...rest
108
109
  },
109
110
  ref,
@@ -279,6 +280,7 @@ export const FieldDate = forwardRef<HTMLInputElement, FieldDateProps>(
279
280
  size={CALENDAR_SIZE_MAP[size]}
280
281
  value={valueProp ? parseDate(valueProp) : undefined}
281
282
  onChangeValue={handleSelectDate}
283
+ buildCellProps={buildCellProps}
282
284
  navigationStartRef={element => {
283
285
  if (pickerAutofocus) {
284
286
  element?.focus();
@@ -1 +1,2 @@
1
1
  export * from './FieldDate';
2
+ export { parseDate } from './utils';
@@ -38,6 +38,11 @@ export function getPrevSlotKey(slotKey: string | null) {
38
38
  }
39
39
  }
40
40
 
41
+ /**
42
+ * Преобразует строковое значение поля FieldDate в тип Date
43
+ * @function helper
44
+ */
45
+
41
46
  export function parseDate(date: string) {
42
47
  const values = date.split('.');
43
48
  return new Date(Number(values[2]), Number(values[1]) - 1, Number(values[0]));