@jsenv/navi 0.8.0 → 0.9.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/navi",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Library of components including navigation to create frontend applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,8 +14,7 @@ import { FormActionContext } from "../action_execution/form_context.js";
14
14
  import { renderActionableComponent } from "../action_execution/render_actionable_component.jsx";
15
15
  import { useAction } from "../action_execution/use_action.js";
16
16
  import { useExecuteAction } from "../action_execution/use_execute_action.js";
17
- import { useConsumAlignProps } from "../layout/flex.jsx";
18
- import { consumeSpacingProps } from "../layout/spacing.jsx";
17
+ import { useLayoutStyle } from "../layout/use_layout_style.js";
19
18
  import { LoaderBackground } from "../loader/loader_background.jsx";
20
19
  import { withPropsClassName } from "../props_composition/with_props_class_name.js";
21
20
  import { withPropsStyle } from "../props_composition/with_props_style.js";
@@ -89,6 +88,7 @@ import.meta.css = /* css */ `
89
88
  .navi_button_content {
90
89
  position: relative;
91
90
  display: inline-flex;
91
+ width: 100%;
92
92
  padding-top: var(--padding-y);
93
93
  padding-right: var(--padding-x);
94
94
  padding-bottom: var(--padding-y);
@@ -212,8 +212,6 @@ const ButtonBasic = forwardRef((props, ref) => {
212
212
 
213
213
  // visual
214
214
  appearance = "navi",
215
- alignX,
216
- alignY,
217
215
  discrete,
218
216
  className,
219
217
  style,
@@ -242,13 +240,8 @@ const ButtonBasic = forwardRef((props, ref) => {
242
240
  appearance === "navi" ? "navi_button" : undefined,
243
241
  className,
244
242
  );
245
- const innerStyle = withPropsStyle(
246
- {
247
- ...consumeSpacingProps(rest),
248
- ...useConsumAlignProps({ alignX, alignY }),
249
- },
250
- style,
251
- );
243
+ const { all } = useLayoutStyle(rest);
244
+ const innerStyle = withPropsStyle(all, style);
252
245
 
253
246
  return (
254
247
  <button
@@ -13,7 +13,7 @@ import { useConstraints } from "../../validation/hooks/use_constraints.js";
13
13
  import { renderActionableComponent } from "../action_execution/render_actionable_component.jsx";
14
14
  import { useActionBoundToOneParam } from "../action_execution/use_action.js";
15
15
  import { useExecuteAction } from "../action_execution/use_execute_action.js";
16
- import { consumeSpacingProps } from "../layout/spacing.jsx";
16
+ import { useLayoutStyle } from "../layout/use_layout_style.js";
17
17
  import {
18
18
  LoadableInlineElement,
19
19
  LoaderBackground,
@@ -333,10 +333,11 @@ const NaviCheckbox = ({
333
333
  return initCustomField(ref.current, inputRef.current);
334
334
  }, []);
335
335
 
336
+ const { all } = useLayoutStyle(rest);
336
337
  const innerStyle = withPropsStyle(
337
338
  {
339
+ ...all,
338
340
  ...(accentColor ? { "--accent-color": accentColor } : {}),
339
- ...consumeSpacingProps(rest),
340
341
  },
341
342
  style,
342
343
  );
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  import { useConstraints } from "../../validation/hooks/use_constraints.js";
10
10
  import { renderActionableComponent } from "../action_execution/render_actionable_component.jsx";
11
- import { consumeSpacingProps } from "../layout/spacing.jsx";
11
+ import { useLayoutStyle } from "../layout/use_layout_style.js";
12
12
  import {
13
13
  LoadableInlineElement,
14
14
  LoaderBackground,
@@ -372,10 +372,11 @@ const NaviRadio = ({
372
372
  return initCustomField(ref.current, inputRef.current);
373
373
  }, []);
374
374
 
375
+ const { all } = useLayoutStyle(rest);
375
376
  const innerStyle = withPropsStyle(
376
377
  {
378
+ ...all,
377
379
  ...(accentColor ? { "--accent-color": accentColor } : {}),
378
- ...consumeSpacingProps(rest),
379
380
  },
380
381
  style,
381
382
  );
@@ -31,7 +31,7 @@ import { useConstraints } from "../../validation/hooks/use_constraints.js";
31
31
  import { renderActionableComponent } from "../action_execution/render_actionable_component.jsx";
32
32
  import { useActionBoundToOneParam } from "../action_execution/use_action.js";
33
33
  import { useExecuteAction } from "../action_execution/use_execute_action.js";
34
- import { consumeSpacingProps } from "../layout/spacing.jsx";
34
+ import { useLayoutStyle } from "../layout/use_layout_style.js";
35
35
  import { LoadableInlineElement } from "../loader/loader_background.jsx";
36
36
  import { withPropsClassName } from "../props_composition/with_props_class_name.js";
37
37
  import { withPropsStyle } from "../props_composition/with_props_style.js";
@@ -88,6 +88,8 @@ import.meta.css = /* css */ `
88
88
  --color: currentColor;
