chili-ui 0.3.1 → 0.5.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/chili/components/DatePicker/handlers.ts +17 -0
- package/chili/components/DatePicker/index.tsx +27 -8
- package/chili/components/DatePicker/types.ts +2 -0
- package/chili/components/DateRange/handlers.ts +19 -0
- package/chili/components/DateRange/index.tsx +27 -8
- package/chili/components/DateRange/types.ts +2 -0
- package/chili/components/DateTimePicker/handlers.ts +19 -0
- package/chili/components/DateTimePicker/index.tsx +27 -8
- package/chili/components/DateTimePicker/types.ts +2 -0
- package/chili/components/DateTimeRange/handlers.ts +19 -0
- package/chili/components/DateTimeRange/index.tsx +27 -8
- package/chili/components/DateTimeRange/types.ts +2 -0
- package/chili/components/DropDownSelect/types.ts +1 -0
- package/chili/components/Icon/icons.tsx +5 -0
- package/chili/components/Icon/types.ts +1 -0
- package/chili/components/MaskedInput/__snapshots__/MaskedInput.test.tsx.snap +4 -0
- package/chili/components/MaskedInput/index.tsx +2 -0
- package/chili/components/MaskedInput/types.ts +2 -0
- package/chili/components/NumericTextBox/types.ts +2 -0
- package/chili/src/DateTimeInput/DateTimeInput.tsx +2 -1
- package/chili/src/DateTimeInput/handlers/handleCalendarClick.ts +2 -0
- package/chili/src/DateTimeInput/handlers/handleMouseDown.ts +1 -7
- package/chili/src/DateTimeInput/handlers/handleReset.ts +18 -6
- package/chili/src/DateTimeInput/hooks.ts +19 -5
- package/chili/src/DateTimeInput/types.ts +2 -0
- package/chili/src/DateTimeInputRange/helpers.ts +6 -4
- package/chili/src/DateTimeInputRange/index.tsx +3 -0
- package/chili/src/DateTimeInputRange/types.ts +2 -0
- package/chili/src/MaskedInputBase/index.tsx +2 -0
- package/chili/src/MaskedInputBase/types.ts +1 -0
- package/dist/components/DatePicker/handlers.d.ts +4 -0
- package/dist/components/DatePicker/handlers.js +11 -0
- package/dist/components/DatePicker/handlers.js.map +1 -0
- package/dist/components/DatePicker/index.js +20 -1
- package/dist/components/DatePicker/index.js.map +1 -1
- package/dist/components/DatePicker/types.d.ts +2 -0
- package/dist/components/DateRange/handlers.d.ts +4 -0
- package/dist/components/DateRange/handlers.js +10 -0
- package/dist/components/DateRange/handlers.js.map +1 -0
- package/dist/components/DateRange/index.js +20 -1
- package/dist/components/DateRange/index.js.map +1 -1
- package/dist/components/DateRange/types.d.ts +2 -0
- package/dist/components/DateTimePicker/handlers.d.ts +4 -0
- package/dist/components/DateTimePicker/handlers.js +11 -0
- package/dist/components/DateTimePicker/handlers.js.map +1 -0
- package/dist/components/DateTimePicker/index.js +20 -1
- package/dist/components/DateTimePicker/index.js.map +1 -1
- package/dist/components/DateTimePicker/types.d.ts +2 -0
- package/dist/components/DateTimeRange/handlers.d.ts +4 -0
- package/dist/components/DateTimeRange/handlers.js +10 -0
- package/dist/components/DateTimeRange/handlers.js.map +1 -0
- package/dist/components/DateTimeRange/index.js +20 -1
- package/dist/components/DateTimeRange/index.js.map +1 -1
- package/dist/components/DateTimeRange/types.d.ts +2 -0
- package/dist/components/DropDownSelect/types.d.ts +1 -0
- package/dist/components/Icon/icons.js +5 -0
- package/dist/components/Icon/icons.js.map +1 -1
- package/dist/components/Icon/types.d.ts +1 -0
- package/dist/components/Icon/types.js +1 -0
- package/dist/components/Icon/types.js.map +1 -1
- package/dist/components/MaskedInput/index.js +3 -3
- package/dist/components/MaskedInput/index.js.map +1 -1
- package/dist/components/MaskedInput/types.d.ts +2 -0
- package/dist/components/NumericTextBox/types.d.ts +2 -0
- package/dist/src/DateTimeInput/DateTimeInput.js +2 -2
- package/dist/src/DateTimeInput/DateTimeInput.js.map +1 -1
- package/dist/src/DateTimeInput/handlers/handleCalendarClick.js +2 -0
- package/dist/src/DateTimeInput/handlers/handleCalendarClick.js.map +1 -1
- package/dist/src/DateTimeInput/handlers/handleMouseDown.d.ts +1 -1
- package/dist/src/DateTimeInput/handlers/handleMouseDown.js +1 -7
- package/dist/src/DateTimeInput/handlers/handleMouseDown.js.map +1 -1
- package/dist/src/DateTimeInput/handlers/handleReset.js +20 -6
- package/dist/src/DateTimeInput/handlers/handleReset.js.map +1 -1
- package/dist/src/DateTimeInput/hooks.js +20 -5
- package/dist/src/DateTimeInput/hooks.js.map +1 -1
- package/dist/src/DateTimeInput/types.d.ts +2 -0
- package/dist/src/DateTimeInputRange/helpers.js +6 -5
- package/dist/src/DateTimeInputRange/helpers.js.map +1 -1
- package/dist/src/DateTimeInputRange/index.js +3 -3
- package/dist/src/DateTimeInputRange/index.js.map +1 -1
- package/dist/src/DateTimeInputRange/types.d.ts +2 -0
- package/dist/src/MaskedInputBase/index.js +2 -2
- package/dist/src/MaskedInputBase/index.js.map +1 -1
- package/dist/src/MaskedInputBase/types.d.ts +1 -0
- package/dist/styles/chili.base.css +1 -1
- package/docs/public/chili_pepper.png +0 -0
- package/docs/public/favicon.ico +0 -0
- package/docs/src/app/BaseLayout.tsx +22 -20
- package/docs/src/app/form-components/date-picker/_demo/DefaultValue.tsx +35 -0
- package/docs/src/app/form-components/date-picker/page.tsx +9 -0
- package/docs/src/app/form-components/date-range/_demo/DefaultValue.tsx +33 -0
- package/docs/src/app/form-components/date-range/page.tsx +9 -0
- package/docs/src/app/form-components/date-time-picker/_demo/DefaultValue.tsx +33 -0
- package/docs/src/app/form-components/date-time-picker/page.tsx +9 -0
- package/docs/src/app/form-components/date-time-range/_demo/DefaultValue.tsx +33 -0
- package/docs/src/app/form-components/date-time-range/page.tsx +10 -1
- package/docs/src/app/form-components/dropdown-select/page.tsx +8 -3
- package/docs/src/app/form-components/masked-input/page.tsx +18 -1
- package/docs/src/app/form-components/numeric-text-box/page.tsx +5 -0
- package/docs/src/app/globals.css +16 -1
- package/docs/src/app/layout-components/icon/page.tsx +1 -1
- package/docs/src/app/layout.tsx +3 -5
- package/docs/src/app/other/chili-provider/page.tsx +1 -1
- package/docs/src/components/header/MenuButton/index.tsx +6 -6
- package/docs/src/components/header/index.tsx +22 -21
- package/docs/src/components/live/DatesLive.tsx +22 -1
- package/docs/src/components/live/index.tsx +22 -1
- package/docs/src/components/nav/NavLi.tsx +1 -1
- package/docs/src/components/typography/A.tsx +1 -1
- package/package.json +1 -1
- 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((
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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((
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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((
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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((
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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" />,
|
|
@@ -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 */
|
|
@@ -121,7 +121,7 @@ export const DateTimeInput = React.forwardRef((props: DateTimeInputProps, ref: R
|
|
|
121
121
|
const handleBlur = createBlurHandler(handlersData);
|
|
122
122
|
const handleCalendarIconMouseDown = createCalendarIconMouseDownHandler(handlersData);
|
|
123
123
|
const handleCalendarKeyDown = createKeyDownHandler(handlersData);
|
|
124
|
-
const handleCalendarMouseDown = createCalendarMouseDownHandler(
|
|
124
|
+
const handleCalendarMouseDown = createCalendarMouseDownHandler();
|
|
125
125
|
const handleCalendarClick = createCalendarClickHandler(handlersData);
|
|
126
126
|
const handleChange = createChangeHandler(handlersData);
|
|
127
127
|
const handleFocus = createFocusHandler(handlersData);
|
|
@@ -167,6 +167,7 @@ export const DateTimeInput = React.forwardRef((props: DateTimeInputProps, ref: R
|
|
|
167
167
|
placeholder={placeholder}
|
|
168
168
|
ref={maskedInputRef}
|
|
169
169
|
value={inputValue}
|
|
170
|
+
inputMode="numeric"
|
|
170
171
|
/>
|
|
171
172
|
{type !== COMPONENT_TYPES.TIME_ONLY && (
|
|
172
173
|
<Icon
|
|
@@ -97,6 +97,8 @@ export const handleDatesSelect = (payload: DatesSelectPayload): void => {
|
|
|
97
97
|
|
|
98
98
|
dispatch(setOpen(false));
|
|
99
99
|
|
|
100
|
+
if (maskedInputRef && maskedInputRef.current) maskedInputRef.current.focus();
|
|
101
|
+
|
|
100
102
|
if (type === COMPONENT_TYPES.DATE_TIME) {
|
|
101
103
|
updateInputSelection(maskedInputRef, format);
|
|
102
104
|
}
|
|
@@ -24,14 +24,8 @@ export const createCalendarIconMouseDownHandler = ({
|
|
|
24
24
|
|
|
25
25
|
dispatch(setOpen(true));
|
|
26
26
|
} else dispatch(setOpen(false));
|
|
27
|
-
|
|
28
|
-
setTimeout(() => {
|
|
29
|
-
if (maskedInputRef.current) maskedInputRef.current.focus();
|
|
30
|
-
}, 0);
|
|
31
27
|
};
|
|
32
28
|
|
|
33
|
-
export const createCalendarMouseDownHandler = (
|
|
29
|
+
export const createCalendarMouseDownHandler = () => (ev: React.MouseEvent<HTMLDivElement>): void => {
|
|
34
30
|
ev.preventDefault();
|
|
35
|
-
|
|
36
|
-
if (maskedInputRef.current) maskedInputRef.current.focus();
|
|
37
31
|
};
|
|
@@ -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
|
|
14
|
-
|
|
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(
|
|
18
|
-
|
|
29
|
+
if (isFunction(onChange)) {
|
|
30
|
+
onChange({
|
|
19
31
|
component: {
|
|
20
|
-
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
|
|
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:
|
|
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
|
-
|
|
15
|
+
const currentValue = valueProp === undefined ? defaultValue : valueProp;
|
|
16
16
|
|
|
17
|
-
if (
|
|
17
|
+
if (!currentValue) return [null, null];
|
|
18
18
|
|
|
19
|
-
|
|
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}
|
|
@@ -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"}
|