Skip to content

Commit fc8d5c8

Browse files
committed
add new example
1 parent 27f8d60 commit fc8d5c8

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = (theme) => ({
2+
'.select': {
3+
DEFAULT: {
4+
backgroundColor: 'var(--colors-prefix2-primary)',
5+
},
6+
multi: {
7+
'.default-multi': {
8+
backgroundColor: 'var(--prefix2-colors-secondary)',
9+
},
10+
'.other-multi': {
11+
backgroundColor: 'var(--prefix2-colors-warning)',
12+
},
13+
},
14+
},
15+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const plugin = require('tailwindcss/plugin')
2+
const merge = require('lodash/merge')
3+
const pluginComponents = require('./components')
4+
const variablesApi = require('../../../api')
5+
// const variablesApi = require('@mertasan/tailwindcss-variables/api')
6+
7+
/**
8+
* @typedef {Object} plugin
9+
* @property {function} withOptions
10+
*/
11+
module.exports = plugin.withOptions(
12+
function(options) {
13+
return function({ addComponents, theme, options, config }) {
14+
const myVariables = {
15+
DEFAULT: {
16+
colors: {
17+
primary: 'black',
18+
secondary: 'white',
19+
warning: 'pink',
20+
},
21+
},
22+
'.admin': {
23+
colors: {
24+
primary: 'blue',
25+
secondary: 'green',
26+
warning: 'gray',
27+
},
28+
},
29+
}
30+
let pluginOptions = merge(
31+
{
32+
variablePrefix: '--prefix1',
33+
darkSelector: null, // default: .dark
34+
darkToRoot: false, // default: true ( :root.dark or .dark )
35+
},
36+
theme('myPlugin.variableOptions', {}),
37+
)
38+
39+
addComponents(variablesApi.variables(myVariables, pluginOptions))
40+
41+
myVariables.DEFAULT.colors.primary = 'yellow'
42+
addComponents(variablesApi.darkVariables(myVariables, pluginOptions, config('darkMode')))
43+
44+
// Automatically register components via API.
45+
addComponents(variablesApi.getComponents(null, theme('myPlugin.components', {})))
46+
}
47+
},
48+
function(options) {
49+
return {
50+
// darkMode: 'class', // or media
51+
theme: {
52+
myPlugin: (theme) => ({
53+
variableOptions: {
54+
variablePrefix: '--prefix2',
55+
},
56+
components: pluginComponents(theme),
57+
}),
58+
},
59+
}
60+
},
61+
)

0 commit comments

Comments
 (0)