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
Copy file name to clipboardExpand all lines: guides/create-a-tailwind-theme.md
+32-16
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ Let's explore how we can create a Tailwind theme — with configurable options
46
46
47
47
## Creating a configurable FormKit theme
48
48
49
-
By following the instructions below we will create a theme like the ones available at [https://themes.formkit.com](https://themes.formkit.com). This includes support for variable configuration options if you as a theme author want to provide them.
49
+
By following the instructions below we will create a theme like the ones available at [https://themes.formkit.com](https://themes.formkit.com). This includes support for user-configurable variables if you choose to provide them.
Better yet, once your theme is complete — if you provided styling for every available FormKit input — you can submit your theme to be included on [https://themes.formkit.com](https://themes.formkit.com) by [opening a PR](https://github.com/formkit/themes.formkit.com/pulls) against the site repo. Once approved it will become available for anyone else to use in their project via the CLI or web UI.
60
+
Once your theme is complete you can submit your theme to be included on [https://themes.formkit.com](https://themes.formkit.com) by [opening a PR](https://github.com/formkit/themes.formkit.com/pulls) against the site repo. Once approved it will become available for anyone else to use in their project via the CLI or web UI.
61
61
62
62
### Initialize a copy of the starter theme
63
63
64
-
FormKit provides a starter theme — which comes with structural styles and plentiful comments — that is intended to help new authors get started quickly creating their own FormKit themes. To get started, run the following command in your terminal:
64
+
FormKit provides a starter theme — which comes with structural styles and plentiful comments — that is intended to help new authors cerate their own themes.
65
+
66
+
To get started, run the following command in your terminal:
65
67
66
68
```bash
67
69
npx formkit create-theme
68
70
```
69
71
70
-
This will download a copy of the starter theme in the directory where you run the command. The starter theme is a fully functional Vite application that includes a "Kitchen Sink" to help you see how your theme applies to every available input in every available input state as you work.
72
+
This will download a clean copy of the starter theme for you to work off of. The starter theme is a fully functional Vite application that includes a "Kitchen Sink" to help you see how your classes affect every available FormKit input.
73
+
74
+
Next, you will need to log in at [https://pro.formkit.com](https://pro.formkit.com) and create a new (free) development key for FormKit Pro. This key will allow you to render the FormKit Pro elements that are included in the Kitchen Sink.
75
+
76
+
Add your FormKit Pro key to a `.env` file in the root of your project
77
+
78
+
```
79
+
FORMKIT_PRO_KEY=fk-**********
80
+
```
71
81
72
-
To begin work on your theme run:
82
+
Once you've added your pro key, run the following commands to begin work on your theme:
73
83
74
84
```bash
75
85
# or npm or yarn
@@ -93,7 +103,7 @@ The remaining files in the starter theme can be ignored (but not removed) as the
93
103
94
104
### Working with variables
95
105
96
-
Variables are a powerful way to share values across your theme and to optionally allow theme users to customize your theme to their liking. Variables are used in your inputs' class lists via the following syntax:
106
+
Variables are a powerful way to re-use values across your theme and to allow theme users to customize your theme to their liking. Variables are used in your inputs' class lists via the following syntax:
97
107
98
108
```js
99
109
// global.ts
@@ -116,7 +126,13 @@ The following variables are defined for convenience in the starter theme but do
116
126
-`colorTemperatureStrengthDark`
117
127
-`inputMaxWidth`
118
128
119
-
You can create your own variables in this fashion by providing a new key/value pair in the variables object:
129
+
The starter theme also ships with the following variables that expose UI controls for theme users:
130
+
131
+
-`radius`,
132
+
-`spacing`,
133
+
-`scale`
134
+
135
+
You can create your own basic non-user-configurable variables by providing a new key/value pair in the variables object:
120
136
121
137
```js
122
138
exportdefaultcreateTheme({
@@ -191,9 +207,9 @@ To do this we provide an `editor` value for our variable. The `editor` determine
191
207
-`spacing`: A slider with a range of values with depictions of tighter spacing at the beginning and wider spacing at the end. By default includes a scale from `0` to `96`.
192
208
-`select`: A standard HTML select list that can contain any number of values. Theme authors must provided their own scale.
193
209
194
-
You can see an example of each of these editor values by looking at the `Regenesis` theme [here](https://themes.formkit.com/editor?theme=regenesis).
210
+
You can see an example of each of these editor values by viewing the editor UI for the `Regenesis` theme [here](https://themes.formkit.com/editor?theme=regenesis).
195
211
196
-
We can update our `spacing` variable to use an appropriate editor.
212
+
We can update our `spacing` variable to use an appropriate editor:
197
213
198
214
```js
199
215
spacing: {
@@ -202,7 +218,7 @@ spacing: {
202
218
}
203
219
```
204
220
205
-
Now when we run our theme locally we will see a new control in the theme editor for our `spacing` variable with a slider that allows us to go from `0` to `96` as we step through the default Tailwind scale.
221
+
Now we will see a new control in the theme editor for our `spacing` variable with a slider that allows us to go from `0` to `96` as we step through the default Tailwind scale.
206
222
207
223
::Callout
208
224
---
@@ -214,7 +230,7 @@ When you expose a variable to a theme user they are changing the base value when
214
230
215
231
### Setting min and max for user-controlled variables
216
232
217
-
In most cases it makes sense to constrain the available scale for a user defined variable. Allowing our users to adjust `spacing` is great, but we probably don't want them to be able to crank the value all the way up to `96` or all the way down to `0`. We can constrain the range of the scale that is available to a user by using the `min` and `max` properties on our variable.
233
+
In most cases it makes sense to constrain the available scale for a user-configurable variable. Allowing our users to adjust `spacing` is great, but we probably don't want them to be able to crank the value all the way up to `96` or all the way down to `0`. We can constrain the range of the scale that is available to a user by using the `min` and `max` properties on our variable.
218
234
219
235
```js
220
236
spacing: {
@@ -229,7 +245,7 @@ This means that our `spacing` variable will now only allow values `1`, `1.5`, `2
229
245
230
246
### Creating one-off min and max constraints
231
247
232
-
Sometimes as a theme author you need to clamp or expand available values beyond what is defined in a variable's default scale. You can do this by passing additional `min` and `max` arguments to a particular instance of a variable in a class list.
248
+
Sometimes as a theme author you need to clamp or expand available values beyond what is defined in a variable's default min and max definition. You can do this by passing additional `min` and `max` arguments to inline instances of a variable.
233
249
234
250
The provided values for `min` and `max`_must_ be values or the variables associated scale — whether that is a default scale for an editor or a custom scale defined by the theme author.
235
251
@@ -254,14 +270,14 @@ export default {
254
270
255
271
### Overriding default editor scales
256
272
257
-
Some `editor` types such as `scale` or `color` come with default scales. However, we can still include a custom `scale` property of our own and override which options are available in the UI.
273
+
Some `editor` types such as `scale` or `color` come with default scales. However, we can override the defaults by providing a custom `scale` property.
258
274
259
275
```js
260
276
accentColor: {
261
277
editor:"color",
262
278
value:"blue",
263
279
// excludes all "gray" colors
264
-
//included in the default scale
280
+
//from the default scale
265
281
scale: [
266
282
"red",
267
283
"orange",
@@ -309,10 +325,10 @@ scale: {
309
325
},
310
326
```
311
327
312
-
## Publishing your theme
313
-
314
328
There are many more comments in the `@formkit/theme-starter` theme itself to help you along your way as you work.
315
329
330
+
## Publishing your theme
331
+
316
332
When you're done creating your theme you can use the included publishing script to build and publish your theme to npm.
317
333
318
334
First, ensure that you have modified the contents of your theme's `meta` key and `package.json` file to accurate reflect your theme's name, description, version, and author information.
0 commit comments