Compare commits

...

33 Commits

Author SHA1 Message Date
maoyingjie 0b89f02745 docs: accept HD-02 snapshot fixes and main integration 2026-10-28 15:05:34 +08:00
maoyingjie b0f32796cb fix(demos): snapshot validated values before asynchronous submissions 2026-10-28 15:05:09 +08:00
maoyingjie 49dd67afac docs: record HD-02 review and async submission snapshot regression 2026-10-28 15:02:25 +08:00
maoyingjie d9536ea5c1 docs: record HD-02 form, overlay and toast demo restoration results 2026-10-28 14:11:53 +08:00
maoyingjie 53e76f676d fix(demos): restore form, overlay and toast demos to the pinned cn baseline
HD-02 scope, all against heroui ce90ea3 cn sources:

- card: add the text-primary class to the coin icons (source parity);
  card-with-form drops the added required validation and inline business
  note, restores the plain href="#" forgot-password link and the baseline
  alert("表单提交成功!") submit feedback (autocomplete kept: no visible
  impact, allowed by the task card)
- input-group-with-textarea: restore the four Tooltips and the Enter Kbd
  hint; drop the stale "Tooltip 组件尚未迁移" note from input-group.md
- alert-dialog: restore the h-px top light line in custom-styles and the
  truncated/missing description text in sizes/custom-portal/
  custom-animations (+ controlled); align the fluid-slide icon with the
  modal mapping (IconArrowBarUp for gravity-ui:arrow-up-from-line)
- toast: restore the upstream demo layout shells (variants/simple/
  custom-indicator/custom-queue) and the action button default variant:
  ToastActionButton now falls back to the Button defaults (primary/md)
  like upstream ToastActionButton, so variants' actions render primary,
  danger stays danger and default stays tertiary; toast.md defaults fixed
- submit demos: restore baseline feedback and structure — alert() for
  card/fieldset/form/checkbox/checkbox-group/switch/select/combo-box/
  autocomplete and console.log for search/number/time field form examples;
  modal-with-form returns to the close-only footer (no submit/result row);
  drop the added inline status/result rows and the max-w-full/
  max-sm:min-w-0 width guards from the restored demos
- radio-group-validation: add the missing text-muted to the result line;
  label.md invalid example gives the real control its invalid state and
  matches the baseline input shape

Tests re-pinned to the baseline contracts (alert/console/close behavior,
four tooltips + Kbd, positional modal footer); full suite 110 files /
1617 tests, typecheck, build:docs and the m35-m36 tarball contract pass.
2026-10-28 14:10:10 +08:00
maoyingjie e9760810b8 docs: accept HD-01 main integration and close root attrs regression 2026-10-28 12:35:56 +08:00
maoyingjie f8de4529f6 fix(dropdown): preserve grouped root attrs and events without breaking seams 2026-10-28 12:35:35 +08:00
maoyingjie 8b1505438e docs: record independent HD-01 review and root attrs regression 2026-10-28 12:25:23 +08:00
maoyingjie 13f7b0b1fb docs: record HD-01 review fix for the merged dropdown seam 2026-10-28 11:40:37 +08:00
maoyingjie 123e3f9cba fix(dropdown): keep dropdown trigger positional inside ButtonGroup
Review of the restored button-group demos found the merged pull-request
group's seam broken: DropdownRoot renders a .hv-dropdown wrapper (a recorded
Vue adaptation) so the trigger button stopped being a positional child of
.button-group and matched :first-child:last-child, taking a full 24px radius
against the merge button's 24/0 end cap. The internal __button_group_child
marker also leaked onto the DOM.

Upstream Dropdown has no DOM root (RAC MenuTrigger renders a bare
SlotProvider and drops root props), so the trigger naturally occupies the
group's :last-child slot and the shared seam rules apply unchanged.

- DropdownRoot absorbs the ButtonGroup direct-child marker and skips the
  wrapper when marked, restoring positional seam radii and outline seam
  borders without touching the styles package (kept line-parity with the
  pinned source)
- wrapper contract (data-slot=dropdown-root, data-trigger, root class host)
  unchanged outside ButtonGroup; documented in dropdown.md
- regression tests: positional trigger + no marker leak in groups, wrapper
  still hosts root class standalone
2026-10-28 11:39:39 +08:00
maoyingjie dfd5248c9b docs: record HD-01 button and navigation demo restoration results 2026-10-28 09:43:48 +08:00
maoyingjie 896bac2cd7 fix(docs): restore button, toggle and nav demos to the pinned cn baseline
- button-group: restore all 9 cn demos incl. merge dropdown menu copy,
  custom-styles merge dropdown, sizes variant=secondary, orientation icon
  groups, full-width second group and the disabled child override
- toggle-button / toggle-button-group: restore cn copy, structure, button
  counts, theme custom-styles classes and aria-labels
- accordion-custom-styles: restore the 3-item collectibles scenario with the
  original 3dicons images, surface variant, selectors and hover motion
- disclosure-group-controlled: restore HeroUI Native / Expo copy and image
  semantics (Expo brand icon adapted to Tabler IconBrandReactNative)
- button-basic / button-loading-state: converge to baseline (console report,
  no added status paragraph) keeping the duplicate-trigger guard
- restore per-demo root gap/alignment/wrap classes instead of demo-row
- icon semantics per task card: search glyph kept on 搜索 buttons,
  rotate-back glyph restored (IconRefresh), person-search glyph restored
  (IconUserSearch); accordion item icons sized to the baseline 16px
