@spark-ui/tailwind-plugins 1.1.2 → 2.0.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,17 @@
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.0.0](https://github.com/adevinta/spark/compare/@spark-ui/tailwind-plugins@1.1.2...@spark-ui/tailwind-plugins@2.0.0) (2023-03-15)
7
+
8
+ ### Features
9
+
10
+ - **tailwind-plugins:** add sizings plugin ([25f76ac](https://github.com/adevinta/spark/commit/25f76ac8ccdece9db718e80eb7fd54a951b4fc22)), closes [#401](https://github.com/adevinta/spark/issues/401)
11
+ - use new Tailwind sizings plugin ([4cbb16a](https://github.com/adevinta/spark/commit/4cbb16a535ffc4c473c729337278dce0cfab3f51)), closes [#401](https://github.com/adevinta/spark/issues/401)
12
+
13
+ ### BREAKING CHANGES
14
+
15
+ - **tailwind-plugins:** Add sizings plugin
16
+
6
17
  ## [1.1.2](https://github.com/adevinta/spark/compare/@spark-ui/tailwind-plugins@1.1.1...@spark-ui/tailwind-plugins@1.1.2) (2023-03-13)
7
18
 
8
19
  **Note:** Version bump only for package @spark-ui/tailwind-plugins
package/README.md ADDED
@@ -0,0 +1 @@
1
+ The documentation for this package is located within our Storybook at https://sparkui.vercel.app/?path=/docs/utils-tailwind-plugins--docs.
@@ -6,7 +6,9 @@ import { Alert } from '@docs/helpers/Alert'
6
6
 
7
7
  # Tailwind animation plugin
8
8
 
9
- To use our Tailwind animation plugins, simply install the `@spark-ui/tailwind-plugins` package and add the animation plugin to your `tailwind.config.js` file
9
+ ## Installation
10
+
11
+ To use our Tailwind animation plugin, simply install the `@spark-ui/tailwind-plugins` package and add the animation plugin to your `tailwind.config.js` file
10
12
 
11
13
  ```bash
12
14
  $ npm i @spark-ui/tailwind-plugins
@@ -19,11 +21,13 @@ const sparkPlugins = require('@spark-ui/tailwind-plugins')
19
21
 
20
22
  module.exports = {
21
23
  ...,
22
- plugins: [sparkPlugins.animation()],
24
+ plugins: [sparkPlugins.animations()],
23
25
  }
24
26
 
25
27
  ```
26
28
 
29
+ ## Usage
30
+
27
31
  This plugin provides the following **animation-related** declaration properties that are missing by default in **Tailwind**:
28
32
 
29
33
  - **animation-fill-mode**: `sp-anime-fill-{value}` (where `value` can be `forwards`, `backwards`, or `none`)
@@ -43,7 +47,7 @@ This plugin also includes four animation keyframes:
43
47
  - **animate-slide-bottom**: `animate-slide-bottom`
44
48
  - **animate-slide-left**: `animate-slide-left`
45
49
 
46
- <StoryHeading label="plugin options" as="h3" />
50
+ <StoryHeading label="Configuration" as="h3" />
47
51
 
48
52
  You can customize the **CSS class prefix** using the `prefixVariant` option.
49
53
 
@@ -56,7 +60,7 @@ const sparkPlugins = require('@spark-ui/tailwind-plugins')
56
60
 
57
61
  module.exports = {
58
62
  ...,
59
- plugins: [sparkPlugins.animation({ prefixVariant: 'bar' })],
63
+ plugins: [sparkPlugins.animations({ prefixVariant: 'bar' })],
60
64
  }
61
65
 
62
66
  ```
package/index.js CHANGED
@@ -1,6 +1,8 @@
1
- /* eslint-disable-next-line @typescript-eslint/no-var-requires */
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
2
  const animations = require('./animations')
3
+ const sizings = require('./sizings')
3
4
 
4
5
  module.exports = {
5
6
  animations,
7
+ sizings,
6
8
  }
@@ -0,0 +1,12 @@
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" />
6
+
7
+ # Tailwind plugins
8
+
9
+ Below is a list of our Tailwind plugins:
10
+
11
+ - [animations](?path=/docs/utils-tailwind-plugins-animations--docs)
12
+ - [sizings](?path=/docs/utils-tailwind-plugins-sizings--docs)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-ui/tailwind-plugins",
3
- "version": "1.1.2",
3
+ "version": "2.0.0",
4
4
  "description": "Spark Tailwind plugins",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,5 +14,5 @@
14
14
  "url": "git@github.com:adevinta/spark.git",
15
15
  "directory": "packages/utils/tailwind-plugins"
16
16
  },
17
- "gitHead": "a1686f8fd79eee57d1515c6926d84c8e7c7f90a2"
17
+ "gitHead": "843a4c9ef31a1f346e4052685ccddceb494fc7bd"
18
18
  }
@@ -0,0 +1,70 @@
1
+ /* eslint-disable-next-line @typescript-eslint/no-var-requires */
2
+ const plugin = require('tailwindcss/plugin')
3
+
4
+ const sizingRange = [
5
+ 0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 48, 56, 64, 80, 96, 112, 128, 144,
6
+ 160, 176, 192, 208, 224, 240, 256, 288, 320, 384, 400, 416, 432, 448, 464, 480, 512, 544, 576,
7
+ 608, 640, 672, 704, 736, 768, 800, 832, 864,
8
+ ]
9
+
10
+ function pxToRem(pxValue, htmlFontSize) {
11
+ const remValue = pxValue / htmlFontSize
12
+
13
+ return `${remValue}rem`
14
+ }
15
+
16
+ function getCSSVariableDeclarations(htmlFontSize) {
17
+ const CSSVariableDeclarations = sizingRange.reduce((acc, size) => {
18
+ acc[`--sz-${size}`] = pxToRem(size, htmlFontSize)
19
+
20
+ return acc
21
+ }, {})
22
+
23
+ return CSSVariableDeclarations
24
+ }
25
+
26
+ function getCSSVariableReferences() {
27
+ const CSSVariableReferences = sizingRange.reduce((acc, size) => {
28
+ acc[`sz-${size}`] = `var(--sz-${size})`
29
+
30
+ return acc
31
+ }, {})
32
+
33
+ return CSSVariableReferences
34
+ }
35
+
36
+ module.exports = plugin.withOptions(
37
+ /**
38
+ * @typedef {Object} Options
39
+ * @property {number} htmlFontSize The base font size of your app.
40
+ */
41
+
42
+ /**
43
+ * @param {Object} options The options for the plugin.
44
+ * @param {string} [options.htmlFontSize=16] The base font size to use to properly compute rem values.
45
+ * @returns {Function} The PostCSS plugin function.
46
+ */
47
+ options =>
48
+ ({ addBase }) => {
49
+ const opts = options || {
50
+ htmlFontSize: 16,
51
+ }
52
+
53
+ const { htmlFontSize } = opts
54
+
55
+ addBase({
56
+ ':root': getCSSVariableDeclarations(htmlFontSize),
57
+ })
58
+ },
59
+ () => ({
60
+ theme: {
61
+ extend: {
62
+ width: getCSSVariableReferences(),
63
+ maxWidth: getCSSVariableReferences(),
64
+ height: getCSSVariableReferences(),
65
+ maxHeight: getCSSVariableReferences(),
66
+ translate: getCSSVariableReferences(),
67
+ },
68
+ },
69
+ })
70
+ )
@@ -0,0 +1,74 @@
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/sizings" />
6
+
7
+ # Tailwind sizing plugin
8
+
9
+ ## Installation
10
+
11
+ To use our Tailwind sizing plugin, simply install the `@spark-ui/tailwind-plugins` package and add the animation 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: [sparkPlugins.sizings({ htmlFontSize: 16 // The base font size for your application (default: 16)
25
+ })],
26
+ }
27
+
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ This plugin predefines a sizing range with the following pixel values:
33
+
34
+ ```ts
35
+ const sizingRange = [
36
+ 0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 48, 56, 64, 80, 96, 112, 128, 144,
37
+ 160, 176, 192, 208, 224, 240, 256, 288, 320, 384, 400, 416, 432, 448, 464, 480, 512, 544, 576,
38
+ 608, 640, 672, 704, 736, 768, 800, 832, 864,
39
+ ]
40
+ ```
41
+
42
+ These values are converted into rem units based on the specified **HTML font size** (see [configuration](#configuration)).
43
+
44
+ The plugin generates CSS variables for each size value, which can then be used for `width`, `height`, `max-width`, `max-height`, and `translate` properties.
45
+
46
+ <StoryHeading label="Example" as="h3" />
47
+
48
+ To set the `width` of an element using the sizing plugin, use the `w-sz-{size}` class, where`{size}` is the desired pixel value from the predefined range:
49
+
50
+ ```tsx
51
+ <div className="w-sz-10">...</div>
52
+ ```
53
+
54
+ This will set the width of the element to **10px** (0.625rem, if `htmlFontSize` is 16) using the custom sizing scale provided by the plugin.
55
+
56
+ <StoryHeading label="Configuration" as="h3" />
57
+
58
+ You can customize the **base html font size** using the `htmlFontSize` option.
59
+
60
+ By default, the base will be `16`, but you can change it like so:
61
+
62
+ ```js
63
+ // tailwind.config.js
64
+
65
+ const sparkPlugins = require('@spark-ui/tailwind-plugins')
66
+
67
+ module.exports = {
68
+ ...,
69
+ plugins: [sparkPlugins.sizings({ htmlFontSize: 10 })],
70
+ }
71
+
72
+ ```
73
+
74
+ This will ensure that the `rem`-based values are accurately calculated according to your application's HTML font size.
File without changes