@gravity-ui/date-components 2.2.1 → 2.3.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.
@@ -61,5 +61,8 @@ function useRelativeDateFieldState(props) {
61
61
  }
62
62
  exports.useRelativeDateFieldState = useRelativeDateFieldState;
63
63
  function isLikeRelativeDate(text) {
64
+ if (typeof date_utils_1.isLikeRelative === 'function') {
65
+ return (0, date_utils_1.isLikeRelative)(text);
66
+ }
64
67
  return /^now/i.test(text);
65
68
  }
@@ -1,6 +1,7 @@
1
1
  import type { DateTime } from '@gravity-ui/date-utils';
2
2
  import type { Value } from '../RelativeDatePicker';
3
3
  import type { DomProps, InputBase, RangeValue, StyleProps, TextInputProps, Validation } from '../types';
4
+ import type { Preset } from './components/Presets/defaultPresets';
4
5
  import type { PresetTab } from './components/Presets/utils';
5
6
  import type { RelativeRangeDatePickerStateOptions } from './hooks/useRelativeRangeDatePickerState';
6
7
  import './RelativeRangeDatePicker.css';
@@ -17,6 +18,8 @@ export interface RelativeRangeDatePickerProps extends RelativeRangeDatePickerSta
17
18
  withPresets?: boolean;
18
19
  /** Custom preset tabs */
19
20
  presetTabs?: PresetTab[];
21
+ /** Custom docs for presets, if empty array docs will be hidden */
22
+ docs?: Preset[];
20
23
  /** Show selected relative values as absolute dates */
21
24
  alwaysShowAsAbsolute?: boolean;
22
25
  /** */
@@ -39,5 +39,5 @@ function DialogContent(props) {
39
39
  props.onApply();
40
40
  }, className: b('apply'), width: "max", children: (0, i18n_1.i18n)('Apply') })) : null, props.withPresets && !props.readOnly ? ((0, jsx_runtime_1.jsx)(Presets_1.Presets, { size: props.size, presetTabs: props.presetTabs, onChoosePreset: (start, end) => {
41
41
  state.setRange({ type: 'relative', value: start }, { type: 'relative', value: end });
42
- }, minValue: props.minValue })) : null, props.withZonesList ? ((0, jsx_runtime_1.jsx)("div", { className: b('zone'), children: (0, jsx_runtime_1.jsx)(Zones_1.Zones, { value: state.timeZone, onUpdate: state.setTimeZone, disabled: props.readOnly, size: props.size }) })) : null] }));
42
+ }, minValue: props.minValue, docs: props.docs })) : null, props.withZonesList ? ((0, jsx_runtime_1.jsx)("div", { className: b('zone'), children: (0, jsx_runtime_1.jsx)(Zones_1.Zones, { value: state.timeZone, onUpdate: state.setTimeZone, disabled: props.readOnly, size: props.size }) })) : null] }));
43
43
  }
@@ -1,4 +1,5 @@
1
1
  import type { DateTime } from '@gravity-ui/date-utils';
2
+ import type { Preset } from './defaultPresets';
2
3
  import type { PresetTab } from './utils';
3
4
  import './Presets.css';
