@pitchfork-ui/react 0.9.0 → 0.11.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.
Files changed (63) hide show
  1. package/dist/components/Badge/Badge.css +4 -0
  2. package/dist/components/Button/Button.css +7 -0
  3. package/dist/components/Collapsible/Collapsible.css +86 -0
  4. package/dist/components/Collapsible/Collapsible2.js +65 -0
  5. package/dist/components/ContextMenu/ContextMenu.css +122 -0
  6. package/dist/components/ContextMenu/ContextMenu2.js +155 -0
  7. package/dist/components/Icon/Icon2.js +17 -0
  8. package/dist/components/InlineCTA/InlineCTA.css +4 -0
  9. package/dist/components/Modal/Modal.css +6 -1
  10. package/dist/components/Resizable/Resizable.css +79 -0
  11. package/dist/components/Resizable/Resizable2.js +101 -0
  12. package/dist/components/ScrollArea/ScrollArea.css +54 -0
  13. package/dist/components/ScrollArea/ScrollArea2.js +18 -0
  14. package/dist/components/Tag/Tag.css +4 -0
  15. package/dist/components/TagInput/TagInput.css +72 -0
  16. package/dist/components/TagInput/TagInput2.js +116 -0
  17. package/dist/components/TimePicker/TimePicker.css +179 -0
  18. package/dist/components/TimePicker/TimePicker2.js +239 -0
  19. package/dist/components/Timeline/Timeline.css +128 -0
  20. package/dist/components/Timeline/Timeline2.js +49 -0
  21. package/dist/components/Toolbar/Toolbar.css +37 -0
  22. package/dist/components/Toolbar/Toolbar2.js +71 -0
  23. package/dist/components/UtilityButton/UtilityButton.css +6 -6
  24. package/dist/components/VisuallyHidden/VisuallyHidden.css +26 -0
  25. package/dist/components/VisuallyHidden/VisuallyHidden2.js +21 -0
  26. package/dist/index.cjs +786 -7
  27. package/dist/index.js +10 -1
  28. package/dist/src/components/Badge/Badge.d.ts +1 -1
  29. package/dist/src/components/Button/Button.d.ts +1 -1
  30. package/dist/src/components/Collapsible/Collapsible.d.ts +11 -0
  31. package/dist/src/components/Collapsible/Collapsible.test.d.ts +1 -0
  32. package/dist/src/components/Collapsible/index.d.ts +1 -0
  33. package/dist/src/components/ContextMenu/ContextMenu.d.ts +20 -0
  34. package/dist/src/components/ContextMenu/ContextMenu.test.d.ts +1 -0
  35. package/dist/src/components/ContextMenu/index.d.ts +1 -0
  36. package/dist/src/components/InlineCTA/InlineCTA.d.ts +1 -1
  37. package/dist/src/components/Resizable/Resizable.d.ts +19 -0
  38. package/dist/src/components/Resizable/Resizable.test.d.ts +1 -0
  39. package/dist/src/components/Resizable/index.d.ts +1 -0
  40. package/dist/src/components/ScrollArea/ScrollArea.d.ts +12 -0
  41. package/dist/src/components/ScrollArea/ScrollArea.test.d.ts +1 -0
  42. package/dist/src/components/ScrollArea/index.d.ts +1 -0
  43. package/dist/src/components/Tag/Tag.d.ts +1 -1
  44. package/dist/src/components/TagInput/TagInput.d.ts +23 -0
  45. package/dist/src/components/TagInput/TagInput.test.d.ts +1 -0
  46. package/dist/src/components/TagInput/index.d.ts +1 -0
  47. package/dist/src/components/TimePicker/TimePicker.d.ts +18 -0
  48. package/dist/src/components/TimePicker/TimePicker.test.d.ts +1 -0
  49. package/dist/src/components/TimePicker/index.d.ts +1 -0
  50. package/dist/src/components/Timeline/Timeline.d.ts +16 -0
  51. package/dist/src/components/Timeline/Timeline.test.d.ts +1 -0
  52. package/dist/src/components/Timeline/index.d.ts +1 -0
  53. package/dist/src/components/Toolbar/Toolbar.d.ts +8 -0
  54. package/dist/src/components/Toolbar/Toolbar.test.d.ts +1 -0
  55. package/dist/src/components/Toolbar/index.d.ts +1 -0
  56. package/dist/src/components/UtilityButton/UtilityButton.d.ts +1 -1
  57. package/dist/src/components/VisuallyHidden/VisuallyHidden.d.ts +15 -0
  58. package/dist/src/components/VisuallyHidden/VisuallyHidden.test.d.ts +1 -0
  59. package/dist/src/components/VisuallyHidden/index.d.ts +1 -0
  60. package/dist/src/index.d.ts +9 -0
  61. package/dist/styles/theme.css +89 -4
  62. package/dist/styles.css +903 -11
  63. package/package.json +1 -1
