@semcore/time-picker 4.52.0 → 4.52.1

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.
@@ -1,108 +1,150 @@
1
- import b from "@babel/runtime/helpers/esm/objectSpread2";
2
- import w from "@babel/runtime/helpers/esm/slicedToArray";
3
- import M from "@babel/runtime/helpers/esm/classCallCheck";
4
- import z from "@babel/runtime/helpers/esm/createClass";
5
- import m from "@babel/runtime/helpers/esm/assertThisInitialized";
6
- import H from "@babel/runtime/helpers/esm/inherits";
7
- import $ from "@babel/runtime/helpers/esm/createSuper";
8
- import p from "@babel/runtime/helpers/esm/defineProperty";
9
- import { sstyled as D } from "@semcore/utils/lib/core/index";
10
- import q, { sstyled as N, assignProps as C, Component as R } from "@semcore/core";
11
- import g from "react";
12
- import B from "@semcore/input";
13
- import { Box as L } from "@semcore/flex-box";
14
- import { Hours as O, Minutes as j } from "./PickerInput.mjs";
15
- import Z from "./PickerFormat.mjs";
16
- import { localizedMessages as E } from "./translations/__intergalactic-dynamic-locales.mjs";
17
- import G from "@semcore/utils/lib/enhances/i18nEnhance";
18
- import J from "@semcore/utils/lib/enhances/keyboardFocusEnhance";
19
- var K = (
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
5
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
7
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
8
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
+ import { sstyled } from "@semcore/utils/lib/core/index";
10
+ import createComponent, { sstyled as sstyled$1, assignProps, Component } from "@semcore/core";
11
+ import React from "react";
12
+ import Input from "@semcore/input";
13
+ import { Box } from "@semcore/flex-box";
14
+ import { Hours, Minutes } from "./PickerInput.mjs";
15
+ import TimePickerFormat from "./PickerFormat.mjs";
16
+ import { localizedMessages } from "./translations/__intergalactic-dynamic-locales.mjs";
17
+ import i18nEnhance from "@semcore/utils/lib/enhances/i18nEnhance";
18
+ import keyboardFocusEnhance from "@semcore/utils/lib/enhances/keyboardFocusEnhance";
19
+ /*!__reshadow-styles__:"./style/time-picker.shadow.css"*/
20
+ var style = (
20
21
  /*__reshadow_css_start__*/
21
- (D.insert(
22
+ (sstyled.insert(
22
23
  /*__inner_css_start__*/
23
- ".___STimePicker_6rpw6_gg_{position:relative;width:auto;outline:0}.___STimePicker_6rpw6_gg_.__keyboardFocused_6rpw6_gg_:focus{box-shadow:var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 143, 248, 0.5))}.___STimePicker_6rpw6_gg_.__disabled_6rpw6_gg_{color:var(--intergalactic-text-secondary, #6c6e79);cursor:default}.___SPickerInput_6rpw6_gg_{box-sizing:content-box;text-align:center;z-index:1;height:1.5em}.___SPickerInput_6rpw6_gg_.__placeholder_6rpw6_gg_{text-overflow:initial}.___SPickerInput_6rpw6_gg_:focus{background-color:var(--intergalactic-bg-highlight-focus, rgba(0, 143, 248, 0.2))}.___SPickerInput_6rpw6_gg_._size_l_6rpw6_gg_,.___SPickerInput_6rpw6_gg_._size_m_6rpw6_gg_{width:19px;margin:0 var(--intergalactic-spacing-2x, 8px);padding:0}.___SPickerInput_6rpw6_gg_._size_l_6rpw6_gg_{width:21px}.___SPickerFormat_6rpw6_gg_{flex-shrink:0;position:relative;display:inline-flex;padding:0;white-space:nowrap;font-family:inherit;font-weight:var(--intergalactic-medium, 500);line-height:normal;-webkit-text-decoration:none;text-decoration:none;align-items:center;border:1px solid var(--intergalactic-border-primary, #c4c7cf);border-radius:0 var(--intergalactic-control-rounded, 6px) var(--intergalactic-control-rounded, 6px)0;outline:0;box-shadow:none;cursor:pointer;box-sizing:border-box;overflow:visible;-webkit-user-select:none;-moz-user-select:none;user-select:none;touch-action:manipulation;-webkit-tap-highlight-color:transparent;color:var(--intergalactic-text-secondary, #6c6e79);background-color:var(--intergalactic-bg-secondary-neutral, #f4f5f9)}@media (hover:hover){.___SPickerFormat_6rpw6_gg_:hover{color:var(--intergalactic-text-secondary, #6c6e79);background-color:var(--intergalactic-bg-secondary-neutral-hover, #e0e1e9)}}.___SPickerFormat_6rpw6_gg_.__active_6rpw6_gg_,.___SPickerFormat_6rpw6_gg_:active{color:var(--intergalactic-text-secondary, #6c6e79);background-color:var(--intergalactic-bg-secondary-neutral-active, #c4c7cf)}.___SPickerFormat_6rpw6_gg_:focus,.___SPickerFormat_6rpw6_gg_:focus-visible{outline:0}.___SPickerFormat_6rpw6_gg_._size_m_6rpw6_gg_{height:var(--intergalactic-form-control-m, 28px);font-size:var(--intergalactic-fs-200, 14px);margin:0-1px 0 0}.___SPickerFormat_6rpw6_gg_._size_m_6rpw6_gg_ .___SPickerFormatText_6rpw6_gg_{margin:0 var(--intergalactic-spacing-2x, 8px)}.___SPickerFormat_6rpw6_gg_._size_l_6rpw6_gg_{height:var(--intergalactic-form-control-l, 40px);font-size:var(--intergalactic-fs-300, 16px);margin:0 calc(-1*var(--intergalactic-spacing-1x, 4px))0 0}.___SPickerFormat_6rpw6_gg_._size_l_6rpw6_gg_ .___SPickerFormatText_6rpw6_gg_{margin:0 var(--intergalactic-spacing-3x, 12px)}.___SPickerFormat_6rpw6_gg_.__disabled_6rpw6_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none;border-color:transparent transparent transparent var(--intergalactic-border-primary, #c4c7cf)}.___SPickerFormat_6rpw6_gg_.__keyboardFocused_6rpw6_gg_{box-shadow:var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 143, 248, 0.5))}.___STimePickerSeparator_6rpw6_gg_{color:var(--intergalactic-text-primary, #191b23)}.___STimePickerSeparator_6rpw6_gg_.__disabled_6rpw6_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);pointer-events:none}",
24
- "6rpw6_gg_"
25
- ), {
26
- __STimePicker: "___STimePicker_6rpw6_gg_",
27
- _keyboardFocused: "__keyboardFocused_6rpw6_gg_",
28
- _disabled: "__disabled_6rpw6_gg_",
29
- __SPickerInput: "___SPickerInput_6rpw6_gg_",
30
- _size_m: "_size_m_6rpw6_gg_",
31
- _size_l: "_size_l_6rpw6_gg_",
32
- __SPickerFormat: "___SPickerFormat_6rpw6_gg_",
33
- __STimePickerSeparator: "___STimePickerSeparator_6rpw6_gg_",
34
- _placeholder: "__placeholder_6rpw6_gg_",
35
- _active: "__active_6rpw6_gg_",
36
- __SPickerFormatText: "___SPickerFormatText_6rpw6_gg_"
24
+ ".___STimePicker_axv7r_gg_{position:relative;width:auto;outline:0}.___STimePicker_axv7r_gg_.__keyboardFocused_axv7r_gg_:focus{box-shadow:var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 143, 248, 0.5))}.___STimePicker_axv7r_gg_.__disabled_axv7r_gg_{color:var(--intergalactic-text-secondary, #6c6e79);cursor:default}.___SPickerInput_axv7r_gg_{box-sizing:content-box;text-align:center;z-index:1;height:1.5em}.___SPickerInput_axv7r_gg_.__placeholder_axv7r_gg_{text-overflow:initial}.___SPickerInput_axv7r_gg_:focus{background-color:var(--intergalactic-bg-highlight-focus, rgba(0, 143, 248, 0.2))}.___SPickerInput_axv7r_gg_._size_l_axv7r_gg_,.___SPickerInput_axv7r_gg_._size_m_axv7r_gg_{width:19px;margin:0 var(--intergalactic-spacing-2x, 8px);padding:0}.___SPickerInput_axv7r_gg_._size_l_axv7r_gg_{width:21px}.___SPickerFormat_axv7r_gg_{flex-shrink:0;position:relative;display:inline-flex;padding:0;white-space:nowrap;font-family:inherit;font-weight:var(--intergalactic-medium, 500);line-height:normal;-webkit-text-decoration:none;text-decoration:none;align-items:center;border:1px solid var(--intergalactic-border-primary, #c4c7cf);border-radius:0 var(--intergalactic-control-rounded, 6px) var(--intergalactic-control-rounded, 6px)0;outline:0;box-shadow:none;cursor:pointer;box-sizing:border-box;overflow:visible;-webkit-user-select:none;-moz-user-select:none;user-select:none;touch-action:manipulation;-webkit-tap-highlight-color:transparent;color:var(--intergalactic-text-secondary, #6c6e79);background-color:var(--intergalactic-bg-secondary-neutral, #f4f5f9)}@media (hover:hover){.___SPickerFormat_axv7r_gg_:hover{color:var(--intergalactic-text-secondary, #6c6e79);background-color:var(--intergalactic-bg-secondary-neutral-hover, #e0e1e9)}}.___SPickerFormat_axv7r_gg_.__active_axv7r_gg_,.___SPickerFormat_axv7r_gg_:active{color:var(--intergalactic-text-secondary, #6c6e79);background-color:var(--intergalactic-bg-secondary-neutral-active, #c4c7cf)}.___SPickerFormat_axv7r_gg_:focus,.___SPickerFormat_axv7r_gg_:focus-visible{outline:0}.___SPickerFormat_axv7r_gg_._size_m_axv7r_gg_{height:var(--intergalactic-form-control-m, 28px);font-size:var(--intergalactic-fs-200, 14px);margin:0-1px 0 0}.___SPickerFormat_axv7r_gg_._size_m_axv7r_gg_ .___SPickerFormatText_axv7r_gg_{margin:0 var(--intergalactic-spacing-2x, 8px)}.___SPickerFormat_axv7r_gg_._size_l_axv7r_gg_{height:var(--intergalactic-form-control-l, 40px);font-size:var(--intergalactic-fs-300, 16px);margin:0 calc(-1*var(--intergalactic-spacing-1x, 4px))0 0}.___SPickerFormat_axv7r_gg_._size_l_axv7r_gg_ .___SPickerFormatText_axv7r_gg_{margin:0 var(--intergalactic-spacing-3x, 12px)}.___SPickerFormat_axv7r_gg_.__disabled_axv7r_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none;border-color:transparent transparent transparent var(--intergalactic-border-primary, #c4c7cf)}.___SPickerFormat_axv7r_gg_.__keyboardFocused_axv7r_gg_{box-shadow:var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 143, 248, 0.5))}.___STimePickerSeparator_axv7r_gg_{color:var(--intergalactic-text-primary, #191b23)}.___STimePickerSeparator_axv7r_gg_.__disabled_axv7r_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);pointer-events:none}",
25
+ /*__inner_css_end__*/
26
+ "axv7r_gg_"
27
+ ), /*__reshadow_css_end__*/
28
+ {
29
+ "__STimePicker": "___STimePicker_axv7r_gg_",
30
+ "_keyboardFocused": "__keyboardFocused_axv7r_gg_",
31
+ "_disabled": "__disabled_axv7r_gg_",
32
+ "__SPickerInput": "___SPickerInput_axv7r_gg_",
33
+ "_size_m": "_size_m_axv7r_gg_",
34
+ "_size_l": "_size_l_axv7r_gg_",
35
+ "__SPickerFormat": "___SPickerFormat_axv7r_gg_",
36
+ "__STimePickerSeparator": "___STimePickerSeparator_axv7r_gg_",
37
+ "_placeholder": "__placeholder_axv7r_gg_",
38
+ "_active": "__active_axv7r_gg_",
39
+ "__SPickerFormatText": "___SPickerFormatText_axv7r_gg_"
37
40
  })
38
- ), Q = {
41
+ );
42
+ var MAP_MERIDIEM = {
39
43
  AM: "PM",
40
44
  PM: "AM"
41
- }, U = {
45
+ };
46
+ var MAP_FIELD_TO_TIME = {
42
47
  hours: 0,
43
48
  minutes: 1
44
49
  };
45
- function x(a) {
46
- var c = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, s = Number.parseInt(a);
47
- return Number.isNaN(s) ? c : s;
50
+ function intOrDefault(value) {
51
+ var def = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
52
+ var number = Number.parseInt(value);
53
+ return Number.isNaN(number) ? def : number;
48
54
  }
49
- function I(a) {
50
- return a = String(a), a.length === 1 ? "0".concat(a) : String(a);
55
+ function withLeadingZero(value) {
56
+ value = String(value);
57
+ if (value.length === 1) return "0".concat(value);
58
+ return String(value);
51
59
  }
52
- function W(a) {
53
- return a >= 12 ? "PM" : "AM";
60
+ function meridiemByHours(hours) {
61
+ return hours >= 12 ? "PM" : "AM";
54
62
  }
55
- function F(a) {
56
- var c = x(a, NaN);
57
- return Number.isNaN(c) ? a : c === 0 ? 12 : c > 12 ? c - 12 : a;
63
+ function formatHoursTo12(hours) {
64
+ var nHours = intOrDefault(hours, NaN);
65
+ if (Number.isNaN(nHours)) return hours;
66
+ if (nHours === 0) return 12;
67
+ if (nHours > 12) return nHours - 12;
68
+ return hours;
58
69
  }
59
- function X(a, c) {
60
- var s = x(a, NaN);
61
- return Number.isNaN(s) ? a : c === "AM" && s === 12 ? 0 : c === "PM" && s < 12 ? s + 12 : a;
70
+ function formatHoursTo24(hours, meridiem) {
71
+ var nHours = intOrDefault(hours, NaN);
72
+ if (Number.isNaN(nHours)) return hours;
73
+ if (meridiem === "AM") {
74
+ if (nHours === 12) return 0;
75
+ }
76
+ if (meridiem === "PM") {
77
+ if (nHours < 12) return nHours + 12;
78
+ }
79
+ return hours;
62
80
  }
63
- var S = /* @__PURE__ */ function(a) {
64
- H(s, a);
65
- var c = $(s);
66
- function s() {
67
- var e;
68
- M(this, s);
69
- for (var t = arguments.length, o = new Array(t), n = 0; n < t; n++)
70
- o[n] = arguments[n];
71
- return e = c.call.apply(c, [this].concat(o)), p(m(e), "hoursInputRef", /* @__PURE__ */ g.createRef()), p(m(e), "minutesInputRef", /* @__PURE__ */ g.createRef()), p(m(e), "_lastMeridiem", "AM"), p(m(e), "handleValueChange", function(r, _, i) {
72
- var u = e.asProps.is12Hour, l = m(e), f = l.meridiem, d;
73
- _ ? (d = e.value.split(":"), d[U[_]] = r) : d = r.split(":");
74
- var k = d, v = w(k, 2), h = v[0], P = h === void 0 ? "" : h, T = v[1], V = T === void 0 ? "" : T;
75
- u && (P = String(F(P))), r = e.timeToValue([P, V], f), e.handlers.value(r, i);
76
- }), p(m(e), "handleMeridiemClick", function(r) {
77
- var _ = e.asProps.is12Hour, i = m(e), u = i.value, l = i.meridiem, f = u.split(":"), d = w(f, 2), k = d[0], v = k === void 0 ? "" : k, h = d[1], P = h === void 0 ? "" : h;
78
- _ && (v = String(F(v))), u = e.timeToValue([v, P], Q[l]), e.handlers.value(u, r);
79
- }), p(m(e), "_getHoursAndMinutesProps", function() {
80
- var r = e.asProps, _ = r.is12Hour, i = r.size, u = r.disabled, l = r.getI18nText, f = e.valueToTime(e.value);
81
+ var TimePickerRoot = /* @__PURE__ */ function(_Component) {
82
+ _inherits(TimePickerRoot2, _Component);
83
+ var _super = _createSuper(TimePickerRoot2);
84
+ function TimePickerRoot2() {
85
+ var _this;
86
+ _classCallCheck(this, TimePickerRoot2);
87
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
88
+ args[_key] = arguments[_key];
89
+ }
90
+ _this = _super.call.apply(_super, [this].concat(args));
91
+ _defineProperty(_assertThisInitialized(_this), "hoursInputRef", /* @__PURE__ */ React.createRef());
92
+ _defineProperty(_assertThisInitialized(_this), "minutesInputRef", /* @__PURE__ */ React.createRef());
93
+ _defineProperty(_assertThisInitialized(_this), "_lastMeridiem", "AM");
94
+ _defineProperty(_assertThisInitialized(_this), "handleValueChange", function(value, field, event) {
95
+ var is12Hour = _this.asProps.is12Hour;
96
+ var _assertThisInitialize = _assertThisInitialized(_this), meridiem = _assertThisInitialize.meridiem;
97
+ var time;
98
+ if (field) {
99
+ time = _this.value.split(":");
100
+ time[MAP_FIELD_TO_TIME[field]] = value;
101
+ } else {
102
+ time = value.split(":");
103
+ }
104
+ var _time = time, _time2 = _slicedToArray(_time, 2), _time2$ = _time2[0], hours = _time2$ === void 0 ? "" : _time2$, _time2$2 = _time2[1], minutes = _time2$2 === void 0 ? "" : _time2$2;
105
+ if (is12Hour) hours = String(formatHoursTo12(hours));
106
+ value = _this.timeToValue([hours, minutes], meridiem);
107
+ _this.handlers.value(value, event);
108
+ });
109
+ _defineProperty(_assertThisInitialized(_this), "handleMeridiemClick", function(event) {
110
+ var is12Hour = _this.asProps.is12Hour;
111
+ var _assertThisInitialize2 = _assertThisInitialized(_this), value = _assertThisInitialize2.value, meridiem = _assertThisInitialize2.meridiem;
112
+ var _value$split = value.split(":"), _value$split2 = _slicedToArray(_value$split, 2), _value$split2$ = _value$split2[0], hours = _value$split2$ === void 0 ? "" : _value$split2$, _value$split2$2 = _value$split2[1], minutes = _value$split2$2 === void 0 ? "" : _value$split2$2;
113
+ if (is12Hour) hours = String(formatHoursTo12(hours));
114
+ value = _this.timeToValue([hours, minutes], MAP_MERIDIEM[meridiem]);
115
+ _this.handlers.value(value, event);
116
+ });
117
+ _defineProperty(_assertThisInitialized(_this), "_getHoursAndMinutesProps", function() {
118
+ var _this$asProps = _this.asProps, is12Hour = _this$asProps.is12Hour, size = _this$asProps.size, disabled = _this$asProps.disabled, getI18nText = _this$asProps.getI18nText;
119
+ var time = _this.valueToTime(_this.value);
81
120
  return {
82
- time: f,
83
- size: i,
84
- is12Hour: _,
85
- disabled: u,
86
- $onValueChange: e.handleValueChange,
87
- minutesInputRef: e.minutesInputRef,
88
- hoursInputRef: e.hoursInputRef,
89
- _getI18nText: l
121
+ time,
122
+ size,
123
+ is12Hour,
124
+ disabled,
125
+ $onValueChange: _this.handleValueChange,
126
+ minutesInputRef: _this.minutesInputRef,
127
+ hoursInputRef: _this.hoursInputRef,
128
+ _getI18nText: getI18nText
90
129
  };
91
- }), p(m(e), "getHoursProps", function() {
92
- return b(b({}, e._getHoursAndMinutesProps()), {}, {
93
- ref: e.hoursInputRef
130
+ });
131
+ _defineProperty(_assertThisInitialized(_this), "getHoursProps", function() {
132
+ return _objectSpread(_objectSpread({}, _this._getHoursAndMinutesProps()), {}, {
133
+ ref: _this.hoursInputRef
94
134
  });
95
- }), p(m(e), "getMinutesProps", function() {
96
- return b(b({}, e._getHoursAndMinutesProps()), {}, {
97
- ref: e.minutesInputRef
135
+ });
136
+ _defineProperty(_assertThisInitialized(_this), "getMinutesProps", function() {
137
+ return _objectSpread(_objectSpread({}, _this._getHoursAndMinutesProps()), {}, {
138
+ ref: _this.minutesInputRef
98
139
  });
99
- }), e;
140
+ });
141
+ return _this;
100
142
  }
101
- return z(s, [{
143
+ _createClass(TimePickerRoot2, [{
102
144
  key: "uncontrolledProps",
103
145
  value: (
104
146
  // default AM
105
- function() {
147
+ function uncontrolledProps() {
106
148
  return {
107
149
  value: null,
108
150
  title: null
@@ -111,37 +153,55 @@ var S = /* @__PURE__ */ function(a) {
111
153
  )
112
154
  }, {
113
155
  key: "componentDidMount",
114
- value: function() {
115
- var t, o = this.asProps, n = o.id, r = o["aria-describedby"], _ = "[for=".concat(n, "]"), i = (t = document.querySelector(_)) !== null && t !== void 0 ? t : document.querySelector("#".concat(r));
116
- i && this.handlers.title(i.textContent);
156
+ value: function componentDidMount() {
157
+ var _document$querySelect;
158
+ var _this$asProps2 = this.asProps, id = _this$asProps2.id, ariaDescribedBy = _this$asProps2["aria-describedby"];
159
+ var selector = "[for=".concat(id, "]");
160
+ var titleElement = (_document$querySelect = document.querySelector(selector)) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.querySelector("#".concat(ariaDescribedBy));
161
+ if (titleElement) {
162
+ this.handlers.title(titleElement.textContent);
163
+ }
117
164
  }
118
165
  }, {
119
166
  key: "value",
120
- get: function() {
121
- var t = this.asProps.value;
122
- return t ?? ":";
167
+ get: function get() {
168
+ var value = this.asProps.value;
169
+ return value === null || value === void 0 ? ":" : value;
123
170
  }
124
171
  }, {
125
172
  key: "meridiem",
126
- get: function() {
127
- var t = this.asProps.value, o = t.split(":"), n = w(o, 1), r = n[0], _ = r === void 0 ? "" : r, i = x(_, NaN);
128
- return Number.isNaN(i) || (this._lastMeridiem = W(i)), this._lastMeridiem;
173
+ get: function get() {
174
+ var value = this.asProps.value;
175
+ var _value$split3 = value.split(":"), _value$split4 = _slicedToArray(_value$split3, 1), _value$split4$ = _value$split4[0], hours = _value$split4$ === void 0 ? "" : _value$split4$;
176
+ var nHours = intOrDefault(hours, NaN);
177
+ if (!Number.isNaN(nHours)) {
178
+ this._lastMeridiem = meridiemByHours(nHours);
179
+ }
180
+ return this._lastMeridiem;
129
181
  }
130
182
  }, {
131
183
  key: "valueToTime",
132
- value: function(t) {
133
- var o = this.asProps.is12Hour, n = t.split(":"), r = w(n, 2), _ = r[0], i = _ === void 0 ? "" : _, u = r[1], l = u === void 0 ? "" : u;
134
- return o && (i = F(i)), i = I(i), l = I(l), [i, l];
184
+ value: function valueToTime(value) {
185
+ var is12Hour = this.asProps.is12Hour;
186
+ var _value$split5 = value.split(":"), _value$split6 = _slicedToArray(_value$split5, 2), _value$split6$ = _value$split6[0], hours = _value$split6$ === void 0 ? "" : _value$split6$, _value$split6$2 = _value$split6[1], minutes = _value$split6$2 === void 0 ? "" : _value$split6$2;
187
+ if (is12Hour) hours = formatHoursTo12(hours);
188
+ hours = withLeadingZero(hours);
189
+ minutes = withLeadingZero(minutes);
190
+ return [hours, minutes];
135
191
  }
136
192
  }, {
137
193
  key: "timeToValue",
138
- value: function(t, o) {
139
- var n = this.asProps.is12Hour, r = w(t, 2), _ = r[0], i = _ === void 0 ? "" : _, u = r[1], l = u === void 0 ? "" : u;
140
- return i = x(i, i), l = x(l, l), n && (i = X(i, o)), "".concat(i, ":").concat(l);
194
+ value: function timeToValue(time, meridiem) {
195
+ var is12Hour = this.asProps.is12Hour;
196
+ var _time3 = _slicedToArray(time, 2), _time3$ = _time3[0], hours = _time3$ === void 0 ? "" : _time3$, _time3$2 = _time3[1], minutes = _time3$2 === void 0 ? "" : _time3$2;
197
+ hours = intOrDefault(hours, hours);
198
+ minutes = intOrDefault(minutes, minutes);
199
+ if (is12Hour) hours = formatHoursTo24(hours, meridiem);
200
+ return "".concat(hours, ":").concat(minutes);
141
201
  }
142
202
  }, {
143
203
  key: "getSeparatorProps",
144
- value: function() {
204
+ value: function getSeparatorProps() {
145
205
  return {
146
206
  disabled: this.asProps.disabled,
147
207
  hoursInputRef: this.hoursInputRef
@@ -149,86 +209,97 @@ var S = /* @__PURE__ */ function(a) {
149
209
  }
150
210
  }, {
151
211
  key: "getFormatProps",
152
- value: function() {
153
- var t = this.asProps, o = t.size, n = t.disabled, r = t.disablePortal, _ = t.getI18nText;
212
+ value: function getFormatProps() {
213
+ var _this$asProps3 = this.asProps, size = _this$asProps3.size, disabled = _this$asProps3.disabled, disablePortal = _this$asProps3.disablePortal, getI18nText = _this$asProps3.getI18nText;
154
214
  return {
155
- size: o,
156
- disabled: n,
157
- disablePortal: r,
215
+ size,
216
+ disabled,
217
+ disablePortal,
158
218
  meridiem: this.meridiem,
159
219
  onClick: this.handleMeridiemClick,
160
- getI18nText: _
220
+ getI18nText
161
221
  };
162
222
  }
163
223
  }, {
164
224
  key: "render",
165
- value: function() {
166
- var t = this.asProps, o, n = B, r = this.asProps, _ = r.styles, i = r.Children, u = r.value, l = r.is12Hour, f = r.getI18nText, d = r.title, k = this.valueToTime(this.value), v = w(k, 2), h = v[0], P = v[1], T = u ? "".concat(d, " ").concat(f("title", {
167
- time: "".concat(h, ":").concat(I(P)),
168
- meridiem: l ? this.meridiem : ""
169
- })) : "".concat(d, " ").concat(f("titleEmpty"));
170
- return o = N(_), /* @__PURE__ */ g.createElement(g.Fragment, null, /* @__PURE__ */ g.createElement(n, o.cn("STimePicker", b({}, C({
171
- role: "group",
172
- "aria-label": T,
173
- __excludeProps: ["value", "title"]
174
- }, t))), /* @__PURE__ */ g.createElement(i, o.cn("Children", {}))));
225
+ value: function render() {
226
+ var _ref = this.asProps, _ref3;
227
+ var STimePicker = Input;
228
+ var _this$asProps4 = this.asProps, styles = _this$asProps4.styles, Children = _this$asProps4.Children, value = _this$asProps4.value, is12Hour = _this$asProps4.is12Hour, getI18nText = _this$asProps4.getI18nText, title = _this$asProps4.title;
229
+ var _this$valueToTime = this.valueToTime(this.value), _this$valueToTime2 = _slicedToArray(_this$valueToTime, 2), hours = _this$valueToTime2[0], minutes = _this$valueToTime2[1];
230
+ var label = value ? "".concat(title, " ").concat(getI18nText("title", {
231
+ time: "".concat(hours, ":").concat(withLeadingZero(minutes)),
232
+ meridiem: is12Hour ? this.meridiem : ""
233
+ })) : "".concat(title, " ").concat(getI18nText("titleEmpty"));
234
+ return _ref3 = sstyled$1(styles), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(STimePicker, _ref3.cn("STimePicker", _objectSpread({}, assignProps({
235
+ "role": "group",
236
+ "aria-label": label,
237
+ "__excludeProps": ["value", "title"]
238
+ }, _ref))), /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {}))));
175
239
  }
176
- }]), s;
177
- }(R);
178
- p(S, "displayName", "TimePicker");
179
- p(S, "style", K);
180
- p(S, "enhance", [G(E), J()]);
181
- p(S, "defaultProps", function(a) {
182
- var c = a.is12Hour;
240
+ }]);
241
+ return TimePickerRoot2;
242
+ }(Component);
243
+ _defineProperty(TimePickerRoot, "displayName", "TimePicker");
244
+ _defineProperty(TimePickerRoot, "style", style);
245
+ _defineProperty(TimePickerRoot, "enhance", [i18nEnhance(localizedMessages), keyboardFocusEnhance()]);
246
+ _defineProperty(TimePickerRoot, "defaultProps", function(_ref5) {
247
+ var is12Hour = _ref5.is12Hour;
183
248
  return {
184
249
  defaultValue: "",
185
250
  size: "m",
186
- children: /* @__PURE__ */ g.createElement(g.Fragment, null, /* @__PURE__ */ g.createElement(y.Hours, null), /* @__PURE__ */ g.createElement(y.Separator, null), /* @__PURE__ */ g.createElement(y.Minutes, null), c && /* @__PURE__ */ g.createElement(y.Format, null)),
187
- i18n: E,
251
+ 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)),
252
+ i18n: localizedMessages,
188
253
  locale: "en",
189
254
  defaultTitle: ""
190
255
  };
191
256
  });
192
- var A = /* @__PURE__ */ function(a) {
193
- H(s, a);
194
- var c = $(s);
195
- function s() {
196
- var e;
197
- M(this, s);
198
- for (var t = arguments.length, o = new Array(t), n = 0; n < t; n++)
199
- o[n] = arguments[n];
200
- return e = c.call.apply(c, [this].concat(o)), p(m(e), "handlerClick", function() {
201
- if (e.asProps.hoursInputRef.current) {
202
- var r;
203
- (r = e.asProps.hoursInputRef.current) === null || r === void 0 || r.focus();
257
+ var Separator = /* @__PURE__ */ function(_Component2) {
258
+ _inherits(Separator2, _Component2);
259
+ var _super2 = _createSuper(Separator2);
260
+ function Separator2() {
261
+ var _this2;
262
+ _classCallCheck(this, Separator2);
263
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
264
+ args[_key2] = arguments[_key2];
265
+ }
266
+ _this2 = _super2.call.apply(_super2, [this].concat(args));
267
+ _defineProperty(_assertThisInitialized(_this2), "handlerClick", function() {
268
+ if (_this2.asProps.hoursInputRef.current) {
269
+ var _this2$asProps$hoursI;
270
+ (_this2$asProps$hoursI = _this2.asProps.hoursInputRef.current) === null || _this2$asProps$hoursI === void 0 ? void 0 : _this2$asProps$hoursI.focus();
204
271
  }
205
- }), e;
272
+ });
273
+ return _this2;
206
274
  }
207
- return z(s, [{
275
+ _createClass(Separator2, [{
208
276
  key: "render",
209
- value: function() {
210
- var t = this.asProps, o, n = L, r = this.asProps.styles;
211
- return o = N(r), /* @__PURE__ */ g.createElement(n, o.cn("STimePickerSeparator", b({}, C({
212
- onClick: this.handlerClick,
277
+ value: function render() {
278
+ var _ref2 = this.asProps, _ref4;
279
+ var STimePickerSeparator = Box;
280
+ var styles = this.asProps.styles;
281
+ return _ref4 = sstyled$1(styles), /* @__PURE__ */ React.createElement(STimePickerSeparator, _ref4.cn("STimePickerSeparator", _objectSpread({}, assignProps({
282
+ "onClick": this.handlerClick,
213
283
  "aria-hidden": "true"
214
- }, t))));
284
+ }, _ref2))));
215
285
  }
216
- }]), s;
217
- }(R);
218
- p(A, "defaultProps", {
286
+ }]);
287
+ return Separator2;
288
+ }(Component);
289
+ _defineProperty(Separator, "defaultProps", {
219
290
  children: ":"
220
291
  });
221
- var y = q(S, {
222
- Hours: O,
223
- Minutes: j,
224
- Separator: A,
225
- Format: Z
292
+ var TimePicker = createComponent(TimePickerRoot, {
293
+ Hours,
294
+ Minutes,
295
+ Separator,
296
+ Format: TimePickerFormat
226
297
  });
227
298
  export {
228
- y as default,
229
- F as formatHoursTo12,
230
- X as formatHoursTo24,
231
- x as intOrDefault,
232
- W as meridiemByHours,
233
- I as withLeadingZero
299
+ TimePicker as default,
300
+ formatHoursTo12,
301
+ formatHoursTo24,
302
+ intOrDefault,
303
+ meridiemByHours,
304
+ withLeadingZero
234
305
  };
package/lib/esm/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { default as e, formatHoursTo12 as t, formatHoursTo24 as a, intOrDefault as f, meridiemByHours as i, withLeadingZero as m } from "./TimePicker.mjs";
1
+ import { default as default2, formatHoursTo12, formatHoursTo24, intOrDefault, meridiemByHours, withLeadingZero } from "./TimePicker.mjs";
2
2
  export {
3
- e as default,
4
- t as formatHoursTo12,
5
- a as formatHoursTo24,
6
- f as intOrDefault,
7
- i as meridiemByHours,
8
- m as withLeadingZero
3
+ default2 as default,
4
+ formatHoursTo12,
5
+ formatHoursTo24,
6
+ intOrDefault,
7
+ meridiemByHours,
8
+ withLeadingZero
9
9
  };
@@ -0,0 +1,121 @@
1
+ STimePicker {
2
+ position: relative;
3
+ width: auto;
4
+ outline: none;
5
+ }
6
+
7
+ STimePicker[keyboardFocused]:focus {
8
+ box-shadow: var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 143, 248, 0.5));
9
+ }
10
+
11
+ STimePicker[disabled] {
12
+ color: var(--intergalactic-text-secondary, #6c6e79);
13
+ cursor: default;
14
+ }
15
+
16
+ SPickerInput {
17
+ box-sizing: content-box;
18
+ text-align: center;
19
+ z-index: 1;
20
+ height: 1.5em;
21
+
22
+ &[placeholder] {
23
+ text-overflow: initial;
24
+ }
25
+ &:focus {
26
+ background-color: var(--intergalactic-bg-highlight-focus, rgba(0, 143, 248, 0.2));
27
+ }
28
+ }
29
+
30
+ SPickerInput[size='m'] {
31
+ width: 19px;
32
+ margin: 0 var(--intergalactic-spacing-2x, 8px);
33
+ padding: 0;
34
+ }
35
+
36
+ SPickerInput[size='l'] {
37
+ width: 21px;
38
+ margin: 0 var(--intergalactic-spacing-2x, 8px);
39
+ padding: 0;
40
+ }
41
+
42
+ SPickerFormat {
43
+ flex-shrink: 0;
44
+ position: relative;
45
+ display: inline-flex;
46
+ padding: 0;
47
+ white-space: nowrap;
48
+ font-family: inherit;
49
+ font-weight: var(--intergalactic-medium, 500);
50
+ line-height: normal;
51
+ text-decoration: none;
52
+ align-items: center;
53
+ border: 1px solid var(--intergalactic-border-primary, #c4c7cf);
54
+ border-radius: 0 var(--intergalactic-control-rounded, 6px)
55
+ var(--intergalactic-control-rounded, 6px) 0;
56
+ outline: 0;
57
+ box-shadow: none;
58
+ cursor: pointer;
59
+ box-sizing: border-box;
60
+ overflow: visible;
61
+ user-select: none;
62
+ touch-action: manipulation;
63
+ -webkit-tap-highlight-color: transparent;
64
+ color: var(--intergalactic-text-secondary, #6c6e79);
65
+ background-color: var(--intergalactic-bg-secondary-neutral, #f4f5f9);
66
+
67
+ &:hover {
68
+ color: var(--intergalactic-text-secondary, #6c6e79);
69
+ background-color: var(--intergalactic-bg-secondary-neutral-hover, #e0e1e9);
70
+ }
71
+
72
+ &:active,
73
+ &[active] {
74
+ color: var(--intergalactic-text-secondary, #6c6e79);
75
+ background-color: var(--intergalactic-bg-secondary-neutral-active, #c4c7cf);
76
+ }
77
+
78
+ &:focus,
79
+ &:focus-visible {
80
+ outline: none;
81
+ }
82
+ }
83
+
84
+ SPickerFormat[size='m'] {
85
+ height: var(--intergalactic-form-control-m, 28px);
86
+ font-size: var(--intergalactic-fs-200, 14px);
87
+ /* disable-tokens-validator */
88
+ margin: 0 -1px 0 0;
89
+ & SPickerFormatText {
90
+ margin: 0 var(--intergalactic-spacing-2x, 8px);
91
+ }
92
+ }
93
+
94
+ SPickerFormat[size='l'] {
95
+ height: var(--intergalactic-form-control-l, 40px);
96
+ font-size: var(--intergalactic-fs-300, 16px);
97
+ margin: 0 calc(-1 * var(--intergalactic-spacing-1x, 4px)) 0 0;
98
+ & SPickerFormatText {
99
+ margin: 0 var(--intergalactic-spacing-3x, 12px);
100
+ }
101
+ }
102
+
103
+ SPickerFormat[disabled] {
104
+ opacity: var(--intergalactic-disabled-opacity, 0.3);
105
+ cursor: default;
106
+ pointer-events: none;
107
+ border-color: transparent transparent transparent var(--intergalactic-border-primary, #c4c7cf);
108
+ }
109
+
110
+ SPickerFormat[keyboardFocused] {
111
+ box-shadow: var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 143, 248, 0.5));
112
+ }
113
+
114
+ STimePickerSeparator {
115
+ color: var(--intergalactic-text-primary, #191b23);
116
+ }
117
+
118
+ STimePickerSeparator[disabled] {
119
+ opacity: var(--intergalactic-disabled-opacity, 0.3);
120
+ pointer-events: none;
121
+ }