-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
262 lines (253 loc) · 7.9 KB
/
index.html
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎛️</text></svg>">
<title>Knobs</title>
<script src="knobs.min.js"></script>
<style>
body{
margin: 0;
height: 100vh;
display: grid;
place-items: center;
cursor: crosshair;
background: var(--main-bg);
font: 14px Arial;
}
.testSubject{
--width: 300;
--height: 10vh;
--bg: #45FDA9;
display: var(--hide, grid);
background: var(--bg, red);
border-radius: var(--radius, 0);
width: calc(var(--width) * 1px);
height: var(--height, 200px);
overflow: hidden;
justify-self: var(--align);
}
</style>
</head>
<body>
<a class='testSubject'></a>
<div class='testSubject'></div>
<script>
var settings = {
theme: {
styles: `
.custom-actions{ margin: 5px 0; }
.custom-actions button{ padding: 0 1em; font-size: 30px; }
`,
//'base-color': '#FF000022'
// flow: 'compact',
// position: 'bottom left', // default
// RTL: true
// mode: 'light'
},
// live: false, // should update immediately (default true)
// standalone: true,
visible: 1, // 0 - starts as hidden, 1 - starts as visible, 2 - always visible
persist: 0, // persist changes using the browser's localstorage. use a string to be able to flush the cache
knobsToggle: true,
CSSVarTarget: document.querySelectorAll('.testSubject'),
callbacks: {
render(){
console.log("knobs 1 ready")
}
},
knobs: [
{
label: 'Number',
labelTitle: 'An ordinary input element',
type: 'number',
min: 0,
max: 10,
// size: 10,
placeholder: 'Type a number between 1 - 10'
},
{
cssVar: ['width', '-px'],
label: 'Width',
type: 'range',
// value: 200,
min: 0,
max: 500,
step: 50,
knobClass: 'width-knob'
// onChange: console.log
},
{
isToggled: false,
cssVar: ['height', 'vh'],
label: 'Height',
type: 'range',
// value: 20,
min: 0,
max: 50,
// onChange: console.log
},
{
isToggled: false,
cssVar: ['width', '-px'],
label: 'Width preset',
type: 'select',
options: [20, 150, [200, '200 nice pixels'], 500],
value: 150,
defaultValue: 150
},
{
cssVar: ['align'],
label: 'Align boxes',
type: 'radio',
name: 'align-radio-group',
options: [
{ value:'left', hidden:true, label: '<svg viewBox="0 0 28 28"><path d="M28 21v2c0 0.547-0.453 1-1 1h-26c-0.547 0-1-0.453-1-1v-2c0-0.547 0.453-1 1-1h26c0.547 0 1 0.453 1 1zM22 15v2c0 0.547-0.453 1-1 1h-20c-0.547 0-1-0.453-1-1v-2c0-0.547 0.453-1 1-1h20c0.547 0 1 0.453 1 1zM26 9v2c0 0.547-0.453 1-1 1h-24c-0.547 0-1-0.453-1-1v-2c0-0.547 0.453-1 1-1h24c0.547 0 1 0.453 1 1zM20 3v2c0 0.547-0.453 1-1 1h-18c-0.547 0-1-0.453-1-1v-2c0-0.547 0.453-1 1-1h18c0.547 0 1 0.453 1 1z"></path></svg>' },
{ value: 'center', label:'Center' },
{ value:'right', hidden:true, label:'<svg viewBox="0 0 28 28"><path d="M28 21v2c0 0.547-0.453 1-1 1h-26c-0.547 0-1-0.453-1-1v-2c0-0.547 0.453-1 1-1h26c0.547 0 1 0.453 1 1zM28 15v2c0 0.547-0.453 1-1 1h-20c-0.547 0-1-0.453-1-1v-2c0-0.547 0.453-1 1-1h20c0.547 0 1 0.453 1 1zM28 9v2c0 0.547-0.453 1-1 1h-24c-0.547 0-1-0.453-1-1v-2c0-0.547 0.453-1 1-1h24c0.547 0 1 0.453 1 1zM28 3v2c0 0.547-0.453 1-1 1h-18c-0.547 0-1-0.453-1-1v-2c0-0.547 0.453-1 1-1h18c0.547 0 1 0.453 1 1z"></path></svg>' }
],
value: 'center',
defaultValue: 'left'
},
"",
{
cssVar: ['radius', '%'],
label: 'Radius of the big square here',
type: 'range',
value: 0,
min: 0,
max: 50,
// onChange: console.log
},
{
cssVar: ['bg'], // alias for the CSS variable
label: 'Box color',
type: 'color',
swatches: ['red', 'gold'],
// value: '#45FDA9',
onChange: (e, knobData, hsla) => console.log(e, knobData, hsla, knobData.value )
},
{
cssVar: ['main-bg', null, document.body], // [alias for the CSS variable, units, applies on element]
cssVarsHSLA: true,
label: 'Page background',
type: 'color',
defaultFormat: 'hsla',
// onChange: console.log
},
{
cssVar: ['hide'], // alias for the CSS variable
label: 'Hide boxes',
type: 'checkbox',
// checked: true,
value: 'none',
// onChange: console.log
},
]
}
var knobs1 = new Knobs(settings)
// setTimeout(knobs1.toggle.bind(knobs1), 1000)
/*
var knobs3 = new Knobs({
live: false,
CSSVarTarget:[...settings.CSSVarTarget].slice(0,1),
knobs:["Only Title",...settings.knobs.slice(0,2)],
visible: 2,
theme: {
position: 'bottom right'
},
})
var knobs2 = new Knobs({
...settings,
live: false,
CSSVarTarget:[...settings.CSSVarTarget].slice(0,1),
knobs:["Only Title",...settings.knobs.slice(0,2), {type:'color', label:'color'}],
theme:{
position: 'top left',
background:'midnightblue'
}
})
*/
knobs1.knobs = [...knobs1.knobs, ...[
["Knobs Self Parameters", 1],
{
label: 'Compact View',
type: 'checkbox',
value: 'none',
checked: knobs1.settings.theme.flow == 'compact',
onChange: (e, knobData) => {
if(knobs1){
knobs1.DOM.scope[`${(knobData.checked ? "set" : "remove")}Attribute`]("data-flow", "compact")
setTimeout(()=> {
knobs1.calculateGroupsHeights()
knobs1.toggle(knobs1.state.visible)
}, 300)
}
}
},
{
cssVar: ['knobs-gap', 'px'],
label: 'Space between knobs',
type: 'range',
value: 3,
min: 0,
max: 10,
step: 1,
onChange: (e, knobData) => {
console.log(knobs1, knobs1.DOM.scope)
if(knobs1){
knobs1.DOM.scope.style.setProperty(`--knobs-gap`, `${knobData.value}px`)
knobs1.calculateGroupsHeights()
knobs1.toggle(knobs1.state.visible)
}
}
},
{
cssVar: ['background', null, knobs1.DOM.scope],
label: 'Knobs Background',
type: 'color',
},
{
cssVar: ['primaryColor', null, knobs1.DOM.scope],
label: 'Slider Color',
type: 'color',
},
{
cssVar: ['textColor', null, knobs1.DOM.scope],
label: 'Text Color',
type: 'color',
},
{
label: 'Custom HTML with label',
render: `
<button type='button' class='specialBtn1'>1</button>
<button type='button' class='specialBtn2'>2</button>
`,
script(knobs, name){
knobs.getKnobElm(name).addEventListener("click", e => {
if( e.target.tagName == 'BUTTON' )
alert(e.target.textContent)
})
},
},
{
render: `
<button type='button' class='specialBtn3'>😎</button>
`,
script(knobs){
const elm = knobs.DOM.scope.querySelector('.specialBtn3')
elm.addEventListener("click", () => alert('😎'))
},
knobClass: 'custom-actions'
},
]]
/*
setTimeout(()=>{
knobs2.knobs = [...settings.knobs]
knobs2.render()
}, 3000)
*/
</script>
</body>
</html>