@@ -0,0 +1,54 @@
1
+ .pf-scroll-area {
2
+ /* Standard scrollbar styling (Firefox + modern browsers). */
3
+ scrollbar-color: var(--pf-scrollarea-thumb) transparent;
4
+ scrollbar-width: thin;
5
+ /* Reserve a gutter so the scrollbar never overlays (and obscures) content. */
6
+ scrollbar-gutter: stable;
7
+ }
8
+
9
+ .pf-scroll-area:focus-visible {
10
+ border-radius: var(--radius-sm);
11
+ box-shadow: var(--pf-scrollarea-focus-ring, var(--pf-focus-ring));
12
+ outline: none;
13
+ }
14
+
15
+ .pf-scroll-area--vertical {
16
+ overflow-x: hidden;
17
+ overflow-y: auto;
18
+ }
19
+
20
+ .pf-scroll-area--horizontal {
21
+ overflow-x: auto;
22
+ overflow-y: hidden;
23
+ }
24
+
25
+ .pf-scroll-area--both {
26
+ overflow: auto;
27
+ }
28
+
29
+ /* WebKit / Blink scrollbar styling. */
30
+ .pf-scroll-area::-webkit-scrollbar {
31
+ height: 10px;
32
+ width: 10px;
33
+ }
34
+
35
+ .pf-scroll-area::-webkit-scrollbar-track {
36
+ background: transparent;
37
+ }
38
+
39
+ .pf-scroll-area::-webkit-scrollbar-thumb {
40
+ background: var(--pf-scrollarea-thumb);
41
+ /* Transparent border + padding-box clip insets the thumb so it reads slimmer. */
42
+ background-clip: padding-box;
43
+ border: 2px solid transparent;
44
+ border-radius: var(--radius-full);
45
+ }
46
+
47
+ .pf-scroll-area::-webkit-scrollbar-thumb:hover {
48
+ background: var(--pf-scrollarea-thumb-hover);
49
+ background-clip: padding-box;
50
+ }
51
+
52
+ .pf-scroll-area::-webkit-scrollbar-corner {
53
+ background: transparent;
54
+ }
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { cx } from "../../utils/cx.js";
3
+ import './ScrollArea.css';/* empty css */
4
+ import { forwardRef } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+ //#region src/components/ScrollArea/ScrollArea.tsx
7
+ var ScrollArea = forwardRef(function ScrollArea({ className, orientation = "vertical", focusable = true, tabIndex, children, ...props }, ref) {
8
+ return /* @__PURE__ */ jsx("div", {
9
+ ref,
10
+ className: cx("pf-scroll-area", `pf-scroll-area--${orientation}`, className),
11
+ tabIndex: tabIndex ?? (focusable ? 0 : void 0),
12
+ ...props,
13
+ children
14
+ });
15
+ });
16
+ ScrollArea.displayName = "ScrollArea";
17
+ //#endregion
18
+ export { ScrollArea };
@@ -32,6 +32,10 @@
32
32
  background: var(--pf-tag-warning-bg);
33
33
  color: var(--pf-tag-warning-text);
34
34
  }
35
+ .pf-tag--danger {
36
+ background: var(--pf-tag-danger-bg);
37
+ color: var(--pf-tag-danger-text);
38
+ }
35
39
 
