@akinon/ui-date-picker 0.4.0 → 1.0.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/dist/esm/index.js CHANGED
@@ -9,9 +9,372 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { DatePicker as AntDatePicker } from 'antd';
12
+ import { Icon } from '@akinon/icons';
13
+ import { useToken } from '@akinon/ui-theme';
14
+ import { useStyleRegister } from '@ant-design/cssinjs';
15
+ import { ConfigProvider, DatePicker as AntDatePicker, Typography } from 'antd';
13
16
  import * as React from 'react';
17
+ import InputMask from 'react-input-mask';
18
+ /**
19
+ * DatePicker component for Akinon UI.
20
+ *
21
+ * The DatePicker component provides a flexible and feature-rich solution for selecting dates, ranges, and times.
22
+ * It supports various configurations, including custom formats, localized options, and enhanced accessibility features.
23
+ * The component integrates seamlessly with the Akinon design system, offering a consistent user experience.
24
+ *
25
+ * Key Features:
26
+ * - Multiple picker types, including date, week, month, quarter, and year.
27
+ * - Customizable placeholder, size, and variant options for styling.
28
+ * - Flexible date and time range selection with validation support.
29
+ * - Event callbacks for value changes, focus, blur, and panel interactions.
30
+ * - Localization support for tailored user experiences.
31
+ *
32
+ * The DatePicker component is designed to cater to both basic and advanced use cases, making it ideal for
33
+ * enterprise-level applications.
34
+ */
14
35
  export const DatePicker = (_a) => {
15
- var restDatePickerProps = __rest(_a, []);
16
- return (React.createElement(AntDatePicker, Object.assign({}, restDatePickerProps)));
36
+ var { pickerType = 'date', suffixIconColor = '#788195', suffixIcon = 'chevron_down', suffixIconSize = '10px', showTitle = false, inputTitle = '' } = _a, restDatePickerProps = __rest(_a, ["pickerType", "suffixIconColor", "suffixIcon", "suffixIconSize", "showTitle", "inputTitle"]);
37
+ const { getPrefixCls, theme } = React.useContext(ConfigProvider.ConfigContext);
38
+ const { token, hashId } = useToken();
39
+ const datePickerToken = token.DatePicker;
40
+ const prefixWithoutHash = `${getPrefixCls()}-picker`;
41
+ const prefixClsWithoutHash = `.${prefixWithoutHash}`;
42
+ const themeClassName = `${prefixWithoutHash}-${restDatePickerProps.theme}`;
43
+ const [startDate, setStartDate] = React.useState('');
44
+ const [startTime, setStartTime] = React.useState('');
45
+ const [endDate, setEndDate] = React.useState('');
46
+ const [endTime, setEndTime] = React.useState('');
47
+ const useStyle = useStyleRegister({
48
+ token: token,
49
+ path: ['DatePicker'],
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ theme: theme
52
+ }, () => {
53
+ const prefixCls = `:where(.${hashId})`;
54
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ const customTokens = theme.customTokens || {};
56
+ return {
57
+ [prefixCls]: {
58
+ [`&${prefixClsWithoutHash}`]: {
59
+ background: customTokens.others.colorTransparent,
60
+ border: customTokens.border.borderNone,
61
+ boxShadow: customTokens.layout.displayNone,
62
+ padding: customTokens.sizing.valueZero,
63
+ [`&:not(${prefixClsWithoutHash}-light)`]: {
64
+ background: datePickerToken.general.bgDarkBlue,
65
+ [`input`]: {
66
+ border: datePickerToken.general.wideBorder
67
+ }
68
+ },
69
+ [`&${prefixClsWithoutHash}-light`]: {
70
+ background: token.colorWhite,
71
+ border: datePickerToken.general.lightThemeBorder,
72
+ [`input`]: {
73
+ border: datePickerToken.general.lightThemeBorder
74
+ }
75
+ },
76
+ [`${prefixClsWithoutHash}-input span`]: {
77
+ position: customTokens.layout.positionAbsolute,
78
+ right: datePickerToken.pickerPanel.range.iconPosition,
79
+ top: customTokens.sizing.valueHalf,
80
+ transform: datePickerToken.pickerPanel.range.iconTransform,
81
+ pointerEvents: customTokens.layout.displayNone
82
+ },
83
+ [`${prefixClsWithoutHash}-input`]: {
84
+ color: datePickerToken.general.fontColor
85
+ },
86
+ [`input`]: {
87
+ fontWeight: datePickerToken.general.fontWeight,
88
+ padding: datePickerToken.general.inputPadding,
89
+ borderRadius: datePickerToken.pickerPanel.range.inputRadius,
90
+ width: `${restDatePickerProps.inputWidth} !important`,
91
+ outline: customTokens.layout.displayNone
92
+ },
93
+ [`&${prefixClsWithoutHash}-range`]: {
94
+ [`${prefixClsWithoutHash}-range-separator`]: {
95
+ content: customTokens.others.emptyContent,
96
+ width: datePickerToken.pickerPanel.separator.width,
97
+ height: datePickerToken.pickerPanel.separator.height,
98
+ background: datePickerToken.pickerPanel.separator.backgroundColor,
99
+ padding: customTokens.sizing.valueZero,
100
+ ['svg']: {
101
+ display: customTokens.layout.displayNone
102
+ }
103
+ },
104
+ [`${prefixClsWithoutHash}-suffix`]: {
105
+ display: customTokens.layout.displayNone
106
+ }
107
+ }
108
+ },
109
+ [`${prefixClsWithoutHash}-active-bar`]: {
110
+ display: customTokens.layout.displayNone
111
+ },
112
+ [`&${prefixClsWithoutHash}-dropdown`]: {
113
+ ['&::before']: {
114
+ content: customTokens.others.emptyContent,
115
+ position: customTokens.layout.positionAbsolute,
116
+ top: datePickerToken.pickerTriangle.beforeTop,
117
+ left: customTokens.layout.valueHalf,
118
+ transform: datePickerToken.pickerTriangle.transform,
119
+ borderLeft: datePickerToken.pickerTriangle.beforeBorderX,
120
+ borderRight: datePickerToken.pickerTriangle.beforeBorderX,
121
+ borderBottom: datePickerToken.pickerTriangle.beforeBorderBottom,
122
+ zIndex: datePickerToken.pickerTriangle.beforeZIndex
123
+ },
124
+ ['&::after']: {
125
+ content: customTokens.others.emptyContent,
126
+ position: customTokens.layout.positionAbsolute,
127
+ top: datePickerToken.pickerTriangle.afterTop,
128
+ left: customTokens.layout.valueHalf,
129
+ transform: datePickerToken.pickerTriangle.transform,
130
+ borderLeft: datePickerToken.pickerTriangle.afterBorderX,
131
+ borderRight: datePickerToken.pickerTriangle.afterBorderX,
132
+ borderBottom: datePickerToken.pickerTriangle.afterBorderBottom,
133
+ zIndex: datePickerToken.pickerTriangle.afterZIndex
134
+ },
135
+ [`${prefixClsWithoutHash}-date-panel-container`]: {
136
+ background: datePickerToken.general.bgDarkBlue,
137
+ border: datePickerToken.general.wideBorder,
138
+ boxShadow: datePickerToken.pickerPanel.shadow,
139
+ [`${prefixClsWithoutHash}-date-panel`]: {
140
+ width: 'fit-content'
141
+ },
142
+ [`${prefixClsWithoutHash}-header`]: {
143
+ border: customTokens.border.borderNone,
144
+ alignItems: datePickerToken.general.itemCenter,
145
+ marginBottom: datePickerToken.pickerPanel.header.marginY,
146
+ marginTop: datePickerToken.pickerPanel.header.marginY,
147
+ padding: datePickerToken.pickerPanel.header.padding,
148
+ [`&-view`]: {
149
+ fontSize: datePickerToken.pickerPanel.header.textSize,
150
+ fontWeight: datePickerToken.general.fontWeight,
151
+ lineHeight: customTokens.others.lineHeightShort,
152
+ letterSpacing: '-0.1px !important',
153
+ color: datePickerToken.pickerPanel.header.textColor
154
+ },
155
+ ['button']: {
156
+ lineHeight: customTokens.others.lineHeightShort
157
+ },
158
+ ['&-prev-btn, &-next-btn']: {
159
+ minWidth: datePickerToken.pickerPanel.header.arrawWidth,
160
+ width: datePickerToken.pickerPanel.header.arrawWidth
161
+ },
162
+ ['&-prev-btn']: {
163
+ paddingLeft: datePickerToken.pickerPanel.header.arrowPaddingLeft
164
+ },
165
+ ['&-next-btn']: {
166
+ paddingRight: datePickerToken.pickerPanel.header.arrowPaddingRight
167
+ },
168
+ ['&-super-prev-btn, &-super-next-btn']: {
169
+ minWidth: datePickerToken.pickerPanel.header.arrawWidth,
170
+ width: datePickerToken.pickerPanel.header.arrawWidth
171
+ }
172
+ },
173
+ [`${prefixClsWithoutHash}-body`]: {
174
+ padding: datePickerToken.pickerPanel.body.padding
175
+ },
176
+ [`${prefixClsWithoutHash}-content`]: {
177
+ width: 'max-content',
178
+ ['thead']: {
179
+ borderBottom: datePickerToken.pickerPanel.content.tableHeaderBorder
180
+ },
181
+ ['th']: {
182
+ fontSize: datePickerToken.pickerPanel.content.tableHeaderFontSize,
183
+ fontWeight: datePickerToken.general.fontWeight,
184
+ lineHeight: customTokens.others.lineHeightShort,
185
+ minWidth: datePickerToken.pickerPanel.content.tableHeaderWidth,
186
+ color: datePickerToken.pickerPanel.content.tableHeaderFontColor,
187
+ textTransform: customTokens.typography.textTransformUppercase,
188
+ height: customTokens.sizing.sizeMaxContent,
189
+ paddingBottom: datePickerToken.pickerPanel.content.tableHeaderPaddingBottom
190
+ },
191
+ ['tr']: {
192
+ display: customTokens.layout.displayBlock,
193
+ marginTop: datePickerToken.pickerPanel.row.marginY
194
+ },
195
+ [`:not(${prefixClsWithoutHash}-cell-in-view)${prefixClsWithoutHash}-cell`]: {
196
+ visibility: customTokens.others.valueHidden,
197
+ padding: customTokens.sizing.valueZero,
198
+ minWidth: datePickerToken.pickerPanel.row.previousCellWidth,
199
+ lineHeight: customTokens.sizing.valueZero,
200
+ height: customTokens.sizing.valueZero,
201
+ [`${prefixClsWithoutHash}-cell-inner`]: {
202
+ lineHeight: customTokens.sizing.valueZero,
203
+ height: customTokens.sizing.valueZero
204
+ }
205
+ },
206
+ [`${prefixClsWithoutHash}-cell-in-view`]: {
207
+ padding: customTokens.sizing.valueZero,
208
+ minWidth: datePickerToken.pickerPanel.content.tableHeaderWidth,
209
+ marginBottom: datePickerToken.pickerPanel.row.marginY
210
+ },
211
+ [`${prefixClsWithoutHash}-cell-today`]: {
212
+ [`${prefixClsWithoutHash}-cell-inner`]: {
213
+ background: datePickerToken.pickerPanel.row.cellBg,
214
+ border: datePickerToken.pickerPanel.row.cellBorder,
215
+ borderRadius: datePickerToken.pickerPanel.row.cellBorderRadius
216
+ }
217
+ },
218
+ [`${prefixClsWithoutHash}-cell-inner`]: {
219
+ fontSize: datePickerToken.general.fontSize,
220
+ fontWeight: datePickerToken.pickerPanel.row.cellFontWeight,
221
+ lineHeight: datePickerToken.pickerPanel.row.cellLineHeight,
222
+ color: datePickerToken.pickerPanel.row.cellTextColor,
223
+ height: customTokens.sizing.valueFull,
224
+ width: customTokens.sizing.valueFull,
225
+ [`&::before`]: {
226
+ display: customTokens.layout.displayNone
227
+ }
228
+ }
229
+ },
230
+ [`${prefixClsWithoutHash}-footer`]: {
231
+ borderTop: datePickerToken.pickerPanel.footer.datePickerBorderTop,
232
+ margin: datePickerToken.pickerPanel.footer.margin,
233
+ padding: datePickerToken.pickerPanel.footer.datePickerPadding,
234
+ ['li']: {
235
+ lineHeight: datePickerToken.pickerPanel.footer.lineHeight,
236
+ ['a']: {
237
+ fontSize: datePickerToken.pickerPanel.footer.fontSize,
238
+ fontWeight: datePickerToken.general.fontWeight,
239
+ color: token.colorWhite,
240
+ padding: datePickerToken.pickerPanel.footer.padding,
241
+ border: datePickerToken.pickerPanel.footer.border,
242
+ borderRadius: datePickerToken.pickerPanel.footer.borderRadius
243
+ }
244
+ }
245
+ }
246
+ }
247
+ },
248
+ [`&${prefixClsWithoutHash}-dropdown-range`]: {
249
+ padding: customTokens.sizing.valueZero,
250
+ [`${prefixClsWithoutHash}-date-panel-container`]: {
251
+ [`${prefixClsWithoutHash}-panel-layout`]: {
252
+ width: 'min-content'
253
+ },
254
+ [`${prefixClsWithoutHash}-header`]: {
255
+ ['&-super-prev-btn, &-super-next-btn']: {
256
+ display: customTokens.layout.displayNone
257
+ }
258
+ },
259
+ [`${prefixClsWithoutHash}-body`]: {
260
+ padding: '0 25px 0 20px !important'
261
+ },
262
+ [`${prefixClsWithoutHash}-content`]: {
263
+ [`${prefixClsWithoutHash}-cell-in-view,
264
+ ${prefixClsWithoutHash}-cell-in-range`]: {
265
+ padding: customTokens.sizing.valueZero,
266
+ minWidth: datePickerToken.pickerPanel.content.tableHeaderWidth,
267
+ marginBottom: datePickerToken.pickerPanel.row.marginY
268
+ },
269
+ [`${prefixClsWithoutHash}-cell-in-range`]: {
270
+ ['&:before']: {
271
+ background: customTokens.others.colorTransparent
272
+ }
273
+ },
274
+ [`${prefixClsWithoutHash}-cell-today,
275
+ ${prefixClsWithoutHash}-cell-range-start,
276
+ ${prefixClsWithoutHash}-cell-range-end`]: {
277
+ [`${prefixClsWithoutHash}-cell-inner`]: {
278
+ background: datePickerToken.pickerPanel.row.cellBg,
279
+ border: datePickerToken.pickerPanel.row.cellBorder,
280
+ borderRadius: datePickerToken.pickerPanel.row.cellBorderRadius
281
+ }
282
+ }
283
+ },
284
+ [`${prefixClsWithoutHash}-footer`]: {
285
+ borderTop: customTokens.border.borderNone,
286
+ padding: customTokens.sizing.valueZero
287
+ }
288
+ }
289
+ },
290
+ [`&${prefixClsWithoutHash}-input-title`]: {
291
+ display: customTokens.layout.displayBlock,
292
+ fontWeight: datePickerToken.general.fontWeight,
293
+ marginBottom: datePickerToken.general.inputMarginBottom,
294
+ [`&:not(${prefixClsWithoutHash}-light)`]: {
295
+ color: token.colorWhite
296
+ },
297
+ [`&${prefixClsWithoutHash}-light`]: {
298
+ color: datePickerToken.title.lightColor
299
+ }
300
+ }
301
+ },
302
+ ['.range-footer']: {
303
+ display: customTokens.layout.displayFlex,
304
+ flexDirection: datePickerToken.pickerPanel.footer.rangeDirection,
305
+ alignItems: datePickerToken.general.itemCenter,
306
+ columnGap: datePickerToken.pickerPanel.footer.rangeColGap,
307
+ ['.range-footer-start, .range-footer-end']: {
308
+ display: customTokens.layout.displayFlex,
309
+ flexDirection: datePickerToken.pickerPanel.footer.rangeDirection,
310
+ alignItems: datePickerToken.general.itemCenter,
311
+ borderTop: datePickerToken.pickerPanel.footer.rangeBorder,
312
+ padding: datePickerToken.pickerPanel.footer.rangePadding,
313
+ columnGap: datePickerToken.pickerPanel.footer.rangeCol
314
+ },
315
+ ['input']: {
316
+ border: datePickerToken.general.wideBorder,
317
+ backgroundColor: datePickerToken.general.bgDarkBlue,
318
+ textAlign: datePickerToken.general.itemCenter,
319
+ width: customTokens.sizing.valueFull,
320
+ padding: datePickerToken.pickerPanel.footer.rangeInputPadding,
321
+ borderRadius: datePickerToken.pickerPanel.footer.rangeInputRadius,
322
+ fontWeight: datePickerToken.general.fontWeight,
323
+ color: token.colorWhite,
324
+ outline: customTokens.layout.displayNone,
325
+ ['&::placeholder']: {
326
+ color: datePickerToken.general.fontColor
327
+ }
328
+ }
329
+ }
330
+ };
331
+ });
332
+ const customPopupStyle = restDatePickerProps.placement === 'center'
333
+ ? { left: '50%', transform: 'translateX(-50%)' }
334
+ : {};
335
+ const handleDateChange = (dates) => {
336
+ const updateDateTime = (date, setDate, setTime) => {
337
+ if (date) {
338
+ setDate(date.format('MM/DD/YYYY'));
339
+ setTime(date.format('HH:mm:ss'));
340
+ }
341
+ else {
342
+ setDate('');
343
+ setTime('');
344
+ }
345
+ };
346
+ if (dates) {
347
+ updateDateTime(dates[0], setStartDate, setStartTime);
348
+ updateDateTime(dates[1], setEndDate, setEndTime);
349
+ }
350
+ };
351
+ const renderFooter = (panelType) => {
352
+ const renderInputMask = (mask, value, onChange, placeholder) => (React.createElement(InputMask, { mask: mask, value: value, onChange: onChange, placeholder: placeholder }));
353
+ const isStartPanel = panelType === 'start';
354
+ const containerClass = isStartPanel
355
+ ? 'range-footer-start'
356
+ : 'range-footer-end';
357
+ return (React.createElement("div", { className: containerClass },
358
+ renderInputMask('99/99/9999', isStartPanel ? startDate : endDate, isStartPanel
359
+ ? e => setStartDate(e.target.value)
360
+ : e => setEndDate(e.target.value), isStartPanel ? '00/00/0000' : 'End Date'),
361
+ renderInputMask('99:99:99', isStartPanel ? startTime : endTime, isStartPanel
362
+ ? e => setStartTime(e.target.value)
363
+ : e => setEndTime(e.target.value), isStartPanel ? '00:00:00' : 'End Time')));
364
+ };
365
+ const RangePickerCustomInput = React.forwardRef((props, ref) => {
366
+ const _a = props, { value, onChange, placeholder } = _a, restProps = __rest(_a, ["value", "onChange", "placeholder"]);
367
+ return (React.createElement(React.Fragment, null,
368
+ React.createElement("input", Object.assign({}, restProps, { ref: ref, value: value, onChange: onChange, placeholder: placeholder })),
369
+ React.createElement("span", null,
370
+ React.createElement(Icon, { icon: suffixIcon, size: suffixIconSize, style: { color: suffixIconColor } }))));
371
+ });
372
+ RangePickerCustomInput.displayName = 'RangePickerCustomInput';
373
+ return useStyle(pickerType === 'range' ? (React.createElement(AntDatePicker.RangePicker, Object.assign({}, restDatePickerProps, { popupStyle: customPopupStyle, onChange: handleDateChange, renderExtraFooter: () => (React.createElement("div", { className: "range-footer" },
374
+ renderFooter('start'),
375
+ renderFooter('end'))), components: {
376
+ input: RangePickerCustomInput
377
+ }, variant: "borderless" }))) : (React.createElement("div", null,
378
+ showTitle && (React.createElement(Typography.Text, { className: `${prefixWithoutHash}-input-title ${themeClassName}` }, inputTitle)),
379
+ React.createElement(AntDatePicker, Object.assign({ className: themeClassName, suffixIcon: React.createElement(Icon, { icon: suffixIcon, size: suffixIconSize, style: { color: suffixIconColor } }) }, restDatePickerProps)))));
17
380
  };