-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
103 lines (90 loc) · 3.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const plugin = require('tailwindcss/plugin');
const getDefaults = require('./defaults');
const animations = require('./animations/index');
const defaultOptions = {
prefix: 'ham-'
}
module.exports = plugin.withOptions(function(options = {}) {
return function({ addComponents, theme, e }) {
let burgerTheme = theme('hamburgers') || {}
if (!('base' in burgerTheme)) {
burgerTheme.base = {scale: {}}
}
options = {
...defaultOptions,
...options
}
function classPrefixer(className, variant) {
if (variant !== 'base') {
variant = '-' + variant
} else {
variant = ''
}
return e(options.prefix + className + variant)
}
function generateVariant(variant) {
let classes = {
wrapper: classPrefixer('wrapper', variant),
inner: classPrefixer('inner', variant),
active: classPrefixer('active',variant),
bar: classPrefixer('bar', variant)
}
let settings = getDefaults(burgerTheme[variant])
settings.classes = classes
const hamburgers = {
[`.${classes.wrapper}`]: {
height: settings.height,
width: settings.width,
backgroundColor: settings.background,
padding: settings.padding,
border: '0 solid transparent',
color: 'inherit',
cursor: 'pointer',
display: 'inline-block',
fontSize: 'inherit',
overflow: 'visible',
textTransform: 'none',
transition: `opacity 0.2s ${settings.ease}, background 0.2s ${settings.ease}`,
// Set color and bg-color in active state
[`&.${classes.active}`]: {
backgroundColor: settings.backgroundActive,
[`span.${classes.bar}`]: {
backgroundColor: settings.colorActive
},
[`> .${classes.inner}, span.${classes.bar}`]: {
'&:nth-child(1), &:nth-child(2), &:nth-child(3)': {
'&::before, &::after': {
backgroundColor: settings.colorActive
}
}
}
},
// Center and scale the inner container
[`> .${classes.inner}`]: {
margin: 'auto',
marginTop: `-${settings.scale.barHeight/2}em`,
position: 'relative',
width: `${settings.scale.barWidth}em`,
fontSize: 'inherit'
},
// This is typically is hidden by the animation classes,
// but it provides a default an animation class isn't specified
[`span.${classes.bar}`]: {
...settings.bar,
'&:nth-child(1)': {
top: `-${settings.scale.spaceBetween}em` //
},
'&:nth-child(3)': {
top: `${settings.scale.spaceBetween}em`
}
}
},
...animations({settings, variant, classPrefixer})
}
addComponents(hamburgers)
}
Object.keys(burgerTheme).forEach(function (variant) {
generateVariant(variant)
})
}
})