Skip to content

Commit 880d3e6

Browse files
committed
!refactor: remove createTheme API
1 parent 5186eec commit 880d3e6

File tree

6 files changed

+23
-215
lines changed

6 files changed

+23
-215
lines changed

index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export {combineStyles} from './lib/combine-styles.js';
22
export {createCssVariables} from './lib/create-css-variables.js';
3-
export {createTheme} from './lib/create-theme.js';
43
export {createThemeRenderer} from './lib/create-theme-renderer.js';
54
export * from './lib/types.js';

lib/create-theme-renderer.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {createWebPreset} from 'fela-preset-web';
77
import {isPlainObject, merge} from 'uinix-fp';
88

99
import {createCssVariables} from './create-css-variables.js';
10-
import {createTheme} from './create-theme.js';
1110
import {coerceEsm} from './utils/coerce-esm.js';
1211
import {responsiveValue} from './utils/plugin-responsive-value.js';
1312
import {themeValue} from './utils/plugin-theme-value.js';
@@ -48,7 +47,7 @@ export const createThemeRenderer = (options = {}) => {
4847
responsiveBreakpoints = [],
4948
responsiveCssProperties = [],
5049
themeSpec = {},
51-
theme = createTheme({}, themeSpec),
50+
theme = {},
5251
} = options;
5352

5453
const enhancers = [coerceEsm(enforceLonghands)()];

lib/create-theme.js

-24
This file was deleted.

readme.md

