asma-ui-core 3.98.1 → 3.99.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.
@@ -1,19 +1,22 @@
1
1
  import r from "../StyledTimePicker.module.js";
2
- import a from "clsx";
3
- import { jsx as n } from "react/jsx-runtime";
4
- import { getHours as _, getMinutes as k, set as w } from "date-fns";
5
- var b = ({ type: m, value: o, onSelect: d }) => {
6
- const s = /* @__PURE__ */ new Date(), t = m === "hours", u = t ? 24 : 12, p = t ? s.getHours() : s.getMinutes();
7
- return /* @__PURE__ */ n("div", {
2
+ import { clampToMinTime as w, isHourDisabled as y, isMinuteDisabled as b } from "../helpers/minTime.js";
3
+ import g from "clsx";
4
+ import { jsx as d } from "react/jsx-runtime";
5
+ import { getHours as u, getMinutes as h, set as M } from "date-fns";
6
+ var C = ({ type: a, value: o, onSelect: p, minTime: s }) => {
7
+ const i = /* @__PURE__ */ new Date(), t = a === "hours", _ = u(o ?? i), f = t ? 24 : 12, k = t ? i.getHours() : i.getMinutes();
8
+ return /* @__PURE__ */ d("div", {
8
9
  className: r["styled-time-picker-root_column"],
9
- children: new Array(u).fill(null).map((y, i) => {
10
- const e = t ? i : i * 5, l = o && e === (t ? _(o) : k(o)), c = p == e;
11
- return /* @__PURE__ */ n("button", {
10
+ children: new Array(f).fill(null).map((x, l) => {
11
+ const e = t ? l : l * 5, c = o && e === (t ? u(o) : h(o)), n = k == e;
12
+ return /* @__PURE__ */ d("button", {
12
13
  type: "button",
13
- "data-cell": l ? "selected" : c ? "now" : void 0,
14
- className: a("border-0", r["styled-time-picker-root_cell"], c && r["styled-time-picker-root_cell__cell-now"], l && r["styled-time-picker-root_cell__cell-selected"]),
14
+ disabled: t ? y(e, s) : b(_, e, s),
15
+ "data-cell": c ? "selected" : n ? "now" : void 0,
16
+ className: g("border-0", r["styled-time-picker-root_cell"], n && r["styled-time-picker-root_cell__cell-now"], c && r["styled-time-picker-root_cell__cell-selected"]),
15
17
  onClick: () => {
16
- d(w(o ?? /* @__PURE__ */ new Date(), t ? { hours: e } : { minutes: e }));
18
+ const m = M(o ?? /* @__PURE__ */ new Date(), t ? { hours: e } : { minutes: e });
19
+ p(t ? w(m, s) : m);
17
20
  },
18
21
  children: e.toString().padStart(2, "0")
19
22
  }, e);
@@ -21,5 +24,5 @@ var b = ({ type: m, value: o, onSelect: d }) => {
21
24
  });
22
25
  };
23
26
  export {
24
- b as TimePickerColumn
27
+ C as TimePickerColumn
25
28
  };
@@ -1,12 +1,13 @@
1
1
  import { StyledButton as e } from "../../../shared-components/button/StyledButton.js";
2
- import { TimePickerBody as d } from "./TimePickerBody.js";
3
- import { EraserIcon as l } from "../../../shared-components/EraserIcon.js";
4
- import { CheckIcon as s } from "../../../shared-components/CheckIcon.js";
5
- import { Fragment as c, jsx as t, jsxs as r } from "react/jsx-runtime";
6
- var b = ({ dataTest: a, value: i, onSelect: m, handleClear: n, onConfirm: o }) => /* @__PURE__ */ r(c, { children: [/* @__PURE__ */ t(d, {
2
+ import { TimePickerBody as l } from "./TimePickerBody.js";
3
+ import { EraserIcon as s } from "../../../shared-components/EraserIcon.js";
4
+ import { CheckIcon as c } from "../../../shared-components/CheckIcon.js";
5
+ import { Fragment as p, jsx as t, jsxs as r } from "react/jsx-runtime";
6
+ var g = ({ dataTest: a, value: i, minTime: m, onSelect: n, handleClear: o, onConfirm: d }) => /* @__PURE__ */ r(p, { children: [/* @__PURE__ */ t(l, {
7
7
  dataTest: `${a}-time-picker-body`,
8
8
  value: i,
9
- onSelect: m
9
+ minTime: m,
10
+ onSelect: n
10
11
  }), /* @__PURE__ */ r("div", {
11
12
  style: {
12
13
  display: "flex",
@@ -19,14 +20,14 @@ var b = ({ dataTest: a, value: i, onSelect: m, handleClear: n, onConfirm: o }) =
19
20
  "data-testid": "time-picker-erase-button",
20
21
  "aria-label": "Clear time",
21
22
  variant: "text",
22
- onClick: n,
23
+ onClick: o,
23
24
  size: "small",
24
25
  disabled: !i,
25
26
  style: {
26
27
  minWidth: "40px",
27
28
  marginLeft: "10px"
28
29
  },
29
- children: /* @__PURE__ */ t(l, {
30
+ children: /* @__PURE__ */ t(s, {
30
31
  width: 24,
31
32
  height: 24
32
33
  })
@@ -36,17 +37,17 @@ var b = ({ dataTest: a, value: i, onSelect: m, handleClear: n, onConfirm: o }) =
36
37
  "aria-label": "Confirm time",
37
38
  variant: "contained",
38
39
  size: "small",
39
- onClick: o,
40
+ onClick: d,
40
41
  style: {
41
42
  minWidth: "40px",
42
43
  marginRight: "16px"
43
44
  },
44
- children: /* @__PURE__ */ t(s, {
45
+ children: /* @__PURE__ */ t(c, {
45
46
  width: 20,
46
47
  height: 20
47
48
  })
48
49
  })]
49
50
  })] });
50
51
  export {
51
- b as TimePickerPanel
52
+ g as TimePickerPanel
52
53
  };
@@ -1,8 +1,8 @@
1
- var u = (s, o) => {
2
- const t = s.split(":"), e = Number(t[0]), n = Number(t[1]);
3
- if (t[0]?.length == 2 && t[1]?.length == 2 && e >= 0 && e <= 23 && n >= 0 && n <= 59) {
4
- const r = o ?? /* @__PURE__ */ new Date();
5
- return r.setHours(e), r.setMinutes(n), r;
1
+ var u = (o, s) => {
2
+ const e = o.split(":"), t = Number(e[0]), n = Number(e[1]);
3
+ if (e[0]?.length == 2 && e[1]?.length == 2 && t >= 0 && t <= 23 && n >= 0 && n <= 59) {
4
+ const r = s ? new Date(s) : /* @__PURE__ */ new Date();
5
+ return r.setHours(t), r.setMinutes(n), r;
6
6
  }
7
7
  return null;
8
8
  };
@@ -0,0 +1,12 @@
1
+ import { isValid as M } from "date-fns";
2
+ var e = (r) => r.getHours() * 60 + r.getMinutes(), s = (r) => !!r && M(r), o = (r, t) => s(t) && e(r) < e(t), i = (r, t) => s(t) && r * 60 + 55 < e(t), n = (r, t, a) => s(a) && r * 60 + t < e(a), v = (r, t) => {
3
+ if (!s(t) || !o(r, t)) return r;
4
+ const a = new Date(r);
5
+ return a.setMinutes(Math.ceil(t.getMinutes() / 5) * 5), a;
6
+ };
7
+ export {
8
+ v as clampToMinTime,
9
+ o as isBeforeMinTime,
10
+ i as isHourDisabled,
11
+ n as isMinuteDisabled
12
+ };
@@ -4,6 +4,7 @@ import { ChangeEvent } from 'react';
4
4
  export declare const TimePickerInput: React.FC<StyledTimePickerProps & {
5
5
  popupState: PopupState;
6
6
  handleChange: (e: ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void;
7
+ handleBlur?: () => void;
7
8
  isValidTime: boolean;
8
9
  isValidEndTime: boolean;
9
10
  localValue: string;
@@ -1,6 +1,7 @@
1
1
  export interface TimePickerPanelProps {
2
2
  dataTest: string;
3
3
  value?: Date;
4
+ minTime?: Date;
4
5
  onSelect: (date: Date | undefined) => void;
5
6
  handleClear: () => void;
6
7
  onConfirm: () => void;
@@ -0,0 +1,12 @@
1
+ /** The minutes column offers 00, 05 … 55. */
2
+ export declare const MINUTE_STEP = 5;
3
+ /** Only the clock time of both dates counts; the calendar day is the consumer's concern. */
4
+ export declare const isBeforeMinTime: (time: Date, minTime?: Date) => boolean;
5
+ /** An hour is disabled when none of its minute cells reaches `minTime` (e.g. hour 12 for 12:57). */
6
+ export declare const isHourDisabled: (hour: number, minTime?: Date) => boolean;
7
+ export declare const isMinuteDisabled: (hour: number, minute: number, minTime?: Date) => boolean;
8
+ /**
9
+ * Picking the `minTime` hour while the kept minutes fall before it (13:10 → hour 12 with minTime 12:35)
10
+ * would land on a disabled cell, so the minutes move up to the first enabled cell (12:35).
11
+ */
12
+ export declare const clampToMinTime: (time: Date, minTime?: Date) => Date;
@@ -17,5 +17,12 @@ export interface StyledTimePickerProps {
17
17
  locale?: 'no' | 'en';
18
18
  title?: string;
19
19
  notBeforeTime?: Date;
20
+ /**
21
+ * @figmaProp none — behavioral; drives the Time item `State=Disabled` cells (node 15086-19871).
22
+ * Earliest selectable clock time; its calendar day is ignored. Earlier hour/minute cells are disabled
23
+ * and a typed earlier time is not committed — the field reverts to the last valid value on blur.
24
+ * Unlike `notBeforeTime`, it never shows an error.
25
+ */
26
+ minTime?: Date;
20
27
  }
21
28
  export type IPopupStateType = JSX.Element;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.98.1",
6
+ "version": "3.99.0",
7
7
  "type": "module",
8
8
  "sideEffects": [
9
9
  "**/*.css",