36
40
  .pf-tag__dismiss {
37
41
  align-items: center;
@@ -0,0 +1,72 @@
1
+ .pf-taginput {
2
+ background: var(--pf-taginput-bg);
3
+ border: 1px solid var(--pf-taginput-border);
4
+ border-radius: var(--radius-md);
5
+ cursor: text;
6
+ min-height: 40px;
7
+ padding: var(--space-1);
8
+ transition:
9
+ border 0.2s,
10
+ box-shadow 0.2s;
11
+ }
12
+
13
+ .pf-taginput:focus-within {
14
+ border-color: var(--pf-taginput-focus-border);
15
+ box-shadow: var(--pf-taginput-focus-ring, var(--pf-focus-ring));
16
+ }
17
+
18
+ .pf-taginput--invalid {
19
+ border-color: var(--pf-taginput-invalid-border);
20
+ }
21
+
22
+ .pf-taginput--disabled {
23
+ background: var(--pf-control-bg-disabled);
24
+ border-color: var(--pf-control-border-disabled);
25
+ cursor: not-allowed;
26
+ opacity: 0.6;
27
+ }
28
+
29
+ .pf-taginput__tags {
30
+ align-items: center;
31
+ display: flex;
32
+ flex-wrap: wrap;
33
+ gap: var(--space-1);
34
+ list-style: none;
35
+ margin: 0;
36
+ padding: 0;
37
+ }
38
+
39
+ .pf-taginput__tag {
40
+ display: inline-flex;
41
+ }
42
+
43
+ .pf-taginput__field {
44
+ display: inline-flex;
45
+ flex: 1;
46
+ min-width: 8ch;
47
+ }
48
+
49
+ .pf-taginput__input {
50
+ background: transparent;
51
+ border: none;
52
+ color: var(--pf-taginput-text);
53
+ flex: 1;
54
+ font: inherit;
55
+ min-width: 0;
56
+ outline: none;
57
+ padding: var(--space-1) var(--space-2);
58
+ }
59
+
60
+ .pf-taginput__input::placeholder {
61
+ color: var(--pf-taginput-placeholder);
62
+ }
63
+
64
+ .pf-taginput__input:disabled {
65
+ cursor: not-allowed;
66
+ }
67
+
68
+ @media (prefers-reduced-motion: reduce) {
69
+ .pf-taginput {
70
+ transition: none;
71
+ }
72
+ }
@@ -0,0 +1,116 @@
1
+ "use client";
2
+ import { Keys, composeDescribedBy } from "../../a11y/index.js";
3
+ import { useComposedRefs } from "../../hooks/useComposedRefs.js";
4
+ import { useControllableState } from "../../hooks/useControllableState.js";
5
+ import { cx } from "../../utils/cx.js";
6
+ import { FieldWrapper } from "../../utils/FieldWrapper.js";
7
+ import { Tag } from "../Tag/Tag2.js";
8
+ import './TagInput.css';/* empty css */
9
+ import { forwardRef, useId, useRef, useState } from "react";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ //#region src/components/TagInput/TagInput.tsx
12
+ var TagInput = forwardRef(function TagInput({ id, value, defaultValue, onValueChange, label, description, error, placeholder = "Add a tag…", max, allowDuplicates = false, delimiters = [Keys.Enter, ","], validate, tagVariant = "neutral", name, required, disabled, className, "aria-describedby": ariaDescribedBy, ...props }, ref) {
13
+ const generatedId = useId();
14
+ const fieldId = id ?? generatedId;
15
+ const descriptionId = description ? `${fieldId}-description` : void 0;
16
+ const errorId = error ? `${fieldId}-error` : void 0;
17
+ const describedBy = composeDescribedBy(ariaDescribedBy, descriptionId, errorId);
18
+ const [tags, setTags] = useControllableState({
19
+ value,
20
+ defaultValue: defaultValue ?? [],
21
+ onChange: onValueChange
22
+ });
23
+ const currentTags = tags ?? [];
24
+ const [draft, setDraft] = useState("");
25
+ const inputRef = useRef(null);
26
+ const inputRefs = useComposedRefs(inputRef, ref);
27
+ const atMax = max !== void 0 && currentTags.length >= max;
28
+ const addTag = (raw) => {
29
+ const tag = raw.trim();
30
+ if (!tag) return;
31
+ if (atMax) return;
32
+ if (validate && !validate(tag)) return;
33
+ const exists = currentTags.some((t) => t.toLowerCase() === tag.toLowerCase());
34
+ if (!allowDuplicates && exists) {
35
+ setDraft("");
36
+ return;
37
+ }
38
+ setTags([...currentTags, tag]);
39
+ setDraft("");
40
+ };
41
+ const removeTag = (index) => {
42
+ setTags(currentTags.filter((_, i) => i !== index));
43
+ };
44
+ const onKeyDown = (event) => {
45
+ if (disabled) return;
46
+ if (delimiters.includes(event.key)) {
47
+ if (draft.trim()) {
48
+ event.preventDefault();
49
+ addTag(draft);
50
+ } else if (event.key !== Keys.Enter) event.preventDefault();
51
+ return;
52
+ }
53
+ if (event.key === "Backspace" && draft === "" && currentTags.length > 0) {
54
+ event.preventDefault();
55
+ removeTag(currentTags.length - 1);
56
+ }
57
+ };
58
+ const onPaste = (event) => {
59
+ const text = event.clipboardData.getData("text");
60
+ if (!/[,\n\t]/.test(text)) return;
61
+ event.preventDefault();
62
+ text.split(/[,\n\t]+/).map((t) => t.trim()).filter(Boolean).forEach((t) => addTag(t));
63
+ };
64
+ return /* @__PURE__ */ jsx(FieldWrapper, {
65
+ labelFor: fieldId,
66
+ label,
67
+ description,
68
+ descriptionId,
69
+ error,
70
+ errorId,
71
+ required,
72
+ children: /* @__PURE__ */ jsxs("div", {
73
+ className: cx("pf-taginput", error && "pf-taginput--invalid", disabled && "pf-taginput--disabled"),
74
+ onClick: () => inputRef.current?.focus(),
75
+ children: [/* @__PURE__ */ jsxs("ul", {
76
+ className: "pf-taginput__tags",
77
+ children: [currentTags.map((tag, index) => /* @__PURE__ */ jsx("li", {
78
+ className: "pf-taginput__tag",
79
+ children: /* @__PURE__ */ jsx(Tag, {
80
+ variant: tagVariant,
81
+ dismissible: !disabled,
82
+ onDismiss: () => removeTag(index),
83
+ children: tag
84
+ })
85
+ }, `${tag}-${index}`)), /* @__PURE__ */ jsx("li", {
86
+ className: "pf-taginput__field",
87
+ children: /* @__PURE__ */ jsx("input", {
88
+ ...props,
89
+ id: fieldId,
90
+ ref: inputRefs,
91
+ type: "text",
92
+ className: cx("pf-taginput__input", className),
93
+ value: draft,
94
+ placeholder: currentTags.length === 0 ? placeholder : "",
95
+ disabled: disabled || atMax,
96
+ required: required && currentTags.length === 0,
97
+ autoComplete: "off",
98
+ "aria-invalid": error ? true : void 0,
99
+ "aria-describedby": describedBy,
100
+ onChange: (event) => setDraft(event.target.value),
101
+ onKeyDown,
102
+ onPaste,
103
+ onBlur: () => addTag(draft)
104
+ })
105
+ })]
106
+ }), name ? currentTags.map((tag, index) => /* @__PURE__ */ jsx("input", {
107
+ type: "hidden",
108
+ name,
109
+ value: tag
110
+ }, index)) : null]
111
+ })
112
+ });
113
+ });
114
+ TagInput.displayName = "TagInput";
115
+ //#endregion
116
+ export { TagInput };
@@ -0,0 +1,179 @@
1
+ .pf-timepicker {
2
+ position: relative;
3
+ }
4
+
5
+ /* ── Trigger ──────────────────────────────────────────────────────────────── */
6
+
7
+ .pf-timepicker__trigger {
8
+ align-items: center;
9
+ background: var(--pf-timepicker-bg);
10
+ border: 1px solid var(--pf-timepicker-border);
11
+ border-radius: var(--radius-md);
12
+ color: var(--pf-timepicker-text);
13
+ cursor: pointer;
14
+ display: flex;
15
+ font: inherit;
16
+ gap: var(--space-2);
17
+ justify-content: space-between;
18
+ min-height: 40px;
19
+ padding: 0 var(--space-3);
20
+ text-align: start;
21
+ width: 100%;
22
+ transition:
23
+ border 0.2s,
24
+ box-shadow 0.2s;
25
+ }
26
+
27
+ .pf-timepicker__trigger:focus {
28
+ outline: none;
29
+ }
30
+
31
+ .pf-timepicker__trigger:focus-visible,
32
+ .pf-timepicker__trigger--open {
33
+ border-color: var(--pf-timepicker-focus-border);
34
+ box-shadow: var(--pf-timepicker-focus-ring, var(--pf-focus-ring));
35
+ }
36
+
37
+ .pf-timepicker__trigger--invalid {
38
+ border-color: var(--pf-timepicker-invalid-border);
39
+ }
40
+
41
+ .pf-timepicker__trigger:disabled {
42
+ background: var(--pf-control-bg-disabled);
43
+ border-color: var(--pf-control-border-disabled);
44
+ color: var(--pf-control-text-disabled);
45
+ cursor: not-allowed;
46
+ opacity: 0.6;
47
+ }
48
+
49
+ .pf-timepicker__value {
50
+ overflow: hidden;
51
+ text-overflow: ellipsis;
52
+ white-space: nowrap;
53
+ }
54
+
55
+ .pf-timepicker__value--placeholder {
56
+ color: var(--pf-timepicker-placeholder);
57
+ }
58
+
59
+ .pf-timepicker__icon {
60
+ align-items: center;
61
+ color: var(--pf-timepicker-text-muted);
62
+ display: inline-flex;
63
+ flex-shrink: 0;
64
+ }
65
+
66
+ .pf-timepicker__icon svg {
67
+ display: block;
68
+ height: 18px;
69
+ width: 18px;
70
+ }
71
+
72
+ /* ── Panel ────────────────────────────────────────────────────────────────── */
73
+
74
+ .pf-timepicker__panel {
75
+ animation: pf-timepicker-in var(--duration-fast) var(--easing-decelerate);
76
+ background: var(--pf-timepicker-menu-bg);
77
+ border: 1px solid var(--pf-timepicker-menu-border);
78
+ border-radius: var(--radius-md);
79
+ box-shadow: var(--pf-elevation-popover-shadow);
80
+ display: flex;
81
+ gap: var(--space-1);
82
+ padding: var(--space-1);
83
+ position: fixed;
84
+ z-index: 1000;
85
+ }
86
+
87
+ .pf-timepicker__panel--exiting {
88
+ animation: pf-timepicker-out var(--duration-fast) var(--easing-accelerate) forwards;
89
+ }
90
+
91
+ @keyframes pf-timepicker-in {
92
+ from {
93
+ opacity: 0;
94
+ transform: translateY(-4px);
95
+ }
96
+ to {
97
+ opacity: 1;
98
+ transform: translateY(0);
99
+ }
100
+ }
101
+
102
+ @keyframes pf-timepicker-out {
103
+ from {
104
+ opacity: 1;
105
+ transform: translateY(0);
106
+ }
107
+ to {
108
+ opacity: 0;
109
+ transform: translateY(-4px);
110
+ }
111
+ }
112
+
113
+ /* ── Columns ──────────────────────────────────────────────────────────────── */
114
+
115
+ .pf-timepicker__column {
116
+ display: flex;
117
+ flex-direction: column;
118
+ gap: 2px;
119
+ max-height: 220px;
120
+ overflow-y: auto;
121
+ scroll-behavior: smooth;
122
+ scrollbar-width: thin;
123
+ }
124
+
125
+ .pf-timepicker__column--meridiem {
126
+ overflow-y: visible;
127
+ }
128
+
129
+ .pf-timepicker__option {
130
+ appearance: none;
131
+ /* Explicit opaque background (matching the panel) so axe can determine the
132
+ contrast background directly on each option, even when it's partially
133
+ clipped by the scrolling column. */
134
+ background: var(--pf-timepicker-menu-bg);
135
+ border: 0;
136
+ border-radius: var(--radius-sm);
137
+ color: var(--pf-timepicker-text);
138
+ cursor: pointer;
139
+ font: inherit;
140
+ font-variant-numeric: tabular-nums;
141
+ min-width: 3ch;
142
+ padding: var(--space-2) var(--space-3);
143
+ text-align: center;
144
+ }
145
+
146
+ .pf-timepicker__option:hover {
147
+ background: var(--pf-timepicker-option-hover-bg);
148
+ }
149
+
150
+ .pf-timepicker__option:focus-visible {
151
+ outline: none;
152
+ box-shadow: inset 0 0 0 2px var(--pf-timepicker-focus-border);
153
+ }
154
+
155
+ .pf-timepicker__option--selected {
156
+ background: var(--pf-timepicker-option-active-bg);
157
+ color: var(--pf-timepicker-option-active-text);
158
+ font-weight: var(--font-weight-medium);
159
+ }
160
+
161
+ .pf-timepicker__option--selected:hover {
162
+ background: var(--pf-timepicker-option-active-bg);
163
+ color: var(--pf-timepicker-option-active-text);
164
+ }
165
+
166
+ @media (prefers-reduced-motion: reduce) {
167
+ .pf-timepicker__trigger {
168
+ transition: none;
169
+ }
170
+
171
+ .pf-timepicker__panel,
172
+ .pf-timepicker__panel--exiting {
173
+ animation: none;
174
+ }
175
+
176
+ .pf-timepicker__column {
177
+ scroll-behavior: auto;
178
+ }
179
+ }
@@ -0,0 +1,239 @@
1
+ "use client";
2
+ import { Keys, composeDescribedBy } from "../../a11y/index.js";
3
+ import { useAnchoredPosition } from "../../hooks/useAnchoredPosition.js";
4
+ import { useComposedRefs } from "../../hooks/useComposedRefs.js";
5
+ import { useControllableState } from "../../hooks/useControllableState.js";
6
+ import { useDisclosure } from "../../hooks/useDisclosure.js";
7
+ import { useOutsideInteraction } from "../../hooks/useOutsideInteraction.js";
8
+ import { usePresence } from "../../hooks/usePresence.js";
9
+ import { cx } from "../../utils/cx.js";
10
+ import { Icon } from "../Icon/Icon2.js";
11
+ import { FieldWrapper } from "../../utils/FieldWrapper.js";
12
+ import './TimePicker.css';/* empty css */
13
+ import { forwardRef, useEffect, useId, useRef } from "react";
14
+ import { jsx, jsxs } from "react/jsx-runtime";
15
+ import { createPortal } from "react-dom";
16
+ //#region src/components/TimePicker/TimePicker.tsx
17
+ var pad = (n) => String(n).padStart(2, "0");
18
+ var parseValue = (value) => {
19
+ const match = /^(\d{1,2}):(\d{2})$/.exec(value.trim());
20
+ if (!match) return {
21
+ hour: null,
22
+ minute: null
23
+ };
24
+ const hour = Number(match[1]);
25
+ const minute = Number(match[2]);
26
+ if (hour > 23 || minute > 59) return {
27
+ hour: null,
28
+ minute: null
29
+ };
30
+ return {
31
+ hour,
32
+ minute
33
+ };
34
+ };
35
+ var formatDisplay = (parts, hourCycle) => {
36
+ if (parts.hour === null || parts.minute === null) return "";
37
+ if (hourCycle === 24) return `${pad(parts.hour)}:${pad(parts.minute)}`;
38
+ const meridiem = parts.hour < 12 ? "AM" : "PM";
39
+ return `${parts.hour % 12 === 0 ? 12 : parts.hour % 12}:${pad(parts.minute)} ${meridiem}`;
40
+ };
41
+ var range = (length, step = 1) => Array.from({ length: Math.ceil(length / step) }, (_, i) => i * step);
42
+ var TimePicker = forwardRef(function TimePicker({ id, value, defaultValue, onValueChange, hourCycle = 24, minuteStep = 1, label, description, error, placeholder = "Select time", required, name, disabled, className, "aria-describedby": ariaDescribedBy, ...props }, ref) {
43
+ const generatedId = useId();
44
+ const fieldId = id ?? generatedId;
45
+ const panelId = `${fieldId}-panel`;
46
+ const descriptionId = description ? `${fieldId}-description` : void 0;
47
+ const errorId = error ? `${fieldId}-error` : void 0;
48
+ const describedBy = composeDescribedBy(ariaDescribedBy, descriptionId, errorId);
49
+ const [current, setCurrent] = useControllableState({
50
+ value,
51
+ defaultValue: defaultValue ?? "",
52
+ onChange: onValueChange
53
+ });
54
+ const parts = parseValue(current ?? "");
55
+ const disclosure = useDisclosure({ disabled });
56
+ const isOpen = disclosure.isOpen ?? false;
57
+ const rootRef = useRef(null);
58
+ const triggerRefs = useComposedRefs(useRef(null), ref);
59
+ const panelRef = useRef(null);
60
+ const { isMounted, isExiting } = usePresence(isOpen, 160);
61
+ const panelStyle = useAnchoredPosition({
62
+ anchorRef: rootRef,
63
+ floatingRef: panelRef,
64
+ enabled: isOpen,
65
+ matchAnchorWidth: false,
66
+ flip: true
67
+ });
68
+ useOutsideInteraction({
69
+ refs: [rootRef, panelRef],
70
+ enabled: isOpen,
71
+ onInteractOutside: () => disclosure.close()
72
+ });
73
+ const hours = hourCycle === 24 ? range(24) : range(12).map((h) => h + 1);
74
+ const minutes = range(60, minuteStep);
75
+ const meridiems = ["AM", "PM"];
76
+ const selectedMeridiem = parts.hour === null ? null : parts.hour < 12 ? "AM" : "PM";
77
+ const selectedHourDisplay = parts.hour === null ? null : hourCycle === 24 ? parts.hour : parts.hour % 12 === 0 ? 12 : parts.hour % 12;
78
+ const emit = (next) => {
79
+ if (next.hour === null || next.minute === null) return;
80
+ setCurrent(`${pad(next.hour)}:${pad(next.minute)}`);
81
+ };
82
+ const selectHour = (h) => {
83
+ let hour24;
84
+ if (hourCycle === 24) hour24 = h;
85
+ else {
86
+ const meridiem = selectedMeridiem ?? "AM";
87
+ const base = h % 12;
88
+ hour24 = meridiem === "PM" ? base + 12 : base;
89
+ }
90
+ emit({
91
+ hour: hour24,
92
+ minute: parts.minute ?? 0
93
+ });
94
+ };
95
+ const selectMinute = (m) => {
96
+ emit({
97
+ hour: parts.hour ?? (hourCycle === 12 ? 0 : 0),
98
+ minute: m
99
+ });
100
+ };
101
+ const selectMeridiem = (mer) => {
102
+ const base = (parts.hour ?? 0) % 12;
103
+ emit({
104
+ hour: mer === "PM" ? base + 12 : base,
105
+ minute: parts.minute ?? 0
106
+ });
107
+ };
108
+ const display = formatDisplay(parts, hourCycle);
109
+ useEffect(() => {
110
+ if (!isMounted) return;
111
+ const frame = requestAnimationFrame(() => {
112
+ panelRef.current?.querySelectorAll("[data-selected=\"true\"]").forEach((el) => el.scrollIntoView({ block: "center" }));
113
+ });
114
+ return () => cancelAnimationFrame(frame);
115
+ }, [isMounted]);
116
+ const onColumnKeyDown = (event) => {
117
+ if (event.key !== Keys.ArrowDown && event.key !== Keys.ArrowUp) return;
118
+ const buttons = Array.from(event.currentTarget.querySelectorAll("button:not(:disabled)"));
119
+ const index = buttons.indexOf(document.activeElement);
120
+ if (index === -1) return;
121
+ event.preventDefault();
122
+ buttons[event.key === Keys.ArrowDown ? Math.min(index + 1, buttons.length - 1) : Math.max(index - 1, 0)]?.focus();
123
+ };
124
+ return /* @__PURE__ */ jsx(FieldWrapper, {
125
+ labelFor: fieldId,
126
+ label,
127
+ description,
128
+ descriptionId,
129
+ error,
130
+ errorId,
131
+ required,
132
+ children: /* @__PURE__ */ jsxs("div", {
133
+ className: "pf-timepicker",
134
+ ref: rootRef,
135
+ children: [
136
+ /* @__PURE__ */ jsxs("button", {
137
+ ...props,
138
+ id: fieldId,
139
+ ref: triggerRefs,
140
+ type: "button",
141
+ className: cx("pf-timepicker__trigger", isOpen && "pf-timepicker__trigger--open", error && "pf-timepicker__trigger--invalid", className),
142
+ disabled,
143
+ "aria-haspopup": "dialog",
144
+ "aria-expanded": isOpen,
145
+ "aria-required": required || void 0,
146
+ "aria-invalid": error ? true : void 0,
147
+ "aria-describedby": describedBy,
148
+ onClick: () => disclosure.toggle(),
149
+ onKeyDown: (event) => {
150
+ if (event.key === Keys.Escape) disclosure.close();
151
+ },
152
+ children: [/* @__PURE__ */ jsx("span", {
153
+ className: cx("pf-timepicker__value", !display && "pf-timepicker__value--placeholder"),
154
+ children: display || placeholder
155
+ }), /* @__PURE__ */ jsx("span", {
156
+ "aria-hidden": true,
157
+ className: "pf-timepicker__icon",
158
+ children: /* @__PURE__ */ jsx(Icon, {
159
+ name: "clock",
160
+ "aria-hidden": true
161
+ })
162
+ })]
163
+ }),
164
+ name ? /* @__PURE__ */ jsx("input", {
165
+ type: "hidden",
166
+ name,
167
+ value: current ?? ""
168
+ }) : null,
169
+ isMounted && typeof document !== "undefined" ? createPortal(/* @__PURE__ */ jsxs("div", {
170
+ id: panelId,
171
+ ref: panelRef,
172
+ role: "dialog",
173
+ "aria-label": label ? `${label} picker` : "Time picker",
174
+ className: cx("pf-timepicker__panel", isExiting && "pf-timepicker__panel--exiting"),
175
+ style: panelStyle,
176
+ children: [
177
+ /* @__PURE__ */ jsx("div", {
178
+ className: "pf-timepicker__column",
179
+ role: "listbox",
180
+ "aria-label": "Hour",
181
+ onKeyDown: onColumnKeyDown,
182
+ children: hours.map((h) => {
183
+ const isSel = selectedHourDisplay === h;
184
+ return /* @__PURE__ */ jsx("button", {
185
+ type: "button",
186
+ role: "option",
187
+ "aria-selected": isSel,
188
+ "data-selected": isSel,
189
+ className: cx("pf-timepicker__option", isSel && "pf-timepicker__option--selected"),
190
+ onClick: () => selectHour(h),
191
+ children: pad(h)
192
+ }, h);
193
+ })
194
+ }),
195
+ /* @__PURE__ */ jsx("div", {
196
+ className: "pf-timepicker__column",
197
+ role: "listbox",
198
+ "aria-label": "Minute",
199
+ onKeyDown: onColumnKeyDown,
200
+ children: minutes.map((m) => {
201
+ const isSel = parts.minute === m;
202
+ return /* @__PURE__ */ jsx("button", {
203
+ type: "button",
204
+ role: "option",
205
+ "aria-selected": isSel,
206
+ "data-selected": isSel,
207
+ className: cx("pf-timepicker__option", isSel && "pf-timepicker__option--selected"),
208
+ onClick: () => selectMinute(m),
209
+ children: pad(m)
210
+ }, m);
211
+ })
212
+ }),
213
+ hourCycle === 12 ? /* @__PURE__ */ jsx("div", {
214
+ className: "pf-timepicker__column pf-timepicker__column--meridiem",
215
+ role: "listbox",
216
+ "aria-label": "AM or PM",
217
+ onKeyDown: onColumnKeyDown,
218
+ children: meridiems.map((mer) => {
219
+ const isSel = selectedMeridiem === mer;
220
+ return /* @__PURE__ */ jsx("button", {
221
+ type: "button",
222
+ role: "option",
223
+ "aria-selected": isSel,
224
+ "data-selected": isSel,
225
+ className: cx("pf-timepicker__option", isSel && "pf-timepicker__option--selected"),
226
+ onClick: () => selectMeridiem(mer),
227
+ children: mer
228
+ }, mer);
229
+ })
230
+ }) : null
231
+ ]
232
+ }), document.body) : null
233
+ ]
234
+ })
235
+ });
236
+ });
237
+ TimePicker.displayName = "TimePicker";
238
+ //#endregion
239
+ export { TimePicker };