@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,218 +1,239 @@
1
+ import { c as _c } from "react-compiler-runtime";
1
2
  import { jsx, jsxs } from "react/jsx-runtime";
2
3
  import * as React from "react";
3
4
  import { Button } from "@ariakit/react/button";
4
5
  import { Role } from "@ariakit/react/role";
5
6
  import { Tooltip, VisuallyHidden } from "@stratakit/bricks";
6
7
  import { Icon } from "@stratakit/foundations";
7
- import {
8
- forwardRef,
9
- useEventHandlers,
10
- useSafeContext,
11
- useUnreactiveCallback
12
- } from "@stratakit/foundations/secret-internals";
8
+ import { forwardRef, useEventHandlers, useSafeContext, useUnreactiveCallback } from "@stratakit/foundations/secret-internals";
13
9
  import cx from "classnames";
14
10
  import { createStore, useStore } from "zustand";
15
11
  import { combine } from "zustand/middleware";
16
12
  function createNavigationRailStore(initialState) {
17
- return createStore(
18
- combine(initialState, (set) => ({
19
- setExpanded: (expanded) => set({ expanded })
20
- }))
21
- );
13
+ return createStore(combine(initialState, (set) => ({
14
+ setExpanded: (expanded) => set({
15
+ expanded
16
+ })
17
+ })));
22
18
  }
23
19
  const NavigationRailContext = React.createContext(void 0);
24
20
  function NavigationRailProvider(props) {
25
- const { defaultExpanded, expanded, setExpanded: setExpandedProp } = props;
26
- const [store] = React.useState(
27
- () => createNavigationRailStore({ expanded: expanded ?? defaultExpanded })
28
- );
29
- const setExpanded = useUnreactiveCallback(setExpandedProp ?? (() => {
30
- }));
31
- React.useEffect(
32
- function synchronizeWithProps() {
33
- if (expanded === void 0) return;
34
- store.setState({ expanded, setExpanded });
35
- },
36
- [store, expanded, setExpanded]
37
- );
38
- return /* @__PURE__ */ jsx(NavigationRailContext.Provider, { value: store, children: props.children });
21
+ const $ = _c(11);
22
+ const {
23
+ defaultExpanded,
24
+ expanded,
25
+ setExpanded: setExpandedProp
26
+ } = props;
27
+ let t0;
28
+ if ($[0] !== defaultExpanded || $[1] !== expanded) {
29
+ t0 = () => createNavigationRailStore({
30
+ expanded: expanded ?? defaultExpanded
31
+ });
32
+ $[0] = defaultExpanded;
33
+ $[1] = expanded;
34
+ $[2] = t0;
35
+ } else {
36
+ t0 = $[2];
37
+ }
38
+ const [store] = React.useState(t0);
39
+ const setExpanded = useUnreactiveCallback(setExpandedProp ?? _temp);
40
+ let t1;
41
+ let t2;
42
+ if ($[3] !== expanded || $[4] !== setExpanded || $[5] !== store) {
43
+ t1 = function synchronizeWithProps() {
44
+ if (expanded === void 0) {
45
+ return;
46
+ }
47
+ store.setState({
48
+ expanded,
49
+ setExpanded
50
+ });
51
+ };
52
+ t2 = [store, expanded, setExpanded];
53
+ $[3] = expanded;
54
+ $[4] = setExpanded;
55
+ $[5] = store;
56
+ $[6] = t1;
57
+ $[7] = t2;
58
+ } else {
59
+ t1 = $[6];
60
+ t2 = $[7];
61
+ }
62
+ React.useEffect(t1, t2);
63
+ let t3;
64
+ if ($[8] !== props.children || $[9] !== store) {
65
+ t3 = jsx(NavigationRailContext.Provider, {
66
+ value: store,
67
+ children: props.children
68
+ });
69
+ $[8] = props.children;
70
+ $[9] = store;
71
+ $[10] = t3;
72
+ } else {
73
+ t3 = $[10];
74
+ }
75
+ return t3;
76
+ }
77
+ function _temp() {
39
78
  }
40
79
  function useNavigationRailState(selectorFn) {
41
80
  const store = useSafeContext(NavigationRailContext);
42
81
  return useStore(store, selectorFn);
43
82
  }