4
5
  export interface PresetProps {
@@ -8,8 +9,9 @@ export interface PresetProps {
8
9
  minValue?: DateTime;
9
10
  size?: 's' | 'm' | 'l' | 'xl';
10
11
  presetTabs?: PresetTab[];
12
+ docs?: Preset[];
11
13
  }
12
- export declare function Presets({ className, size, minValue, withTime, onChoosePreset, presetTabs, }: PresetProps): import("react/jsx-runtime").JSX.Element | null;
14
+ export declare function Presets({ className, size, minValue, withTime, onChoosePreset, presetTabs, docs, }: PresetProps): import("react/jsx-runtime").JSX.Element | null;
13
15
  export declare const SIZE_TO_ITEM_HEIGHT: {
14
16
  s: number;
15
17
  m: number;
@@ -10,7 +10,7 @@ const PresetsDoc_1 = require("./PresetsDoc");
10
10
  const utils_1 = require("./utils");
11
11
  require("./Presets.css");
12
12
  const b = (0, cn_1.block)('relative-range-date-picker-presets');
13
- function Presets({ className, size = 'm', minValue, withTime, onChoosePreset, presetTabs, }) {
13
+ function Presets({ className, size = 'm', minValue, withTime, onChoosePreset, presetTabs, docs, }) {
14
14
  var _a, _b;
15
15
  const tabs = react_1.default.useMemo(() => {
16
16
  return (0, utils_1.filterPresetTabs)(presetTabs !== null && presetTabs !== void 0 ? presetTabs : (0, utils_1.getDefaultPresetTabs)({ withTime }), { minValue });
@@ -26,7 +26,7 @@ function Presets({ className, size = 'm', minValue, withTime, onChoosePreset, pr
26
26
  if (activeTab.id !== activeTabId) {
27
27
  setActiveTab(activeTab.id);
28
28
  }
29
- return ((0, jsx_runtime_1.jsxs)("div", { className: b({ size }, className), children: [(0, jsx_runtime_1.jsxs)("div", { className: b('tabs'), children: [(0, jsx_runtime_1.jsx)(uikit_1.Tabs, { activeTab: activeTabId, onSelectTab: setActiveTab, items: tabs, size: size === 's' ? 'm' : size }), (0, jsx_runtime_1.jsx)(PresetsDoc_1.PresetsDoc, { className: b('doc'), size: size })] }), (0, jsx_runtime_1.jsx)("div", { className: b('content'), children: (0, jsx_runtime_1.jsx)(PresetsList, { presets: activeTab.presets, onChoosePreset: onChoosePreset, size: size }) })] }));
29
+ return ((0, jsx_runtime_1.jsxs)("div", { className: b({ size }, className), children: [(0, jsx_runtime_1.jsxs)("div", { className: b('tabs'), children: [(0, jsx_runtime_1.jsx)(uikit_1.Tabs, { activeTab: activeTabId, onSelectTab: setActiveTab, items: tabs, size: size === 's' ? 'm' : size }), (0, jsx_runtime_1.jsx)(PresetsDoc_1.PresetsDoc, { className: b('doc'), size: size, docs: docs })] }), (0, jsx_runtime_1.jsx)("div", { className: b('content'), children: (0, jsx_runtime_1.jsx)(PresetsList, { presets: activeTab.presets, onChoosePreset: onChoosePreset, size: size }) })] }));
30
30
  }
31
31
  exports.Presets = Presets;
32
32
  exports.SIZE_TO_ITEM_HEIGHT = {
@@ -1,7 +1,9 @@
1
+ import type { Preset } from './defaultPresets';
1
2
  import './PresetsDoc.css';
2
3
  interface PresetsDocProps {
3
4
  className?: string;
4
5
  size?: 's' | 'm' | 'l' | 'xl';
6
+ docs?: Preset[];
5
7
  }
6
- export declare function PresetsDoc({ className, size }: PresetsDocProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare function PresetsDoc({ className, size, docs }: PresetsDocProps): import("react/jsx-runtime").JSX.Element | null;
7
9
  export {};
@@ -68,23 +68,26 @@ const data = [
68
68
  to: 'now - 1M/M',
69
69
  },
70
70
  ];
71
- function PresetsExamples({ size }) {
72
- return (0, jsx_runtime_1.jsx)(uikit_1.Table, { columns: columns, data: data, className: b('table', { size }) });
71
+ function PresetsExamples({ size, docs }) {
72
+ return (0, jsx_runtime_1.jsx)(uikit_1.Table, { columns: columns, data: docs, className: b('table', { size }) });
73
73
  }
74
- function DesktopDoc({ className, size }) {
75
- return ((0, jsx_runtime_1.jsx)(uikit_1.Popover, { className: b(null, className), tooltipContentClassName: b('content'), hasArrow: false, content: (0, jsx_runtime_1.jsx)(PresetsExamples, { size: size }), children: (0, jsx_runtime_1.jsx)(uikit_1.Button, { className: b('button'), view: "flat-secondary", size: (0, getButtonSizeForInput_1.getButtonSizeForInput)(size), children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.CircleQuestion }) }) }));
74
+ function DesktopDoc({ className, size, docs }) {
75
+ return ((0, jsx_runtime_1.jsx)(uikit_1.Popover, { className: b(null, className), tooltipContentClassName: b('content'), hasArrow: false, content: (0, jsx_runtime_1.jsx)(PresetsExamples, { size: size, docs: docs }), children: (0, jsx_runtime_1.jsx)(uikit_1.Button, { className: b('button'), view: "flat-secondary", size: (0, getButtonSizeForInput_1.getButtonSizeForInput)(size), children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.CircleQuestion }) }) }));
76
76
  }
77
- function MobileDoc({ className, size }) {
77
+ function MobileDoc({ className, size, docs }) {
78
78
  const [open, setOpen] = react_1.default.useState(false);
79
79
  return ((0, jsx_runtime_1.jsxs)("div", { className: b(null, className), children: [(0, jsx_runtime_1.jsx)(uikit_1.Button, { className: b('button'), view: "flat-secondary", size: "l", onClick: () => {
80
80
  setOpen(true);
81
- }, children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.CircleQuestion }) }), (0, jsx_runtime_1.jsx)(uikit_1.Sheet, { visible: open, onClose: () => setOpen(false), children: (0, jsx_runtime_1.jsx)(PresetsExamples, { size: size }) })] }));
81
+ }, children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.CircleQuestion }) }), (0, jsx_runtime_1.jsx)(uikit_1.Sheet, { visible: open, onClose: () => setOpen(false), children: (0, jsx_runtime_1.jsx)(PresetsExamples, { size: size, docs: docs }) })] }));
82
82
  }
