@jsenv/navi 0.6.0 → 0.6.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.
@@ -18593,60 +18593,75 @@ const parseStyleString = (styleString) => {
18593
18593
  return style;
18594
18594
  };
18595
18595
 
18596
- const getStyleForSpacingProps = ({
18597
- margin,
18598
- marginX,
18599
- marginY,
18600
- marginLeft,
18601
- marginTop,
18602
- marginBottom,
18603
- marginRight,
18604
- padding,
18605
- paddingX,
18606
- paddingY,
18607
- paddingLeft,
18608
- paddingTop,
18609
- paddingBottom,
18610
- paddingRight
18611
- }) => {
18596
+ const consumeSpacingProps = props => {
18597
+ const consume = name => {
18598
+ if (Object.hasOwn(props, name)) {
18599
+ const value = props[name];
18600
+ delete props[name];
18601
+ return value;
18602
+ }
18603
+ return undefined;
18604
+ };
18605
+ const margin = consume("margin");
18606
+ const marginX = consume("marginX");
18607
+ const marginY = consume("marginY");
18608
+ const marginLeft = consume("marginLeft");
18609
+ const marginRight = consume("marginRight");
18610
+ const marginTop = consume("marginTop");
18611
+ const marginBottom = consume("marginBottom");
18612
18612
  const style = {};
18613
18613
  if (margin !== undefined) {
18614
18614
  style.margin = margin;
18615
18615
  }
18616
- const effectiveMarginLeft = marginLeft ?? marginX;
18617
- const effectiveMarginRight = marginRight ?? marginX;
18618
- const effectiveMarginTop = marginTop ?? marginY;
18619
- const effectiveMarginBottom = marginBottom ?? marginY;
18620
- if (effectiveMarginLeft !== undefined) {
18621
- style.marginLeft = effectiveMarginLeft;
18622
- }
18623
- if (effectiveMarginRight !== undefined) {
18624
- style.marginRight = effectiveMarginRight;
18625
- }
18626
- if (effectiveMarginTop !== undefined) {
18627
- style.marginTop = effectiveMarginTop;
18628
- }
18629
- if (effectiveMarginBottom !== undefined) {
18630
- style.marginBottom = effectiveMarginBottom;
18631
- }
18616
+ if (marginLeft !== undefined) {
18617
+ style.marginLeft = marginLeft;
18618
+ } else if (marginX !== undefined) {
18619
+ style.marginLeft = marginX;
18620
+ }
18621
+ if (marginRight !== undefined) {
18622
+ style.marginRight = marginRight;
18623
+ } else if (marginX !== undefined) {
18624
+ style.marginRight = marginX;
18625
+ }
18626
+ if (marginTop !== undefined) {
18627
+ style.marginTop = marginTop;
18628
+ } else if (marginY !== undefined) {
18629
+ style.marginTop = marginY;
18630
+ }
18631
+ if (marginBottom !== undefined) {
18632
+ style.marginBottom = marginBottom;
18633
+ } else if (marginY !== undefined) {
18634
+ style.marginBottom = marginY;
18635
+ }
18636
+ const padding = consume("padding");
18637
+ const paddingX = consume("paddingX");
18638
+ const paddingY = consume("paddingY");
18639
+ const paddingLeft = consume("paddingLeft");
18640
+ const paddingRight = consume("paddingRight");
18641
+ const paddingTop = consume("paddingTop");
18642
+ const paddingBottom = consume("paddingBottom");
18632
18643
  if (padding !== undefined) {
18633
18644
  style.padding = padding;
18634
18645
  }
18635
- const effectivePaddingLeft = paddingLeft ?? paddingX;
18636
- const effectivePaddingRight = paddingRight ?? paddingX;
18637
- const effectivePaddingTop = paddingTop ?? paddingY;
18638
- const effectivePaddingBottom = paddingBottom ?? paddingY;
18639
- if (effectivePaddingLeft !== undefined) {
18640
- style.paddingLeft = effectivePaddingLeft;
18646
+ if (paddingLeft !== undefined) {
18647
+ style.paddingLeft = paddingLeft;
18648
+ } else if (paddingX !== undefined) {
18649
+ style.paddingLeft = paddingX;
18641
18650
  }
18642
- if (effectivePaddingRight !== undefined) {
18643
- style.paddingRight = effectivePaddingRight;
18651
+ if (paddingRight !== undefined) {
18652
+ style.paddingRight = paddingRight;
18653
+ } else if (paddingX !== undefined) {
18654
+ style.paddingRight = paddingX;
18644
18655
  }
18645
- if (effectivePaddingTop !== undefined) {
18646
- style.paddingTop = effectivePaddingTop;
18656
+ if (paddingTop !== undefined) {
18657
+ style.paddingTop = paddingTop;
18658
+ } else if (paddingY !== undefined) {
18659
+ style.paddingTop = paddingY;
18647
18660
  }
18648
- if (effectivePaddingBottom !== undefined) {
18649
- style.paddingBottom = effectivePaddingBottom;
18661
+ if (paddingBottom !== undefined) {
18662
+ style.paddingBottom = paddingBottom;
18663
+ } else if (paddingY !== undefined) {
18664
+ style.paddingBottom = paddingY;
18650
18665
  }
18651
18666
  return style;
18652
18667
  };
@@ -18655,8 +18670,9 @@ const Spacing = ({
18655
18670
  children,
18656
18671
  ...rest
18657
18672
  }) => {
18658
- const styleForSpacing = getStyleForSpacingProps(rest);
18673
+ const styleForSpacing = consumeSpacingProps(rest);
18659
18674
  return jsx("div", {
18675
+ ...rest,
18660
18676
  style: withPropsStyle(styleForSpacing, style),
18661
18677
  children: children
18662
18678
  });
@@ -20217,7 +20233,7 @@ const NaviCheckbox = ({
20217
20233
  ...(accentColor ? {
20218
20234
  "--accent-color": accentColor
20219
20235
  } : {}),
20220
- ...getStyleForSpacingProps(rest)
20236
+ ...consumeSpacingProps(rest)
20221
20237
  }, style);
20222
20238
  return jsxs("div", {
20223
20239
  ...rest,
@@ -20642,7 +20658,7 @@ const NaviRadio = ({
20642
20658
  ...(accentColor ? {
20643
20659
  "--accent-color": accentColor
20644
20660
  } : {}),
20645
- ...getStyleForSpacingProps(rest)
20661
+ ...consumeSpacingProps(rest)
20646
20662
  }, style);
20647
20663
  return jsxs("span", {
20648
20664
  ...rest,
@@ -20863,7 +20879,7 @@ const InputTextualBasic = forwardRef((props, ref) => {
20863
20879
  const innerStyle = withPropsStyle({
20864
20880
  width,
20865
20881
  height,
20866
- ...getStyleForSpacingProps(rest)
20882
+ ...consumeSpacingProps(rest)
20867
20883
  }, style);
20868
20884
  const inputTextual = jsx("input", {
20869
20885
  ...rest,
@@ -21544,11 +21560,6 @@ const Button = forwardRef((props, ref) => {
21544
21560
  WithActionInsideForm: ButtonWithActionInsideForm
21545
21561
  });
21546
21562
  });
21547
- const alignXMapping = {
21548
- start: undefined,
21549
- center: "center",
21550
- end: "flex-end"
21551
- };
21552
21563
  const ButtonBasic = forwardRef((props, ref) => {
21553
21564
  const contextLoading = useContext(LoadingContext);
21554
21565
  const contextLoadingElement = useContext(LoadingElementContext);
@@ -21585,15 +21596,23 @@ const ButtonBasic = forwardRef((props, ref) => {
21585
21596
  } else {
21586
21597
  buttonChildren = children;
21587
21598
  }
21588
- const innerStyle = {
21589
- ...getStyleForSpacingProps(rest),
21590
- "align-self": alignXMapping[alignX]
21591
- };
21599
+ const innerClassName = withPropsClassName(appearance === "navi" ? "navi_button" : undefined, className);
21600
+ const innerStyle = withPropsStyle({
21601
+ ...consumeSpacingProps(rest),
21602
+ ...(alignX === "start" ? {} : alignX === "center" ? {
21603
+ alignSelf: "center",
21604
+ marginLeft: "auto",
21605
+ marginRight: "auto"
21606
+ } : {
21607
+ alignSelf: "end",
21608
+ marginRight: "auto"
21609
+ })
21610
+ }, style);
21592
21611
  return jsx("button", {
21593
21612
  ...rest,
21594
21613
  ref: innerRef,
21595
- className: withPropsClassName(appearance === "navi" ? "navi_button" : undefined, className),
21596
- style: withPropsStyle(innerStyle, style),
21614
+ className: innerClassName,
21615
+ style: innerStyle,
21597
21616
  disabled: innerDisabled,
21598
21617
  "data-discrete": discrete ? "" : undefined,
21599
21618
  "data-readonly": innerReadOnly ? "" : undefined,
@@ -28041,7 +28060,7 @@ const Text = ({
28041
28060
  fontWeight: bold ? "bold" : undefined,
28042
28061
  fontStyle: italic ? "italic" : undefined,
28043
28062
  textDecoration: underline ? "underline" : undefined,
28044
- ...getStyleForSpacingProps(rest)
28063
+ ...consumeSpacingProps(rest)
28045
28064
  }, style);
28046
28065
  return jsx("span", {
28047
28066
  ...rest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/navi",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Library of components including navigation to create frontend applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +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 { getStyleForSpacingProps } from "../layout/spacing.jsx";
17
+ import { consumeSpacingProps } from "../layout/spacing.jsx";
18
18
  import { LoaderBackground } from "../loader/loader_background.jsx";
19
19
  import { withPropsClassName } from "../props_composition/with_props_class_name.js";
20
20
  import { withPropsStyle } from "../props_composition/with_props_style.js";
@@ -197,11 +197,6 @@ export const Button = forwardRef((props, ref) => {
197
197
  });
198
198
  });
199
199
 
200
- const alignXMapping = {
201
- start: undefined,
202
- center: "center",
203
- end: "flex-end",
204
- };
205
200
  const ButtonBasic = forwardRef((props, ref) => {
206
201
  const contextLoading = useContext(LoadingContext);
207
202
  const contextLoadingElement = useContext(LoadingElementContext);
@@ -241,20 +236,35 @@ const ButtonBasic = forwardRef((props, ref) => {
241
236
  buttonChildren = children;
242
237
  }
243
238
 
244
- const innerStyle = {
245
- ...getStyleForSpacingProps(rest),
246
- "align-self": alignXMapping[alignX],
247
- };
239
+ const innerClassName = withPropsClassName(
240
+ appearance === "navi" ? "navi_button" : undefined,
241
+ className,
242
+ );
243
+ const innerStyle = withPropsStyle(
244
+ {
245
+ ...consumeSpacingProps(rest),
246
+ ...(alignX === "start"
247
+ ? {}
248
+ : alignX === "center"
249
+ ? {
250
+ alignSelf: "center",
251
+ marginLeft: "auto",
252
+ marginRight: "auto",
253
+ }
254
+ : {
255
+ alignSelf: "end",
256
+ marginRight: "auto",
257
+ }),
258
+ },
259
+ style,
260
+ );
248
261
 
249
262
  return (
250
263
  <button
251
264
  {...rest}
252
265
  ref={innerRef}
253
- className={withPropsClassName(
254
- appearance === "navi" ? "navi_button" : undefined,
255
- className,
256
- )}
257
- style={withPropsStyle(innerStyle, style)}
266
+ className={innerClassName}
267
+ style={innerStyle}
258
268
  disabled={innerDisabled}
259
269
  data-discrete={discrete ? "" : undefined}
260
270
  data-readonly={innerReadOnly ? "" : undefined}
@@ -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 { getStyleForSpacingProps } from "../layout/spacing.jsx";
16
+ import { consumeSpacingProps } from "../layout/spacing.jsx";
17
17
  import {
18
18
  LoadableInlineElement,
19
19
  LoaderBackground,
@@ -336,7 +336,7 @@ const NaviCheckbox = ({
336
336
  const innerStyle = withPropsStyle(
337
337
  {
338
338
  ...(accentColor ? { "--accent-color": accentColor } : {}),
339
- ...getStyleForSpacingProps(rest),
339
+ ...consumeSpacingProps(rest),
340
340
  },
341
341
  style,
342
342
  );
@@ -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 { getStyleForSpacingProps } from "../layout/spacing.jsx";
11
+ import { consumeSpacingProps } from "../layout/spacing.jsx";
12
12
  import {
13
13
  LoadableInlineElement,
14
14
  LoaderBackground,
@@ -375,7 +375,7 @@ const NaviRadio = ({
375
375
  const innerStyle = withPropsStyle(
376
376
  {
377
377
  ...(accentColor ? { "--accent-color": accentColor } : {}),
378
- ...getStyleForSpacingProps(rest),
378
+ ...consumeSpacingProps(rest),
379
379
  },
380
380
  style,
381
381
  );
@@ -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 { getStyleForSpacingProps } from "../layout/spacing.jsx";
34
+ import { consumeSpacingProps } from "../layout/spacing.jsx";
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";
@@ -203,7 +203,7 @@ const InputTextualBasic = forwardRef((props, ref) => {
203
203
  {
204
204
  width,
205
205
  height,
206
- ...getStyleForSpacingProps(rest),
206
+ ...consumeSpacingProps(rest),
207
207
  },
208
208
  style,
209
209
  );
@@ -1,68 +1,87 @@
1
1
  import { withPropsStyle } from "../props_composition/with_props_style.js";
2
2
 
3
- export const getStyleForSpacingProps = ({
4
- margin,
5
- marginX,
6
- marginY,
7
- marginLeft,
8
- marginTop,
9
- marginBottom,
10
- marginRight,
11
- padding,
12
- paddingX,
13
- paddingY,
14
- paddingLeft,
15
- paddingTop,
16
- paddingBottom,
17
- paddingRight,
18
- }) => {
19
- const style = {};
3
+ export const consumeSpacingProps = (props) => {
4
+ const consume = (name) => {
5
+ if (Object.hasOwn(props, name)) {
6
+ const value = props[name];
7
+ delete props[name];
8
+ return value;
9
+ }
10
+ return undefined;
11
+ };
12
+ const margin = consume("margin");
13
+ const marginX = consume("marginX");
14
+ const marginY = consume("marginY");
15
+ const marginLeft = consume("marginLeft");
16
+ const marginRight = consume("marginRight");
17
+ const marginTop = consume("marginTop");
18
+ const marginBottom = consume("marginBottom");
20
19
 
20
+ const style = {};
21
21
  if (margin !== undefined) {
22
22
  style.margin = margin;
23
23
  }
24
- const effectiveMarginLeft = marginLeft ?? marginX;
25
- const effectiveMarginRight = marginRight ?? marginX;
26
- const effectiveMarginTop = marginTop ?? marginY;
27
- const effectiveMarginBottom = marginBottom ?? marginY;
28
-
29
- if (effectiveMarginLeft !== undefined) {
30
- style.marginLeft = effectiveMarginLeft;
24
+ if (marginLeft !== undefined) {
25
+ style.marginLeft = marginLeft;
26
+ } else if (marginX !== undefined) {
27
+ style.marginLeft = marginX;
31
28
  }
32
- if (effectiveMarginRight !== undefined) {
33
- style.marginRight = effectiveMarginRight;
29
+ if (marginRight !== undefined) {
30
+ style.marginRight = marginRight;
31
+ } else if (marginX !== undefined) {
32
+ style.marginRight = marginX;
34
33
  }
35
- if (effectiveMarginTop !== undefined) {
36
- style.marginTop = effectiveMarginTop;
34
+ if (marginTop !== undefined) {
35
+ style.marginTop = marginTop;
36
+ } else if (marginY !== undefined) {
37
+ style.marginTop = marginY;
37
38
  }
38
- if (effectiveMarginBottom !== undefined) {
39
- style.marginBottom = effectiveMarginBottom;
39
+ if (marginBottom !== undefined) {
40
+ style.marginBottom = marginBottom;
41
+ } else if (marginY !== undefined) {
42
+ style.marginBottom = marginY;
40
43
  }
41
44
 
45
+ const padding = consume("padding");
46
+ const paddingX = consume("paddingX");
47
+ const paddingY = consume("paddingY");
48
+ const paddingLeft = consume("paddingLeft");
49
+ const paddingRight = consume("paddingRight");
50
+ const paddingTop = consume("paddingTop");
51
+ const paddingBottom = consume("paddingBottom");
52
+
42
53
  if (padding !== undefined) {
43
54
  style.padding = padding;
44
55
  }
45
- const effectivePaddingLeft = paddingLeft ?? paddingX;
46
- const effectivePaddingRight = paddingRight ?? paddingX;
47
- const effectivePaddingTop = paddingTop ?? paddingY;
48
- const effectivePaddingBottom = paddingBottom ?? paddingY;
49
- if (effectivePaddingLeft !== undefined) {
50
- style.paddingLeft = effectivePaddingLeft;
56
+ if (paddingLeft !== undefined) {
57
+ style.paddingLeft = paddingLeft;
58
+ } else if (paddingX !== undefined) {
59
+ style.paddingLeft = paddingX;
51
60
  }
52
- if (effectivePaddingRight !== undefined) {
53
- style.paddingRight = effectivePaddingRight;
61
+ if (paddingRight !== undefined) {
62
+ style.paddingRight = paddingRight;
63
+ } else if (paddingX !== undefined) {
64
+ style.paddingRight = paddingX;
54
65
  }
55
- if (effectivePaddingTop !== undefined) {
56
- style.paddingTop = effectivePaddingTop;
66
+ if (paddingTop !== undefined) {
67
+ style.paddingTop = paddingTop;
68
+ } else if (paddingY !== undefined) {
69
+ style.paddingTop = paddingY;
57
70
  }
58
- if (effectivePaddingBottom !== undefined) {
59
- style.paddingBottom = effectivePaddingBottom;
71
+ if (paddingBottom !== undefined) {
72
+ style.paddingBottom = paddingBottom;
73
+ } else if (paddingY !== undefined) {
74
+ style.paddingBottom = paddingY;
60
75
  }
61
76
 
62
77
  return style;
63
78
  };
64
79
 
65
80
  export const Spacing = ({ style, children, ...rest }) => {
66
- const styleForSpacing = getStyleForSpacingProps(rest);
67
- return <div style={withPropsStyle(styleForSpacing, style)}>{children}</div>;
81
+ const styleForSpacing = consumeSpacingProps(rest);
82
+ return (
83
+ <div {...rest} style={withPropsStyle(styleForSpacing, style)}>
84
+ {children}
85
+ </div>
86
+ );
68
87
  };
@@ -1,4 +1,4 @@
1
- import { getStyleForSpacingProps } from "../layout/spacing.jsx";
1
+ import { consumeSpacingProps } from "../layout/spacing.jsx";
2
2
  import { withPropsStyle } from "../props_composition/with_props_style.js";
3
3
 
4
4
  import.meta.css = /* css */ `
@@ -39,7 +39,7 @@ export const Text = ({
39
39
  fontWeight: bold ? "bold" : undefined,
40
40
  fontStyle: italic ? "italic" : undefined,
41
41
  textDecoration: underline ? "underline" : undefined,
42
- ...getStyleForSpacingProps(rest),
42
+ ...consumeSpacingProps(rest),
43
43
  },
44
44
  style,
45
45
  );