forked from frappe/insights
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8c798c
commit 2892747
Showing
8 changed files
with
121 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<template> | ||
<div> | ||
<label class="mb-1.5 block text-xs text-gray-600">Color Palette</label> | ||
<Autocomplete | ||
v-model="selectedPalette" | ||
:options="colorPaletteOptions" | ||
placeholder="Color palette" | ||
> | ||
</Autocomplete> | ||
<div class="mt-1.5 flex flex-wrap gap-1 px-1"> | ||
<template | ||
v-for="(color, index) in getPaletteColors(selectedPalette.value)" | ||
:key="index" | ||
> | ||
<ColorPicker | ||
:modelValue="color" | ||
@update:modelValue="handleColorChange($event, index)" | ||
> | ||
<template #target="{ togglePopover }"> | ||
<div | ||
class="h-5 w-5 cursor-pointer rounded-sm" | ||
:style="{ backgroundColor: color }" | ||
@click="togglePopover" | ||
@click.meta="removeColor(index)" | ||
></div> | ||
</template> | ||
</ColorPicker> | ||
</template> | ||
<ColorPicker | ||
:modelValue="newColor" | ||
@update:modelValue="handleColorChange($event, newColorIndex)" | ||
> | ||
<template #target="{ togglePopover }"> | ||
<div | ||
class="flex h-5 w-5 cursor-pointer items-center justify-center rounded-sm border border-dashed border-gray-500 text-gray-500 hover:border-gray-700 hover:text-gray-700" | ||
@click=" | ||
() => { | ||
togglePopover() | ||
newColor = '#000000' | ||
newColorIndex = getPaletteColors(selectedPalette.value).length | ||
} | ||
" | ||
> | ||
<Plus class="h-3 w-3" /> | ||
</div> | ||
</template> | ||
</ColorPicker> | ||
</div> | ||
</div> | ||
</template> | ||
; ;; | ||
<script setup> | ||
import { getColors } from '@/utils/colors' | ||
import { debounce } from 'frappe-ui' | ||
import { Plus } from 'lucide-vue-next' | ||
import { ref } from 'vue' | ||
import ColorPicker from './ColorPicker.vue' | ||
const colors = defineModel() | ||
const paletteColors = { | ||
default: getColors(), | ||
} | ||
const colorPaletteOptions = [ | ||
{ label: 'Default', value: 'default' }, | ||
{ label: 'Custom', value: 'custom' }, | ||
] | ||
const selectedPalette = ref() | ||
if (colors.value?.length === 0) { | ||
selectedPalette.value = colorPaletteOptions[0] | ||
} else if (isDefaultPalette(colors.value)) { | ||
selectedPalette.value = colorPaletteOptions[0] | ||
} else { | ||
selectedPalette.value = colorPaletteOptions[1] | ||
} | ||
function getPaletteColors(palette) { | ||
if (palette === 'custom') { | ||
return colors.value?.length ? colors.value : getPaletteColors('default') | ||
} | ||
return paletteColors[palette]?.slice(0, 10) ?? [] | ||
} | ||
function isDefaultPalette(colors) { | ||
if (!colors) return true | ||
return colors.every((color, index) => color === paletteColors.default[index]) | ||
} | ||
function handleColorChange(color, index) { | ||
if (selectedPalette.value.value !== 'custom') { | ||
const currentColors = [...getPaletteColors(selectedPalette.value.value)] | ||
selectedPalette.value = colorPaletteOptions[1] | ||
colors.value = currentColors.length ? currentColors : getPaletteColors('default') | ||
} | ||
colors.value[index] = color | ||
} | ||
const newColor = ref('#000000') | ||
const newColorIndex = ref(0) | ||
function removeColor(index) { | ||
if (selectedPalette.value.value !== 'custom') return | ||
colors.value.splice(index, 1) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.