@semcore/time-picker 16.1.13 → 16.1.14-prerelease.8
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/CHANGELOG.md +7 -0
- package/README.md +4 -4
- package/lib/cjs/component/PickerFormat/PickerFormat.js +84 -0
- package/lib/cjs/component/PickerFormat/PickerFormat.js.map +1 -0
- package/lib/cjs/component/PickerFormat/PickerFormat.type.js +2 -0
- package/lib/cjs/component/PickerFormat/PickerFormat.type.js.map +1 -0
- package/lib/cjs/{style/time-picker.shadow.css → component/PickerFormat/picker-format.shadow.css} +1 -56
- package/lib/cjs/component/PickerInput/PickerInput.js +228 -0
- package/lib/cjs/component/PickerInput/PickerInput.js.map +1 -0
- package/lib/cjs/component/PickerInput/PickerInput.type.js +2 -0
- package/lib/cjs/component/PickerInput/PickerInput.type.js.map +1 -0
- package/lib/cjs/component/PickerInput/picker-input.shadow.css +11 -0
- package/lib/cjs/component/TimePicker/TimePicker.js +220 -0
- package/lib/cjs/component/TimePicker/TimePicker.js.map +1 -0
- package/lib/cjs/component/TimePicker/TimePicker.type.js +2 -0
- package/lib/cjs/component/TimePicker/TimePicker.type.js.map +1 -0
- package/lib/cjs/component/TimePicker/time-picker.shadow.css +34 -0
- package/lib/cjs/entity/TimePickerEntity.js +73 -0
- package/lib/cjs/entity/TimePickerEntity.js.map +1 -0
- package/lib/cjs/index.js +9 -8
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js +16 -16
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/es6/component/PickerFormat/PickerFormat.js +79 -0
- package/lib/es6/component/PickerFormat/PickerFormat.js.map +1 -0
- package/lib/es6/component/PickerFormat/PickerFormat.type.js +2 -0
- package/lib/es6/component/PickerFormat/PickerFormat.type.js.map +1 -0
- package/lib/{esm/style/time-picker.shadow.css → es6/component/PickerFormat/picker-format.shadow.css} +1 -56
- package/lib/es6/component/PickerInput/PickerInput.js +222 -0
- package/lib/es6/component/PickerInput/PickerInput.js.map +1 -0
- package/lib/es6/component/PickerInput/PickerInput.type.js +2 -0
- package/lib/es6/component/PickerInput/PickerInput.type.js.map +1 -0
- package/lib/es6/component/PickerInput/picker-input.shadow.css +11 -0
- package/lib/es6/component/TimePicker/TimePicker.js +216 -0
- package/lib/es6/component/TimePicker/TimePicker.js.map +1 -0
- package/lib/es6/component/TimePicker/TimePicker.type.js +2 -0
- package/lib/es6/component/TimePicker/TimePicker.type.js.map +1 -0
- package/lib/es6/component/TimePicker/time-picker.shadow.css +34 -0
- package/lib/es6/entity/TimePickerEntity.js +66 -0
- package/lib/es6/entity/TimePickerEntity.js.map +1 -0
- package/lib/es6/index.js +2 -2
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/translations/__intergalactic-dynamic-locales.js +15 -15
- package/lib/es6/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/esm/component/PickerFormat/PickerFormat.mjs +84 -0
- package/lib/{es6/style/time-picker.shadow.css → esm/component/PickerFormat/picker-format.shadow.css} +1 -56
- package/lib/esm/component/PickerInput/PickerInput.mjs +227 -0
- package/lib/esm/component/PickerInput/picker-input.shadow.css +11 -0
- package/lib/esm/component/TimePicker/TimePicker.mjs +220 -0
- package/lib/esm/component/TimePicker/time-picker.shadow.css +34 -0
- package/lib/esm/entity/TimePickerEntity.mjs +65 -0
- package/lib/esm/index.mjs +2 -7
- package/lib/esm/translations/__intergalactic-dynamic-locales.mjs +1 -1
- package/lib/types/component/PickerFormat/PickerFormat.d.ts +17 -0
- package/lib/types/component/PickerFormat/PickerFormat.type.d.ts +16 -0
- package/lib/types/component/PickerInput/PickerInput.d.ts +54 -0
- package/lib/types/component/PickerInput/PickerInput.type.d.ts +13 -0
- package/lib/types/component/TimePicker/TimePicker.d.ts +3 -0
- package/lib/types/component/TimePicker/TimePicker.type.d.ts +50 -0
- package/lib/types/entity/TimePickerEntity.d.ts +22 -0
- package/lib/types/index.d.ts +2 -63
- package/lib/types/translations/__intergalactic-dynamic-locales.d.ts +114 -0
- package/package.json +6 -6
- package/vite.config.ts +1 -4
- package/lib/cjs/PickerFormat.js +0 -81
- package/lib/cjs/PickerFormat.js.map +0 -1
- package/lib/cjs/PickerInput.js +0 -286
- package/lib/cjs/PickerInput.js.map +0 -1
- package/lib/cjs/TimePicker.js +0 -348
- package/lib/cjs/TimePicker.js.map +0 -1
- package/lib/cjs/index.d.js +0 -2
- package/lib/cjs/index.d.js.map +0 -1
- package/lib/es6/PickerFormat.js +0 -75
- package/lib/es6/PickerFormat.js.map +0 -1
- package/lib/es6/PickerInput.js +0 -281
- package/lib/es6/PickerInput.js.map +0 -1
- package/lib/es6/TimePicker.js +0 -339
- package/lib/es6/TimePicker.js.map +0 -1
- package/lib/es6/index.d.js +0 -2
- package/lib/es6/index.d.js.map +0 -1
- package/lib/esm/PickerFormat.mjs +0 -67
- package/lib/esm/PickerInput.mjs +0 -263
- package/lib/esm/TimePicker.mjs +0 -297
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import _applyDecs from "@babel/runtime/helpers/esm/applyDecs2311";
|
|
3
|
+
import _identity from "@babel/runtime/helpers/esm/identity";
|
|
4
|
+
import { createComponent, sstyled, Component, assignProps } from "@semcore/core";
|
|
5
|
+
import { ScreenReaderOnly, Box } from "@semcore/base-components";
|
|
6
|
+
import propsObserver from "@semcore/core/lib/decorators/propsObserver";
|
|
7
|
+
import reactive from "@semcore/core/lib/decorators/reactive";
|
|
8
|
+
import i18nEnhance from "@semcore/core/lib/utils/enhances/i18nEnhance";
|
|
9
|
+
import Input from "@semcore/input";
|
|
10
|
+
import React from "react";
|
|
11
|
+
import TimePickerEntity from "../../entity/TimePickerEntity.mjs";
|
|
12
|
+
import { localizedMessages } from "../../translations/__intergalactic-dynamic-locales.mjs";
|
|
13
|
+
import TimePickerFormat from "../PickerFormat/PickerFormat.mjs";
|
|
14
|
+
import { Minutes, Hours } from "../PickerInput/PickerInput.mjs";
|
|
15
|
+
var _Class, _TimePickerRoot3;
|
|
16
|
+
let _initClass, _classDecs, _entityDecs, _init_entity, _init_extra_entity, _TimePickerRoot2, _ref5;
|
|
17
|
+
/*!__reshadow-styles__:"./time-picker.shadow.css"*/
|
|
18
|
+
const style = (
|
|
19
|
+
/*__reshadow_css_start__*/
|
|
20
|
+
(sstyled.insert(
|
|
21
|
+
/*__inner_css_start__*/
|
|
22
|
+
".___STimePicker_17xeh_gg_{position:relative;width:auto;outline:0}.___STimePicker_17xeh_gg_ .___SPickerInput_17xeh_gg_{box-sizing:content-box;text-align:center;z-index:1;height:1.5em}.___STimePicker_17xeh_gg_ .___SPickerInput_17xeh_gg_.__placeholder_17xeh_gg_{text-overflow:initial}.___STimePicker_17xeh_gg_ .___SPickerInput_17xeh_gg_:focus{outline:0;background-color:var(--intergalactic-bg-highlight-focus, rgba(0, 143, 248, 0.2))}.___STimePicker_17xeh_gg_.__disabled_17xeh_gg_{color:var(--intergalactic-text-secondary, #6c6e79);cursor:default}.___STimePickerSeparator_17xeh_gg_{color:var(--intergalactic-text-primary, #191b23)}.___STimePickerSeparator_17xeh_gg_.__disabled_17xeh_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);pointer-events:none}",
|
|
23
|
+
/*__inner_css_end__*/
|
|
24
|
+
"17xeh_gg_"
|
|
25
|
+
), /*__reshadow_css_end__*/
|
|
26
|
+
{
|
|
27
|
+
"__STimePicker": "___STimePicker_17xeh_gg_",
|
|
28
|
+
"_disabled": "__disabled_17xeh_gg_",
|
|
29
|
+
"__STimePickerSeparator": "___STimePickerSeparator_17xeh_gg_",
|
|
30
|
+
"__SPickerInput": "___SPickerInput_17xeh_gg_",
|
|
31
|
+
"_placeholder": "__placeholder_17xeh_gg_"
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
_classDecs = [propsObserver(["value", "is12Hour"])];
|
|
35
|
+
let _TimePickerRoot;
|
|
36
|
+
new (_TimePickerRoot2 = (_ref5 = (_entityDecs = reactive(["meridiem"], function() {
|
|
37
|
+
this.forceUpdate();
|
|
38
|
+
}), "hoursInputRef"), _TimePickerRoot3 = class TimePickerRoot extends Component {
|
|
39
|
+
constructor(...args) {
|
|
40
|
+
super(...args);
|
|
41
|
+
_defineProperty(this, _ref5, /* @__PURE__ */ React.createRef());
|
|
42
|
+
_defineProperty(this, "minutesInputRef", /* @__PURE__ */ React.createRef());
|
|
43
|
+
_defineProperty(this, "state", {
|
|
44
|
+
ariaLabel: ""
|
|
45
|
+
});
|
|
46
|
+
_defineProperty(this, "entity", _init_entity(this, new TimePickerEntity(this.props.value ?? this.props.defaultValue, this.props.is12Hour)));
|
|
47
|
+
_defineProperty(this, "handleValueChange", (_init_extra_entity(this), (value, field, event) => {
|
|
48
|
+
this.entity[field] = value;
|
|
49
|
+
this.handlers.value(this.entity.toString(), event);
|
|
50
|
+
}));
|
|
51
|
+
_defineProperty(this, "handleMeridiemClick", (event) => {
|
|
52
|
+
this.entity.toggleMeridiem();
|
|
53
|
+
this.handlers.value(this.entity.toString(), event);
|
|
54
|
+
});
|
|
55
|
+
_defineProperty(this, "getCommonPickerInputProps", () => {
|
|
56
|
+
const {
|
|
57
|
+
is12Hour,
|
|
58
|
+
size,
|
|
59
|
+
disabled
|
|
60
|
+
} = this.asProps;
|
|
61
|
+
return {
|
|
62
|
+
size,
|
|
63
|
+
is12Hour,
|
|
64
|
+
disabled,
|
|
65
|
+
$onValueChange: this.handleValueChange,
|
|
66
|
+
minutesInputRef: this.minutesInputRef,
|
|
67
|
+
hoursInputRef: this.hoursInputRef
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
_defineProperty(this, "getHoursProps", () => {
|
|
71
|
+
return {
|
|
72
|
+
...this.getCommonPickerInputProps(),
|
|
73
|
+
time: this.entity.hours,
|
|
74
|
+
ariaLabel: this.asProps.getI18nText("hours"),
|
|
75
|
+
ref: this.hoursInputRef
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
_defineProperty(this, "getMinutesProps", () => {
|
|
79
|
+
return {
|
|
80
|
+
...this.getCommonPickerInputProps(),
|
|
81
|
+
time: this.entity.minutes,
|
|
82
|
+
ariaLabel: this.asProps.getI18nText("minutes"),
|
|
83
|
+
ref: this.minutesInputRef
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
componentDidMount() {
|
|
88
|
+
const {
|
|
89
|
+
id,
|
|
90
|
+
"aria-describedby": ariaDescribedBy
|
|
91
|
+
} = this.asProps;
|
|
92
|
+
const selector = `[for=${id}]`;
|
|
93
|
+
const element = document.querySelector(selector) ?? document.querySelector(`#${ariaDescribedBy}`);
|
|
94
|
+
if (element) {
|
|
95
|
+
this.setState({
|
|
96
|
+
ariaLabel: element.textContent
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
onPropsChange(changedProps) {
|
|
101
|
+
const {
|
|
102
|
+
value,
|
|
103
|
+
is12Hour
|
|
104
|
+
} = changedProps;
|
|
105
|
+
if (value !== void 0) {
|
|
106
|
+
const [hours = "", minutes = ""] = value.split(":");
|
|
107
|
+
this.entity.hours = hours;
|
|
108
|
+
this.entity.minutes = minutes;
|
|
109
|
+
}
|
|
110
|
+
if (is12Hour !== void 0) {
|
|
111
|
+
this.entity.is12Hour = is12Hour;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
uncontrolledProps() {
|
|
115
|
+
return {
|
|
116
|
+
value: null
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
getSeparatorProps() {
|
|
120
|
+
return {
|
|
121
|
+
disabled: this.asProps.disabled,
|
|
122
|
+
hoursInputRef: this.hoursInputRef
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
getFormatProps() {
|
|
126
|
+
const {
|
|
127
|
+
size,
|
|
128
|
+
disabled,
|
|
129
|
+
getI18nText
|
|
130
|
+
} = this.asProps;
|
|
131
|
+
return {
|
|
132
|
+
size,
|
|
133
|
+
disabled,
|
|
134
|
+
meridiem: this.entity.meridiem,
|
|
135
|
+
onClick: this.handleMeridiemClick,
|
|
136
|
+
getI18nText
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
render() {
|
|
140
|
+
var _ref = this.asProps, _ref3;
|
|
141
|
+
const STimePicker = Input;
|
|
142
|
+
const {
|
|
143
|
+
styles,
|
|
144
|
+
Children,
|
|
145
|
+
value,
|
|
146
|
+
is12Hour,
|
|
147
|
+
getI18nText,
|
|
148
|
+
id
|
|
149
|
+
} = this.asProps;
|
|
150
|
+
const time = `${this.entity.hours}:${this.entity.minutes}`;
|
|
151
|
+
const meridiem = is12Hour ? this.entity.meridiem : "";
|
|
152
|
+
const label = value ? `${this.state.ariaLabel} ${getI18nText("title", {
|
|
153
|
+
time,
|
|
154
|
+
meridiem
|
|
155
|
+
})}` : `${this.state.ariaLabel} ${getI18nText("titleEmpty")}`;
|
|
156
|
+
return _ref3 = sstyled(styles), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(STimePicker, _ref3.cn("STimePicker", {
|
|
157
|
+
...assignProps({
|
|
158
|
+
"role": "group",
|
|
159
|
+
"aria-label": label,
|
|
160
|
+
"__excludeProps": ["value", "id"]
|
|
161
|
+
}, _ref)
|
|
162
|
+
}), /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {}))), /* @__PURE__ */ React.createElement(ScreenReaderOnly, _ref3.cn("ScreenReaderOnly", {
|
|
163
|
+
"tag": "input",
|
|
164
|
+
"tabIndex": -1,
|
|
165
|
+
"id": id,
|
|
166
|
+
"aria-hidden": true,
|
|
167
|
+
"value": `${time} ${meridiem}`
|
|
168
|
+
})));
|
|
169
|
+
}
|
|
170
|
+
}, {
|
|
171
|
+
e: [_init_entity, _init_extra_entity],
|
|
172
|
+
c: [_TimePickerRoot, _initClass]
|
|
173
|
+
} = _applyDecs(_TimePickerRoot3, _classDecs, [[_entityDecs, 0, "entity"]], 0, void 0, Component), _TimePickerRoot3), _Class = class extends _identity {
|
|
174
|
+
constructor() {
|
|
175
|
+
super(_TimePickerRoot), _defineProperty(this, "displayName", "TimePicker"), _defineProperty(this, "style", style), _defineProperty(this, "enhance", [i18nEnhance(localizedMessages)]), _defineProperty(this, "defaultProps", ({
|
|
176
|
+
is12Hour
|
|
177
|
+
}) => ({
|
|
178
|
+
defaultValue: "",
|
|
179
|
+
size: "m",
|
|
180
|
+
children: /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TimePicker.Hours, null), /* @__PURE__ */ React.createElement(TimePicker.Separator, null), /* @__PURE__ */ React.createElement(TimePicker.Minutes, null), is12Hour && /* @__PURE__ */ React.createElement(TimePicker.Format, null)),
|
|
181
|
+
locale: "en"
|
|
182
|
+
})), _initClass();
|
|
183
|
+
}
|
|
184
|
+
}, _defineProperty(_Class, _TimePickerRoot2, void 0), _Class)();
|
|
185
|
+
class Separator extends Component {
|
|
186
|
+
constructor(...args) {
|
|
187
|
+
super(...args);
|
|
188
|
+
_defineProperty(this, "handlerClick", () => {
|
|
189
|
+
var _a;
|
|
190
|
+
if (this.asProps.hoursInputRef.current) {
|
|
191
|
+
(_a = this.asProps.hoursInputRef.current) == null ? void 0 : _a.focus();
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
render() {
|
|
196
|
+
var _ref2 = this.asProps, _ref4;
|
|
197
|
+
const STimePickerSeparator = Box;
|
|
198
|
+
const {
|
|
199
|
+
styles
|
|
200
|
+
} = this.asProps;
|
|
201
|
+
return _ref4 = sstyled(styles), /* @__PURE__ */ React.createElement(STimePickerSeparator, _ref4.cn("STimePickerSeparator", {
|
|
202
|
+
...assignProps({
|
|
203
|
+
"onClick": this.handlerClick,
|
|
204
|
+
"aria-hidden": "true"
|
|
205
|
+
}, _ref2)
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
_defineProperty(Separator, "defaultProps", {
|
|
210
|
+
children: ":"
|
|
211
|
+
});
|
|
212
|
+
const TimePicker = createComponent(_TimePickerRoot, {
|
|
213
|
+
Hours,
|
|
214
|
+
Minutes,
|
|
215
|
+
Separator,
|
|
216
|
+
Format: TimePickerFormat
|
|
217
|
+
});
|
|
218
|
+
export {
|
|
219
|
+
TimePicker as default
|
|
220
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
STimePicker {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: auto;
|
|
4
|
+
outline: none;
|
|
5
|
+
|
|
6
|
+
SPickerInput {
|
|
7
|
+
box-sizing: content-box;
|
|
8
|
+
text-align: center;
|
|
9
|
+
z-index: 1;
|
|
10
|
+
height: 1.5em;
|
|
11
|
+
|
|
12
|
+
&[placeholder] {
|
|
13
|
+
text-overflow: initial;
|
|
14
|
+
}
|
|
15
|
+
&:focus {
|
|
16
|
+
outline: none;
|
|
17
|
+
background-color: var(--intergalactic-bg-highlight-focus, rgba(0, 143, 248, 0.2));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
STimePicker[disabled] {
|
|
23
|
+
color: var(--intergalactic-text-secondary, #6c6e79);
|
|
24
|
+
cursor: default;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
STimePickerSeparator {
|
|
28
|
+
color: var(--intergalactic-text-primary, #191b23);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
STimePickerSeparator[disabled] {
|
|
32
|
+
opacity: var(--intergalactic-disabled-opacity, 0.3);
|
|
33
|
+
pointer-events: none;
|
|
34
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
class TimePickerEntity {
|
|
3
|
+
constructor(value = ":", is12Hour = false) {
|
|
4
|
+
_defineProperty(this, "_hours", "");
|
|
5
|
+
_defineProperty(this, "_minutes", "");
|
|
6
|
+
_defineProperty(this, "_is12Hour", void 0);
|
|
7
|
+
_defineProperty(this, "_meridiem", "AM");
|
|
8
|
+
const [hours = "", minutes = ""] = value.split(":");
|
|
9
|
+
this._is12Hour = is12Hour;
|
|
10
|
+
this._hours = hours;
|
|
11
|
+
this._minutes = minutes;
|
|
12
|
+
}
|
|
13
|
+
get meridiem() {
|
|
14
|
+
return this._meridiem;
|
|
15
|
+
}
|
|
16
|
+
get hours() {
|
|
17
|
+
return this._is12Hour ? this.formatHoursTo12(this._hours) : this.formatHoursTo24(this._hours);
|
|
18
|
+
}
|
|
19
|
+
get minutes() {
|
|
20
|
+
return this._minutes && this.withLeadingZero(this._minutes);
|
|
21
|
+
}
|
|
22
|
+
set is12Hour(newIs12Hour) {
|
|
23
|
+
this._is12Hour = newIs12Hour;
|
|
24
|
+
}
|
|
25
|
+
set hours(newHours) {
|
|
26
|
+
this._hours = newHours;
|
|
27
|
+
}
|
|
28
|
+
set minutes(newMinutes) {
|
|
29
|
+
this._minutes = newMinutes;
|
|
30
|
+
}
|
|
31
|
+
set meridiem(newMeridiem) {
|
|
32
|
+
this._meridiem = newMeridiem;
|
|
33
|
+
}
|
|
34
|
+
withLeadingZero(value) {
|
|
35
|
+
return String(value).padStart(2, "0");
|
|
36
|
+
}
|
|
37
|
+
formatHoursTo12(hours) {
|
|
38
|
+
const numberHours = Number.parseInt(hours, 10);
|
|
39
|
+
if (Number.isNaN(numberHours)) return hours;
|
|
40
|
+
if (numberHours === 0) {
|
|
41
|
+
return "12";
|
|
42
|
+
} else if (numberHours > 12) {
|
|
43
|
+
return this.withLeadingZero(numberHours - 12);
|
|
44
|
+
}
|
|
45
|
+
return this.withLeadingZero(numberHours);
|
|
46
|
+
}
|
|
47
|
+
formatHoursTo24(hours) {
|
|
48
|
+
const numberHours = Number.parseInt(hours, 10);
|
|
49
|
+
if (Number.isNaN(numberHours)) return hours;
|
|
50
|
+
if (this.meridiem === "AM") {
|
|
51
|
+
return this.withLeadingZero(numberHours === 12 ? 0 : numberHours);
|
|
52
|
+
}
|
|
53
|
+
return this.withLeadingZero(numberHours < 12 ? numberHours + 12 : numberHours);
|
|
54
|
+
}
|
|
55
|
+
toggleMeridiem() {
|
|
56
|
+
this.meridiem = this._meridiem === "AM" ? "PM" : "AM";
|
|
57
|
+
}
|
|
58
|
+
toString() {
|
|
59
|
+
const hours = this._is12Hour ? this.formatHoursTo24(this.hours) : this.hours;
|
|
60
|
+
return `${hours}:${this.minutes}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
TimePickerEntity as default
|
|
65
|
+
};
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { default as default2
|
|
1
|
+
import { default as default2 } from "./component/TimePicker/TimePicker.mjs";
|
|
2
2
|
export {
|
|
3
|
-
default2 as default
|
|
4
|
-
formatHoursTo12,
|
|
5
|
-
formatHoursTo24,
|
|
6
|
-
intOrDefault,
|
|
7
|
-
meridiemByHours,
|
|
8
|
-
withLeadingZero
|
|
3
|
+
default2 as default
|
|
9
4
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Component } from '@semcore/core';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { TimePickerFormatProps, TimePickerFormatPropsInternal } from './PickerFormat.type';
|
|
4
|
+
declare class TimePickerFormat extends Component<TimePickerFormatProps, typeof TimePickerFormat.enhance, {}, TimePickerFormatPropsInternal> {
|
|
5
|
+
static style: {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
8
|
+
static enhance: readonly [(props: any) => {
|
|
9
|
+
uid: ReturnType<typeof import("@semcore/core/lib/utils/uniqueID").useUID>;
|
|
10
|
+
}];
|
|
11
|
+
state: {
|
|
12
|
+
changedFormatNotice: string;
|
|
13
|
+
};
|
|
14
|
+
handleClick: () => void;
|
|
15
|
+
render(): React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export default TimePickerFormat;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BoxProps } from '@semcore/base-components';
|
|
2
|
+
import type { useI18n } from '@semcore/core/lib/utils/enhances/WithI18n';
|
|
3
|
+
import type { TimePickerMeridiem } from '../TimePicker/TimePicker.type';
|
|
4
|
+
export type TimePickerFormatProps = BoxProps & {};
|
|
5
|
+
export type TimePickerFormatPropsInternal = {
|
|
6
|
+
/** @Internal */
|
|
7
|
+
getI18nText: ReturnType<typeof useI18n>;
|
|
8
|
+
/** @Internal */
|
|
9
|
+
size: 'm' | 'l';
|
|
10
|
+
/** @Internal */
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
/** @Internal */
|
|
13
|
+
meridiem: TimePickerMeridiem;
|
|
14
|
+
/** @Internal */
|
|
15
|
+
onClick: (event: React.SyntheticEvent) => void;
|
|
16
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Component } from '@semcore/core';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { PickerInputMinMax, PickerInputProps } from './PickerInput.type';
|
|
4
|
+
import type { TimePickerField } from '../TimePicker/TimePicker.type';
|
|
5
|
+
type State = {
|
|
6
|
+
dirtyValue?: string;
|
|
7
|
+
visible: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare abstract class AbstractPickerInput extends Component<PickerInputProps, [], {}, {}, State> {
|
|
10
|
+
static style: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
};
|
|
13
|
+
static defaultProps: (_: PickerInputProps) => {
|
|
14
|
+
placeholder: string;
|
|
15
|
+
offset: number[];
|
|
16
|
+
};
|
|
17
|
+
state: State;
|
|
18
|
+
inputRef: React.RefObject<unknown>;
|
|
19
|
+
abstract get field(): TimePickerField;
|
|
20
|
+
abstract get minMax(): PickerInputMinMax;
|
|
21
|
+
abstract handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void;
|
|
22
|
+
parseValueWithMinMax: (value: string) => string;
|
|
23
|
+
dispatchOnChange(value: string, event: React.SyntheticEvent): void;
|
|
24
|
+
submitChanges(event: React.SyntheticEvent): void;
|
|
25
|
+
handleChange: (value: string, event: React.SyntheticEvent) => void;
|
|
26
|
+
handleBlur: (event: React.SyntheticEvent) => void;
|
|
27
|
+
handleSelect: (value: string, event: React.SyntheticEvent) => void;
|
|
28
|
+
handleVisibleChange: (visible: boolean) => void;
|
|
29
|
+
render(): React.ReactNode;
|
|
30
|
+
}
|
|
31
|
+
declare class Hours extends AbstractPickerInput {
|
|
32
|
+
static defaultProps: (props: PickerInputProps) => {
|
|
33
|
+
ml: number | undefined;
|
|
34
|
+
placeholder: string;
|
|
35
|
+
offset: number[];
|
|
36
|
+
};
|
|
37
|
+
get field(): TimePickerField;
|
|
38
|
+
get minMax(): PickerInputMinMax;
|
|
39
|
+
focusNext(): void;
|
|
40
|
+
handleKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
41
|
+
componentDidUpdate(_: PickerInputProps, prevState: State): void;
|
|
42
|
+
}
|
|
43
|
+
declare class Minutes extends AbstractPickerInput {
|
|
44
|
+
static defaultProps: (props: PickerInputProps) => {
|
|
45
|
+
mr: number | undefined;
|
|
46
|
+
placeholder: string;
|
|
47
|
+
offset: number[];
|
|
48
|
+
};
|
|
49
|
+
get field(): TimePickerField;
|
|
50
|
+
get minMax(): PickerInputMinMax;
|
|
51
|
+
focusPrev(): void;
|
|
52
|
+
handleKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
53
|
+
}
|
|
54
|
+
export { Hours, Minutes };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SelectProps } from '@semcore/select';
|
|
2
|
+
import type { TimePickerField, TimePickerItemProps } from '../TimePicker/TimePicker.type';
|
|
3
|
+
export type PickerInputProps = SelectProps & TimePickerItemProps & {
|
|
4
|
+
time: string;
|
|
5
|
+
size?: 'm' | 'l';
|
|
6
|
+
is12Hour?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
$onValueChange: (value: string, field: TimePickerField, event: React.SyntheticEvent) => void;
|
|
9
|
+
minutesInputRef: React.RefObject<HTMLElement>;
|
|
10
|
+
hoursInputRef: React.RefObject<HTMLElement>;
|
|
11
|
+
ariaLabel: string;
|
|
12
|
+
};
|
|
13
|
+
export type PickerInputMinMax = [number, number];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Box } from '@semcore/base-components';
|
|
2
|
+
import type { PropGetterFn, Intergalactic } from '@semcore/core';
|
|
3
|
+
import type { InputProps, InputValueProps } from '@semcore/input';
|
|
4
|
+
import type { TimePickerFormatProps } from '../PickerFormat/PickerFormat.type';
|
|
5
|
+
export type TimePickerProps = Omit<InputProps, 'size'> & {
|
|
6
|
+
/** Time in the hh:mm format */
|
|
7
|
+
value?: string;
|
|
8
|
+
/** Default value if `value` property is not provided */
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
/** The event responses upon time changing */
|
|
11
|
+
onChange?: (time: string, event?: React.SyntheticEvent) => void;
|
|
12
|
+
/** In charge of the component blocking */
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
/** Control size
|
|
15
|
+
* @default m */
|
|
16
|
+
size?: 'm' | 'l';
|
|
17
|
+
/** 12-hour time format */
|
|
18
|
+
is12Hour?: boolean;
|
|
19
|
+
/** Specifies the locale for i18n support */
|
|
20
|
+
locale?: string;
|
|
21
|
+
};
|
|
22
|
+
export type TimePickerSeparatorProps = {
|
|
23
|
+
/** @Internal */
|
|
24
|
+
hoursInputRef: React.RefObject<HTMLElement>;
|
|
25
|
+
/** @Internal */
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
};
|
|
28
|
+
export type TimePickerItemProps = InputValueProps & {
|
|
29
|
+
/** Step for changing of the values in the dropdown list */
|
|
30
|
+
step?: number;
|
|
31
|
+
};
|
|
32
|
+
export type TimePickerContext = {
|
|
33
|
+
getHoursProps: PropGetterFn;
|
|
34
|
+
getFormatProps: PropGetterFn;
|
|
35
|
+
getMinutesProps: PropGetterFn;
|
|
36
|
+
getSeparatorProps: PropGetterFn;
|
|
37
|
+
};
|
|
38
|
+
export type TimePickerHandlers = {
|
|
39
|
+
value: (value: string) => void;
|
|
40
|
+
};
|
|
41
|
+
export type TimePickerMeridiem = 'AM' | 'PM';
|
|
42
|
+
export type TimePickerField = 'hours' | 'minutes';
|
|
43
|
+
export type TimePickerComponent = Intergalactic.Component<'div', TimePickerProps, TimePickerContext, [
|
|
44
|
+
handlers: TimePickerHandlers
|
|
45
|
+
]> & {
|
|
46
|
+
Hours: Intergalactic.Component<'div', TimePickerItemProps>;
|
|
47
|
+
Minutes: Intergalactic.Component<'div', TimePickerItemProps>;
|
|
48
|
+
Separator: typeof Box;
|
|
49
|
+
Format: Intergalactic.Component<'div', TimePickerFormatProps>;
|
|
50
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TimePickerMeridiem } from '../component/TimePicker/TimePicker.type';
|
|
2
|
+
declare class TimePickerEntity {
|
|
3
|
+
private _hours;
|
|
4
|
+
private _minutes;
|
|
5
|
+
private _is12Hour;
|
|
6
|
+
private _meridiem;
|
|
7
|
+
constructor(value?: string, // should be in the format 'HH:mm'
|
|
8
|
+
is12Hour?: boolean);
|
|
9
|
+
get meridiem(): TimePickerMeridiem;
|
|
10
|
+
get hours(): string;
|
|
11
|
+
get minutes(): string;
|
|
12
|
+
set is12Hour(newIs12Hour: boolean);
|
|
13
|
+
set hours(newHours: string);
|
|
14
|
+
set minutes(newMinutes: string);
|
|
15
|
+
private set meridiem(value);
|
|
16
|
+
private withLeadingZero;
|
|
17
|
+
private formatHoursTo12;
|
|
18
|
+
private formatHoursTo24;
|
|
19
|
+
toggleMeridiem(): void;
|
|
20
|
+
toString(): string;
|
|
21
|
+
}
|
|
22
|
+
export default TimePickerEntity;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,63 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { InputProps, InputValueProps } from '@semcore/input';
|
|
4
|
-
import type React from 'react';
|
|
5
|
-
|
|
6
|
-
/** @deprecated */
|
|
7
|
-
export interface ITimePickerProps extends TimePickerProps, UnknownProperties {}
|
|
8
|
-
export type TimePickerProps = Omit<InputProps, 'size'> & {
|
|
9
|
-
/** Time in the hh:mm format */
|
|
10
|
-
value?: string;
|
|
11
|
-
/** Default value if `value` property is not provided */
|
|
12
|
-
defaultValue?: string;
|
|
13
|
-
/** The event responses upon time changing */
|
|
14
|
-
onChange?: (time: string, event?: React.SyntheticEvent) => void;
|
|
15
|
-
/** In charge of the component blocking */
|
|
16
|
-
disabled?: boolean;
|
|
17
|
-
/** Control size
|
|
18
|
-
* @default m */
|
|
19
|
-
size?: 'm' | 'l';
|
|
20
|
-
/** 12-hour time format */
|
|
21
|
-
is12Hour?: boolean;
|
|
22
|
-
/** Specifies the locale for i18n support */
|
|
23
|
-
locale?: string;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/** @deprecated */
|
|
27
|
-
export interface ITimePickerItemProps extends TimePickerItemProps, UnknownProperties {}
|
|
28
|
-
export type TimePickerItemProps = InputValueProps & {
|
|
29
|
-
/** Step for changing of the values in the dropdown list */
|
|
30
|
-
step?: number;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/** @deprecated */
|
|
34
|
-
export interface ITimePickerFormatProps extends TimePickerFormatProps, UnknownProperties {}
|
|
35
|
-
export type TimePickerFormatProps = BoxProps & {};
|
|
36
|
-
|
|
37
|
-
/** @deprecated */
|
|
38
|
-
export interface ITimePickerContext extends TimePickerContext, UnknownProperties {}
|
|
39
|
-
export type TimePickerContext = {
|
|
40
|
-
getHoursProps: PropGetterFn;
|
|
41
|
-
getFormatProps: PropGetterFn;
|
|
42
|
-
getMinutesProps: PropGetterFn;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/** @deprecated */
|
|
46
|
-
export interface ITimePickerHandlers extends TimePickerHandlers, UnknownProperties {}
|
|
47
|
-
export type TimePickerHandlers = {
|
|
48
|
-
value: (value: string) => void;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
declare const TimePicker: Intergalactic.Component<
|
|
52
|
-
'div',
|
|
53
|
-
TimePickerProps,
|
|
54
|
-
TimePickerContext,
|
|
55
|
-
[handlers: TimePickerHandlers]
|
|
56
|
-
> & {
|
|
57
|
-
Hours: Intergalactic.Component<'div', TimePickerItemProps>;
|
|
58
|
-
Minutes: Intergalactic.Component<'div', TimePickerItemProps>;
|
|
59
|
-
Separator: typeof Box;
|
|
60
|
-
Format: Intergalactic.Component<'div', TimePickerFormatProps>;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export default TimePicker;
|
|
1
|
+
export { default } from './component/TimePicker/TimePicker';
|
|
2
|
+
export * from './component/TimePicker/TimePicker.type';
|