chili-ui 0.3.1 → 0.4.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.
Files changed (101) hide show
  1. package/chili/components/DatePicker/handlers.ts +17 -0
  2. package/chili/components/DatePicker/index.tsx +27 -8
  3. package/chili/components/DatePicker/types.ts +2 -0
  4. package/chili/components/DateRange/handlers.ts +19 -0
  5. package/chili/components/DateRange/index.tsx +27 -8
  6. package/chili/components/DateRange/types.ts +2 -0
  7. package/chili/components/DateTimePicker/handlers.ts +19 -0
  8. package/chili/components/DateTimePicker/index.tsx +27 -8
  9. package/chili/components/DateTimePicker/types.ts +2 -0
  10. package/chili/components/DateTimeRange/handlers.ts +19 -0
  11. package/chili/components/DateTimeRange/index.tsx +27 -8
  12. package/chili/components/DateTimeRange/types.ts +2 -0
  13. package/chili/components/DropDownSelect/types.ts +1 -0
  14. package/chili/components/Icon/icons.tsx +5 -0
  15. package/chili/components/Icon/types.ts +1 -0
  16. package/chili/components/MaskedInput/__snapshots__/MaskedInput.test.tsx.snap +4 -0
  17. package/chili/components/MaskedInput/index.tsx +2 -0
  18. package/chili/components/MaskedInput/types.ts +2 -0
  19. package/chili/components/NumericTextBox/types.ts +2 -0
  20. package/chili/src/DateTimeInput/handlers/handleReset.ts +18 -6
  21. package/chili/src/DateTimeInput/hooks.ts +19 -5
  22. package/chili/src/DateTimeInput/types.ts +2 -0
  23. package/chili/src/DateTimeInputRange/helpers.ts +6 -4
  24. package/chili/src/DateTimeInputRange/index.tsx +3 -0
  25. package/chili/src/DateTimeInputRange/types.ts +2 -0
  26. package/chili/src/MaskedInputBase/index.tsx +2 -0
  27. package/chili/src/MaskedInputBase/types.ts +1 -0
  28. package/dist/components/DatePicker/handlers.d.ts +4 -0
  29. package/dist/components/DatePicker/handlers.js +11 -0
  30. package/dist/components/DatePicker/handlers.js.map +1 -0
  31. package/dist/components/DatePicker/index.js +20 -1
  32. package/dist/components/DatePicker/index.js.map +1 -1
  33. package/dist/components/DatePicker/types.d.ts +2 -0
  34. package/dist/components/DateRange/handlers.d.ts +4 -0
  35. package/dist/components/DateRange/handlers.js +10 -0
  36. package/dist/components/DateRange/handlers.js.map +1 -0
  37. package/dist/components/DateRange/index.js +20 -1
  38. package/dist/components/DateRange/index.js.map +1 -1
  39. package/dist/components/DateRange/types.d.ts +2 -0
  40. package/dist/components/DateTimePicker/handlers.d.ts +4 -0
  41. package/dist/components/DateTimePicker/handlers.js +11 -0
  42. package/dist/components/DateTimePicker/handlers.js.map +1 -0
  43. package/dist/components/DateTimePicker/index.js +20 -1
  44. package/dist/components/DateTimePicker/index.js.map +1 -1
  45. package/dist/components/DateTimePicker/types.d.ts +2 -0
  46. package/dist/components/DateTimeRange/handlers.d.ts +4 -0
  47. package/dist/components/DateTimeRange/handlers.js +10 -0
  48. package/dist/components/DateTimeRange/handlers.js.map +1 -0
  49. package/dist/components/DateTimeRange/index.js +20 -1
  50. package/dist/components/DateTimeRange/index.js.map +1 -1
  51. package/dist/components/DateTimeRange/types.d.ts +2 -0
  52. package/dist/components/DropDownSelect/types.d.ts +1 -0
  53. package/dist/components/Icon/icons.js +5 -0
  54. package/dist/components/Icon/icons.js.map +1 -1
  55. package/dist/components/Icon/types.d.ts +1 -0
  56. package/dist/components/Icon/types.js +1 -0
  57. package/dist/components/Icon/types.js.map +1 -1
  58. package/dist/components/MaskedInput/index.js +3 -3
  59. package/dist/components/MaskedInput/index.js.map +1 -1
  60. package/dist/components/MaskedInput/types.d.ts +2 -0
  61. package/dist/components/NumericTextBox/types.d.ts +2 -0
  62. package/dist/src/DateTimeInput/handlers/handleReset.js +20 -6
  63. package/dist/src/DateTimeInput/handlers/handleReset.js.map +1 -1
  64. package/dist/src/DateTimeInput/hooks.js +20 -5
  65. package/dist/src/DateTimeInput/hooks.js.map +1 -1
  66. package/dist/src/DateTimeInput/types.d.ts +2 -0
  67. package/dist/src/DateTimeInputRange/helpers.js +6 -5
  68. package/dist/src/DateTimeInputRange/helpers.js.map +1 -1
  69. package/dist/src/DateTimeInputRange/index.js +3 -3
  70. package/dist/src/DateTimeInputRange/index.js.map +1 -1
  71. package/dist/src/DateTimeInputRange/types.d.ts +2 -0
  72. package/dist/src/MaskedInputBase/index.js +2 -2
  73. package/dist/src/MaskedInputBase/index.js.map +1 -1
  74. package/dist/src/MaskedInputBase/types.d.ts +1 -0
  75. package/dist/styles/chili.base.css +1 -1
  76. package/docs/public/chili_pepper.png +0 -0
  77. package/docs/public/favicon.ico +0 -0
  78. package/docs/src/app/BaseLayout.tsx +22 -20
  79. package/docs/src/app/form-components/date-picker/_demo/DefaultValue.tsx +35 -0
  80. package/docs/src/app/form-components/date-picker/page.tsx +9 -0
  81. package/docs/src/app/form-components/date-range/_demo/DefaultValue.tsx +33 -0
  82. package/docs/src/app/form-components/date-range/page.tsx +9 -0
  83. package/docs/src/app/form-components/date-time-picker/_demo/DefaultValue.tsx +33 -0
  84. package/docs/src/app/form-components/date-time-picker/page.tsx +9 -0
  85. package/docs/src/app/form-components/date-time-range/_demo/DefaultValue.tsx +33 -0
  86. package/docs/src/app/form-components/date-time-range/page.tsx +10 -1
  87. package/docs/src/app/form-components/dropdown-select/page.tsx +8 -3
  88. package/docs/src/app/form-components/masked-input/page.tsx +18 -1
  89. package/docs/src/app/form-components/numeric-text-box/page.tsx +5 -0
  90. package/docs/src/app/globals.css +16 -1
  91. package/docs/src/app/layout-components/icon/page.tsx +1 -1
  92. package/docs/src/app/layout.tsx +3 -5
  93. package/docs/src/app/other/chili-provider/page.tsx +1 -1
  94. package/docs/src/components/header/MenuButton/index.tsx +6 -6
  95. package/docs/src/components/header/index.tsx +22 -21
  96. package/docs/src/components/live/DatesLive.tsx +22 -1
  97. package/docs/src/components/live/index.tsx +22 -1
  98. package/docs/src/components/nav/NavLi.tsx +1 -1
  99. package/docs/src/components/typography/A.tsx +1 -1
  100. package/package.json +1 -1
  101. package/public/favicon.jpg +0 -0