44
- const NavigationRailRoot = forwardRef(
45
- (props, forwardedRef) => {
46
- const { defaultExpanded = false, expanded, setExpanded, ...rest } = props;
47
- return /* @__PURE__ */ jsx(
48
- NavigationRailProvider,
49
- {
50
- defaultExpanded,
51
- expanded,
52
- setExpanded,
53
- children: /* @__PURE__ */ jsx(NavigationRailRootInner, { ...rest, ref: forwardedRef })
54
- }
55
- );
56
- }
57
- );
58
- const NavigationRailRootInner = forwardRef(
59
- (props, forwardedRef) => {
60
- const expanded = useNavigationRailState((state) => state.expanded);
61
- return /* @__PURE__ */ jsx(
62
- Role.nav,
63
- {
64
- ...props,
65
- className: cx("\u{1F95D}NavigationRail", props.className),
66
- "data-_sk-expanded": expanded ? "true" : void 0,
67
- ref: forwardedRef
68
- }
69
- );
70
- }
71
- );
72
- const NavigationRailHeader = forwardRef(
73
- (props, forwardedRef) => {
74
- const expanded = useNavigationRailState((state) => state.expanded);
75
- return /* @__PURE__ */ jsx(
76
- Role.header,
77
- {
78
- ...props,
79
- className: cx("\u{1F95D}NavigationRailHeader", props.className),
80
- "data-_sk-expanded": expanded ? "true" : void 0,
81
- ref: forwardedRef
82
- }
83
- );
84
- }
85
- );
83
+ const NavigationRailRoot = forwardRef((props, forwardedRef) => {
84
+ const {
85
+ defaultExpanded = false,
86
+ expanded,
87
+ setExpanded,
88
+ ...rest
89
+ } = props;
90
+ return /* @__PURE__ */ jsx(NavigationRailProvider, {
91
+ defaultExpanded,
92
+ expanded,
93
+ setExpanded,
94
+ children: /* @__PURE__ */ jsx(NavigationRailRootInner, {
95
+ ...rest,
96
+ ref: forwardedRef
97
+ })
98
+ });
99
+ });
100
+ const NavigationRailRootInner = forwardRef((props, forwardedRef) => {
101
+ const expanded = useNavigationRailState((state) => state.expanded);
102
+ return /* @__PURE__ */ jsx(Role.nav, {
103
+ ...props,
104
+ className: cx("\u{1F95D}NavigationRail", props.className),
105
+ "data-_sk-expanded": expanded ? "true" : void 0,
106
+ ref: forwardedRef
107
+ });
108
+ });
109
+ const NavigationRailHeader = forwardRef((props, forwardedRef) => {
110
+ const expanded = useNavigationRailState((state) => state.expanded);
111
+ return /* @__PURE__ */ jsx(Role.header, {
112
+ ...props,
113
+ className: cx("\u{1F95D}NavigationRailHeader", props.className),
114
+ "data-_sk-expanded": expanded ? "true" : void 0,
115
+ ref: forwardedRef
116
+ });
117
+ });
86
118
  const NavigationRailToggleButton = forwardRef((props, forwardedRef) => {
87
- const { label = "Expand navigation", ...rest } = props;
119
+ const {
120
+ label = "Expand navigation",
121
+ ...rest
122
+ } = props;
88
123
  const expanded = useNavigationRailState((state) => state.expanded);
89
- const setExpanded = useNavigationRailState((state) => state.setExpanded);
90
- return /* @__PURE__ */ jsxs(
91
- Button,
92
- {
93
- "aria-expanded": expanded ? "true" : "false",
94
- ...rest,
95
- className: cx("\u{1F95D}NavigationRailToggleButton", props.className),
96
- ref: forwardedRef,
97
- onClick: useEventHandlers(props.onClick, () => setExpanded(!expanded)),
98
- children: [
99
- /* @__PURE__ */ jsx("svg", { width: "12", height: "12", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx(
100
- "path",
101
- {
102
- fill: "currentColor",
103
- d: "M5.405 2.845a.75.75 0 1 0-1.06 1.06L6.439 6 4.345 8.095a.75.75 0 0 0 1.06 1.06L8.03 6.53a.75.75 0 0 0 0-1.06L5.405 2.845Z"
104
- }
105
- ) }),
106
- /* @__PURE__ */ jsx(VisuallyHidden, { children: label })
107
- ]
108
- }
109
- );
124
+ const setExpanded = useNavigationRailState((state_0) => state_0.setExpanded);
125
+ return /* @__PURE__ */ jsxs(Button, {
126
+ "aria-expanded": expanded ? "true" : "false",
127
+ ...rest,
128
+ className: cx("\u{1F95D}NavigationRailToggleButton", props.className),
129
+ ref: forwardedRef,
130
+ onClick: useEventHandlers(props.onClick, () => setExpanded(!expanded)),
131
+ children: [/* @__PURE__ */ jsx("svg", {
132
+ width: "12",
133
+ height: "12",
134
+ fill: "none",
135
+ "aria-hidden": "true",
136
+ children: /* @__PURE__ */ jsx("path", {
137
+ fill: "currentColor",
138
+ d: "M5.405 2.845a.75.75 0 1 0-1.06 1.06L6.439 6 4.345 8.095a.75.75 0 0 0 1.06 1.06L8.03 6.53a.75.75 0 0 0 0-1.06L5.405 2.845Z"
139
+ })
140
+ }), /* @__PURE__ */ jsx(VisuallyHidden, {
141
+ children: label
142
+ })]
143
+ });
144
+ });
145
+ const NavigationRailContent = forwardRef((props, forwardedRef) => {
146
+ return /* @__PURE__ */ jsx(Role.div, {
147
+ ...props,
148
+ className: cx("\u{1F95D}NavigationRailContent", props.className),
149
+ ref: forwardedRef
150
+ });
151
+ });
152
+ const NavigationRailList = forwardRef((props, forwardedRef) => {
153
+ return /* @__PURE__ */ jsx(Role, {
154
+ role: "list",
155
+ ...props,
156
+ className: cx("\u{1F95D}NavigationRailList", props.className),
157
+ ref: forwardedRef
158
+ });
159
+ });
160
+ const NavigationRailListItem = forwardRef((props, forwardedRef) => {
161
+ return /* @__PURE__ */ jsx(Role.div, {
162
+ role: "listitem",
163
+ ...props,
164
+ className: cx("\u{1F95D}NavigationRailListItem", props.className),
165
+ ref: forwardedRef
166
+ });
110
167
  });
