@os-design/core 1.0.280 → 1.0.281
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/dist/Avatar/utils/nameToInitials.d.ts.map +1 -1
- package/dist/Avatar/utils/strToHue.d.ts.map +1 -1
- package/dist/Button/index.d.ts.map +1 -1
- package/dist/Button/index.js +1 -1
- package/dist/Button/utils/useButtonColors.d.ts.map +1 -1
- package/dist/ButtonLink/index.d.ts.map +1 -1
- package/dist/ButtonLink/index.js +0 -5
- package/dist/Checkbox/index.d.ts.map +1 -1
- package/dist/Checkbox/index.js +1 -6
- package/dist/DateCalendar/Calendar.d.ts +25 -0
- package/dist/DateCalendar/Calendar.d.ts.map +1 -0
- package/dist/DateCalendar/Calendar.js +271 -0
- package/dist/DateCalendar/MonthPicker.d.ts +12 -0
- package/dist/DateCalendar/MonthPicker.d.ts.map +1 -0
- package/dist/DateCalendar/MonthPicker.js +159 -0
- package/dist/DateCalendar/index.d.ts +41 -0
- package/dist/DateCalendar/index.d.ts.map +1 -0
- package/dist/DateCalendar/index.js +77 -0
- package/dist/DateCalendar/locale.d.ts +6 -0
- package/dist/DateCalendar/locale.d.ts.map +1 -0
- package/dist/DateCalendar/locale.js +4 -0
- package/dist/DateCalendar/utils/calendarDays.d.ts +10 -0
- package/dist/DateCalendar/utils/calendarDays.d.ts.map +1 -0
- package/dist/DateCalendar/utils/calendarDays.js +46 -0
- package/dist/DateCalendar/utils/dayOfWeek.d.ts +8 -0
- package/dist/DateCalendar/utils/dayOfWeek.d.ts.map +1 -0
- package/dist/DateCalendar/utils/dayOfWeek.js +6 -0
- package/dist/DateCalendar/utils/daysInMonth.d.ts +7 -0
- package/dist/DateCalendar/utils/daysInMonth.d.ts.map +1 -0
- package/dist/DateCalendar/utils/daysInMonth.js +14 -0
- package/dist/DateCalendar/utils/month.d.ts +14 -0
- package/dist/DateCalendar/utils/month.d.ts.map +1 -0
- package/dist/DateCalendar/utils/month.js +24 -0
- package/dist/DateCalendar/utils/shift.d.ts +3 -0
- package/dist/DateCalendar/utils/shift.d.ts.map +1 -0
- package/dist/DateCalendar/utils/shift.js +12 -0
- package/dist/DatePicker/index.d.ts +68 -62
- package/dist/DatePicker/index.d.ts.map +1 -1
- package/dist/DatePicker/index.js +359 -265
- package/dist/DatePicker/utils/createTimes.d.ts +7 -0
- package/dist/DatePicker/utils/createTimes.d.ts.map +1 -0
- package/dist/DatePicker/utils/createTimes.js +15 -0
- package/dist/GlobalStyles/resetStyles.d.ts.map +1 -1
- package/dist/GlobalStyles/typographyStyles.d.ts.map +1 -1
- package/dist/Input/index.d.ts +15 -0
- package/dist/Input/index.d.ts.map +1 -1
- package/dist/Input/index.js +5 -5
- package/dist/Input/utils/getFocusableElements.d.ts.map +1 -1
- package/dist/InputDateUnstyled/index.d.ts +94 -0
- package/dist/InputDateUnstyled/index.d.ts.map +1 -0
- package/dist/InputDateUnstyled/index.js +406 -0
- package/dist/InputDateUnstyled/utils/convertHours.d.ts +4 -0
- package/dist/InputDateUnstyled/utils/convertHours.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/convertHours.js +12 -0
- package/dist/InputDateUnstyled/utils/convertToFullYear.d.ts +3 -0
- package/dist/InputDateUnstyled/utils/convertToFullYear.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/convertToFullYear.js +10 -0
- package/dist/InputDateUnstyled/utils/dateToString.d.ts +3 -0
- package/dist/InputDateUnstyled/utils/dateToString.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/dateToString.js +10 -0
- package/dist/InputDateUnstyled/utils/daysInMonth.d.ts +7 -0
- package/dist/InputDateUnstyled/utils/daysInMonth.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/daysInMonth.js +14 -0
- package/dist/InputDateUnstyled/utils/ensureCaretVisible.d.ts +3 -0
- package/dist/InputDateUnstyled/utils/ensureCaretVisible.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/ensureCaretVisible.js +32 -0
- package/dist/InputDateUnstyled/utils/eraseSelectedTokens.d.ts +10 -0
- package/dist/InputDateUnstyled/utils/eraseSelectedTokens.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/eraseSelectedTokens.js +29 -0
- package/dist/InputDateUnstyled/utils/replaceSubstring.d.ts +3 -0
- package/dist/InputDateUnstyled/utils/replaceSubstring.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/replaceSubstring.js +9 -0
- package/dist/InputDateUnstyled/utils/same.d.ts +6 -0
- package/dist/InputDateUnstyled/utils/same.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/same.js +3 -0
- package/dist/InputDateUnstyled/utils/stringToDay.d.ts +12 -0
- package/dist/InputDateUnstyled/utils/stringToDay.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/stringToDay.js +55 -0
- package/dist/InputDateUnstyled/utils/stringToTime.d.ts +7 -0
- package/dist/InputDateUnstyled/utils/stringToTime.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/stringToTime.js +40 -0
- package/dist/InputDateUnstyled/utils/token.d.ts +9 -0
- package/dist/InputDateUnstyled/utils/token.d.ts.map +1 -0
- package/dist/InputDateUnstyled/utils/token.js +66 -0
- package/dist/Link/index.d.ts.map +1 -1
- package/dist/Link/index.js +3 -8
- package/dist/LinkButton/index.d.ts.map +1 -1
- package/dist/LinkButton/index.js +0 -5
- package/dist/List/utils/bodyPointerEvents.d.ts.map +1 -1
- package/dist/List/utils/frameTimeout.d.ts.map +1 -1
- package/dist/List/utils/useRWLoadNext.d.ts.map +1 -1
- package/dist/LogoLink/index.d.ts.map +1 -1
- package/dist/LogoLink/index.js +1 -6
- package/dist/Menu/utils/useFocusWithArrows.d.ts.map +1 -1
- package/dist/Modal/index.d.ts +5 -0
- package/dist/Modal/index.d.ts.map +1 -1
- package/dist/Modal/index.js +53 -48
- package/dist/Navigation/utils/useScrollFlags.d.ts.map +1 -1
- package/dist/NavigationItem/index.d.ts.map +1 -1
- package/dist/NavigationItem/index.js +1 -6
- package/dist/Popover/utils/usePopoverPosition.d.ts.map +1 -1
- package/dist/ScrollButton/utils/useContainerPosition.d.ts.map +1 -1
- package/dist/ScrollButton/utils/useVisibility.d.ts.map +1 -1
- package/dist/Select/index.d.ts.map +1 -1
- package/dist/Select/index.js +2 -3
- package/dist/Switch/index.d.ts.map +1 -1
- package/dist/Switch/index.js +1 -7
- package/dist/TagLink/index.d.ts.map +1 -1
- package/dist/TagLink/index.js +1 -6
- package/dist/TimeGrid/index.d.ts +63 -0
- package/dist/TimeGrid/index.d.ts.map +1 -0
- package/dist/TimeGrid/index.js +111 -0
- package/dist/TimeGrid/utils/convertHours.d.ts +4 -0
- package/dist/TimeGrid/utils/convertHours.d.ts.map +1 -0
- package/dist/TimeGrid/utils/convertHours.js +12 -0
- package/dist/TimeGrid/utils/createTimes.d.ts +7 -0
- package/dist/TimeGrid/utils/createTimes.d.ts.map +1 -0
- package/dist/TimeGrid/utils/createTimes.js +15 -0
- package/dist/TimeGrid/utils/timeToString.d.ts +4 -0
- package/dist/TimeGrid/utils/timeToString.d.ts.map +1 -0
- package/dist/TimeGrid/utils/timeToString.js +12 -0
- package/dist/TimeGridSkeleton/index.d.ts +18 -0
- package/dist/TimeGridSkeleton/index.d.ts.map +1 -0
- package/dist/TimeGridSkeleton/index.js +33 -0
- package/dist/TimeList/index.d.ts +45 -0
- package/dist/TimeList/index.d.ts.map +1 -0
- package/dist/TimeList/index.js +80 -0
- package/dist/TimeList/utils/convertHours.d.ts +4 -0
- package/dist/TimeList/utils/convertHours.d.ts.map +1 -0
- package/dist/TimeList/utils/convertHours.js +12 -0
- package/dist/TimeList/utils/createTimes.d.ts +7 -0
- package/dist/TimeList/utils/createTimes.d.ts.map +1 -0
- package/dist/TimeList/utils/createTimes.js +15 -0
- package/dist/TimeList/utils/timeToString.d.ts +4 -0
- package/dist/TimeList/utils/timeToString.d.ts.map +1 -0
- package/dist/TimeList/utils/timeToString.js +12 -0
- package/dist/TimeListSkeleton/index.d.ts +13 -0
- package/dist/TimeListSkeleton/index.d.ts.map +1 -0
- package/dist/TimeListSkeleton/index.js +30 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/message/styles.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/Button/index.tsx +1 -1
- package/src/ButtonLink/index.tsx +0 -5
- package/src/Checkbox/index.tsx +1 -6
- package/src/DateCalendar/Calendar.tsx +400 -0
- package/src/DateCalendar/MonthPicker.tsx +212 -0
- package/src/DateCalendar/index.tsx +135 -0
- package/src/DateCalendar/locale.ts +22 -0
- package/src/DateCalendar/utils/calendarDays.ts +61 -0
- package/src/DateCalendar/utils/dayOfWeek.ts +14 -0
- package/src/DateCalendar/utils/daysInMonth.ts +22 -0
- package/src/DateCalendar/utils/month.ts +30 -0
- package/src/DateCalendar/utils/shift.ts +14 -0
- package/src/DatePicker/index.tsx +506 -417
- package/src/DatePicker/utils/createTimes.ts +20 -0
- package/src/Input/index.tsx +11 -8
- package/src/InputDateUnstyled/index.tsx +533 -0
- package/src/InputDateUnstyled/utils/convertHours.ts +15 -0
- package/src/InputDateUnstyled/utils/convertToFullYear.ts +11 -0
- package/src/InputDateUnstyled/utils/dateToString.ts +21 -0
- package/src/InputDateUnstyled/utils/daysInMonth.ts +22 -0
- package/src/InputDateUnstyled/utils/ensureCaretVisible.ts +37 -0
- package/src/InputDateUnstyled/utils/eraseSelectedTokens.ts +38 -0
- package/src/InputDateUnstyled/utils/replaceSubstring.ts +10 -0
- package/src/InputDateUnstyled/utils/same.ts +15 -0
- package/src/InputDateUnstyled/utils/stringToDay.ts +69 -0
- package/src/InputDateUnstyled/utils/stringToTime.ts +48 -0
- package/src/InputDateUnstyled/utils/token.ts +102 -0
- package/src/Link/index.tsx +5 -25
- package/src/LinkButton/index.tsx +2 -15
- package/src/LogoLink/index.tsx +2 -6
- package/src/Modal/index.tsx +71 -60
- package/src/NavigationItem/index.tsx +2 -16
- package/src/Select/index.tsx +2 -3
- package/src/Switch/index.tsx +1 -11
- package/src/TagLink/index.tsx +3 -11
- package/src/TimeGrid/index.tsx +189 -0
- package/src/TimeGrid/utils/convertHours.ts +15 -0
- package/src/TimeGrid/utils/createTimes.ts +20 -0
- package/src/TimeGrid/utils/timeToString.ts +17 -0
- package/src/TimeGridSkeleton/index.tsx +50 -0
- package/src/TimeList/index.tsx +135 -0
- package/src/TimeList/utils/convertHours.ts +15 -0
- package/src/TimeList/utils/createTimes.ts +20 -0
- package/src/TimeList/utils/timeToString.ts +17 -0
- package/src/TimeListSkeleton/index.tsx +44 -0
- package/src/index.ts +12 -0
- package/dist/DatePicker/DatePickerCalendar.d.ts +0 -11
- package/dist/DatePicker/DatePickerCalendar.d.ts.map +0 -1
- package/dist/DatePicker/DatePickerCalendar.js +0 -178
- package/dist/TimePicker/index.d.ts +0 -29
- package/dist/TimePicker/index.d.ts.map +0 -1
- package/dist/TimePicker/index.js +0 -100
- package/src/DatePicker/DatePickerCalendar.tsx +0 -230
- package/src/TimePicker/index.tsx +0 -144
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTimes.d.ts","sourceRoot":"","sources":["../../../src/DatePicker/utils/createTimes.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,QAAA,MAAM,WAAW,GAAI,MAAM,IAAI,EAAE,IAAI,IAAI,EAAE,aAAa,MAAM,WAY7D,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const createTimes = (from, to, stepMinutes) => {
|
|
2
|
+
const min = from.hour * 60 + from.minute;
|
|
3
|
+
const max = to.hour * 60 + to.minute;
|
|
4
|
+
const times = [];
|
|
5
|
+
for (let i = min; i <= max - stepMinutes; i += stepMinutes) {
|
|
6
|
+
const hour = Math.floor(i / 60);
|
|
7
|
+
const minute = i % 60;
|
|
8
|
+
times.push({
|
|
9
|
+
hour,
|
|
10
|
+
minute
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return times;
|
|
14
|
+
};
|
|
15
|
+
export default createTimes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resetStyles.d.ts","sourceRoot":"","sources":["../../src/GlobalStyles/resetStyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,QAAA,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"resetStyles.d.ts","sourceRoot":"","sources":["../../src/GlobalStyles/resetStyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,QAAA,MAAM,WAAW,GAAI,OAAO,KAAK,KAAG,gBAUnC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typographyStyles.d.ts","sourceRoot":"","sources":["../../src/GlobalStyles/typographyStyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,KAAK,KAAK,EAAO,MAAM,oBAAoB,CAAC;AAmBrD,QAAA,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"typographyStyles.d.ts","sourceRoot":"","sources":["../../src/GlobalStyles/typographyStyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,KAAK,KAAK,EAAO,MAAM,oBAAoB,CAAC;AAmBrD,QAAA,MAAM,gBAAgB,GAAI,OAAO,KAAK,KAAG,gBAqDxC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
package/dist/Input/index.d.ts
CHANGED
|
@@ -73,6 +73,21 @@ export declare const StyledInput: import("@emotion/styled").StyledComponent<{
|
|
|
73
73
|
theme?: import("@emotion/react").Theme;
|
|
74
74
|
as?: React.ElementType;
|
|
75
75
|
} & StyledInputProps, React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, {}>;
|
|
76
|
+
interface InputAddonProps {
|
|
77
|
+
hasPadding?: boolean;
|
|
78
|
+
}
|
|
79
|
+
export declare const InputLeftAddon: import("@emotion/styled").StyledComponent<{
|
|
80
|
+
theme?: import("@emotion/react").Theme;
|
|
81
|
+
as?: React.ElementType;
|
|
82
|
+
} & InputAddonProps & React.ClassAttributes<HTMLSpanElement> & React.HTMLAttributes<HTMLSpanElement> & {
|
|
83
|
+
theme?: import("@emotion/react").Theme;
|
|
84
|
+
}, {}, {}>;
|
|
85
|
+
export declare const InputRightAddon: import("@emotion/styled").StyledComponent<{
|
|
86
|
+
theme?: import("@emotion/react").Theme;
|
|
87
|
+
as?: React.ElementType;
|
|
88
|
+
} & InputAddonProps & React.ClassAttributes<HTMLSpanElement> & React.HTMLAttributes<HTMLSpanElement> & {
|
|
89
|
+
theme?: import("@emotion/react").Theme;
|
|
90
|
+
}, {}, {}>;
|
|
76
91
|
/**
|
|
77
92
|
* The basic input component.
|
|
78
93
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Input/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,EACZ,KAAK,WAAW,EAEhB,KAAK,YAAY,EAKlB,MAAM,OAAO,CAAC;AAGf,KAAK,aAAa,GAAG,IAAI,CACvB,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAC9B,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,CACtC,CAA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AJV,MAAO,WAAW;;;UAWnC,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,KAAK,qFAyGV,CAAC;AAIF,eAAe,KAAK,CAAC"}
|
package/dist/Input/index.js
CHANGED
|
@@ -88,7 +88,7 @@ export const StyledInput = styled('input', omitEmotionProps('hasLeft', 'hasRight
|
|
|
88
88
|
${notHasLeftStyles};
|
|
89
89
|
${notHasRightStyles};
|
|
90
90
|
`;
|
|
91
|
-
const
|
|
91
|
+
const InputAddon = styled('span', omitEmotionProps('hasPadding'))`
|
|
92
92
|
display: flex;
|
|
93
93
|
align-items: center;
|
|
94
94
|
user-select: none;
|
|
@@ -98,13 +98,13 @@ const Addon = styled('span', omitEmotionProps('hasPadding'))`
|
|
|
98
98
|
transform: scale(1.2);
|
|
99
99
|
}
|
|
100
100
|
`;
|
|
101
|
-
const
|
|
101
|
+
export const InputLeftAddon = styled(InputAddon)`
|
|
102
102
|
padding-right: ${p => p.theme.inputAddonPaddingHorizontal}em;
|
|
103
103
|
${p => p.hasPadding && css`
|
|
104
104
|
padding-left: ${p.theme.inputPaddingHorizontal}em;
|
|
105
105
|
`}
|
|
106
106
|
`;
|
|
107
|
-
const
|
|
107
|
+
export const InputRightAddon = styled(InputAddon)`
|
|
108
108
|
padding-left: ${p => p.theme.inputAddonPaddingHorizontal}em;
|
|
109
109
|
${p => p.hasPadding && css`
|
|
110
110
|
padding-right: ${p.theme.inputPaddingHorizontal}em;
|
|
@@ -164,7 +164,7 @@ const Input = /*#__PURE__*/forwardRef(({
|
|
|
164
164
|
overrides: {
|
|
165
165
|
buttonPaddingHorizontal: 0.8
|
|
166
166
|
},
|
|
167
|
-
children: /*#__PURE__*/_jsx(
|
|
167
|
+
children: /*#__PURE__*/_jsx(InputLeftAddon, {
|
|
168
168
|
hasPadding: leftHasPadding,
|
|
169
169
|
children: left
|
|
170
170
|
})
|
|
@@ -181,7 +181,7 @@ const Input = /*#__PURE__*/forwardRef(({
|
|
|
181
181
|
overrides: {
|
|
182
182
|
buttonPaddingHorizontal: 0.8
|
|
183
183
|
},
|
|
184
|
-
children: /*#__PURE__*/_jsx(
|
|
184
|
+
children: /*#__PURE__*/_jsx(InputRightAddon, {
|
|
185
185
|
hasPadding: rightHasPaddingValue,
|
|
186
186
|
children: rightValue
|
|
187
187
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFocusableElements.d.ts","sourceRoot":"","sources":["../../../src/Input/utils/getFocusableElements.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"getFocusableElements.d.ts","sourceRoot":"","sources":["../../../src/Input/utils/getFocusableElements.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,oBAAoB,GAAI,SAAS,UAAU,KAAG,WAAW,EAW9D,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type Day, type OnDayError } from './utils/stringToDay.js';
|
|
2
|
+
import { type Time } from './utils/stringToTime.js';
|
|
3
|
+
export declare const tokens: readonly ["DD", "MM", "YYYY", "YY", "hh", "HH", "mm", "aa"];
|
|
4
|
+
export declare const numericTokens: string[];
|
|
5
|
+
export type Token = (typeof tokens)[number];
|
|
6
|
+
export interface Selection {
|
|
7
|
+
start: number;
|
|
8
|
+
end: number;
|
|
9
|
+
}
|
|
10
|
+
type JsxInputProps = Omit<JSX.IntrinsicElements['input'], 'value' | 'defaultValue' | 'onChange' | 'ref'>;
|
|
11
|
+
export interface InputDateUnstyledProps extends JsxInputProps {
|
|
12
|
+
/**
|
|
13
|
+
* The string format. Supported tokens:
|
|
14
|
+
* `DD` - The day of the month (01-31).
|
|
15
|
+
* `MM` - The month (01-12).
|
|
16
|
+
* `YYYY` - Four-digit year (2025).
|
|
17
|
+
* `YY` - Two-digit year (25).
|
|
18
|
+
* `hh` - The hour, 12-hour clock (01-12).
|
|
19
|
+
* `HH` - The hour, 24-hour clock (00-23).
|
|
20
|
+
* `mm` - The minute (00-59).
|
|
21
|
+
* `aa` - The meridiem (am, pm).
|
|
22
|
+
* @default `DD.MM.YYYY`
|
|
23
|
+
*/
|
|
24
|
+
format?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Selected date.
|
|
27
|
+
* @default undefined
|
|
28
|
+
*/
|
|
29
|
+
value?: Date | null;
|
|
30
|
+
/**
|
|
31
|
+
* The value of the input.
|
|
32
|
+
* @default undefined
|
|
33
|
+
*/
|
|
34
|
+
inputValue?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The caret position.
|
|
37
|
+
* @default undefined
|
|
38
|
+
*/
|
|
39
|
+
selection?: Selection;
|
|
40
|
+
/**
|
|
41
|
+
* The default value.
|
|
42
|
+
* @default undefined
|
|
43
|
+
*/
|
|
44
|
+
defaultValue?: Date | null;
|
|
45
|
+
/**
|
|
46
|
+
* The change event handler.
|
|
47
|
+
* @default undefined
|
|
48
|
+
*/
|
|
49
|
+
onChange?: (value: Date | null) => void;
|
|
50
|
+
/**
|
|
51
|
+
* The callback called when the input is changed.
|
|
52
|
+
* @default undefined
|
|
53
|
+
*/
|
|
54
|
+
onInputChange?: (value: string) => void;
|
|
55
|
+
/**
|
|
56
|
+
* The callback called when the selection has been changed.
|
|
57
|
+
* @default undefined
|
|
58
|
+
*/
|
|
59
|
+
onSelectionChange?: (selection: Selection) => void;
|
|
60
|
+
/**
|
|
61
|
+
* The callback called when the day is changed.
|
|
62
|
+
* @default undefined
|
|
63
|
+
*/
|
|
64
|
+
onDayChange?: (value: Day) => void;
|
|
65
|
+
/**
|
|
66
|
+
* The callback called when the time is changed.
|
|
67
|
+
* @default undefined
|
|
68
|
+
*/
|
|
69
|
+
onTimeChange?: (value: Time) => void;
|
|
70
|
+
/**
|
|
71
|
+
* The error handler called when the day has been entered incorrectly.
|
|
72
|
+
* @default undefined
|
|
73
|
+
*/
|
|
74
|
+
onDayError?: OnDayError;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The input for entering a date/time without any styles.
|
|
78
|
+
*/
|
|
79
|
+
declare const InputDateUnstyled: import("react").ForwardRefExoticComponent<InputDateUnstyledProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
80
|
+
export { default as convertToFullYear } from './utils/convertToFullYear.js';
|
|
81
|
+
export { default as dateToString } from './utils/dateToString.js';
|
|
82
|
+
export { default as daysInMonth } from './utils/daysInMonth.js';
|
|
83
|
+
export { default as ensureCaretVisible } from './utils/ensureCaretVisible.js';
|
|
84
|
+
export { default as eraseSelectedTokens } from './utils/eraseSelectedTokens.js';
|
|
85
|
+
export { default as replaceSubstring } from './utils/replaceSubstring.js';
|
|
86
|
+
export { default as stringToDay } from './utils/stringToDay.js';
|
|
87
|
+
export { default as stringToTime } from './utils/stringToTime.js';
|
|
88
|
+
export * from './utils/convertHours.js';
|
|
89
|
+
export * from './utils/same.js';
|
|
90
|
+
export * from './utils/stringToDay.js';
|
|
91
|
+
export * from './utils/stringToTime.js';
|
|
92
|
+
export * from './utils/token.js';
|
|
93
|
+
export default InputDateUnstyled;
|
|
94
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/InputDateUnstyled/index.tsx"],"names":[],"mappings":"AAcA,OAAoB,EAAE,KAAK,GAAG,EAAE,KAAK,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAqB,EAAE,KAAK,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAIlE,eAAO,MAAM,MAAM,6DAST,CAAC;AACX,eAAO,MAAM,aAAa,UAA+C,CAAC;AAE1E,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,KAAK,aAAa,GAAG,IAAI,CACvB,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,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F,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAClE,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AAEjC,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { forwardRef, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { nextToken, prevToken } from './utils/token.js';
|
|
3
|
+
import replaceSubstring from './utils/replaceSubstring.js';
|
|
4
|
+
import dateToString from './utils/dateToString.js';
|
|
5
|
+
import { useEvent, useForwardedRef, useForwardedState } from '@os-design/utils';
|
|
6
|
+
import eraseSelectedTokens from './utils/eraseSelectedTokens.js';
|
|
7
|
+
import stringToDay from './utils/stringToDay.js';
|
|
8
|
+
import stringToTime from './utils/stringToTime.js';
|
|
9
|
+
import ensureCaretVisible from './utils/ensureCaretVisible.js';
|
|
10
|
+
import { sameDate, sameDay, sameTime } from './utils/same.js';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
export const tokens = ['DD', 'MM', 'YYYY', 'YY', 'hh', 'HH', 'mm', 'aa'];
|
|
13
|
+
export const numericTokens = ['DD', 'MM', 'YYYY', 'YY', 'hh', 'HH', 'mm'];
|
|
14
|
+
/**
|
|
15
|
+
* The input for entering a date/time without any styles.
|
|
16
|
+
*/
|
|
17
|
+
const InputDateUnstyled = /*#__PURE__*/forwardRef(({
|
|
18
|
+
format = 'DD.MM.YYYY',
|
|
19
|
+
value,
|
|
20
|
+
inputValue,
|
|
21
|
+
selection,
|
|
22
|
+
defaultValue,
|
|
23
|
+
onChange,
|
|
24
|
+
onInputChange,
|
|
25
|
+
onSelectionChange = () => {},
|
|
26
|
+
onDayChange = () => {},
|
|
27
|
+
onTimeChange = () => {},
|
|
28
|
+
onDayError,
|
|
29
|
+
onFocus = () => {},
|
|
30
|
+
onKeyDown = () => {},
|
|
31
|
+
...rest
|
|
32
|
+
}, ref) => {
|
|
33
|
+
const [inputRef, mergedInputRef] = useForwardedRef(ref);
|
|
34
|
+
const [forwardedValue, setForwardedValue] = useForwardedState({
|
|
35
|
+
value,
|
|
36
|
+
defaultValue,
|
|
37
|
+
onChange
|
|
38
|
+
});
|
|
39
|
+
const [forwardedSelection, setForwardedSelection] = useForwardedState({
|
|
40
|
+
value: selection,
|
|
41
|
+
defaultValue: {
|
|
42
|
+
start: 0,
|
|
43
|
+
end: 0
|
|
44
|
+
},
|
|
45
|
+
onChange: onSelectionChange
|
|
46
|
+
});
|
|
47
|
+
const defaultInputValue = useMemo(() => {
|
|
48
|
+
let res = format;
|
|
49
|
+
tokens.forEach(token => {
|
|
50
|
+
res = res.replaceAll(token, '_'.repeat(token.length));
|
|
51
|
+
});
|
|
52
|
+
return res;
|
|
53
|
+
}, [format]);
|
|
54
|
+
const [forwardedInputValue, setForwardedInputValue] = useForwardedState({
|
|
55
|
+
value: inputValue,
|
|
56
|
+
defaultValue: defaultInputValue,
|
|
57
|
+
onChange: onInputChange
|
|
58
|
+
});
|
|
59
|
+
const dayRef = useRef(null);
|
|
60
|
+
const timeRef = useRef(null);
|
|
61
|
+
const forwardedValueRef = useRef(forwardedValue);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
forwardedValueRef.current = forwardedValue;
|
|
64
|
+
}, [forwardedValue]);
|
|
65
|
+
const setForwardedValueRef = useRef(setForwardedValue);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
setForwardedValueRef.current = setForwardedValue;
|
|
68
|
+
}, [setForwardedValue]);
|
|
69
|
+
const forwardedSelectionRef = useRef(forwardedSelection);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
forwardedSelectionRef.current = forwardedSelection;
|
|
72
|
+
}, [forwardedSelection]);
|
|
73
|
+
const setForwardedSelectionRef = useRef(setForwardedSelection);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
setForwardedSelectionRef.current = setForwardedSelection;
|
|
76
|
+
}, [setForwardedSelection]);
|
|
77
|
+
const defaultInputValueRef = useRef(defaultInputValue);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
defaultInputValueRef.current = defaultInputValue;
|
|
80
|
+
}, [defaultInputValue]);
|
|
81
|
+
const forwardedInputValueRef = useRef(forwardedInputValue);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
forwardedInputValueRef.current = forwardedInputValue;
|
|
84
|
+
}, [forwardedInputValue]);
|
|
85
|
+
const setForwardedInputValueRef = useRef(setForwardedInputValue);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
setForwardedInputValueRef.current = setForwardedInputValue;
|
|
88
|
+
}, [setForwardedInputValue]);
|
|
89
|
+
const formatRef = useRef(format);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
formatRef.current = format;
|
|
92
|
+
}, [format]);
|
|
93
|
+
const onDayChangeRef = useRef(onDayChange);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
onDayChangeRef.current = onDayChange;
|
|
96
|
+
}, [onDayChange]);
|
|
97
|
+
const onTimeChangeRef = useRef(onTimeChange);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
onTimeChangeRef.current = onTimeChange;
|
|
100
|
+
}, [onTimeChange]);
|
|
101
|
+
const onDayErrorRef = useRef(onDayError);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
onDayErrorRef.current = onDayError;
|
|
104
|
+
}, [onDayError]);
|
|
105
|
+
const onKeyDownRef = useRef(onKeyDown);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
onKeyDownRef.current = onKeyDown;
|
|
108
|
+
}, [onKeyDown]);
|
|
109
|
+
|
|
110
|
+
// Change the input selection when the selection state is changed
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (!inputRef.current) return;
|
|
113
|
+
const selection = forwardedSelection || {
|
|
114
|
+
start: 0,
|
|
115
|
+
end: 0
|
|
116
|
+
};
|
|
117
|
+
inputRef.current.setSelectionRange(selection.start, selection.end);
|
|
118
|
+
ensureCaretVisible(inputRef.current);
|
|
119
|
+
}, [forwardedSelection, inputRef]);
|
|
120
|
+
|
|
121
|
+
// Change the input value when the value is changed
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
const nextInputValue = forwardedValue ? dateToString(forwardedValue, formatRef.current) : defaultInputValueRef.current;
|
|
124
|
+
setForwardedInputValueRef.current(nextInputValue);
|
|
125
|
+
}, [forwardedValue]);
|
|
126
|
+
|
|
127
|
+
// Calls onDayChange, onTimeChange, onChange handlers
|
|
128
|
+
// when the input value is changed.
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
const inputValue = forwardedInputValue || defaultInputValueRef.current;
|
|
131
|
+
const day = stringToDay(inputValue, formatRef.current, onDayErrorRef.current);
|
|
132
|
+
const time = stringToTime(inputValue, formatRef.current);
|
|
133
|
+
if (day && (!dayRef.current || !sameDay(day, dayRef.current))) {
|
|
134
|
+
onDayChangeRef.current(day);
|
|
135
|
+
dayRef.current = day;
|
|
136
|
+
}
|
|
137
|
+
if (time && (!timeRef.current || !sameTime(time, timeRef.current))) {
|
|
138
|
+
onTimeChangeRef.current(time);
|
|
139
|
+
timeRef.current = time;
|
|
140
|
+
}
|
|
141
|
+
if (!inputValue.includes('_')) {
|
|
142
|
+
const date = forwardedValueRef.current ? new Date(forwardedValueRef.current.getTime()) : new Date();
|
|
143
|
+
if (day) {
|
|
144
|
+
date.setFullYear(day.year);
|
|
145
|
+
date.setMonth(day.month);
|
|
146
|
+
date.setDate(day.day);
|
|
147
|
+
}
|
|
148
|
+
if (time) {
|
|
149
|
+
date.setHours(time.hour);
|
|
150
|
+
date.setMinutes(time.minute);
|
|
151
|
+
}
|
|
152
|
+
if (!forwardedValueRef.current || !sameDate(date, forwardedValueRef.current)) {
|
|
153
|
+
setForwardedValueRef.current(date);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, [forwardedInputValue]);
|
|
157
|
+
const keyDownHandler = useCallback(e => {
|
|
158
|
+
e.preventDefault(); // Avoid the default input behaviour
|
|
159
|
+
|
|
160
|
+
let start = e.currentTarget.selectionStart || 0;
|
|
161
|
+
const end = e.currentTarget.selectionEnd || 0;
|
|
162
|
+
let nextInputValue = forwardedInputValueRef.current || defaultInputValueRef.current;
|
|
163
|
+
if (/^[0-9]$/.test(e.key)) {
|
|
164
|
+
// If the user has selected multiple characters, erase tokens
|
|
165
|
+
// that contain them.
|
|
166
|
+
nextInputValue = eraseSelectedTokens({
|
|
167
|
+
value: nextInputValue,
|
|
168
|
+
start,
|
|
169
|
+
end,
|
|
170
|
+
format: formatRef.current,
|
|
171
|
+
tokens
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// Move the caret to the left, skipping all `_`
|
|
175
|
+
while (start > 0 && nextInputValue.charAt(start - 1) === '_') {
|
|
176
|
+
start--;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Find the next token and check whether it's a numeric one
|
|
180
|
+
const next = nextToken(start, formatRef.current, tokens);
|
|
181
|
+
if (!next || !numericTokens.includes(next.token)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Move the caret the the found token. There are 2 possible cases:
|
|
186
|
+
// 1. If the caret has been inside the token, the caret is not moved.
|
|
187
|
+
// 2. If the token is placed to the right of the caret, the caret
|
|
188
|
+
// moves to the start of the token.
|
|
189
|
+
start = next.pos;
|
|
190
|
+
let substr = e.key;
|
|
191
|
+
const digit = Number(e.key);
|
|
192
|
+
const prevChar = start > 0 ? nextInputValue.charAt(start - 1) : null;
|
|
193
|
+
const posInToken = next.pos - next.start;
|
|
194
|
+
switch (next.token) {
|
|
195
|
+
case 'DD':
|
|
196
|
+
if (posInToken === 0 && digit >= 4) {
|
|
197
|
+
substr = `0${digit}`;
|
|
198
|
+
} else if (posInToken === 1 && prevChar === '0' && digit === 0) {
|
|
199
|
+
return;
|
|
200
|
+
} else if (posInToken === 1 && prevChar === '3' && digit >= 2) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
case 'MM':
|
|
205
|
+
if (posInToken === 0 && digit >= 2) {
|
|
206
|
+
substr = `0${digit}`;
|
|
207
|
+
} else if (posInToken === 1 && prevChar === '0' && digit === 0) {
|
|
208
|
+
return;
|
|
209
|
+
} else if (posInToken === 1 && prevChar === '1' && digit >= 3) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
213
|
+
case 'hh':
|
|
214
|
+
if (posInToken === 0 && digit >= 2) {
|
|
215
|
+
substr = `0${digit}`;
|
|
216
|
+
} else if (posInToken === 1 && prevChar === '0' && digit === 0) {
|
|
217
|
+
return;
|
|
218
|
+
} else if (posInToken === 1 && prevChar === '1' && digit >= 3) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
case 'HH':
|
|
223
|
+
if (posInToken === 0 && digit >= 3) {
|
|
224
|
+
substr = `0${digit}`;
|
|
225
|
+
} else if (posInToken === 1 && prevChar === '2' && digit >= 4) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
case 'mm':
|
|
230
|
+
if (posInToken === 0 && digit >= 6) {
|
|
231
|
+
substr = `0${digit}`;
|
|
232
|
+
}
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Replace the next characters of the current token with '_'
|
|
237
|
+
const suffixLength = next.end - start - substr.length;
|
|
238
|
+
const suffix = suffixLength > 0 ? '_'.repeat(suffixLength) : '';
|
|
239
|
+
nextInputValue = replaceSubstring(nextInputValue, start, `${substr}${suffix}`);
|
|
240
|
+
|
|
241
|
+
// Move the caret to the next token
|
|
242
|
+
start += substr.length;
|
|
243
|
+
const next2 = nextToken(start, formatRef.current, tokens);
|
|
244
|
+
if (next2) start = next2.pos;
|
|
245
|
+
setForwardedInputValueRef.current(nextInputValue);
|
|
246
|
+
setForwardedSelectionRef.current({
|
|
247
|
+
start,
|
|
248
|
+
end: start
|
|
249
|
+
});
|
|
250
|
+
} else if ('ap'.includes(e.key.toLowerCase())) {
|
|
251
|
+
if (e.metaKey && e.key === 'a') {
|
|
252
|
+
// Select all
|
|
253
|
+
setForwardedSelectionRef.current({
|
|
254
|
+
start: 0,
|
|
255
|
+
end: formatRef.current.length
|
|
256
|
+
});
|
|
257
|
+
} else {
|
|
258
|
+
// Find the next token and check whether it's the meridiem token
|
|
259
|
+
const next = nextToken(start, formatRef.current, tokens);
|
|
260
|
+
if (!next || next.token !== 'aa') return;
|
|
261
|
+
|
|
262
|
+
// Move the caret to the start of the token even if the caret
|
|
263
|
+
// has been located inside it.
|
|
264
|
+
start = next.start;
|
|
265
|
+
|
|
266
|
+
// Fill in the token
|
|
267
|
+
const substr = e.key.toLowerCase() === 'p' ? 'pm' : 'am';
|
|
268
|
+
nextInputValue = replaceSubstring(nextInputValue, start, substr);
|
|
269
|
+
|
|
270
|
+
// Move the caret to the next token
|
|
271
|
+
start += substr.length;
|
|
272
|
+
const next2 = nextToken(start, formatRef.current, tokens);
|
|
273
|
+
if (next2) start = next2.pos;
|
|
274
|
+
setForwardedInputValueRef.current(nextInputValue);
|
|
275
|
+
setForwardedSelectionRef.current({
|
|
276
|
+
start,
|
|
277
|
+
end: start
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
} else if (e.key === 'Backspace') {
|
|
281
|
+
if (end > start) {
|
|
282
|
+
// If the user has selected multiple characters, erase tokens
|
|
283
|
+
// that contain them.
|
|
284
|
+
nextInputValue = eraseSelectedTokens({
|
|
285
|
+
value: nextInputValue,
|
|
286
|
+
start,
|
|
287
|
+
end,
|
|
288
|
+
format: formatRef.current,
|
|
289
|
+
tokens
|
|
290
|
+
});
|
|
291
|
+
} else {
|
|
292
|
+
// If the caret in the first position, just ignore this event.
|
|
293
|
+
if (start === 0) return;
|
|
294
|
+
|
|
295
|
+
// Move the caret to the previous token
|
|
296
|
+
const prev = prevToken(start, formatRef.current, tokens);
|
|
297
|
+
if (!prev) return;
|
|
298
|
+
let substr = '_';
|
|
299
|
+
if (prev.token === 'aa') {
|
|
300
|
+
// Move the caret to the start of the meridiem token and erase
|
|
301
|
+
// all the characters of this token.
|
|
302
|
+
start = prev.start;
|
|
303
|
+
substr = '__';
|
|
304
|
+
} else {
|
|
305
|
+
// Erase the token to the end.
|
|
306
|
+
// For example, if the token contains 4 characters and the caret
|
|
307
|
+
// is located after the 2nd one, when the user presses backspace,
|
|
308
|
+
// the 2nd, 3rd, and 4th characters are erased.
|
|
309
|
+
start = prev.pos - 1;
|
|
310
|
+
substr = '_'.repeat(prev.end - start);
|
|
311
|
+
}
|
|
312
|
+
nextInputValue = replaceSubstring(nextInputValue, start, substr);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Move the caret to the previous token
|
|
316
|
+
const prev2 = prevToken(start, formatRef.current, tokens);
|
|
317
|
+
if (prev2) start = prev2.pos;
|
|
318
|
+
setForwardedInputValueRef.current(nextInputValue);
|
|
319
|
+
setForwardedSelectionRef.current({
|
|
320
|
+
start,
|
|
321
|
+
end: start
|
|
322
|
+
});
|
|
323
|
+
} else if (e.key === 'ArrowLeft') {
|
|
324
|
+
// If the caret in the first position, just ignore this event.
|
|
325
|
+
if (start === 0) return;
|
|
326
|
+
|
|
327
|
+
// Move the caret to the beginning of the string if the meta key
|
|
328
|
+
// has been pressed (cmd or ctrl).
|
|
329
|
+
if (e.metaKey) start = 0;
|
|
330
|
+
// Move the caret to the left
|
|
331
|
+
else start--;
|
|
332
|
+
setForwardedSelectionRef.current({
|
|
333
|
+
start,
|
|
334
|
+
end: start
|
|
335
|
+
});
|
|
336
|
+
} else if (e.key === 'ArrowRight') {
|
|
337
|
+
// If the caret in the last position, just ignore this event.
|
|
338
|
+
if (start === formatRef.current.length) return;
|
|
339
|
+
|
|
340
|
+
// Move the caret to the end of the string if the meta key
|
|
341
|
+
// has been pressed (cmd or ctrl).
|
|
342
|
+
if (e.metaKey) start = formatRef.current.length;
|
|
343
|
+
// Move the caret to the right
|
|
344
|
+
else start++;
|
|
345
|
+
setForwardedSelectionRef.current({
|
|
346
|
+
start,
|
|
347
|
+
end: start
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
onKeyDownRef.current(e);
|
|
351
|
+
}, []);
|
|
352
|
+
|
|
353
|
+
// Update the selection when the user clicks inside the input
|
|
354
|
+
const updateSelection = useCallback(e => {
|
|
355
|
+
const input = e.currentTarget;
|
|
356
|
+
const start = input.selectionStart || 0;
|
|
357
|
+
const end = input.selectionEnd || 0;
|
|
358
|
+
const selection = forwardedSelectionRef.current || {
|
|
359
|
+
start: 0,
|
|
360
|
+
end: 0
|
|
361
|
+
};
|
|
362
|
+
if (start !== selection.start || end !== selection.end) {
|
|
363
|
+
setForwardedSelectionRef.current({
|
|
364
|
+
start,
|
|
365
|
+
end
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}, []);
|
|
369
|
+
useEvent(inputRef, 'mouseup', updateSelection);
|
|
370
|
+
useEvent(inputRef, 'touchend', updateSelection);
|
|
371
|
+
const focusHandler = useCallback(e => {
|
|
372
|
+
setTimeout(() => {
|
|
373
|
+
// Move the caret to the beginning of the first token or if
|
|
374
|
+
// there are no tokens to the beginning of the string.
|
|
375
|
+
const next = nextToken(0, formatRef.current, tokens);
|
|
376
|
+
const pos = next ? next.pos : 0;
|
|
377
|
+
setForwardedSelectionRef.current({
|
|
378
|
+
start: pos,
|
|
379
|
+
end: pos
|
|
380
|
+
});
|
|
381
|
+
onFocus(e);
|
|
382
|
+
}, 0);
|
|
383
|
+
}, [onFocus]);
|
|
384
|
+
return /*#__PURE__*/_jsx("input", {
|
|
385
|
+
...rest,
|
|
386
|
+
onFocus: focusHandler,
|
|
387
|
+
onKeyDown: keyDownHandler,
|
|
388
|
+
value: forwardedInputValue,
|
|
389
|
+
ref: mergedInputRef
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
InputDateUnstyled.displayName = 'InputDateUnstyled';
|
|
393
|
+
export { default as convertToFullYear } from './utils/convertToFullYear.js';
|
|
394
|
+
export { default as dateToString } from './utils/dateToString.js';
|
|
395
|
+
export { default as daysInMonth } from './utils/daysInMonth.js';
|
|
396
|
+
export { default as ensureCaretVisible } from './utils/ensureCaretVisible.js';
|
|
397
|
+
export { default as eraseSelectedTokens } from './utils/eraseSelectedTokens.js';
|
|
398
|
+
export { default as replaceSubstring } from './utils/replaceSubstring.js';
|
|
399
|
+
export { default as stringToDay } from './utils/stringToDay.js';
|
|
400
|
+
export { default as stringToTime } from './utils/stringToTime.js';
|
|
401
|
+
export * from './utils/convertHours.js';
|
|
402
|
+
export * from './utils/same.js';
|
|
403
|
+
export * from './utils/stringToDay.js';
|
|
404
|
+
export * from './utils/stringToTime.js';
|
|
405
|
+
export * from './utils/token.js';
|
|
406
|
+
export default InputDateUnstyled;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertHours.d.ts","sourceRoot":"","sources":["../../../src/InputDateUnstyled/utils/convertHours.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;AAEnC,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,CAAC,MAAM,EAAE,QAAQ,CAOjE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,EAAE,UAAU,QAAQ,KAAG,MAGpE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const convertTo12hours = hours => {
|
|
2
|
+
if (hours >= 12) {
|
|
3
|
+
const hours12 = hours % 12;
|
|
4
|
+
return [hours12 === 0 ? 12 : hours12, 'pm'];
|
|
5
|
+
} else {
|
|
6
|
+
return [hours === 0 ? 12 : hours, 'am'];
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export const convertTo24hours = (hours, meridiem) => {
|
|
10
|
+
const h = hours === 12 ? 0 : hours;
|
|
11
|
+
return h + (meridiem === 'am' ? 0 : 12);
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertToFullYear.d.ts","sourceRoot":"","sources":["../../../src/InputDateUnstyled/utils/convertToFullYear.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,iBAAiB,GAAI,cAAc,MAAM,EAAE,aAAa,MAAM,WAQnE,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const convertToFullYear = (twoDigitYear, currentYear) => {
|
|
2
|
+
const fromYear = currentYear - 50;
|
|
3
|
+
const toYear = currentYear + 50;
|
|
4
|
+
if (twoDigitYear >= fromYear % 100) {
|
|
5
|
+
return Math.floor(fromYear / 100) * 100 + twoDigitYear;
|
|
6
|
+
} else {
|
|
7
|
+
return Math.floor(toYear / 100) * 100 + twoDigitYear;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export default convertToFullYear;
|