@@ -0,0 +1,17 @@
1
+ import { isFunction } from 'lodash';
2
+ import type { SetState } from '../../commonTypes';
3
+ import type { DatePickerProps } from './types';
4
+ import type { ChangeEvent } from '../../src/DateTimeInput/types';
5
+
6
+ export const createChangeHandler = (
7
+ props: DatePickerProps,
8
+ setUncontrolledValue: SetState<string | Date | null>,
9
+ ) => (ev: ChangeEvent): void => {
10
+ const { onChange, value } = props;
11
+
12
+ if (value === undefined) {
13
+ setUncontrolledValue(ev.component.date ?? ev.component.value);
14
+ }
15
+
16
+ if (isFunction(onChange)) onChange(ev);
17
+ };
@@ -4,14 +4,33 @@ import * as React from 'react';
4
4
  import { DateTimeInput } from '../../src/DateTimeInput';
5
5
  import { COMPONENT_TYPES } from '../../src/DateTimeInput/constants';
6
6
  import type { DatePickerProps } from './types';
7
+ import { useValue, useProps } from '../../utils';
8
+ import { createChangeHandler } from './handlers';
7
9
 
8
- export const DatePicker = React.forwardRef((props: DatePickerProps, ref: React.Ref<HTMLElement>) => (
9
- <DateTimeInput
10
- {...props}
11
- format={props.format || 'dd.MM.yyyy'}
12
- type={COMPONENT_TYPES.DATE_ONLY}
13
- ref={ref}
14
- />
15
- )) as React.FC<DatePickerProps>;
10
+ export const DatePicker = React.forwardRef((rawProps: DatePickerProps, ref: React.Ref<HTMLElement>) => {
11
+ const props = useProps(rawProps);
12
+
13
+ const {
14
+ defaultValue = null,
15
+ value: valueProp,
16
+ ...restProps
17
+ } = props;
18
+
19
+ const [value, setUncontrolledValue] = useValue<string | Date | null>(valueProp, defaultValue);
20
+
21
+ const handleChange = createChangeHandler(props, setUncontrolledValue);
22
+
23
+ return (
24
+ <DateTimeInput
25
+ {...restProps}
26
+ defaultValue={defaultValue}
27
+ value={value}
28
+ onChange={handleChange}
29
+ format={props.format || 'dd.MM.yyyy'}
30
+ type={COMPONENT_TYPES.DATE_ONLY}
31
+ ref={ref}
32
+ />
33
+ );
34
+ }) as React.FC<DatePickerProps>;
16
35
 
