@xsolla/xui-svg-themed 0.149.1 → 0.151.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.
Files changed (2) hide show
  1. package/README.md +52 -146
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,82 +1,75 @@
1
- # SVG Themed
1
+ # SvgThemed
2
2
 
3
- A React component that wraps SVG content and automatically resolves theme tokens (like `$colors_core_text_primary`) to actual theme values, enabling theme-aware custom SVG graphics.
3
+ A React SVG wrapper that resolves `$`-prefixed token strings on `fill`, `stroke`, `stopColor`, and `color` attributes to live theme values. Any standard SVG attribute (`width`, `height`, `viewBox`, etc.) is accepted via `SVGProps<SVGSVGElement>`.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
8
  npm install @xsolla/xui-svg-themed
9
- # or
10
- yarn add @xsolla/xui-svg-themed
11
9
  ```
12
10
 
13
- ## Demo
11
+ ## Imports
14
12
 
15
- ### Basic Usage
13
+ ```tsx
14
+ import { SvgThemed, type SvgThemedProps } from '@xsolla/xui-svg-themed';
15
+ ```
16
+
17
+ ## Quick start
16
18
 
17
19
  ```tsx
18
20
  import * as React from 'react';
19
21
  import { SvgThemed } from '@xsolla/xui-svg-themed';
20
22
 
