@stratakit/structures 0.4.5 → 0.5.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,168 +1,141 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import {
4
- Collection,
5
- CollectionItem,
6
- useCollectionStore
7
- } from "@ariakit/react/collection";
8
- import {
9
- Dialog,
10
- DialogDisclosure,
11
- DialogProvider
12
- } from "@ariakit/react/dialog";
3
+ import { Collection, CollectionItem, useCollectionStore } from "@ariakit/react/collection";
4
+ import { Dialog, DialogDisclosure, DialogProvider } from "@ariakit/react/dialog";
13
5
  import { Role } from "@ariakit/react/role";
14
6
  import { useStoreState } from "@ariakit/react/store";
15
7
  import { Button, Text, VisuallyHidden } from "@stratakit/bricks";
16
8
  import { IconButtonPresentation } from "@stratakit/bricks/secret-internals";
17
- import {
18
- forwardRef,
19
- useControlledState
20
- } from "@stratakit/foundations/secret-internals";
9
+ import { forwardRef, useControlledState } from "@stratakit/foundations/secret-internals";
21
10
  import cx from "classnames";
22
11
  import { ChevronDown, StatusIcon } from "./~utils.icons.js";
23
- const ErrorRegionRoot = forwardRef(
24
- (props, forwardedRef) => {
25
- const {
26
- label,
27
- items: itemsProp = [],
28
- open: openProp,
29
- setOpen: setOpenProp,
30
- ...rest
31
- } = props;
32
- const labelId = React.useId();
33
- const sectionLabelledBy = props["aria-label"] ? void 0 : label ? labelId : void 0;
34
- const visible = Array.isArray(itemsProp) ? itemsProp.length > 0 : !!label;
35
- const [open, setOpen] = useControlledState(
36
- false,
37
- openProp,
38
- setOpenProp
39
- );
40
- const containerRef = React.useRef(null);
41
- const pulse = () => {
42
- const el = containerRef.current;
43
- if (!el) return;
44
- const id = "--\u{1F95D}ErrorRegion-pulse";
45
- const animations = el.getAnimations({ subtree: true });
46
- if (animations.find((animation) => animation.id === id)) return;
47
- el.animate(
48
- [
49
- {
50
- boxShadow: "0 0 0 0 var(--stratakit-color-border-attention-base)",
51
- opacity: 1
52
- },
53
- {
54
- boxShadow: "0 0 15px 2px var(--stratakit-color-border-attention-base)",
55
- opacity: 0.7,
56
- offset: 0.5
57
- },
58
- {
59
- boxShadow: "0 0 0 0 var(--stratakit-color-border-attention-base)",
60
- opacity: 1
61
- }
62
- ],
63
- {
64
- id,
65
- duration: 600,
66
- easing: "cubic-bezier(0.4, 0, 0.2, 1)",
67
- pseudoElement: "::before"
68
- }
69
- );
70
- };
71
- const store = useCollectionStore({
72
- setItems: (newItems) => {
73
- const prevItemsSet = new Set(prevItems.map((item) => item.id));
74
- const addedItems = newItems.filter(
75
- (item) => !prevItemsSet.has(item.id)
76
- );
77
- if (addedItems.length === 0) return;
78
- pulse();
79
- setLiveLabel(label);
80
- }
12
+ const ErrorRegionRoot = forwardRef((props, forwardedRef) => {
13
+ const {
14
+ label,
15
+ items = [],
16
+ open: openProp,
17
+ setOpen: setOpenProp,
18
+ ...rest
19
+ } = props;
20
+ const labelId = React.useId();
21
+ const sectionLabelledBy = props["aria-label"] ? void 0 : label ? labelId : void 0;
22
+ const visible = items.length > 0;
23
+ const [open, setOpen] = useControlledState(false, openProp, setOpenProp);
24
+ const containerRef = React.useRef(null);
25
+ const pulse = () => {
26
+ const el = containerRef.current;
27
+ if (!el) return;
28
+ const id = "--\u{1F95D}ErrorRegion-pulse";
29
+ const animations = el.getAnimations({
30
+ subtree: true
81
31
  });
82
- const prevItems = useStoreState(store, "items");
83
- const [liveLabel, setLiveLabel] = React.useState(label);
84
- return /* @__PURE__ */ jsxs(Fragment, { children: [
85
- /* @__PURE__ */ jsx(VisuallyHidden, { "aria-live": "polite", "aria-atomic": true, children: liveLabel === label ? liveLabel : void 0 }),
86
- /* @__PURE__ */ jsx(DialogProvider, { open, setOpen, children: /* @__PURE__ */ jsx(
87
- Role.section,
88
- {
89
- "aria-labelledby": sectionLabelledBy,
90
- ...rest,
91
- className: cx("\u{1F95D}ErrorRegion", props.className),
92
- "data-_sk-visible": visible,
93
- "data-_sk-expanded": open,
94
- ref: forwardedRef,
95
- children: /* @__PURE__ */ jsxs("div", { className: "\u{1F95D}ErrorRegionContainer", ref: containerRef, children: [
96
- /* @__PURE__ */ jsxs(
97
- DialogDisclosure,
98
- {
99
- className: "\u{1F95D}ErrorRegionHeader",
100
- render: /* @__PURE__ */ jsx(Button, { variant: "ghost" }),
101
- children: [
102
- /* @__PURE__ */ jsx(StatusIcon, { tone: "attention", className: "\u{1F95D}ErrorRegionIcon" }),
103
- /* @__PURE__ */ jsx(
104
- Text,
105
- {
106
- render: /* @__PURE__ */ jsx("span", {}),
107
- id: labelId,
108
- className: "\u{1F95D}ErrorRegionLabel",
109
- variant: "body-sm",
110
- children: label
111
- }
112
- ),
113
- /* @__PURE__ */ jsx(IconButtonPresentation, { inert: true, variant: "ghost", children: /* @__PURE__ */ jsx(ChevronDown, {}) })
114
- ]
115
- }
116
- ),
117
- /* @__PURE__ */ jsx(
118
- Dialog,
119
- {
120
- className: "\u{1F95D}ErrorRegionDialog",
121
- portal: false,
122
- modal: false,
123
- autoFocusOnShow: false,
124
- "aria-labelledby": labelId,
125
- children: /* @__PURE__ */ jsx(
126
- Collection,
127
- {
128
- store,
129
- className: "\u{1F95D}ErrorRegionItems",
130
- role: "list",
131
- children: itemsProp
132
- }
133
- )
134
- }
135
- )
136
- ] })
137
- }
138
- ) })
139
- ] });
140
- }
141
- );
142
- const ErrorRegionItem = forwardRef(
143
- (props, forwardedRef) => {
144
- const generatedId = React.useId();
145
- const {
146
- message,
147
- messageId = `${generatedId}-message`,
148
- actions,
149
- ...rest
150
- } = props;
151
- return /* @__PURE__ */ jsxs(
152
- CollectionItem,
153
- {
32
+ if (animations.find((animation) => animation.id === id)) return;
33
+ el.animate([{
34
+ boxShadow: "0 0 0 0 var(--stratakit-color-border-attention-base)",
35
+ opacity: 1
36
+ }, {
37
+ boxShadow: "0 0 15px 2px var(--stratakit-color-border-attention-base)",
38
+ opacity: 0.7,
39
+ offset: 0.5
40
+ }, {
41
+ boxShadow: "0 0 0 0 var(--stratakit-color-border-attention-base)",
42
+ opacity: 1
43
+ }], {
44
+ id,
45
+ duration: 600,
46
+ easing: "cubic-bezier(0.4, 0, 0.2, 1)",
47
+ pseudoElement: "::before"
48
+ });
49
+ };
50
+ const store = useCollectionStore({
51
+ setItems: (newItems) => {
52
+ const prevItemsSet = new Set(prevItems.map((item) => item.id));
53
+ const addedItems = newItems.filter((item_0) => !prevItemsSet.has(item_0.id));
54
+ if (addedItems.length === 0) return;
55
+ pulse();
56
+ setLiveLabel(label);
57
+ }
58
+ });
59
+ const prevItems = useStoreState(store, "items");
60
+ const [liveLabel, setLiveLabel] = React.useState(label);
61
+ return /* @__PURE__ */ jsxs(Fragment, {
62
+ children: [/* @__PURE__ */ jsx(VisuallyHidden, {
63
+ "aria-live": "polite",
64
+ "aria-atomic": true,
65
+ children: liveLabel === label ? liveLabel : void 0
66
+ }), /* @__PURE__ */ jsx(DialogProvider, {
67
+ open,
68
+ setOpen,
69
+ children: /* @__PURE__ */ jsx(Role.section, {
70
+ "aria-labelledby": sectionLabelledBy,
154
71
  ...rest,
155
- role: "listitem",
156
- className: cx("\u{1F95D}ErrorRegionItem", props.className),
72
+ className: cx("\u{1F95D}ErrorRegion", props.className),
73
+ "data-_sk-visible": visible,
74
+ "data-_sk-expanded": open,
157
75
  ref: forwardedRef,
158
- children: [
159
- /* @__PURE__ */ jsx(Text, { id: messageId, variant: "body-sm", children: message }),
160
- /* @__PURE__ */ jsx("div", { className: "\u{1F95D}ErrorRegionItemActions", children: actions })
161
- ]
162
- }
163
- );
164
- }
165
- );
76
+ children: /* @__PURE__ */ jsxs("div", {
77
+ className: "\u{1F95D}ErrorRegionContainer",
78
+ ref: containerRef,
79
+ children: [/* @__PURE__ */ jsxs(DialogDisclosure, {
80
+ className: "\u{1F95D}ErrorRegionHeader",
81
+ render: /* @__PURE__ */ jsx(Button, {
82
+ variant: "ghost"
83
+ }),
84
+ children: [/* @__PURE__ */ jsx(StatusIcon, {
85
+ tone: "attention",
86
+ className: "\u{1F95D}ErrorRegionIcon"
87
+ }), /* @__PURE__ */ jsx(Text, {
88
+ render: /* @__PURE__ */ jsx("span", {}),
89
+ id: labelId,
90
+ className: "\u{1F95D}ErrorRegionLabel",
91
+ variant: "body-sm",
92
+ children: label
93
+ }), /* @__PURE__ */ jsx(IconButtonPresentation, {
94
+ inert: true,
95
+ variant: "ghost",
96
+ children: /* @__PURE__ */ jsx(ChevronDown, {})
97
+ })]
98
+ }), /* @__PURE__ */ jsx(Dialog, {
99
+ className: "\u{1F95D}ErrorRegionDialog",
100
+ portal: false,
101
+ modal: false,
102
+ autoFocusOnShow: false,
103
+ "aria-labelledby": labelId,
104
+ children: /* @__PURE__ */ jsx(Collection, {
105
+ store,
106
+ className: "\u{1F95D}ErrorRegionItems",
107
+ role: "list",
108
+ children: items
109
+ })
110
+ })]
111
+ })
112
+ })
113
+ })]
114
+ });
115
+ });
116
+ const ErrorRegionItem = forwardRef((props, forwardedRef) => {
117
+ const generatedId = React.useId();
118
+ const {
119
+ message,
120
+ messageId = `${generatedId}-message`,
121
+ actions,
122
+ ...rest
123
+ } = props;
124
+ return /* @__PURE__ */ jsxs(CollectionItem, {
125
+ ...rest,
126
+ role: "listitem",
127
+ className: cx("\u{1F95D}ErrorRegionItem", props.className),
128
+ ref: forwardedRef,
129
+ children: [/* @__PURE__ */ jsx(Text, {
130
+ id: messageId,
131
+ variant: "body-sm",
132
+ children: message
133
+ }), /* @__PURE__ */ jsx("div", {
134
+ className: "\u{1F95D}ErrorRegionItemActions",
135
+ children: actions
136
+ })]
137
+ });
138
+ });
166
139
  export {
167
140
  ErrorRegionItem as Item,
168
141
  ErrorRegionRoot as Root