111
- const NavigationRailContent = forwardRef(
112
- (props, forwardedRef) => {
113
- return /* @__PURE__ */ jsx(
114
- Role.div,
115
- {
116
- ...props,
117
- className: cx("\u{1F95D}NavigationRailContent", props.className),
118
- ref: forwardedRef
119
- }
120
- );
121
- }
122
- );
123
- const NavigationRailList = forwardRef(
124
- (props, forwardedRef) => {
125
- return /* @__PURE__ */ jsx(
126
- Role,
127
- {
128
- role: "list",
129
- ...props,
130
- className: cx("\u{1F95D}NavigationRailList", props.className),
131
- ref: forwardedRef
132
- }
133
- );
134
- }
135
- );
136
- const NavigationRailListItem = forwardRef(
137
- (props, forwardedRef) => {
138
- return /* @__PURE__ */ jsx(
139
- Role.div,
140
- {
141
- role: "listitem",
142
- ...props,
143
- className: cx("\u{1F95D}NavigationRailListItem", props.className),
144
- ref: forwardedRef
145
- }
146
- );
147
- }
148
- );
149
168
  const NavigationRailItemAction = forwardRef((props, forwardedRef) => {
150
169
  const expanded = useNavigationRailState((state) => state.expanded);
151
- const { label, icon, ...rest } = props;
152
- const action = /* @__PURE__ */ jsxs(
153
- Role,
154
- {
155
- ...rest,
156
- className: cx("\u{1F95D}NavigationRailItemAction", props.className),
157
- ref: forwardedRef,
158
- children: [
159
- typeof icon === "string" ? /* @__PURE__ */ jsx(Icon, { href: icon }) : icon,
160
- /* @__PURE__ */ jsx(
161
- Role.span,
162
- {
163
- className: "\u{1F95D}NavigationRailItemActionLabel",
164
- render: !expanded ? /* @__PURE__ */ jsx(VisuallyHidden, {}) : void 0,
165
- children: label
166
- }
167
- )
168
- ]
169
- }
170
- );
170
+ const {
171
+ label,
172
+ icon,
173
+ ...rest
174
+ } = props;
175
+ const action = /* @__PURE__ */ jsxs(Role, {
176
+ ...rest,
177
+ className: cx("\u{1F95D}NavigationRailItemAction", props.className),
178
+ ref: forwardedRef,
179
+ children: [typeof icon === "string" ? /* @__PURE__ */ jsx(Icon, {
180
+ href: icon
181
+ }) : icon, /* @__PURE__ */ jsx(Role.span, {
182
+ className: "\u{1F95D}NavigationRailItemActionLabel",
183
+ render: !expanded ? /* @__PURE__ */ jsx(VisuallyHidden, {}) : void 0,
184
+ children: label
185
+ })]
186
+ });
171
187
  if (!expanded) {
172
- return /* @__PURE__ */ jsx(Tooltip, { content: label, placement: "right", type: "none", children: action });
188
+ return /* @__PURE__ */ jsx(Tooltip, {
189
+ content: label,
190
+ placement: "right",
191
+ type: "none",
192
+ children: action
193
+ });
173
194
  }
174
195
  return action;
175
196
  });
