@pitchfork-ui/react 0.8.0 → 0.10.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.
- package/LICENSE +21 -0
- package/dist/a11y/index.js +1 -0
- package/dist/components/Accordion/Accordion2.js +1 -0
- package/dist/components/Alert/Alert2.js +1 -0
- package/dist/components/Avatar/Avatar2.js +1 -0
- package/dist/components/AvatarGroup/AvatarGroup2.js +1 -0
- package/dist/components/Badge/Badge2.js +1 -0
- package/dist/components/BadgeGroup/BadgeGroup2.js +1 -0
- package/dist/components/Breadcrumbs/Breadcrumbs2.js +1 -0
- package/dist/components/Button/Button2.js +1 -0
- package/dist/components/ButtonGroup/ButtonGroup2.js +1 -0
- package/dist/components/Calendar/Calendar2.js +1 -0
- package/dist/components/Card/Card2.js +1 -0
- package/dist/components/Carousel/Carousel2.js +1 -0
- package/dist/components/Checkbox/Checkbox2.js +1 -0
- package/dist/components/CodeSnippet/CodeSnippet2.js +1 -0
- package/dist/components/Collapsible/Collapsible.css +86 -0
- package/dist/components/Collapsible/Collapsible2.js +65 -0
- package/dist/components/Combobox/Combobox2.js +1 -0
- package/dist/components/CommandPalette/CommandPalette2.js +1 -0
- package/dist/components/ContentDivider/ContentDivider2.js +1 -0
- package/dist/components/ContextMenu/ContextMenu.css +122 -0
- package/dist/components/ContextMenu/ContextMenu2.js +155 -0
- package/dist/components/CreditCard/CreditCard2.js +1 -0
- package/dist/components/DatePicker/DatePicker2.js +1 -0
- package/dist/components/DateRangePicker/DateRangePicker2.js +1 -0
- package/dist/components/Dropdown/Dropdown2.js +1 -0
- package/dist/components/EmptyState/EmptyState2.js +1 -0
- package/dist/components/FileUploader/FileUploader2.js +1 -0
- package/dist/components/GaugeChart/GaugeChart2.js +1 -0
- package/dist/components/HeaderNavigation/HeaderNavigation2.js +1 -0
- package/dist/components/Heatmap/Heatmap2.js +1 -0
- package/dist/components/Icon/Icon2.js +18 -0
- package/dist/components/InlineCTA/InlineCTA2.js +1 -0
- package/dist/components/Input/Input2.js +1 -0
- package/dist/components/Kbd/Kbd2.js +1 -0
- package/dist/components/LineBarCharts/LineBarChart2.js +1 -0
- package/dist/components/LoadingIndicators/LoadingIndicators2.js +1 -0
- package/dist/components/Metrics/Metrics2.js +1 -0
- package/dist/components/Modal/Modal.css +6 -3
- package/dist/components/Modal/Modal2.js +1 -0
- package/dist/components/MultiSelect/MultiSelect2.js +1 -0
- package/dist/components/Notification/Notification2.js +1 -0
- package/dist/components/NumberInput/NumberInput2.js +1 -0
- package/dist/components/PageHeader/PageHeader2.js +1 -0
- package/dist/components/Pagination/Pagination2.js +1 -0
- package/dist/components/PieChart/PieChart2.js +1 -0
- package/dist/components/Popover/Popover2.js +1 -0
- package/dist/components/ProgressIndicators/ProgressIndicators2.js +1 -0
- package/dist/components/ProgressSteps/ProgressSteps2.js +1 -0
- package/dist/components/RadarChart/RadarChart2.js +1 -0
- package/dist/components/RadioButton/RadioButton2.js +1 -0
- package/dist/components/RadioGroup/RadioGroup2.js +1 -0
- package/dist/components/Rating/Rating2.js +1 -0
- package/dist/components/Resizable/Resizable.css +79 -0
- package/dist/components/Resizable/Resizable2.js +101 -0
- package/dist/components/RichTextEditor/RichTextEditor2.js +1 -0
- package/dist/components/ScrollArea/ScrollArea.css +54 -0
- package/dist/components/ScrollArea/ScrollArea2.js +18 -0
- package/dist/components/SectionFooter/SectionFooter2.js +1 -0
- package/dist/components/SectionHeader/SectionHeader2.js +1 -0
- package/dist/components/Select/Select2.js +1 -0
- package/dist/components/SidebarNavigation/SidebarNavigation2.js +1 -0
- package/dist/components/SlideoutMenu/SlideoutMenu2.js +1 -0
- package/dist/components/Slider/Slider2.js +1 -0
- package/dist/components/Sparkline/Sparkline2.js +1 -0
- package/dist/components/Switch/Switch2.js +1 -0
- package/dist/components/Table/Table2.js +1 -0
- package/dist/components/Tabs/Tabs2.js +1 -0
- package/dist/components/Tag/Tag2.js +1 -0
- package/dist/components/TagInput/TagInput.css +72 -0
- package/dist/components/TagInput/TagInput2.js +116 -0
- package/dist/components/Textarea/Textarea2.js +1 -0
- package/dist/components/TimePicker/TimePicker.css +179 -0
- package/dist/components/TimePicker/TimePicker2.js +239 -0
- package/dist/components/Timeline/Timeline.css +128 -0
- package/dist/components/Timeline/Timeline2.js +49 -0
- package/dist/components/Toast/Toast.js +1 -0
- package/dist/components/Toolbar/Toolbar.css +37 -0
- package/dist/components/Toolbar/Toolbar2.js +71 -0
- package/dist/components/Tooltip/Tooltip2.js +1 -0
- package/dist/components/TreeView/TreeView2.js +1 -0
- package/dist/components/UtilityButton/UtilityButton2.js +1 -0
- package/dist/components/VideoPlayer/VideoPlayer2.js +1 -0
- package/dist/components/VisuallyHidden/VisuallyHidden.css +26 -0
- package/dist/components/VisuallyHidden/VisuallyHidden2.js +21 -0
- package/dist/hooks/useAnchoredPosition.js +1 -0
- package/dist/hooks/useComposedRefs.js +1 -0
- package/dist/hooks/useControllableState.js +1 -0
- package/dist/hooks/useDisclosure.js +1 -0
- package/dist/hooks/useExitAnimation.js +1 -0
- package/dist/hooks/useFocusTrap.js +1 -0
- package/dist/hooks/useListNavigation.js +1 -0
- package/dist/hooks/useOutsideInteraction.js +1 -0
- package/dist/hooks/usePresence.js +1 -0
- package/dist/index.cjs +787 -7
- package/dist/index.js +11 -1
- package/dist/src/components/Collapsible/Collapsible.d.ts +11 -0
- package/dist/src/components/Collapsible/Collapsible.test.d.ts +1 -0
- package/dist/src/components/Collapsible/index.d.ts +1 -0
- package/dist/src/components/ContextMenu/ContextMenu.d.ts +20 -0
- package/dist/src/components/ContextMenu/ContextMenu.test.d.ts +1 -0
- package/dist/src/components/ContextMenu/index.d.ts +1 -0
- package/dist/src/components/Resizable/Resizable.d.ts +19 -0
- package/dist/src/components/Resizable/Resizable.test.d.ts +1 -0
- package/dist/src/components/Resizable/index.d.ts +1 -0
- package/dist/src/components/ScrollArea/ScrollArea.d.ts +12 -0
- package/dist/src/components/ScrollArea/ScrollArea.test.d.ts +1 -0
- package/dist/src/components/ScrollArea/index.d.ts +1 -0
- package/dist/src/components/TagInput/TagInput.d.ts +23 -0
- package/dist/src/components/TagInput/TagInput.test.d.ts +1 -0
- package/dist/src/components/TagInput/index.d.ts +1 -0
- package/dist/src/components/TimePicker/TimePicker.d.ts +18 -0
- package/dist/src/components/TimePicker/TimePicker.test.d.ts +1 -0
- package/dist/src/components/TimePicker/index.d.ts +1 -0
- package/dist/src/components/Timeline/Timeline.d.ts +16 -0
- package/dist/src/components/Timeline/Timeline.test.d.ts +1 -0
- package/dist/src/components/Timeline/index.d.ts +1 -0
- package/dist/src/components/Toolbar/Toolbar.d.ts +8 -0
- package/dist/src/components/Toolbar/Toolbar.test.d.ts +1 -0
- package/dist/src/components/Toolbar/index.d.ts +1 -0
- package/dist/src/components/VisuallyHidden/VisuallyHidden.d.ts +15 -0
- package/dist/src/components/VisuallyHidden/VisuallyHidden.test.d.ts +1 -0
- package/dist/src/components/VisuallyHidden/index.d.ts +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/styles/theme.css +77 -0
- package/dist/styles.css +866 -3
- package/dist/utils/FieldWrapper.js +1 -0
- package/dist/utils/cx.js +1 -0
- package/package.json +29 -3
|
@@ -30,10 +30,11 @@
|
|
|
30
30
|
.pf-modal {
|
|
31
31
|
background: var(--pf-modal-bg);
|
|
32
32
|
border: 1px solid color-mix(in srgb, var(--pf-modal-border) 85%, transparent);
|
|
33
|
-
border-radius: var(--radius-lg)
|
|
33
|
+
border-radius: var(--radius-lg);
|
|
34
34
|
box-shadow: var(--pf-modal-elevation-overlay-shadow, var(--pf-elevation-overlay-shadow));
|
|
35
35
|
color: var(--pf-modal-text);
|
|
36
|
-
display:
|
|
36
|
+
display: flex;
|
|
37
|
+
flex-direction: column;
|
|
37
38
|
max-height: 92vh;
|
|
38
39
|
overflow: hidden;
|
|
39
40
|
width: 100%;
|
|
@@ -41,7 +42,6 @@
|
|
|
41
42
|
|
|
42
43
|
@media (min-width: 768px) {
|
|
43
44
|
.pf-modal {
|
|
44
|
-
border-radius: var(--radius-lg);
|
|
45
45
|
max-height: min(90vh, 720px);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
.pf-modal__footer {
|
|
67
67
|
align-items: start;
|
|
68
68
|
display: flex;
|
|
69
|
+
flex-shrink: 0;
|
|
69
70
|
gap: var(--space-3);
|
|
70
71
|
justify-content: space-between;
|
|
71
72
|
padding: var(--space-3);
|
|
@@ -90,7 +91,9 @@
|
|
|
90
91
|
|
|
91
92
|
.pf-modal__body {
|
|
92
93
|
display: grid;
|
|
94
|
+
flex: 1 1 auto;
|
|
93
95
|
gap: var(--space-4);
|
|
96
|
+
min-height: 0;
|
|
94
97
|
overflow-y: auto;
|
|
95
98
|
padding: var(--space-3);
|
|
96
99
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
.pf-resizable {
|
|
2
|
+
display: flex;
|
|
3
|
+
overflow: hidden;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.pf-resizable--horizontal {
|
|
7
|
+
flex-direction: row;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.pf-resizable--vertical {
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.pf-resizable__panel {
|
|
15
|
+
flex-grow: 0;
|
|
16
|
+
flex-shrink: 0;
|
|
17
|
+
min-height: 0;
|
|
18
|
+
min-width: 0;
|
|
19
|
+
overflow: auto;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.pf-resizable__panel--fill {
|
|
23
|
+
flex: 1 1 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* ── Handle ───────────────────────────────────────────────────────────────── */
|
|
27
|
+
|
|
28
|
+
.pf-resizable__handle {
|
|
29
|
+
align-items: center;
|
|
30
|
+
background: var(--pf-resizable-handle-bg);
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-shrink: 0;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
position: relative;
|
|
35
|
+
touch-action: none;
|
|
36
|
+
transition: background var(--pf-transition-fast);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.pf-resizable__handle:hover,
|
|
40
|
+
.pf-resizable__handle:focus-visible {
|
|
41
|
+
background: var(--pf-resizable-handle-active-bg);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.pf-resizable__handle:focus-visible {
|
|
45
|
+
outline: none;
|
|
46
|
+
box-shadow: var(--pf-resizable-focus-ring, var(--pf-focus-ring));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.pf-resizable--horizontal .pf-resizable__handle {
|
|
50
|
+
cursor: col-resize;
|
|
51
|
+
width: var(--pf-resizable-handle-size, 6px);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.pf-resizable--vertical .pf-resizable__handle {
|
|
55
|
+
cursor: row-resize;
|
|
56
|
+
height: var(--pf-resizable-handle-size, 6px);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Grip affordance (dots/line) centered in the handle. */
|
|
60
|
+
.pf-resizable__grip {
|
|
61
|
+
background: var(--pf-resizable-grip);
|
|
62
|
+
border-radius: var(--radius-full);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.pf-resizable--horizontal .pf-resizable__grip {
|
|
66
|
+
height: 24px;
|
|
67
|
+
width: 2px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.pf-resizable--vertical .pf-resizable__grip {
|
|
71
|
+
height: 2px;
|
|
72
|
+
width: 24px;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@media (prefers-reduced-motion: reduce) {
|
|
76
|
+
.pf-resizable__handle {
|
|
77
|
+
transition: none;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Keys } 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 './Resizable.css';/* empty css */
|
|
7
|
+
import { Children, forwardRef, useId, useRef } from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
//#region src/components/Resizable/Resizable.tsx
|
|
10
|
+
var clamp = (n, min, max) => Math.min(Math.max(n, min), max);
|
|
11
|
+
var Resizable = forwardRef(function Resizable({ className, orientation = "horizontal", size, defaultSize = 50, onSizeChange, min = 10, max = 90, step = 2, handleLabel = "Resize panels", children, ...props }, ref) {
|
|
12
|
+
const handleId = useId();
|
|
13
|
+
const containerRef = useRef(null);
|
|
14
|
+
const containerRefs = useComposedRefs(containerRef, ref);
|
|
15
|
+
const draggingRef = useRef(false);
|
|
16
|
+
const [current, setCurrent] = useControllableState({
|
|
17
|
+
value: size,
|
|
18
|
+
defaultValue: defaultSize,
|
|
19
|
+
onChange: onSizeChange
|
|
20
|
+
});
|
|
21
|
+
const value = clamp(current ?? defaultSize, min, max);
|
|
22
|
+
const isHorizontal = orientation === "horizontal";
|
|
23
|
+
const panels = Children.toArray(children);
|
|
24
|
+
const first = panels[0] ?? null;
|
|
25
|
+
const second = panels[1] ?? null;
|
|
26
|
+
const setFromPointer = (clientX, clientY) => {
|
|
27
|
+
const el = containerRef.current;
|
|
28
|
+
if (!el) return;
|
|
29
|
+
const rect = el.getBoundingClientRect();
|
|
30
|
+
const pct = isHorizontal ? (clientX - rect.left) / rect.width * 100 : (clientY - rect.top) / rect.height * 100;
|
|
31
|
+
setCurrent(clamp(Math.round(pct), min, max));
|
|
32
|
+
};
|
|
33
|
+
const onPointerDown = (event) => {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
36
|
+
draggingRef.current = true;
|
|
37
|
+
};
|
|
38
|
+
const onPointerMove = (event) => {
|
|
39
|
+
if (!draggingRef.current) return;
|
|
40
|
+
setFromPointer(event.clientX, event.clientY);
|
|
41
|
+
};
|
|
42
|
+
const onPointerUp = (event) => {
|
|
43
|
+
draggingRef.current = false;
|
|
44
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
45
|
+
};
|
|
46
|
+
const onKeyDown = (event) => {
|
|
47
|
+
const decKey = isHorizontal ? Keys.ArrowLeft : Keys.ArrowUp;
|
|
48
|
+
const incKey = isHorizontal ? Keys.ArrowRight : Keys.ArrowDown;
|
|
49
|
+
if (event.key === decKey) {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
setCurrent(clamp(value - step, min, max));
|
|
52
|
+
} else if (event.key === incKey) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
setCurrent(clamp(value + step, min, max));
|
|
55
|
+
} else if (event.key === Keys.Home) {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
setCurrent(min);
|
|
58
|
+
} else if (event.key === Keys.End) {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
setCurrent(max);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
64
|
+
ref: containerRefs,
|
|
65
|
+
className: cx("pf-resizable", `pf-resizable--${orientation}`, className),
|
|
66
|
+
...props,
|
|
67
|
+
children: [
|
|
68
|
+
/* @__PURE__ */ jsx("div", {
|
|
69
|
+
className: "pf-resizable__panel",
|
|
70
|
+
style: { flexBasis: `${value}%` },
|
|
71
|
+
children: first
|
|
72
|
+
}),
|
|
73
|
+
/* @__PURE__ */ jsx("div", {
|
|
74
|
+
id: handleId,
|
|
75
|
+
role: "separator",
|
|
76
|
+
tabIndex: 0,
|
|
77
|
+
"aria-orientation": isHorizontal ? "vertical" : "horizontal",
|
|
78
|
+
"aria-label": handleLabel,
|
|
79
|
+
"aria-valuenow": value,
|
|
80
|
+
"aria-valuemin": min,
|
|
81
|
+
"aria-valuemax": max,
|
|
82
|
+
className: "pf-resizable__handle",
|
|
83
|
+
onPointerDown,
|
|
84
|
+
onPointerMove,
|
|
85
|
+
onPointerUp,
|
|
86
|
+
onKeyDown,
|
|
87
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
88
|
+
className: "pf-resizable__grip",
|
|
89
|
+
"aria-hidden": true
|
|
90
|
+
})
|
|
91
|
+
}),
|
|
92
|
+
/* @__PURE__ */ jsx("div", {
|
|
93
|
+
className: "pf-resizable__panel pf-resizable__panel--fill",
|
|
94
|
+
children: second
|
|
95
|
+
})
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
Resizable.displayName = "Resizable";
|
|
100
|
+
//#endregion
|
|
101
|
+
export { Resizable };
|
|
@@ -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 };
|
|
@@ -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 };
|