feat: add public ColorArea components, docs, and package contract
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { ColorArea, ColorAreaThumb } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-56 max-w-full items-center justify-center">
|
||||
<ColorArea default-value="rgb(116, 52, 255)">
|
||||
<ColorAreaThumb />
|
||||
</ColorArea>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef } from "vue";
|
||||
import {
|
||||
ColorArea,
|
||||
ColorAreaThumb,
|
||||
ColorSwatch,
|
||||
parseColor,
|
||||
type Color,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const color = shallowRef<Color | null>(parseColor("#9B80FF"));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<ColorArea
|
||||
v-model="color"
|
||||
color-space="rgb"
|
||||
x-channel="red"
|
||||
y-channel="green"
|
||||
>
|
||||
<ColorAreaThumb />
|
||||
</ColorArea>
|
||||
<div class="flex w-[300px] items-center gap-3">
|
||||
<ColorSwatch :color="color" size="md" />
|
||||
<p class="text-sm text-muted">
|
||||
Current color:
|
||||
<span class="font-medium">
|
||||
{{ color ? color.toString("hex") : "(empty)" }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { ColorArea, ColorAreaThumb } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ColorArea class="size-44 rounded-3xl" default-value="rgb(116, 52, 255)">
|
||||
<ColorAreaThumb class="size-5 rounded-full border-4 border-white" />
|
||||
</ColorArea>
|
||||
</template>
|
||||
@@ -0,0 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { ColorArea, ColorAreaThumb } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-56 max-w-full items-center justify-center">
|
||||
<ColorArea is-disabled default-value="hsl(200, 100%, 50%)">
|
||||
<ColorAreaThumb />
|
||||
</ColorArea>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { ColorArea, ColorAreaThumb } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-56 max-w-full items-center justify-center">
|
||||
<ColorArea as-child default-value="rgb(116, 52, 255)">
|
||||
<div data-custom="slider">
|
||||
<ColorAreaThumb as="span" data-custom="thumb" />
|
||||
</div>
|
||||
</ColorArea>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,187 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, shallowRef } from "vue";
|
||||
import {
|
||||
ColorArea,
|
||||
ColorAreaThumb,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Select,
|
||||
SelectIndicator,
|
||||
SelectPopover,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
parseColor,
|
||||
type Color,
|
||||
type ColorAxisChannel,
|
||||
type ColorSpace,
|
||||
type SelectModelValue,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
interface ChannelOption {
|
||||
id: ColorAxisChannel;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const colorSpaces: Array<{ id: ColorSpace; name: string }> = [
|
||||
{ id: "rgb", name: "RGB" },
|
||||
{ id: "hsl", name: "HSL" },
|
||||
{ id: "hsb", name: "HSB" },
|
||||
];
|
||||
|
||||
const channelsBySpace: Record<ColorSpace, ChannelOption[]> = {
|
||||
hsb: [
|
||||
{ id: "hue", name: "Hue" },
|
||||
{ id: "saturation", name: "Saturation" },
|
||||
{ id: "brightness", name: "Brightness" },
|
||||
],
|
||||
hsl: [
|
||||
{ id: "hue", name: "Hue" },
|
||||
{ id: "saturation", name: "Saturation" },
|
||||
{ id: "lightness", name: "Lightness" },
|
||||
],
|
||||
rgb: [
|
||||
{ id: "red", name: "Red" },
|
||||
{ id: "green", name: "Green" },
|
||||
{ id: "blue", name: "Blue" },
|
||||
],
|
||||
};
|
||||
|
||||
const color = shallowRef<Color | null>(parseColor("hsb(219, 58%, 93%)"));
|
||||
const colorSpace = ref<ColorSpace>("hsb");
|
||||
const xChannel = ref<ColorAxisChannel>("saturation");
|
||||
const yChannel = ref<ColorAxisChannel>("brightness");
|
||||
|
||||
const channels = computed(() => channelsBySpace[colorSpace.value]);
|
||||
const xChannelOptions = computed(() =>
|
||||
channels.value.filter((channel) => channel.id !== yChannel.value),
|
||||
);
|
||||
const yChannelOptions = computed(() =>
|
||||
channels.value.filter((channel) => channel.id !== xChannel.value),
|
||||
);
|
||||
|
||||
function handleColorSpaceChange(value: SelectModelValue) {
|
||||
if (typeof value !== "string") return;
|
||||
const space = value as ColorSpace;
|
||||
colorSpace.value = space;
|
||||
if (space === "rgb") {
|
||||
xChannel.value = "blue";
|
||||
yChannel.value = "green";
|
||||
} else if (space === "hsl") {
|
||||
xChannel.value = "saturation";
|
||||
yChannel.value = "lightness";
|
||||
} else {
|
||||
xChannel.value = "saturation";
|
||||
yChannel.value = "brightness";
|
||||
}
|
||||
}
|
||||
|
||||
function handleXChannel(value: SelectModelValue) {
|
||||
if (typeof value === "string") xChannel.value = value as ColorAxisChannel;
|
||||
}
|
||||
|
||||
function handleYChannel(value: SelectModelValue) {
|
||||
if (typeof value === "string") yChannel.value = value as ColorAxisChannel;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col items-center gap-6">
|
||||
<div class="flex gap-4">
|
||||
<Select
|
||||
class="w-32"
|
||||
:model-value="colorSpace"
|
||||
@update:model-value="handleColorSpaceChange"
|
||||
>
|
||||
<Label>Color Space</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="space in colorSpaces"
|
||||
:key="space.id"
|
||||
:id="space.id"
|
||||
:text-value="space.name"
|
||||
>
|
||||
{{ space.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
|
||||
<Select
|
||||
class="w-36"
|
||||
:model-value="xChannel"
|
||||
@update:model-value="handleXChannel"
|
||||
>
|
||||
<Label>X Axis</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="channel in xChannelOptions"
|
||||
:key="channel.id"
|
||||
:id="channel.id"
|
||||
:text-value="channel.name"
|
||||
>
|
||||
{{ channel.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
|
||||
<Select
|
||||
class="w-36"
|
||||
:model-value="yChannel"
|
||||
@update:model-value="handleYChannel"
|
||||
>
|
||||
<Label>Y Axis</Label>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
<SelectIndicator />
|
||||
</SelectTrigger>
|
||||
<SelectPopover>
|
||||
<ListBox>
|
||||
<ListBoxItem
|
||||
v-for="channel in yChannelOptions"
|
||||
:key="channel.id"
|
||||
:id="channel.id"
|
||||
:text-value="channel.name"
|
||||
>
|
||||
{{ channel.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</SelectPopover>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<ColorArea
|
||||
v-model="color"
|
||||
:color-space="colorSpace"
|
||||
:x-channel="xChannel"
|
||||
:y-channel="yChannel"
|
||||
>
|
||||
<ColorAreaThumb />
|
||||
</ColorArea>
|
||||
|
||||
<div class="flex items-center gap-3">
|
||||
<div
|
||||
class="size-8 rounded-md border border-default"
|
||||
:style="{ backgroundColor: color?.toString('css') }"
|
||||
/>
|
||||
<code class="rounded bg-default/50 px-2 py-1 text-sm">
|
||||
{{ color?.toString(colorSpace) ?? "(empty)" }}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { ColorArea, ColorAreaThumb } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-56 max-w-full items-center justify-center">
|
||||
<ColorArea show-dots default-value="hsl(200, 100%, 50%)">
|
||||
<ColorAreaThumb />
|
||||
</ColorArea>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user