83
- function PresetsDoc({ className, size }) {
83
+ function PresetsDoc({ className, size, docs = data }) {
84
84
  const isMobile = (0, uikit_1.useMobile)();
85
+ if (!Array.isArray(docs) || docs.length === 0) {
86
+ return null;
87
+ }
85
88
  if (isMobile) {
86
- return (0, jsx_runtime_1.jsx)(MobileDoc, { className: className, size: size });
89
+ return (0, jsx_runtime_1.jsx)(MobileDoc, { className: className, size: size, docs: docs });
87
90
  }
88
- return (0, jsx_runtime_1.jsx)(DesktopDoc, { className: className, size: size });
91
+ return (0, jsx_runtime_1.jsx)(DesktopDoc, { className: className, size: size, docs: docs });
89
92
  }
90
93
  exports.PresetsDoc = PresetsDoc;
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
- import { dateTimeParse, isValid } from '@gravity-ui/date-utils';
2
+ import { dateTimeParse,
3
+ // @ts-expect-error added in new version of date-utils
4
+ isLikeRelative, isValid, } from '@gravity-ui/date-utils';
3
5
  import { useControlledState } from '@gravity-ui/uikit';
4
6
  export function useRelativeDateFieldState(props) {
5
7
  var _a;
@@ -56,5 +58,8 @@ export function useRelativeDateFieldState(props) {
56
58
  };
57
59
  }
58
60
  function isLikeRelativeDate(text) {
61
+ if (typeof isLikeRelative === 'function') {
62
+ return isLikeRelative(text);
63
+ }
59
64
  return /^now/i.test(text);
60
65
  }
@@ -1,6 +1,7 @@
1
1
  import type { DateTime } from '@gravity-ui/date-utils';
2
2
  import type { Value } from '../RelativeDatePicker';
3
3
  import type { DomProps, InputBase, RangeValue, StyleProps, TextInputProps, Validation } from '../types';
4
+ import type { Preset } from './components/Presets/defaultPresets';
4
5
  import type { PresetTab } from './components/Presets/utils';
5
6
  import type { RelativeRangeDatePickerStateOptions } from './hooks/useRelativeRangeDatePickerState';
6
7
  import './RelativeRangeDatePicker.css';
@@ -17,6 +18,8 @@ export interface RelativeRangeDatePickerProps extends RelativeRangeDatePickerSta
17
18
  withPresets?: boolean;
18
19
  /** Custom preset tabs */
19
20
  presetTabs?: PresetTab[];
21
+ /** Custom docs for presets, if empty array docs will be hidden */
22
+ docs?: Preset[];
20
23
  /** Show selected relative values as absolute dates */
21
24
  alwaysShowAsAbsolute?: boolean;
22
25
  /** */
@@ -35,5 +35,5 @@ function DialogContent(props) {
35
35
  props.onApply();
36
36
  }, className: b('apply'), width: "max", children: i18n('Apply') })) : null, props.withPresets && !props.readOnly ? (_jsx(Presets, { size: props.size, presetTabs: props.presetTabs, onChoosePreset: (start, end) => {
37
37
  state.setRange({ type: 'relative', value: start }, { type: 'relative', value: end });
38
- }, minValue: props.minValue })) : null, props.withZonesList ? (_jsx("div", { className: b('zone'), children: _jsx(Zones, { value: state.timeZone, onUpdate: state.setTimeZone, disabled: props.readOnly, size: props.size }) })) : null] }));
38
+ }, minValue: props.minValue, docs: props.docs })) : null, props.withZonesList ? (_jsx("div", { className: b('zone'), children: _jsx(Zones, { value: state.timeZone, onUpdate: state.setTimeZone, disabled: props.readOnly, size: props.size }) })) : null] }));
39
39
  }
