@uniai-fe/uds-primitives 0.11.0 → 0.12.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/README.md +38 -453
- package/dist/styles.css +370 -327
- package/package.json +3 -3
- package/src/components/input/markup/time/Template.tsx +423 -0
- package/src/components/input/markup/time/Trigger.tsx +289 -0
- package/src/components/input/markup/time/index.tsx +2 -2
- package/src/components/input/styles/time.scss +160 -317
- package/src/components/input/styles/variables.scss +9 -47
- package/src/components/input/types/time.ts +61 -120
- package/src/components/time-picker/img/minus.svg +3 -0
- package/src/components/time-picker/img/plus.svg +3 -0
- package/src/components/time-picker/index.scss +1 -0
- package/src/components/time-picker/index.tsx +11 -0
- package/src/components/time-picker/markup/Footer.tsx +71 -0
- package/src/components/time-picker/markup/HourSection.tsx +99 -0
- package/src/components/time-picker/markup/MinuteSection.tsx +86 -0
- package/src/components/time-picker/markup/Summary.tsx +24 -0
- package/src/components/time-picker/markup/Template.tsx +86 -0
- package/src/components/time-picker/markup/index.tsx +10 -0
- package/src/components/time-picker/styles/index.scss +2 -0
- package/src/components/time-picker/styles/template.scss +174 -0
- package/src/components/time-picker/styles/variables.scss +64 -0
- package/src/components/time-picker/types/index.ts +1 -0
- package/src/components/time-picker/types/time-picker.ts +94 -0
- package/src/components/time-picker/utils/index.ts +1 -0
- package/src/components/time-picker/utils/time.ts +110 -0
- package/src/index.scss +1 -0
- package/src/index.tsx +1 -0
- package/src/components/input/markup/time/Picker.tsx +0 -378
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import type {
|
|
5
|
+
ChangeEvent,
|
|
6
|
+
ComponentPropsWithoutRef,
|
|
7
|
+
FocusEvent,
|
|
8
|
+
KeyboardEvent,
|
|
9
|
+
MouseEvent,
|
|
10
|
+
ReactNode,
|
|
11
|
+
} from "react";
|
|
12
|
+
import { forwardRef, useRef } from "react";
|
|
13
|
+
import { Calendar } from "../../../calendar";
|
|
14
|
+
import type {
|
|
15
|
+
TimePickerFormat,
|
|
16
|
+
TimePickerPeriod,
|
|
17
|
+
TimePickerUnit,
|
|
18
|
+
} from "../../../time-picker/types";
|
|
19
|
+
import type { InputPriority, InputSize, InputState } from "../../types";
|
|
20
|
+
|
|
21
|
+
interface InputTimeTriggerFields {
|
|
22
|
+
hours: string;
|
|
23
|
+
minutes: string;
|
|
24
|
+
seconds: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface InputTimeTriggerProps extends Omit<
|
|
28
|
+
ComponentPropsWithoutRef<"div">,
|
|
29
|
+
"onBlur" | "onFocus"
|
|
30
|
+
> {
|
|
31
|
+
fields: InputTimeTriggerFields;
|
|
32
|
+
period: TimePickerPeriod;
|
|
33
|
+
activeUnit: TimePickerUnit | null;
|
|
34
|
+
priority: InputPriority;
|
|
35
|
+
size: InputSize;
|
|
36
|
+
state: InputState;
|
|
37
|
+
format: TimePickerFormat;
|
|
38
|
+
withSeconds: boolean;
|
|
39
|
+
disabled: boolean;
|
|
40
|
+
readOnly: boolean;
|
|
41
|
+
icon: ReactNode;
|
|
42
|
+
iconPosition: "left" | "right";
|
|
43
|
+
iconLabel: string;
|
|
44
|
+
hoursInputLabel: string;
|
|
45
|
+
minutesInputLabel: string;
|
|
46
|
+
secondsInputLabel: string;
|
|
47
|
+
amPmInputLabel: string;
|
|
48
|
+
hoursPlaceholder: string;
|
|
49
|
+
minutesPlaceholder: string;
|
|
50
|
+
secondsPlaceholder: string;
|
|
51
|
+
onFieldChange: (unit: TimePickerUnit, value: string) => void;
|
|
52
|
+
onFieldFocus: (
|
|
53
|
+
unit: TimePickerUnit,
|
|
54
|
+
event: FocusEvent<HTMLInputElement>,
|
|
55
|
+
) => void;
|
|
56
|
+
onFieldBlur: (unit: TimePickerUnit) => void;
|
|
57
|
+
onFieldKeyDown: (
|
|
58
|
+
unit: TimePickerUnit,
|
|
59
|
+
event: KeyboardEvent<HTMLInputElement>,
|
|
60
|
+
) => void;
|
|
61
|
+
onPeriodChange: (period: TimePickerPeriod) => void;
|
|
62
|
+
onStep: (amount: 1 | -1) => void;
|
|
63
|
+
onRootBlur: (event: FocusEvent<HTMLDivElement>) => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Input Time trigger; 시·분·초 field와 focus 단위 stepper를 렌더한다.
|
|
68
|
+
* @component
|
|
69
|
+
* @param {InputTimeTriggerProps} props
|
|
70
|
+
* @returns {ReactNode} 시간 입력 trigger
|
|
71
|
+
*/
|
|
72
|
+
const InputTimeTrigger = forwardRef<HTMLDivElement, InputTimeTriggerProps>(
|
|
73
|
+
(
|
|
74
|
+
{
|
|
75
|
+
fields,
|
|
76
|
+
period,
|
|
77
|
+
activeUnit,
|
|
78
|
+
priority,
|
|
79
|
+
size,
|
|
80
|
+
state,
|
|
81
|
+
format,
|
|
82
|
+
withSeconds,
|
|
83
|
+
disabled,
|
|
84
|
+
readOnly,
|
|
85
|
+
icon,
|
|
86
|
+
iconPosition,
|
|
87
|
+
iconLabel,
|
|
88
|
+
hoursInputLabel,
|
|
89
|
+
minutesInputLabel,
|
|
90
|
+
secondsInputLabel,
|
|
91
|
+
amPmInputLabel,
|
|
92
|
+
hoursPlaceholder,
|
|
93
|
+
minutesPlaceholder,
|
|
94
|
+
secondsPlaceholder,
|
|
95
|
+
onFieldChange,
|
|
96
|
+
onFieldFocus,
|
|
97
|
+
onFieldBlur,
|
|
98
|
+
onFieldKeyDown,
|
|
99
|
+
onPeriodChange,
|
|
100
|
+
onStep,
|
|
101
|
+
onRootBlur,
|
|
102
|
+
className,
|
|
103
|
+
...restProps
|
|
104
|
+
},
|
|
105
|
+
ref,
|
|
106
|
+
) => {
|
|
107
|
+
const hoursRef = useRef<HTMLInputElement | null>(null);
|
|
108
|
+
const onChange =
|
|
109
|
+
(unit: TimePickerUnit) => (event: ChangeEvent<HTMLInputElement>) => {
|
|
110
|
+
onFieldChange(unit, event.currentTarget.value);
|
|
111
|
+
};
|
|
112
|
+
const onFocus =
|
|
113
|
+
(unit: TimePickerUnit) => (event: FocusEvent<HTMLInputElement>) => {
|
|
114
|
+
onFieldFocus(unit, event);
|
|
115
|
+
};
|
|
116
|
+
const onBlur = (unit: TimePickerUnit) => () => onFieldBlur(unit);
|
|
117
|
+
const onKeyDown =
|
|
118
|
+
(unit: TimePickerUnit) => (event: KeyboardEvent<HTMLInputElement>) => {
|
|
119
|
+
onFieldKeyDown(unit, event);
|
|
120
|
+
};
|
|
121
|
+
const onStepperMouseDown = (event: MouseEvent<HTMLButtonElement>) => {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
};
|
|
124
|
+
const onInteractiveClick = (event: MouseEvent<HTMLElement>) => {
|
|
125
|
+
event.stopPropagation();
|
|
126
|
+
};
|
|
127
|
+
const onClockClick = () => {
|
|
128
|
+
hoursRef.current?.focus();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<div
|
|
133
|
+
{...restProps}
|
|
134
|
+
ref={ref}
|
|
135
|
+
className={clsx("input-time input-time-picker", className)}
|
|
136
|
+
data-priority={priority}
|
|
137
|
+
data-size={size}
|
|
138
|
+
data-state={state}
|
|
139
|
+
data-readonly={readOnly ? "true" : undefined}
|
|
140
|
+
data-active-unit={activeUnit ?? undefined}
|
|
141
|
+
data-icon-position={iconPosition}
|
|
142
|
+
onBlur={onRootBlur}
|
|
143
|
+
>
|
|
144
|
+
<div className="input-time-trigger-input">
|
|
145
|
+
{iconPosition === "left" ? (
|
|
146
|
+
<button
|
|
147
|
+
type="button"
|
|
148
|
+
className="input-time-icon-button"
|
|
149
|
+
tabIndex={-1}
|
|
150
|
+
aria-label={iconLabel}
|
|
151
|
+
disabled={disabled}
|
|
152
|
+
onMouseDown={onStepperMouseDown}
|
|
153
|
+
onClick={onClockClick}
|
|
154
|
+
>
|
|
155
|
+
{icon}
|
|
156
|
+
</button>
|
|
157
|
+
) : null}
|
|
158
|
+
<div className="input-time-fields-group">
|
|
159
|
+
<input
|
|
160
|
+
ref={hoursRef}
|
|
161
|
+
className="input-time-field"
|
|
162
|
+
type="text"
|
|
163
|
+
inputMode="numeric"
|
|
164
|
+
autoComplete="off"
|
|
165
|
+
maxLength={2}
|
|
166
|
+
value={fields.hours}
|
|
167
|
+
placeholder={hoursPlaceholder}
|
|
168
|
+
aria-label={hoursInputLabel}
|
|
169
|
+
aria-invalid={state === "error" ? true : undefined}
|
|
170
|
+
disabled={disabled}
|
|
171
|
+
readOnly={readOnly}
|
|
172
|
+
onChange={onChange("hours")}
|
|
173
|
+
onClick={onInteractiveClick}
|
|
174
|
+
onFocus={onFocus("hours")}
|
|
175
|
+
onBlur={onBlur("hours")}
|
|
176
|
+
onKeyDown={onKeyDown("hours")}
|
|
177
|
+
/>
|
|
178
|
+
<span aria-hidden="true">:</span>
|
|
179
|
+
<input
|
|
180
|
+
className="input-time-field"
|
|
181
|
+
type="text"
|
|
182
|
+
inputMode="numeric"
|
|
183
|
+
autoComplete="off"
|
|
184
|
+
maxLength={2}
|
|
185
|
+
value={fields.minutes}
|
|
186
|
+
placeholder={minutesPlaceholder}
|
|
187
|
+
aria-label={minutesInputLabel}
|
|
188
|
+
aria-invalid={state === "error" ? true : undefined}
|
|
189
|
+
disabled={disabled}
|
|
190
|
+
readOnly={readOnly}
|
|
191
|
+
onChange={onChange("minutes")}
|
|
192
|
+
onClick={onInteractiveClick}
|
|
193
|
+
onFocus={onFocus("minutes")}
|
|
194
|
+
onBlur={onBlur("minutes")}
|
|
195
|
+
onKeyDown={onKeyDown("minutes")}
|
|
196
|
+
/>
|
|
197
|
+
{withSeconds ? (
|
|
198
|
+
<>
|
|
199
|
+
<span aria-hidden="true">:</span>
|
|
200
|
+
<input
|
|
201
|
+
className="input-time-field"
|
|
202
|
+
type="text"
|
|
203
|
+
inputMode="numeric"
|
|
204
|
+
autoComplete="off"
|
|
205
|
+
maxLength={2}
|
|
206
|
+
value={fields.seconds}
|
|
207
|
+
placeholder={secondsPlaceholder}
|
|
208
|
+
aria-label={secondsInputLabel}
|
|
209
|
+
aria-invalid={state === "error" ? true : undefined}
|
|
210
|
+
disabled={disabled}
|
|
211
|
+
readOnly={readOnly}
|
|
212
|
+
onChange={onChange("seconds")}
|
|
213
|
+
onClick={onInteractiveClick}
|
|
214
|
+
onFocus={onFocus("seconds")}
|
|
215
|
+
onBlur={onBlur("seconds")}
|
|
216
|
+
onKeyDown={onKeyDown("seconds")}
|
|
217
|
+
/>
|
|
218
|
+
</>
|
|
219
|
+
) : null}
|
|
220
|
+
{format === "12h" ? (
|
|
221
|
+
<select
|
|
222
|
+
className="input-time-period-field"
|
|
223
|
+
value={period}
|
|
224
|
+
aria-label={amPmInputLabel}
|
|
225
|
+
disabled={disabled}
|
|
226
|
+
onClick={onInteractiveClick}
|
|
227
|
+
onChange={event =>
|
|
228
|
+
onPeriodChange(
|
|
229
|
+
event.currentTarget.value === "pm" ? "pm" : "am",
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
>
|
|
233
|
+
<option value="am">오전</option>
|
|
234
|
+
<option value="pm">오후</option>
|
|
235
|
+
</select>
|
|
236
|
+
) : null}
|
|
237
|
+
</div>
|
|
238
|
+
{iconPosition === "right" ? (
|
|
239
|
+
<button
|
|
240
|
+
type="button"
|
|
241
|
+
className="input-time-icon-button"
|
|
242
|
+
tabIndex={-1}
|
|
243
|
+
aria-label={iconLabel}
|
|
244
|
+
disabled={disabled}
|
|
245
|
+
onMouseDown={onStepperMouseDown}
|
|
246
|
+
onClick={onClockClick}
|
|
247
|
+
>
|
|
248
|
+
{icon}
|
|
249
|
+
</button>
|
|
250
|
+
) : null}
|
|
251
|
+
</div>
|
|
252
|
+
{activeUnit && !disabled && !readOnly ? (
|
|
253
|
+
<div className="input-time-stepper" aria-label="시간 값 조절">
|
|
254
|
+
<button
|
|
255
|
+
type="button"
|
|
256
|
+
className="input-time-stepper-button"
|
|
257
|
+
tabIndex={-1}
|
|
258
|
+
aria-label={`${activeUnit} 증가`}
|
|
259
|
+
onMouseDown={onStepperMouseDown}
|
|
260
|
+
onClick={event => {
|
|
261
|
+
onInteractiveClick(event);
|
|
262
|
+
onStep(1);
|
|
263
|
+
}}
|
|
264
|
+
>
|
|
265
|
+
<Calendar.Icon.Chevron.up aria-hidden="true" />
|
|
266
|
+
</button>
|
|
267
|
+
<button
|
|
268
|
+
type="button"
|
|
269
|
+
className="input-time-stepper-button"
|
|
270
|
+
tabIndex={-1}
|
|
271
|
+
aria-label={`${activeUnit} 감소`}
|
|
272
|
+
onMouseDown={onStepperMouseDown}
|
|
273
|
+
onClick={event => {
|
|
274
|
+
onInteractiveClick(event);
|
|
275
|
+
onStep(-1);
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
<Calendar.Icon.Chevron.down aria-hidden="true" />
|
|
279
|
+
</button>
|
|
280
|
+
</div>
|
|
281
|
+
) : null}
|
|
282
|
+
</div>
|
|
283
|
+
);
|
|
284
|
+
},
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
InputTimeTrigger.displayName = "InputTimeTrigger";
|
|
288
|
+
|
|
289
|
+
export default InputTimeTrigger;
|