|
1 | | -import { computed, toRefs } from 'composition-api' |
| 1 | +import { ref, computed, toRefs } from 'composition-api' |
2 | 2 |
|
3 | 3 | export default function useStyle (props, context, dependencies) |
4 | 4 | { |
5 | | - const { width, height, speed, offBackground, onBackground, disabledBackground, offTextColor, |
6 | | - onTextColor, disabledTextColor, fontSize, handleColor, disabledHandleColor, } = toRefs(props) |
| 5 | + const { width, height, speed, colors, fontSize } = toRefs(props) |
| 6 | + |
| 7 | + // ================ DATA ================ |
| 8 | + |
| 9 | + // no export |
| 10 | + const defaultColors = ref({ |
| 11 | + background: { |
| 12 | + on: '#41b883', |
| 13 | + off: '#d4e0e7', |
| 14 | + disabled: '#d4e0e7', |
| 15 | + }, |
| 16 | + text: { |
| 17 | + on: '#ffffff', |
| 18 | + off: '#80878c', |
| 19 | + disabled: '#80878c', |
| 20 | + }, |
| 21 | + handle: { |
| 22 | + on: '#ffffff', |
| 23 | + off: '#ffffff', |
| 24 | + disabled: '#f2faff', |
| 25 | + }, |
| 26 | + }) |
7 | 27 |
|
8 | 28 | // ============== COMPUTED ============== |
9 | 29 |
|
| 30 | + // no export |
| 31 | + const cssColors = computed(() => { |
| 32 | + let cssColors = Object.assign({}, defaultColors.value) |
| 33 | + |
| 34 | + if (colors.value.background) { |
| 35 | + cssColors.background = Object.assign({}, cssColors.background, colors.value.background) |
| 36 | + } |
| 37 | + |
| 38 | + if (colors.value.text) { |
| 39 | + cssColors.text = Object.assign({}, cssColors.text, colors.value.text) |
| 40 | + } |
| 41 | + |
| 42 | + if (colors.value.handle) { |
| 43 | + cssColors.handle = Object.assign({}, cssColors.handle, colors.value.handle) |
| 44 | + } |
| 45 | + |
| 46 | + return cssColors |
| 47 | + }) |
| 48 | + |
10 | 49 | const cssVars = computed(() => { |
11 | 50 | let cssVars = { |
12 | | - '--toggle-off-background': offBackground.value, |
13 | | - '--toggle-on-background': onBackground.value, |
14 | | - '--toggle-disabled-background': disabledBackground.value, |
15 | | - '--toggle-off-text-color': offTextColor.value, |
16 | | - '--toggle-on-text-color': onTextColor.value, |
17 | | - '--toggle-disabled-text-color': disabledTextColor.value, |
18 | | - '--toggle-handle-color': handleColor.value, |
19 | | - '--toggle-disabled-handle-color': disabledHandleColor.value, |
| 51 | + '--toggle-off-background': cssColors.value.background.off, |
| 52 | + '--toggle-on-background': cssColors.value.background.on, |
| 53 | + '--toggle-disabled-background': cssColors.value.background.disabled, |
| 54 | + '--toggle-off-text-color': cssColors.value.text.off, |
| 55 | + '--toggle-on-text-color': cssColors.value.text.on, |
| 56 | + '--toggle-disabled-text-color': cssColors.value.text.disabled, |
| 57 | + '--toggle-on-handle-color': cssColors.value.handle.on, |
| 58 | + '--toggle-off-handle-color': cssColors.value.handle.off, |
| 59 | + '--toggle-disabled-handle-color': cssColors.value.handle.disabled, |
20 | 60 | '--toggle-height': height.value + 'px', |
21 | 61 | '--toggle-width': width.value + 'px', |
22 | 62 | '--toggle-speed': (speed.value / 1000) + 's', |
|
0 commit comments