@pitchfork-ui/react 0.7.0 → 0.9.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 (117) hide show
  1. package/LICENSE +21 -0
  2. package/dist/a11y/index.js +1 -0
  3. package/dist/components/Accordion/Accordion2.js +1 -0
  4. package/dist/components/Alert/Alert2.js +1 -0
  5. package/dist/components/Avatar/Avatar2.js +1 -0
  6. package/dist/components/AvatarGroup/AvatarGroup.css +26 -0
  7. package/dist/components/AvatarGroup/AvatarGroup2.js +38 -0
  8. package/dist/components/Badge/Badge2.js +1 -0
  9. package/dist/components/BadgeGroup/BadgeGroup2.js +1 -0
  10. package/dist/components/Breadcrumbs/Breadcrumbs2.js +1 -0
  11. package/dist/components/Button/Button2.js +1 -0
  12. package/dist/components/ButtonGroup/ButtonGroup2.js +1 -0
  13. package/dist/components/Calendar/Calendar.css +0 -1
  14. package/dist/components/Calendar/Calendar2.js +1 -0
  15. package/dist/components/Card/Card2.js +1 -0
  16. package/dist/components/Carousel/Carousel2.js +1 -0
  17. package/dist/components/Checkbox/Checkbox2.js +1 -0
  18. package/dist/components/CodeSnippet/CodeSnippet2.js +1 -0
  19. package/dist/components/Combobox/Combobox.css +155 -0
  20. package/dist/components/Combobox/Combobox2.js +192 -0
  21. package/dist/components/CommandPalette/CommandPalette.css +225 -0
  22. package/dist/components/CommandPalette/CommandPalette2.js +196 -0
  23. package/dist/components/ContentDivider/ContentDivider2.js +1 -0
  24. package/dist/components/CreditCard/CreditCard2.js +1 -0
  25. package/dist/components/DatePicker/DatePicker2.js +1 -0
  26. package/dist/components/DateRangePicker/DateRangePicker.css +258 -0
  27. package/dist/components/DateRangePicker/DateRangePicker2.js +379 -0
  28. package/dist/components/Dropdown/Dropdown2.js +1 -0
  29. package/dist/components/EmptyState/EmptyState2.js +1 -0
  30. package/dist/components/FileUploader/FileUploader2.js +1 -0
  31. package/dist/components/GaugeChart/GaugeChart2.js +1 -0
  32. package/dist/components/HeaderNavigation/HeaderNavigation2.js +1 -0
  33. package/dist/components/Heatmap/Heatmap2.js +1 -0
  34. package/dist/components/Icon/Icon2.js +44 -0
  35. package/dist/components/InlineCTA/InlineCTA2.js +1 -0
  36. package/dist/components/Input/Input2.js +1 -0
  37. package/dist/components/Kbd/Kbd.css +25 -0
  38. package/dist/components/Kbd/Kbd2.js +18 -0
  39. package/dist/components/LineBarCharts/LineBarChart2.js +1 -0
  40. package/dist/components/LoadingIndicators/LoadingIndicators2.js +1 -0
  41. package/dist/components/Metrics/Metrics2.js +1 -0
  42. package/dist/components/Modal/Modal.css +6 -3
  43. package/dist/components/Modal/Modal2.js +1 -0
  44. package/dist/components/MultiSelect/MultiSelect2.js +1 -0
  45. package/dist/components/Notification/Notification2.js +1 -0
  46. package/dist/components/NumberInput/NumberInput.css +98 -0
  47. package/dist/components/NumberInput/NumberInput2.js +166 -0
  48. package/dist/components/PageHeader/PageHeader2.js +1 -0
  49. package/dist/components/Pagination/Pagination2.js +1 -0
  50. package/dist/components/PieChart/PieChart2.js +1 -0
  51. package/dist/components/Popover/Popover.css +46 -0
  52. package/dist/components/Popover/Popover2.js +77 -0
  53. package/dist/components/ProgressIndicators/ProgressIndicators2.js +1 -0
  54. package/dist/components/ProgressSteps/ProgressSteps2.js +1 -0
  55. package/dist/components/RadarChart/RadarChart2.js +1 -0
  56. package/dist/components/RadioButton/RadioButton2.js +1 -0
  57. package/dist/components/RadioGroup/RadioGroup2.js +1 -0
  58. package/dist/components/Rating/Rating2.js +1 -0
  59. package/dist/components/RichTextEditor/RichTextEditor2.js +1 -0
  60. package/dist/components/SectionFooter/SectionFooter2.js +1 -0
  61. package/dist/components/SectionHeader/SectionHeader2.js +1 -0
  62. package/dist/components/Select/Select2.js +1 -0
  63. package/dist/components/SidebarNavigation/SidebarNavigation2.js +1 -0
  64. package/dist/components/SlideoutMenu/SlideoutMenu2.js +1 -0
  65. package/dist/components/Slider/Slider2.js +1 -0
  66. package/dist/components/Sparkline/Sparkline2.js +1 -0
  67. package/dist/components/Switch/Switch2.js +1 -0
  68. package/dist/components/Table/Table2.js +1 -0
  69. package/dist/components/Tabs/Tabs2.js +1 -0
  70. package/dist/components/Tag/Tag2.js +1 -0
  71. package/dist/components/Textarea/Textarea2.js +1 -0
  72. package/dist/components/Toast/Toast.js +130 -0
  73. package/dist/components/Tooltip/Tooltip2.js +1 -0
  74. package/dist/components/TreeView/TreeView2.js +1 -0
  75. package/dist/components/UtilityButton/UtilityButton2.js +1 -0
  76. package/dist/components/VideoPlayer/VideoPlayer2.js +1 -0
  77. package/dist/hooks/useAnchoredPosition.js +1 -0
  78. package/dist/hooks/useComposedRefs.js +1 -0
  79. package/dist/hooks/useControllableState.js +1 -0
  80. package/dist/hooks/useDisclosure.js +1 -0
  81. package/dist/hooks/useExitAnimation.js +1 -0
  82. package/dist/hooks/useFocusTrap.js +1 -0
  83. package/dist/hooks/useListNavigation.js +1 -0
  84. package/dist/hooks/useOutsideInteraction.js +1 -0
  85. package/dist/hooks/usePresence.js +1 -0
  86. package/dist/index.cjs +1191 -24
  87. package/dist/index.js +10 -1
  88. package/dist/src/components/AvatarGroup/AvatarGroup.d.ts +14 -0
  89. package/dist/src/components/AvatarGroup/AvatarGroup.test.d.ts +1 -0
  90. package/dist/src/components/AvatarGroup/index.d.ts +1 -0
  91. package/dist/src/components/Combobox/Combobox.d.ts +20 -0
  92. package/dist/src/components/Combobox/Combobox.test.d.ts +1 -0
  93. package/dist/src/components/Combobox/index.d.ts +1 -0
  94. package/dist/src/components/CommandPalette/CommandPalette.d.ts +18 -0
  95. package/dist/src/components/CommandPalette/CommandPalette.test.d.ts +1 -0
  96. package/dist/src/components/CommandPalette/index.d.ts +1 -0
  97. package/dist/src/components/DateRangePicker/DateRangePicker.d.ts +21 -0
  98. package/dist/src/components/DateRangePicker/DateRangePicker.test.d.ts +1 -0
  99. package/dist/src/components/DateRangePicker/index.d.ts +1 -0
  100. package/dist/src/components/Kbd/Kbd.d.ts +9 -0
  101. package/dist/src/components/Kbd/Kbd.test.d.ts +1 -0
  102. package/dist/src/components/Kbd/index.d.ts +1 -0
  103. package/dist/src/components/NumberInput/NumberInput.d.ts +19 -0
  104. package/dist/src/components/NumberInput/NumberInput.test.d.ts +1 -0
  105. package/dist/src/components/NumberInput/index.d.ts +1 -0
  106. package/dist/src/components/Popover/Popover.d.ts +21 -0
  107. package/dist/src/components/Popover/Popover.test.d.ts +1 -0
  108. package/dist/src/components/Popover/index.d.ts +1 -0
  109. package/dist/src/components/Toast/Toast.d.ts +35 -0
  110. package/dist/src/components/Toast/Toast.test.d.ts +1 -0
  111. package/dist/src/components/Toast/index.d.ts +1 -0
  112. package/dist/src/index.d.ts +8 -0
  113. package/dist/styles/theme.css +68 -0
  114. package/dist/styles.css +983 -80
  115. package/dist/utils/FieldWrapper.js +1 -0
  116. package/dist/utils/cx.js +1 -0
  117. package/package.json +29 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Leland Rangel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  //#region src/a11y/index.ts