+22-124
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ To further explore uinix-theme, visit the [Theme Playground] for interactive dem
4040
- [API](#api)
4141
- [`combineStyles(styles) => styleRule`](#combinestylesstyles--stylerule)
4242
- [`createCssVariables(theme?, options?) => cssVariables`](#createcssvariablestheme-options--cssvariables)
43-
- [`createTheme(theme?, themeSpec?) => theme`](#createthemetheme-themespec--theme)
4443
- [`createThemeRenderer(options?) => renderer`](#createthemerendereroptions--renderer)
4544
- [Theme specs](#theme-specs)
4645
- [Glossary](#glossary)
4746
- [Project](#project)
4847
- [Origin](#origin)
48+
- [Types](#types)
4949
- [Version](#version)
5050
- [Contribute](#contribute)
5151
- [Related](#related)
@@ -146,49 +146,29 @@ const themeSpec = {
146146

147147
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*.
148148

149-
Create a theme using a *theme spec* with `createTheme`:
150-
151-
```js
152-
import {createTheme} from 'uinix-theme';
153-
154-
const theme = 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-
174149
```js
175150
const theme = {
176151
colors: {
177-
brand: {
152+
brand: { // can be arbitrarily nested for organization.
178153
primary: 'red',
179154
link: 'blue',
180155
},
181156
},
182-
margins: {}, // every theme property in the theme spec is materialized if not specified.
183157
paddings: {
184158
s: 4,
185159
m: 8,
186160
l: 16,
187161
},
188-
// unsupported theme properties not whitelisted in the theme spec are dropped.
189162
};
190163
```
191164

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+
192172
### Create a theme renderer
193173

194174
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:
408388
}
409389
```
410390

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.
412392
413393
### Configure and render themed CSS variables
414394

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.
416396

417397
```js
418398
import {createThemeRenderer} from 'uinix-theme';
@@ -516,14 +496,15 @@ Yields the following rendered CSS
516496
517497
## API
518498

519-
`uinix-theme` exports the following identifiers:
499+
uinix-theme exports the following identifiers:
520500
- `combineStyles`
521501
- `createCssVariables`
522-
- `createTheme`
523502
- `createThemeRenderer`
524503

525504
There are no default exports.
526505

506+
APIs are explorable via [JSDoc]-based [Typescript] typings accompanying the source code.
507+
527508
Please refer to the [§ Glossary](#glossary) for definitions of *italicized terms* referenced throughout this document.
528509

529510
### `combineStyles(styles) => styleRule`
@@ -637,96 +618,6 @@ const cssVariables = {
637618

638619
</details>
639620

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.
643-
644-
##### Parameters
645-
646-
###### `theme` (`Theme`, optional, default: `{}`)
647-
648-
See *theme* defined in [§ Glossary](#glossary).
649-
650-
###### `themeSpec` (`ThemeSpec`, optional, default: `{}`)
651-
652-
See *theme spec* defined in [§ Glossary](#glossary).
653-
654-
##### Returns
655-
656-
###### `theme` (`Theme`)
657-
A validated theme object based on the provided theme spec.
658-
659-
<details>
660-
<summary>Example</summary>
661-
662-
```js
663-
import {createTheme} from 'uinix-theme';
664-
665-
const themeSpec = {
666-
colors: [
667-
'backgroundColor',
668-
'color'
669-
],
670-
fontFamilies: [
671-
'fontFamily',
672-
],
673-
fontSizes: [
674-
'fontSize',
675-
],
676-
spacings: [
677-
'margin',
678-
'marginBottom',
679-
'marginLeft',
680-
'marginRight',
681-
'marginTop',
682-
'padding',
683-
'paddingBottom',
684-
'paddingLeft',
685-
'paddingRight',
686-
'paddingTop',
687-
],
688-
};
689-
690-
const theme = createTheme({
691-
colors: {
692-
brand: {
693-
primary: 'red',
694-
link: 'blue',
695-
},
696-
},
697-
spacings: {
698-
s: 4,
699-
m: 8,
700-
l: 16,
701-
},
702-
unsupportedThemeProperty: {}
703-
}, themeSpec);
704-
705-
console.log(theme);
706-
```
707-
708-
Yields the following validated theme:
709-
710-
```js
711-
const theme = {
712-
colors: {
713-
brand: {
714-
primary: 'red',
715-
link: 'blue',
716-
},
717-
},
718-
fontFamilies: {}, // materialized from themeSpec
719-
fontSizes: {}, // materialized from themeSpec
720-
spacings: {
721-
s: 4,
722-
m: 8,
723-
l: 16,
724-
},
725-
// unsupported theme properties are dropped
726-
}
727-
```
728-
</details>
729-
730621
### `createThemeRenderer(options?) => renderer`
731622

732623
Creates a theme renderer to resolve *themed styles* based on the provided *theme* and *theme spec*, and render the resolved styles to the DOM.
@@ -758,7 +649,7 @@ Whitelist the corresponding responsive *CSS properties* to be responsive-aware.
758649

759650
See *theme* defined in [§ Glossary](#glossary).
760651

761-
###### `options.theme` (`Theme`, optional, default: `createTheme()`)
652+
###### `options.theme` (`Theme`, optional, default: `{}`)
762653

763654
See *theme spec* defined in [§ Glossary](#glossary).
764655

@@ -1171,10 +1062,16 @@ uinix-theme approaches theme systems with the following principles:
11711062
- Build-free: APIs are usable without the need for a build system (e.g. directly usable in browsers as plain JS).
11721063
- Update-free: APIs are intended to be stable, imparting confidence for both maintainers and consumers of the project.
11731064

1065+
## Types
1066+
1067+
uinix-theme ships with [Typescript] declarations, compiled and emitted when installed. The source code is pure Javascript.
1068+
11741069
### Version
11751070

11761071
uinix-theme adheres to [semver] starting at 1.0.0.
11771072

1073+
**Note:** uinix-theme is a *JS-first* project. [Typescript] types are provided as a supplementary convenience for the TS community. Changes in typings will always be treated as [semver] fixes.
1074+
11781075
### Contribute
11791076

11801077
Node 18+ is required for development.
@@ -1228,3 +1125,4 @@ Install dependencies with `npm i` and run tests with `npm test`. You can also r
12281125
[npm]: https://docs.npmjs.com/cli/v8/commands/npm-install
12291126
[semver]: https://semver.org/
12301127
[theme-ui]: https://github.com/system-ui/theme-ui
1128+
[typescript]: https://github.com/microsoft/TypeScript

test/create-theme.js

-63
This file was deleted.

test/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import './coerce-esm.js';
22
import './combine-styles.js';
33
import './create-css-variables.js';
4-
import './create-theme.js';
54
import './create-theme-renderer.js';

0 commit comments

Comments
 (0)