@spark-ui/tailwind-plugins 2.1.2 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.2.0](https://github.com/adevinta/spark/compare/@spark-ui/tailwind-plugins@2.1.3...@spark-ui/tailwind-plugins@2.2.0) (2023-03-21)
7
+
8
+ ### Features
9
+
10
+ - **tailwind-plugins:** consolidate tw plugin calls and auto-apply options ([c203355](https://github.com/adevinta/spark/commit/c2033552976cc611172de2a14f6927be76522e41))
11
+
12
+ ## [2.1.3](https://github.com/adevinta/spark/compare/@spark-ui/tailwind-plugins@2.1.2...@spark-ui/tailwind-plugins@2.1.3) (2023-03-21)
13
+
14
+ **Note:** Version bump only for package @spark-ui/tailwind-plugins
15
+
6
16
  ## [2.1.2](https://github.com/adevinta/spark/compare/@spark-ui/tailwind-plugins@2.1.1...@spark-ui/tailwind-plugins@2.1.2) (2023-03-20)
7
17
 
8
18
  ### Bug Fixes
@@ -43,11 +43,9 @@ module.exports = plugin.withOptions(
43
43
  */
44
44
  options =>
45
45
  ({ addUtilities, addVariant, matchUtilities, theme }) => {
46
- const opts = options || {
47
- variantPrefix: 'sp-anime',
48
- }
46
+ const opts = options || {}
49
47
 
50
- const { variantPrefix } = opts
48
+ const { variantPrefix = 'sp-anime' } = opts
51
49
 
52
50
  matchUtilities(
53
51
  {
package/index.js CHANGED
@@ -2,9 +2,32 @@
2
2
  const animations = require('./animations')
3
3
  const sizings = require('./sizings')
4
4
  const sparkTheme = require('./spark-theme')
5
+ const tailwindcssRadix = require('tailwindcss-radix')
6
+
7
+ /**
8
+ * @typedef {Object} Options
9
+ * @property {Object} options.themes - An object containing your themes where each key corresponds to a data-theme attribute value.
10
+ * @property {number} htmlFontSize The base font size of your app.
11
+ */
12
+
13
+ /**
14
+ * @param {Object} options The options for the plugin.
15
+ * @param {Object} [options.themes={}] An object containing your themes where each key corresponds to a data-theme attribute value.
16
+ * @param {string} [options.htmlFontSize=16] The base font size to use to properly compute rem values.
17
+ * @returns {Function} The PostCSS plugin function.
18
+ */
19
+ const sparkConfig = ({ htmlFontSize, themes }) => {
20
+ return [
21
+ sparkTheme({ htmlFontSize, themes }),
22
+ sizings({ htmlFontSize }),
23
+ animations(),
24
+ tailwindcssRadix({ variantPrefix: 'spark' }),
25
+ ]
26
+ }
5
27
 
6
28
  module.exports = {
7
29
  animations,
8
30
  sizings,
9
31
  sparkTheme,
32
+ sparkConfig,
10
33
  }
package/index.stories.mdx CHANGED
@@ -8,6 +8,7 @@ import { Alert } from '@docs/helpers/Alert'
8
8
 
9
9
  Below is a list of our Tailwind plugins:
10
10
 
11
+ - [spark config](?path=/docs/utils-tailwind-plugins-spark-config--docs)
11
12
  - [spark theme](?path=/docs/utils-tailwind-plugins-spark-theme--docs)
12
13
  - [animations](?path=/docs/utils-tailwind-plugins-animations--docs)
13
14
  - [sizings](?path=/docs/utils-tailwind-plugins-sizings--docs)
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@spark-ui/tailwind-plugins",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "Spark Tailwind plugins",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "main": "index.js",
9
9
  "dependencies": {
10
- "@spark-ui/theme-utils": "^2.9.1"
10
+ "@spark-ui/theme-utils": "^2.9.1",
11
+ "tailwindcss-radix": "^2.8.0"
11
12
  },
12
13
  "peerDependencies": {
13
14
  "tailwindcss": "^3.2.7"
@@ -17,5 +18,5 @@
17
18
  "url": "git@github.com:adevinta/spark.git",
18
19
  "directory": "packages/utils/tailwind-plugins"
19
20
  },
20
- "gitHead": "6efd4ae4a8f830e228ba06081f8fd2a242e0f86a"
21
+ "gitHead": "5807dd41683a7e1196bc24311e7d7afcb43e2b47"
21
22
  }
package/sizings/index.js CHANGED
@@ -46,11 +46,9 @@ module.exports = plugin.withOptions(
46
46
  */
47
47
  options =>
48
48
  ({ addBase }) => {
49
- const opts = options || {
50
- htmlFontSize: 16,
51
- }
49
+ const opts = options || {}
52
50
 
53
- const { htmlFontSize } = opts
51
+ const { htmlFontSize = 16 } = opts
54
52
 
55
53
  addBase({
56
54
  ':root': getCSSVariableDeclarations(htmlFontSize),
@@ -0,0 +1,136 @@
1
+ import { Meta } from '@storybook/blocks'
2
+ import { StoryHeading } from '@docs/helpers/StoryHeading'
3
+ import { Alert } from '@docs/helpers/Alert'
4
+
5
+ <Meta title="utils/Tailwind plugins/spark config" />
6
+
7
+ # Tailwind spark config plugin
8
+
9
+ ## Installation
10
+
11
+ To use our Tailwind spark theme plugin, simply install the `@spark-ui/tailwind-plugins` package and add the spark theme plugin to your `tailwind.config.js` file
12
+
13
+ ```bash
14
+ $ npm i @spark-ui/tailwind-plugins
15
+ ```
16
+
17
+ ```js
18
+ // tailwind.config.js
19
+
20
+ const sparkPlugins = require('@spark-ui/tailwind-plugins')
21
+
22
+ module.exports = {
23
+ ...,
24
+ plugins: [
25
+ ...sparkPlugins.sparkConfig({
26
+ htmlFontSize: 16 // The base font size for your application (default: 16),
27
+ themes: {
28
+ default: yourDefaultTheme,
29
+ dark: yourDarkTheme,
30
+ foo: someOtherTheme,
31
+ ...rest
32
+ } //
33
+ })],
34
+ }
35
+
36
+ ```
37
+
38
+ <StoryHeading label="Usage" as="h2" />
39
+
40
+ The plugin streamlines the setup process by wrapping the call to all our other plugins (plus some external ones) with the appropriate options applied.
41
+
42
+ This approach eliminates the need for manually calling each of our plugins. Here's a comparison:
43
+
44
+ **without the plugin:**
45
+
46
+ ```js
47
+ const sparkPlugins = require('@spark-ui/tailwind-plugins')
48
+
49
+ /** @type {import('tailwindcss').Config} */
50
+ module.exports = {
51
+ content: ['./packages/**/*.{js,ts,jsx,tsx}', './documentation/**/*.{js,ts,jsx,tsx,mdx}'],
52
+ plugins: [
53
+ sparkPlugins.sparkTheme({
54
+ htmlFontSize: 10,
55
+ themes: {
56
+ default: themeUtils.defaultTheme,
57
+ dark: themeUtils.defaultThemeDark,
58
+ },
59
+ }),
60
+ sparkPlugins.sizings({ htmlFontSize: 10 }),
61
+ sparkPlugins.animations(),
62
+ ...
63
+ ],
64
+ }
65
+ ```
66
+
67
+ **with the plugin:**
68
+
69
+ ```js
70
+ const sparkPlugins = require('@spark-ui/tailwind-plugins')
71
+
72
+ /** @type {import('tailwindcss').Config} */
73
+ module.exports = {
74
+ content: ['./packages/**/*.{js,ts,jsx,tsx}', './documentation/**/*.{js,ts,jsx,tsx,mdx}'],
75
+ plugins: [
76
+ ...sparkPlugins.sparkConfig({
77
+ htmlFontSize: 10,
78
+ themes: {
79
+ default: themeUtils.defaultTheme,
80
+ dark: themeUtils.defaultThemeDark,
81
+ },
82
+ }),
83
+ ],
84
+ }
85
+ ```
86
+
87
+ For more details about our other plugins, please refer to the [**Tailwind plugins documentation**](?path=/docs/utils-tailwind-plugins--docs).
88
+
89
+ <StoryHeading label="Configuration" as="h2" />
90
+
91
+ This plugin can be customized by providing a configuration object with two fields, `themes` and `htmlFontSize`.
92
+
93
+ **themes**:
94
+
95
+ An object containing your themes. Each key in the object will be extracted to a `[data-theme]` attribute, and the values will be converted to CSS custom properties inside the `css` file generated by Tailwing. **Note that this object requires a key with a value of default**, which specifies the default theme for your project.
96
+
97
+ For example, if your `themes` object looks like this:
98
+
99
+ ```js
100
+
101
+ sparkPlugins.sparkTheme({
102
+ themes: {
103
+ default: yourDefaultTheme,
104
+ alternative: someAlternativeTheme,
105
+ },
106
+ }),
107
+ ```
108
+
109
+ Tailwind will generate the following CSS:
110
+
111
+ ```css
112
+ :root {
113
+ /* ...tokens from yourDefaultTheme */
114
+ }
115
+
116
+ [data-theme='alternative'] {
117
+ /* ...tokens from someAlternativeTheme */
118
+ }
119
+ ```
120
+
121
+ You can populate the `themes` object with as many themes as desired, with the only requirement being that they conform to our `Theme` interface. The Theme interface can be accessed through the [**@spark-ui/theme-utils**](?path=/docs/utils-theme--docs#theme) package.
122
+
123
+ **htmlFontSize (optional)**:
124
+
125
+ Spark uses a base font size of **16 pixels** as a standard value for calculating the sizes of all other font-related properties defined in the theme. For example, our `spacing.lg` value is defined as **1rem**, which is equal to 16 pixels (based on the default base font size of 16 pixels).
126
+
127
+ However, if your application uses a different base font size, such as **10 pixels** for example, this can cause issues with the sizing of elements in the application. To account for this, you can set the `htmlFontSize` to the appropriate value for your application's base font size. This will adjust the `rem` based values in Spark to be relative to the new base font size.
128
+
129
+ This will ensure that the `rem`-based values are accurately calculated according to your application's HTML font size.
130
+
131
+ <Alert>
132
+ To better understand what happens when you adjust `htmlFontSize`, it's useful to know that we use CSS custom properties to define the values of our design tokens, such as `spacing.lg`.
133
+
134
+ By default, the value for this token is expressed as `--spacing-lg: 1rem;`. However, when you define a `htmlFontSize` of 10, for example, this value will be updated to `--spacing-lg: 1.6rem;`
135
+
136
+ </Alert>