UNPKG

2.36 kBMarkdownView Raw
1---
2title: Theme
3isExperimentalPackage: true
4---
5
6🚧 — Under construction
7
8The theme packages exports a set of objects and utilities that are used
9internally to create Spark Web components as well as for consumers to be able to
10override
11
12## useTheme
13
14The `useTheme` hook returns an object with our theme tokens along with a set of
15styling utilities.
16
17The theme will always be in the same shape, but the values can be overridden by
18[passing in a custom theme to the SparkProvider](/package/core).
19
20Theme tokens differ slightly from the values passed into the provider (or the
21defaultTokens if you don't provide a theme) as they are run through the
22[decorateTokens](https://github.com/brighte-labs/spark-web/blob/6fc8d1bc37e25d0cd622bc37f68a1d92eb5961b5/packages/theme/src/make-theme.ts#L101)
23function which add some extra values that should never change (and therefore
24aren't themeable) as well as using
25[Capsize](https://seek-oss.github.io/capsize/) to add tokens we need to trim
26space above capital letters and below the baseline so spacing between elements
27is consistent and doesn't vary depending on line-height, font-size etc.
28
29For more documentation about our tokens, please see the
30[tokens reference page](/reference/tokens).
31
32#### mapResponsiveProp
33
34Returns either the string value of the token provided to it, or an array which
35maps to [our breakpoints](/reference/tokens#breakpoint) (where index 0 refers to
36the mobile breakpoint, 1 is the tablet breakpoint and so on).
37
38### Theme utils
39
40#### mapResponsiveScale
41
42Helper for mapping keys/breakpoint map to a theme scale e.g.
43
44```jsx
45mapResponsiveProp('small', { small: 8, large: 16 }); // 8
46mapResponsiveProp(
47 { mobile: 'small', tablet: 'large' },
48 { small: 8, medium: 12, large: 16 }
49); // [8, 16]
50```
51
52#### optimizeResponsiveArray
53
54TODO
55
56#### responsiveRange
57
58Designed to be used alongside `optimizeResponsiveArray`.
59
60#### responsiveStyles
61
62TODO
63
64#### resolveResponsiveProps
65
66TODO
67
68## defaultTokens
69
70This is the default tokens for the Brighte theme _before_ they've been
71decorated.
72
73## makeBrighteTheme
74
75This function
76
77- decorates to passed in tokens
78- decorates them
79- works out if the background tokens are dark or light
80- adds the [theme utils](#theme-utils)
81
82Pass the result of this function into the
83[SparkProvider](/package/core#sparkprovider) if you want to override the default
84theme.