Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/src/components/Controls/ColorInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ref="colorPickerRef"
:placement="placement"
:offset="popoverOffset"
:portal-to="portalTo"
@open="events.onFocus"
@close="handleClose"
:modelValue="resolvedColor"
Expand Down Expand Up @@ -164,6 +165,7 @@ const props = withDefaults(
showPickerOnMount?: boolean;
popoverOffset?: number;
autocompleteReferenceElementSelector?: string;
portalTo?: string | HTMLElement | boolean;
}>(),
{
modelValue: null,
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/components/Controls/ColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
v-if="renderMode === 'popover'"
:placement="placement"
:offset="offset"
:portal-to="portalTo"
@open="emit('open')"
@close="emit('close')"
class="!block w-full">
<template #target="{ togglePopover, isOpen }">
<slot
Expand All @@ -21,7 +24,9 @@
ref="contentRef"
:modelValue="modelValue"
:showInput="showInput"
:showColorVariableOptions="showColorVariableOptions"
renderMode="popover"
@mousedown.stop
@update:modelValue="emit('update:modelValue', $event)" />
</template>
</Popover>
Expand All @@ -30,7 +35,9 @@
ref="contentRef"
:modelValue="modelValue"
:showInput="showInput"
:showColorVariableOptions="showColorVariableOptions"
renderMode="inline"
@mousedown.stop
@update:modelValue="emit('update:modelValue', $event)" />
</template>
<script setup lang="ts">
Expand All @@ -44,6 +51,7 @@ const props = withDefaults(
defineProps<{
modelValue?: CSSColorValue | null;
showInput?: boolean;
showColorVariableOptions?: boolean;
placement?:
| "bottom-start"
| "top-start"
Expand All @@ -59,11 +67,12 @@ const props = withDefaults(
| "left";
renderMode?: "popover" | "inline";
offset?: number;
portalTo?: string | HTMLElement;
}>(),
{ modelValue: null, showInput: false, placement: "left-start", renderMode: "popover", offset: 10 },
{ modelValue: null, showInput: false, showColorVariableOptions: true, placement: "left-start", renderMode: "popover", offset: 10 },
);

const emit = defineEmits(["update:modelValue"]);
const emit = defineEmits(["update:modelValue", "open", "close"]);
const colorPickerPopover = ref<InstanceType<typeof Popover> | null>(null);
const contentRef = ref<InstanceType<typeof ColorPickerContent> | null>(null);

Expand Down
62 changes: 36 additions & 26 deletions frontend/src/components/Controls/ColorPickerContent.vue
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
<template>
<div
:class="[
'color-picker-container flex flex-col gap-2',
renderMode === 'inline' ? 'w-full' : 'rounded-lg bg-surface-base p-3 shadow-lg',
'color-picker-container flex flex-col gap-1.5',
renderMode === 'inline' ? 'w-full' : 'rounded-lg bg-surface-base p-2 shadow-lg w-40',
]">
<div
ref="colorMap"
:style="colorMapStyle"
class="relative m-auto h-20 w-full rounded-md"
@mousedown.prevent="handleSelectorMove"
class="relative m-auto h-24 w-full rounded-md"
@click.prevent="setColor">
<div
@mousedown.stop.prevent="handleSelectorMove"
:class="selectorClass"
:style="colorSelectorStyle"></div>
:style="colorSelectorStyle"
@mousedown.stop.prevent="handleSelectorMove"></div>
</div>
<div
ref="hueMap"
class="relative m-auto h-3 w-full rounded-md"
class="relative m-auto h-2.5 w-full rounded-md"
:style="hueMapStyle"
@click="setHue"
@mousedown.prevent="handleHueSelectorMove"
:style="hueMapStyle">
<div @mousedown="handleHueSelectorMove" :class="hueSelectorClass" :style="hueSelectorStyle"></div>
@mousedown.prevent="handleHueSelectorMove">
<div :class="hueSelectorClass" :style="hueSelectorStyle" @mousedown="handleHueSelectorMove"></div>
</div>
<div
ref="alphaMap"
class="relative m-auto h-3 w-full rounded-md"
class="relative m-auto h-2.5 w-full rounded-md"
:style="alphaMapStyle"
@click="setAlpha"
@mousedown.prevent="handleAlphaSelectorMove"
:style="alphaMapStyle">
<div @mousedown="handleAlphaSelectorMove" :class="hueSelectorClass" :style="alphaSelectorStyle"></div>
@mousedown.prevent="handleAlphaSelectorMove">
<div :class="hueSelectorClass" :style="alphaSelectorStyle" @mousedown="handleAlphaSelectorMove"></div>
</div>
<div class="flex flex-wrap gap-1.5">
<div class="flex flex-wrap gap-1">
<div
v-for="color in colors"
:key="color"
class="h-3.5 w-3.5 cursor-pointer rounded-full shadow-sm"
@click="selectColor(color)"
:style="{ background: color }"></div>
class="h-3 w-3 cursor-pointer rounded-full shadow-sm"
:style="{ background: color }"
@click="selectColor(color)"></div>
<EyeDropperIcon v-if="isSupported" class="text-ink-gray-7" @click="() => open()" />
</div>
<Autocomplete
v-if="showInput"
:modelValue="displayValue"
class="mt-2 w-full text-sm [&>div>div>input]:text-sm"
:model-value="displayValue"
class="mt-1 w-full text-sm [&>div>div>input]:text-sm"
placeholder="Set Color"
:getOptions="getOptions"
referenceElementSelector=".color-picker-container"
@update:modelValue="handleInputChange" />
:get-options="getOptions"
reference-element-selector=".color-picker-container"
@update:model-value="handleInputChange">
<template #prefix>
<div
class="size-4 shrink-0 rounded border border-outline-gray-2"
:style="{ background: currentColor }"></div>
</template>
</Autocomplete>
</div>
</template>
<script setup lang="ts">
Expand Down Expand Up @@ -104,8 +110,9 @@ const props = withDefaults(
modelValue?: CSSColorValue | null;
showInput?: boolean;
renderMode?: "popover" | "inline";
showColorVariableOptions?: boolean;
}>(),
{ modelValue: null, showInput: false, renderMode: "popover" },
{ modelValue: null, showInput: false, renderMode: "popover", showColorVariableOptions: true },
);

const modelColor = computed(() => {
Expand All @@ -122,8 +129,11 @@ const displayValue = computed(() => {
return props.modelValue;
});

const getOptions = async (query: string) =>
getColorVariableOptions(query, variables.value, resolveVariableValue, builderStore.canvasDarkMode);
const getOptions = async (query: string) => {
if (props.showColorVariableOptions === false) return [];
if (query && !query.trim()) return [];
return getColorVariableOptions(query, variables.value, resolveVariableValue, builderStore.canvasDarkMode);
};

const emit = defineEmits(["update:modelValue"]);

Expand Down Expand Up @@ -158,7 +168,7 @@ const colorMapStyle = computed(() => ({
}));

const hueMapStyle = computed(() => ({
background: `linear-gradient(90deg, hsl(0,100%,50%), hsl(60,100%,50%), hsl(120,100%,50%), hsl(180,100%,50%), hsl(240,100%,50%), hsl(300,100%,50%), hsl(360,100%,50%))`,
background: "linear-gradient(90deg, hsl(0,100%,50%), hsl(60,100%,50%), hsl(120,100%,50%), hsl(180,100%,50%), hsl(240,100%,50%), hsl(300,100%,50%), hsl(360,100%,50%))",
}));

const alphaMapStyle = computed(() => ({
Expand Down
Loading
Loading