21
- export default function BasicSvg() {
23
+ export default function QuickStart() {
22
24
  return (
23
25
  <SvgThemed width={24} height={24} viewBox="0 0 24 24">
24
- <circle
25
- cx={12}
26
- cy={12}
27
- r={10}
28
- fill="$colors_core_text_primary"
29
- />
26
+ <circle cx={12} cy={12} r={10} fill="$colors_core_text_primary" />
30
27
  </SvgThemed>
31
28
  );
32
29
  }
33
30
  ```
34
31
 
35
- ### With Theme Tokens
32
+ ## API Reference
36
33
 
37
- ```tsx
38
- import * as React from 'react';
39
- import { SvgThemed } from '@xsolla/xui-svg-themed';
34
+ ### `<SvgThemed>`
40
35
 
41
- export default function ThemedIcon() {
42
- return (
43
- <SvgThemed width={32} height={32} viewBox="0 0 32 32">
44
- <rect
45
- x={4}
46
- y={4}
47
- width={24}
48
- height={24}
49
- rx={4}
50
- fill="$colors_control_faint_bg"
51
- />
52
- <path
53
- d="M16 8L20 16H12L16 8Z"
54
- fill="$colors_core_text_brand"
55
- />
56
- </SvgThemed>
57
- );
58
- }
59
- ```
36
+ | Prop | Type | Default | Description |
37
+ | --- | --- | --- | --- |
38
+ | `children` | `ReactNode` | | SVG content. Themed token strings are resolved recursively. |
39
+ | `data-testid` | `string` | — | Test identifier. |
60
40
 
61
- ## Anatomy
41
+ Standard SVG attributes (`width`, `height`, `viewBox`, `xmlns`, `role`, `fill`, `stroke`, etc.) come from `SVGProps<SVGSVGElement>` and are forwarded to the underlying `<svg>` element — they are not enumerated as explicit props.
62
42
 
63
- ```jsx
64
- import { SvgThemed } from '@xsolla/xui-svg-themed';
43
+ Inherits `ThemeOverrideProps` (`themeMode`, `themeProductContext`).
65
44
 
66
- <SvgThemed
67
- width={24}
68
- height={24}
69
- viewBox="0 0 24 24"
70
- // All standard SVG props
71
- >
72
- <path fill="$colors_core_text_primary" d="..." />
73
- <circle stroke="$colors_core_text_brand" />
74
- </SvgThemed>
75
- ```
45
+ ### Themeable attributes
46
+
47
+ The following descendant attributes are scanned recursively and replaced when their string value starts with `$`:
48
+
49
+ - `fill`
50
+ - `stroke`
51
+ - `stopColor`
52
+ - `color`
53
+
54
+ ## Theming
55
+
56
+ Token strings start with `$` and map to theme paths. Tokens not in the map are passed through unchanged.
57
+
58
+ | Token | Theme path |
59
+ | --- | --- |
60
+ | `$colors_core_text_primary` | `content.primary` |
61
+ | `$colors_core_text_secondary` | `content.secondary` |
62
+ | `$colors_core_text_tertiary` | `content.tertiary` |
63
+ | `$colors_core_text_brand` | `content.brand.primary` |
64
+ | `$colors_core_text_success` | `content.success.primary` |
65
+ | `$colors_core_text_warning` | `content.warning.primary` |
66
+ | `$colors_core_text_alert` | `content.alert.primary` |
67
+ | `$colors_core_text_neutral` | `content.neutral.primary` |
68
+ | `$colors_control_faint_bg` | `control.mono.secondary.bg` |
76
69
 
77
70
  ## Examples
78
71
 
79
- ### Custom Status Icon
72
+ ### Themed status icon
80
73
 
81
74
  ```tsx
82
75
  import * as React from 'react';
@@ -85,12 +78,7 @@ import { SvgThemed } from '@xsolla/xui-svg-themed';
85
78
  export default function StatusIcon() {
86
79
  return (
87
80
  <SvgThemed width={24} height={24} viewBox="0 0 24 24">
88
- <circle
89
- cx={12}
90
- cy={12}
91
- r={10}
92
- fill="$colors_core_text_success"
93
- />
81
+ <circle cx={12} cy={12} r={10} fill="$colors_core_text_success" />
94
82
  <path
95
83
  d="M8 12L11 15L16 9"
96
84
  stroke="#fff"
@@ -104,7 +92,7 @@ export default function StatusIcon() {
104
92
  }
105
93
  ```
106
94
 
107
- ### Illustration with Multiple Colors
95
+ ### Multi-colour illustration
108
96
 
109
97
  ```tsx
110
98
  import * as React from 'react';
@@ -113,35 +101,15 @@ import { SvgThemed } from '@xsolla/xui-svg-themed';
113
101
  export default function Illustration() {
114
102
  return (
115
103
  <SvgThemed width={100} height={100} viewBox="0 0 100 100">
116
- {/* Background */}
117
- <rect
118
- width={100}
119
- height={100}
120
- rx={12}
121
- fill="$colors_control_faint_bg"
122
- />
123
- {/* Primary shape */}
124
- <circle
125
- cx={50}
126
- cy={40}
127
- r={20}
128
- fill="$colors_core_text_brand"
129
- />
130
- {/* Secondary shape */}
131
- <rect
132
- x={30}
133
- y={65}
134
- width={40}
135
- height={20}
136
- rx={4}
137
- fill="$colors_core_text_secondary"
138
- />
104
+ <rect width={100} height={100} rx={12} fill="$colors_control_faint_bg" />
105
+ <circle cx={50} cy={40} r={20} fill="$colors_core_text_brand" />
106
+ <rect x={30} y={65} width={40} height={20} rx={4} fill="$colors_core_text_secondary" />
139
107
  </SvgThemed>
140
108
  );
141
109
  }
142
110
  ```
143
111
 
144
- ### Badge with Gradient
112
+ ### Gradient with token stops
145
113
 
146
114
  ```tsx
147
115
  import * as React from 'react';
@@ -157,74 +125,12 @@ export default function GradientBadge() {
157
125
  </linearGradient>
158
126
  </defs>
159
127
  <circle cx={24} cy={24} r={20} fill="url(#grad)" />
160
- <text
161
- x={24}
162
- y={24}
163
- textAnchor="middle"
164
- dominantBaseline="central"
165
- fill="#fff"
166
- fontSize={16}
167
- fontWeight="bold"
168
- >
169
- XP
170
- </text>
171
128
  </SvgThemed>
172
129
  );
173
130
  }
174
131
  ```
175
132
 
176
- ## API Reference
177
-
178
- ### SvgThemed
179
-
180
- **SvgThemedProps:**
181
-
182
- Extends all standard SVG element attributes plus:
183
-
184
- | Prop | Type | Default | Description |
185
- | :--- | :--- | :------ | :---------- |
186
- | children | `ReactNode` | - | SVG content with theme tokens. |
187
- | width | `number \| string` | - | SVG width. |
188
- | height | `number \| string` | - | SVG height. |
189
- | viewBox | `string` | - | SVG viewBox attribute. |
190
-
191
- ## Supported Theme Tokens
192
-
193
- Use these token strings prefixed with `$` for theme-aware colors:
194
-
195
- | Token | Theme Path |
196
- | :---- | :--------- |
197
- | `$colors_core_text_primary` | `content.primary` |
198
- | `$colors_core_text_secondary` | `content.secondary` |
199
- | `$colors_core_text_tertiary` | `content.tertiary` |
200
- | `$colors_core_text_brand` | `content.brand.primary` |
201
- | `$colors_core_text_success` | `content.success.primary` |
202
- | `$colors_core_text_warning` | `content.warning.primary` |
203
- | `$colors_core_text_alert` | `content.alert.primary` |
204
- | `$colors_core_text_neutral` | `content.neutral.primary` |
205
- | `$colors_control_faint_bg` | `control.mono.secondary.bg` |
206
-
207
- ## Themeable Properties
208
-
209
- The following SVG properties are automatically resolved:
210
-
211
- - `fill`
212
- - `stroke`
213
- - `stopColor`
214
- - `color`
215
-
216
- ## Use Cases
217
-
218
- - Custom icons not available in icon packages
219
- - Theme-aware illustrations
220
- - Dynamic SVG graphics that adapt to light/dark modes
221
- - Brand-specific visual elements
222
- - Decorative graphics with theme integration
223
-
224
- ## How It Works
133
+ ## Accessibility
225
134
 
226
- 1. SvgThemed wraps your SVG content
227
- 2. It recursively processes all child elements
228
- 3. Properties starting with `$` are matched against token map
229
- 4. Tokens are replaced with actual theme color values
230
- 5. Result is a fully themed SVG that updates with theme changes
135
+ - Pass `role="img"` and an `aria-label` (or `<title>` element) when the SVG conveys meaning.
136
+ - Set `aria-hidden="true"` for decorative graphics.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-svg-themed",
3
- "version": "0.149.1",
3
+ "version": "0.151.0",
4
4
  "main": "./web/index.js",
5
5
  "module": "./web/index.mjs",
6
6
  "types": "./web/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  "build:native": "PLATFORM=native tsup"
11
11
  },
12
12
  "dependencies": {
13
- "@xsolla/xui-core": "0.149.1",
14
- "@xsolla/xui-primitives-core": "0.149.1"
13
+ "@xsolla/xui-core": "0.151.0",
14
+ "@xsolla/xui-primitives-core": "0.151.0"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": ">=16.8.0",