fix(docs): restore pinned color demos and color values
This commit is contained in:
@@ -1,111 +1,372 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 apps/docs/src/components/color-section.tsx.
|
||||
// Port of HeroUI ce90ea3 color-section.tsx: four original layout families.
|
||||
// Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE.
|
||||
// Vue DOM/CSS token display; copying keeps the browser's resolved CSS color.
|
||||
import { ref } from "vue";
|
||||
import { Button, Tooltip, TooltipContent } from "@heroui-vue/components";
|
||||
defineProps<{ name: string; tokens: string[] }>();
|
||||
import { computed, ref } from "vue";
|
||||
import { Chip } from "@heroui-vue/components";
|
||||
import { IconSettings } from "@tabler/icons-vue";
|
||||
import DocsColorSwatch from "./DocsColorSwatch.vue";
|
||||
import {
|
||||
colorSections,
|
||||
type SectionId,
|
||||
type SideSection,
|
||||
type Swatch,
|
||||
} from "./color-sections";
|
||||
const props = defineProps<{ section: SectionId }>();
|
||||
const section = computed(() => colorSections[props.section]);
|
||||
const side = computed(() =>
|
||||
section.value.kind === "ColorSectionSideBySide" ? section.value : undefined,
|
||||
);
|
||||
const stacked = computed(() =>
|
||||
section.value.kind === "ColorSectionStacked" ? section.value : undefined,
|
||||
);
|
||||
const field = computed(() =>
|
||||
section.value.kind === "ColorSectionFormField"
|
||||
? section.value.colors
|
||||
: undefined,
|
||||
);
|
||||
const primitive = computed(() =>
|
||||
section.value.kind === "ColorSectionPrimitive"
|
||||
? section.value.colors
|
||||
: undefined,
|
||||
);
|
||||
const message = ref("");
|
||||
async function copy(event: MouseEvent, token: string) {
|
||||
const value = getComputedStyle(
|
||||
event.currentTarget as HTMLElement,
|
||||
).backgroundColor;
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
message.value = `已复制 ${token}: ${value}`;
|
||||
} catch {
|
||||
message.value = `无法复制,请使用变量 ${token}`;
|
||||
}
|
||||
}
|
||||
const themes = ["light", "dark"] as const;
|
||||
const swatch = (
|
||||
label: string,
|
||||
variable: string,
|
||||
cssValue?: string,
|
||||
tooltip?: string,
|
||||
border?: boolean,
|
||||
): Swatch => ({ label, variable, cssValue, tooltip, border });
|
||||
const header = (s: SideSection) =>
|
||||
swatch(s.name, s.baseVariable, undefined, s.baseTooltip);
|
||||
</script>
|
||||
<template>
|
||||
<div class="docs-color-section not-prose">
|
||||
<div
|
||||
v-for="theme in ['light', 'dark']"
|
||||
:key="theme"
|
||||
:data-theme="theme"
|
||||
class="docs-color-column"
|
||||
>
|
||||
<div class="docs-color-header">
|
||||
<strong>{{ name }}</strong>
|
||||
<span>{{ theme === "light" ? "Light" : "Dark" }}</span>
|
||||
<div
|
||||
class="docs-color-section not-prose"
|
||||
:data-color-section="props.section"
|
||||
:data-color-layout="section.kind"
|
||||
>
|
||||
<div v-if="side" class="docs-color-side">
|
||||
<div
|
||||
v-for="theme in themes"
|
||||
:key="theme"
|
||||
:data-theme="theme"
|
||||
class="docs-color-column"
|
||||
>
|
||||
<DocsColorSwatch
|
||||
:swatch="header(side)"
|
||||
:theme="theme"
|
||||
header
|
||||
@copied="message = $event"
|
||||
/>
|
||||
<div class="docs-color-groups">
|
||||
<div
|
||||
class="docs-color-solid"
|
||||
:style="{ backgroundColor: `var(${side.baseVariable})` }"
|
||||
>
|
||||
<span
|
||||
class="docs-color-group-title"
|
||||
:style="{ backgroundColor: `var(${side.baseVariable})` }"
|
||||
>
|
||||
{{ side.name }}
|
||||
</span>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Hover',
|
||||
side.hoverVariable,
|
||||
side.hoverCssValue,
|
||||
side.hoverTooltip,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
@copied="message = $event"
|
||||
/>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Foreground',
|
||||
side.foregroundVariable,
|
||||
undefined,
|
||||
side.foregroundTooltip,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="side.soft" class="docs-color-soft">
|
||||
<div class="docs-color-soft-surface" />
|
||||
<div
|
||||
class="docs-color-soft-tint"
|
||||
:style="{
|
||||
backgroundColor:
|
||||
side.soft.baseCssValue || `var(${side.soft.baseVariable})`,
|
||||
}"
|
||||
/>
|
||||
<span class="docs-color-soft-title">{{ side.name }} Soft</span>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Hover',
|
||||
side.soft.hoverVariable,
|
||||
side.soft.hoverCssValue,
|
||||
side.soft.hoverTooltip,
|
||||
true,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
plain-text
|
||||
contrast-border
|
||||
@copied="message = $event"
|
||||
/>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Foreground',
|
||||
side.soft.foregroundVariable,
|
||||
side.soft.foregroundCssValue,
|
||||
side.soft.foregroundTooltip,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Tooltip v-for="token in tokens" :key="token" :delay="0">
|
||||
<Button
|
||||
variant="ghost"
|
||||
class="docs-color-token"
|
||||
:style="{ backgroundColor: `var(${token})` }"
|
||||
:aria-label="`复制 ${theme} ${token}`"
|
||||
@click="copy($event, token)"
|
||||
>
|
||||
<span>{{ token }}</span>
|
||||
</Button>
|
||||
<TooltipContent>
|
||||
{{ token }} · 点击复制浏览器解析后的颜色值
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<span class="docs-color-message" role="status">{{ message }}</span>
|
||||
<template v-else-if="stacked">
|
||||
<div
|
||||
v-for="theme in themes"
|
||||
:key="theme"
|
||||
:data-theme="theme"
|
||||
class="docs-color-row"
|
||||
>
|
||||
<div>
|
||||
<Chip size="sm">
|
||||
<IconSettings :size="14" aria-hidden="true" />
|
||||
{{ theme === "light" ? "Light" : "Dark" }}
|
||||
</Chip>
|
||||
</div>
|
||||
<div class="docs-color-swatches">
|
||||
<DocsColorSwatch
|
||||
v-for="(color, i) in theme === 'light'
|
||||
? stacked.lightColors
|
||||
: stacked.darkColors"
|
||||
:key="i"
|
||||
:swatch="color"
|
||||
:theme="theme"
|
||||
stacked
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="field">
|
||||
<div
|
||||
v-for="theme in themes"
|
||||
:key="theme"
|
||||
:data-theme="theme"
|
||||
class="docs-color-row"
|
||||
>
|
||||
<div>
|
||||
<Chip size="sm">
|
||||
<IconSettings :size="14" aria-hidden="true" />
|
||||
{{ theme === "light" ? "Light" : "Dark" }}
|
||||
</Chip>
|
||||
</div>
|
||||
<div class="docs-color-field-layout">
|
||||
<div
|
||||
class="docs-color-field-bg"
|
||||
:style="{ backgroundColor: `var(${field.bg})` }"
|
||||
>
|
||||
<span
|
||||
class="docs-color-group-title"
|
||||
:style="{ backgroundColor: `var(${field.bg})` }"
|
||||
>
|
||||
Bg
|
||||
</span>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Hover',
|
||||
field.bg,
|
||||
field.bgHover,
|
||||
field.bgHoverTooltip,
|
||||
true,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
contrast-border
|
||||
@copied="message = $event"
|
||||
/>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch('Focus', field.bg, undefined, field.bgFocusTooltip, true)
|
||||
"
|
||||
:theme="theme"
|
||||
contrast-border
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
<div class="docs-color-field-text">
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Placeholder',
|
||||
field.placeholder,
|
||||
undefined,
|
||||
field.placeholderTooltip,
|
||||
true,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
@copied="message = $event"
|
||||
/>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Foreground',
|
||||
field.foreground,
|
||||
undefined,
|
||||
field.foregroundTooltip,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else-if="primitive" class="docs-color-swatches">
|
||||
<DocsColorSwatch
|
||||
v-for="color in primitive"
|
||||
:key="color.variable"
|
||||
:swatch="color"
|
||||
stacked
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
<span class="sr-only" role="status">{{ message }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.docs-color-section {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-block: 20px;
|
||||
}
|
||||
[data-theme="light"] {
|
||||
--docs-color-outline: rgb(0 0 0 / 12%);
|
||||
}
|
||||
[data-theme="dark"] {
|
||||
--docs-color-outline: rgb(255 255 255 / 12%);
|
||||
}
|
||||
.docs-color-side {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
.docs-color-column {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-groups {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-solid,
|
||||
.docs-color-soft,
|
||||
.docs-color-field-bg {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
background: var(--surface);
|
||||
color: var(--foreground);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.docs-color-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.docs-color-header span {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.docs-color-token {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
min-height: 48px;
|
||||
padding: 12px;
|
||||
justify-content: start;
|
||||
border-radius: 12px;
|
||||
border: 1px solid color-mix(in oklab, var(--foreground) 12%, transparent);
|
||||
}
|
||||
.docs-color-token span {
|
||||
background: inherit;
|
||||
.docs-color-group-title {
|
||||
background-clip: text;
|
||||
-webkit-background-clip: text;
|
||||
color: transparent;
|
||||
filter: invert(1) grayscale(1) contrast(100);
|
||||
font-size: 12px;
|
||||
overflow-wrap: anywhere;
|
||||
white-space: normal;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
line-height: 24px;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
.docs-color-message {
|
||||
grid-column: 1 / -1;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
.docs-color-soft {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
@media (max-width: 480px) {
|
||||
.docs-color-section {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
.docs-color-soft-surface,
|
||||
.docs-color-soft-tint {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
}
|
||||
.docs-color-soft-surface {
|
||||
background: var(--surface);
|
||||
}
|
||||
.docs-color-soft-title,
|
||||
.docs-color-soft :deep(.docs-swatch) {
|
||||
position: relative;
|
||||
}
|
||||
.docs-color-soft-title {
|
||||
color: var(--foreground);
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
.docs-color-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-swatches {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-swatches :deep(.docs-swatch) {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.docs-color-field-layout {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-field-bg {
|
||||
border: 1px solid rgb(0 0 0 / 12%);
|
||||
}
|
||||
.docs-color-field-text {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-field-text :deep(.docs-swatch) {
|
||||
flex: 1;
|
||||
}
|
||||
@media (min-width: 640px) {
|
||||
.docs-color-side,
|
||||
.docs-color-groups,
|
||||
.docs-color-swatches,
|
||||
.docs-color-field-layout {
|
||||
flex-direction: row;
|
||||
}
|
||||
.docs-color-field-text {
|
||||
width: 160px;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<script setup lang="ts">
|
||||
// Vue adaptation of HeroUI ce90ea3 ColorHeader/ColorBlock/StackedSwatch.
|
||||
// Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE.
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { Tooltip, TooltipContent } from "@heroui-vue/components";
|
||||
import type { Swatch } from "./color-sections";
|
||||
import { colorValue } from "./color-value";
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
swatch: Swatch;
|
||||
theme?: string;
|
||||
header?: boolean;
|
||||
stacked?: boolean;
|
||||
plainText?: boolean;
|
||||
contrastBorder?: boolean;
|
||||
}>(),
|
||||
{ theme: "primitive" },
|
||||
);
|
||||
const emit = defineEmits<{ copied: [message: string] }>();
|
||||
const element = ref<HTMLButtonElement>();
|
||||
const resolved = ref("");
|
||||
const expression = computed(
|
||||
() => props.swatch.cssValue ?? `var(${props.swatch.variable})`,
|
||||
);
|
||||
const token = computed(
|
||||
() => props.swatch.tooltip?.split(":")[0].trim() || props.swatch.variable,
|
||||
);
|
||||
const contrast = computed(() =>
|
||||
props.plainText
|
||||
? { color: "var(--foreground)" }
|
||||
: {
|
||||
backgroundColor: `var(${props.swatch.variable})`,
|
||||
backgroundClip: "text",
|
||||
WebkitBackgroundClip: "text",
|
||||
color: "transparent",
|
||||
filter: "invert(1) grayscale(1) contrast(100)",
|
||||
},
|
||||
);
|
||||
function read() {
|
||||
if (element.value)
|
||||
resolved.value = colorValue(
|
||||
getComputedStyle(element.value).backgroundColor,
|
||||
);
|
||||
}
|
||||
onMounted(read);
|
||||
async function copy() {
|
||||
read();
|
||||
try {
|
||||
await navigator.clipboard.writeText(resolved.value);
|
||||
emit("copied", `已复制 ${token.value}: ${resolved.value}`);
|
||||
} catch {
|
||||
emit("copied", `无法复制,请使用 ${expression.value}`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<Tooltip :delay="0">
|
||||
<button
|
||||
ref="element"
|
||||
type="button"
|
||||
class="docs-swatch"
|
||||
:class="{
|
||||
'docs-swatch-header': header,
|
||||
'docs-swatch-stacked': stacked,
|
||||
'docs-swatch-border': swatch.border,
|
||||
'docs-swatch-contrast-border': contrastBorder,
|
||||
}"
|
||||
:style="{ backgroundColor: expression }"
|
||||
:data-color-variable="swatch.variable"
|
||||
:data-color-label="swatch.label"
|
||||
:data-color-expression="expression"
|
||||
:aria-label="`复制 ${theme} ${swatch.label} ${token}`"
|
||||
@pointerenter="read"
|
||||
@focus="read"
|
||||
@click="copy"
|
||||
>
|
||||
<span class="docs-swatch-label" :style="contrast">
|
||||
{{ swatch.label }}
|
||||
</span>
|
||||
<span class="docs-swatch-token" :style="contrast">{{ token }}</span>
|
||||
<span v-if="header" class="docs-swatch-theme" :style="contrast">
|
||||
{{ theme === "light" ? "Light" : "Dark" }}
|
||||
</span>
|
||||
</button>
|
||||
<TooltipContent class="docs-color-tooltip">
|
||||
<pre
|
||||
>{{ token }}: {{ expression }}
|
||||
当前取值:{{ resolved }}</pre>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</template>
|
||||
<style scoped>
|
||||
.docs-swatch {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
padding: 10px 16px;
|
||||
border: 0;
|
||||
border-radius: 12px;
|
||||
text-align: start;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.docs-swatch:focus-visible {
|
||||
outline: 2px solid var(--focus);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.docs-swatch-label {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
line-height: 20px;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
.docs-swatch-token {
|
||||
display: none;
|
||||
font: 10px/1.1 monospace;
|
||||
opacity: 0.6;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.docs-swatch-header {
|
||||
position: relative;
|
||||
padding: 12px 16px;
|
||||
}
|
||||
.docs-swatch-header .docs-swatch-label {
|
||||
font-size: 18px;
|
||||
line-height: 28px;
|
||||
padding-inline-end: 40px;
|
||||
}
|
||||
.docs-swatch-theme {
|
||||
position: absolute;
|
||||
inset-inline-end: 16px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
.docs-swatch-stacked {
|
||||
min-height: 56px;
|
||||
padding-block: 8px;
|
||||
}
|
||||
.docs-swatch-border {
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.docs-swatch-contrast-border {
|
||||
border-color: var(--docs-color-outline);
|
||||
}
|
||||
.docs-color-tooltip pre {
|
||||
margin: 0;
|
||||
font: 12px/1.6 monospace;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
@media (max-width: 639px) {
|
||||
.docs-swatch-token {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,513 @@
|
||||
// Data ported verbatim from HeroUI ce90ea3 Chinese colors.mdx.
|
||||
// Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE.
|
||||
// Explicit demo formulas intentionally differ from some library-derived tokens.
|
||||
export interface Swatch {
|
||||
label: string;
|
||||
variable: string;
|
||||
cssValue?: string;
|
||||
border?: boolean;
|
||||
tooltip?: string;
|
||||
}
|
||||
interface Soft {
|
||||
baseVariable: string;
|
||||
baseCssValue?: string;
|
||||
baseTooltip?: string;
|
||||
hoverVariable: string;
|
||||
hoverCssValue?: string;
|
||||
hoverTooltip?: string;
|
||||
foregroundVariable: string;
|
||||
foregroundCssValue?: string;
|
||||
foregroundTooltip?: string;
|
||||
}
|
||||
export interface SideSection {
|
||||
kind: "ColorSectionSideBySide";
|
||||
name: string;
|
||||
baseVariable: string;
|
||||
baseTooltip?: string;
|
||||
hoverVariable: string;
|
||||
hoverCssValue?: string;
|
||||
hoverTooltip?: string;
|
||||
foregroundVariable: string;
|
||||
foregroundTooltip?: string;
|
||||
soft?: Soft;
|
||||
}
|
||||
interface StackSection {
|
||||
kind: "ColorSectionStacked";
|
||||
lightColors: Swatch[];
|
||||
darkColors: Swatch[];
|
||||
}
|
||||
interface FieldColors {
|
||||
bg: string;
|
||||
bgTooltip?: string;
|
||||
bgHover: string;
|
||||
bgHoverTooltip?: string;
|
||||
bgFocusTooltip?: string;
|
||||
placeholder: string;
|
||||
placeholderTooltip?: string;
|
||||
foreground: string;
|
||||
foregroundTooltip?: string;
|
||||
}
|
||||
interface FieldSection {
|
||||
kind: "ColorSectionFormField";
|
||||
colors: FieldColors;
|
||||
}
|
||||
interface PrimitiveSection {
|
||||
kind: "ColorSectionPrimitive";
|
||||
colors: Swatch[];
|
||||
}
|
||||
export type SectionId =
|
||||
| "accent"
|
||||
| "default"
|
||||
| "success"
|
||||
| "warning"
|
||||
| "danger"
|
||||
| "foreground"
|
||||
| "background"
|
||||
| "surface"
|
||||
| "field"
|
||||
| "separator"
|
||||
| "other"
|
||||
| "primitive";
|
||||
export const colorSections: Record<
|
||||
SectionId,
|
||||
SideSection | StackSection | FieldSection | PrimitiveSection
|
||||
> = {
|
||||
accent: {
|
||||
kind: "ColorSectionSideBySide",
|
||||
name: "强调色",
|
||||
baseVariable: "--accent",
|
||||
baseTooltip: "--accent: oklch(0.6204 0.195 253.83)",
|
||||
hoverVariable: "--accent",
|
||||
hoverCssValue:
|
||||
"color-mix(in oklab, var(--accent) 90%, var(--accent-foreground) 10%)",
|
||||
hoverTooltip:
|
||||
"--color-accent-hover:\n color-mix(\n in oklab,\n var(--accent) 90%,\n var(--accent-foreground) 10%\n )",
|
||||
foregroundVariable: "--accent-foreground",
|
||||
foregroundTooltip: "--accent-foreground: var(--snow)",
|
||||
soft: {
|
||||
baseVariable: "--accent",
|
||||
baseCssValue: "color-mix(in oklab, var(--accent) 15%, transparent)",
|
||||
baseTooltip:
|
||||
"--color-accent-soft:\n color-mix(\n in oklab,\n var(--accent) 15%,\n transparent\n )",
|
||||
hoverVariable: "--accent",
|
||||
hoverCssValue: "color-mix(in oklab, var(--accent) 20%, transparent)",
|
||||
hoverTooltip:
|
||||
"--color-accent-soft-hover:\n color-mix(\n in oklab,\n var(--accent) 20%,\n transparent\n )",
|
||||
foregroundVariable: "--accent",
|
||||
foregroundCssValue: "var(--accent)",
|
||||
foregroundTooltip: "--color-accent-soft-foreground: var(--accent)",
|
||||
},
|
||||
},
|
||||
default: {
|
||||
kind: "ColorSectionSideBySide",
|
||||
name: "默认",
|
||||
baseVariable: "--default",
|
||||
baseTooltip: "--default: oklch(94% 0.001 286.375)",
|
||||
hoverVariable: "--default",
|
||||
hoverCssValue:
|
||||
"color-mix(in oklab, var(--default) 96%, var(--default-foreground) 4%)",
|
||||
hoverTooltip:
|
||||
"--color-default-hover:\n color-mix(\n in oklab,\n var(--default) 96%,\n var(--default-foreground) 4%\n )",
|
||||
foregroundVariable: "--default-foreground",
|
||||
foregroundTooltip: "--default-foreground: var(--eclipse)",
|
||||
},
|
||||
success: {
|
||||
kind: "ColorSectionSideBySide",
|
||||
name: "成功",
|
||||
baseVariable: "--success",
|
||||
baseTooltip: "--success: oklch(0.7329 0.1935 150.81)",
|
||||
hoverVariable: "--success",
|
||||
hoverCssValue:
|
||||
"color-mix(in oklab, var(--success) 90%, var(--success-foreground) 10%)",
|
||||
hoverTooltip:
|
||||
"--color-success-hover:\n color-mix(\n in oklab,\n var(--success) 90%,\n var(--success-foreground) 10%\n )",
|
||||
foregroundVariable: "--success-foreground",
|
||||
foregroundTooltip: "--success-foreground: var(--eclipse)",
|
||||
soft: {
|
||||
baseVariable: "--success",
|
||||
baseCssValue: "color-mix(in oklab, var(--success) 15%, transparent)",
|
||||
baseTooltip:
|
||||
"--color-success-soft:\n color-mix(\n in oklab,\n var(--success) 15%,\n transparent\n )",
|
||||
hoverVariable: "--success",
|
||||
hoverCssValue: "color-mix(in oklab, var(--success) 20%, transparent)",
|
||||
hoverTooltip:
|
||||
"--color-success-soft-hover:\n color-mix(\n in oklab,\n var(--success) 20%,\n transparent\n )",
|
||||
foregroundVariable: "--success",
|
||||
foregroundCssValue: "var(--success)",
|
||||
foregroundTooltip: "--color-success-soft-foreground: var(--success)",
|
||||
},
|
||||
},
|
||||
warning: {
|
||||
kind: "ColorSectionSideBySide",
|
||||
name: "警告",
|
||||
baseVariable: "--warning",
|
||||
baseTooltip: "--warning: oklch(0.7819 0.1585 72.33)",
|
||||
hoverVariable: "--warning",
|
||||
hoverCssValue:
|
||||
"color-mix(in oklab, var(--warning) 90%, var(--warning-foreground) 10%)",
|
||||
hoverTooltip:
|
||||
"--color-warning-hover:\n color-mix(\n in oklab,\n var(--warning) 90%,\n var(--warning-foreground) 10%\n )",
|
||||
foregroundVariable: "--warning-foreground",
|
||||
foregroundTooltip: "--warning-foreground: var(--eclipse)",
|
||||
soft: {
|
||||
baseVariable: "--warning",
|
||||
baseCssValue: "color-mix(in oklab, var(--warning) 15%, transparent)",
|
||||
baseTooltip:
|
||||
"--color-warning-soft:\n color-mix(\n in oklab,\n var(--warning) 15%,\n transparent\n )",
|
||||
hoverVariable: "--warning",
|
||||
hoverCssValue: "color-mix(in oklab, var(--warning) 20%, transparent)",
|
||||
hoverTooltip:
|
||||
"--color-warning-soft-hover:\n color-mix(\n in oklab,\n var(--warning) 20%,\n transparent\n )",
|
||||
foregroundVariable: "--warning",
|
||||
foregroundCssValue: "var(--warning)",
|
||||
foregroundTooltip: "--color-warning-soft-foreground: var(--warning)",
|
||||
},
|
||||
},
|
||||
danger: {
|
||||
kind: "ColorSectionSideBySide",
|
||||
name: "危险",
|
||||
baseVariable: "--danger",
|
||||
baseTooltip: "--danger: oklch(0.6532 0.2328 25.74)",
|
||||
hoverVariable: "--danger",
|
||||
hoverCssValue:
|
||||
"color-mix(in oklab, var(--danger) 90%, var(--danger-foreground) 10%)",
|
||||
hoverTooltip:
|
||||
"--color-danger-hover:\n color-mix(\n in oklab,\n var(--danger) 90%,\n var(--danger-foreground) 10%\n )",
|
||||
foregroundVariable: "--danger-foreground",
|
||||
foregroundTooltip: "--danger-foreground: var(--snow)",
|
||||
soft: {
|
||||
baseVariable: "--danger",
|
||||
baseCssValue: "color-mix(in oklab, var(--danger) 15%, transparent)",
|
||||
baseTooltip:
|
||||
"--color-danger-soft:\n color-mix(\n in oklab,\n var(--danger) 15%,\n transparent\n )",
|
||||
hoverVariable: "--danger",
|
||||
hoverCssValue: "color-mix(in oklab, var(--danger) 20%, transparent)",
|
||||
hoverTooltip:
|
||||
"--color-danger-soft-hover:\n color-mix(\n in oklab,\n var(--danger) 20%,\n transparent\n )",
|
||||
foregroundVariable: "--danger",
|
||||
foregroundCssValue: "var(--danger)",
|
||||
foregroundTooltip: "--color-danger-soft-foreground: var(--danger)",
|
||||
},
|
||||
},
|
||||
foreground: {
|
||||
kind: "ColorSectionStacked",
|
||||
lightColors: [
|
||||
{
|
||||
label: "前景",
|
||||
variable: "--foreground",
|
||||
tooltip: "--foreground: var(--eclipse)",
|
||||
},
|
||||
{
|
||||
label: "弱化",
|
||||
variable: "--muted",
|
||||
tooltip: "--muted: oklch(0.5517 0.0138 285.94)",
|
||||
},
|
||||
{
|
||||
label: "分段",
|
||||
variable: "--segment",
|
||||
tooltip: "--segment: var(--white)",
|
||||
},
|
||||
{
|
||||
label: "遮罩",
|
||||
variable: "--overlay",
|
||||
tooltip: "--overlay: var(--white)",
|
||||
},
|
||||
{
|
||||
label: "链接",
|
||||
variable: "--link",
|
||||
tooltip: "--link: var(--foreground)",
|
||||
},
|
||||
],
|
||||
darkColors: [
|
||||
{
|
||||
label: "前景",
|
||||
variable: "--foreground",
|
||||
border: true,
|
||||
tooltip: "--foreground: var(--snow)",
|
||||
},
|
||||
{
|
||||
label: "弱化",
|
||||
variable: "--muted",
|
||||
border: true,
|
||||
tooltip: "--muted: oklch(70.5% 0.015 286.067)",
|
||||
},
|
||||
{
|
||||
label: "分段",
|
||||
variable: "--segment",
|
||||
border: true,
|
||||
tooltip: "--segment: oklch(0.3964 0.01 285.93)",
|
||||
},
|
||||
{
|
||||
label: "遮罩",
|
||||
variable: "--overlay",
|
||||
border: true,
|
||||
tooltip: "--overlay: oklch(0.2103 0.0059 285.89)",
|
||||
},
|
||||
{
|
||||
label: "链接",
|
||||
variable: "--link",
|
||||
border: true,
|
||||
tooltip: "--link: var(--foreground)",
|
||||
},
|
||||
],
|
||||
},
|
||||
background: {
|
||||
kind: "ColorSectionStacked",
|
||||
lightColors: [
|
||||
{
|
||||
label: "背景",
|
||||
variable: "--background",
|
||||
border: true,
|
||||
tooltip: "--background: oklch(0.9702 0 0)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--background",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--background) 96%, var(--foreground) 4%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-background-secondary:\n color-mix(\n in oklab,\n var(--background) 96%,\n var(--foreground) 4%\n )",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--background",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--background) 92%, var(--foreground) 8%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-background-tertiary:\n color-mix(\n in oklab,\n var(--background) 92%,\n var(--foreground) 8%\n )",
|
||||
},
|
||||
{
|
||||
label: "反色",
|
||||
variable: "--foreground",
|
||||
tooltip: "--color-background-inverse: var(--foreground)",
|
||||
},
|
||||
],
|
||||
darkColors: [
|
||||
{
|
||||
label: "背景",
|
||||
variable: "--background",
|
||||
border: true,
|
||||
tooltip: "--background: oklch(12% 0.005 285.823)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--background",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--background) 96%, var(--foreground) 4%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-background-secondary:\n color-mix(\n in oklab,\n var(--background) 96%,\n var(--foreground) 4%\n )",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--background",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--background) 92%, var(--foreground) 8%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-background-tertiary:\n color-mix(\n in oklab,\n var(--background) 92%,\n var(--foreground) 8%\n )",
|
||||
},
|
||||
{
|
||||
label: "反色",
|
||||
variable: "--foreground",
|
||||
border: true,
|
||||
tooltip: "--color-background-inverse: var(--foreground)",
|
||||
},
|
||||
],
|
||||
},
|
||||
surface: {
|
||||
kind: "ColorSectionStacked",
|
||||
lightColors: [
|
||||
{
|
||||
label: "表面",
|
||||
variable: "--surface",
|
||||
border: true,
|
||||
tooltip: "--surface: var(--white)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--surface-secondary",
|
||||
border: true,
|
||||
tooltip: "--surface-secondary: oklch(0.9524 0.0013 286.37)",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--surface-tertiary",
|
||||
border: true,
|
||||
tooltip: "--surface-tertiary: oklch(0.9373 0.0013 286.37)",
|
||||
},
|
||||
],
|
||||
darkColors: [
|
||||
{
|
||||
label: "表面",
|
||||
variable: "--surface",
|
||||
border: true,
|
||||
tooltip: "--surface: oklch(0.2103 0.0059 285.89)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--surface-secondary",
|
||||
border: true,
|
||||
tooltip: "--surface-secondary: oklch(0.257 0.0037 286.14)",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--surface-tertiary",
|
||||
border: true,
|
||||
tooltip: "--surface-tertiary: oklch(0.2721 0.0024 247.91)",
|
||||
},
|
||||
],
|
||||
},
|
||||
field: {
|
||||
kind: "ColorSectionFormField",
|
||||
colors: {
|
||||
bg: "--field-background",
|
||||
bgTooltip: "--field-background: var(--white)",
|
||||
bgHover:
|
||||
"color-mix(in oklab, var(--field-background) 90%, var(--field-foreground) 10%)",
|
||||
bgHoverTooltip:
|
||||
"--color-field-hover:\n color-mix(\n in oklab,\n var(--field-background, var(--default)) 90%,\n var(--field-foreground, var(--foreground)) 2%\n )",
|
||||
bgFocusTooltip:
|
||||
"--color-field-focus:\n var(--field-background, var(--default))",
|
||||
placeholder: "--field-placeholder",
|
||||
placeholderTooltip: "--field-placeholder: var(--muted)",
|
||||
foreground: "--field-foreground",
|
||||
foregroundTooltip: "--field-foreground: oklch(0.2103 0.0059 285.89)",
|
||||
},
|
||||
},
|
||||
separator: {
|
||||
kind: "ColorSectionStacked",
|
||||
lightColors: [
|
||||
{
|
||||
label: "分隔线",
|
||||
variable: "--separator",
|
||||
border: true,
|
||||
tooltip: "--separator: oklch(92% 0.004 286.32)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--surface",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--surface) 85%, var(--surface-foreground) 15%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-separator-secondary:\n color-mix(\n in oklab,\n var(--surface) 85%,\n var(--surface-foreground) 15%\n )",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--surface",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--surface) 81%, var(--surface-foreground) 19%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-separator-tertiary:\n color-mix(\n in oklab,\n var(--surface) 81%,\n var(--surface-foreground) 19%\n )",
|
||||
},
|
||||
],
|
||||
darkColors: [
|
||||
{
|
||||
label: "分隔线",
|
||||
variable: "--separator",
|
||||
border: true,
|
||||
tooltip: "--separator: oklch(25% 0.006 286.033)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--surface",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--surface) 85%, var(--surface-foreground) 15%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-separator-secondary:\n color-mix(\n in oklab,\n var(--surface) 85%,\n var(--surface-foreground) 15%\n )",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--surface",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--surface) 81%, var(--surface-foreground) 19%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-separator-tertiary:\n color-mix(\n in oklab,\n var(--surface) 81%,\n var(--surface-foreground) 19%\n )",
|
||||
},
|
||||
],
|
||||
},
|
||||
other: {
|
||||
kind: "ColorSectionStacked",
|
||||
lightColors: [
|
||||
{
|
||||
label: "边框",
|
||||
variable: "--border",
|
||||
tooltip: "--border: oklch(90% 0.004 286.32)",
|
||||
},
|
||||
{
|
||||
label: "背衬",
|
||||
variable: "--backdrop",
|
||||
tooltip: "--backdrop: rgba(0, 0, 0, 0.5)",
|
||||
},
|
||||
{
|
||||
label: "遮罩",
|
||||
variable: "--overlay",
|
||||
border: true,
|
||||
tooltip: "--overlay: var(--white)",
|
||||
},
|
||||
{
|
||||
label: "分段",
|
||||
variable: "--segment",
|
||||
border: true,
|
||||
tooltip: "--segment: var(--white)",
|
||||
},
|
||||
],
|
||||
darkColors: [
|
||||
{
|
||||
label: "边框",
|
||||
variable: "--border",
|
||||
tooltip: "--border: oklch(28% 0.006 286.033)",
|
||||
},
|
||||
{
|
||||
label: "背衬",
|
||||
variable: "--backdrop",
|
||||
tooltip: "--backdrop: rgba(0, 0, 0, 0.6)",
|
||||
},
|
||||
{
|
||||
label: "遮罩",
|
||||
variable: "--overlay",
|
||||
border: true,
|
||||
tooltip: "--overlay: oklch(0.2103 0.0059 285.89)",
|
||||
},
|
||||
{
|
||||
label: "分段",
|
||||
variable: "--segment",
|
||||
border: true,
|
||||
tooltip: "--segment: oklch(0.3964 0.01 285.93)",
|
||||
},
|
||||
],
|
||||
},
|
||||
primitive: {
|
||||
kind: "ColorSectionPrimitive",
|
||||
colors: [
|
||||
{
|
||||
label: "白",
|
||||
variable: "--white",
|
||||
border: true,
|
||||
tooltip: "--white: oklch(100% 0 0)",
|
||||
},
|
||||
{
|
||||
label: "黑",
|
||||
variable: "--black",
|
||||
tooltip: "--black: oklch(0% 0 0)",
|
||||
},
|
||||
{
|
||||
label: "雪白",
|
||||
variable: "--snow",
|
||||
border: true,
|
||||
tooltip: "--snow: oklch(0.9911 0 0)",
|
||||
},
|
||||
{
|
||||
label: "月蚀",
|
||||
variable: "--eclipse",
|
||||
tooltip: "--eclipse: oklch(0.2103 0.0059 285.89)",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
// Match the fixed color-section's OKLCH clipboard format without a runtime color dependency.
|
||||
// Input is the browser's computed sRGB/OKLab/OKLCH serialization, not arbitrary CSS.
|
||||
export function colorValue(css: string) {
|
||||
const format = (n: number) => String(Number(n.toFixed(4)));
|
||||
const output = (l: number, a: number, b: number, alpha = 1) => {
|
||||
const c = Math.hypot(a, b);
|
||||
const h = c < 1e-7 ? 0 : ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360;
|
||||
return `oklch(${format(l)} ${format(c < 1e-7 ? 0 : c)} ${format(h)}${alpha < 1 ? ` / ${format(alpha)}` : ""})`;
|
||||
};
|
||||
const ok = css.match(/^ok(lab|lch)\((.+)\)$/);
|
||||
if (ok) {
|
||||
const [components, opacity] = ok[2].split("/").map((s) => s.trim());
|
||||
const values = components.split(/\s+/);
|
||||
const lightness =
|
||||
parseFloat(values[0]) / (values[0].endsWith("%") ? 100 : 1);
|
||||
const alpha =
|
||||
opacity === undefined
|
||||
? 1
|
||||
: parseFloat(opacity) / (opacity.endsWith("%") ? 100 : 1);
|
||||
if (ok[1] === "lab")
|
||||
return output(
|
||||
lightness,
|
||||
parseFloat(values[1]),
|
||||
parseFloat(values[2]),
|
||||
alpha,
|
||||
);
|
||||
return `oklch(${format(lightness)} ${format(parseFloat(values[1]))} ${format(parseFloat(values[2]) || 0)}${alpha < 1 ? ` / ${format(alpha)}` : ""})`;
|
||||
}
|
||||
const rgb = css.match(/^rgba?\((.+)\)$/);
|
||||
if (!rgb) return css;
|
||||
const parts = rgb[1].split(/[\s,/]+/).filter(Boolean);
|
||||
const [r, g, b] = parts.slice(0, 3).map((s) => {
|
||||
const v = parseFloat(s) / (s.endsWith("%") ? 100 : 255);
|
||||
return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
||||
});
|
||||
const alpha =
|
||||
parts[3] === undefined
|
||||
? 1
|
||||
: parseFloat(parts[3]) / (parts[3].endsWith("%") ? 100 : 1);
|
||||
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
||||
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
||||
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
||||
return output(
|
||||
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
||||
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
||||
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
||||
alpha,
|
||||
);
|
||||
}
|
||||
+15
-15
@@ -5,55 +5,55 @@ description: HeroUI v3 的调色板与主题系统
|
||||
|
||||
颜色通过语义变量表达用途。浅色和深色共用变量名称,由主题容器决定实际取值;组件使用变量而不是各自硬编码品牌色。本页沿用固定 HeroUI 基线的颜色分类,类名使用本库的 `hv-` 前缀。
|
||||
|
||||
以下色板同时展示 Light / Dark。悬停或键盘聚焦查看变量名,点击色块复制浏览器解析后的颜色值;复制的是当前主题下的颜色,不是变量名。
|
||||
以下色板同时展示 Light / Dark。悬停或键盘聚焦查看变量名,点击色块复制浏览器解析后的颜色值;复制的是当前主题下的颜色,不是变量名。实色与柔和色、明暗色阶、字段预览和基础色分别沿用官方演示结构;显式混色公式也与固定源演示一致。
|
||||
|
||||
## 强调色
|
||||
|
||||
强调色代表品牌或产品的主识别色,用于吸引对关键操作、高亮与重点时刻的注意。应节制使用,以保留视觉层级。组件从基础强调色派生悬停和柔和背景;改变 `--accent` 时也应保证配对前景色可读。
|
||||
|
||||
<DocsColorSection name="强调色" :tokens="['--accent', '--accent-hover', '--accent-foreground', '--accent-soft', '--accent-soft-hover', '--accent-soft-foreground']" />
|
||||
<DocsColorSection section="accent" />
|
||||
|
||||
## 默认(中性色)
|
||||
|
||||
默认色构成系统的中性骨架,适用于大多数非强调的界面元素。它与页面背景、卡片表面有不同用途,不应随意互换。
|
||||
|
||||
<DocsColorSection name="默认" :tokens="['--default', '--default-hover', '--default-foreground', '--default-soft', '--default-soft-hover', '--default-soft-foreground']" />
|
||||
<DocsColorSection section="default" />
|
||||
|
||||
## 成功
|
||||
|
||||
成功色表达积极结果、确认与完成状态,常见于反馈、状态指示与校验通过等场景。
|
||||
|
||||
<DocsColorSection name="成功" :tokens="['--success', '--success-hover', '--success-foreground', '--success-soft', '--success-soft-hover', '--success-soft-foreground']" />
|
||||
<DocsColorSection section="success" />
|
||||
|
||||
## 警告
|
||||
|
||||
警告色表示需要谨慎、存在风险或需要留意的操作。它用于提醒和复核,不应替代危险色表达破坏性操作。
|
||||
|
||||
<DocsColorSection name="警告" :tokens="['--warning', '--warning-hover', '--warning-foreground', '--warning-soft', '--warning-soft-hover', '--warning-soft-foreground']" />
|
||||
<DocsColorSection section="warning" />
|
||||
|
||||
## 危险
|
||||
|
||||
危险色用于错误、严重告警和破坏性操作。组件的错误样式还需要关联错误说明与实际校验语义,仅改变颜色不会使字段成为无效状态。
|
||||
|
||||
<DocsColorSection name="危险" :tokens="['--danger', '--danger-hover', '--danger-foreground', '--danger-soft', '--danger-soft-hover', '--danger-soft-foreground']" />
|
||||
<DocsColorSection section="danger" />
|
||||
|
||||
## 前景色
|
||||
|
||||
`--foreground` 用于正文与图标,`--muted` 用于次要信息。带专用背景的组件应使用其配对前景色,例如 `--accent-foreground`,而不是固定白色。
|
||||
|
||||
<DocsColorSection name="前景色" :tokens="['--foreground', '--muted']" />
|
||||
<DocsColorSection section="foreground" />
|
||||
|
||||
## 背景色
|
||||
|
||||
背景是界面的基底画布;secondary 和 tertiary 在同一画布上建立层级。inverse 提供反色背景,使用时仍需自行确认文字对比度。
|
||||
|
||||
<DocsColorSection name="背景色" :tokens="['--background', '--background-secondary', '--background-tertiary', '--background-inverse']" />
|
||||
<DocsColorSection section="background" />
|
||||
|
||||
## 表面色
|
||||
|
||||
表面色用于卡片、面板和其他非浮层容器;`--overlay` 专门用于 Popover、Modal、菜单等浮层。表面通过明度、层级和阴影区分内容,不依赖强烈色相差异。
|
||||
|
||||
<DocsColorSection name="表面色" :tokens="['--surface', '--surface-secondary', '--surface-tertiary', '--surface-hover', '--overlay']" />
|
||||
<DocsColorSection section="surface" />
|
||||
|
||||
每层还有对应的 foreground:`--surface-foreground`、`--surface-secondary-foreground`、`--surface-tertiary-foreground` 和 `--overlay-foreground`。
|
||||
|
||||
@@ -61,29 +61,29 @@ description: HeroUI v3 的调色板与主题系统
|
||||
|
||||
字段有独立的背景、文本、placeholder、hover/focus 和边框变量。修改这些变量可以调整表单而不改变按钮或卡片的基础表面。
|
||||
|
||||
<DocsColorSection name="表单字段" :tokens="['--field-background', '--field-foreground', '--field-placeholder', '--field-hover', '--field-focus', '--field-border', '--field-border-hover', '--field-border-focus']" />
|
||||
<DocsColorSection section="field" />
|
||||
|
||||
默认 `--field-border` 是透明色,色板可能显示底层表面。`--field-border-width` 决定字段描边宽度;焦点环使用 `--focus`,错误状态使用 `--danger`。
|
||||
字段预览展示背景、Hover、Focus、Placeholder 与 Foreground。Hover 色块沿用固定源演示的 90% 背景 + 10% 前景公式;它是配色演示,不宣称等同于组件当前的 `--field-hover`(前景配比 2%)。默认 `--field-border` 是透明色。`--field-border-width` 决定字段描边宽度;焦点环使用 `--focus`,错误状态使用 `--danger`。
|
||||
|
||||
## 分隔线
|
||||
|
||||
分隔线用于轻量组织内容,边框用于轮廓。secondary/tertiary 是相对于表面的派生层次。
|
||||
|
||||
<DocsColorSection name="分隔与边框" :tokens="['--separator', '--separator-secondary', '--separator-tertiary', '--border', '--border-secondary', '--border-tertiary']" />
|
||||
<DocsColorSection section="separator" />
|
||||
|
||||
## 其他
|
||||
|
||||
焦点、链接、分段控件、遮罩和滚动条也使用语义变量。
|
||||
|
||||
<DocsColorSection name="其他" :tokens="['--focus', '--link', '--segment', '--segment-foreground', '--backdrop', '--scrollbar-thumb', '--scrollbar-track']" />
|
||||
<DocsColorSection section="other" />
|
||||
|
||||
`--scrollbar-track` 默认透明,滚动条的宽度和模式参见[主题中的滚动条](/themes#滚动条)。
|
||||
滚动条的宽度和模式参见[主题中的滚动条](/themes#滚动条)。
|
||||
|
||||
## 基础色
|
||||
|
||||
基础色是主题的底层取值,明暗模式之间不变。业务页面通常优先选择语义颜色,而不是直接使用黑色或白色。
|
||||
|
||||
<DocsColorSection name="基础色" :tokens="['--white', '--black', '--snow', '--eclipse']" />
|
||||
<DocsColorSection section="primitive" />
|
||||
|
||||
## 如何使用颜色
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## 从哪里启动
|
||||
|
||||
任务卡与六篇完整文稿在 `task/handbook-docs-and-checklist` 交付分支,基于 `d6d80a0e0f6fa755601a448e022e5ecb04bd1718`(审计修复链)。尚未自动合main。新AI必须从包含本卡与文稿的交付提交或之后用户集成的提交启动,不能拿旧main当最新基线。文稿/任务实施提交为 `26df6e88a2c0aa15c92d27de1270304517f527f3`;完整交付与验证见 [HANDBOOK-DOCS结果](results/HANDBOOK-DOCS.md) 及Git历史。
|
||||
任务卡与六篇完整文稿在 `task/handbook-docs-and-checklist` 交付分支;之后颜色页布局/色值纠正在其后继分支 `task/handbook-colors-parity`。后续任务应保留该修正,从当前ACTIVE所记的最新交付提交启动。原文稿分支基于 `d6d80a0e0f6fa755601a448e022e5ecb04bd1718`(审计修复链)。尚未自动合main。新AI必须从包含本卡与文稿的交付提交或之后用户集成的提交启动,不能拿旧main当最新基线。文稿/任务实施提交为 `26df6e88a2c0aa15c92d27de1270304517f527f3`;完整交付与验证见 [HANDBOOK-DOCS结果](results/HANDBOOK-DOCS.md) 及Git历史。
|
||||
|
||||
以下是建议串行顺序,不是另一份任务状态表;实时状态只看各卡task-metadata。前一任务的已验收提交应先由用户安排集成或明确交接,再交下一AI。各卡以共同可用基线定义,不虚构尚未实施的硬依赖。前一任务若改变公共API,下一AI须读取其结果并以实际新基线继续,保留成果。
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
| 卡 | 用途 |
|
||||
| ----------------------------------------- | ----------------------------------------------------------- |
|
||||
| [HANDBOOK-COLORS-PARITY](HANDBOOK-COLORS-PARITY.md) | 纠正颜色页四类演示布局与固定源色值 |
|
||||
| [HANDBOOK-DOCS](HANDBOOK-DOCS.md) | 六篇 Handbook 文稿与后续排查交付 |
|
||||
| [Handbook 后续排查队列](HB-QUEUE.md) | 九张可交接任务卡、建议执行顺序及82根覆盖清单 |
|
||||
| [HANDBOOK-IMPLEMENTATION-AUDIT](HANDBOOK-IMPLEMENTATION-AUDIT.md) | 固定源六篇 Handbook 的组件实现与浏览器行为审计 |
|
||||
|
||||
@@ -341,3 +341,10 @@ CSS/tv 仅加 `hv-` 前缀与 Apache-2.0 来源;`colorPickerVariants` 保持
|
||||
- 固定 ce90ea3 中文 getting-started/(handbook) 的 colors/theming/dark-mode/styling/animation/composition 六篇:迁移全部56个二级主题,文稿用实际Vue接口适配;React/Next专属内容解释边界,不新增服务端支持。
|
||||
- `apps/docs/src/components/color-section.tsx` 的双主题色板、变量展示/复制与对比文字处理移植为文档组件 `DocsColorSection.vue`;保留Apache来源,颜色取本库实际CSS变量,复制浏览器解析结果,不新增culori依赖。
|
||||
- 五个 handbook-*.vue 为Vue指南可运行示例,预览/复制/高亮同源;不冒充原React演示的逐像素迁移结果。任务队列与审计证据见HB-QUEUE及HANDBOOK-DOCS结果。
|
||||
|
||||
## HANDBOOK-COLORS-PARITY(2026-10-27)
|
||||
|
||||
- 纠正HANDBOOK-DOCS曾将全部颜色演示简化为列表的问题。固定ce90ea3的colors.mdx十二个ColorSection配置(含显式CSS公式、顺序、标签、变量、原tooltip数据)保存在文档color-sections.ts;四类布局从color-section.tsx移植至DocsColorSection/DocsColorSwatch,保留Apache来源。
|
||||
- 恢复实色/Soft分组、明暗色阶上下行、字段左右分区、独立基础色行及源640px断点。演示soft前景沿用源基础强调色,字段Hover沿用源显式10%混色,不更改库主题派生变量。
|
||||
- 原字段tooltip写2%而实际演示写10%;本库展示真实演示公式和浏览器当前颜色,复制按源OKLCH四位格式规范化并保留alpha。依赖不增加culori,不导入/运行React。
|
||||
- 可选只读检查 `node scripts/check-handbook-color-source.mjs` 静态解析固定源与本库缓存数据,十二配置完全相等;库构建/运行不读取相邻仓库。
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
// Optional audit of cached documentation data against the pinned, read-only source.
|
||||
// Not part of build/runtime; no React is imported or executed.
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import assert from "node:assert/strict";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import ts from "typescript";
|
||||
const root = path.resolve(import.meta.dirname, "..");
|
||||
const option = process.argv.indexOf("--reference");
|
||||
const reference = path.resolve(
|
||||
root,
|
||||
option < 0 ? "../heroui" : process.argv[option + 1],
|
||||
);
|
||||
const raw = execFileSync(
|
||||
"git",
|
||||
[
|
||||
"show",
|
||||
"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960:apps/docs/content/docs/cn/react/getting-started/(handbook)/colors.mdx",
|
||||
],
|
||||
{ cwd: reference, encoding: "utf8" },
|
||||
);
|
||||
const tags = [...raw.matchAll(/<ColorSection\w+\b[\s\S]*?\/>/g)].map(
|
||||
(m) => m[0],
|
||||
);
|
||||
function literal(node) {
|
||||
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node))
|
||||
return node.text;
|
||||
if (node.kind === ts.SyntaxKind.TrueKeyword) return true;
|
||||
if (node.kind === ts.SyntaxKind.FalseKeyword) return false;
|
||||
if (ts.isArrayLiteralExpression(node)) return node.elements.map(literal);
|
||||
if (ts.isObjectLiteralExpression(node))
|
||||
return Object.fromEntries(
|
||||
node.properties.map((p) => {
|
||||
assert(ts.isPropertyAssignment(p), "Expected static data property");
|
||||
return [p.name.text, literal(p.initializer)];
|
||||
}),
|
||||
);
|
||||
throw Error("Non-literal source: " + ts.SyntaxKind[node.kind]);
|
||||
}
|
||||
const source = ts.createSourceFile(
|
||||
"source.tsx",
|
||||
"const sections = <>" + tags.join("\n") + "</>;",
|
||||
ts.ScriptTarget.Latest,
|
||||
true,
|
||||
ts.ScriptKind.TSX,
|
||||
);
|
||||
const original = [];
|
||||
function collect(node) {
|
||||
if (ts.isJsxSelfClosingElement(node))
|
||||
original.push({
|
||||
kind: node.tagName.getText(source),
|
||||
...Object.fromEntries(
|
||||
node.attributes.properties.map((p) => [
|
||||
p.name.text,
|
||||
ts.isStringLiteral(p.initializer)
|
||||
? p.initializer.text
|
||||
: literal(p.initializer.expression),
|
||||
]),
|
||||
),
|
||||
});
|
||||
ts.forEachChild(node, collect);
|
||||
}
|
||||
collect(source);
|
||||
const cachedSource = ts.createSourceFile(
|
||||
"cached.ts",
|
||||
fs.readFileSync(
|
||||
path.join(root, "apps/docs/.vitepress/theme/color-sections.ts"),
|
||||
"utf8",
|
||||
),
|
||||
ts.ScriptTarget.Latest,
|
||||
true,
|
||||
);
|
||||
let cached;
|
||||
function find(node) {
|
||||
if (
|
||||
ts.isVariableDeclaration(node) &&
|
||||
node.name.getText(cachedSource) === "colorSections"
|
||||
)
|
||||
cached = literal(node.initializer);
|
||||
ts.forEachChild(node, find);
|
||||
}
|
||||
find(cachedSource);
|
||||
assert(cached);
|
||||
assert.equal(original.length, 12);
|
||||
assert.deepEqual(Object.values(cached), original);
|
||||
console.log(
|
||||
"12/12 color sections match pinned source: order, layout, labels, variables, explicit formulas and tooltip source data.",
|
||||
);
|
||||
@@ -10,6 +10,57 @@ import Theme from "../apps/docs/demos/handbook-theme.vue";
|
||||
import States from "../apps/docs/demos/handbook-states.vue";
|
||||
import Composition from "../apps/docs/demos/handbook-composition.vue";
|
||||
import Motion from "../apps/docs/demos/handbook-animation.vue";
|
||||
import DocsColorSection from "../apps/docs/.vitepress/theme/DocsColorSection.vue";
|
||||
import { colorValue } from "../apps/docs/.vitepress/theme/color-value";
|
||||
|
||||
it("copies computed colors in the original OKLCH format without losing alpha", () => {
|
||||
expect(colorValue("oklab(0.5 0.1 0.1 / 0.2)")).toBe(
|
||||
"oklch(0.5 0.1414 45 / 0.2)",
|
||||
);
|
||||
expect(colorValue("rgba(0, 0, 0, 0.5)")).toBe("oklch(0 0 0 / 0.5)");
|
||||
expect(colorValue("rgb(255, 255, 255)")).toBe("oklch(1 0 0)");
|
||||
expect(colorValue("rgb(255, 0, 0)")).toBe("oklch(0.628 0.2577 29.2339)");
|
||||
expect(colorValue("oklch(99.11% 0 0)")).toBe("oklch(0.9911 0 0)");
|
||||
});
|
||||
import {
|
||||
colorSections,
|
||||
type SectionId,
|
||||
} from "../apps/docs/.vitepress/theme/color-sections";
|
||||
|
||||
it("renders each original color layout without dropping groups or adding primitive theme duplicates", () => {
|
||||
const counts = [10, 6, 10, 10, 10, 10, 8, 6, 8, 6, 8, 4];
|
||||
Object.keys(colorSections).forEach((id, i) => {
|
||||
const wrapper = mount(DocsColorSection, {
|
||||
props: { section: id as SectionId },
|
||||
});
|
||||
wrappers.push(wrapper);
|
||||
expect(wrapper.findAll("button.docs-swatch"), id).toHaveLength(counts[i]);
|
||||
if (["accent", "success", "warning", "danger"].includes(id)) {
|
||||
expect(wrapper.findAll(".docs-color-soft"), id).toHaveLength(2);
|
||||
expect(
|
||||
wrapper
|
||||
.findAll('.docs-color-soft [data-color-label="Foreground"]')
|
||||
.map((w) => w.attributes("data-color-expression")),
|
||||
).toEqual([`var(--${id})`, `var(--${id})`]);
|
||||
}
|
||||
if (id === "field")
|
||||
expect(
|
||||
wrapper
|
||||
.findAll('[data-color-label="Hover"]')
|
||||
.map((w) => w.attributes("data-color-expression")),
|
||||
).toEqual(
|
||||
Array(2).fill(
|
||||
"color-mix(in oklab, var(--field-background) 90%, var(--field-foreground) 10%)",
|
||||
),
|
||||
);
|
||||
if (id === "foreground")
|
||||
expect(
|
||||
wrapper
|
||||
.findAll('[data-theme="light"] [data-color-label]')
|
||||
.map((w) => w.attributes("data-color-label")),
|
||||
).toEqual(["前景", "弱化", "分段", "遮罩", "链接"]);
|
||||
});
|
||||
});
|
||||
|
||||
it("ships self-contained follow-up cards with real prerequisite and test paths", () => {
|
||||
const ids = [
|
||||
|
||||
Reference in New Issue
Block a user