89
89
  --color-readonly: color-mix(in srgb, currentColor 60%, transparent);
90
90
  --color-disabled: var(--color-readonly);
91
+
92
+ width: 100%;
91
93
  color: var(--color);
92
94
 
93
95
  background-color: var(--background-color);
@@ -170,8 +172,6 @@ const InputTextualBasic = forwardRef((props, ref) => {
170
172
  // visual
171
173
  appearance = "navi",
172
174
  accentColor,
173
- width,
174
- height,
175
175
  className,
176
176
  style,
177
177
 
@@ -199,14 +199,8 @@ const InputTextualBasic = forwardRef((props, ref) => {
199
199
  appearance === "navi" ? "navi_input" : undefined,
200
200
  className,
201
201
  );
202
- const innerStyle = withPropsStyle(
203
- {
204
- width,
205
- height,
206
- ...consumeSpacingProps(rest),
207
- },
208
- style,
209
- );
202
+ const { margin, padding, alignment, expansion } = useLayoutStyle(rest);
203
+ const innerStyle = withPropsStyle(padding, style);
210
204
  const inputTextual = (
211
205
  <input
212
206
  {...rest}
@@ -254,11 +248,12 @@ const InputTextualBasic = forwardRef((props, ref) => {
254
248
  <LoadableInlineElement
255
249
  loading={innerLoading}
256
250
  style={{
251
+ ...margin,
252
+ ...alignment,
253
+ ...expansion,
257
254
  "--accent-color": accentColor || "light-dark(#355fcc, #4476ff)",
258
255
  }}
259
256
  color="var(--accent-color)"
260
- width={width}
261
- height={height}
262
257
  inset={-1}
263
258
  >
264
259
  {inputTextual}
@@ -0,0 +1,351 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>useLayoutStyle Demo - Buttons</title>
6
+ <style>
7
+ .demo-container {
8
+ margin-bottom: 30px;
9
+ padding: 20px;
10
+ background: #f8f9fa;
11
+ border-radius: 8px;
12
+ }
13
+
14
+ .demo-box {
15
+ min-width: 60px;
16
+ padding: 10px;
17
+ text-align: center;
18
+ background: #e3f2fd;
19
+ border: 1px solid #90caf9;
20
+ border-radius: 4px;
21
+ }
22
+
23
+ .visual-container {
24
+ margin: 10px 0;
25
+ padding: 10px;
26
+ background: #fff3e0;
27
+ border: 2px dashed #ff9800;
28
+ }
29
+
30
+ h3 {
31
+ margin-top: 0;
32
+ }
33
+
34
+ /* Helper to visualize the container boundaries */
35
+ .bounded {
36
+ width: 400px;
37
+ height: 100px;
38
+ padding: 10px;
39
+ background: #f0f4ff;
40
+ border: 1px solid #6366f1;
41
+ }
42
+ </style>
43
+ </head>
44
+ <body>
45
+ <div id="app"></div>
46
+ <script type="module" jsenv-type="module/jsx">
47
+ /* eslint-disable no-unused-vars */
48
+ import { render } from "preact";
49
+ import { FlexRow, FlexColumn, Input, Button } from "@jsenv/navi";
50
+
51
+ const DemoBox = ({ children, ...props }) => (
52
+ <div className="demo-box" {...props}>
53
+ {children}
54
+ </div>
55
+ );
56
+
57
+ const Demo = () => {
58
+ return (
59
+ <div style={{ padding: "20px", fontFamily: "system-ui, sans-serif" }}>
60
+ <h1>useLayoutStyle Demo - Button Elements</h1>
61
+ <p>
62
+ Testing spacing (margin/padding), alignment, and expand behavior
63
+ specifically with Button components in various layout contexts.
64
+ </p>
65
+
66
+ <div className="demo-container">
67
+ <h3>1. Button ExpandX - Horizontal Expansion Only</h3>
68
+ <div className="visual-container">
69
+ <h4>In FlexRow (grows horizontally)</h4>
70
+ <FlexRow gap="10px">
71
+ <Button>Fixed</Button>
72
+ <Button expandX>ExpandX Button</Button>
73
+ <Button>Fixed</Button>
74
+ </FlexRow>
75
+
76
+ <h4>In FlexColumn (takes full width)</h4>
77
+ <FlexColumn gap="10px" style={{ height: "150px" }}>
78
+ <Button>Normal Width</Button>
79
+ <Button expandX>Full Width Button</Button>
80
+ <Button>Normal Width</Button>
81
+ </FlexColumn>
82
+ </div>
83
+ </div>
84
+
85
+ <div className="demo-container">
86
+ <h3>2. Button ExpandY - Vertical Expansion Only</h3>
87
+ <div className="visual-container">
88
+ <h4>In FlexRow (takes full height)</h4>
89
+ <FlexRow gap="10px" style={{ height: "100px" }}>
90
+ <Button>Normal Height</Button>
91
+ <Button expandY>Full Height Button</Button>
92
+ <Button>Normal Height</Button>
93
+ </FlexRow>
94
+
95
+ <h4>In FlexColumn (grows vertically)</h4>
96
+ <FlexColumn gap="10px" style={{ height: "200px" }}>
97
+ <Button>Fixed</Button>
98
+ <Button expandY>ExpandY Button</Button>
99
+ <Button>Fixed</Button>
100
+ </FlexColumn>
101
+ </div>
102
+ </div>
103
+
104
+ <div className="demo-container">
105
+ <h3>3. Button ExpandX + ExpandY - Both Axes</h3>
106
+ <div className="visual-container">
107
+ <h4>In FlexRow (grows horizontally, full height)</h4>
108
+ <FlexRow gap="10px" style={{ height: "80px" }}>
109
+ <Button>Fixed</Button>
110
+ <Button expandX expandY>
111
+ Both Axes
112
+ </Button>
113
+ <Button>Fixed</Button>
114
+ </FlexRow>
115
+
116
+ <h4>In FlexColumn (full width, grows vertically)</h4>
117
+ <FlexColumn gap="10px" style={{ height: "150px" }}>
118
+ <Button>Fixed</Button>
119
+ <Button expandX expandY>
120
+ Both Axes
121
+ </Button>
122
+ <Button>Fixed</Button>
123
+ </FlexColumn>
124
+ </div>
125
+ </div>
126
+
127
+ <div className="demo-container">
128
+ <h3>4. Precise Control Comparison</h3>
129
+ <div className="visual-container">
130
+ <FlexColumn gap="15px">
131
+ <div>
132
+ <h4>FlexRow with different expansions</h4>
133
+ <FlexRow
134
+ gap="10px"
135
+ style={{
136
+ height: "60px",
137
+ background: "#f8f9fa",
138
+ padding: "10px",
139
+ }}
140
+ >
141
+ <Button>No Expand</Button>
142
+ <Button expandX>ExpandX Only</Button>
143
+ <Button expandY>ExpandY Only</Button>
144
+ <Button expandX expandY>
145
+ Both
146
+ </Button>
147
+ </FlexRow>
148
+ </div>
149
+
150
+ <div>
151
+ <h4>FlexColumn with different expansions</h4>
152
+ <FlexColumn
153
+ gap="10px"
154
+ style={{
155
+ height: "200px",
156
+ background: "#f8f9fa",
157
+ padding: "10px",
158
+ }}
159
+ >
160
+ <Button>No Expand</Button>
161
+ <Button expandX>ExpandX Only</Button>
162
+ <Button expandY>ExpandY Only</Button>
163
+ <Button expandX expandY>
164
+ Both
165
+ </Button>
166
+ </FlexColumn>
167
+ </div>
168
+ </FlexColumn>
169
+ </div>
170
+ </div>
171
+
172
+ <div className="demo-container">
173
+ <h3>5. Outside Flex Context</h3>
174
+ <div className="visual-container">
175
+ <div
176
+ style={{
177
+ width: "300px",
178
+ height: "150px",
179
+ border: "1px solid #ccc",
180
+ padding: "10px",
181
+ }}
182
+ >
183
+ <Button>Normal Button</Button>
184
+ <br />
185
+ <br />
186
+ <Button expandX>ExpandX (full width)</Button>
187
+ <br />
188
+ <br />
189
+ <Button expandY>ExpandY (full height)</Button>
190
+ <br />
191
+ <br />
192
+ <Button expandX expandY>
193
+ Both (full width & height)
194
+ </Button>
195
+ </div>
196
+ </div>
197
+ </div>
198
+
199
+ <div className="demo-container">
200
+ <h3>6. Multiple Expand Buttons</h3>
201
+ <div className="visual-container">
202
+ <FlexRow gap="10px">
203
+ <Button expandX>ExpandX 1</Button>
204
+ <Button expandX>ExpandX 2</Button>
205
+ <Button expandX>ExpandX 3</Button>
206
+ </FlexRow>
207
+ </div>
208
+ </div>
209
+
210
+ <div className="demo-container">
211
+ <h3>7. Button Spacing - Margins</h3>
212
+ <div className="visual-container">
213
+ <FlexColumn gap="5px">
214
+ <Button margin="10px">Margin All Sides</Button>
215
+ <Button marginX="20px">MarginX Only</Button>
216
+ <Button marginY="15px">MarginY Only</Button>
217
+ <Button marginLeft="30px">MarginLeft Only</Button>
218
+ <Button marginRight="25px">MarginRight Only</Button>
219
+ </FlexColumn>
220
+ </div>
221
+ </div>
222
+
223
+ <div className="demo-container">
224
+ <h3>6. Button Spacing - Padding</h3>
225
+ <div className="visual-container">
226
+ <FlexColumn gap="5px">
227
+ <Button>Default Padding</Button>
228
+ <Button padding="20px">Extra Padding</Button>
229
+ <Button paddingX="30px">PaddingX Only</Button>
230
+ <Button paddingY="15px">PaddingY Only</Button>
231
+ <Button paddingLeft="25px">PaddingLeft Only</Button>
232
+ </FlexColumn>
233
+ </div>
234
+ </div>
235
+
236
+ <div className="demo-container">
237
+ <h3>8. Button AlignX Test: FlexRow + alignX="end"</h3>
238
+ <div className="visual-container">
239
+ <div className="bounded">
240
+ <FlexRow gap="10px" style={{ height: "100%" }}>
241
+ <Button>Default</Button>
242
+ <Button alignX="end">Pushed to End</Button>
243
+ </FlexRow>
244
+ </div>
245
+ </div>
246
+ </div>
247
+
248
+ <div className="demo-container">
249
+ <h3>9. Combined Spacing and ExpandX</h3>
250
+ <div className="visual-container">
251
+ <FlexRow gap="10px">
252
+ <Button>Label</Button>
253
+ <Button expandX marginY="5px" paddingX="20px">
254
+ Margin + Padding + ExpandX
255
+ </Button>
256
+ <Button>End</Button>
257
+ </FlexRow>
258
+ </div>
259
+ </div>
260
+
261
+ <div className="demo-container">
262
+ <h3>10. Button Toolbar Layout</h3>
263
+ <div className="visual-container">
264
+ <FlexRow gap="10px">
265
+ <Button>New</Button>
266
+ <Button>Open</Button>
267
+ <Button>Save</Button>
268
+ <Button expandX>Status Message Area</Button>
269
+ <Button alignX="end">Settings</Button>
270
+ </FlexRow>
271
+ </div>
272
+ </div>
273
+
274
+ <div className="demo-container">
275
+ <h3>11. Button Group with Various Alignments</h3>
276
+ <div className="visual-container">
277
+ <FlexColumn gap="10px">
278
+ <FlexRow gap="10px">
279
+ <Button>Start</Button>
280
+ <Button alignX="center">Center</Button>
281
+ <Button alignX="end">End</Button>
282
+ </FlexRow>
283
+
284
+ <FlexRow gap="10px">
285
+ <Button expandX>Primary Action</Button>
286
+ <Button>Cancel</Button>
287
+ </FlexRow>
288
+
289
+ <FlexRow gap="10px" alignX="end">
290
+ <Button>Back</Button>
291
+ <Button>Next</Button>
292
+ </FlexRow>
293
+ </FlexColumn>
294
+ </div>
295
+ </div>
296
+
297
+ <div className="demo-container">
298
+ <h3>12. Card Layout with Button Actions</h3>
299
+ <div className="visual-container">
300
+ <div
301
+ style={{
302
+ border: "1px solid #ddd",
303
+ borderRadius: "8px",
304
+ padding: "20px",
305
+ width: "350px",
306
+ }}
307
+ >
308
+ <h4 style={{ margin: "0 0 10px 0" }}>Card Title</h4>
309
+ <p style={{ margin: "0 0 20px 0", color: "#666" }}>
310
+ This is some card content that describes the item or action.
311
+ </p>
312
+
313
+ <FlexRow gap="10px">
314
+ <Button expandX>Primary Action</Button>
315
+ <Button alignX="end">More</Button>
316
+ </FlexRow>
317
+ </div>
318
+ </div>
319
+ </div>
320
+
321
+ <div className="demo-container">
322
+ <h3>13. Navigation Button Layout</h3>
323
+ <div className="visual-container">
324
+ <FlexColumn gap="15px">
325
+ <FlexRow gap="10px">
326
+ <Button>Home</Button>
327
+ <Button expandX>Current Page Title</Button>
328
+ <Button alignX="end">Profile</Button>
329
+ </FlexRow>
330
+
331
+ <FlexRow gap="10px" alignX="center">
332
+ <Button marginX="5px">Tab 1</Button>
333
+ <Button marginX="5px">Tab 2</Button>
334
+ <Button marginX="5px">Tab 3</Button>
335
+ </FlexRow>
336
+
337
+ <FlexRow gap="10px" alignX="space-between">
338
+ <Button>Previous</Button>
339
+ <Button>Next</Button>
340
+ </FlexRow>
341
+ </FlexColumn>
342
+ </div>
343
+ </div>
344
+ </div>
345
+ );
346
+ };
347
+
348
+ render(<Demo />, document.getElementById("app"));
349
+ </script>
350
+ </body>
351
+ </html>