-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathspacing.js
178 lines (166 loc) · 6.11 KB
/
spacing.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
'use strict'
exports.twClasses = function twClasses(config) {
/* PADDING CLASSES */
let padding = []
config.scales.DEFAULT_SPACING_SCALE.forEach(scale => {
padding.push(
{
label: `p-${scale.name}`,
detail: `padding: ${scale.value};`,
documentation: `Set the padding on all sides of an element to ${scale.value}.`
},
{
label: `px-${scale.name}`,
detail: `padding-left: ${scale.value}; padding-right: ${scale.value};`,
documentation: `Set the horizontal padding of an element to ${scale.value}.`
},
{
label: `py-${scale.name}`,
detail: `padding-top: ${scale.value}; padding-bottom: ${scale.value};`,
documentation: `Set the vertical padding of an element to ${scale.value}.`
},
{
label: `pt-${scale.name}`,
detail: `padding-top: ${scale.value};`,
documentation: `Set the top padding of an element to ${scale.value}.`
},
{
label: `pr-${scale.name}`,
detail: `padding-right: ${scale.value};`,
documentation: `Set the right padding of an element to ${scale.value}.`
},
{
label: `pb-${scale.name}`,
detail: `padding-bottom: ${scale.value};`,
documentation: `Set the bottom padding of an element to ${scale.value}.`
},
{
label: `pl-${scale.name}`,
detail: `padding-left: ${scale.value};`,
documentation: `Set the left padding of an element to ${scale.value}.`
}
)
})
/* MARGIN CLASSES */
let margin = []
config.scales.DEFAULT_SPACING_SCALE.forEach(scale => {
margin.push(
{
label: `m-${scale.name}`,
detail: `margin: ${scale.value};`,
documentation: `Set the margin on all sides of an element to ${scale.value}.`,
allowNegation: true
},
{
label: `mx-${scale.name}`,
detail: `margin-left: ${scale.value}; margin-right: ${scale.value};`,
documentation: `Set the horizontal margin of an element to ${scale.value}.`,
allowNegation: true
},
{
label: `my-${scale.name}`,
detail: `margin-top: ${scale.value}; margin-bottom: ${scale.value};`,
documentation: `Set the vertical margin of an element to ${scale.value}.`,
allowNegation: true
},
{
label: `mt-${scale.name}`,
detail: `margin-top: ${scale.value};`,
documentation: `Set the top margin of an element to ${scale.value}.`,
allowNegation: true
},
{
label: `mr-${scale.name}`,
detail: `margin-right: ${scale.value};`,
documentation: `Set the right margin of an element to ${scale.value}.`,
allowNegation: true
},
{
label: `mb-${scale.name}`,
detail: `margin-bottom: ${scale.value};`,
documentation: `Set the bottom margin of an element to ${scale.value}.`,
allowNegation: true
},
{
label: `ml-${scale.name}`,
detail: `margin-left: ${scale.value};`,
documentation: `Set the left margin of an element to ${scale.value}.`,
allowNegation: true
}
)
})
margin.push(
{
label: 'm-auto',
detail: 'margin: auto;',
documentation: 'Set an element\'s margin automatically. Often used to center an element.'
},
{
label: 'my-auto',
detail: 'margin-top: auto; margin-bottom: auto;',
documentation: 'Let the browser determine an element\'s top and bottom margin automatically.'
},
{
label: 'mx-auto',
detail: 'margin-left: auto; margin-right: auto;',
documentation: 'Let the browser determine an element\'s left and right margin automatically.'
},
{
label: 'mt-auto',
detail: 'margin-top: auto;',
documentation: 'Let the browser determine an element\'s top margin automatically.'
},
{
label: 'mr-auto',
detail: 'margin-right: auto;',
documentation: 'Let the browser determine an element\'s right margin automatically.'
},
{
label: 'mb-auto',
detail: 'margin-bottom: auto;',
documentation: 'Let the browser determine an element\'s bottom margin automatically.'
},
{
label: 'ml-auto',
detail: 'margin-left: auto;',
documentation: 'Let the browser determine an element\'s left margin automatically.'
}
)
/* SPACE BETWEEN CLASSES */
let spaceBetween = []
config.scales.DEFAULT_SPACING_SCALE.forEach(scale => {
spaceBetween.push(
{
label: `space-x-${scale.name}`,
detail: `--tw-space-x-reverse: 0; margin-right: calc(${scale.value} * var(--tw-space-x-reverse)); margin-left: calc(${scale.value} * calc(1 - var(--tw-space-x-reverse)));`,
documentation: 'Set horizontal space between child elements.',
allowNegation: true
},
{
label: `space-y-${scale.name}`,
detail: `--tw-space-y-reverse: 0; margin-top: calc(${scale.value} * calc(1 - var(--tw-space-y-reverse))); margin-bottom: calc(${scale.value} * var(--tw-space-y-reverse));`,
documentation: 'Set the vertical space between child elements.',
allowNegation: true
},
)
})
spaceBetween.push(
{
label: 'space-x-reverse',
detail: '--tw-space-x-reverse: 1;',
documentation: 'If elements are in reverse order (eg: flex-row-reverse), set the horizontal space to the correct side of an element.'
},
{
label: 'space-y-reverse',
detail: '--tw-space-y-reverse: 1;',
documentation: 'If elements are in reverse order (eg: flex-col-reverse), set the vertical space to the correct side of an element.'
}
)
return {
spacing: {
padding: padding,
margin: margin,
spaceBetween: spaceBetween
}
}
}