smbls 0.8.14 → 0.8.17

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "UI Library built on Scratch and DOMQL",
4
4
  "private": false,
5
5
  "author": "symbo.ls",
6
- "version": "0.8.14",
6
+ "version": "0.8.17",
7
7
  "repository": "https://github.com/rackai/symbols",
8
8
  "main": "src/index.js",
9
9
  "files": [
package/src/Box/index.js CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  import { Shape, Position, Block, Text, Overflow, Transition, Transform, Responsive } from '..'
4
4
 
5
+ const PropsCSS = {
6
+ class: { propsCSS: ({ props }) => props && props.css }
7
+ }
8
+
5
9
  export const Box = {
6
- proto: [Shape, Position, Block, Text, Overflow, Transition, Transform, Responsive],
7
- class: {
8
- fromProps: ({ props }) => props && props.css
9
- }
10
+ proto: [Shape, Position, Block, Text, Overflow, Transition, Transform, Responsive, PropsCSS],
10
11
  }
@@ -5,7 +5,7 @@ import { Shape, Block, IconText, Direction } from '../'
5
5
  import style from './style'
6
6
 
7
7
  export const Button = {
8
- proto: [IconText],
8
+ proto: IconText,
9
9
  tag: 'button',
10
10
  style,
11
11
  props: {
@@ -1,9 +1,9 @@
1
1
  'use strict'
2
2
 
3
- import { isArray, isObject } from '@domql/utils'
3
+ import { isArray, isObject, exec } from '@domql/utils'
4
4
  import { mapSpacing, getTheme, getColor } from '@symbo.ls/scratch'
5
5
 
6
- import style, { shape, depth } from './style'
6
+ import style, { SHAPES, depth } from './style'
7
7
 
8
8
  const isBorderStyle = str =>
9
9
  ['none','hidden','dotted','dashed','solid','double','groove','ridge','inset','outset','initial'].some(v => str.includes(v))
@@ -22,8 +22,17 @@ const diffBorder = (border, key = 'border') => {
22
22
  export const Shape = {
23
23
  class: {
24
24
  default: style,
25
- shape: ({ props }) => props.shape ? shape[props.shape] : null,
26
- shapeDirection: ({ props }) => props.shape ? shape[props.shape][props.shapeDirection || 'top'] : null,
25
+ shape: (element) => {
26
+ const { props } = element
27
+ const { shape } = props
28
+ return shape ? exec(SHAPES[shape], element) : null
29
+ },
30
+ shapeDirection: ({ props }) => {
31
+ const { shape, shapeDirection } = props
32
+ if (!shape || !shapeDirection) return
33
+ const shapeDir = SHAPES[shape + 'Direction']
34
+ return shape ? shapeDir[shapeDirection || 'top'] : null
35
+ },
27
36
  shapeDirectionColor: ({ props, ...el }) => props.shapeDirection ? { '&:before': { borderColor: el.class.backgroundColor } } : null,
28
37
  depth: ({ props }) => depth[props.depth],
29
38
  round: ({ props, key, ...el }) => props.round ? (mapSpacing(props.round, 'borderRadius') || ({ borderRadius: props.round })) : null,
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { UNIT } from '@symbo.ls/scratch'
3
+ import { UNIT, getColor } from '@symbo.ls/scratch'
4
4
 
5
5
  export default {
6
6
  boxSizing: 'border-box'
@@ -15,21 +15,25 @@ export const depth = {
15
15
  42: { boxShadow: `rgba(0,0,0,.10) 0 20${UNIT.default} 42${UNIT.default}` }
16
16
  }
17
17
 
18
- export const shape = {
18
+ export const SHAPES = {
19
19
  rectangle: {},
20
20
  circle: { borderRadius: '100%' },
21
21
  bubble: {},
22
- tooltip: {
22
+
23
+ tooltip: ({ props }) => ({
23
24
  position: 'relative',
24
25
  '&:before': {
25
26
  content: '""',
26
27
  display: 'block',
27
28
  width: '0px',
28
29
  height: '0px',
29
- border: '6px solid #343434',
30
+ border: `6px solid ${getColor(props.background)}`,
30
31
  position: 'absolute',
31
32
  borderRadius: '2px'
32
- },
33
+ }
34
+ }),
35
+
36
+ tooltipDirection: {
33
37
  top: {
34
38
  '&:before': {
35
39
  top: '2px',
@@ -59,17 +63,21 @@ export const shape = {
59
63
  }
60
64
  }
61
65
  },
62
- tag: {
66
+
67
+ tag: ({ props }) => ({
63
68
  position: 'relative',
64
69
  '&:before': {
65
70
  content: '""',
66
71
  display: 'block',
67
72
  width: '0',
68
73
  height: '0',
69
- border: '16px solid #343434',
74
+ border: `16px solid ${getColor(props.background)}`,
70
75
  borderRadius: '6px',
71
76
  position: 'absolute'
72
77
  },
78
+ }),
79
+
80
+ tagDirection: {
73
81
  top: {
74
82
  '&:before': {
75
83
  bottom: '100%',
@@ -1,32 +1,35 @@
1
1
  'use strict'
2
2
 
3
3
  import style from './style'
4
+ import { set, opacify } from '@symbo.ls/scratch'
5
+ import { isFunction } from '@domql/utils'
4
6
 
5
7
  import { SquareButton, Shape } from '..'
6
- import * as Scratch from '@symbo.ls/scratch'
7
- import { isFunction } from 'domql/src/utils'
8
8
 
9
- // TODO: fix this
10
- Scratch.setValue('THEME', {
11
- background: 'white 0.2',
9
+ set({
10
+ theme: {
11
+ sliderThumb: {
12
+ background: 'white 0.2',
12
13
 
13
- '&::-webkit-slider-thumb': {
14
- background: '#232526',
15
- borderColor: Scratch.opacify('#454646', 0.75)
16
- },
14
+ '&::-webkit-slider-thumb': {
15
+ background: '#232526',
16
+ borderColor: opacify('#454646', 0.75)
17
+ },
17
18
 
18
- '&:hover': {
19
- '&::-webkit-slider-thumb': {
20
- borderColor: Scratch.opacify('#fff', 0.35)
21
- }
22
- },
19
+ '&:hover': {
20
+ '&::-webkit-slider-thumb': {
21
+ borderColor: opacify('#fff', 0.35)
22
+ }
23
+ },
23
24
 
24
- '&:focus, &:active': {
25
- '&::-webkit-slider-thumb': {
26
- borderColor: '#3C6AC0'
25
+ '&:focus, &:active': {
26
+ '&::-webkit-slider-thumb': {
27
+ borderColor: '#3C6AC0'
28
+ }
29
+ }
27
30
  }
28
31
  }
29
- }, 'sliderThumb')
32
+ })
30
33
 
31
34
  export const RangeSlider = {
32
35
  style,
@@ -39,50 +42,59 @@ export const RangeSlider = {
39
42
  attr: { type: 'range' }
40
43
  }
41
44
 
42
- const findOut = (el, s, prop, def) => {
43
- const val = el.parent.parent.props[prop]
44
- return isFunction(val) ? val(el, s) : val || def
45
+ const listenProp = (el, prop, def) => {
46
+ const val = el.props && el.props[prop]
47
+ const r = (isFunction(val) ? val() : val) || (def !== undefined ? def : 50)
48
+ // if (prop === 'value') console.log(r)
49
+ return r
45
50
  }
46
51
 
47
52
  export const Slider = {
48
- proto: [Shape],
49
-
50
- button0: {
51
- proto: [SquareButton],
52
- props: {
53
- icon: 'minus'
54
- },
53
+ minus: {
54
+ proto: SquareButton,
55
+ props: { icon: 'minus' },
55
56
  on: {
56
57
  click: (ev, el, s) => {
57
- el.parent.parent.props.minusClick(ev, el, s)
58
+ el.props && isFunction(el.props.click) && el.props.click(ev, el, s)
59
+ const input = el.parent.input
60
+ const props = input.props
61
+ const value = isFunction(props.value) ? props.value() : props.value
62
+ input.node.value = value
58
63
  }
59
64
  }
60
65
  },
61
66
  value: {
67
+ style: { width: '4ch' },
62
68
  tag: 'span',
63
- // class: { w: { minWidth: `4ch` } },
64
- text: (el, s) => `${findOut(el, s, 'value', 50)}${findOut(el, s, 'type') === 'fontSize' ? 'px' : ''}`
69
+ text: (el, s) => {
70
+ const value = listenProp(el.parent.input, 'value')
71
+ const unit = listenProp(el.parent.input, 'unit', '')
72
+ return '' + value + unit
73
+ }
65
74
  },
66
- range: {
75
+ input: {
67
76
  proto: RangeSlider,
68
77
  attr: {
69
- value: (el, s) => findOut(el, s, 'value', 50),
70
- min: (el, s) => findOut(el, s, 'min', 0),
71
- max: (el, s) => findOut(el, s, 'max', 100),
72
- step: (el, s) => findOut(el, s, 'step', 1)
78
+ value: (el, s) => listenProp(el, 'value', 50),
79
+ min: (el, s) => listenProp(el, 'min', 0),
80
+ max: (el, s) => listenProp(el, 'max', 100),
81
+ step: (el, s) => listenProp(el, 'step', 1)
73
82
  },
74
83
  on: {
75
- input: (ev, el, s) => el.parent.parent.props.input(ev, el, s)
84
+ input: (ev, el, s) => el.props && isFunction(el.props.input) && el.props.input(ev, el, s),
85
+ change: (ev, el, s) => el.props && isFunction(el.props.change) && el.props.change(ev, el, s)
76
86
  }
77
87
  },
78
- button1: {
79
- proto: [SquareButton],
80
- props: {
81
- icon: 'plus'
82
- },
88
+ plus: {
89
+ proto: SquareButton,
90
+ props: { icon: 'plus' },
83
91
  on: {
84
92
  click: (ev, el, s) => {
85
- el.parent.parent.props.plusClick(ev, el, s)
93
+ el.props && isFunction(el.props.click) && el.props.click(ev, el, s)
94
+ const input = el.parent.input
95
+ const props = input.props
96
+ const value = isFunction(props.value) ? props.value() : props.value
97
+ input.node.value = value
86
98
  }
87
99
  }
88
100
  }