You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A *theme* is an object relating *theme properties* with *CSS values* (can be arbitrarily nested). It provides a way to define and reference CSS values via *theme values*.
148
148
149
-
Create a theme using a *theme spec* with `createTheme`:
150
-
151
-
```js
152
-
import {createTheme} from'uinix-theme';
153
-
154
-
consttheme=createTheme({
155
-
colors: {
156
-
brand: { // can be arbitrarily nested for organization.
157
-
primary:'red',
158
-
link:'blue',
159
-
},
160
-
},
161
-
paddings: {
162
-
s:4,
163
-
m:8,
164
-
l:16,
165
-
},
166
-
unsupportedThemeProperty: {}
167
-
}, themeSpec);
168
-
169
-
console.log(theme);
170
-
```
171
-
172
-
Yields a compliant theme based on the provided theme spec:
173
-
174
149
```js
175
150
consttheme= {
176
151
colors: {
177
-
brand: {
152
+
brand: {// can be arbitrarily nested for organization.
178
153
primary:'red',
179
154
link:'blue',
180
155
},
181
156
},
182
-
margins: {}, // every theme property in the theme spec is materialized if not specified.
183
157
paddings: {
184
158
s:4,
185
159
m:8,
186
160
l:16,
187
161
},
188
-
// unsupported theme properties not whitelisted in the theme spec are dropped.
189
162
};
190
163
```
191
164
165
+
The following *theme values* (authored as [JSONPath] syntax relative to the provided *theme*) resolve to their respective assigned *CSS values*.
166
+
-`colors.brand.primary`: `'red'`
167
+
-`colors.brand.link`: `'blue'`
168
+
-`paddings.s`: `4`
169
+
-`paddings.m`: `8`
170
+
-`paddings.l`: `16`
171
+
192
172
### Create a theme renderer
193
173
194
174
A *theme renderer* provides ways to resolve *themed styles* based on the provided *theme* and *theme spec*, and renders the resolved CSS to the DOM.
@@ -408,11 +388,11 @@ Yields the following rendered atomic CSS classes:
408
388
}
409
389
```
410
390
411
-
> **Note**: We recommend enabling atomic CSS in production as a scalable solution to share and reuse CSS class definitions across HTML elements. Disabling atomic styles in development is recommended to improve debugging experience.
391
+
> **Note**: We recommend enabling atomic CSS in production as a scalable solution to share and reuse CSS class definitions across HTML elements. Disabling atomic styles in development is recommended to improve development experience.
412
392
413
393
### Configure and render themed CSS variables
414
394
415
-
If you prefer to work with *CSS variables* and would like to integrate CSS workstreams with uinix-theme, you can configure rendering the entire *theme* as CSS variables in the global style sheet.
395
+
If you prefer to work with *CSS variables* and would like to integrate CSS workstreams with uinix-theme, you can configure rendering the entire *theme* as CSS variables into the global style sheet.
416
396
417
397
```js
418
398
import {createThemeRenderer} from'uinix-theme';
@@ -516,14 +496,15 @@ Yields the following rendered CSS
516
496
517
497
## API
518
498
519
-
`uinix-theme` exports the following identifiers:
499
+
uinix-theme exports the following identifiers:
520
500
-`combineStyles`
521
501
-`createCssVariables`
522
-
-`createTheme`
523
502
-`createThemeRenderer`
524
503
525
504
There are no default exports.
526
505
506
+
APIs are explorable via [JSDoc]-based [Typescript] typings accompanying the source code.
507
+
527
508
Please refer to the [§ Glossary](#glossary) for definitions of *italicized terms* referenced throughout this document.
528
509
529
510
### `combineStyles(styles) => styleRule`
@@ -637,96 +618,6 @@ const cssVariables = {
637
618
638
619
</details>
639
620
640
-
### `createTheme(theme?, themeSpec?) => theme`
641
-
642
-
Creates a validated theme object based on the provided *theme* and *theme spec*. *Theme properties* not specified on the theme spec are considered invalid and are not included in the returned object.
See *theme spec* defined in [§ Glossary](#glossary).
764
655
@@ -1171,10 +1062,16 @@ uinix-theme approaches theme systems with the following principles:
1171
1062
- Build-free: APIs are usable without the need for a build system (e.g. directly usable in browsers as plain JS).
1172
1063
- Update-free: APIs are intended to be stable, imparting confidence for both maintainers and consumers of the project.
1173
1064
1065
+
## Types
1066
+
1067
+
uinix-theme ships with [Typescript] declarations, compiled and emitted when installed. The source code is pure Javascript.
1068
+
1174
1069
### Version
1175
1070
1176
1071
uinix-theme adheres to [semver] starting at 1.0.0.
1177
1072
1073
+
**Note:** uinix-theme is a *JS-first* project. [Typescript] types are provided as a supplementary convenience for the TScommunity. Changesin typings will always be treated as [semver] fixes.
1074
+
1178
1075
### Contribute
1179
1076
1180
1077
Node18+ is required for development.
@@ -1228,3 +1125,4 @@ Install dependencies with `npm i` and run tests with `npm test`. You can also r
0 commit comments