17
36
  DatePicker.displayName = 'DatePicker';
@@ -9,6 +9,8 @@ import type {
9
9
  import type { PartialGlobalDefaultTheme } from '../../utils/useTheme';
10
10
 
11
11
  export interface DatePickerProps extends DateTimeInputProps {
12
+ /** Default value */
13
+ defaultValue?: string | Date | null,
12
14
  /** Date format, dd.MM.yyyy by default */
13
15
  format?: string,
14
16
  /** Control opened state */
@@ -0,0 +1,19 @@
1
+ import { isFunction } from 'lodash';
2
+ import type { SetState } from '../../commonTypes';
3
+ import type { DateRangeProps } from './types';
4
+ import type {
5
+ CustomRangeEvent,
6
+ } from '../../src/DateTimeInputRange/types';
7
+
8
+ export const createChangeHandler = (
9
+ props: DateRangeProps,
10
+ setUncontrolledValue: SetState<DateRangeProps['value']>,
11
+ ) => (ev: CustomRangeEvent): void => {
12
+ const { onChange, value } = props;
13
+
14
+ if (value === undefined) {
15
+ setUncontrolledValue(ev.component.date);
16
+ }
17
+
18
+ if (isFunction(onChange)) onChange(ev);
19
+ };
@@ -3,15 +3,34 @@
3
3
  import * as React from 'react';
4
4
  import { COMPONENT_TYPES } from '../../src/DateTimeInput/constants';
5
5
  import { DateTimeInputRange } from '../../src/DateTimeInputRange';
6
+ import { useProps, useValue } from '../../utils';
6
7
  import type { DateRangeProps } from './types';
8
+ import { createChangeHandler } from './handlers';
7
9
 
8
- export const DateRange = React.forwardRef((props: DateRangeProps, ref: React.Ref<HTMLElement>) => (
9
- <DateTimeInputRange
10
- {...props}
11
- type={COMPONENT_TYPES.DATE_ONLY}
12
- format={props.format || 'dd.MM.yyyy'}
13
- ref={ref}
14
- />
15
- )) as React.FC<DateRangeProps>;
10
+ export const DateRange = React.forwardRef((rawProps: DateRangeProps, ref: React.Ref<HTMLElement>) => {
11
+ const props = useProps(rawProps);
12
+
13
+ const {
14
+ defaultValue = [null, null],
15
+ value: valueProp,
16
+ ...restProps
17
+ } = props;
18
+
19
+ const [value, setUncontrolledValue] = useValue<DateRangeProps['value']>(valueProp, defaultValue);
20
+
21
+ const handleChange = createChangeHandler(props, setUncontrolledValue);
22
+
23
+ return (
24
+ <DateTimeInputRange
25
+ {...restProps}
26
+ type={COMPONENT_TYPES.DATE_ONLY}
27
+ format={props.format || 'dd.MM.yyyy'}
28
+ defaultValue={defaultValue}
29
+ value={value}
30
+ onChange={handleChange}
31
+ ref={ref}
32
+ />
33
+ );
34
+ }) as React.FC<DateRangeProps>;
16
35
 
17
36
  DateRange.displayName = 'DateRange';
@@ -7,6 +7,8 @@ import type {
7
7
  } from '../../src/DateTimeInputRange/types';
8
8
 
9
9
  export interface DateRangeProps extends DateTimeInputRangeProps {
10
+ /** Default value */
11
+ defaultValue?: [string, string] | [Date | null, Date | null],
10
12
  /** Date format, dd.MM.yyyy by default */
11
13
  format?: string,
12
14
  /** Disabled input state */
@@ -0,0 +1,19 @@
1
+ import { isFunction } from 'lodash';
2
+ import type { SetState } from '../../commonTypes';
3
+ import type { DateTimePickerProps } from './types';
4
+ import type {
5
+ ChangeEvent,
6
+ } from '../../src/DateTimeInput/types';
7
+
8
+ export const createChangeHandler = (
9
+ props: DateTimePickerProps,
10
+ setUncontrolledValue: SetState<string | Date | null>,
11
+ ) => (ev: ChangeEvent): void => {
12
+ const { onChange, value } = props;
13
+
14
+ if (value === undefined) {
15
+ setUncontrolledValue(ev.component.date ?? ev.component.value);
16
+ }
17
+
18
+ if (isFunction(onChange)) onChange(ev);
19
+ };
@@ -3,15 +3,34 @@
3
3
  import * as React from 'react';
4
4
  import { DateTimeInput } from '../../src/DateTimeInput';
5
5
  import { COMPONENT_TYPES } from '../../src/DateTimeInput/constants';
6
+ import { useProps, useValue } from '../../utils';
6
7
  import type { DateTimePickerProps } from './types';
8
+ import { createChangeHandler } from './handlers';
7
9
 
8
- export const DateTimePicker = React.forwardRef((props: DateTimePickerProps, ref: React.Ref<HTMLElement>) => (
9
- <DateTimeInput
10
- {...props}
11
- format={props.format || 'dd.MM.yyyy hh:mm'}
12
- ref={ref}
13
- type={COMPONENT_TYPES.DATE_TIME}
14
- />
15
- )) as React.FC<DateTimePickerProps>;
10
+ export const DateTimePicker = React.forwardRef((rawProps: DateTimePickerProps, ref: React.Ref<HTMLElement>) => {
11
+ const props = useProps(rawProps);
12
+
13
+ const {
14
+ defaultValue = null,
15
+ value: valueProp,
16
+ ...restProps
17
+ } = props;
18
+
19
+ const [value, setUncontrolledValue] = useValue<string | Date | null>(valueProp, defaultValue);
20
+
21
+ const handleChange = createChangeHandler(props, setUncontrolledValue);
22
+
23
+ return (
24
+ <DateTimeInput
25
+ {...restProps}
26
+ format={props.format || 'dd.MM.yyyy hh:mm'}
27
+ defaultValue={defaultValue}
28
+ value={value}
29
+ onChange={handleChange}
30
+ ref={ref}
31
+ type={COMPONENT_TYPES.DATE_TIME}
32
+ />
33
+ );
34
+ }) as React.FC<DateTimePickerProps>;
16
35
 
17
36
  DateTimePicker.displayName = 'DateTimePicker';
@@ -4,6 +4,8 @@ import type {
4
4
  } from '../../src/DateTimeInput/types';
5
5
 
6
6
  export interface DateTimePickerProps extends DateTimeInputProps {
7
+ /** Default value */
8
+ defaultValue?: string | Date | null,
7
9
  /** Date format, dd.MM.yyyy hh:mm by default */
8
10
  format?: string,
9
11
  /** Control opened state */
@@ -0,0 +1,19 @@
1
+ import { isFunction } from 'lodash';
2
+ import type { SetState } from '../../commonTypes';
3
+ import type { DateTimeRangeProps } from './types';
4
+ import type {
5
+ CustomRangeEvent,
6
+ } from '../../src/DateTimeInputRange/types';
7
+
8
+ export const createChangeHandler = (
9
+ props: DateTimeRangeProps,
10
+ setUncontrolledValue: SetState<DateTimeRangeProps['value']>,
11
+ ) => (ev: CustomRangeEvent): void => {
12
+ const { onChange, value } = props;
13
+
14
+ if (value === undefined) {
15
+ setUncontrolledValue(ev.component.date);
16
+ }
17
+
18
+ if (isFunction(onChange)) onChange(ev);
19
+ };
@@ -3,15 +3,34 @@
3
3
  import * as React from 'react';
4
4
  import { DateTimeInputRange } from '../../src/DateTimeInputRange';
5
5
  import { COMPONENT_TYPES } from '../../src/DateTimeInput/constants';
6
+ import { useProps, useValue } from '../../utils';
6
7
  import type { DateTimeRangeProps } from './types';
8
+ import { createChangeHandler } from './handlers';
7
9
 
8
- export const DateTimeRange = React.forwardRef((props: DateTimeRangeProps, ref: React.Ref<HTMLElement>) => (
9
- <DateTimeInputRange
10
- {...props}
11
- type={COMPONENT_TYPES.DATE_TIME}
12
- format={props.format || 'dd.MM.yyyy hh:mm'}
13
- ref={ref}
14
- />
15
- )) as React.FC<DateTimeRangeProps>;
10
+ export const DateTimeRange = React.forwardRef((rawProps: DateTimeRangeProps, ref: React.Ref<HTMLElement>) => {
11
+ const props = useProps(rawProps);
12
+
13
+ const {
14
+ defaultValue = [null, null],
15
+ value: valueProp,
16
+ ...restProps
17
+ } = props;
18
+
19
+ const [value, setUncontrolledValue] = useValue<DateTimeRangeProps['value']>(valueProp, defaultValue);
20
+
21
+ const handleChange = createChangeHandler(props, setUncontrolledValue);
22
+
23
+ return (
24
+ <DateTimeInputRange
25
+ {...restProps}
26
+ type={COMPONENT_TYPES.DATE_TIME}
27
+ format={props.format || 'dd.MM.yyyy hh:mm'}
28
+ defaultValue={defaultValue}
29
+ value={value}
30
+ onChange={handleChange}
31
+ ref={ref}
32
+ />
33
+ );
34
+ }) as React.FC<DateTimeRangeProps>;
16
35
 
17
36
  DateTimeRange.displayName = 'DateTimeRange';
@@ -7,6 +7,8 @@ import type {
7
7
  } from '../../src/DateTimeInputRange/types';
8
8
 
9
9
  export interface DateTimeRangeProps extends DateTimeInputRangeProps {
10
+ /** Default value */
11
+ defaultValue?: [string, string] | [Date | null, Date | null],
10
12
  /** Date format, dd.MM.yyyy hh:mm by default */
11
13
  format?: string,
12
14
  /** Disabled input state */
@@ -57,6 +57,7 @@ export interface FocusEvent<T extends Value = Value> extends React.FocusEvent<HT
57
57
  }
58
58
 
59
59
  export interface DropDownSelectProps<T extends Value = Value> extends ValidationProps {
60
+ /** Browser autofill, off is the default value. Works as HTML autoComplete attribute */
60
61
  autoComplete?: string,
61
62
  boundingContainerRef?: React.RefObject<HTMLElement>,
62
63
  compareObjectsBy?: T extends object ? ((suggestionListItem: T) => unknown) | string : never,
@@ -71,6 +71,11 @@ export const ICON_PATHS: Record<Icons, React.ReactNode[]> = {
71
71
  [Icons.Star]: [
72
72
  <polygon key="0" points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />,
73
73
  ],
74
+ [Icons.Menu]: [
75
+ <line key="0" x1="3" y1="12" x2="21" y2="12" />,
76
+ <line key="1" x1="3" y1="6" x2="21" y2="6" />,
77
+ <line key="2" x1="3" y1="18" x2="21" y2="18" />,
78
+ ],
74
79
  [Icons.X]: [
75
80
  <line key="0" x1="18" y1="6" x2="6" y2="18" />,
76
81
  <line key="1" x1="6" y1="6" x2="18" y2="18" />,
@@ -31,5 +31,6 @@ export enum Icons {
31
31
  PlusSquare = 'plus-square',
32
32
  Square = 'square',
33
33
  Star = 'star',
34
+ Menu = 'menu',
34
35
  X = 'x',
35
36
  }
@@ -23,6 +23,7 @@ exports[`MaskedInput SNAPSHOTS should render different component states should r
23
23
  >
24
24
  <Input
25
25
  aria-invalid={false}
26
+ autoComplete="off"
26
27
  className="masked-input-element"
27
28
  disabled={true}
28
29
  mask="+# (###) ###-##-##"
@@ -45,6 +46,7 @@ exports[`MaskedInput SNAPSHOTS should render different component states should r
45
46
  >
46
47
  <input
47
48
  aria-invalid={false}
49
+ autoComplete="off"
48
50
  className="masked-input-element"
49
51
  disabled={true}
50
52
  maxLength={19}
@@ -99,6 +101,7 @@ exports[`MaskedInput SNAPSHOTS should render different component states should r
99
101
  >
100
102
  <Input
101
103
  aria-invalid={false}
104
+ autoComplete="off"
102
105
  className="masked-input-element"
103
106
  mask="+# (###) ###-##-##"
104
107
  onBlur={[Function]}
@@ -119,6 +122,7 @@ exports[`MaskedInput SNAPSHOTS should render different component states should r
119
122
  >
120
123
  <input
121
124
  aria-invalid={false}
125
+ autoComplete="off"
122
126
  className="masked-input-element"
123
127
  disabled={false}
124
128
  maxLength={19}
@@ -14,6 +14,7 @@ import { getValue, getValueToValidate } from './helpers';
14
14
 
15
15
  export const MaskedInput = React.forwardRef((props: MaskedInputProps, ref: React.Ref<HTMLElement>) => {
16
16
  const {
17
+ autoComplete = 'off',
17
18
  className,
18
19
  defaultValue,
19
20
  inputRender,
@@ -138,6 +139,7 @@ export const MaskedInput = React.forwardRef((props: MaskedInputProps, ref: React
138
139
  {...restProps}
139
140
  aria-invalid={!isValid}
140
141
  aria-required={isRequired}
142
+ autoComplete={autoComplete}
141
143
  className={theme.input}
142
144
  isDisabled={isDisabled}
143
145
  mask={mask}
@@ -23,6 +23,8 @@ export interface ResetEvent {
23
23
  export type ChangeEvent = BaseChangeEvent | ResetEvent;
24
24
 
25
25
  export interface MaskedInputProps extends ValidationProps {
26
+ /** Browser autofill, off is the default value. Works as HTML autoComplete attribute */
27
+ autoComplete?: string,
26
28
  /** Default value */
27
29
  defaultValue?: string,
28
30
  /** Input customizator. It replaces MaskedInputBase! */
@@ -115,6 +115,8 @@ export interface NumericTextBoxProps extends ValidationProps {
115
115
  onEnterPress?: (event: EnterPressEvent) => void,
116
116
  /** Focus handler */
117
117
  onFocus?: (event: FocusEvent) => void,
118
+ /** Placeholder */
119
+ placeholder?: string,
118
120
  /** Ref */
119
121
  ref?: React.Ref<HTMLElement>,
120
122
  /** To trim or not to trim */
@@ -1,7 +1,8 @@
1
1
  import type * as React from 'react';
2
- import { isFunction } from 'lodash';
2
+ import { isFunction, isDate } from 'lodash';
3
3
  import type { DateTimeInputProps, AllActions } from '../types';
4
4
  import { setDate, setValue } from '../actions';
5
+ import { stringToDate, formatDateTime } from '../helpers';
5
6
 
6
7
  export const createResetHandler = ({
7
8
  props,
@@ -10,14 +11,25 @@ export const createResetHandler = ({
10
11
  props: DateTimeInputProps,
11
12
  dispatch: React.Dispatch<AllActions>,
12
13
  }) => () => {
13
- const date = null;
14
- const value = '';
14
+ const { defaultValue, format = 'dd.MM.yyyy', name, onChange } = props;
15
+
16
+ const date = (() => {
17
+ if (isDate(defaultValue)) return defaultValue;
18
+ if (typeof defaultValue === 'string') return stringToDate(defaultValue, format);
19
+ return null;
20
+ })();
21
+
22
+ const value = (() => {
23
+ if (isDate(defaultValue)) return formatDateTime(defaultValue, format);
24
+ if (typeof defaultValue === 'string') return defaultValue;
25
+ return '';
26
+ })();
15
27
  dispatch(setValue(value));
16
28
  dispatch(setDate(date));
17
- if (isFunction(props.onChange)) {
18
- props.onChange({
29
+ if (isFunction(onChange)) {
30
+ onChange({
19
31
  component: {
20
- name: props.name,
32
+ name,
21
33
  date,
22
34
  value,
23
35
  },
@@ -7,7 +7,7 @@ import { VIEW_TYPES } from '../CalendarBase/constants';
7
7
  import { MaskedInputBase } from '../MaskedInputBase';
8
8
  import { setDate, setViewDate } from './actions';
9
9
  import {
10
- stringToDate,
10
+ stringToDate, formatDateTime,
11
11
  } from './helpers';
12
12
  import { stateReducer } from './reducer';
13
13
  import type {
@@ -59,7 +59,7 @@ export const useDateTimeInputEffects = ({
59
59
 
60
60
  export const useDateTimeInputState = (props: DateTimeInputProps): [DateTimeInputState, React.Dispatch<AllActions>] => {
61
61
  const {
62
- value: valueProp, format, min, max,
62
+ value: valueProp, defaultValue, format = 'dd.MM.yyyy', min, max,
63
63
  } = props;
64
64
 
65
65
  // if today's date is out of min/max range - open the calendar with the min/max date instead
@@ -69,11 +69,25 @@ export const useDateTimeInputState = (props: DateTimeInputProps): [DateTimeInput
69
69
  // today's date, the time is 00:00
70
70
  const today = new Date();
71
71
 
72
- const stringValue = isDate(valueProp) || valueProp === null ? '' : valueProp;
72
+ const initialPropValue = valueProp === undefined ? defaultValue : valueProp;
73
+
74
+ const initialDate = (() => {
75
+ if (isDate(initialPropValue)) return initialPropValue;
76
+ if (typeof initialPropValue === 'string') return stringToDate(initialPropValue, format);
77
+ return null;
78
+ })();
79
+
80
+ const initialValue = (() => {
81
+ if (isDate(initialPropValue)) return formatDateTime(initialPropValue, format);
82
+ if (typeof initialPropValue === 'string') return initialPropValue;
83
+ return '';
84
+ })();
85
+
86
+ const stringValue = isDate(initialPropValue) || initialPropValue === null || initialPropValue === undefined ? '' : initialPropValue as string;
73
87
 
74
88
  const initialState = {
75
- date: null,
76
- value: '',
89
+ date: initialDate,
90
+ value: initialValue,
77
91
  isValid: true,
78
92
  isFocused: false,
79
93
  isOpen: false,
@@ -105,6 +105,8 @@ export interface DateTimeInputProps extends ValidationProps {
105
105
  onFocus?: (ev: FocusEvent) => void,
106
106
  /** Placeholder */
107
107
  placeholder?: string,
108
+ /** Default value */
109
+ defaultValue?: string | Date | null,
108
110
  /** Theme */
109
111
  theme?: PartialGlobalDefaultTheme[typeof COMPONENTS_NAMESPACES.dateTimeInput],
110
112
  /** Component type */
@@ -10,13 +10,15 @@ export const isDateValue = (value: DateTimeInputRangeProps['value']): value is [
10
10
  && (isNil(value[1]) || isDate(value[1]));
11
11
 
12
12
  export const getDateRangeFromValue = (props: DateTimeInputRangeProps): [Date | null, Date | null] => {
13
- const { value: valueProp, format } = props;
13
+ const { value: valueProp, defaultValue, format } = props;
14
14
 
15
- if (!valueProp) return [null, null];
15
+ const currentValue = valueProp === undefined ? defaultValue : valueProp;
16
16
 
17
- if (isDateValue(valueProp)) return valueProp;
17
+ if (!currentValue) return [null, null];
18
18
 
19
- return [stringToDate(valueProp[0], format), stringToDate(valueProp[1], format)];
19
+ if (isDateValue(currentValue)) return currentValue;
20
+
21
+ return [stringToDate(currentValue[0], format), stringToDate(currentValue[1], format)];
20
22
  };
21
23
 
22
24
  export const getPlaceholder = (placeholder?: [string | undefined, string | undefined] | string): [string | undefined, string | undefined] => {
@@ -41,6 +41,7 @@ export const DateTimeInputRange = React.forwardRef((props: DateTimeInputRangePro
41
41
  placeholder: placeholderProp,
42
42
  theme: themeProp,
43
43
  type,
44
+ defaultValue,
44
45
  value: valueProp,
45
46
  weeksRowRender,
46
47
  wrapperRangeRender,
@@ -123,6 +124,7 @@ export const DateTimeInputRange = React.forwardRef((props: DateTimeInputRangePro
123
124
  onEnterPress={handleEnterPress('from')}
124
125
  onFocus={onFocus}
125
126
  placeholder={placeholders[0]}
127
+ defaultValue={defaultValue?.[0] ?? null}
126
128
  theme={theme.from}
127
129
  type={type}
128
130
  value={value[0]}
@@ -155,6 +157,7 @@ export const DateTimeInputRange = React.forwardRef((props: DateTimeInputRangePro
155
157
  onFocus={onFocus}
156
158
  placeholder={placeholders[1]}
157
159
  ref={toDateTimeInputRef}
160
+ defaultValue={defaultValue?.[1] ?? null}
158
161
  theme={theme.to}
159
162
  type={type}
160
163
  value={value[1]}
@@ -46,6 +46,8 @@ export interface DelimiterProps {
46
46
  }
47
47
 
48
48
  export interface DateTimeInputRangeProps {
49
+ /** Default value */
50
+ defaultValue?: [string, string] | [Date | null, Date | null],
49
51
  boundingContainerRef?: React.RefObject<HTMLElement>,
50
52
  className?: string,
51
53
  max?: Date,
@@ -19,6 +19,7 @@ export const MaskedInputBase = React.forwardRef((props: MaskedInputBaseProps, re
19
19
  className,
20
20
  mask,
21
21
  value,
22
+ autoComplete,
22
23
  placeholderChar = DEFAULT_PLACEHOLDER_CHAR,
23
24
  placeholder,
24
25
  isDisabled = false,
@@ -90,6 +91,7 @@ export const MaskedInputBase = React.forwardRef((props: MaskedInputBaseProps, re
90
91
  <input
91
92
  disabled={isDisabled}
92
93
  className={className}
94
+ autoComplete={autoComplete}
93
95
  maxLength={mask.length + 1}
94
96
  onBlur={handleBlur}
95
97
  onFocus={handleFocus}
@@ -68,6 +68,7 @@ export interface MaskedInputBaseProps {
68
68
  isDisabled?: boolean,
69
69
  mask: string,
70
70
  maxLength?: number,
71
+ autoComplete?: string,
71
72
  name?: string,
72
73
  onBlur?: (event: BlurEvent) => void,
73
74
  onChange: (event: ChangeEvent) => void,
@@ -0,0 +1,4 @@
1
+ import type { SetState } from '../../commonTypes';
2
+ import type { DatePickerProps } from './types';
3
+ import type { ChangeEvent } from '../../src/DateTimeInput/types';
4
+ export declare const createChangeHandler: (props: DatePickerProps, setUncontrolledValue: SetState<string | Date | null>) => (ev: ChangeEvent) => void;
@@ -0,0 +1,11 @@
1
+ import { isFunction } from 'lodash';
2
+ export const createChangeHandler = (props, setUncontrolledValue) => (ev) => {
3
+ var _a;
4
+ const { onChange, value } = props;
5
+ if (value === undefined) {
6
+ setUncontrolledValue((_a = ev.component.date) !== null && _a !== void 0 ? _a : ev.component.value);
7
+ }
8
+ if (isFunction(onChange))
9
+ onChange(ev);
10
+ };
11
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../../chili/components/DatePicker/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAKpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,KAAsB,EACtB,oBAAoD,EACpD,EAAE,CAAC,CAAC,EAAe,EAAQ,EAAE;;IAC7B,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAElC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,oBAAoB,CAAC,MAAA,EAAE,CAAC,SAAS,CAAC,IAAI,mCAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAChE,CAAC;IAED,IAAI,UAAU,CAAC,QAAQ,CAAC;QAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;AACzC,CAAC,CAAC"}
@@ -1,8 +1,27 @@
1
1
  'use client';
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  import { jsx as _jsx } from "react/jsx-runtime";
3
14
  import * as React from 'react';
4
15
  import { DateTimeInput } from '../../src/DateTimeInput';
5
16
  import { COMPONENT_TYPES } from '../../src/DateTimeInput/constants';
6
- export const DatePicker = React.forwardRef((props, ref) => (_jsx(DateTimeInput, Object.assign({}, props, { format: props.format || 'dd.MM.yyyy', type: COMPONENT_TYPES.DATE_ONLY, ref: ref }))));
17
+ import { useValue, useProps } from '../../utils';
18
+ import { createChangeHandler } from './handlers';
19
+ export const DatePicker = React.forwardRef((rawProps, ref) => {
20
+ const props = useProps(rawProps);
21
+ const { defaultValue = null, value: valueProp } = props, restProps = __rest(props, ["defaultValue", "value"]);
22
+ const [value, setUncontrolledValue] = useValue(valueProp, defaultValue);
23
+ const handleChange = createChangeHandler(props, setUncontrolledValue);
24
+ return (_jsx(DateTimeInput, Object.assign({}, restProps, { defaultValue: defaultValue, value: value, onChange: handleChange, format: props.format || 'dd.MM.yyyy', type: COMPONENT_TYPES.DATE_ONLY, ref: ref })));
25
+ });
7
26
  DatePicker.displayName = 'DatePicker';
8
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../chili/components/DatePicker/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGpE,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAsB,EAAE,GAA2B,EAAE,EAAE,CAAC,CAClG,KAAC,aAAa,oBACR,KAAK,IACT,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,YAAY,EACpC,IAAI,EAAE,eAAe,CAAC,SAAS,EAC/B,GAAG,EAAE,GAAG,IACR,CACH,CAA8B,CAAC;AAEhC,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../chili/components/DatePicker/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEpE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,QAAyB,EAAE,GAA2B,EAAE,EAAE;IACpG,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEjC,MAAM,EACJ,YAAY,GAAG,IAAI,EACnB,KAAK,EAAE,SAAS,KAEd,KAAK,EADJ,SAAS,UACV,KAAK,EAJH,yBAIL,CAAQ,CAAC;IAEV,MAAM,CAAC,KAAK,EAAE,oBAAoB,CAAC,GAAG,QAAQ,CAAuB,SAAS,EAAE,YAAY,CAAC,CAAC;IAE9F,MAAM,YAAY,GAAG,mBAAmB,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;IAEtE,OAAO,CACL,KAAC,aAAa,oBACR,SAAS,IACb,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,YAAY,EACpC,IAAI,EAAE,eAAe,CAAC,SAAS,EAC/B,GAAG,EAAE,GAAG,IACR,CACH,CAAC;AACJ,CAAC,CAA8B,CAAC;AAEhC,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC"}
@@ -3,6 +3,8 @@ import type { COMPONENTS_NAMESPACES } from '../../constants';
3
3
  import type { BlurEvent, ChangeEvent, FocusEvent, DateTimeInputProps } from '../../src/DateTimeInput/types';
4
4
  import type { PartialGlobalDefaultTheme } from '../../utils/useTheme';
5
5
  export interface DatePickerProps extends DateTimeInputProps {
6
+ /** Default value */
7
+ defaultValue?: string | Date | null;
6
8
  /** Date format, dd.MM.yyyy by default */
7
9
  format?: string;
8
10
  /** Control opened state */
@@ -0,0 +1,4 @@
1
+ import type { SetState } from '../../commonTypes';
2
+ import type { DateRangeProps } from './types';
3
+ import type { CustomRangeEvent } from '../../src/DateTimeInputRange/types';
4
+ export declare const createChangeHandler: (props: DateRangeProps, setUncontrolledValue: SetState<DateRangeProps['value']>) => (ev: CustomRangeEvent) => void;