@@ -1,4 +1,5 @@
1
1
  import type { DateTime } from '@gravity-ui/date-utils';
2
+ import type { Preset } from './defaultPresets';
2
3
  import type { PresetTab } from './utils';
3
4
  import './Presets.css';
4
5
  export interface PresetProps {
@@ -8,8 +9,9 @@ export interface PresetProps {
8
9
  minValue?: DateTime;
9
10
  size?: 's' | 'm' | 'l' | 'xl';
10
11
  presetTabs?: PresetTab[];
12
+ docs?: Preset[];
11
13
  }
12
- export declare function Presets({ className, size, minValue, withTime, onChoosePreset, presetTabs, }: PresetProps): import("react/jsx-runtime").JSX.Element | null;
14
+ export declare function Presets({ className, size, minValue, withTime, onChoosePreset, presetTabs, docs, }: PresetProps): import("react/jsx-runtime").JSX.Element | null;
13
15
  export declare const SIZE_TO_ITEM_HEIGHT: {
14
16
  s: number;
15
17
  m: number;
@@ -6,7 +6,7 @@ import { PresetsDoc } from './PresetsDoc';
6
6
  import { filterPresetTabs, getDefaultPresetTabs } from './utils';
7
7
  import './Presets.css';
8
8
  const b = block('relative-range-date-picker-presets');
9
- export function Presets({ className, size = 'm', minValue, withTime, onChoosePreset, presetTabs, }) {
9
+ export function Presets({ className, size = 'm', minValue, withTime, onChoosePreset, presetTabs, docs, }) {
10
10
  var _a, _b;
11
11
  const tabs = React.useMemo(() => {
12
12
  return filterPresetTabs(presetTabs !== null && presetTabs !== void 0 ? presetTabs : getDefaultPresetTabs({ withTime }), { minValue });
@@ -22,7 +22,7 @@ export function Presets({ className, size = 'm', minValue, withTime, onChoosePre
22
22
  if (activeTab.id !== activeTabId) {
23
23
  setActiveTab(activeTab.id);
24
24
  }
25
- return (_jsxs("div", { className: b({ size }, className), children: [_jsxs("div", { className: b('tabs'), children: [_jsx(Tabs, { activeTab: activeTabId, onSelectTab: setActiveTab, items: tabs, size: size === 's' ? 'm' : size }), _jsx(PresetsDoc, { className: b('doc'), size: size })] }), _jsx("div", { className: b('content'), children: _jsx(PresetsList, { presets: activeTab.presets, onChoosePreset: onChoosePreset, size: size }) })] }));
25
+ return (_jsxs("div", { className: b({ size }, className), children: [_jsxs("div", { className: b('tabs'), children: [_jsx(Tabs, { activeTab: activeTabId, onSelectTab: setActiveTab, items: tabs, size: size === 's' ? 'm' : size }), _jsx(PresetsDoc, { className: b('doc'), size: size, docs: docs })] }), _jsx("div", { className: b('content'), children: _jsx(PresetsList, { presets: activeTab.presets, onChoosePreset: onChoosePreset, size: size }) })] }));
26
26
  }
27
27
  export const SIZE_TO_ITEM_HEIGHT = {
28
28
  s: 28,
@@ -1,7 +1,9 @@
1
+ import type { Preset } from './defaultPresets';
1
2
  import './PresetsDoc.css';
2
3
  interface PresetsDocProps {
3
4
  className?: string;
4
5
  size?: 's' | 'm' | 'l' | 'xl';
6
+ docs?: Preset[];
5
7
  }
6
- export declare function PresetsDoc({ className, size }: PresetsDocProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare function PresetsDoc({ className, size, docs }: PresetsDocProps): import("react/jsx-runtime").JSX.Element | null;
7
9
  export {};
@@ -64,22 +64,25 @@ const data = [
64
64
  to: 'now - 1M/M',
65
65
  },
66
66
  ];
67
- function PresetsExamples({ size }) {
68
- return _jsx(Table, { columns: columns, data: data, className: b('table', { size }) });
67
+ function PresetsExamples({ size, docs }) {
68
+ return _jsx(Table, { columns: columns, data: docs, className: b('table', { size }) });
69
69
  }
70
- function DesktopDoc({ className, size }) {
71
- return (_jsx(Popover, { className: b(null, className), tooltipContentClassName: b('content'), hasArrow: false, content: _jsx(PresetsExamples, { size: size }), children: _jsx(Button, { className: b('button'), view: "flat-secondary", size: getButtonSizeForInput(size), children: _jsx(Icon, { data: CircleQuestion }) }) }));
70
+ function DesktopDoc({ className, size, docs }) {
71
+ return (_jsx(Popover, { className: b(null, className), tooltipContentClassName: b('content'), hasArrow: false, content: _jsx(PresetsExamples, { size: size, docs: docs }), children: _jsx(Button, { className: b('button'), view: "flat-secondary", size: getButtonSizeForInput(size), children: _jsx(Icon, { data: CircleQuestion }) }) }));
72
72
  }
73
- function MobileDoc({ className, size }) {
73
+ function MobileDoc({ className, size, docs }) {
74
74
  const [open, setOpen] = React.useState(false);
75
75
  return (_jsxs("div", { className: b(null, className), children: [_jsx(Button, { className: b('button'), view: "flat-secondary", size: "l", onClick: () => {
76
76
  setOpen(true);
77
- }, children: _jsx(Icon, { data: CircleQuestion }) }), _jsx(Sheet, { visible: open, onClose: () => setOpen(false), children: _jsx(PresetsExamples, { size: size }) })] }));
77
+ }, children: _jsx(Icon, { data: CircleQuestion }) }), _jsx(Sheet, { visible: open, onClose: () => setOpen(false), children: _jsx(PresetsExamples, { size: size, docs: docs }) })] }));
78
78
  }
79
- export function PresetsDoc({ className, size }) {
79
+ export function PresetsDoc({ className, size, docs = data }) {
80
80
  const isMobile = useMobile();
81
+ if (!Array.isArray(docs) || docs.length === 0) {
82
+ return null;
83
+ }
81
84
  if (isMobile) {
82
- return _jsx(MobileDoc, { className: className, size: size });
85
+ return _jsx(MobileDoc, { className: className, size: size, docs: docs });
83
86
  }
84
- return _jsx(DesktopDoc, { className: className, size: size });
87
+ return _jsx(DesktopDoc, { className: className, size: size, docs: docs });
85
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/date-components",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",