176
- const NavigationRailAnchor = forwardRef(
177
- (props, forwardedRef) => {
178
- const { label, icon, active, ...rest } = props;
179
- return /* @__PURE__ */ jsx(
180
- NavigationRailItemAction,
181
- {
182
- label,
183
- icon,
184
- "aria-current": active ? "page" : void 0,
185
- render: /* @__PURE__ */ jsx(Role.a, { ...rest, ref: forwardedRef })
186
- }
187
- );
188
- }
189
- );
190
- const NavigationRailButton = forwardRef(
191
- (props, forwardedRef) => {
192
- const { label, icon, ...rest } = props;
193
- return /* @__PURE__ */ jsx(
194
- NavigationRailItemAction,
195
- {
196
- label,
197
- icon,
198
- render: /* @__PURE__ */ jsx(Role.button, { ...rest, ref: forwardedRef })
199
- }
200
- );
201
- }
202
- );
203
- const NavigationRailFooter = forwardRef(
204
- (props, forwardedRef) => {
205
- return /* @__PURE__ */ jsx(
206
- Role,
207
- {
208
- render: /* @__PURE__ */ jsx("footer", {}),
209
- ...props,
210
- className: cx("\u{1F95D}NavigationRailFooter", props.className),
211
- ref: forwardedRef
212
- }
213
- );
214
- }
215
- );
197
+ const NavigationRailAnchor = forwardRef((props, forwardedRef) => {
198
+ const {
199
+ label,
200
+ icon,
201
+ active,
202
+ ...rest
203
+ } = props;
204
+ return /* @__PURE__ */ jsx(NavigationRailItemAction, {
205
+ label,
206
+ icon,
207
+ "aria-current": active ? "page" : void 0,
208
+ render: /* @__PURE__ */ jsx(Role.a, {
209
+ ...rest,
210
+ ref: forwardedRef
211
+ })
212
+ });
213
+ });
214
+ const NavigationRailButton = forwardRef((props, forwardedRef) => {
215
+ const {
216
+ label,
217
+ icon,
218
+ ...rest
219
+ } = props;
220
+ return /* @__PURE__ */ jsx(NavigationRailItemAction, {
221
+ label,
222
+ icon,
223
+ render: /* @__PURE__ */ jsx(Role.button, {
224
+ ...rest,
225
+ ref: forwardedRef
226
+ })
227
+ });
228
+ });
229
+ const NavigationRailFooter = forwardRef((props, forwardedRef) => {
230
+ return /* @__PURE__ */ jsx(Role, {
231
+ render: /* @__PURE__ */ jsx("footer", {}),
232
+ ...props,
233
+ className: cx("\u{1F95D}NavigationRailFooter", props.className),
234
+ ref: forwardedRef
235
+ });
236
+ });
216
237
  export {
217
238
  NavigationRailAnchor as Anchor,
218
239
  NavigationRailButton as Button,