@jsenv/navi 0.5.1 → 0.5.2

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.
@@ -27749,28 +27749,17 @@ const useSignalSync = (value, initialValue = value) => {
27749
27749
  return signal;
27750
27750
  };
27751
27751
 
27752
- /**
27753
- * FontSizedSvg component
27754
- *
27755
- * This component wraps an SVG element to make it inherit the current font size.
27756
- * It creates a container that's exactly 1em × 1em in size, allowing the SVG to scale
27757
- * proportionally with the surrounding text.
27758
- *
27759
- * Usage:
27760
- * ```jsx
27761
- * <FontSizedSvg>
27762
- * <svg width="100%" height="100%" viewBox="...">
27763
- * <path d="..." />
27764
- * </svg>
27765
- * </FontSizedSvg>
27766
- * ```
27767
- *
27768
- * Notes:
27769
- * - The wrapped SVG should use width="100%" and height="100%" to fill the container
27770
- * - This ensures SVG icons match the current text size without additional styling
27771
- * - Useful for inline icons that should respect the parent's font-size
27772
- */
27773
-
27752
+ installImportMetaCss(import.meta);import.meta.css = /* css */`
27753
+ .navi_font_sized_svg {
27754
+ display: flex;
27755
+ width: 1em;
27756
+ height: 1em;
27757
+ flex-shrink: 0;
27758
+ align-items: center;
27759
+ justify-self: center;
27760
+ line-height: 1em;
27761
+ }
27762
+ `;
27774
27763
  const FontSizedSvg = ({
27775
27764
  width = "1em",
27776
27765
  height = "1em",
@@ -27780,16 +27769,11 @@ const FontSizedSvg = ({
27780
27769
  }) => {
27781
27770
  return jsx("span", {
27782
27771
  ...props,
27783
- style: {
27784
- ...style,
27785
- display: "flex",
27786
- alignItems: "center",
27787
- width,
27788
- height,
27789
- justifySelf: "center",
27790
- lineHeight: "1em",
27791
- flexShrink: 0
27792
- },
27772
+ className: "navi_font_sized_svg",
27773
+ style: withPropsStyle({
27774
+ width: width === "1em" ? undefined : width,
27775
+ height: height === "1em" ? undefined : height
27776
+ }, style),
27793
27777
  children: children
27794
27778
  });
27795
27779
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/navi",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Library of components including navigation to create frontend applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,136 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>withPropsStyle Demo - Simple</title>
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+ <script type="module" jsenv-type="module/jsx">
10
+ /* eslint-disable no-unused-vars */
11
+ import { render } from "preact";
12
+ import { withPropsStyle } from "../with_props_style.js";
13
+
14
+ // Simple button component
15
+ const Button = ({ style, children, ...rest }) => (
16
+ <button
17
+ style={withPropsStyle(
18
+ {
19
+ padding: "12px 20px",
20
+ borderRadius: "4px",
21
+ border: "1px solid #ccc",
22
+ backgroundColor: "#f8f9fa",
23
+ cursor: "pointer",
24
+ fontFamily: "system-ui, sans-serif",
25
+ },
26
+ style,
27
+ )}
28
+ {...rest}
29
+ >
30
+ {children}
31
+ </button>
32
+ );
33
+
34
+ // Component using CSS variables
35
+ const ThemedBox = ({ style, children, ...rest }) => (
36
+ <div
37
+ style={withPropsStyle(
38
+ {
39
+ padding: "20px",
40
+ borderRadius: "8px",
41
+ backgroundColor: "var(--box-color, #e3f2fd)",
42
+ border: "2px solid var(--border-color, #90caf9)",
43
+ color: "var(--text-color, #1565c0)",
44
+ },
45
+ style,
46
+ )}
47
+ {...rest}
48
+ >
49
+ {children}
50
+ </div>
51
+ );
52
+
53
+ const Demo = () => {
54
+ return (
55
+ <div
56
+ style={{
57
+ padding: "20px",
58
+ fontFamily: "system-ui, sans-serif",
59
+ maxWidth: "600px",
60
+ }}
61
+ >
62
+ <h1>withPropsStyle Demo</h1>
63
+
64
+ <section style={{ marginBottom: "30px" }}>
65
+ <h2>Background Color Control</h2>
66
+
67
+ <div style={{ display: "flex", gap: "10px", flexWrap: "wrap" }}>
68
+ <Button>Default Button</Button>
69
+
70
+ <Button style={{ backgroundColor: "#007bff" }}>
71
+ Object: Blue
72
+ </Button>
73
+
74
+ <Button style="background-color: #28a745;">
75
+ String: Green
76
+ </Button>
77
+
78
+ <Button style={{ backgroundColor: "#dc3545", color: "white" }}>
79
+ Object: Red + White Text
80
+ </Button>
81
+
82
+ <Button style="background-color: #ffc107; color: black;">
83
+ String: Yellow + Black Text
84
+ </Button>
85
+ </div>
86
+ </section>
87
+
88
+ <section>
89
+ <h2>CSS Variables Control</h2>
90
+
91
+ <div
92
+ style={{
93
+ display: "flex",
94
+ flexDirection: "column",
95
+ gap: "15px",
96
+ }}
97
+ >
98
+ <ThemedBox>Default themed box with CSS variables</ThemedBox>
99
+
100
+ <ThemedBox
101
+ style={{
102
+ "--box-color": "#ffebee",
103
+ "--border-color": "#f44336",
104
+ "--text-color": "#c62828",
105
+ }}
106
+ >
107
+ Object: Red theme via CSS variables
108
+ </ThemedBox>
109
+
110
+ <ThemedBox style="--box-color: #e8f5e8; --border-color: #4caf50; --text-color: #2e7d32;">
111
+ String: Green theme via CSS variables
112
+ </ThemedBox>
113
+
114
+ <ThemedBox
115
+ style={{
116
+ "--box-color": "#fff3e0",
117
+ "--border-color": "#ff9800",
118
+ "padding": "30px",
119
+ }}
120
+ >
121
+ Object: Orange theme + custom padding override
122
+ </ThemedBox>
123
+
124
+ <ThemedBox style="--box-color: #f3e5f5; --border-color: #9c27b0; --text-color: #6a1b9a; border-radius: 16px;">
125
+ String: Purple theme + border-radius override
126
+ </ThemedBox>
127
+ </div>
128
+ </section>
129
+ </div>
130
+ );
131
+ };
132
+
133
+ render(<Demo />, document.getElementById("app"));
134
+ </script>
135
+ </body>
136
+ </html>
@@ -20,6 +20,20 @@
20
20
  * - Useful for inline icons that should respect the parent's font-size
21
21
  */
22
22
 
23
+ import { withPropsStyle } from "../props_composition/with_props_style.js";
24
+
25
+ import.meta.css = /* css */ `
26
+ .navi_font_sized_svg {
27
+ display: flex;
28
+ width: 1em;
29
+ height: 1em;
30
+ flex-shrink: 0;
31
+ align-items: center;
32
+ justify-self: center;
33
+ line-height: 1em;
34
+ }
35
+ `;
36
+
23
37
  export const FontSizedSvg = ({
24
38
  width = "1em",
25
39
  height = "1em",
@@ -30,16 +44,14 @@ export const FontSizedSvg = ({
30
44
  return (
31
45
  <span
32
46
  {...props}
33
- style={{
34
- ...style,
35
- display: "flex",
36
- alignItems: "center",
37
- width,
38
- height,
39
- justifySelf: "center",
40
- lineHeight: "1em",
41
- flexShrink: 0,
42
- }}
47
+ className="navi_font_sized_svg"
48
+ style={withPropsStyle(
49
+ {
50
+ width: width === "1em" ? undefined : width,
51
+ height: height === "1em" ? undefined : height,
52
+ },
53
+ style,
54
+ )}
43
55
  >
44
56
  {children}
45
57
  </span>