2
3
  var Keys = {
3
4
  ArrowDown: "ArrowDown",
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { Keys } from "../../a11y/index.js";
2
3
  import { useControllableState } from "../../hooks/useControllableState.js";
3
4
  import { cx } from "../../utils/cx.js";
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useExitAnimation } from "../../hooks/useExitAnimation.js";
2
3
  import { cx } from "../../utils/cx.js";
3
4
  import { Icon } from "../Icon/Icon2.js";
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import './Avatar.css';/* empty css */
3
4
  import { forwardRef } from "react";
@@ -0,0 +1,26 @@
1
+ .pf-avatar-group {
2
+ display: inline-flex;
3
+ align-items: center;
4
+ /* Overlap amount between avatars */
5
+ --pf-avatar-group-overlap: 8px;
6
+ }
7
+
8
+ .pf-avatar-group--lg,
9
+ .pf-avatar-group--xl {
10
+ --pf-avatar-group-overlap: 12px;
11
+ }
12
+
13
+ .pf-avatar-group__item {
14
+ position: relative;
15
+ /* Ring in the surface color so overlapping avatars stay visually separated */
16
+ box-shadow: 0 0 0 2px var(--pf-avatar-group-ring);
17
+ }
18
+
19
+ .pf-avatar-group__item + .pf-avatar-group__item {
20
+ margin-inline-start: calc(-1 * var(--pf-avatar-group-overlap));
21
+ }
22
+
23
+ .pf-avatar-group__overflow {
24
+ background: var(--pf-avatar-group-overflow-bg);
25
+ color: var(--pf-avatar-group-overflow-text);
26
+ }
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ import { cx } from "../../utils/cx.js";
3
+ import { Avatar } from "../Avatar/Avatar2.js";
4
+ import './AvatarGroup.css';/* empty css */
5
+ import { forwardRef } from "react";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ //#region src/components/AvatarGroup/AvatarGroup.tsx
8
+ var AvatarGroup = forwardRef(function AvatarGroup({ className, avatars, max = 5, size = "md", total, label, ...props }, ref) {
9
+ const shown = avatars.slice(0, Math.max(0, max));
10
+ const overflow = (total ?? avatars.length) - shown.length;
11
+ const count = total ?? avatars.length;
12
+ return /* @__PURE__ */ jsxs("div", {
13
+ ref,
14
+ className: cx("pf-avatar-group", `pf-avatar-group--${size}`, className),
15
+ role: "group",
16
+ "aria-label": label ?? `${count} ${count === 1 ? "person" : "people"}`,
17
+ ...props,
18
+ children: [shown.map((avatar, index) => /* @__PURE__ */ jsx(Avatar, {
19
+ size,
20
+ className: "pf-avatar-group__item",
21
+ style: { zIndex: shown.length - index },
22
+ ...avatar
23
+ }, index)), overflow > 0 ? /* @__PURE__ */ jsx("span", {
24
+ className: cx("pf-avatar", `pf-avatar--${size}`, "pf-avatar-group__item", "pf-avatar-group__overflow"),
25
+ role: "img",
26
+ "aria-label": `${overflow} more`,
27
+ style: { zIndex: 0 },
28
+ children: /* @__PURE__ */ jsxs("span", {
29
+ className: "pf-avatar__fallback",
30
+ "aria-hidden": true,
31
+ children: ["+", overflow]
32
+ })
33
+ }) : null]
34
+ });
35
+ });
36
+ AvatarGroup.displayName = "AvatarGroup";
37
+ //#endregion
38
+ export { AvatarGroup };
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import './Badge.css';/* empty css */
3
4
  import { forwardRef } from "react";
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import './BadgeGroup.css';/* empty css */
3
4
  import { forwardRef } from "react";
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import './Breadcrumbs.css';/* empty css */
3
4
  import { forwardRef } from "react";
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import './Button.css';/* empty css */
3
4
  import { forwardRef } from "react";
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import './ButtonGroup.css';/* empty css */
3
4
  import { forwardRef, useMemo, useState } from "react";
