From 6532445c860625acc28bd27c2c2dcb51a2c9a29a Mon Sep 17 00:00:00 2001 From: liuxinran Date: Mon, 13 Aug 2018 07:58:35 +0800 Subject: [PATCH] feat(Slider): add swatches as properties and support for black and white fix #118 fix #134 --- src/components/Slider.vue | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/components/Slider.vue b/src/components/Slider.vue index bb2f425..f0485fa 100644 --- a/src/components/Slider.vue +++ b/src/components/Slider.vue @@ -9,7 +9,7 @@
@@ -25,22 +25,30 @@ export default { name: 'Slider', mixins: [colorMixin], props: { - direction: String + swatches: { + type: Array, + default () { + return ['.80', '.65', '.50', '.35', '.20'] + } + } }, components: { hue }, computed: { activeOffset () { - if (Math.round(this.colors.hsl.s * 100) / 100 === 0.50) { - return Math.round(this.colors.hsl.l * 100) / 100 + const hasBlack = this.swatches.includes('0') + const hasWhite = this.swatches.includes('1') + const hsl = this.colors.hsl + + if (Math.round(hsl.s * 100) / 100 === 0.50) { + return Math.round(hsl.l * 100) / 100 + } else if (hasBlack && hsl.l === 0) { + return 0; + } else if (hasWhite && hsl.l === 1) { + return 1; } - return 0 - } - }, - data () { - return { - swatches: ['.80', '.65', '.50', '.35', '.20'] + return -1; } }, methods: { @@ -105,4 +113,10 @@ export default { transform: scaleY(1.8); border-radius: 3.6px/2px; } +.vc-slider-swatch-picker--white { + box-shadow: inset 0 0 0 1px #ddd; +} +.vc-slider-swatch-picker--active.vc-slider-swatch-picker--white { + box-shadow: inset 0 0 0 0.6px #ddd; +}