2026-10-28 09:42:17 +08:00
maoyingjie df954aface docs: record repair queue main integration and first task handoff 2026-10-28 07:42:16 +08:00
maoyingjie bdc7de188a docs: include source audit evidence for repair task handoff 2026-10-28 07:40:27 +08:00
maoyingjie 93f82a205e docs: prepare reviewed hard-difference repair task queue 2026-10-28 07:38:38 +08:00
maoyingjie db5670f4e1 docs: record navigation text state verification 2026-10-28 00:11:42 +08:00
maoyingjie b49e3a9b42 fix(docs): keep section tab typography stable on hover 2026-10-28 00:11:22 +08:00
maoyingjie d616df3159 docs: define navigation text state follow-up 2026-10-28 00:10:37 +08:00
maoyingjie 6f9d039c85 docs: record control state audit evidence and handoff 2026-10-28 00:09:28 +08:00
maoyingjie 2a1a074ac3 fix: align field placeholder tokens and docs control semantics 2026-10-28 00:03:01 +08:00
maoyingjie ffe0c6b5bd docs: define control state audit and root-cause fixes 2026-10-27 23:39:01 +08:00
maoyingjie f6fdb3bdd1 docs: record navigation hover verification 2026-10-27 23:34:13 +08:00
maoyingjie adceb7ee8b fix(docs): remove navigation underline and card hover border 2026-10-27 23:33:49 +08:00
maoyingjie 4f6ce5045c docs: define navigation hover adjustments 2026-10-27 23:32:50 +08:00
maoyingjie 5ab21fded9 docs: record color parity verification and handoff 2026-10-27 23:31:10 +08:00
maoyingjie dd0d7b22ee fix(docs): restore pinned color demos and color values 2026-10-27 23:24:15 +08:00
maoyingjie 748abe4dfe docs: define color handbook parity correction 2026-10-27 21:51:10 +08:00
maoyingjie bd49252fc2 docs: record handbook delivery and sequential AI handoff 2026-10-27 21:47:42 +08:00
maoyingjie 26df6e88a2 docs: complete handbook and prepare component verification tasks 2026-10-27 21:46:42 +08:00
maoyingjie 4da00943f1 docs: define handbook completion and follow-up scope 2026-10-27 21:24:02 +08:00
maoyingjie d6d80a0e0f docs: record handbook implementation audit evidence and gaps 2026-10-27 21:11:38 +08:00
maoyingjie 202e3a5b5d fix: enforce handbook scrollbar and reduced motion contracts 2026-10-27 21:10:51 +08:00
maoyingjie b1344d8a4c docs: define handbook implementation audit scope 2026-10-27 20:39:06 +08:00
205 changed files with 8288 additions and 1091 deletions
@@ -0,0 +1,372 @@
<script setup lang="ts">
// Port of HeroUI ce90ea3 color-section.tsx: four original layout families.
// Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE.
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("");
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"
: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>
</div>
<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: 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;
padding: 12px;
border-radius: 12px;
}
.docs-color-group-title {
background-clip: text;
-webkit-background-clip: text;
color: transparent;
filter: invert(1) grayscale(1) contrast(100);
font-size: 16px;
font-weight: 500;
line-height: 24px;
letter-spacing: -0.025em;
}
.docs-color-soft {
position: relative;
overflow: hidden;
}
.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>
+12 -11
View File
@@ -36,6 +36,7 @@ import {
PopoverHeading,
ScrollShadow,
} from "@heroui-vue/components";
import { buttonVariants } from "@heroui-vue/styles";
import {
IconMenu2,
IconArrowUpRight,
@@ -240,17 +241,17 @@ async function copyMarkdownCode(event: MouseEvent) {
</div>
<DocSearch />
<div class="nav-tools">
<Button as-child variant="tertiary" size="sm" class="docs-github">
<a
href="https://git.myjdemo.cn/maoyingjie/heroui-vue"
target="_blank"
rel="noreferrer noopener"
aria-label="项目源码"
>
<IconBrandGithub :size="16" aria-hidden="true" />
<span>源码</span>
</a>
</Button>
<Link
class="docs-github"
:class="buttonVariants({ variant: 'tertiary', size: 'sm' })"
href="https://git.myjdemo.cn/maoyingjie/heroui-vue"
target="_blank"
rel="noreferrer noopener"
aria-label="项目源码"
>
<IconBrandGithub :size="16" aria-hidden="true" />
<span>源码</span>
</Link>
<DocsThemeSwitch />
<Drawer v-model:open="mobile">
<DrawerTrigger as-child>
@@ -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)",
},
],
},
};
+49
View File
@@ -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,
);
}
+2
View File
@@ -2,6 +2,7 @@ import type { Theme } from "vitepress";
import { IconCopy, IconCheck } from "@tabler/icons-vue";
import { Button } from "@heroui-vue/components";
import DocsComponents from "./DocsComponents.vue";
import DocsColorSection from "./DocsColorSection.vue";
import Layout from "./Layout.vue";
import Demo from "./Demo.vue";
import "@heroui-vue/styles/css";
@@ -14,6 +15,7 @@ export default {
app.component("ComponentPreview", Demo);
app.component("DocsCopyButton", Button);
app.component("DocsComponents", DocsComponents);
app.component("DocsColorSection", DocsColorSection);
app.component("DocsCopyIcon", IconCopy);
app.component("DocsCheckIcon", IconCheck);
},
+5
View File
@@ -392,7 +392,12 @@ export const guideGroups: DocsGroup[] = [
{
title: "手册",
items: [
{ title: "颜色", url: "/colors" },
{ title: "主题", url: "/themes" },
{ title: "深色模式", url: "/dark-mode" },
{ title: "样式", url: "/styling" },
{ title: "动画", url: "/animation" },
{ title: "组合", url: "/composition" },
{ title: "字段与表单基础", url: "/fields" },
],
},
+10 -5
View File
@@ -57,6 +57,7 @@ html {
min-width: 0;
}
.docs-nav .brand {
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 10px;
@@ -126,7 +127,10 @@ html {
gap: 12px;
height: 100%;
}
.docs-nav-sections nav .hv-link {
/* Section tabs keep their text treatment on hover; selection controls color. */
.docs-nav-sections nav .hv-link,
.docs-nav-sections nav .hv-link:is(:hover, [data-hovered="true"]) {
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 8px;
@@ -251,6 +255,7 @@ html {
margin: -8px 0 32px;
}
.source-links .hv-link {
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 4px;
@@ -418,6 +423,7 @@ html {
margin-top: 8px;
}
.component-index-title {
text-decoration: none;
font-size: 16px;
font-weight: 500;
line-height: 24px;
@@ -429,9 +435,6 @@ html {
inset: 0;
border-radius: 12px;
}
.component-index-card:hover .component-index-preview {
border-color: var(--muted);
}
.component-index-card:focus-within .component-index-preview {
outline: 2px solid var(--focus);
outline-offset: 3px;
@@ -551,6 +554,7 @@ html {
scrollbar-width: thin;
}
.search-results .hv-link {
text-decoration: none;
display: block;
padding: 12px;
border: 1px solid transparent;
@@ -716,7 +720,8 @@ html {
.docs-nav-sections nav {
gap: 20px;
}
.docs-nav-sections nav .hv-link {
.docs-nav-sections nav .hv-link,
.docs-nav-sections nav .hv-link:is(:hover, [data-hovered="true"]) {
font-size: 13px;
padding-bottom: 6px;
}
+123
View File
@@ -0,0 +1,123 @@
---
title: 动画
description: 为 HeroUI v3 组件添加流畅的动画和过渡
---
组件使用内置 CSS 过渡与关键帧,也可以在应用中添加自定义 CSS 或 Vue 动画。浮层动画还与定位、焦点及卸载有关,不能只给静态元素添加一个动画类就替代组件生命周期。
## 内置动画
浮层进入与退出时使用明确的阶段标记,按钮使用原生与数据状态。Vue 组件把这些状态适配到真实 DOM,再由样式控制:
```css
.hv-popover[data-entering="true"] {
/* 进入关键帧 */
}
.hv-popover[data-exiting="true"] {
/* 退出关键帧 */
}
.hv-button:active,
.hv-button[data-pressed="true"] {
transform: scale(0.97);
}
```
<ComponentPreview name="handbook-animation" />
| 状态 | 用途与边界 |
| ---------------------------------------------- | ------------------------------------------------ |
| `data-hovered="true"` | 部分交互组件的悬停状态,也可能使用原生 `:hover` |
| `data-pressed="true"` | 按下反馈,不等同于已经触发业务提交 |
| `data-focus-visible="true"` | 键盘焦点提示;原生 `:focus-visible` 也可能参与 |
| `disabled` / `aria-disabled` / `data-disabled` | 按实际组件语义与属性格式使用 |
| `data-entering="true"` / `data-exiting="true"` | 组件暴露的动画阶段,不是任意组件通用的控制属性 |
| `aria-expanded` | 触发器展开语义,不能用它判断面板是否可见、可点击 |
正常关闭时,Presence 保留浮层以播放退出动画,完成后卸载并按组件规则恢复焦点。用户禁用动画或动画被取消时,状态也需要清理;应用不要以过早的外层 `v-if` 抢先删除整套 Root/Content。设置 `display: none`、修改关键帧或 Portal 目标都可能影响退出阶段。
## CSS 动画
组件接受应用自定义的类。标准 CSS 无需额外动画库:
```vue
<script setup lang="ts">
import { Card } from "@heroui-vue/components";
</script>
<template>
<Card class="fade-in">Welcome!</Card>
</template>
<style scoped>
.fade-in {
animation: welcome 200ms ease-out;
}
@keyframes welcome {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media (prefers-reduced-motion: reduce) {
.fade-in {
animation: none;
}
}
.fade-in[data-reduce-motion="true"],
:global([data-reduce-motion="true"]) .fade-in {
animation: none;
}
</style>
```
对自己插入、删除的普通内容可使用 Vue `<Transition>`。不要在本身管理 Presence 的弹层外再建立互相冲突的卸载状态源。内部使用的 `tw-animate-css` 已随库样式编译,但不会在消费者构建中自动生成任意 `animate-*` 工具;自定义 Tailwind 动画需要在应用内配置。
## Framer Motion
官方的 Framer Motion / `motion/react` 示例依赖 React,不能直接用于 Vue。本库没有绑定第三方 Vue 动画库。可以先用 CSS 与 Vue Transition;确需动画库时,在应用内选择兼容 Vue 的库,并单独验证它的根元素、事件和 ref 透传。
尤其不要为了动画把 Button 的根节点替换成无按钮语义的 div,也不要让动画包装层拦截键盘事件。第三方库的安装和集成不作为本库当前已经验收的能力。
## 渲染属性
用作用域插槽读取组件状态,将自定义反馈施加到实际根或内容上:
```vue
<Button as-child v-slot="{ isPressed }">
<button :style="{ opacity: isPressed ? 0.8 : 1 }">Interactive Button</button>
</Button>
```
这是 Button 的状态插槽,不是 React render prop。`asChild` 必须保留唯一且语义正确的 DOM 根。已有按钮按下缩放时,不应再给同一根叠加冲突的 transform;复杂内容可在根内增加 span 作为独立动画目标。
## 无障碍
减少动态效果支持系统 `prefers-reduced-motion: reduce`,以及元素或祖先上的显式 `data-reduce-motion="true"`。应用级禁用建议设置在 `<html>`,以覆盖挂载到 body 的浮层:
```html
<html data-reduce-motion="true">
...
</html>
```
局部设置只影响该 DOM 子树;内容经 Teleport 挂载到其他地方后,不会自动继承触发器祖先的属性。上面的示例把 PopoverContent `to` 指向同一个容器,因此局部控制也能影响弹层。
库的共享变体覆盖组件装饰动画及伪元素。应用自定义动画仍需自行处理系统偏好和显式属性;不能因为子节点是库组件,就假定第三方动画会自动停止。`data-reduce-motion="false"` 不应被文稿解释为能够绕过系统减少动效偏好的统一保证。
本轮已验证代表性 Popover 的动态取消与卸载,以及若干浮层 BEM 的最终减少动效规则;其他嵌套、方向和组件生命周期按后续任务逐项验收。没有据此声称整库所有动画均已验收。
## 性能技巧
优先用 transform 与 opacity 表达位移和渐变,减少无必要的布局变化。高度展开等交互确实需要测量时,复用组件原有机制,不用固定假高度覆盖真实内容。
`will-change` 只用于确有动画的目标,避免长时间为大量元素保留图层。自定义动画不要修改定位库拥有的 wrapper transform;在允许的内容节点上做视觉变换。动画完成、取消、快速重开、卸载和减少动效切换都应释放监听与观察器。
## 下一步
- [样式](/styling):class、数据状态与 CSS 层。
- [组合](/composition):唯一根、事件与插槽。
- [主题](/themes):主题变量及 Portal 继承。
+140
View File
@@ -0,0 +1,140 @@
---
title: 颜色
description: HeroUI v3 的调色板与主题系统
---
颜色通过语义变量表达用途。浅色和深色共用变量名称,由主题容器决定实际取值;组件使用变量而不是各自硬编码品牌色。本页沿用固定 HeroUI 基线的颜色分类,类名使用本库的 `hv-` 前缀。
以下色板同时展示 Light / Dark。悬停或键盘聚焦查看变量名,点击色块复制浏览器解析后的颜色值;复制的是当前主题下的颜色,不是变量名。实色与柔和色、明暗色阶、字段预览和基础色分别沿用官方演示结构;显式混色公式也与固定源演示一致。
## 强调色
强调色代表品牌或产品的主识别色,用于吸引对关键操作、高亮与重点时刻的注意。应节制使用,以保留视觉层级。组件从基础强调色派生悬停和柔和背景;改变 `--accent` 时也应保证配对前景色可读。
<DocsColorSection section="accent" />
## 默认(中性色)
默认色构成系统的中性骨架,适用于大多数非强调的界面元素。它与页面背景、卡片表面有不同用途,不应随意互换。
<DocsColorSection section="default" />
## 成功
成功色表达积极结果、确认与完成状态,常见于反馈、状态指示与校验通过等场景。
<DocsColorSection section="success" />
## 警告
警告色表示需要谨慎、存在风险或需要留意的操作。它用于提醒和复核,不应替代危险色表达破坏性操作。
<DocsColorSection section="warning" />
## 危险
危险色用于错误、严重告警和破坏性操作。组件的错误样式还需要关联错误说明与实际校验语义,仅改变颜色不会使字段成为无效状态。
<DocsColorSection section="danger" />
## 前景色
`--foreground` 用于正文与图标,`--muted` 用于次要信息。带专用背景的组件应使用其配对前景色,例如 `--accent-foreground`,而不是固定白色。
<DocsColorSection section="foreground" />
## 背景色
背景是界面的基底画布;secondary 和 tertiary 在同一画布上建立层级。inverse 提供反色背景,使用时仍需自行确认文字对比度。
<DocsColorSection section="background" />
## 表面色
表面色用于卡片、面板和其他非浮层容器;`--overlay` 专门用于 Popover、Modal、菜单等浮层。表面通过明度、层级和阴影区分内容,不依赖强烈色相差异。
<DocsColorSection section="surface" />
每层还有对应的 foreground:`--surface-foreground`、`--surface-secondary-foreground`、`--surface-tertiary-foreground` 和 `--overlay-foreground`。
## 表单字段
字段有独立的背景、文本、placeholder、hover/focus 和边框变量。修改这些变量可以调整表单而不改变按钮或卡片的基础表面。
<DocsColorSection section="field" />
字段预览展示背景、Hover、Focus、Placeholder 与 Foreground。Hover 色块沿用固定源演示的 90% 背景 + 10% 前景公式;它是配色演示,不宣称等同于组件当前的 `--field-hover`(前景配比 2%)。默认 `--field-border` 是透明色。`--field-border-width` 决定字段描边宽度;焦点环使用 `--focus`,错误状态使用 `--danger`。
## 分隔线
分隔线用于轻量组织内容,边框用于轮廓。secondary/tertiary 是相对于表面的派生层次。
<DocsColorSection section="separator" />
## 其他
焦点、链接、分段控件、遮罩和滚动条也使用语义变量。
<DocsColorSection section="other" />
滚动条的宽度和模式参见[主题中的滚动条](/themes#滚动条)。
## 基础色
基础色是主题的底层取值,明暗模式之间不变。业务页面通常优先选择语义颜色,而不是直接使用黑色或白色。
<DocsColorSection section="primitive" />
## 如何使用颜色
组件通过 `variant` 等公开属性选择已有样式;自定义内容可以直接使用 CSS 变量。
```vue
<template>
<section class="summary">项目摘要</section>
</template>
<style scoped>
.summary {
background: var(--surface);
color: var(--surface-foreground);
border: 1px solid var(--border);
border-radius: var(--radius-xl);
}
</style>
```
使用 Tailwind 的应用需要在自己的构建中注册语义令牌,再使用 `bg-background`、`text-foreground` 等工具类。当前预编译 CSS **不会自动向消费者的 Tailwind 编译器注册令牌**;完整接入示例见[添加自定义颜色](/themes#添加自定义颜色)。
## 默认主题
默认值采用固定基线的 OKLCH 颜色与 `color-mix()` 派生公式。全局主题用 `.light` / `.dark` 或 `data-theme="light"` / `data-theme="dark"` 显式设置。
```html
<html class="dark">
<!-- 页面及挂载到 body 的浮层共同继承主题 -->
</html>
```
主题切换、跟随系统以及持久化由应用控制,见[深色模式](/dark-mode)。组件包当前没有公共 `useTheme`。
## 自定义颜色
在库 CSS 之后覆盖语义变量。局部主题同时添加 `light` 或 `dark`,使依赖这些颜色的派生变量在容器内重新计算。
```css
.light[data-theme="brand"] {
--accent: oklch(0.62 0.2 300);
--accent-foreground: var(--snow);
}
.dark[data-theme="brand"] {
--accent: oklch(0.72 0.17 300);
--accent-foreground: var(--eclipse);
}
```
```html
<section class="light" data-theme="brand">...</section>
```
派生变量继承的是计算结果,不能假定在任意子节点只覆盖 `--accent` 就会重新计算祖先的所有派生颜色。局部主题中的浮层还需使用支持的挂载目标,见[主题](/themes#快速开始)。
+1 -1
View File
@@ -410,7 +410,7 @@ Dropdown 组件实现 ARIA 菜单模式,并提供:
- 官方 `items` + 渲染函数的数据驱动集合用 `v-for` 表达;`renderEmptyState` 对应 `empty` 插槽。不提供 React Collection 对象模型。
- 子菜单悬停展开延迟由底层固定为 100ms,未暴露官方 `delay`(默认 200ms);子菜单面板的 `side`/`align` 由底层固定,只有偏移与碰撞参数可调。
- `DropdownTrigger` 的作用域插槽只提供 `{ isOpen }`,`DropdownPopover` 只提供 `{ isEntering, isExiting, placement }`;官方 Button/Popover 的完整 render props 未全部覆盖。
- `DropdownRoot` 额外渲染一层 `.hv-dropdown` 包裹元素(官方该类没有 DOM 宿主),用于承载根级 class 与方向。
- `DropdownRoot` 额外渲染一层 `.hv-dropdown` 包裹元素(官方该类没有 DOM 宿主),承载根级 class、style、id、ARIA、data 属性与原生事件。作为 `ButtonGroup` 直接子级时仍保留该容器,接缝样式按容器在组内的位置适配内部触发按钮;根级属性与捕获事件的行为不变。
- 条目 `id` 是业务 key,DOM id 为实例级;官方把 key 直接作为 DOM id(Vue 端避免数字 `0` 与字符串 `"0"` 冲突)。
- 条目 `onClick` 中 `preventDefault()` 会取消动作、选择与关闭;`stopImmediatePropagation()` 会终止后续处理器,均为原生事件语义。
+1 -1
View File
@@ -123,7 +123,7 @@ Fieldset 复合组件暴露以下 CSS 选择器:
三个部件使用对应 BEM 基础类,class 接受字符串、数组和对象。命名导出替代 React 对象式子部件;原生属性直接传递,不使用 nativeProps 对象。根元素固定为语义化原生元素,暂不提供 React render 根元素替换。
Fieldset 不维护字段值或校验队列。请使用 Form + TextField / SearchField,提交与 reset 沿用原生表单;示例展示实际 FormData 与成功反馈,不执行后台保存。
Fieldset 不维护字段值或校验队列。请使用 Form + TextField / SearchField,提交与 reset 沿用原生表单;示例以 `alert` 给出成功反馈,不执行后台保存。
## 相关组件
+24 -24
View File
@@ -80,32 +80,32 @@ import { Form, Button } from "@heroui-vue/components";
Form 复用本库共享字段上下文与浏览器 Constraint Validation API。`FormRoot` 是同一组件别名;原生属性、ARIA、class、style 与 DOM 监听器透传到实际 form。
| Prop / 事件 | 类型 | 默认值 | 描述 |
| --- | --- | --- | --- |
| `action` | `string` | - | 提交表单数据的 URL;保留浏览器传统提交 |
| `class` | Vue class 绑定 | - | 应用于 form 元素的布局与样式 |
| 默认插槽 | `() => VNodeChild` | - | 表单内容(字段、按钮等) |
| `enctype` | `string` | - | 原生编码类型,如 `multipart/form-data` |
| `method` | `string` | - | 原生提交方法,如 `get` / `post` |
| `@invalid` | `(event: Event) => void` | - | 每个无效控件每次检查通知一次;`preventDefault()` 取消默认焦点,不放行无效提交 |
| `@reset` | `(event: Event) => void` | - | 原生重置事件;可 `preventDefault()` 取消 |
| `@submit` | `(event: SubmitEvent) => void` | - | 校验通过或显式跳过校验时调用;使用 `.prevent` 接管提交 |
| `target` | `string` | - | 提交后显示响应的位置 |
| `validationBehavior` | `'native' \| 'aria'` | `'native'` | 默认字段校验策略;字段可覆盖 |
| `validationErrors` | `Record<string, string \| string[]>` | `{}` | 按字段名映射的服务端错误;编辑该字段后忽略当前响应中的错误 |
| `aria-label` | `string` | - | 表单的无障碍名称 |
| `aria-labelledby` | `string` | - | 标注表单的元素 ID |
| `novalidate` / `noValidate` | `boolean` | `false`(调用方意图) | 为 `true` 或空属性时跳过本库提交检查;实际 DOM 始终有 novalidate,见下文 |
| `render`(上游) | Vue attrs / 默认插槽替代 | - | 添加原生属性直接透传;不移植 React DOMRenderFunction |
| Prop / 事件 | 类型 | 默认值 | 描述 |
| --------------------------- | ------------------------------------ | --------------------- | ----------------------------------------------------------------------------- |
| `action` | `string` | - | 提交表单数据的 URL;保留浏览器传统提交 |
| `class` | Vue class 绑定 | - | 应用于 form 元素的布局与样式 |
| 默认插槽 | `() => VNodeChild` | - | 表单内容(字段、按钮等) |
| `enctype` | `string` | - | 原生编码类型,如 `multipart/form-data` |
| `method` | `string` | - | 原生提交方法,如 `get` / `post` |
| `@invalid` | `(event: Event) => void` | - | 每个无效控件每次检查通知一次;`preventDefault()` 取消默认焦点,不放行无效提交 |
| `@reset` | `(event: Event) => void` | - | 原生重置事件;可 `preventDefault()` 取消 |
| `@submit` | `(event: SubmitEvent) => void` | - | 校验通过或显式跳过校验时调用;使用 `.prevent` 接管提交 |
| `target` | `string` | - | 提交后显示响应的位置 |
| `validationBehavior` | `'native' \| 'aria'` | `'native'` | 默认字段校验策略;字段可覆盖 |
| `validationErrors` | `Record<string, string \| string[]>` | `{}` | 按字段名映射的服务端错误;编辑该字段后忽略当前响应中的错误 |
| `aria-label` | `string` | - | 表单的无障碍名称 |
| `aria-labelledby` | `string` | - | 标注表单的元素 ID |
| `novalidate` / `noValidate` | `boolean` | `false`(调用方意图) | 为 `true` 或空属性时跳过本库提交检查;实际 DOM 始终有 novalidate,见下文 |
| `render`(上游) | Vue attrs / 默认插槽替代 | - | 添加原生属性直接透传;不移植 React DOMRenderFunction |
公开类型包含 `FormProps`、`FormRootProps`、`FormSlots`、`FormExpose`。实例能力是 Vue 扩展:
| 实例成员 | 类型 | 说明 |
| --- | --- | --- |
| `element` | `HTMLFormElement \| undefined` | 挂载后实际 form |
| `checkValidity()` | `() => boolean` | 按 native/aria 策略检查并产生 invalid;不自动聚焦 |
| `reportValidity()` | `() => boolean` | 检查并聚焦首个无效字段,除非调用方取消;错误由 FieldError 展示,不重复调用原生气泡校验 |
| `reset()` | `() => void` | 调用原生 form.reset(),遵守取消与既有受控值协议 |
| 实例成员 | 类型 | 说明 |
| ------------------ | ------------------------------ | -------------------------------------------------------------------------------------- |
| `element` | `HTMLFormElement \| undefined` | 挂载后实际 form |
| `checkValidity()` | `() => boolean` | 按 native/aria 策略检查并产生 invalid;不自动聚焦 |
| `reportValidity()` | `() => boolean` | 检查并聚焦首个无效字段,除非调用方取消;错误由 FieldError 展示,不重复调用原生气泡校验 |
| `reset()` | `() => void` | 调用原生 form.reset(),遵守取消与既有受控值协议 |
### Form Validation
@@ -174,7 +174,7 @@ Form 与共享字段组件协作:
- 错误通过 FieldError 与真实控件的 ARIA 描述关联。
- `validationBehavior="aria"` 保留错误语义但不阻止提交。
三个预览沿用固定源的字段、文案、校验与布局;为适应窄屏增加 `max-w-full`,提交结果用页内 `status` 替代上游 `alert`,reset 同时清除该反馈。React 专属机制按上述 Vue 方式适配。当前仅支持浏览器客户端;未将完整读屏矩阵或逐像素比较视为已完成。
三个预览沿用固定源的字段、文案、校验、布局与提交反馈:有效提交以 `alert` 展示表单数据,`reset` 重置字段与校验错误。React 专属机制按上述 Vue 方式适配。当前仅支持浏览器客户端;未将完整读屏矩阵或逐像素比较视为已完成。
## 相关案例
-2
View File
@@ -167,8 +167,6 @@ InputGroup 会自动反映父级 TextField 的无效状态。
多行输入请使用 **InputGroupTextArea**,并搭配前缀与后缀。当存在 textarea 时,容器高度会自动适应内容,并将前缀/后缀与顶部对齐。
上游示例中的 Tooltip 由原生 `title` 与 `aria-label` 适配(Tooltip 组件尚未迁移)。
<ComponentPreview name="input-group-with-textarea" />
## 自定义样式
+1 -1
View File
@@ -52,7 +52,7 @@ import { Label, Input } from "@heroui-vue/components";
<template>
<Label for="password" is-invalid>密码</Label>
<Input id="password" type="password" />
<Input id="password" invalid />
</template>
```
+1 -1
View File
@@ -392,7 +392,7 @@ NumberFieldDecrementButton 支持原生 button 属性、事件、`isDisabled`
- FormData 只提交一份未格式化的完整数值,显示货币或百分比不改变提交值。native 校验阻止无效提交;aria 只展示状态。reset 尊重取消,非受控恢复初值,受控保留父值。validate 为同步函数;不提供 RAC validationDetails。
- React render prop 对应默认作用域插槽;class/style 函数改用 Vue 绑定,不支持 React PressEvent。渲染函数示例用 data-custom 透传表达相同默认 div 的自定义属性,不宣称支持任意 React render 回调。
- 增减按钮的 click 可取消;支持指针按住重复、释放/取消/移出清理及键盘激活。默认图标移植上游公共图标,自定义图标示例使用 Tabler Vue。任意非原生交互 asChild 根的键盘语义由调用方负责。
- 校验示例的百分比模型按 0–1 判断(原演示将模型与 0–100 混用);表单示例仅本地模拟提交,反馈与定时器清理不代表真实业务请求。
- 校验示例的百分比模型按 0–1 判断(原演示将模型与 0–100 混用);表单示例与基线一致,仅本地模拟提交并将提交值输出到控制台,定时器清理不代表真实业务请求。
- SSR 关联预规划支持直接部件、原生包装及 NumberFieldGroup。自定义 Vue 包装内部的 ID 请显式指定;完整读屏、触屏及 Nuxt 验收以验证报告为准。
- 上游 Input API 表还列有 variant,但固定实现只从根生成样式;Vue 同样使用根 variant,自定义 Input 外观通过 class/style,不暴露无效的叶子 variant 参数。
+1 -1
View File
@@ -103,7 +103,7 @@ SearchField 组件支持两种视觉变体:
### 表单示例
完整的表单集成示例,包含校验、实际 FormData 和模拟提交反馈;没有后台搜索请求。
完整的表单集成示例,包含校验与模拟提交(提交值输出到控制台);没有后台搜索请求。
<ComponentPreview name="search-field-form-example" />
+1 -1
View File
@@ -341,7 +341,7 @@ Select 组件使用以下 CSS 类([查看源码样式](https://github.com/hero
- 关闭态从已知 ListBox/Section/Item 插槽预规划元数据;不执行任意包装组件的 setup/render。不透明包装请提供 Select 的 `items`,否则首次打开前未知选项只能显示 key,且无法提交未知选项。
- 唯一原生 select 提交层保留字符串边界,多选使用重复 name;类型区分只用于组件值与事件。浏览器自动填充通过选中 option 的索引恢复原始 key,不把内部编码放进 FormData。
- 支持原生必填、重置、Fieldset 与 Form 错误关联;跨浏览器自动填充与实际屏幕阅读器播报仍需专项验收,不声明等同 React Aria 全部能力。
- 样式及 19 个中文示例来自固定 HeroUI 基线;React 渲染函数改为 Vue 插槽,文档的表单成功反馈使用内联状态,图标扩展示例使用 Tabler。
- 样式及 19 个中文示例来自固定 HeroUI 基线;React 渲染函数改为 Vue 插槽,表单成功反馈与基线一致使用 `alert`,图标扩展示例使用 Tabler。
## 相关组件
+1 -1
View File
@@ -452,7 +452,7 @@ TimeFieldSuffix 接受标准 HTML `div` 属性:
- `locale` / `dir` 默认读取 ConfigProvider(否则 en-US / ltr);可显式覆盖。`form` 支持外部表单,`autoComplete` 默认 off;`disabled` 是 isDisabled 的原生别名。Root 暴露 `element` / `focus()`。
- React `render` 改为 `as` 和原生 attrs;children render prop 改默认作用域插槽。class/style 函数不直接移植,使用插槽状态和 Vue 绑定。没有声明继承全部 RAC props;Reka 的 step/stepSnapping 不作为额外公共 API。
- Group 支持 `variant`、`fullWidth`、`as`;Input、InputContainer、Segment、Prefix、Suffix 支持 `as` 和原生 attrs,Segment 还要求 `segment`。Input 的视觉变体由 Group 设置。取消按键需在实际 Segment 上使用 `@keydown.prevent`(可按需 stop);Root 的冒泡监听晚于分段编辑,不能撤销已经完成的子处理。
- 表单示例在模拟提交后显示实际提交值并清空;替代上游控制台反馈,保留 1500ms 加载流程并在卸载时清理计时器。
- 表单示例与基线一致:模拟提交(1500ms 加载)后将实际提交值输出到控制台并清空输入,卸载时清理计时器。
- 当前仅支持浏览器客户端。未开展完整系统 IME、读屏、真机或逐像素自动对比专项。
Enter 在实际 Segment 上触发所属原生表单的 `requestSubmit()`(支持外部 form),遵守原生约束校验和 `@keydown.prevent`。blur 不重复发送已经接受的值。
+7 -7
View File
@@ -274,13 +274,13 @@ Toast 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/
### ToastActionButton
| Prop / 事件 | 类型 | 默认值 | 描述 |
| ---------------------------- | ------------ | ------------- | --------------------------------------------------------------- |
| `variant` | Button 变体 | `'secondary'` | 按钮变体 |
| `size` | Button 尺寸 | `'sm'` | 按钮尺寸 |
| `isDisabled` | `boolean` | `false` | 禁用 |
| `@click` | `MouseEvent` | — | 默认命令式动作先调用用户处理,再关闭;preventDefault 可阻止关闭 |
| 其余 Button props / 默认插槽 | 见 Button | — | 透传给基础 Button;自定义插槽中的按钮可调用 close |
| Prop / 事件 | 类型 | 默认值 | 描述 |
| ---------------------------- | ------------ | ----------- | --------------------------------------------------------------- |
| `variant` | Button 变体 | `'primary'` | 按钮变体(与上游一致,回落到 Button 默认变体) |
| `size` | Button 尺寸 | `'md'` | 按钮尺寸(与上游一致,回落到 Button 默认尺寸) |
| `isDisabled` | `boolean` | `false` | 禁用 |
| `@click` | `MouseEvent` | — | 默认命令式动作先调用用户处理,再关闭;preventDefault 可阻止关闭 |
| 其余 Button props / 默认插槽 | 见 Button | — | 透传给基础 Button;自定义插槽中的按钮可调用 close |
### ToastCloseButton
+158
View File
@@ -0,0 +1,158 @@
---
title: 组合
description: 使用组件组合模式构建灵活的 UI
---
组合的目标是在保留组件语义、状态和可访问行为的同时调整外观与结构。Vue 使用具名部件、普通属性、`v-model`、具名/作用域插槽,以及按需支持的 `as` / `asChild`。
## 与框架无关的样式
`@heroui-vue/styles` 提供变体函数和 CSS,不运行 React。只想把组件样式用于原生元素时,可以从样式包导入函数:
```ts
import { buttonVariants, tv, type VariantProps } from "@heroui-vue/styles";
import "@heroui-vue/styles/css";
```
当前完整 CSS 通过 `/css` 导入,JS 根导出提供变体函数;没有公开官方那套 `/components/button.css`、`/themes/default` 等子路径。按需入口仍是后续任务,见[导入策略](/themes#导入策略)。
## 多态样式
可将样式应用到符合实际用途的原生元素。例如导航链接可以采用按钮外观,而实际操作继续使用 button:
<ComponentPreview name="handbook-composition" />
第一个元素仍是链接,后两个示例展示实际 Button 与 Link。样式相似不代表键盘模型相同;不要把所有元素统一改成 div,也不要用 `role="button"` 掩盖缺少键盘处理的问题。
## 直接应用类名
用完整 BEM 类名可复用预编译样式:
```html
<a class="hv-button hv-button--secondary hv-button--md" href="/settings">
Settings
</a>
```
此时只有样式,禁用、加载、焦点管理和表单行为由元素与应用负责。本库组件通常是获得完整交互的更直接方式。
## 使用变体函数
变体函数决定类名和默认变体,不建立 Vue 状态:
```vue
<script setup lang="ts">
import { buttonVariants } from "@heroui-vue/styles";
</script>
<template>
<a
href="/settings"
:class="buttonVariants({ variant: 'secondary', size: 'sm' })"
>
Settings
</a>
</template>
```
Button 的函数返回类名字符串;Card、Popover 等带 slots 的函数返回部件函数集合。按函数真实返回类型使用,例如 `cardVariants().base()`,不要假定所有 variants 都有相同的返回结构。
## 复合组件
复杂组件导出协同工作的具名部件,不采用默认的 React `Popover.Trigger` 对象写法:
```vue
<script setup lang="ts">
import {
Button,
Popover,
PopoverContent,
PopoverDialog,
PopoverHeading,
} from "@heroui-vue/components";
</script>
<template>
<Popover>
<Button>打开</Button>
<PopoverContent>
<PopoverDialog>
<PopoverHeading>标题</PopoverHeading>
内容
</PopoverDialog>
</PopoverContent>
</Popover>
</template>
```
`PopoverRoot` 是 `Popover` 的同一实现别名;按各组件公开导出选择。需要上下文的 Trigger、Item、Content 不能脱离对应 Root 任意放置。复杂包装应透传显式数据和插槽,不通过执行未知子组件的 setup/render 来探测元数据。
普通值使用 `v-model`;展开状态通常使用 `v-model:open`,二态控件按 API 使用 `v-model:checked`。Root 与子控件不要绑定两个相互冲突的值源。受控组件会发出更新提案,父级可以拒绝,显示值仍应保持父级接受值。
## 混合使用变体函数
`cn` 可以合并类名,`tv` 可以扩展变体。注意多个组件的根样式可能同时定义尺寸、布局和 transform,不应仅为拼出外观就叠加互相冲突的根类。
```ts
import { cn, buttonVariants } from "@heroui-vue/styles";
const classes = cn(buttonVariants({ variant: "ghost" }), "font-semibold");
```
应用新增的工具类需要由自己的构建产出。合并函数不会生成 CSS,也不会让未公开的变体名称自动成为组件 prop。
## 自定义组件
把可复用业务布局包装成 Vue 组件时,明确以下边界:
- `$attrs`、class/style、ARIA 和原生事件落到哪个实际节点。
- `v-model` 是否保留受控接受值和更新事件。
- 默认、具名和作用域插槽分别传给哪个部件。
- ref 返回包装组件还是实际控件;需要的方法通过 `defineExpose` 明确公开。
多根组件设置 `inheritAttrs: false` 并显式转交属性。事件取消、capture 和子节点监听必须保持正确顺序,不能同时手动调用和再次透传导致双触发。包装示例见[创建包装组件](/styling#创建包装组件)。
## 自定义变体
扩展样式函数,不改写原组件已定义的 prop 取值:
```ts
import { buttonVariants, tv, type VariantProps } from "@heroui-vue/styles";
export const customButton = tv({
extend: buttonVariants,
variants: {
emphasis: { quiet: "opacity-80", strong: "font-bold" },
},
defaultVariants: { emphasis: "quiet" },
});
export type CustomButtonVariants = VariantProps<typeof customButton>;
```
将计算结果通过 class 传给 Button;`emphasis` 属于你的包装组件,不是库 Button 新增的 API。不要直接向 Button 传入不存在的 `variant="gradient"`。
## 自定义 DOM 元素
支持 `asChild` 的部件把自身属性、交互与默认插槽中的唯一根节点合并。Button 的根仍需是原生 button:
```vue
<Button as-child v-slot="{ isPressed }">
<button type="button" :data-custom="isPressed ? 'pressed' : 'idle'">点按</button>
</Button>
```
遵循组件期待的元素语义;保留唯一根;自定义 Vue 组件继续把属性、事件和 ref 边界转交到实际 DOM。原生 submit/reset、disabled、focus 和 ARIA 不能因换根而丢失。Button 与 Link 的行为模型不同,支持 `asChild` 不等于任意元素都可互换。
`as` 一般选择组件支持的标签,`asChild` 合并已有根;两者范围由各组件 API 决定。不要将 React 的 `render` 或 `ref` prop 原样传入 Vue。
## 框架集成
Vue 客户端应用可直接使用原生链接。路由器适配可用它提供的自定义链接插槽或把导航外观用于路由链接,前提是仍生成正确的 anchor 并透传 href、事件与可访问属性。基础包不强依赖 Vue Router。
Next.js 示例不适用于 Vue;当前不提供 Nuxt 服务端消费承诺。第三方路由和动画包装的全部组合尚未逐项验收,应按真实 DOM、键盘、事件取消和实例方法检查,不能只凭 TypeScript 编译通过判断可用。
## 下一步
- [样式](/styling):类名、CSS Modules 与状态。
- [动画](/animation):动画和卸载的协调。
- [所有组件](/components):逐组件的 Props、插槽和状态契约。
+95
View File
@@ -0,0 +1,95 @@
---
title: 深色模式
description: 在 HeroUI v3 中添加浅色、深色以及跟随系统的主题切换
---
主题的实际外观由 CSS 变量决定;选择浅色、深色或跟随系统、保存偏好以及更新根元素标记,是应用的职责。支持 `.light`、`.dark` 和内置的 `data-theme` 值。下面示例只影响预览容器,不会修改你在文档站选择的外观。
<ComponentPreview name="handbook-dark-mode" />
## 在 Next.js 中使用 next-themes
官方这一节面向 React/Next.js。Vue 客户端项目不使用 `next-themes`,当前也不支持 SSR、水合或 Nuxt 服务端渲染。客户端应用可以在入口引入库样式,再由自己的状态逻辑更新 `<html>`。
```ts
import "@heroui-vue/styles/css";
function applyTheme(theme: "light" | "dark") {
const root = document.documentElement;
root.classList.toggle("light", theme === "light");
root.classList.toggle("dark", theme === "dark");
root.dataset.theme = theme;
}
```
这段函数在浏览器中调用。将主题放在根元素上,挂载到 body 的浮层也能继承。不要把服务端注入、无闪烁水合等能力推断为本库支持。
## 使用自定义主题名称
自定义主题名称需要有对应的 CSS 选择器,并明确它所采用的明暗模式。内置 CSS 不会自动识别 `ocean` 这样的任意名称。
```html
<html class="dark" data-theme="ocean"></html>
```
```css
/* 放在库 CSS 之后 */
.light[data-theme="ocean"] {
--accent: oklch(0.62 0.2 253.83);
--accent-foreground: var(--snow);
}
.dark[data-theme="ocean"] {
--accent: oklch(0.72 0.16 253.83);
--accent-foreground: var(--eclipse);
}
```
让 `.dark` 与 `data-theme` 表达一致的选择,避免 `.dark[data-theme="light"]` 等冲突组合。局部容器与 Portal 的边界见[主题](/themes#快速开始)。
## 在 React 中使用 useTheme
官方的 `useTheme` 是 React API,当前 Vue 组件包没有同名导出。Vue 应用可以采用已有的 VueUse,不需要为了使用组件再安装一套 React 主题管理器。
如果应用已使用 VueUse,可以在应用级单一入口调用 `useColorMode`:
```vue
<script setup lang="ts">
import { useColorMode } from "@vueuse/core";
const mode = useColorMode({
storageKey: "app-appearance",
emitAuto: true,
});
// mode.value: 'light' / 'dark' / 'auto';auto 表示跟随系统。
// 默认更新 html 的 class,并保存应用自己的偏好。
</script>
<template>
<label>
外观
<select v-model="mode">
<option value="light">浅色</option>
<option value="dark">深色</option>
<option value="auto">跟随系统</option>
</select>
</label>
</template>
```
VueUse 是应用的可选依赖,使用前在应用内安装;它不是从 `@heroui-vue/components` 导入。顶部示例用 `usePreferredDark` 解析系统偏好,保留独立预览状态,不写入存储。应保存用户选择的模式,而不是把 `auto` 固化为某次解析出的 `dark`。
## 同时为两种主题设置样式
优先使用语义变量,它们会随主题变化:
```css
.panel {
background: var(--surface);
color: var(--surface-foreground);
border: 1px solid var(--border);
}
```
只在两种模式确实需要不同规则时使用显式选择器。Vue 单文件组件内可用 `:global(.dark) .panel`,CSS Modules 可使用 `$style` 配合全局主题选择器。使用 Tailwind `dark:` 时由应用配置对应变体;仅导入库的预编译 CSS 不会改变应用编译器的规则。
系统 `prefers-color-scheme` 本身不会为本库全部主题变量自动添加 `.dark`;需要应用逻辑解析偏好并更新主题标记。主题控制的完整兼容性仍在后续排查范围中,不把文档站自己的切换器等同于库的公共 API。
+3 -2
View File
@@ -9,7 +9,7 @@ import {
AccordionTrigger,
} from "@heroui-vue/components";
import {
IconArrowsLeftRight,
IconRefresh,
IconBox,
IconChevronDown,
IconCreditCard,
@@ -24,7 +24,7 @@ const iconMap = {
cart: IconShoppingBag,
earth: IconWorld,
receipt: IconReceipt,
rotate: IconArrowsLeftRight,
rotate: IconRefresh,
} as const;
function iconFor(key: keyof typeof iconMap) {
@@ -77,6 +77,7 @@ const items = [
<span class="me-3 size-4 shrink-0 text-muted">
<component
:is="iconFor(item.icon as keyof typeof iconMap)"
class="size-4"
aria-hidden="true"
/>
</span>
+53 -21
View File
@@ -8,34 +8,66 @@ import {
AccordionPanel,
AccordionTrigger,
} from "@heroui-vue/components";
import { IconChevronDown } from "@tabler/icons-vue";
const items = [
{
content: "通过实时通知及时了解账户动态。",
iconUrl:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/3dicons/bell-small.png",
subtitle: "接收账户活动更新",
title: "开启通知",
},
{
content: "安装我们的官方浏览器扩展,获得更顺畅的浏览体验。",
iconUrl:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/3dicons/compass-small.png",
subtitle: "将浏览器连接到你的账户",
title: "安装浏览器扩展",
},
{
content: "创建你的第一件数字藏品,开启数字收藏之旅。",
iconUrl:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/3dicons/mint-collective-small.png",
subtitle: "创建你的第一件收藏品",
title: "铸造收藏品",
},
];
</script>
<template>
<Accordion class="w-full max-w-md rounded-xl bg-gray-50 dark:bg-neutral-900">
<AccordionItem>
<Accordion
class="bg-surface-1/10 w-full max-w-md rounded-2xl"
variant="surface"
>
<AccordionItem
v-for="(item, index) in items"
:key="index"
class="group/item first:**:data-[slot=accordion-trigger]:rounded-t-2xl last:[&:not(:has([data-slot=accordion-trigger][aria-expanded='true']))_[data-slot=accordion-trigger]]:rounded-b-2xl"
>
<AccordionHeading>
<AccordionTrigger class="text-lg font-semibold">
自定义标题字号
<AccordionIndicator />
<AccordionTrigger
class="group flex items-center gap-2 transition-none hover:bg-surface"
>
<img
v-if="item.iconUrl"
:alt="item.title"
class="h-11 w-11 transition-[scale,rotate] duration-300 ease-out group-hover/item:scale-120 group-hover/item:-rotate-10 group-hover/item:drop-shadow-lg"
:src="item.iconUrl"
/>
<div class="flex flex-col gap-0">
<span class="leading-5 font-medium">{{ item.title }}</span>
<span class="leading-6 font-normal text-muted/80">
{{ item.subtitle }}
</span>
</div>
<AccordionIndicator class="text-muted/50 [&>svg]:size-4">
<IconChevronDown />
</AccordionIndicator>
</AccordionTrigger>
</AccordionHeading>
<AccordionPanel>
<AccordionBody class="text-base text-foreground">
通过覆盖 trigger 与 body 的 class,可以快速调整字号与颜色。
</AccordionBody>
</AccordionPanel>
</AccordionItem>
<AccordionItem>
<AccordionHeading>
<AccordionTrigger class="text-lg font-semibold">
描边容器
<AccordionIndicator />
</AccordionTrigger>
</AccordionHeading>
<AccordionPanel>
<AccordionBody class="rounded-lg border-2 border-border p-4 shadow-lg">
给根容器加边框与阴影,得到描边变体的观感。
</AccordionBody>
<AccordionBody class="text-muted/80">{{ item.content }}</AccordionBody>
</AccordionPanel>
</AccordionItem>
</Accordion>
@@ -9,7 +9,7 @@ import {
AccordionTrigger,
} from "@heroui-vue/components";
import {
IconArrowsLeftRight,
IconRefresh,
IconBox,
IconChevronDown,
IconCreditCard,
@@ -50,7 +50,7 @@ const items = [
{
content:
"若对购买不满意,可在购买后 30 天内申请退款。请联系客服团队协助处理。",
icon: IconArrowsLeftRight,
icon: IconRefresh,
title: "如何申请退款?",
},
];
@@ -67,7 +67,7 @@ const items = [
<AccordionHeading as="div" data-custom="heading">
<AccordionTrigger as="button" data-custom="trigger">
<span class="me-3 size-4 shrink-0 text-muted">
<component :is="item.icon" aria-hidden="true" />
<component :is="item.icon" class="size-4" aria-hidden="true" />
</span>
{{ item.title }}
<AccordionIndicator>
+3 -2
View File
@@ -9,7 +9,7 @@ import {
AccordionTrigger,
} from "@heroui-vue/components";
import {
IconArrowsLeftRight,
IconRefresh,
IconBox,
IconChevronDown,
IconCreditCard,
@@ -24,7 +24,7 @@ const iconMap = {
cart: IconShoppingBag,
earth: IconWorld,
receipt: IconReceipt,
rotate: IconArrowsLeftRight,
rotate: IconRefresh,
} as const;
function iconFor(key: keyof typeof iconMap) {
@@ -77,6 +77,7 @@ const items = [
<span class="me-3 size-4 shrink-0 text-muted">
<component
:is="iconFor(item.icon as keyof typeof iconMap)"
class="size-4"
aria-hidden="true"
/>
</span>
@@ -42,7 +42,7 @@ const items = [
<AccordionHeading>
<AccordionTrigger>
<span class="me-3 size-4 shrink-0 text-muted">
<component :is="item.icon" aria-hidden="true" />
<component :is="item.icon" class="size-4" aria-hidden="true" />
</span>
{{ item.title }}
<AccordionIndicator>
@@ -1,5 +1,8 @@
<script setup lang="ts">
import { IconArrowUp, IconSparkles } from "@tabler/icons-vue";
import {
IconArrowBarUp as ArrowUpFromLine,
IconSparkles,
} from "@tabler/icons-vue";
import {
AlertDialog,
AlertDialogBackdrop,
@@ -28,9 +31,9 @@ const animations = [
},
{
name: "流体滑入",
icon: IconArrowUp,
icon: ArrowUpFromLine,
description:
"模拟在介质中运动并受流体阻力影响,避免机械式线性,更自然、更贴地。",
"模拟在介质中运动并受流体阻力影响,避免机械式线性,更自然、更贴地,适合底部抽屉或 Toast。",
backdropClass:
"data-[entering]:duration-500 data-[entering]:ease-[cubic-bezier(0.25,1,0.5,1)] data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.5,0,0.75,0)]",
containerClass:
@@ -50,10 +50,17 @@ const portalEl = ref<HTMLElement | null>(null);
</AlertDialogHeader>
<AlertDialogBody>
<p class="text-sm text-muted">
此段为示例占位文案,用于演示在自定义容器内渲染对话框时的滚动与排版效果。
此段为示例占位文案,用于演示在自定义容器内渲染对话框时的滚动与排版效果。实际项目中请替换为真实说明内容。
</p>
<p class="text-sm text-muted">
通过将浮层挂载到局部容器,可以配合裁剪、缩放或卡片布局,避免遮挡整个页面。
通过将浮层挂载到局部容器,可以配合裁剪、缩放或卡片布局,避免遮挡整个页面,同时仍保持焦点管理与无障碍行为。
</p>
<p class="text-sm text-muted">
若容器存在
<code>transform</code>
或
<code>filter</code>
等属性,请注意浏览器会为其创建新的包含块,从而影响定位与层级关系。
</p>
</AlertDialogBody>
<AlertDialogFooter>
@@ -29,6 +29,10 @@ import {
aria-hidden="true"
class="pointer-events-none absolute inset-x-0 top-0 h-24 bg-linear-to-b from-accent/6 to-transparent dark:from-accent/10"
/>
<div
aria-hidden="true"
class="pointer-events-none absolute inset-x-8 top-0 h-px bg-linear-to-r from-transparent via-accent/35 to-transparent dark:via-accent/45"
/>
<AlertDialogHeader class="relative">
<AlertDialogIcon status="accent" />
<AlertDialogHeading>确定要退出账户吗?</AlertDialogHeading>
+3 -2
View File
@@ -45,12 +45,13 @@ const sizes = ["xs", "sm", "md", "lg", "cover"] as const;
<p v-if="size === 'cover'">
此警告框使用
<code>cover</code>
尺寸:在移动端与桌面端保留边距铺满可视区域,仍保持圆角与标准内边距。
尺寸:在移动端与桌面端保留边距(移动端约 16px、桌面端约
40px)铺满可视区域,仍保持圆角与标准内边距,适合需要最大宽度又保留对话框气质的关键确认。
</p>
<p v-else>
此警告框使用
<code>{{ size }}</code>
尺寸。在移动端各尺寸都会接近全宽以便阅读;在桌面端则对应不同的最大宽度。
尺寸。在移动端各尺寸都会接近全宽以便阅读;在桌面端则对应不同的最大宽度,以适配不同信息量。
</p>
</AlertDialogBody>
<AlertDialogFooter>
+2 -9
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Autocomplete,
AutocompleteClearButton,
@@ -41,13 +40,10 @@ const countries = [
{ id: "germany", name: "Germany" },
];
const message = ref<string | null>(null);
function onSubmit(event: Event) {
event.preventDefault();
const formData = new FormData(event.currentTarget as HTMLFormElement);
void formData;
message.value = "表单提交成功!";
// The Form guard already blocks invalid submits, so a reached handler is valid.
alert("表单提交成功!");
}
</script>
@@ -144,8 +140,5 @@ function onSubmit(event: Event) {
<FieldError />
</Autocomplete>
<Button type="submit">提交</Button>
<p v-if="message" role="status" class="text-sm text-muted">
{{ message }}
</p>
</Form>
</template>
+6 -3
View File
@@ -1,8 +1,11 @@
<script setup lang="ts">
import { ref } from "vue";
import { Button } from "@heroui-vue/components";
const pressed = ref(false);
function onPress() {
console.log("按钮已按下");
}
</script>
<template>
<Button @click="pressed = true">{{ pressed ? "按钮已按下" : "点我" }}</Button>
<Button @click="onPress">点我</Button>
</template>
+1 -1
View File
@@ -2,7 +2,7 @@
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="demo-row">
<div class="flex flex-wrap gap-3">
<Button is-disabled variant="primary">主要</Button>
<Button is-disabled variant="secondary">次要</Button>
<Button is-disabled variant="tertiary">第三</Button>
+202 -12
View File
@@ -1,20 +1,210 @@
<script setup lang="ts">
import {
ButtonGroup,
Button,
ButtonGroup,
ButtonGroupSeparator,
Chip,
Description,
DropdownItem,
DropdownMenu,
DropdownPopover,
DropdownRoot,
DropdownTrigger,
Label,
} from "@heroui-vue/components";
import {
IconChevronDown,
IconChevronLeft,
IconChevronRight,
IconDots,
IconGitFork,
IconPhoto,
IconPin,
IconQrcode,
IconStar,
IconAlignCenter,
IconAlignJustified,
IconAlignLeft,
IconAlignRight,
IconThumbDown,
IconThumbUp,
IconVideo,
} from "@tabler/icons-vue";
</script>
<template>
<ButtonGroup>
<Button>First</Button>
<Button>
<ButtonGroupSeparator />
Second
</Button>
<Button>
<ButtonGroupSeparator />
Third
</Button>
</ButtonGroup>
<div class="flex flex-col items-start gap-6">
<!-- 单个按钮与下拉菜单 -->
<div class="flex flex-col gap-2">
<ButtonGroup>
<Button>合并拉取请求</Button>
<DropdownRoot>
<DropdownTrigger>
<Button is-icon-only aria-label="更多选项">
<ButtonGroupSeparator />
<IconChevronDown aria-hidden="true" />
</Button>
</DropdownTrigger>
<DropdownPopover class="max-w-[290px]" placement="bottom end">
<DropdownMenu>
<DropdownItem
id="merge"
class="flex flex-col items-start gap-1"
text-value="创建合并提交"
>
<Label>创建合并提交</Label>
<Description>此分支上的所有提交都将加入基础分支</Description>
</DropdownItem>
<DropdownItem
id="squash-and-merge"
class="flex flex-col items-start gap-1"
text-value="压缩并合并"
>
<Label>压缩并合并</Label>
<Description>
此分支上的 14 个提交将合并为一次提交并加入基础分支
</Description>
</DropdownItem>
<DropdownItem
id="rebase-and-merge"
class="flex flex-col items-start gap-1"
text-value="变基并合并"
>
<Label>变基并合并</Label>
<Description>
此分支上的 14 个提交将变基后加入基础分支
</Description>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</ButtonGroup>
</div>
<!-- 独立按钮 -->
<div class="flex flex-col gap-2">
<div class="flex flex-wrap gap-x-2 gap-y-4">
<ButtonGroup variant="tertiary">
<Button>
<IconGitFork class="size-3.5" aria-hidden="true" />
复刻
<Chip color="accent" size="sm" variant="soft">24</Chip>
</Button>
<Button is-icon-only aria-label="更多复刻选项">
<ButtonGroupSeparator />
<IconChevronDown aria-hidden="true" />
</Button>
</ButtonGroup>
<ButtonGroup variant="tertiary">
<Button is-icon-only aria-label="显示二维码">
<IconQrcode aria-hidden="true" />
</Button>
<Button>
<ButtonGroupSeparator />
扫码支付
</Button>
</ButtonGroup>
<ButtonGroup variant="tertiary">
<Button>
<IconThumbUp aria-hidden="true" />
<span class="text-xs font-semibold">2.4K</span>
</Button>
<Button is-icon-only aria-label="点踩">
<ButtonGroupSeparator />
<IconThumbDown aria-hidden="true" />
</Button>
</ButtonGroup>
<ButtonGroup variant="tertiary">
<Button>
<IconStar class="size-3.5" aria-hidden="true" />
星标
</Button>
<Button class="px-2">
<ButtonGroupSeparator />
<Chip color="accent" size="sm" variant="soft">104</Chip>
</Button>
</ButtonGroup>
<ButtonGroup variant="tertiary">
<Button>
<IconPin aria-hidden="true" />
已置顶
</Button>
<Button is-icon-only aria-label="更多置顶选项">
<ButtonGroupSeparator />
<IconChevronDown aria-hidden="true" />
</Button>
</ButtonGroup>
</div>
</div>
<!-- 上一页 / 下一页 -->
<div class="flex flex-col gap-2">
<ButtonGroup variant="tertiary">
<Button>
<IconChevronLeft aria-hidden="true" />
上一页
</Button>
<Button>
<ButtonGroupSeparator />
下一页
<IconChevronRight aria-hidden="true" />
</Button>
</ButtonGroup>
</div>
<!-- 内容类型选择 -->
<div class="flex flex-col gap-2">
<ButtonGroup variant="tertiary">
<Button>
<IconPhoto aria-hidden="true" />
照片
</Button>
<Button>
<ButtonGroupSeparator />
<IconVideo aria-hidden="true" />
视频
</Button>
<Button is-icon-only aria-label="更多选项">
<ButtonGroupSeparator />
<IconDots aria-hidden="true" />
</Button>
</ButtonGroup>
</div>
<!-- 文本对齐 -->
<div class="flex flex-col gap-2">
<ButtonGroup variant="tertiary">
<Button>左对齐</Button>
<Button>
<ButtonGroupSeparator />
居中
</Button>
<Button>
<ButtonGroupSeparator />
右对齐
</Button>
</ButtonGroup>
</div>
<!-- 仅图标:对齐 -->
<div class="flex flex-col gap-2">
<ButtonGroup variant="tertiary">
<Button is-icon-only aria-label="左对齐">
<IconAlignLeft aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="居中对齐">
<ButtonGroupSeparator />
<IconAlignCenter aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="右对齐">
<ButtonGroupSeparator />
<IconAlignRight aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="两端对齐">
<ButtonGroupSeparator />
<IconAlignJustified aria-hidden="true" />
</Button>
</ButtonGroup>
</div>
</div>
</template>
+58 -10
View File
@@ -1,20 +1,68 @@
<script setup lang="ts">
import {
ButtonGroup,
Button,
ButtonGroup,
ButtonGroupSeparator,
Description,
DropdownItem,
DropdownMenu,
DropdownPopover,
DropdownRoot,
DropdownTrigger,
Label,
} from "@heroui-vue/components";
import { IconChevronDown } from "@tabler/icons-vue";
</script>
<template>
<ButtonGroup class="gap-2 rounded-lg">
<Button class="rounded-lg">First</Button>
<Button class="rounded-lg">
<ButtonGroupSeparator class="opacity-25" />
Second
</Button>
<Button class="rounded-lg">
<ButtonGroupSeparator class="opacity-25" />
Third
<ButtonGroup>
<Button class="rounded-none bg-[#08872B] data-hovered:bg-[#0FBF3E]">
合并拉取请求
</Button>
<DropdownRoot>
<DropdownTrigger>
<Button
is-icon-only
aria-label="合并选项"
class="rounded-none bg-[#08872B] data-hovered:bg-[#0FBF3E]"
>
<ButtonGroupSeparator />
<IconChevronDown class="size-4" aria-hidden="true" />
</Button>
</DropdownTrigger>
<DropdownPopover
class="max-w-[290px] rounded-none"
placement="bottom end"
>
<DropdownMenu>
<DropdownItem
id="merge"
class="flex flex-col items-start gap-1 rounded-none"
text-value="创建合并提交"
>
<Label>创建合并提交</Label>
<Description>此分支的所有提交将添加到基础分支</Description>
</DropdownItem>
<DropdownItem
id="squash-and-merge"
class="flex flex-col items-start gap-1 rounded-none"
text-value="压缩并合并"
>
<Label>压缩并合并</Label>
<Description>
此分支的 14 个提交将在基础分支中合并为一个提交
</Description>
</DropdownItem>
<DropdownItem
id="rebase-and-merge"
class="flex flex-col items-start gap-1 rounded-none"
text-value="变基并合并"
>
<Label>变基并合并</Label>
<Description>此分支的 14 个提交将变基后添加到基础分支</Description>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</ButtonGroup>
</template>
+32 -12
View File
@@ -1,20 +1,40 @@
<script setup lang="ts">
import {
ButtonGroup,
Button,
ButtonGroup,
ButtonGroupSeparator,
} from "@heroui-vue/components";
</script>
<template>
<ButtonGroup is-disabled>
<Button>First</Button>
<Button>
<ButtonGroupSeparator />
Second
</Button>
<Button>
<ButtonGroupSeparator />
Third
</Button>
</ButtonGroup>
<div class="flex flex-col gap-6">
<div class="flex flex-col items-start gap-2">
<p class="text-sm text-muted">全部禁用</p>
<ButtonGroup is-disabled>
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
第二项
</Button>
<Button>
<ButtonGroupSeparator />
第三项
</Button>
</ButtonGroup>
</div>
<div class="flex flex-col items-start gap-2">
<p class="text-sm text-muted">组已禁用,但单个按钮可覆盖</p>
<ButtonGroup is-disabled>
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
第二项
</Button>
<Button :is-disabled="false">
<ButtonGroupSeparator />
第三项(可用)
</Button>
</ButtonGroup>
</div>
</div>
</template>
+24 -5
View File
@@ -1,21 +1,40 @@
<script setup lang="ts">
import {
ButtonGroup,
Button,
ButtonGroup,
ButtonGroupSeparator,
} from "@heroui-vue/components";
import {
IconAlignCenter,
IconAlignLeft,
IconAlignRight,
} from "@tabler/icons-vue";
</script>
<template>
<div class="w-full max-w-md">
<div class="w-[400px] space-y-3">
<ButtonGroup full-width>
<Button>First</Button>
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
Second
第二项
</Button>
<Button>
<ButtonGroupSeparator />
Third
第三项
</Button>
</ButtonGroup>
<ButtonGroup full-width>
<Button is-icon-only aria-label="左对齐">
<IconAlignLeft aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="居中对齐">
<ButtonGroupSeparator />
<IconAlignCenter aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="右对齐">
<ButtonGroupSeparator />
<IconAlignRight aria-hidden="true" />
</Button>
</ButtonGroup>
</div>
+49 -24
View File
@@ -1,33 +1,58 @@
<script setup lang="ts">
import {
ButtonGroup,
Button,
ButtonGroup,
ButtonGroupSeparator,
} from "@heroui-vue/components";
import {
IconAlignCenter,
IconAlignJustified,
IconAlignLeft,
IconAlignRight,
} from "@tabler/icons-vue";
</script>
<template>
<div class="demo-row">
<ButtonGroup orientation="horizontal">
<Button>First</Button>
<Button>
<ButtonGroupSeparator />
Second
</Button>
<Button>
<ButtonGroupSeparator />
Third
</Button>
</ButtonGroup>
<ButtonGroup orientation="vertical">
<Button>First</Button>
<Button>
<ButtonGroupSeparator />
Second
</Button>
<Button>
<ButtonGroupSeparator />
Third
</Button>
</ButtonGroup>
<div class="flex items-start gap-8">
<div class="flex flex-col gap-2">
<span class="text-sm text-muted">横向</span>
<ButtonGroup orientation="horizontal" variant="tertiary">
<Button is-icon-only aria-label="左对齐">
<IconAlignLeft aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="居中对齐">
<ButtonGroupSeparator />
<IconAlignCenter aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="右对齐">
<ButtonGroupSeparator />
<IconAlignRight aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="两端对齐">
<ButtonGroupSeparator />
<IconAlignJustified aria-hidden="true" />
</Button>
</ButtonGroup>
</div>
<div class="flex flex-col gap-2">
<span class="text-sm text-muted">纵向</span>
<ButtonGroup orientation="vertical" variant="tertiary">
<Button is-icon-only aria-label="左对齐">
<IconAlignLeft aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="居中对齐">
<ButtonGroupSeparator />
<IconAlignCenter aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="右对齐">
<ButtonGroupSeparator />
<IconAlignRight aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="两端对齐">
<ButtonGroupSeparator />
<IconAlignJustified aria-hidden="true" />
</Button>
</ButtonGroup>
</div>
</div>
</template>
+37 -14
View File
@@ -1,29 +1,52 @@
<script setup lang="ts">
import {
ButtonGroup,
Button,
ButtonGroup,
ButtonGroupSeparator,
} from "@heroui-vue/components";
const sizes = [
{ size: "sm", label: "Small" },
{ size: "md", label: "Medium (default)" },
{ size: "lg", label: "Large" },
] as const;
</script>
<template>
<div class="flex w-full flex-col gap-6">
<div v-for="item in sizes" :key="item.size" class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">{{ item.label }}</p>
<ButtonGroup :size="item.size">
<Button>First</Button>
<div class="flex flex-col gap-4">
<div class="flex flex-col items-start gap-2">
<p class="text-sm text-muted">小</p>
<ButtonGroup size="sm" variant="secondary">
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
Second
第二项
</Button>
<Button>
<ButtonGroupSeparator />
Third
第三项
</Button>
</ButtonGroup>
</div>
<div class="flex flex-col items-start gap-2">
<p class="text-sm text-muted">中(默认)</p>
<ButtonGroup size="md" variant="secondary">
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
第二项
</Button>
<Button>
<ButtonGroupSeparator />
第三项
</Button>
</ButtonGroup>
</div>
<div class="flex flex-col items-start gap-2">
<p class="text-sm text-muted">大</p>
<ButtonGroup size="lg" variant="secondary">
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
第二项
</Button>
<Button>
<ButtonGroupSeparator />
第三项
</Button>
</ButtonGroup>
</div>
+79 -17
View File
@@ -1,32 +1,94 @@
<script setup lang="ts">
import {
ButtonGroup,
Button,
ButtonGroup,
ButtonGroupSeparator,
} from "@heroui-vue/components";
const variants = [
"primary",
"secondary",
"tertiary",
"outline",
"ghost",
"danger",
] as const;
</script>
<template>
<div class="flex w-full flex-col gap-6">
<div v-for="variant in variants" :key="variant" class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">{{ variant }}</p>
<ButtonGroup :variant="variant">
<Button>First</Button>
<div class="flex flex-col gap-6">
<div class="flex flex-col gap-2">
<p class="text-sm text-muted">主要</p>
<ButtonGroup variant="primary">
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
Second
第二项
</Button>
<Button>
<ButtonGroupSeparator />
Third
第三项
</Button>
</ButtonGroup>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm text-muted">次要</p>
<ButtonGroup variant="secondary">
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
第二项
</Button>
<Button>
<ButtonGroupSeparator />
第三项
</Button>
</ButtonGroup>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm text-muted">第三</p>
<ButtonGroup variant="tertiary">
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
第二项
</Button>
<Button>
<ButtonGroupSeparator />
第三项
</Button>
</ButtonGroup>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm text-muted">线框</p>
<ButtonGroup variant="outline">
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
第二项
</Button>
<Button>
<ButtonGroupSeparator />
第三项
</Button>
</ButtonGroup>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm text-muted">幽灵</p>
<ButtonGroup variant="ghost">
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
第二项
</Button>
<Button>
<ButtonGroupSeparator />
第三项
</Button>
</ButtonGroup>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm text-muted">危险</p>
<ButtonGroup variant="danger">
<Button>第一项</Button>
<Button>
<ButtonGroupSeparator />
第二项
</Button>
<Button>
<ButtonGroupSeparator />
第三项
</Button>
</ButtonGroup>
</div>
+17 -15
View File
@@ -1,43 +1,45 @@
<script setup lang="ts">
import {
ButtonGroup,
Button,
ButtonGroup,
ButtonGroupSeparator,
} from "@heroui-vue/components";
import { IconWorld, IconPlus, IconTrash } from "@tabler/icons-vue";
import { IconSearch, IconPlus, IconTrash } from "@tabler/icons-vue";
</script>
<template>
<div class="flex w-full flex-col gap-6">
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">With icons</p>
<div class="flex flex-col gap-6">
<div class="flex flex-col items-start gap-2">
<p class="text-sm text-muted">带图标</p>
<ButtonGroup variant="secondary">
<Button>
<IconWorld aria-hidden="true" />
Search
<!-- 上游为 Globe;按任务卡保留“搜索”语义,使用搜索字形 -->
<IconSearch aria-hidden="true" />
搜索
</Button>
<Button>
<ButtonGroupSeparator />
<IconPlus aria-hidden="true" />
Add
添加
</Button>
<Button>
<ButtonGroupSeparator />
<IconTrash aria-hidden="true" />
Delete
删除
</Button>
</ButtonGroup>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">Icon only buttons</p>
<div class="flex flex-col items-start gap-2">
<p class="text-sm text-muted">仅图标按钮</p>
<ButtonGroup variant="tertiary">
<Button is-icon-only aria-label="Search">
<IconWorld aria-hidden="true" />
<Button is-icon-only aria-label="搜索">
<IconSearch aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="Add">
<Button is-icon-only aria-label="添加">
<ButtonGroupSeparator />
<IconPlus aria-hidden="true" />
</Button>
<Button is-icon-only aria-label="Delete">
<Button is-icon-only aria-label="删除">
<ButtonGroupSeparator />
<IconTrash aria-hidden="true" />
</Button>
@@ -1,10 +1,11 @@
<script setup lang="ts">
import { ButtonGroup, Button } from "@heroui-vue/components";
import { Button, ButtonGroup } from "@heroui-vue/components";
</script>
<template>
<ButtonGroup>
<Button>First</Button>
<Button>Second</Button>
<Button>Third</Button>
<Button>第一项</Button>
<Button>第二项</Button>
<Button>第三项</Button>
</ButtonGroup>
</template>
+1 -1
View File
@@ -3,7 +3,7 @@ import { IconDots, IconSettings, IconTrash } from "@tabler/icons-vue";
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="demo-row">
<div class="flex gap-3">
<Button is-icon-only variant="tertiary" aria-label="更多选项">
<IconDots aria-hidden="true" />
</Button>
+10 -26
View File
@@ -2,41 +2,25 @@
import { IconPaperclip } from "@tabler/icons-vue";
import { ref, onBeforeUnmount } from "vue";
import { Button, Spinner } from "@heroui-vue/components";
const isLoading = ref(false),
message = ref("");
const isLoading = ref(false);
let timer: ReturnType<typeof setTimeout> | undefined;
function upload() {
if (isLoading.value) return;
isLoading.value = true;
message.value = "";
timer = setTimeout(() => {
isLoading.value = false;
message.value = "上传完成,可以再次上传。";
}, 2000);
}
onBeforeUnmount(() => clearTimeout(timer));
</script>
<template>
<div class="upload-demo">
<Button :is-pending="isLoading" @click="upload">
<Spinner v-if="isLoading" color="current" size="sm" />
<IconPaperclip v-else aria-hidden="true" />
{{ isLoading ? "上传中…" : "上传文件" }}
</Button>
<p class="upload-status" role="status">{{ message }}</p>
</div>
<Button :is-pending="isLoading" @click="upload">
<Spinner v-if="isLoading" color="current" size="sm" />
<IconPaperclip v-else aria-hidden="true" />
{{ isLoading ? "上传中…" : "上传文件" }}
</Button>
</template>
<style scoped>
.upload-demo {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
}
.upload-status {
font-size: 12px;
color: var(--muted);
min-height: 20px;
margin: 0;
}
</style>
+1 -1
View File
@@ -2,7 +2,7 @@
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="demo-row">
<div class="flex items-center gap-3">
<Button size="sm">小</Button>
<Button size="md">中</Button>
<Button size="lg">大</Button>
+1 -1
View File
@@ -2,7 +2,7 @@
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="demo-row">
<div class="flex flex-wrap gap-3">
<Button variant="primary">主要</Button>
<Button variant="secondary">次要</Button>
<Button variant="tertiary">第三</Button>
+1 -1
View File
@@ -8,7 +8,7 @@ import {
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="demo-row">
<div class="flex flex-wrap gap-3">
<Button variant="primary">
<IconSearch aria-hidden="true" />
搜索
+1 -1
View File
@@ -12,7 +12,7 @@ import {
</script>
<template>
<Card class="w-[400px]">
<IconCoin role="img" aria-label="美元图标" class="size-6" />
<IconCoin role="img" aria-label="美元图标" class="text-primary size-6" />
<CardHeader>
<CardTitle>成为 Acme 创作者!</CardTitle>
<CardDescription>
+7 -20
View File
@@ -10,10 +10,12 @@ import {
Link,
} from "@heroui-vue/components";
import { Input, Label } from "@heroui-vue/components";
import { ref, useId } from "vue";
import { useId } from "vue";
const id = useId();
const submitted = ref(false);
const message = ref("");
function onSubmit(event: Event) {
event.preventDefault();
alert("表单提交成功!");
}
</script>
<template>
<Card class="w-full max-w-md">
@@ -21,7 +23,7 @@ const message = ref("");
<CardTitle>登录</CardTitle>
<CardDescription>输入账号信息以访问您的账户</CardDescription>
</CardHeader>
<form class="flex flex-col" @submit.prevent="submitted = true">
<form class="flex flex-col" @submit="onSubmit">
<CardContent>
<div class="flex flex-col gap-4">
<div class="flex flex-col gap-1">
@@ -33,7 +35,6 @@ const message = ref("");
autocomplete="email"
placeholder="email@example.com"
variant="secondary"
required
/>
</div>
<div class="flex flex-col gap-1">
@@ -45,28 +46,14 @@ const message = ref("");
autocomplete="current-password"
placeholder="••••••••"
variant="secondary"
required
/>
</div>
</div>
</CardContent>
<CardFooter class="mt-4 flex flex-col gap-2">
<Button class="w-full" type="submit">登录</Button>
<Link
class="text-center text-sm"
href="#"
@click.prevent="message = '请联系账户管理员重置密码。'"
>
忘记密码?
</Link>
<Link class="text-center text-sm" href="#">忘记密码?</Link>
</CardFooter>
<p
v-if="submitted || message"
role="status"
class="mt-2 text-sm text-muted"
>
{{ message || "表单提交成功!此示例不会发送账号信息。" }}
</p>
</form>
</Card>
</template>
+1 -1
View File
@@ -62,7 +62,7 @@ import {
<IconCoin
role="img"
aria-label="美元图标"
class="size-8 shrink-0"
class="text-primary size-8 shrink-0"
/>
<div class="flex flex-col gap-1">
<span class="text-xs font-medium text-muted uppercase">
+4 -9
View File
@@ -6,15 +6,13 @@ import {
Checkbox,
Button,
} from "@heroui-vue/components";
import { ref } from "vue";
const result = ref("");
function submit(event: Event) {
const data = new FormData(event.currentTarget as HTMLFormElement);
result.value =
"表单提交数据:\n" +
Array.from(data)
alert(
`表单提交数据:\n${Array.from(data)
.map(([key, value]) => `${key}: ${value}`)
.join("\n");
.join("\n")}`,
);
}
</script>
<template>
@@ -46,8 +44,5 @@ function submit(event: Event) {
</Checkbox>
</div>
<Button class="mt-4" size="sm" type="submit" variant="primary">提交</Button>
<pre v-if="result" role="status" class="whitespace-pre-wrap text-sm">{{
result
}}</pre>
</form>
</template>
@@ -10,11 +10,10 @@ import {
Button,
Form,
} from "@heroui-vue/components";
import { ref } from "vue";
const result = ref("");
function submit(event: Event) {
const data = new FormData(event.currentTarget as HTMLFormElement);
result.value = "已选偏好:" + data.getAll("preferences").join(", ");
const values = data.getAll("preferences");
alert(`已选偏好:${values.join(", ")}`);
}
</script>
<template>
@@ -48,6 +47,5 @@ function submit(event: Event) {
<FieldError>请至少选择一种通知方式。</FieldError>
</CheckboxGroup>
<Button type="submit">提交</Button>
<p v-if="result" role="status" class="text-sm">{{ result }}</p>
</Form>
</template>
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
ComboBox,
@@ -36,10 +35,8 @@ function validate(value: string | number | (string | number)[] | null) {
return true;
}
const message = ref("");
function onSubmit() {
message.value = "表单提交成功!";
alert("表单提交成功!");
}
</script>
@@ -67,6 +64,5 @@ function onSubmit() {
<FieldError />
</ComboBox>
<Button class="w-fit" type="submit">提交</Button>
<p v-if="message" class="text-sm text-muted" role="status">{{ message }}</p>
</Form>
</template>
+1 -7
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
ComboBox,
@@ -16,11 +15,9 @@ import {
Surface,
} from "@heroui-vue/components";
const message = ref("");
function onSubmit(event: Event) {
event.preventDefault();
message.value = "表单提交成功!";
alert("表单提交成功!");
}
</script>
@@ -64,9 +61,6 @@ function onSubmit(event: Event) {
<FieldError />
</ComboBox>
<Button type="submit">提交</Button>
<p v-if="message" class="text-sm text-muted" role="status">
{{ message }}
</p>
</Form>
</Surface>
</template>
+2 -9
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
ComboBox,
@@ -15,12 +14,9 @@ import {
ListBoxItemIndicator,
} from "@heroui-vue/components";
const submitted = ref(false);
function submit(event: Event) {
function submit() {
// The Form guard already blocks invalid submits, so a reached handler is valid.
void new FormData(event.currentTarget as HTMLFormElement);
submitted.value = true;
alert("表单提交成功!");
}
</script>
@@ -63,8 +59,5 @@ function submit(event: Event) {
<FieldError />
</ComboBox>
<Button type="submit">提交</Button>
<p v-if="submitted" role="status" class="text-sm text-muted">
表单提交成功!
</p>
</Form>
</template>
@@ -17,7 +17,8 @@ import {
IconChevronDown,
IconQrcode,
IconBrandAppleFilled,
IconDeviceMobile,
// 上游为 iconify `logos:expo-icon`;Tabler 无 Expo 品牌字形,按品牌图形约定取 React Native 品牌图标
IconBrandReactNative,
} from "@tabler/icons-vue";
const expandedKeys = ref<Array<string | number>>(["preview"]);
@@ -92,7 +93,7 @@ const { isNextDisabled, isPrevDisabled, onNext, onPrevious } =
/>
<p class="text-sm text-muted">设备需已安装 Expo。</p>
<Button class="mt-4" variant="primary">
<IconDeviceMobile aria-hidden="true" />
<IconBrandReactNative aria-hidden="true" />
在 Expo Go 预览
</Button>
</DisclosureBody>
@@ -113,7 +114,7 @@ const { isNextDisabled, isPrevDisabled, onNext, onPrevious } =
>
<div class="flex w-full items-center justify-start gap-2">
<IconBrandAppleFilled aria-hidden="true" />
下载应用
下载 HeroUI Native
</div>
<DisclosureIndicator class="text-muted" />
</Button>
@@ -127,11 +128,11 @@ const { isNextDisabled, isPrevDisabled, onNext, onPrevious } =
使用手机相机扫描此二维码,即可预览 HeroUI Native 组件。
</p>
<img
alt="App Store 二维码"
alt="Expo Go 二维码"
class="aspect-square w-full max-w-54 object-cover"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/images/qr-code-native.png"
/>
<p class="text-sm text-muted">支持 iOS 和 Android 设备。</p>
<p class="text-sm text-muted">设备需已安装 Expo。</p>
<Button class="mt-4" variant="primary">
<IconBrandAppleFilled aria-hidden="true" />
在 App Store 下载
+3 -11
View File
@@ -14,19 +14,14 @@ import {
TextField,
} from "@heroui-vue/components";
import { IconDeviceFloppy } from "@tabler/icons-vue";
import { ref } from "vue";
const result = ref("");
function validateName(value: string) {
return value.length < 3 ? "姓名至少需要 3 个字符" : null;
}
function validateBio(value: string) {
return value.length < 10 ? "简介至少需要 10 个字符" : null;
}
function submit(event: Event) {
const data = Object.fromEntries(
new FormData(event.currentTarget as HTMLFormElement),
);
result.value = `表单提交成功!${JSON.stringify(data)}`;
function submit() {
alert("表单提交成功!");
}
</script>
<template>
@@ -57,11 +52,8 @@ function submit(event: Event) {
<IconDeviceFloppy aria-hidden="true" />
保存更改
</Button>
<Button type="reset" variant="secondary" @click="result = ''">
取消
</Button>
<Button type="reset" variant="secondary">取消</Button>
</FieldsetActions>
</Fieldset>
<p v-if="result" class="text-sm text-muted" role="status">{{ result }}</p>
</Form>
</template>
+3 -11
View File
@@ -14,19 +14,14 @@ import {
TextField,
} from "@heroui-vue/components";
import { IconDeviceFloppy } from "@tabler/icons-vue";
import { ref } from "vue";
const result = ref("");
function validateName(value: string) {
return value.length < 3 ? "姓名至少需要 3 个字符" : null;
}
function validateBio(value: string) {
return value.length < 10 ? "简介至少需要 10 个字符" : null;
}
function submit(event: Event) {
const data = Object.fromEntries(
new FormData(event.currentTarget as HTMLFormElement),
);
result.value = `表单提交成功!${JSON.stringify(data)}`;
function submit() {
alert("表单提交成功!");
}
const shell =
"rounded-xl border border-border/70 bg-linear-to-b from-neutral-50/90 to-white p-4 ring-1 ring-black/5 dark:from-neutral-900/80 dark:to-neutral-900 dark:ring-white/10";
@@ -67,11 +62,8 @@ const fieldClass =
<IconDeviceFloppy aria-hidden="true" />
保存更改
</Button>
<Button type="reset" variant="secondary" @click="result = ''">
取消
</Button>
<Button type="reset" variant="secondary">取消</Button>
</FieldsetActions>
</Fieldset>
<p v-if="result" class="text-sm text-muted" role="status">{{ result }}</p>
</Form>
</template>
+4 -14
View File
@@ -15,24 +15,19 @@ import {
Surface,
} from "@heroui-vue/components";
import { IconDeviceFloppy } from "@tabler/icons-vue";
import { ref } from "vue";
const result = ref("");
function validateName(value: string) {
return value.length < 3 ? "姓名至少需要 3 个字符" : null;
}
function validateBio(value: string) {
return value.length < 10 ? "简介至少需要 10 个字符" : null;
}
function submit(event: Event) {
const data = Object.fromEntries(
new FormData(event.currentTarget as HTMLFormElement),
);
result.value = `表单提交成功!${JSON.stringify(data)}`;
function submit() {
alert("表单提交成功!");
}
</script>
<template>
<div class="flex items-center justify-center rounded-3xl bg-surface p-6">
<Surface class="w-full min-w-[380px] max-sm:min-w-0">
<Surface class="w-full min-w-[380px]">
<Form @submit.prevent="submit">
<Fieldset class="w-full">
<FieldsetLegend>个人资料设置</FieldsetLegend>
@@ -60,14 +55,9 @@ function submit(event: Event) {
<IconDeviceFloppy aria-hidden="true" />
保存更改
</Button>
<Button type="reset" variant="tertiary" @click="result = ''">
取消
</Button>
<Button type="reset" variant="tertiary">取消</Button>
</FieldsetActions>
</Fieldset>
<p v-if="result" class="text-sm text-muted" role="status">
{{ result }}
</p>
</Form>
</Surface>
</div>
+2 -14
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { ref } from "vue";
import { IconCheck } from "@tabler/icons-vue";
import {
Button,
@@ -11,7 +10,6 @@ import {
TextField,
} from "@heroui-vue/components";
const result = ref("");
function onSubmit(event: Event) {
event.preventDefault();
const formData = new FormData(event.currentTarget as HTMLFormElement);
@@ -19,7 +17,7 @@ function onSubmit(event: Event) {
formData.forEach((value, key) => {
data[key] = value.toString();
});
result.value = `表单提交数据:${JSON.stringify(data, null, 2)}`;
alert(`表单提交数据:${JSON.stringify(data, null, 2)}`);
}
function validateEmail(value: string) {
return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value)
@@ -35,11 +33,7 @@ function validatePassword(value: string) {
</script>
<template>
<Form
class="flex w-96 max-w-full flex-col gap-4"
@submit="onSubmit"
@reset="result = ''"
>
<Form class="flex w-96 flex-col gap-4" @submit="onSubmit">
<TextField is-required name="email" type="email" :validate="validateEmail">
<Label>邮箱</Label>
<Input placeholder="john@example.com" />
@@ -64,11 +58,5 @@ function validatePassword(value: string) {
</Button>
<Button type="reset" variant="secondary">重置</Button>
</div>
<pre
v-if="result"
role="status"
aria-label="提交结果"
class="whitespace-pre-wrap break-all text-xs"
>{{ result }}</pre>
</Form>
</template>
+1 -1
View File
@@ -4,7 +4,7 @@ import { Button, Form, Input, Label, TextField } from "@heroui-vue/components";
<template>
<Form
class="flex w-80 max-w-full flex-col gap-3 rounded-xl border border-border/80 bg-surface p-4 shadow-sm"
class="flex w-80 flex-col gap-3 rounded-xl border border-border/80 bg-surface p-4 shadow-sm"
@submit.prevent
>
<TextField is-required name="email" type="email">
+2 -15
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { ref } from "vue";
import { IconCheck } from "@tabler/icons-vue";
import {
Button,
@@ -11,7 +10,6 @@ import {
TextField,
} from "@heroui-vue/components";
const result = ref("");
function onSubmit(event: Event) {
event.preventDefault();
const formData = new FormData(event.currentTarget as HTMLFormElement);
@@ -19,7 +17,7 @@ function onSubmit(event: Event) {
formData.forEach((value, key) => {
data[key] = value.toString();
});
result.value = `表单提交数据:${JSON.stringify(data, null, 2)}`;
alert(`表单提交数据:${JSON.stringify(data, null, 2)}`);
}
function validateEmail(value: string) {
return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value)
@@ -35,12 +33,7 @@ function validatePassword(value: string) {
</script>
<template>
<Form
class="flex w-96 max-w-full flex-col gap-4"
data-custom="foo"
@submit="onSubmit"
@reset="result = ''"
>
<Form class="flex w-96 flex-col gap-4" data-custom="foo" @submit="onSubmit">
<TextField is-required name="email" type="email" :validate="validateEmail">
<Label>邮箱</Label>
<Input placeholder="john@example.com" />
@@ -65,11 +58,5 @@ function validatePassword(value: string) {
</Button>
<Button type="reset" variant="secondary">重置</Button>
</div>
<pre
v-if="result"
role="status"
aria-label="提交结果"
class="whitespace-pre-wrap break-all text-xs"
>{{ result }}</pre>
</Form>
</template>
+47
View File
@@ -0,0 +1,47 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
Spinner,
Skeleton,
Popover,
PopoverContent,
PopoverDialog,
PopoverHeading,
} from "@heroui-vue/components";
const reduced = ref(false);
const target = ref<HTMLElement>();
</script>
<template>
<section
ref="target"
:data-reduce-motion="reduced ? 'true' : undefined"
class="motion-demo"
>
<label>
<input v-model="reduced" type="checkbox" />
减少动态效果
</label>
<div class="flex items-center gap-4">
<Spinner aria-label="加载中" />
<Skeleton class="h-6 w-32" />
<Button>点按动画</Button>
</div>
<Popover>
<Button>查看进出场动画</Button>
<PopoverContent :to="target">
<PopoverDialog>
<PopoverHeading>动画与卸载</PopoverHeading>
<p>关闭时保留退出阶段;减少动态效果时禁用装饰动画。</p>
</PopoverDialog>
</PopoverContent>
</Popover>
</section>
</template>
<style scoped>
.motion-demo {
width: 100%;
display: grid;
gap: 20px;
}
</style>
+28
View File
@@ -0,0 +1,28 @@
<script setup lang="ts">
import { ref } from "vue";
import { Button, Link, buttonVariants } from "@heroui-vue/components";
import { tv } from "@heroui-vue/styles";
const count = ref(0);
const customButton = tv({
extend: buttonVariants,
variants: { emphasis: { strong: "font-bold" } },
});
</script>
<template>
<div class="flex flex-wrap items-center gap-3">
<a href="#自定义变体" :class="buttonVariants({ variant: 'secondary' })">
链接采用按钮外观
</a>
<Button
as-child
v-slot="{ isPressed }"
:class="customButton({ emphasis: 'strong' })"
@click="count++"
>
<button type="button" :data-custom-state="isPressed ? 'pressed' : 'idle'">
自定义根节点 · {{ count }}
</button>
</Button>
<Link href="/components/button">查看 Button API</Link>
</div>
</template>
+52
View File
@@ -0,0 +1,52 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import { usePreferredDark } from "@vueuse/core";
import { Button, Card, Input } from "@heroui-vue/components";
const mode = ref("system");
const systemDark = usePreferredDark();
const resolved = computed(() =>
mode.value === "system" ? (systemDark.value ? "dark" : "light") : mode.value,
);
</script>
<template>
<div class="mode-demo">
<label>
外观
<select v-model="mode">
<option value="light">浅色</option>
<option value="dark">深色</option>
<option value="system">跟随系统</option>
</select>
</label>
<section :class="resolved" class="mode-preview">
<Card>
<strong>主题预览</strong>
<p>当前选择:{{ mode }};解析为:{{ resolved }}。</p>
</Card>
<Input aria-label="深色模式预览" placeholder="输入内容" />
<Button>继续</Button>
</section>
</div>
</template>
<style scoped>
.mode-demo {
width: 100%;
display: grid;
gap: 16px;
}
.mode-preview {
display: grid;
gap: 16px;
padding: 20px;
border-radius: 16px;
background: var(--background);
color: var(--foreground);
}
select {
padding: 4px 8px;
background: var(--field-background);
color: var(--field-foreground);
border: 1px solid var(--border);
border-radius: 6px;
}
</style>
+33
View File
@@ -0,0 +1,33 @@
<script setup lang="ts">
import { ref } from "vue";
import { Button } from "@heroui-vue/components";
const pending = ref(false);
</script>
<template>
<div class="flex flex-wrap items-center gap-3">
<Button as-child v-slot="{ isPressed, isHovered, isFocusVisible }">
<button class="handbook-state-button">
{{
isPressed
? "按下中"
: isHovered
? "悬停中"
: isFocusVisible
? "键盘焦点"
: "与我交互"
}}
</button>
</Button>
<Button is-disabled>禁用</Button>
<Button :is-pending="pending">{{ pending ? "加载中" : "正常操作" }}</Button>
<label>
<input v-model="pending" type="checkbox" />
加载状态
</label>
</div>
</template>
<style scoped>
.handbook-state-button[data-pressed="true"] {
outline: 2px solid var(--focus);
}
</style>
+72
View File
@@ -0,0 +1,72 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
Card,
Input,
Popover,
PopoverContent,
PopoverDialog,
PopoverHeading,
} from "@heroui-vue/components";
const theme = ref("light");
const target = ref<HTMLElement>();
</script>
<template>
<div class="handbook-theme-demo">
<label>
预览主题
<select v-model="theme">
<option value="light">浅色</option>
<option value="dark">深色</option>
</select>
</label>
<section
ref="target"
:class="theme"
class="theme-preview"
data-theme="ocean"
>
<Card>
<strong>自定义主题</strong>
<p>组件通过同一组语义变量更新外观。</p>
</Card>
<Input aria-label="主题预览邮箱" placeholder="输入你的邮箱" />
<Popover>
<Button>打开主题弹层</Button>
<PopoverContent :to="target">
<PopoverDialog>
<PopoverHeading>同一主题容器</PopoverHeading>
<p>to 指向局部容器,保留 CSS 变量继承。</p>
</PopoverDialog>
</PopoverContent>
</Popover>
</section>
</div>
</template>
<style scoped>
.handbook-theme-demo {
width: 100%;
display: grid;
gap: 16px;
}
.theme-preview {
display: grid;
gap: 16px;
padding: 20px;
border-radius: 16px;
background: var(--background);
color: var(--foreground);
}
[data-theme="ocean"] {
--accent: oklch(0.62 0.2 253.83);
--accent-foreground: var(--snow);
}
select {
background: var(--field-background);
color: var(--field-foreground);
border: 1px solid var(--border);
border-radius: 6px;
padding: 4px 8px;
}
</style>
+53 -30
View File
@@ -6,8 +6,12 @@ import {
InputGroupPrefix,
InputGroupSuffix,
InputGroupTextArea,
Kbd,
KbdAbbr,
Spinner,
TextField,
Tooltip,
TooltipContent,
} from "@heroui-vue/components";
import {
IconArrowUp,
@@ -53,45 +57,64 @@ function handleSubmit() {
:rows="5"
/>
<InputGroupSuffix class="flex w-full items-center gap-1.5 px-3 py-0">
<Button
is-icon-only
aria-label="附加文件"
size="sm"
title="添加文件等"
variant="tertiary"
>
<IconPlus aria-hidden="true" />
</Button>
<Button
is-icon-only
aria-label="连接应用"
size="sm"
title="连接应用"
variant="tertiary"
>
<IconPlugConnected aria-hidden="true" />
</Button>
<div class="ms-auto flex items-center gap-1.5">
<Tooltip :delay="0">
<Button
is-icon-only
aria-label="语音输入"
aria-label="附加文件"
size="sm"
title="语音输入"
variant="ghost"
variant="tertiary"
>
<IconMicrophone aria-hidden="true" />
<IconPlus aria-hidden="true" />
</Button>
<TooltipContent>
<p class="text-xs">添加文件等</p>
</TooltipContent>
</Tooltip>
<Tooltip :delay="0">
<Button
is-icon-only
aria-label="发送提示"
:is-disabled="!value.trim()"
:is-pending="isSubmitting"
title="发送"
@click="handleSubmit"
aria-label="连接应用"
size="sm"
variant="tertiary"
>
<Spinner v-if="isSubmitting" color="current" size="sm" />
<IconArrowUp v-else aria-hidden="true" />
<IconPlugConnected aria-hidden="true" />
</Button>
<TooltipContent>
<p class="text-xs">连接应用</p>
</TooltipContent>
</Tooltip>
<div class="ms-auto flex items-center gap-1.5">
<Tooltip :delay="0">
<Button
is-icon-only
aria-label="语音输入"
size="sm"
variant="ghost"
>
<IconMicrophone aria-hidden="true" />
</Button>
<TooltipContent>
<p class="text-xs">语音输入</p>
</TooltipContent>
</Tooltip>
<Tooltip :delay="0">
<Button
is-icon-only
aria-label="发送提示"
:is-disabled="!value.trim()"
:is-pending="isSubmitting"
@click="handleSubmit"
>
<Spinner v-if="isSubmitting" color="current" size="sm" />
<IconArrowUp v-else aria-hidden="true" />
</Button>
<TooltipContent class="flex items-center gap-1">
<p class="text-xs">发送</p>
<Kbd class="h-4 rounded-sm px-1">
<KbdAbbr key-value="enter" />
</Kbd>
</TooltipContent>
</Tooltip>
</div>
</InputGroupSuffix>
</InputGroup>
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { ref } from "vue";
import { IconPencil, IconSquarePlus, IconTrash } from "@tabler/icons-vue";
import {
Description,
@@ -14,7 +13,9 @@ import {
Separator,
Surface,
} from "@heroui-vue/components";
const message = ref("");
function onAction(key: string | number) {
alert(`已选项目:${key}`);
}
const actions = [
{
id: "new-file",
@@ -33,56 +34,53 @@ const actions = [
];
</script>
<template>
<div class="space-y-3">
<Surface class="w-[256px] rounded-3xl shadow-surface">
<ListBox
aria-label="文件操作"
class="w-full p-2"
selection-mode="none"
@action="message = `已选项目:${$event}`"
:disabled-keys="['delete-file']"
>
<ListBoxSection>
<Header>操作</Header>
<ListBoxItem
v-for="action in actions"
:key="action.id"
:id="action.id"
:text-value="action.title"
>
<div class="flex h-8 items-start justify-center pt-px">
<component :is="action.icon" class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>{{ action.title }}</Label>
<Description>{{ action.description }}</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>{{ action.shortcut }}</KbdContent>
</Kbd>
</ListBoxItem>
</ListBoxSection>
<Separator />
<ListBoxSection>
<Header>危险区域</Header>
<ListBoxItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</ListBoxItem>
</ListBoxSection>
</ListBox>
</Surface>
<p v-if="message" role="status" class="text-sm text-muted">{{ message }}</p>
</div>
<Surface class="w-[256px] rounded-3xl shadow-surface">
<ListBox
aria-label="文件操作"
class="w-full p-2"
selection-mode="none"
@action="onAction"
:disabled-keys="['delete-file']"
>
<ListBoxSection>
<Header>操作</Header>
<ListBoxItem
v-for="action in actions"
:key="action.id"
:id="action.id"
:text-value="action.title"
>
<div class="flex h-8 items-start justify-center pt-px">
<component :is="action.icon" class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>{{ action.title }}</Label>
<Description>{{ action.description }}</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>{{ action.shortcut }}</KbdContent>
</Kbd>
</ListBoxItem>
</ListBoxSection>
<Separator />
<ListBoxSection>
<Header>危险区域</Header>
<ListBoxItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</ListBoxItem>
</ListBoxSection>
</ListBox>
</Surface>
</template>
+51 -53
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { ref } from "vue";
import { IconPencil, IconSquarePlus, IconTrash } from "@tabler/icons-vue";
import {
Description,
@@ -14,7 +13,9 @@ import {
Separator,
Surface,
} from "@heroui-vue/components";
const message = ref("");
function onAction(key: string | number) {
alert(`已选项目:${key}`);
}
const actions = [
{
id: "new-file",
@@ -33,55 +34,52 @@ const actions = [
];
</script>
<template>
<div class="space-y-3">
<Surface class="w-[256px] rounded-3xl shadow-surface">
<ListBox
aria-label="文件操作"
class="w-full p-2"
selection-mode="none"
@action="message = `已选项目:${$event}`"
>
<ListBoxSection>
<Header>操作</Header>
<ListBoxItem
v-for="action in actions"
:key="action.id"
:id="action.id"
:text-value="action.title"
>
<div class="flex h-8 items-start justify-center pt-px">
<component :is="action.icon" class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>{{ action.title }}</Label>
<Description>{{ action.description }}</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>{{ action.shortcut }}</KbdContent>
</Kbd>
</ListBoxItem>
</ListBoxSection>
<Separator />
<ListBoxSection>
<Header>危险区域</Header>
<ListBoxItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</ListBoxItem>
</ListBoxSection>
</ListBox>
</Surface>
<p v-if="message" role="status" class="text-sm text-muted">{{ message }}</p>
</div>
<Surface class="w-[256px] rounded-3xl shadow-surface">
<ListBox
aria-label="文件操作"
class="w-full p-2"
selection-mode="none"
@action="onAction"
>
<ListBoxSection>
<Header>操作</Header>
<ListBoxItem
v-for="action in actions"
:key="action.id"
:id="action.id"
:text-value="action.title"
>
<div class="flex h-8 items-start justify-center pt-px">
<component :is="action.icon" class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>{{ action.title }}</Label>
<Description>{{ action.description }}</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>{{ action.shortcut }}</KbdContent>
</Kbd>
</ListBoxItem>
</ListBoxSection>
<Separator />
<ListBoxSection>
<Header>危险区域</Header>
<ListBoxItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</ListBoxItem>
</ListBoxSection>
</ListBox>
</Surface>
</template>
+53 -71
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { ref, useId } from "vue";
import {
Button,
Input,
@@ -17,78 +16,61 @@ import {
ModalIcon,
Surface,
TextField,
useOverlayState,
} from "@heroui-vue/components";
import { IconMail as Envelope } from "@tabler/icons-vue";
const state = useOverlayState();
const formId = useId();
const result = ref<Record<string, FormDataEntryValue>>();
function submit(event: SubmitEvent) {
result.value = Object.fromEntries(
new FormData(event.currentTarget as HTMLFormElement),
);
state.close();
}
</script>
<template>
<div>
<Modal :state="state">
<Button variant="secondary">打开联系表单</Button>
<ModalBackdrop>
<ModalContainer placement="auto">
<ModalDialog class="sm:max-w-md">
<ModalCloseTrigger></ModalCloseTrigger>
<ModalHeader>
<ModalIcon class="bg-accent-soft text-accent-soft-foreground">
<Envelope aria-hidden="true" class="size-5"></Envelope>
</ModalIcon>
<ModalHeading>联系我们</ModalHeading>
<p class="mt-1.5 text-sm leading-5 text-muted">
填写下方表单,我们会尽快回复。在移动端弹出键盘时,模态框会自动适配。
</p>
</ModalHeader>
<ModalBody class="p-6">
<Surface variant="default">
<form
:id="formId"
class="flex flex-col gap-4"
@submit.prevent="submit"
>
<TextField class="w-full" name="name" type="text">
<Label>姓名</Label>
<Input placeholder="输入你的姓名"></Input>
</TextField>
<TextField class="w-full" name="email" type="email">
<Label>邮箱</Label>
<Input placeholder="输入你的邮箱"></Input>
</TextField>
<TextField class="w-full" name="phone" type="tel">
<Label>电话</Label>
<Input placeholder="输入你的电话号码"></Input>
</TextField>
<TextField class="w-full" name="company">
<Label>公司</Label>
<Input placeholder="输入公司名称"></Input>
</TextField>
<TextField class="w-full" name="message">
<Label>留言</Label>
<Input placeholder="输入留言内容"></Input>
</TextField>
</form>
</Surface>
</ModalBody>
<ModalFooter>
<ModalClose as-child>
<Button variant="secondary">取消</Button>
</ModalClose>
<Button type="submit" :form="formId">发送消息</Button>
</ModalFooter>
</ModalDialog>
</ModalContainer>
</ModalBackdrop>
</Modal>
<p v-if="result" role="status" class="mt-3 text-sm text-muted">
已记录表单:{{ result }}
</p>
</div>
<Modal>
<Button variant="secondary">打开联系表单</Button>
<ModalBackdrop>
<ModalContainer placement="auto">
<ModalDialog class="sm:max-w-md">
<ModalCloseTrigger></ModalCloseTrigger>
<ModalHeader>
<ModalIcon class="bg-accent-soft text-accent-soft-foreground">
<Envelope aria-hidden="true" class="size-5"></Envelope>
</ModalIcon>
<ModalHeading>联系我们</ModalHeading>
<p class="mt-1.5 text-sm leading-5 text-muted">
填写下方表单,我们会尽快回复。在移动端弹出键盘时,模态框会自动适配。
</p>
</ModalHeader>
<ModalBody class="p-6">
<Surface variant="default">
<form class="flex flex-col gap-4">
<TextField class="w-full" name="name" type="text">
<Label>姓名</Label>
<Input placeholder="输入你的姓名"></Input>
</TextField>
<TextField class="w-full" name="email" type="email">
<Label>邮箱</Label>
<Input placeholder="输入你的邮箱"></Input>
</TextField>
<TextField class="w-full" name="phone" type="tel">
<Label>电话</Label>
<Input placeholder="输入你的电话号码"></Input>
</TextField>
<TextField class="w-full" name="company">
<Label>公司</Label>
<Input placeholder="输入公司名称"></Input>
</TextField>
<TextField class="w-full" name="message">
<Label>留言</Label>
<Input placeholder="输入留言内容"></Input>
</TextField>
</form>
</Surface>
</ModalBody>
<ModalFooter>
<ModalClose as-child>
<Button variant="secondary">取消</Button>
</ModalClose>
<ModalClose as-child>
<Button>发送消息</Button>
</ModalClose>
</ModalFooter>
</ModalDialog>
</ModalContainer>
</ModalBackdrop>
</Modal>
</template>
+5 -10
View File
@@ -14,8 +14,7 @@ import {
Spinner,
} from "@heroui-vue/components";
const value = ref<number | null>(null),
isSubmitting = ref(false),
feedback = ref("");
isSubmitting = ref(false);
const STOCK_AVAILABLE = 3;
const isOutOfStock = computed(
() => value.value !== null && value.value > STOCK_AVAILABLE,
@@ -29,13 +28,13 @@ function submit() {
value.value > STOCK_AVAILABLE
)
return;
const submittedValue = value.value;
isSubmitting.value = true;
feedback.value = "";
// Local demonstration only; no order or network request is created.
// Simulate API call
timer = setTimeout(() => {
console.log("Order submitted:", { quantity: submittedValue });
value.value = null;
isSubmitting.value = false;
feedback.value = "模拟提交成功";
}, 1500);
}
onBeforeUnmount(() => {
@@ -43,10 +42,7 @@ onBeforeUnmount(() => {
});
</script>
<template>
<Form
class="flex w-[280px] max-w-full flex-col gap-4"
@submit.prevent="submit"
>
<Form class="flex w-[280px] flex-col gap-4" @submit.prevent="submit">
<NumberField
v-model="value"
is-required
@@ -79,6 +75,5 @@ onBeforeUnmount(() => {
</template>
<template v-else>下单</template>
</Button>
<p v-if="feedback" role="status">{{ feedback }}</p>
</Form>
</template>
+1 -1
View File
@@ -9,7 +9,7 @@ import {
} from "@heroui-vue/components";
</script>
<template>
<div class="w-[400px] max-w-full space-y-4">
<div class="w-[400px] space-y-4">
<NumberField fullWidth :defaultValue="1024" :minValue="0" name="width">
<Label>宽度</Label>
<NumberFieldGroup>
+1 -1
View File
@@ -52,6 +52,6 @@ function submit(event: Event) {
<FieldError>请先选择订阅套餐再继续。</FieldError>
</RadioGroup>
<Button class="mt-2 w-fit" type="submit">Submit</Button>
<p v-if="result" role="status" class="text-sm">{{ result }}</p>
<p v-if="result" role="status" class="text-sm text-muted">{{ result }}</p>
</Form>
</template>
@@ -8,7 +8,8 @@ import {
Label,
Description,
} from "@heroui-vue/components";
import { IconFilter, IconCircleX } from "@tabler/icons-vue";
// 上游自定义 SVG 为“人形搜索”字形;IconFilter 语义无关,按任务卡通过条件改用搜索人形字形
import { IconUserSearch, IconCircleX } from "@tabler/icons-vue";
</script>
<template>
@@ -17,7 +18,7 @@ import { IconFilter, IconCircleX } from "@tabler/icons-vue";
<Label>搜索(自定义图标)</Label>
<SearchFieldGroup>
<SearchFieldSearchIcon>
<IconFilter aria-hidden="true" />
<IconUserSearch aria-hidden="true" />
</SearchFieldSearchIcon>
<SearchFieldInput class="w-[280px]" placeholder="搜索…" />
<SearchFieldClearButton>
@@ -15,20 +15,18 @@ import { Form } from "@heroui-vue/components";
import { computed, onBeforeUnmount, ref } from "vue";
const value = ref("");
const isSubmitting = ref(false);
const result = ref("");
const isInvalid = computed(
() => value.value.length > 0 && value.value.length < 3,
);
let timer: ReturnType<typeof setTimeout> | undefined;
onBeforeUnmount(() => clearTimeout(timer));
function submit(event: Event) {
function submit() {
if (value.value.length < 3 || isSubmitting.value) return;
const query = new FormData(event.currentTarget as HTMLFormElement).get(
"search",
);
const submittedValue = value.value;
isSubmitting.value = true;
// Simulate API call
timer = setTimeout(() => {
result.value = `已模拟提交搜索:${query}`;
console.log("Search submitted:", { query: submittedValue });
value.value = "";
isSubmitting.value = false;
}, 1500);
@@ -65,6 +63,5 @@ function submit(event: Event) {
</template>
<template v-else>搜索</template>
</Button>
<p v-if="result" role="status" class="text-sm text-muted">{{ result }}</p>
</Form>
</template>
+4 -6
View File
@@ -14,12 +14,13 @@ import {
Button,
Surface,
} from "@heroui-vue/components";
import { ref } from "vue";
const submitted = ref(false);
function submit() {
alert("表单提交成功!");
}
</script>
<template>
<Surface class="w-[320px] rounded-3xl p-6">
<Form class="flex w-full flex-col gap-4" @submit.prevent="submitted = true">
<Form class="flex w-full flex-col gap-4" @submit.prevent="submit">
<Select
is-required
class="w-full"
@@ -105,9 +106,6 @@ const submitted = ref(false);
<FieldError />
</Select>
<Button type="submit">提交</Button>
<p v-if="submitted" role="status" class="text-sm text-success">
表单提交成功!
</p>
</Form>
</Surface>
</template>
+4 -9
View File
@@ -13,14 +13,12 @@ import {
FieldError,
Button,
} from "@heroui-vue/components";
import { ref } from "vue";
const submitted = ref(false);
function submit() {
alert("表单提交成功!");
}
</script>
<template>
<Form
class="flex w-[256px] flex-col gap-4"
@submit.prevent="submitted = true"
>
<Form class="flex w-[256px] flex-col gap-4" @submit.prevent="submit">
<Select is-required class="w-full" name="state" placeholder="请选择">
<Label>州</Label>
<SelectTrigger>
@@ -94,8 +92,5 @@ const submitted = ref(false);
<FieldError />
</Select>
<Button type="submit">提交</Button>
<p v-if="submitted" role="status" class="text-sm text-success">
表单提交成功!
</p>
</Form>
</template>
+9 -21
View File
@@ -7,13 +7,13 @@ import {
SwitchGroup,
Button,
} from "@heroui-vue/components";
import { ref } from "vue";
const result = ref("");
function submit(event: Event) {
const values = [...new FormData(event.target as HTMLFormElement).entries()];
result.value = values.length
? "表单提交内容:" + values.map(([k, v]) => `${k}: ${v}`).join(",")
: "未选择任何选项";
const data = new FormData(event.currentTarget as HTMLFormElement);
alert(
`表单提交内容:\n${Array.from(data)
.map(([key, value]) => `${key}: ${value}`)
.join("\n")}`,
);
}
</script>
<template>
@@ -38,20 +38,8 @@ function submit(event: Event) {
</SwitchContent>
</Switch>
</SwitchGroup>
<div class="flex gap-2">
<Button class="mt-4" size="sm" type="submit">Submit</Button>
<Button
class="mt-4"
size="sm"
type="reset"
variant="secondary"
@click="result = ''"
>
重置
</Button>
</div>
<output v-if="result" class="text-sm text-muted" aria-live="polite">
{{ result }}
</output>
<Button class="mt-4" size="sm" type="submit" variant="primary">
Submit
</Button>
</form>
</template>
+3 -6
View File
@@ -30,14 +30,14 @@ const isInvalid = computed(() => {
});
import { onBeforeUnmount } from "vue";
const isSubmitting = shallowRef(false);
const submitted = shallowRef("");
let timer: ReturnType<typeof setTimeout> | undefined;
function submit() {
if (!value.value || isInvalid.value || isSubmitting.value) return;
const payload = value.value.toString();
const submittedValue = value.value;
isSubmitting.value = true;
// Simulate API call
timer = setTimeout(() => {
submitted.value = payload;
console.log("Time submitted:", { time: submittedValue });
value.value = null;
isSubmitting.value = false;
}, 1500);
@@ -78,8 +78,5 @@ onBeforeUnmount(() => clearTimeout(timer));
>
{{ isSubmitting ? "提交中…" : "提交" }}
</Button>
<output v-if="submitted" class="text-sm text-muted">
已提交:{{ submitted }}
</output>
</Form>
</template>
+1 -1
View File
@@ -21,7 +21,7 @@ function show() {
</script>
<template>
<div class="flex flex-col gap-3">
<div class="flex h-full max-w-xl flex-col items-center justify-center">
<Button size="sm" variant="secondary" @click="show">自定义指示器</Button>
<ToastProvider :queue="queue" to="body" />
</div>
+47 -43
View File
@@ -11,51 +11,55 @@ onBeforeUnmount(() =>
);
</script>
<template>
<div
class="flex h-full max-w-4xl flex-wrap items-center justify-center gap-4"
>
<Button
size="sm"
variant="secondary"
@click="
notificationQueue.add({
title: '新通知',
description: '您有一条新消息',
variant: 'default',
})
"
>
添加通知(最多 2 条)
</Button>
<Button
size="sm"
variant="danger-soft"
@click="
errorQueue.add({
title: '发生错误',
description: '保存更改失败',
variant: 'danger',
})
"
>
添加错误(最多 3 条)
</Button>
<Button
size="sm"
variant="secondary"
class="text-success"
@click="
successQueue.add({
title: '成功!',
description: `操作 ${Date.now()}`,
variant: 'success',
})
"
>
添加成功(最多 1 条)
</Button>
<div class="flex h-full max-w-4xl items-center justify-center gap-4">
<ToastProvider :queue="notificationQueue" to="body" placement="bottom" />
<div class="flex justify-center gap-2">
<Button
size="sm"
variant="secondary"
@click="
notificationQueue.add({
title: '新通知',
description: '您有一条新消息',
variant: 'default',
})
"
>
添加通知(最多 2 条)
</Button>
</div>
<ToastProvider :queue="errorQueue" to="body" placement="bottom start" />
<div class="flex justify-center gap-2">
<Button
size="sm"
variant="danger-soft"
@click="
errorQueue.add({
title: '发生错误',
description: '保存更改失败',
variant: 'danger',
})
"
>
添加错误(最多 3 条)
</Button>
</div>
<ToastProvider :queue="successQueue" to="body" placement="bottom end" />
<div class="flex justify-center gap-2">
<Button
size="sm"
variant="secondary"
class="text-success"
@click="
successQueue.add({
title: '成功!',
description: `操作 ${Date.now()}`,
variant: 'success',
})
"
>
添加成功(最多 1 条)
</Button>
</div>
</div>
</template>
+27 -21
View File
@@ -11,26 +11,32 @@ const toast = createToastFunction(queue);
onBeforeUnmount(() => queue.destroy());
</script>
<template>
<div class="flex h-full max-w-xl flex-wrap items-center justify-center gap-4">
<Button size="sm" variant="secondary" @click="toast('简单消息')">
默认
</Button>
<Button size="sm" variant="secondary" @click="toast.success('操作已完成')">
成功
</Button>
<Button size="sm" variant="secondary" @click="toast.info('有新更新可用')">
信息
</Button>
<Button
size="sm"
variant="secondary"
@click="toast.warning('请检查您的设置')"
>
警告
</Button>
<Button size="sm" variant="secondary" @click="toast.danger('出了点问题')">
错误
</Button>
<ToastProvider :queue="queue" to="body" />
<div class="flex h-full max-w-xl flex-col items-center justify-center">
<div class="flex w-full flex-wrap items-center justify-center gap-4">
<Button size="sm" variant="secondary" @click="toast('简单消息')">
默认
</Button>
<Button
size="sm"
variant="secondary"
@click="toast.success('操作已完成')"
>
成功
</Button>
<Button size="sm" variant="secondary" @click="toast.info('有新更新可用')">
信息
</Button>
<Button
size="sm"
variant="secondary"
@click="toast.warning('请检查您的设置')"
>
警告
</Button>
<Button size="sm" variant="secondary" @click="toast.danger('出了点问题')">
错误
</Button>
<ToastProvider :queue="queue" to="body" />
</div>
</div>
</template>
+27 -25
View File
@@ -62,7 +62,7 @@ function show(v: (typeof variants)[number]["key"]) {
actionProps: {
label: item.action,
variant:
v === "danger" ? "danger" : v === "default" ? "tertiary" : "secondary",
v === "danger" ? "danger" : v === "default" ? "tertiary" : undefined,
class:
v === "success"
? "bg-success text-success-foreground"
@@ -75,29 +75,31 @@ function show(v: (typeof variants)[number]["key"]) {
</script>
<template>
<div class="flex flex-wrap gap-3">
<Button
v-for="v in variants"
:key="v.key"
size="sm"
:variant="
v.key === 'danger'
? 'danger-soft'
: v.key === 'accent'
? 'secondary'
: 'tertiary'
"
:class="
v.key === 'success'
? 'text-success'
: v.key === 'warning'
? 'text-warning'
: undefined
"
@click="show(v.key)"
>
{{ v.label }}
</Button>
<ToastProvider :queue="queue" to="body" />
<div class="flex h-full max-w-xl flex-col items-center justify-center">
<div class="flex w-full flex-wrap items-center justify-center gap-4">
<Button
v-for="v in variants"
:key="v.key"
size="sm"
:variant="
v.key === 'danger'
? 'danger-soft'
: v.key === 'accent'
? 'secondary'
: 'tertiary'
"
:class="
v.key === 'success'
? 'text-success'
: v.key === 'warning'
? 'text-warning'
: undefined
"
@click="show(v.key)"
>
{{ v.label }}
</Button>
<ToastProvider :queue="queue" to="body" />
</div>
</div>
</template>
+6 -15
View File
@@ -1,20 +1,11 @@
<script setup lang="ts">
import { ref } from "vue";
import { ToggleButton } from "@heroui-vue/components";
import { IconHeart, IconHeartFilled } from "@tabler/icons-vue";
const liked = ref(false);
import { IconHeart } from "@tabler/icons-vue";
</script>
<template>
<div class="flex gap-3">
<ToggleButton v-model="liked">
<IconHeartFilled v-if="liked" aria-hidden="true" />
<IconHeart v-else aria-hidden="true" />
Like
</ToggleButton>
<ToggleButton variant="ghost">
<IconHeart aria-hidden="true" />
Like
</ToggleButton>
</div>
<ToggleButton>
<IconHeart aria-hidden="true" />
点赞
</ToggleButton>
</template>
+8 -11
View File
@@ -5,20 +5,17 @@ import { IconHeart, IconHeartFilled } from "@tabler/icons-vue";
const isSelected = ref(false);
</script>
<template>
<div class="flex flex-col gap-4">
<div class="flex gap-3">
<ToggleButton v-model="isSelected">
<IconHeartFilled v-if="isSelected" aria-hidden="true" />
<IconHeart v-else aria-hidden="true" />
{{ isSelected ? "Liked" : "Like" }}
</ToggleButton>
</div>
<ToggleButton v-slot="{ isSelected: selected }" v-model="isSelected">
<IconHeartFilled v-if="selected" aria-hidden="true" />
<IconHeart v-else aria-hidden="true" />
{{ selected ? "已点赞" : "点赞" }}
</ToggleButton>
<p class="text-sm text-muted">
Status:
<span class="font-medium">
{{ isSelected ? "Selected" : "Not selected" }}
</span>
状态:
<span class="font-medium">{{ isSelected ? "已选" : "未选" }}</span>
</p>
</div>
</template>
@@ -2,9 +2,12 @@
import { ToggleButton } from "@heroui-vue/components";
import { IconHeart } from "@tabler/icons-vue";
</script>
<template>
<ToggleButton class="rounded-lg bg-purple-500 text-white">
<ToggleButton
class="gap-2 rounded-full border border-border/80 bg-surface px-4 text-foreground shadow-sm data-[selected=true]:border-accent/30 data-[selected=true]:bg-accent-soft data-[selected=true]:text-accent-soft-foreground [&_svg]:text-muted data-[selected=true]:[&_svg]:text-accent"
>
<IconHeart aria-hidden="true" />
Like
收藏文章
</ToggleButton>
</template>
+4 -3
View File
@@ -2,15 +2,16 @@
import { ToggleButton } from "@heroui-vue/components";
import { IconHeart, IconHeartFilled } from "@tabler/icons-vue";
</script>
<template>
<div class="flex gap-3">
<div class="flex items-center gap-3">
<ToggleButton is-disabled>
<IconHeart aria-hidden="true" />
Like
点赞
</ToggleButton>
<ToggleButton default-selected is-disabled>
<IconHeartFilled aria-hidden="true" />
Like
点赞
</ToggleButton>
</div>
</template>
@@ -1,62 +1,52 @@
<script setup lang="ts">
import {
ToggleButtonGroup,
ToggleButton,
ToggleButtonGroup,
ToggleButtonGroupSeparator,
} from "@heroui-vue/components";
import {
IconBold,
IconItalic,
IconUnderline,
IconStrikethrough,
IconUnderline,
} from "@tabler/icons-vue";
</script>
<template>
<div class="flex w-full flex-col gap-6">
<div class="flex flex-col gap-6">
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">Attached (default)</p>
<span class="text-sm text-muted">附着(默认)</span>
<ToggleButtonGroup selection-mode="multiple">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton
id="strikethrough"
is-icon-only
aria-label="Strikethrough"
>
<ToggleButton id="strikethrough" is-icon-only aria-label="删除线">
<ToggleButtonGroupSeparator />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">Detached</p>
<span class="text-sm text-muted">分离</span>
<ToggleButtonGroup is-detached selection-mode="multiple">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButtonGroupSeparator />
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButtonGroupSeparator />
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton
id="strikethrough"
is-icon-only
aria-label="Strikethrough"
>
<ToggleButtonGroupSeparator />
<ToggleButton id="strikethrough" is-icon-only aria-label="删除线">
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
@@ -1,30 +1,31 @@
<script setup lang="ts">
import {
ToggleButtonGroup,
ToggleButton,
ToggleButtonGroup,
ToggleButtonGroupSeparator,
} from "@heroui-vue/components";
import {
IconBold,
IconItalic,
IconUnderline,
IconStrikethrough,
IconUnderline,
} from "@tabler/icons-vue";
</script>
<template>
<ToggleButtonGroup selection-mode="multiple">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton id="strikethrough" is-icon-only aria-label="Strikethrough">
<ToggleButton id="strikethrough" is-icon-only aria-label="删除线">
<ToggleButtonGroupSeparator />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
@@ -1,43 +1,44 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import {
ToggleButtonGroup,
ToggleButton,
ToggleButtonGroup,
ToggleButtonGroupSeparator,
} from "@heroui-vue/components";
import {
IconBold,
IconItalic,
IconUnderline,
IconStrikethrough,
IconUnderline,
} from "@tabler/icons-vue";
const selectedKeys = ref<(string | number)[]>(["bold"]);
const selectedKeys = ref<Array<string | number>>(["bold"]);
const label = computed(() =>
selectedKeys.value.length ? selectedKeys.value.join(", ") : "None",
selectedKeys.value.length > 0 ? selectedKeys.value.join(", ") : "无",
);
</script>
<template>
<div class="flex flex-col gap-4">
<ToggleButtonGroup v-model="selectedKeys" selection-mode="multiple">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton id="strikethrough" is-icon-only aria-label="Strikethrough">
<ToggleButton id="strikethrough" is-icon-only aria-label="删除线">
<ToggleButtonGroupSeparator />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
<p class="text-sm text-muted">
Selected:
已选:
<span class="font-medium">{{ label }}</span>
</p>
</div>
@@ -1,47 +1,35 @@
<script setup lang="ts">
import {
ToggleButtonGroup,
ToggleButton,
ToggleButtonGroupSeparator,
} from "@heroui-vue/components";
import {
IconBold,
IconItalic,
IconUnderline,
IconStrikethrough,
} from "@tabler/icons-vue";
import { ToggleButton, ToggleButtonGroup } from "@heroui-vue/components";
import { IconBold, IconItalic, IconUnderline } from "@tabler/icons-vue";
const toggleClass =
"rounded-lg text-muted data-[selected=true]:bg-accent-soft data-[selected=true]:text-accent-soft-foreground";
</script>
<template>
<ToggleButtonGroup class="rounded-lg" selection-mode="multiple">
<ToggleButton id="bold" is-icon-only class="rounded-lg" aria-label="Bold">
<ToggleButtonGroup
aria-label="文本格式"
class="gap-1 rounded-xl border border-border/80 bg-surface p-1 shadow-sm"
selection-mode="multiple"
>
<ToggleButton id="bold" is-icon-only aria-label="粗体" :class="toggleClass">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton
id="italic"
is-icon-only
class="rounded-lg"
aria-label="Italic"
aria-label="斜体"
:class="toggleClass"
>
<ToggleButtonGroupSeparator class="opacity-25" />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton
id="underline"
is-icon-only
class="rounded-lg"
aria-label="Underline"
aria-label="下划线"
:class="toggleClass"
>
<ToggleButtonGroupSeparator class="opacity-25" />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton
id="strikethrough"
is-icon-only
class="rounded-lg"
aria-label="Strikethrough"
>
<ToggleButtonGroupSeparator class="opacity-25" />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
</template>
@@ -1,40 +1,41 @@
<script setup lang="ts">
import {
ToggleButtonGroup,
ToggleButton,
ToggleButtonGroup,
ToggleButtonGroupSeparator,
} from "@heroui-vue/components";
import { IconBold, IconItalic, IconUnderline } from "@tabler/icons-vue";
</script>
<template>
<div class="flex w-full flex-col gap-6">
<div class="flex flex-col gap-6">
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">All buttons disabled</p>
<span class="text-sm text-muted">全部按钮已禁用</span>
<ToggleButtonGroup is-disabled selection-mode="multiple">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">Individual button disabled</p>
<span class="text-sm text-muted">单个按钮已禁用</span>
<ToggleButtonGroup selection-mode="multiple">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only is-disabled aria-label="Italic">
<ToggleButton id="italic" is-disabled is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
@@ -1,34 +1,54 @@
<script setup lang="ts">
import {
ToggleButtonGroup,
ToggleButton,
ToggleButtonGroup,
ToggleButtonGroupSeparator,
} from "@heroui-vue/components";
import {
IconAlignCenter,
IconAlignLeft,
IconAlignRight,
IconBold,
IconItalic,
IconUnderline,
IconStrikethrough,
IconUnderline,
} from "@tabler/icons-vue";
</script>
<template>
<div class="w-full max-w-md">
<div class="w-full max-w-md space-y-3">
<ToggleButtonGroup full-width selection-mode="multiple">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton id="strikethrough" is-icon-only aria-label="Strikethrough">
<ToggleButton id="strikethrough" is-icon-only aria-label="删除线">
<ToggleButtonGroupSeparator />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
<ToggleButtonGroup full-width selection-mode="single">
<ToggleButton id="left">
<IconAlignLeft aria-hidden="true" />
左对齐
</ToggleButton>
<ToggleButton id="center">
<ToggleButtonGroupSeparator />
<IconAlignCenter aria-hidden="true" />
居中
</ToggleButton>
<ToggleButton id="right">
<ToggleButtonGroupSeparator />
<IconAlignRight aria-hidden="true" />
右对齐
</ToggleButton>
</ToggleButtonGroup>
</div>
</template>
@@ -1,64 +1,44 @@
<script setup lang="ts">
import {
ToggleButtonGroup,
ToggleButton,
ToggleButtonGroup,
ToggleButtonGroupSeparator,
} from "@heroui-vue/components";
import {
IconBold,
IconItalic,
IconUnderline,
IconStrikethrough,
} from "@tabler/icons-vue";
import { IconBold, IconItalic, IconUnderline } from "@tabler/icons-vue";
</script>
<template>
<div class="flex items-start gap-8">
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">Horizontal</p>
<span class="text-sm text-muted">水平</span>
<ToggleButtonGroup orientation="horizontal" selection-mode="multiple">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton
id="strikethrough"
is-icon-only
aria-label="Strikethrough"
>
<ToggleButtonGroupSeparator />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">Vertical</p>
<span class="text-sm text-muted">垂直</span>
<ToggleButtonGroup orientation="vertical" selection-mode="multiple">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton
id="strikethrough"
is-icon-only
aria-label="Strikethrough"
>
<ToggleButtonGroupSeparator />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
</div>
</div>
@@ -1,62 +1,62 @@
<script setup lang="ts">
import {
ToggleButtonGroup,
ToggleButton,
ToggleButtonGroup,
ToggleButtonGroupSeparator,
} from "@heroui-vue/components";
import {
IconAlignLeft,
IconAlignCenter,
IconAlignLeft,
IconAlignRight,
IconBold,
IconItalic,
IconUnderline,
IconStrikethrough,
IconUnderline,
} from "@tabler/icons-vue";
</script>
<template>
<div class="flex w-full flex-col gap-6">
<div class="flex flex-col gap-6">
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">Single selection</p>
<ToggleButtonGroup default-selected-keys="center" selection-mode="single">
<span class="text-sm text-muted">单选</span>
<ToggleButtonGroup
:default-selected-keys="['center']"
selection-mode="single"
>
<ToggleButton id="left">
<IconAlignLeft aria-hidden="true" />
Left
左对齐
</ToggleButton>
<ToggleButton id="center">
<ToggleButtonGroupSeparator />
<IconAlignCenter aria-hidden="true" />
Center
居中
</ToggleButton>
<ToggleButton id="right">
<ToggleButtonGroupSeparator />
<IconAlignRight aria-hidden="true" />
Right
右对齐
</ToggleButton>
</ToggleButtonGroup>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">Multiple selection</p>
<span class="text-sm text-muted">多选</span>
<ToggleButtonGroup
:default-selected-keys="['bold', 'underline']"
selection-mode="multiple"
>
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton
id="strikethrough"
is-icon-only
aria-label="Strikethrough"
>
<ToggleButton id="strikethrough" is-icon-only aria-label="删除线">
<ToggleButtonGroupSeparator />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
+51 -20
View File
@@ -1,43 +1,74 @@
<script setup lang="ts">
import {
ToggleButtonGroup,
ToggleButton,
ToggleButtonGroup,
ToggleButtonGroupSeparator,
} from "@heroui-vue/components";
import {
IconBold,
IconItalic,
IconUnderline,
IconStrikethrough,
IconUnderline,
} from "@tabler/icons-vue";
const sizes = [
{ size: "sm", label: "Small" },
{ size: "md", label: "Medium (default)" },
{ size: "lg", label: "Large" },
] as const;
</script>
<template>
<div class="flex w-full flex-col gap-6">
<div v-for="item in sizes" :key="item.size" class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">{{ item.label }}</p>
<ToggleButtonGroup selection-mode="multiple" :size="item.size">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<div class="flex flex-col gap-6">
<div class="flex flex-col gap-2">
<span class="text-sm text-muted">小</span>
<ToggleButtonGroup selection-mode="multiple" size="sm">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton
id="strikethrough"
is-icon-only
aria-label="Strikethrough"
>
<ToggleButton id="strikethrough" is-icon-only aria-label="删除线">
<ToggleButtonGroupSeparator />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
</div>
<div class="flex flex-col gap-2">
<span class="text-sm text-muted">中(默认)</span>
<ToggleButtonGroup selection-mode="multiple" size="md">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton id="strikethrough" is-icon-only aria-label="删除线">
<ToggleButtonGroupSeparator />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
</div>
<div class="flex flex-col gap-2">
<span class="text-sm text-muted">大</span>
<ToggleButtonGroup selection-mode="multiple" size="lg">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<ToggleButtonGroupSeparator />
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<ToggleButtonGroupSeparator />
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton id="strikethrough" is-icon-only aria-label="删除线">
<ToggleButtonGroupSeparator />
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
@@ -1,24 +1,25 @@
<script setup lang="ts">
import { ToggleButtonGroup, ToggleButton } from "@heroui-vue/components";
import { ToggleButton, ToggleButtonGroup } from "@heroui-vue/components";
import {
IconBold,
IconItalic,
IconUnderline,
IconStrikethrough,
IconUnderline,
} from "@tabler/icons-vue";
</script>
<template>
<ToggleButtonGroup selection-mode="multiple">
<ToggleButton id="bold" is-icon-only aria-label="Bold">
<ToggleButton id="bold" is-icon-only aria-label="粗体">
<IconBold aria-hidden="true" />
</ToggleButton>
<ToggleButton id="italic" is-icon-only aria-label="Italic">
<ToggleButton id="italic" is-icon-only aria-label="斜体">
<IconItalic aria-hidden="true" />
</ToggleButton>
<ToggleButton id="underline" is-icon-only aria-label="Underline">
<ToggleButton id="underline" is-icon-only aria-label="下划线">
<IconUnderline aria-hidden="true" />
</ToggleButton>
<ToggleButton id="strikethrough" is-icon-only aria-label="Strikethrough">
<ToggleButton id="strikethrough" is-icon-only aria-label="删除线">
<IconStrikethrough aria-hidden="true" />
</ToggleButton>
</ToggleButtonGroup>
+5 -4
View File
@@ -1,13 +1,14 @@
<script setup lang="ts">
import { ToggleButton } from "@heroui-vue/components";
import { IconHeart, IconBookmark } from "@tabler/icons-vue";
import { IconBookmark, IconHeart } from "@tabler/icons-vue";
</script>
<template>
<div class="flex gap-3">
<ToggleButton is-icon-only aria-label="Like">
<div class="flex items-center gap-3">
<ToggleButton is-icon-only aria-label="点赞">
<IconHeart aria-hidden="true" />
</ToggleButton>
<ToggleButton is-icon-only variant="ghost" aria-label="Bookmark">
<ToggleButton is-icon-only aria-label="收藏" variant="ghost">
<IconBookmark aria-hidden="true" />
</ToggleButton>
</div>

Some files were not shown because too many files have changed in this diff Show More