-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefixedClassnames.js
62 lines (56 loc) · 1.3 KB
/
prefixedClassnames.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
exports.c = function c () {
var name = arguments[0]
var modifiers = Array.prototype.slice.call(arguments, 1)
modifiers = processModifiers(name, modifiers).concat(modifiers)
return clsx.apply(undefined, modifiers)
}
function prefix (prefix, name) {
return prefix + '-' + name
}
function processModifiers (name, modifiers) {
return modifiers.map(modifier => {
if (isArray(modifier)) return processModifiers(name, modifier)
if (typeof modifier === 'string') return prefix(name, modifier)
var res = {}
for (var key in modifier) {
res[prefix(name, key)] = modifier[key]
}
return res
})
}
function isArray (value) {
return Object.prototype.toString.call(value) === '[object Array]'
}
// clsx 1.0.3
// https://github.com/lukeed/clsx
function toVal (mix) {
var k
var y
var str = ''
if (mix) {
if (typeof mix === 'object') {
for (k in mix) {
if (mix[k] && (y = toVal(!!mix.push ? mix[k] : k))) {
str && (str += ' ')
str += y
}
}
} else if (typeof mix !== 'boolean') {
str && (str += ' ')
str += mix
}
}
return str
}
function clsx () {
var i = 0
var x
var str = ''
while (i < arguments.length) {
if (x = toVal(arguments[i++])) {
str && (str += ' ')
str += x
}
}
return str
}