mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 12:09:26 +00:00
Swatch picker component
This commit is contained in:
@@ -137,15 +137,7 @@
|
||||
</div>
|
||||
<template #content>
|
||||
<template v-if="hue === 'gray'">
|
||||
<wa-radio-group class="core-color" orientation="horizontal" :value="computedGrayColor" @input="grayColor = $event.target.value">
|
||||
<template v-for="h in hues">
|
||||
<wa-radio-button :id="'gray-undertone-' + h" :value="h" :label="capitalize(h)" :style="{'--color': `var(--wa-color-${ h })`}"></wa-radio-button>
|
||||
<wa-tooltip :for="'gray-undertone-' + h" hoist>{{ capitalize(h) }}</wa-tooltip>
|
||||
</template>
|
||||
<div slot="label">
|
||||
Gray undertone
|
||||
</div>
|
||||
</wa-radio-group>
|
||||
<color-swatch-picker :model-value="computedGrayColor" @update:model-value="grayColor = $event" label="Gray undertone" :colors="coreColors"></color-swatch-picker>
|
||||
|
||||
<color-slider coord="c" type="scale"
|
||||
:model-value="computedGrayChroma"
|
||||
|
||||
@@ -12,6 +12,7 @@ import ColorInput from './vue-components/color-input.js';
|
||||
import ColorPopup from './vue-components/color-popup.js';
|
||||
import ColorSelect from './vue-components/color-select.js';
|
||||
import ColorSlider from './vue-components/color-slider.js';
|
||||
import ColorSwatchPicker from './vue-components/color-swatch-picker.js';
|
||||
import InfoTip from './vue-components/info-tip.js';
|
||||
import Prism from '/assets/scripts/prism.js';
|
||||
import { Permalink } from '/assets/scripts/tweak.js';
|
||||
@@ -987,6 +988,7 @@ let paletteAppSpec = {
|
||||
ColorInput,
|
||||
ColorSelect,
|
||||
ColorSlider,
|
||||
ColorSwatchPicker,
|
||||
InfoTip,
|
||||
},
|
||||
|
||||
|
||||
56
docs/docs/palettes/app/vue-components/color-swatch-picker.js
Normal file
56
docs/docs/palettes/app/vue-components/color-swatch-picker.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const template = `
|
||||
<wa-radio-group class="core-color" orientation="horizontal" :value="modelValue" @input="handleInput($event.target.value)">
|
||||
<template v-for="h in hues">
|
||||
<info-tip>
|
||||
<wa-radio-button :label="capitalize(h)" :value="h" :style="{'--color': colors[h]}"></wa-radio-button>
|
||||
<template #content>{{ capitalize(h) }}</template>
|
||||
</info-tip>
|
||||
</template>
|
||||
<div slot="label">{{ label }}</div>
|
||||
</wa-radio-group>
|
||||
`;
|
||||
|
||||
import Color from 'https://colorjs.io/dist/color.js';
|
||||
import InfoTip from './info-tip.js';
|
||||
import { hues } from '/assets/scripts/tweak/data.js';
|
||||
import { capitalize, promise, roundTo } from '/assets/scripts/tweak/util.js';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
modelValue: String,
|
||||
label: {
|
||||
type: String,
|
||||
default: 'Color',
|
||||
},
|
||||
colors: Object,
|
||||
},
|
||||
emits: ['update:modelValue', 'input'],
|
||||
data() {
|
||||
return {
|
||||
defaultValue: this.modelValue,
|
||||
};
|
||||
},
|
||||
created() {
|
||||
Object.assign(this, { hues });
|
||||
},
|
||||
computed: {},
|
||||
methods: {
|
||||
capitalize,
|
||||
|
||||
/** Called when value changes due to user interaction */
|
||||
handleInput(value) {
|
||||
this.value = value;
|
||||
this.$emit('input', value);
|
||||
this.$emit('update:modelValue', value);
|
||||
},
|
||||
|
||||
reset() {
|
||||
this.handleInput(this.defaultValue);
|
||||
},
|
||||
},
|
||||
template,
|
||||
components: { InfoTip },
|
||||
compilerOptions: {
|
||||
isCustomElement: tag => tag.startsWith('wa-'),
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user