@symbo.ls/range 1.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +131 -0
- package/package.json +13 -0
package/index.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isFunction } from '@domql/utils'
|
|
4
|
+
import { opacify } from '@symbo.ls/scratch'
|
|
5
|
+
import { SquareButton } from '@symbo.ls/button'
|
|
6
|
+
|
|
7
|
+
const props = {
|
|
8
|
+
appearance: 'none',
|
|
9
|
+
width: '100%',
|
|
10
|
+
height: '2px',
|
|
11
|
+
outline: 'none',
|
|
12
|
+
flex: 1,
|
|
13
|
+
|
|
14
|
+
style: {
|
|
15
|
+
appearance: 'none'
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
'::-webkit-slider-thumb': {
|
|
19
|
+
boxSizing: 'content-box',
|
|
20
|
+
width: '8px',
|
|
21
|
+
height: '8px',
|
|
22
|
+
borderWidth: '2px',
|
|
23
|
+
borderStyle: 'solid',
|
|
24
|
+
borderRadius: '100%',
|
|
25
|
+
opacity: '.8',
|
|
26
|
+
|
|
27
|
+
style: {
|
|
28
|
+
appearance: 'none'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
'::-webkit-slider-runnable-track': {
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
'@dark': {
|
|
36
|
+
background: 'white 0.2',
|
|
37
|
+
|
|
38
|
+
'::-webkit-slider-thumb': {
|
|
39
|
+
background: '#232526',
|
|
40
|
+
borderColor: opacify('#454646', 0.75)
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
':hover': {
|
|
44
|
+
'::-webkit-slider-thumb': {
|
|
45
|
+
borderColor: opacify('#fff', 0.35)
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
':focus': {
|
|
50
|
+
'::-webkit-slider-thumb': {
|
|
51
|
+
borderColor: '#3C6AC0'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
'@light': {
|
|
57
|
+
background: 'gray9',
|
|
58
|
+
|
|
59
|
+
'::-webkit-slider-thumb': {
|
|
60
|
+
background: 'white',
|
|
61
|
+
borderColor: 'gray9'
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
':hover': {
|
|
65
|
+
'::-webkit-slider-thumb': {
|
|
66
|
+
borderColor: 'gray7'
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
':focus': {
|
|
71
|
+
'::-webkit-slider-thumb': {
|
|
72
|
+
borderColor: 'blue'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const Range = {
|
|
79
|
+
props,
|
|
80
|
+
|
|
81
|
+
tag: 'input',
|
|
82
|
+
attr: { type: 'range' }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const listenProp = (el, prop, def) => {
|
|
86
|
+
const val = el.props && el.props[prop]
|
|
87
|
+
const r = (isFunction(val) ? val(el, el.state) : val !== undefined ? val : def !== undefined ? def : 50)
|
|
88
|
+
return r + ''
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const RangeWithButtons = {
|
|
92
|
+
minus: {
|
|
93
|
+
extend: SquareButton,
|
|
94
|
+
props: { theme: 'tertiary', icon: 'minus' },
|
|
95
|
+
on: {
|
|
96
|
+
click: (ev, el, s) => {
|
|
97
|
+
el.props && isFunction(el.props.onClick) && el.props.onClick(ev, el, s)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
value: {
|
|
102
|
+
style: { width: '4ch' },
|
|
103
|
+
tag: 'span',
|
|
104
|
+
text: (el, s) => {
|
|
105
|
+
const unit = listenProp(el.parent.input, 'unit', '')
|
|
106
|
+
return '' + (s.value || 50) + unit
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
input: {
|
|
110
|
+
extend: Range,
|
|
111
|
+
attr: {
|
|
112
|
+
value: (el, s) => parseFloat(s.value),
|
|
113
|
+
min: (el, s) => listenProp(el, 'min', 0),
|
|
114
|
+
max: (el, s) => listenProp(el, 'max', 100),
|
|
115
|
+
step: (el, s) => listenProp(el, 'step', 1)
|
|
116
|
+
},
|
|
117
|
+
on: {
|
|
118
|
+
input: (ev, el, s) => el.props && isFunction(el.props.onInput) && el.props.onInput(ev, el, s),
|
|
119
|
+
change: (ev, el, s) => el.props && isFunction(el.props.onChange) && el.props.onChange(ev, el, s)
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
plus: {
|
|
123
|
+
extend: SquareButton,
|
|
124
|
+
props: { theme: 'tertiary', icon: 'plus' },
|
|
125
|
+
on: {
|
|
126
|
+
click: (ev, el, s) => {
|
|
127
|
+
el.props && isFunction(el.props.onClick) && el.props.onClick(ev, el, s)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@symbo.ls/range",
|
|
3
|
+
"version": "1.2.12",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"gitHead": "f4abd30cc0ed14e927ec765232b6721e8954a658",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@domql/utils": "latest",
|
|
9
|
+
"@symbo.ls/button": "latest",
|
|
10
|
+
"@symbo.ls/scratch": "latest"
|
|
11
|
+
},
|
|
12
|
+
"source": "src/index.js"
|
|
13
|
+
}
|