@@ -117,7 +117,6 @@
117
117
 
118
118
  .pf-calendar__day--outside {
119
119
  color: var(--pf-calendar-text-muted);
120
- opacity: 0.55;
121
120
  }
122
121
 
123
122
  .pf-calendar__day--today {
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import { Icon } from "../Icon/Icon2.js";
3
4
  import { Dropdown } from "../Dropdown/Dropdown2.js";
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import './Card.css';/* empty css */
3
4
  import { jsx } from "react/jsx-runtime";
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import { Icon } from "../Icon/Icon2.js";
3
4
  import './Carousel.css';/* empty css */
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import './Checkbox.css';/* empty css */
3
4
  import { forwardRef, useId } from "react";
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { cx } from "../../utils/cx.js";
2
3
  import { Icon } from "../Icon/Icon2.js";
3
4
  import './CodeSnippet.css';/* empty css */
@@ -0,0 +1,155 @@
1
+ .pf-combobox {
2
+ position: relative;
3
+ }
4
+
5
+ .pf-combobox__control {
6
+ align-items: center;
7
+ background: var(--pf-combobox-bg);
8
+ border: 1px solid var(--pf-combobox-border);
9
+ border-radius: var(--radius-md);
10
+ display: flex;
11
+ gap: var(--space-2);
12
+ min-height: 40px;
13
+ padding: 0 var(--space-3);
14
+ transition:
15
+ border 0.2s,
16
+ box-shadow 0.2s;
17
+ }
18
+
19
+ .pf-combobox__control:focus-within {
20
+ border-color: var(--pf-combobox-focus-border);
21
+ box-shadow: var(--pf-combobox-focus-ring, var(--pf-focus-ring));
22
+ }
23
+
24
+ .pf-combobox__control--invalid {
25
+ border-color: var(--pf-combobox-invalid-border);
26
+ }
27
+
28
+ .pf-combobox__input {
29
+ background: transparent;
30
+ border: none;
31
+ color: var(--pf-combobox-text);
32
+ flex: 1;
33
+ font: inherit;
34
+ min-width: 0;
35
+ outline: none;
36
+ padding: 0;
37
+ }
38
+
39
+ .pf-combobox__input::placeholder {
40
+ color: var(--pf-combobox-placeholder);
41
+ }
42
+
43
+ .pf-combobox__input:disabled {
44
+ cursor: not-allowed;
45
+ }
46
+
47
+ .pf-combobox__control:has(.pf-combobox__input:disabled) {
48
+ background: var(--pf-control-bg-disabled);
49
+ border-color: var(--pf-control-border-disabled);
50
+ color: var(--pf-control-text-disabled);
51
+ opacity: 0.6;
52
+ }
53
+
54
+ .pf-combobox__icon {
55
+ align-items: center;
56
+ color: var(--pf-combobox-text);
57
+ display: inline-flex;
58
+ flex-shrink: 0;
59
+ height: 20px;
60
+ justify-content: center;
61
+ transform-origin: center;
62
+ transition: transform var(--pf-transition-fast);
63
+ width: 20px;
64
+ }
65
+
66
+ .pf-combobox__icon svg {
67
+ display: block;
68
+ height: 16px;
69
+ width: 16px;
70
+ }
71
+
72
+ .pf-combobox__icon--open {
73
+ transform: rotate(180deg);
74
+ }
75
+
76
+ .pf-combobox__menu {
77
+ animation: pf-combobox-menu-in var(--duration-fast) var(--easing-decelerate);
78
+ background: var(--pf-combobox-menu-bg);
79
+ border: 1px solid var(--pf-combobox-menu-border);
80
+ border-radius: var(--radius-md);
81
+ box-shadow: var(--pf-combobox-elevation-popover-shadow, var(--pf-elevation-popover-shadow));
82
+ list-style: none;
83
+ margin: 0;
84
+ max-height: 220px;
85
+ overflow: auto;
86
+ padding: var(--space-1);
87
+ position: fixed;
88
+ transform-origin: top center;
89
+ z-index: 1000;
90
+ }
91
+
92
+ .pf-combobox__menu--exiting {
93
+ animation: pf-combobox-menu-out var(--duration-fast) var(--easing-accelerate) forwards;
94
+ }
95
+
96
+ @keyframes pf-combobox-menu-in {
97
+ from {
98
+ opacity: 0;
99
+ transform: translateY(-4px) scaleY(0.96);
100
+ }
101
+ to {
102
+ opacity: 1;
103
+ transform: translateY(0) scaleY(1);
104
+ }
105
+ }
106
+
107
+ @keyframes pf-combobox-menu-out {
108
+ from {
109
+ opacity: 1;
110
+ transform: translateY(0) scaleY(1);
111
+ }
112
+ to {
113
+ opacity: 0;
114
+ transform: translateY(-4px) scaleY(0.96);
115
+ }
116
+ }
117
+
118
+ .pf-combobox__option {
119
+ border-radius: var(--radius-sm);
120
+ color: var(--pf-combobox-text);
121
+ cursor: pointer;
122
+ padding: var(--space-2) var(--space-3);
123
+ }
124
+
125
+ .pf-combobox__option--active {
126
+ background: var(--pf-combobox-option-active-bg);
127
+ color: var(--pf-combobox-option-active-text);
128
+ }
129
+
130
+ .pf-combobox__option--selected {
131
+ font-weight: var(--font-weight-medium);
132
+ }
133
+
134
+ .pf-combobox__option--disabled {
135
+ background: transparent;
136
+ color: var(--pf-combobox-placeholder);
137
+ cursor: not-allowed;
138
+ }
139
+
140
+ .pf-combobox__empty {
141
+ color: var(--pf-combobox-placeholder);
142
+ padding: var(--space-2) var(--space-3);
143
+ }
144
+
145
+ @media (prefers-reduced-motion: reduce) {
146
+ .pf-combobox__control,
147
+ .pf-combobox__icon {
148
+ transition: none;
149
+ }
150
+
151
+ .pf-combobox__menu,
152
+ .pf-combobox__menu--exiting {
153
+ animation: none;
154
+ }
155
+ }
@@ -0,0 +1,192 @@
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 { useOutsideInteraction } from "../../hooks/useOutsideInteraction.js";
7
+ import { usePresence } from "../../hooks/usePresence.js";
8
+ import { cx } from "../../utils/cx.js";
9
+ import { Icon } from "../Icon/Icon2.js";
10
+ import { FieldWrapper } from "../../utils/FieldWrapper.js";
11
+ import './Combobox.css';/* empty css */
12
+ import { forwardRef, useId, useMemo, useRef, useState } from "react";
13
+ import { jsx, jsxs } from "react/jsx-runtime";
14
+ import { createPortal } from "react-dom";
15
+ //#region src/components/Combobox/Combobox.tsx
16
+ var Combobox = forwardRef(function Combobox({ id, options, value, defaultValue, onValueChange, label, description, error, placeholder = "Search…", emptyMessage = "No matches", name, required, className, disabled, "aria-describedby": ariaDescribedBy, ...props }, ref) {
17
+ const generatedId = useId();
18
+ const fieldId = id ?? generatedId;
19
+ const listboxId = `${fieldId}-listbox`;
20
+ const descriptionId = description ? `${fieldId}-description` : void 0;
21
+ const errorId = error ? `${fieldId}-error` : void 0;
22
+ const describedBy = composeDescribedBy(ariaDescribedBy, descriptionId, errorId);
23
+ const [selectedValue, setSelectedValue] = useControllableState({
24
+ value,
25
+ defaultValue: defaultValue ?? "",
26
+ onChange: onValueChange
27
+ });
28
+ const selectedOption = options.find((option) => option.value === selectedValue);
29
+ const [query, setQuery] = useState(() => selectedOption?.label ?? "");
30
+ const [isOpen, setIsOpen] = useState(false);
31
+ const [activeIndex, setActiveIndex] = useState(0);
32
+ const rootRef = useRef(null);
33
+ const inputRef = useRef(null);
34
+ const listboxRef = useRef(null);
35
+ const inputRefs = useComposedRefs(inputRef, ref);
36
+ const { isMounted, isExiting } = usePresence(isOpen, 160);
37
+ const menuStyle = useAnchoredPosition({
38
+ anchorRef: rootRef,
39
+ floatingRef: listboxRef,
40
+ enabled: isOpen,
41
+ matchAnchorWidth: true,
42
+ flip: true
43
+ });
44
+ const filtered = useMemo(() => {
45
+ const q = query.trim().toLowerCase();
46
+ const fromSelection = selectedOption && query === selectedOption.label;
47
+ if (!q || fromSelection) return options;
48
+ return options.filter((option) => option.label.toLowerCase().includes(q));
49
+ }, [
50
+ options,
51
+ query,
52
+ selectedOption
53
+ ]);
54
+ useOutsideInteraction({
55
+ refs: [rootRef, listboxRef],
56
+ enabled: isOpen,
57
+ onInteractOutside: () => closeAndRevert()
58
+ });
59
+ const open = () => {
60
+ if (disabled) return;
61
+ setIsOpen(true);
62
+ setActiveIndex(0);
63
+ };
64
+ const closeAndRevert = () => {
65
+ setIsOpen(false);
66
+ setQuery(selectedOption?.label ?? "");
67
+ };
68
+ const selectOption = (option) => {
69
+ if (option.disabled) return;
70
+ setSelectedValue(option.value);
71
+ setQuery(option.label);
72
+ setIsOpen(false);
73
+ };
74
+ const onKeyDown = (event) => {
75
+ if (disabled) return;
76
+ if (event.key === Keys.ArrowDown) {
77
+ event.preventDefault();
78
+ if (!isOpen) {
79
+ open();
80
+ return;
81
+ }
82
+ setActiveIndex((index) => Math.min(index + 1, filtered.length - 1));
83
+ return;
84
+ }
85
+ if (event.key === Keys.ArrowUp) {
86
+ event.preventDefault();
87
+ if (isOpen) setActiveIndex((index) => Math.max(index - 1, 0));
88
+ return;
89
+ }
90
+ if (event.key === Keys.Enter) {
91
+ if (isOpen && filtered[activeIndex]) {
92
+ event.preventDefault();
93
+ selectOption(filtered[activeIndex]);
94
+ }
95
+ return;
96
+ }
97
+ if (event.key === Keys.Escape) {
98
+ if (isOpen) {
99
+ event.preventDefault();
100
+ closeAndRevert();
101
+ }
102
+ }
103
+ };
104
+ const activeOptionId = isOpen && filtered[activeIndex] ? `${listboxId}-option-${activeIndex}` : void 0;
105
+ return /* @__PURE__ */ jsx(FieldWrapper, {
106
+ labelFor: fieldId,
107
+ label,
108
+ description,
109
+ descriptionId,
110
+ error,
111
+ errorId,
112
+ required,
113
+ children: /* @__PURE__ */ jsxs("div", {
114
+ className: "pf-combobox",
115
+ ref: rootRef,
116
+ children: [
117
+ /* @__PURE__ */ jsxs("div", {
118
+ className: cx("pf-combobox__control", error && "pf-combobox__control--invalid"),
119
+ children: [/* @__PURE__ */ jsx("input", {
120
+ ...props,
121
+ id: fieldId,
122
+ ref: inputRefs,
123
+ type: "text",
124
+ role: "combobox",
125
+ className: cx("pf-combobox__input", className),
126
+ value: query,
127
+ placeholder,
128
+ disabled,
129
+ required,
130
+ autoComplete: "off",
131
+ "aria-autocomplete": "list",
132
+ "aria-expanded": isOpen,
133
+ "aria-controls": listboxId,
134
+ "aria-activedescendant": activeOptionId,
135
+ "aria-describedby": describedBy,
136
+ onChange: (event) => {
137
+ setQuery(event.target.value);
138
+ setActiveIndex(0);
139
+ if (!isOpen) setIsOpen(true);
140
+ },
141
+ onClick: open,
142
+ onKeyDown
143
+ }), /* @__PURE__ */ jsx("span", {
144
+ "aria-hidden": true,
145
+ className: cx("pf-combobox__icon", isOpen && "pf-combobox__icon--open"),
146
+ children: /* @__PURE__ */ jsx(Icon, {
147
+ name: "chevron-down",
148
+ "aria-hidden": true
149
+ })
150
+ })]
151
+ }),
152
+ name ? /* @__PURE__ */ jsx("input", {
153
+ type: "hidden",
154
+ name,
155
+ value: selectedValue
156
+ }) : null,
157
+ isMounted && typeof document !== "undefined" ? createPortal(/* @__PURE__ */ jsx("ul", {
158
+ id: listboxId,
159
+ ref: listboxRef,
160
+ role: "listbox",
161
+ className: cx("pf-combobox__menu", isExiting && "pf-combobox__menu--exiting"),
162
+ style: menuStyle,
163
+ "aria-label": label,
164
+ children: filtered.length === 0 ? /* @__PURE__ */ jsx("li", {
165
+ className: "pf-combobox__empty",
166
+ role: "presentation",
167
+ children: emptyMessage
168
+ }) : filtered.map((option, index) => {
169
+ const isSelected = option.value === selectedValue;
170
+ const isActive = index === activeIndex;
171
+ return /* @__PURE__ */ jsx("li", {
172
+ id: `${listboxId}-option-${index}`,
173
+ role: "option",
174
+ "aria-selected": isSelected,
175
+ "aria-disabled": option.disabled ? true : void 0,
176
+ className: cx("pf-combobox__option", isSelected && "pf-combobox__option--selected", isActive && "pf-combobox__option--active", option.disabled && "pf-combobox__option--disabled"),
177
+ onMouseEnter: () => {
178
+ if (!option.disabled) setActiveIndex(index);
179
+ },
180
+ onMouseDown: (event) => event.preventDefault(),
181
+ onClick: () => selectOption(option),
182
+ children: option.label
183
+ }, option.value);
184
+ })
185
+ }), document.body) : null
186
+ ]
187
+ })
188
+ });
189
+ });
190
+ Combobox.displayName = "Combobox";
191
+ //#endregion
192
+ export { Combobox };