Compare commits

...

100 Commits

Author SHA1 Message Date
maoyingjie 2eb787a0bb docs: accept HD-09 measured virtual layout and R1 verification 2026-10-29 17:17:44 +08:00
maoyingjie 6d9e3f31cf fix(list-box): update conditional virtual loader reservations 2026-10-29 17:15:30 +08:00
maoyingjie 5a00e25a25 fix(virtualization): measure natural rows and align viewport geometry 2026-10-29 17:13:12 +08:00
maoyingjie 9f7eb1fa8d docs: record HD-09 review blockers and R1 repair requirements 2026-10-29 16:37:36 +08:00
maoyingjie ae27fb28d1 fix(list-box): preserve typed virtual keys and add HD-09 review repros 2026-10-29 16:36:02 +08:00
maoyingjie ee37e66d37 docs: record HD-09 virtual layout results and layout mapping
Results table with geometry evidence (row heights, visible rows, scroll
sizes against the pinned demos), the native-table scroll-container
verdict, tarball contract extension and the recorded gaps
(estimatedHeadingHeight, dropIndicatorThickness, popover height clamp).
2026-10-29 16:22:46 +08:00
maoyingjie 9e8d89e48d feat(collections): virtual row layout with variable heights, headings, loader and gap/padding
ListBox virtualized mode grows a full row stream (padding spacers, data-driven
heading rows, item rows, #loader row) with px semantics mapped from the pinned
ListLayout contract: rowHeight may be a per-index function falling back to
estimatedRowHeight, gap sits between content rows only, padding is end
spacers, and every input is re-read per layout pass. Scroll ownership resolves
to the list root or the nearest scrolling ancestor so popovers scroll as a
whole with a sticky search field (data-virtualized hook; the historical 320px
self-scroll rule stays for non-virtualized lists).

Table gains the public useVirtualRows/bindVirtualRows pure geometry helpers
(prefix sums + binary search, no state kernel): variable heights, estimated
fallback, gap/padding and a loader reservation that stays consistent with the
rendered spacers. headingHeight and dropIndicatorThickness remain unavailable
(no sectioned header model, no drag-and-drop) and are recorded as such.

Pinned demo values stay explicit (table 42px, list-box/autocomplete 50px);
the table demo scrolls an outer viewport div because a native table cannot be
a scroll container (verified: 300px height blown out to 45036px).
2026-10-29 16:21:09 +08:00
maoyingjie dd4f04c200 Merge header hover parity fixes into main 2026-10-29 15:02:43 +08:00
maoyingjie aa881d21d5 docs: accept HD-10 collections review and submenu fixes 2026-10-29 14:47:56 +08:00
maoyingjie bf6cf0f8d1 fix(dropdown): preserve disabled and click semantics during submenu delays 2026-10-29 14:45:59 +08:00
maoyingjie d1528569a8 docs: record HD-10 collections loading, filtering and submenu results 2026-10-29 13:46:48 +08:00
maoyingjie c8d54abefb feat(collections): auto incremental async loading, shared filtering and submenu delay
HD-10 scope, against heroui ce90ea3 collection sources and their
react-aria/react-stately dependencies:

- the ComboBox async demo now auto-loads on scroll-to-bottom
  (IntersectionObserver sentinel + fill chain mirroring the pinned
  ListBoxLoadMoreItem re-observe semantics), never duplicates requests
  (loading guards + monotonic sequence token), drops stale responses on
  query switches, keeps a retry path for failures (injectable mock
  failure) and documents its differences from the pinned SWAPI source;
  the Select demo's observer stays untouched (real-network scroll
  triggering verified in browser)
- the Autocomplete virtualization demo and the default filter share one
  locale-sensitive matcher: createBaseContains (Intl.Collator base
  sensitivity, cafe matches Cafe with accent folding) is now exported
  from the package root
- Autocomplete trigger semantics verified complete (single tab stop,
  Enter/Space/Escape/Delete/IME, single and multiple selection) and the
  scoped slots gained composition data instead of child copying:
  AutocompleteValue exposes selectedItem and per-entry source item,
  the ComboBox root exposes selectedItem
- DropdownSubmenuTrigger exposes the pinned delay contract (default
  200ms): the controlled open gate retimes Reka's fixed 100ms hover,
  keyboard opens stay immediate and cancel the pending hover, pointer
  leave cancels; the dead side/align forwarding is gone (Reka fixes the
  submenu side per direction); Button/Avatar trigger layout
  compensation kept after browser proof it is what wins the cascade
- tests/fixtures/collections-rtl.vue drives the real-browser delay and
  RTL geometry checks; b02-pickers contract pins the new export and
  slot typing

Full suite 111 files / 1666 tests, typecheck, build:docs and the
b02-pickers + api-root-aliases tarball contracts pass.
2026-10-29 13:46:34 +08:00
maoyingjie c34faccd70 docs: accept HD-08 table review and boundary fixes 2026-10-29 11:11:46 +08:00
maoyingjie c019768e6a fix(table): align constrained widths and guard invalid fr factors 2026-10-29 11:11:10 +08:00
maoyingjie 86d76a0675 docs: record HD-08 table empty state, sort focus and column width results 2026-10-29 10:59:39 +08:00
maoyingjie 658dfbb7d9 fix(table): full-width empty state, sort focus ring and fr column widths
HD-08 scope, against heroui ce90ea3 table sources and their
react-aria/react-stately dependencies:

- TableBody empty state now spans every real leaf column by default
  (self-registered TableColumns — selection and wrapper-rendered ones
  included — reactively following column changes), explicit colspan
  still wins, and the vnode-level empty detection keeps avoiding
  unknown-component setup/render probing
- sorting keeps one activation per click/Enter/Space (single sort path
  via the column) while the baseline focus ring returns: the trigger
  button keeps keyboard focus and forwards its real :focus-visible
  state to the th's existing [data-focus-visible] hook, so the inset
  ring lands on the column header like the pinned source and the UA
  outline is suppressed only inside a column; aria-sort="none" on
  sortable unsorted columns matches useTableColumnHeader and stays
- defaultWidth="Nfr" distributes the remaining width by weight
  instead of silently becoming auto: widths.ts ports react-stately's
  calculateColumnSizes (static px/% first, fr flex-grow sharing,
  min/max violation freezing, cascade rounding); fr mode locks
  table-layout: fixed for exact geometry, re-shares on container
  resize, freezes dragged columns to their pixel width and keeps
  geometry (with flipped drag direction) in RTL; unmeasured
  environments keep native widths
- .table__cell's text-start/font-normal verified to block caller
  inheritance and narrowed to th.hv-table__cell { inherit }, keeping
  the baseline td row-header typography while ancestor align/weight
  cascade into cells again; th scope=row, corner selectors and the
  resizer z-index fix are untouched
- tests/fixtures/table-layout.vue (playground) drives the real-browser
  geometry/drag/RTL/theme verification; m35-m36 contract pins the two
  new CSS markers in the final tarball

Full suite 111 files / 1657 tests, typecheck, build:docs and the
m35-m36 + handbook-styles tarball contracts pass.
2026-10-29 10:59:24 +08:00
maoyingjie aac93db658 docs: accept HD-07 field and OTP verification 2026-10-29 09:32:06 +08:00
maoyingjie 2d7e3d4e1e fix: complete field and OTP public contracts (HD-07) 2026-10-29 09:30:58 +08:00
maoyingjie 27cc62e36f docs: accept HD-06 link navigation and focus behavior 2026-10-29 09:05:05 +08:00
maoyingjie 68d45c66f9 fix: disable link navigation and align breadcrumb actions and date focus 2026-10-29 09:03:52 +08:00
maoyingjie 680a592e7b docs: accept HD-05 shared style exports and border fallback 2026-10-28 23:44:37 +08:00
maoyingjie 0b303476c2 docs: record HD-05 styles export and border fallback results 2026-10-28 23:37:21 +08:00
maoyingjie dc859fb8ae feat(styles): export shared field variant maps and restore the border fallback
HD-05 scope, against heroui ce90ea3 styles sources:

- add labelVariants/descriptionVariants/fieldErrorVariants/
  textFieldVariants/switchGroupVariants (+ VariantProps types) to
  @heroui-vue/styles and re-export them from @heroui-vue/components;
  variant keys, defaultVariants and slot sets match the pinned
  *.styles.ts files key for key (hv- namespace only)
- Label/Description/FieldError/useTextField/SwitchGroup now consume
  those mappings instead of inline class strings, so the state classes
  have a single source; rendered class output is unchanged and pinned
  by tests/shared-field-styles.test.ts (mapping output <-> component
  output)
- restore the global border-color fallback
  (*, ::after, ::before, ::backdrop, ::file-selector-button ->
  border-color: var(--border, currentColor)) in a new base/base.css,
  imported layer(base) right after preflight like the pinned entry:
  a low-priority default that components, utilities and consumer CSS
  override without !important
- view-transition globals from the pinned base.css stay unported: no
  View Transitions API usage exists in the library or docs site
- shared-styles package contract: packed runtime exports from both
  entries, variant-output assertions, CSS tokens incl. the fallback,
  strict nodenext+bundler type contract, and a real-browser consumer
  fixture (light/dark --border, explicit colors, consumer overrides,
  currentColor fallback) wired into check-package.mjs
- docs: styling layers/border fallback/exports notes, five component
  API pages, compatibility matrix and upstream source records

Full suite 111 files / 1634 tests, typecheck and build:docs pass;
shared-styles + api-root-aliases + handbook-styles verified against
the final tarballs.
2026-10-28 23:36:59 +08:00
maoyingjie 35b602e5b9 docs: accept HD-04 documentation and showcase closeout 2026-10-28 23:06:47 +08:00
maoyingjie f9938eea8c fix(docs): restore related showcases and correct CSS customization examples 2026-10-28 23:06:08 +08:00
maoyingjie cfbcb38ec3 docs: record HD-04 documentation closeout results 2026-10-28 22:32:36 +08:00
maoyingjie 145a208687 docs: close documentation facts, structure and related-component mapping
HD-04 scope, against heroui ce90ea3 cn sources:

- stale/fictional content: input.md no longer claims TextField is
  unmigrated; color-field.md no longer claims ColorPicker is private;
  header.md drops the fictional Header.Root subcomponent and the stale
  'menus not migrated' wording (MenuSection label registration is now
  documented from HeaderRoot source); radio-group.md drops three copied
  CheckboxGroup wordings (variant override is Radio's, scalar emits,
  native single-value submit); input-otp.md drops the fictional
  data-complete state and lists the real missing upstream props
- toggle-button disabled row now matches the real CSS hooks
  (:disabled / [aria-disabled], with data-disabled as a marker only)
- part API / CSS classes / interactive states restored per pinned
  sources: button (full class lists + real variable-based global CSS),
  accordion (per-part tables + variant/state lists), card (per-part
  tables + variant list), switch (SwitchGroup snippet + Switch/
  SwitchGroup class lists + states), color-field Group (class list +
  states), input-otp (variant notes, global CSS, class/state lists);
  input-group gains the two upstream usage chapters
- RelatedComponents restored from the pinned componentRelationships
  (first-3, filtered against componentsMap): 64 pages rewritten,
  list-box/slider sections added, 7 empty-mapping pages' fabricated
  entries removed; RelatedShowcases left unmigrated with its real data
  inventory recorded (2 cases, showcase-site cards)
- defaults unified on implementation evidence: granularity (inferred
  day/minute) and visibleYears (full min-max span, no "or 20" fallback);
  HD-03 hand-offs resolved (trigger focus-visible noted for HD-06,
  width guards kept)
- new demos: header-collection-grouping (MenuSection/ListBoxSection
  label wiring), empty-state-collection (collection empty slot);
  empty-state page deduplicated with a boundary compatibility note
- ComponentPreview minHeight/isBgSolid restored per the 30 upstream
  marks; tabs-overflow max-w-full kept after measuring internal scroll
- tests: +3 header registration/demo cases, +1 empty-state collection
  case; full suite 110 files / 1630 tests, typecheck and build:docs
  pass
2026-10-28 22:32:10 +08:00
maoyingjie 2c6d871354 docs: accept HD-03 locale and responsive popover fixes 2026-10-28 17:50:32 +08:00
maoyingjie 462044c3b8 fix(demos): bound format popover width and keep mobile trigger reachable 2026-10-28 17:49:49 +08:00
maoyingjie 1029444a98 docs: record HD-03 date demo locale and popover results 2026-10-28 16:37:16 +08:00
maoyingjie 2e3fdd4800 fix(demos): inherit ConfigProvider locale and restore the format-options popover width
HD-03 scope, all against heroui ce90ea3 cn sources:

- calendar-disabled/read-only: restore the today() default value and the
  baseline description lines (日历已禁用 / 日历为只读) inside the
  flex flex-col items-center wrapper
- calendar-controlled: restore the second button row (设为今天/设为圣诞节/
  清空) and the baseline feedback wording (已选日期:…(未选))
- locale inheritance: add a public useLocale() accessor (the components'
  ConfigProvider → en-US/ltr chain) and use it for startOfWeek in
  calendar-controlled, isWeekend in booking-calendar/unavailable-dates and
  the DateFormatter in date-range-picker-format-options instead of the
  hardcoded 'en-US' / 'zh-CN' literals
- date-range-picker-format-options: restore the pinned w-full popover class;
  the pinned source positions the popover against the initial containing
  block (full viewport width — verified on the reference docs at desktop and
  narrow), while Reka's shrink-to-fit positioning wrapper collapses the same
  class. A scoped adapter rule (.hv-date-range-picker__popover.w-full →
  100vw, layering-safe like the dropdown static-wrapper adapter) restores
  the baseline effect: viewport-wide popover, 252px calendar, stretched
  time rows, identical boundary clamping

- tests: locale dynamic-switching regressions covering zh-CN/en-US for week
  start, weekend rules (with ar-EG flipping the weekend for a observable
  rule change) and range formatting; full suite 110 files / 1627 tests,
  typecheck, build:docs and the date-range-picker / api-root-aliases /
  calendar tarball contracts pass
2026-10-28 16:35:26 +08:00
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 4bfc2ef170 docs: record corrected reference hover verification 2026-10-28 08:49:27 +08:00
maoyingjie 652cf854be fix(docs): match reference navigation and search hover colors 2026-10-28 08:49:11 +08:00
maoyingjie 28b0b3f0b6 docs: clarify reference header hover behavior 2026-10-28 08:48:35 +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
maoyingjie a9bfc71c8a docs: record Root aliases main integration 2026-10-27 19:56:20 +08:00
maoyingjie 08c9bf5767 merge: integrate verified Root aliases and ProgressBar demo 2026-10-27 19:56:07 +08:00
maoyingjie bdbb2cb7dc docs: accept API aliases and progress demo review fixes 2026-10-27 19:56:07 +08:00
maoyingjie 5937577101 test: reproduce NumberField typing regression within one task 2026-10-27 19:55:43 +08:00
maoyingjie 9720ba1d03 docs: record API root aliases and progress-bar demo results 2026-10-27 19:50:38 +08:00
maoyingjie 8f51b0e097 feat: align public Root aliases and rework progress-bar custom-value demo
- 包根补齐固定上游 82 对 Xxx/XxxRoot 同对象别名(55 个缺失 Root 别名 + Dropdown 反向别名)与 59 个 RootProps/Menu/Dropdown 类型别名;不杜撰上游没有的名称(如 CheckboxGroupRoot、ToastRootProps)
- tests/package 新增 api-root-aliases 契约:完整别名清单、82 对身份等价断言与 strict NodeNext/bundler 类型正反例
- progress-bar custom-value 演示回填公共 NumberField/Select,保持固定源文案/布局/范围/四格式与边界处理
- 修复 NumberFieldInput keydown 无条件 restore 还原同任务键入字符的缺陷,并入 number-field 回归
- 文档导航 dropdown 归位固定 meta.json 顺序并补顺序断言;修正“原生临时控件”陈述
2026-10-27 19:48:35 +08:00
maoyingjie e0dd052cc3 docs: record Form main integration verification 2026-10-27 18:29:25 +08:00
maoyingjie 0847db9ae0 merge: integrate verified public Form migration 2026-10-27 18:28:58 +08:00
maoyingjie f53ce0a520 docs: record Form client migration acceptance 2026-10-27 18:28:58 +08:00
maoyingjie 2c221e0995 feat: complete public Form migration and validation focus contract 2026-10-27 18:28:13 +08:00
maoyingjie f424fa5597 docs: plan public Form migration completion 2026-10-27 18:16:46 +08:00
maoyingjie ee43cc615d docs: record Avatar main integration verification 2026-10-27 18:06:38 +08:00
maoyingjie 8f3880073d merge: integrate verified Avatar migration completion 2026-10-27 18:06:02 +08:00
maoyingjie 4f2061a809 docs: record Avatar migration acceptance evidence 2026-10-27 18:06:02 +08:00
maoyingjie fa8b22719e fix: complete Avatar image composition and fallback migration 2026-10-27 18:05:26 +08:00
maoyingjie 6de246de49 docs: plan Avatar migration completion 2026-10-27 17:59:15 +08:00
maoyingjie c05cc7dfa7 docs: record ColorPicker main integration verification 2026-10-27 17:57:01 +08:00
maoyingjie 23eecaffef merge: integrate verified ColorPicker migration 2026-10-27 17:56:32 +08:00
maoyingjie 74cd597b81 fix: close ColorPicker review findings and record acceptance 2026-10-27 17:56:32 +08:00
maoyingjie 63606399e3 docs: record ColorPicker migration and client verification 2026-10-27 17:48:47 +08:00
maoyingjie ee5fce9adb feat: migrate public ColorPicker composition 2026-10-27 17:47:52 +08:00
maoyingjie 312d223f7c docs: start ColorPicker public migration task 2026-10-27 16:31:36 +08:00
maoyingjie d75540c5be docs: plan public ColorPicker migration 2026-10-27 16:14:59 +08:00
maoyingjie b72a6e0dd0 docs: record ColorSwatchPicker main integration verification 2026-10-27 16:05:15 +08:00
maoyingjie 457d340d7b merge: integrate verified ColorSwatchPicker migration 2026-10-27 16:04:32 +08:00
maoyingjie 8e8fc69117 docs: accept swatch picker migration after review fixes 2026-10-27 16:04:32 +08:00
maoyingjie 3c8473d597 fix: cancel swatch picker press ownership on window blur 2026-10-27 16:03:46 +08:00
maoyingjie 3a4142e891 docs: record ColorSwatchPicker review fixes 2026-10-27 15:24:58 +08:00
maoyingjie adca8d0047 fix: handle ColorSwatchPicker activation lifecycle and dynamic focus 2026-10-27 15:23:24 +08:00
maoyingjie 980930ed76 test: record ColorSwatchPicker review regressions and findings 2026-10-27 15:12:41 +08:00
maoyingjie efb53d4ce7 docs: record ColorSwatchPicker migration and client verification 2026-10-27 14:44:07 +08:00
maoyingjie 8d9adda8da feat: publish ColorSwatchPicker and shared swatch picker parts 2026-10-27 14:42:29 +08:00
maoyingjie fa4146ee0b docs: plan public ColorSwatchPicker migration 2026-10-27 13:11:10 +08:00
438 changed files with 25193 additions and 1954 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>
@@ -0,0 +1,125 @@
<script setup lang="ts">
// Adapted from HeroUI ce90ea3 related-showcases/showcase-item and registry/navigation,
// Apache-2.0. Cards link to the upstream React examples; no local showcase runtime.
import { computed } from "vue";
const props = defineProps<{ component: string }>();
const cdn =
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/showcases";
const showcases = [
{
name: "apple-iphone-disclosure",
title: "Apple iPhone 17 Pro Disclosure",
components: ["DisclosureGroup", "Disclosure", "Button"],
asset: 1,
},
{
name: "apple-iphone-camera-zoom",
title: "Apple iPhone 17 Pro Camera Zoom",
components: ["Tabs"],
asset: 2,
},
];
const items = computed(() =>
showcases.filter((item) =>
item.components.some(
(name) => name.toLowerCase() === props.component.toLowerCase(),
),
),
);
</script>
<template>
<div v-if="items.length" class="docs-related-showcases not-prose">
<a
v-for="item in items"
:key="item.name"
class="showcase-card"
:href="`https://heroui.com/cn/showcase/${item.name}`"
target="_blank"
rel="noopener noreferrer"
:aria-label="`${item.title}(上游 React 案例,新窗口)`"
>
<div class="showcase-media">
<span class="showcase-status">new</span>
<video
autoplay
loop
muted
playsinline
preload="none"
:poster="`${cdn}/${item.asset}.jpg`"
>
<source :src="`${cdn}/${item.asset}.mp4`" type="video/mp4" />
</video>
</div>
<span class="showcase-title">{{ item.title }}</span>
</a>
</div>
</template>
<style scoped>
.docs-related-showcases {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 250px));
gap: 16px;
padding: 8px;
margin: 0 -8px;
}
.showcase-card {
position: relative;
display: flex;
flex-direction: column;
height: 180px;
max-width: 250px;
min-width: 0;
color: var(--foreground);
text-decoration: none;
}
.showcase-media {
position: relative;
flex: 1;
min-height: 0;
overflow: hidden;
border: 1px solid transparent;
border-radius: 12px;
box-shadow: var(--surface-shadow);
transition: transform 250ms ease-out;
}
.showcase-card:hover .showcase-media {
transform: scale(1.02);
}
.showcase-card:focus-visible {
outline: 2px solid var(--focus);
outline-offset: 4px;
border-radius: 12px;
}
.showcase-media video {
width: 100%;
height: 100%;
object-fit: cover;
}
.showcase-status {
position: absolute;
z-index: 1;
top: 6px;
right: 8px;
padding: 2px 6px;
border: 1px solid rgb(255 255 255 / 10%);
border-radius: 999px;
background: rgb(255 255 255 / 10%);
color: rgb(255 255 255 / 80%);
font-size: 11px;
}
.showcase-title {
margin-top: 12px;
padding: 0 4px;
font-size: 14px;
color: color-mix(in oklab, var(--foreground) 50%, transparent);
}
@media (prefers-reduced-motion: reduce) {
.showcase-media {
transition: none;
}
}
</style>
+13 -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>
@@ -381,6 +382,7 @@ async function copyMarkdownCode(event: MouseEvent) {
<IconArrowUpRight :size="12" aria-hidden="true" />
</Link>
<Link
v-if="frontmatter.stylesSource !== false"
:href="`https://github.com/heroui-inc/heroui/blob/ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960/packages/styles/components/${componentSlug}.css`"
target="_blank"
rel="noreferrer noopener"
@@ -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,
);
}
+4
View File
@@ -2,8 +2,10 @@ 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 DocsRelatedShowcases from "./DocsRelatedShowcases.vue";
import "@heroui-vue/styles/css";
import "./utilities.css";
import "./style.css";
@@ -12,8 +14,10 @@ export default {
Layout,
enhanceApp({ app }) {
app.component("ComponentPreview", Demo);
app.component("DocsRelatedShowcases", DocsRelatedShowcases);
app.component("DocsCopyButton", Button);
app.component("DocsComponents", DocsComponents);
app.component("DocsColorSection", DocsColorSection);
app.component("DocsCopyIcon", IconCopy);
app.component("DocsCheckIcon", IconCheck);
},
+25 -5
View File
@@ -100,6 +100,11 @@ export const componentItems: DocsItem[] = [
url: "/components/color-field",
category: "colors",
},
{
title: "ColorPicker 颜色选择器",
url: "/components/color-picker",
category: "colors",
},
{
title: "ColorSlider 颜色滑块",
url: "/components/color-slider",
@@ -110,6 +115,11 @@ export const componentItems: DocsItem[] = [
url: "/components/color-swatch",
category: "colors",
},
{
title: "ColorSwatchPicker 颜色色块选择器",
url: "/components/color-swatch-picker",
category: "colors",
},
{
title: "ComboBox 组合框",
url: "/components/combo-box",
@@ -150,6 +160,11 @@ export const componentItems: DocsItem[] = [
url: "/components/drawer",
category: "overlays",
},
{
title: "Dropdown 下拉菜单",
url: "/components/dropdown",
category: "collections",
},
{
title: "EmptyState 空状态",
url: "/components/empty-state",
@@ -170,6 +185,11 @@ export const componentItems: DocsItem[] = [
url: "/components/fieldset",
category: "forms",
},
{
title: "Form 表单",
url: "/components/form",
category: "forms",
},
{
title: "Header 标题",
url: "/components/header",
@@ -205,11 +225,6 @@ export const componentItems: DocsItem[] = [
url: "/components/link",
category: "navigation",
},
{
title: "Dropdown 下拉菜单",
url: "/components/dropdown",
category: "collections",
},
{
title: "ListBox 列表框",
url: "/components/list-box",
@@ -377,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" },
],
},
+16 -3
View File
@@ -57,6 +57,7 @@ html {
min-width: 0;
}
.docs-nav .brand {
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 10px;
@@ -127,6 +128,7 @@ html {
height: 100%;
}
.docs-nav-sections nav .hv-link {
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 8px;
@@ -142,6 +144,11 @@ html {
border-color: var(--accent);
color: var(--foreground);
}
@media (hover: hover) {
.docs-nav-sections nav .hv-link:is(:hover, [data-hovered="true"]) {
color: var(--foreground);
}
}
.docs-theme-wide {
padding: 2px;
border-radius: 999px;
@@ -251,6 +258,7 @@ html {
margin: -8px 0 32px;
}
.source-links .hv-link {
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 4px;
@@ -418,6 +426,7 @@ html {
margin-top: 8px;
}
.component-index-title {
text-decoration: none;
font-size: 16px;
font-weight: 500;
line-height: 24px;
@@ -429,9 +438,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;
@@ -471,6 +477,7 @@ html {
margin-left: auto;
}
.search-trigger .hv-kbd {
color: inherit;
height: 20px;
line-height: 20px;
font-size: 14px;
@@ -482,6 +489,11 @@ html {
box-shadow: none;
white-space: nowrap;
}
@media (hover: hover) {
.search-trigger:is(:hover, [data-hovered="true"]) {
color: var(--foreground);
}
}
.dark .search-trigger {
background: color-mix(
in oklab,
@@ -551,6 +563,7 @@ html {
scrollbar-width: thin;
}
.search-results .hv-link {
text-decoration: none;
display: block;
padding: 12px;
border: 1px solid transparent;
+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#快速开始)。
+76 -18
View File
@@ -37,7 +37,7 @@ import {
</template>
```
<ComponentPreview name="accordion-basic" />
<ComponentPreview name="accordion-basic" minHeight="400px" />
## 组件结构
@@ -76,37 +76,37 @@ Accordion 复用 DisclosureGroup 的展开键协议(数组、字符串/数字
### 表面样式
<ComponentPreview name="accordion-surface" />
<ComponentPreview name="accordion-surface" minHeight="400px" />
### 无分隔线
<ComponentPreview name="accordion-without-separator" />
<ComponentPreview name="accordion-without-separator" minHeight="400px" />
### 多项展开
<ComponentPreview name="accordion-multiple" />
<ComponentPreview name="accordion-multiple" minHeight="524px" />
### 禁用状态
<ComponentPreview name="accordion-disabled" />
<ComponentPreview name="accordion-disabled" minHeight="524px" />
### 受控组件
<ComponentPreview name="accordion-controlled" />
<ComponentPreview name="accordion-controlled" minHeight="400px" />
### 自定义指示器
<ComponentPreview name="accordion-custom-indicator" />
<ComponentPreview name="accordion-custom-indicator" minHeight="320px" />
### 渲染函数
上游 `render` 映射为 `as` 与透传属性。
<ComponentPreview name="accordion-render-function" />
<ComponentPreview name="accordion-render-function" minHeight="400px" />
### 常见问题布局
<ComponentPreview name="accordion-faq" />
<ComponentPreview name="accordion-faq" minHeight="720px" />
## 自定义样式
@@ -130,11 +130,40 @@ Accordion 复用 DisclosureGroup 的展开键协议(数组、字符串/数字
## 样式参考
- `.hv-accordion` - 根容器
- `.hv-accordion__item` - 单项与分隔线
- `.hv-accordion__heading` / `.hv-accordion__trigger` / `.hv-accordion__indicator`
- `.hv-accordion__panel` / `.hv-accordion__body` / `.hv-accordion__body-inner`
- `.hv-accordion--surface` - 表面变体
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
### CSS 类
Accordion 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/accordion.css)):
#### 基础类 [!toc]
- `.hv-accordion` - Accordion 根容器
- `.hv-accordion__item` - 单个 Accordion 项(含分隔线)
- `.hv-accordion__heading` - 标题包裹层
- `.hv-accordion__trigger` - 可点击的触发按钮
- `.hv-accordion__indicator` - 展开/收起指示图标
- `.hv-accordion__panel` - 可折叠面板容器(高度动画宿主)
- `.hv-accordion__body` / `.hv-accordion__body-inner` - 正文外层与内层包裹
#### 变体类 [!toc]
- `.hv-accordion--surface` - 表面变体(边框、背景与分隔线收口)
#### 状态类 [!toc]
- `.hv-accordion__trigger[aria-expanded="true"]` - 展开状态
- `.hv-accordion__trigger[aria-disabled="true"]` - 禁用状态
- `.hv-accordion__panel[data-expanded="true"]` / `.hv-accordion__indicator[data-expanded="true"]` - 面板与指示器的展开标记
### 交互状态
触发器以 CSS 伪类为主(组件不输出 `data-hovered` / `data-focus-visible` 标记,可通过 attrs 传入这些标记作为自定义样式钩子):
- **悬停**:触发器上 `:hover`(仅未展开时上色)
- **聚焦**:触发器上 `:focus-visible`(显示焦点环)
- **禁用**:触发器上 `:disabled` 或 `[aria-disabled="true"]`(同时输出 `[data-disabled="true"]` 标记)
- **展开**:触发器上 `[aria-expanded="true"]`
## API 参考
@@ -161,11 +190,40 @@ Accordion 复用 DisclosureGroup 的展开键协议(数组、字符串/数字
| `isDisabled` | `boolean` | `false` | 禁用该项 |
| `as` | `string` | `"div"` | 项根元素 |
### AccordionHeading / Trigger / Panel / Body / Indicator
### AccordionHeading
与 Disclosure 对应部件语义一致,使用 `hv-accordion__*` 样式;Trigger 为 `type="button"`,Panel 负责高度动画,Indicator 支持自定义图标插槽。
| 属性 | 类型 | 默认值 | 描述 |
| -------- | --------------------------- | ------ | -------------- |
| `as` | `string` | `'h3'` | 标题根元素标签 |
| `level` | `number` | `3` | 语义标题级别 |
| `class` | `string \| Array \| Object` | - | 额外的 CSS 类 |
| 默认插槽 | - | - | 标题内容 |
### AccordionTrigger
| 属性 | 类型 | 默认值 | 描述 |
| -------------- | --------------------------- | ---------- | ------------------------------------------------ |
| `as` | `string` | `'button'` | 触发器根元素;为 `button` 时输出 `type="button"` |
| `asChild` | `boolean` | `false` | 将展开切换与状态合并到默认插槽中唯一的根元素 |
| `class` | `string \| Array \| Object` | - | 额外的 CSS 类 |
| 默认作用域插槽 | - | - | 提供 `isExpanded`、`isDisabled` |
### AccordionPanel / AccordionBody
| 属性 | 类型 | 默认值 | 描述 |
| -------- | --------------------------- | ------- | ---------------------------------------------------------- |
| `as` | `string` | `'div'` | 根元素;Panel 负责高度动画,Body 的 `class` 落在内层包裹上 |
| `class` | `string \| Array \| Object` | - | 额外的 CSS 类 |
| 默认插槽 | - | - | 面板 / 正文内容 |
### AccordionIndicator
| 属性 | 类型 | 默认值 | 描述 |
| -------------- | ---- | ------ | ------------------------------------------------------------------ |
| 默认作用域插槽 | - | - | 自定义指示图标;提供 `isExpanded`。缺省时渲染基线 ChevronDown 图标 |
与 Disclosure 对应部件语义一致,使用 `hv-accordion__*` 样式。
## 相关组件
- [Disclosure 折叠面板](./disclosure)
- [DisclosureGroup 折叠面板组](./disclosure-group)
[DisclosureGroup 折叠面板组](./disclosure-group) · [Disclosure 折叠面板](./disclosure)
+1 -2
View File
@@ -296,5 +296,4 @@ state.setOpen(true);
## 相关组件
- [Modal 模态框](./modal)
- [Button 按钮](./button)
[Button 按钮](./button) · [CloseButton 关闭按钮](./close-button)
+1 -1
View File
@@ -145,4 +145,4 @@ Alert 会把内部 `surfaceContext` 重置为 `default`,避免嵌套在其他
## 相关组件
[Button 按钮](./button) · [CloseButton 关闭按钮](./close-button) · [Spinner 加载指示器](./spinner)
[CloseButton 关闭按钮](./close-button) · [Button 按钮](./button) · [Spinner 加载指示器](./spinner)
+5 -3
View File
@@ -162,7 +162,7 @@ Autocomplete 组件支持两种视觉变体:
::: warning
多选模式下,上游 `Autocomplete.Value` 会把每个选中项在 `ListBox.Item` 中的 children 复制到触发器中,并以符合当前语言环境的分隔符连接:仅包含文本的选项显示为纯文本,但复选框、头像等可见内容会随每个选中项各出现一次;函数形式的 children 也始终以 `isSelected: false` 调用。
本库不复制子树,而是给 `AutocompleteValue` 的作用域插槽提供 `selectedItems`(`{ key, textValue }[]`)与 `selectedText`(纯文本),因此不存在上述重复渲染问题,但函数形式的插槽同样不携带 `isSelected`。
本库不复制子树,而是给 `AutocompleteValue` 的作用域插槽提供 `selectedItems`(`{ key, textValue, item? }[]`,`item` 为根 `items` 中的源数据项)、`selectedItem`(首个选中项)与 `selectedText`(纯文本),调用方可直接用源数据组合头像、可移除标签等丰富展示,因此不存在上述重复渲染问题,但函数形式的插槽同样不携带 `isSelected`。
:::
如需以纯文本显示选中值,请使用 `selectedText`:
@@ -437,15 +437,17 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co
| `isPlaceholder` | `boolean` | 是否没有选中项 |
| `defaultChildren` | `string`(上游为 `ReactNode`) | 缺省文本(选中项文本以逗号连接,否则占位符) |
| `selectedText` | `string` | 选中项 `textValue` 的连接文本 |
| `selectedItems` | `Array<{ key, textValue }>` | 选中项 |
| `selectedItems` | `Array<{ key, textValue, item? }>` | 选中项;`item` 为根 `items` 中的源数据项(集合自发现的项没有) |
| `selectedItem` | `{ key, textValue, item? } \| null` | 首个选中项(单选即所选项),便于单选组合 |
上游 `state.selectedItems`(节点)在本库中是上表的 `selectedItems`(数据);不复制 item 子树,见「多选」说明。
上游 `state.selectedItems`(节点)在本库中是上表的 `selectedItems`(数据,条目携带源数据 `item`);不复制 item 子树,见「多选」说明。
### 过滤函数(`useFilter` 替代)
上游页面导出的 `useFilter` hook(`contains` / `startsWith` / `endsWith` 与 `sensitivity`)在本库没有对应导出。替代方式:
- `AutocompleteFilter` 的默认谓词等价于 `useFilter({ sensitivity: "base" }).contains`:按 `ConfigProvider` 的 locale 折叠大小写与变音符号,`cafe` 能命中 `Café`
- 调用方自行过滤数据时(虚拟化、异步数据源),可从包根导入 `createBaseContains`(与默认谓词同一实现)保持语义一致:`const { locale } = useLocale(); const contains = createBaseContains(locale.value)`
- 需要 `startsWith` / `endsWith` 等语义时,直接给 `:filter="(text, input) => …"` 传函数
- 数据源或调用方已过滤时(异步、虚拟化示例),传 `:filter="() => true"` 避免二次过滤
+1 -1
View File
@@ -145,4 +145,4 @@ AvatarGroup 组件使用以下 CSS 类:
## 相关组件
[Avatar 头像](./avatar) · [Card 卡片](./card)
[Avatar 头像](./avatar) · [Badge 徽章](./badge) · [Chip 标签](./chip)
+12 -8
View File
@@ -110,7 +110,7 @@ Avatar 组件使用以下 CSS 类:
## API 参考
### Avatar
### Avatar / AvatarRoot
| Prop | 类型 | 默认值 | 描述 |
| --------- | ------------------------------------------------------------- | ----------- | ----------------- |
@@ -123,7 +123,7 @@ Avatar 组件使用以下 CSS 类:
| Prop | 类型 | 默认值 | 描述 |
| ------------- | ---------------------------------- | ------- | ------------------------------------------ |
| `src` | `string` | - | 图片 URL |
| `src` | `string` | - | 可选图片 URL,省略时显示回退 |
| `srcSet` | `string` | - | 响应式图片的 `srcset` 属性 |
| `sizes` | `string` | - | 响应式图片的 `sizes` 属性 |
| `alt` | `string` | - | 图片替代文本 |
@@ -136,14 +136,18 @@ Avatar 组件使用以下 CSS 类:
### AvatarFallback
| Prop | 类型 | 默认值 | 描述 |
| --------- | ------------------------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------- |
| `delayMs` | `number` | - | 显示 fallback 前的延迟(防止闪烁)。`0` 与未指定不同:底座在 `delayMs=0` 时不会显示 fallback,需要延迟时请传正数 |
| `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | - | 覆盖父级颜色(替换而非叠加) |
| `class` | `string` | - | 附加 CSS 类 |
| Prop | 类型 | 默认值 | 描述 |
| --------- | ------------------------------------------------------------- | ------ | ------------------------------------------------------------------------- |
| `delayMs` | `number` | - | 显示 fallback 前的延迟(毫秒);省略或 `0` 时立即显示,正数延迟可动态更新 |
| `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | - | 覆盖父级颜色(替换而非叠加) |
| `class` | `string` | - | 附加 CSS 类 |
三个部件均支持 `as`(根/回退默认 `span`,图片默认 `img`)与 `asChild`(默认 `false`)。`asChild` 需要单个可接收属性的元素或组件;自定义组件应将 attrs 和事件透传到实际 DOM。Image 的默认插槽用于提供自定义图片,Root / Fallback 的默认插槽分别提供部件与回退内容。`referrerPolicy` 接受原生图片策略并透传。
`AvatarRoot` 是 `Avatar` 的同一组件别名。React ref 改用 Vue 模板 ref 的 `$el` 获取根 DOM;不提供框架专属合成事件。图片加载由底座预加载 `src` 来决定显示状态,`srcSet` / `sizes` 传给实际图片,预加载探测不按响应式候选选择图片;加载中的实际 img 保留在 DOM 并以 `display:none` 隐藏,这是与上游 Radix 按加载状态挂载图片的差异。未提供 `src` 时仅有 `srcSet` 不会令图片显示。
Avatar 使用 Reka UI 的 `AvatarRoot` / `AvatarImage` / `AvatarFallback` 处理加载与回退状态。`onLoad` / `onError` 对应 Vue 原生 `@load` / `@error` 事件,不声明与 React 合成事件完全等价。
## 相关组件
[AvatarGroup 头像组](./avatar-group) · [Card 卡片](./card)
[AvatarGroup 头像组](./avatar-group) · [Separator 分隔符](./separator) · [Badge 徽章](./badge)
+1 -1
View File
@@ -186,4 +186,4 @@ Badge 支持组合变体与颜色类(如 `.hv-badge--primary.hv-badge--accent`
## 相关组件
[Chip 标签](./chip) · [Avatar 头像](./avatar)
[Avatar 头像](./avatar) · [Chip 标签](./chip)
+33 -19
View File
@@ -127,19 +127,33 @@ Breadcrumbs 组件使用以下 CSS 类([查看源码样式](https://github.com
### Breadcrumbs
| 属性 | 类型 | 默认值 | 描述 |
| ------------ | --------------------------- | --------------- | ------------------------------------------------ |
| `aria-label` | `string` | `'Breadcrumbs'` | 面包屑列表的可访问名称。 |
| `isDisabled` | `boolean` | `false` | 是否禁用所有面包屑链接。 |
| `as` | `string` | `'ol'` | 自定义根元素标签;对应上游 `render` 的元素替换。 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定)。 |
| 默认插槽 | - | - | `BreadcrumbsItem` 列表。 |
| `#separator` | - | 默认右箭头图标 | 自定义各项之间的分隔符。 |
| 属性 | 类型 | 默认值 | 描述 |
| ------------ | --------------------------- | ------------------------ | ------------------------------------------------ |
| `aria-label` | `string` | 随 ConfigProvider locale | 面包屑列表的可访问名称,显式值优先。 |
| `isDisabled` | `boolean` | `false` | 是否禁用所有面包屑链接。 |
| `as` | `string` | `'ol'` | 自定义根元素标签;对应上游 `render` 的元素替换。 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定)。 |
| 默认插槽 | - | - | `BreadcrumbsItem` 列表。 |
| `#separator` | - | 默认右箭头图标 | 自定义各项之间的分隔符。 |
根元素同时接收其余 `$attrs`(`data-*`、`id`、`style`、事件等);`aria-label` 为空字符串时回退为 `Breadcrumbs`。`isDisabled` 通过既有禁用作用域传给内部 `Link`,不复制禁用逻辑。
根元素同时接收其余 `$attrs`(`data-*`、`id`、`style`、事件等);`aria-label` 未传或为空字符串时按当前 `ConfigProvider` locale 本地化(默认 en-US 的 Breadcrumbs、zh-CN 的“导航栏”)。`isDisabled` 通过既有禁用作用域传给内部 `Link`,不复制禁用逻辑。
### action 事件
`@action="onAction"` 在非当前、未禁用项被点击或通过 Enter 激活后触发一次。事件参数为项的 `id`(若提供),否则为 Vue `key`,均未提供时使用从 0 开始的位置索引。数字 `0`、字符串 `"0"` 与空字符串分别保留,不做真值回退。调用方 `@click.prevent` 或 `stopImmediatePropagation()` 可以取消该 action;事件本身不替代 href 的浏览器导航。
```vue
<Breadcrumbs @action="(key) => console.log(key)">
<BreadcrumbsItem :id="0">首页</BreadcrumbsItem>
<BreadcrumbsItem id="">产品</BreadcrumbsItem>
<BreadcrumbsItem>当前页</BreadcrumbsItem>
</Breadcrumbs>
```
### BreadcrumbsItem
`id?: string | number` 指定 action 身份,同时透传为 li 的 DOM id;请保持 DOM id 唯一。未传时从 Vue key(或位置索引)取得事件身份。
| 属性 | 类型 | 默认值 | 描述 |
| ------------ | --------------------------- | ------- | -------------------------------------------------------------------------------- |
| `href` | `string` | - | 链接 URL;未提供时渲染不可导航的 `span[role="link"]`,当前项与禁用项也不可导航。 |
@@ -151,26 +165,26 @@ Breadcrumbs 组件使用以下 CSS 类([查看源码样式](https://github.com
| `class` | `string \| Array \| Object` | - | 附加 CSS 类;同时合并到 `li` 与内部链接。 |
| 默认插槽 | `{ isCurrent, isDisabled }` | - | 项内容;可用作用域状态渲染条件内容。 |
`li` 根节点接收除事件处理器外的 `$attrs`;`onClick`、`onKeydown`、`onFocus` 等事件绑定到真实链接,从而复用 `Link` 的禁用拦截与事件顺序。`isLast` 和 `separatorSlot` 由 `Breadcrumbs` 自动注入,不列入公开 `BreadcrumbsItemProps` 类型或 API 表,调用方无需设置。
`li` 根节点接收除事件处理器外的 `$attrs`;`onClick`、`onKeydown`、`onFocus` 等事件绑定到真实链接,从而复用 `Link` 的禁用拦截与事件顺序。`isLast`、`separatorSlot` 和 `itemKey` 由 `Breadcrumbs` 自动注入,不列入公开 `BreadcrumbsItemProps` 类型或 API 表,调用方无需设置。
### 上游差异
| 上游 React 能力 | Vue 实现 |
| ----------------------------- | ------------------------------------------ |
| `Breadcrumbs.Item` 对象子部件 | 独立具名导出 `BreadcrumbsItem` |
| `separator: ReactNode` | `#separator` 插槽,默认图标从基线 SVG 移植 |
| `render` 函数 | `as` 更换元素,属性直接透传 |
| `className` / `children` | `class` / 默认插槽 |
| `onAction` | 未提供;使用链接原生行为或 `@click` |
| 上游 React 能力 | Vue 实现 |
| ----------------------------- | --------------------------------------------- |
| `Breadcrumbs.Item` 对象子部件 | 独立具名导出 `BreadcrumbsItem` |
| `separator: ReactNode` | `#separator` 插槽,默认图标从基线 SVG 移植 |
| `render` 函数 | `as` 更换元素,属性直接透传 |
| `className` / `children` | `class` / 默认插槽 |
| `onAction` | `@action(key)`,取消的点击与禁用/当前项不触发 |
## 无障碍
- 根元素是 `ol`,默认带 `aria-label="Breadcrumbs"`。固定基线的 React Aria Components `Breadcrumbs` 实际渲染 `ol` 而不是 `nav`;中文文档中的“导航地标”描述与源码 DOM 不完全一致,本实现以固定提交源码为准。需要独立导航地标时,可由应用在外层使用 `<nav>`。
- 默认名称是英文常量,不随 locale 自动本地化;需要本地化时显式传入 `aria-label`。
- 默认名称随 ConfigProvider locale 动态更新;显式 `aria-label` 优先,未收录的语言回退英文。
- 最后一项自动附加 `aria-current="page"`,并以 `role="link"`、`aria-disabled="true"`、`tabindex="-1"` 的 `span` 呈现,不可 Tab 聚焦或激活。
- 带 `href` 的可导航非当前项使用原生 `a`,支持标准 Tab、Enter 与浏览器链接行为;未提供 `href` 的非当前项、禁用的非当前项与当前项均以 `span[role="link"]` 呈现。禁用/当前项带 `aria-disabled="true"`、`tabindex="-1"`,不保留 `href`,点击被拦截;未禁用的无 `href` 项保留 `tabindex="0"`。RAC 的禁用 span 省略 `tabindex`,Vue Link 保留 `-1` 供程序化聚焦,两者都不能通过 Tab 聚焦。
- 分隔符默认标记为 `aria-hidden="true"` 与 `role="presentation"`,不进入可访问名称。
## 相关组件
[Link 链接](./link) · [Separator 分隔符](./separator)
[Link 链接](./link) · [Separator 分隔符](./separator) · [Tabs 标签页](./tabs)
+1 -3
View File
@@ -153,6 +153,4 @@ ButtonGroup 组件自动为按钮应用圆角:
## 相关组件
- [Button 按钮](./button)
- [ToggleButton 切换按钮](./toggle-button)
- [ToggleButtonGroup 切换按钮组](./toggle-button-group)
[Button 按钮](./button) · [Dropdown 下拉菜单](./dropdown) · [Chip 标签](./chip)
+56 -3
View File
@@ -89,21 +89,68 @@ Vue 使用 `asChild` 将按钮属性与交互合并到一个自定义原生 butt
### 全局 CSS
可使用 `@layer components` 指令自定义 Button 组件类;下面的选择器与语义变量都是当前样式表中真实存在的入口:
```css
@layer components {
/* 覆盖变体语义变量 */
.hv-button--primary {
--button-bg: oklch(0.6 0.2 300);
--button-bg-hover: oklch(0.55 0.2 300);
--button-bg-pressed: oklch(0.55 0.2 300);
--button-fg: white;
}
/* 或直接覆盖类规则 */
.hv-button--icon-only {
@apply rounded-lg;
}
}
```
## 样式参考
基础类为 `.hv-button`,变体为 `.hv-button--primary` 等;尺寸为 `.hv-button--sm` / `md` / `lg`。支持 `.hv-button--icon-only` 和 `.hv-button--full-width`。
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
### CSS 类
Button 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/button.css)):
#### 基础与尺寸类 [!toc]
- `.hv-button` - 基础按钮样式
- `.hv-button--sm` - 小尺寸变体
- `.hv-button--md` - 中尺寸变体(默认)
- `.hv-button--lg` - 大尺寸变体
#### 变体类 [!toc]
- `.hv-button--primary`
- `.hv-button--secondary`
- `.hv-button--tertiary`
- `.hv-button--outline`
- `.hv-button--ghost`
- `.hv-button--danger`
- `.hv-button--danger-soft`
#### 修饰符类 [!toc]
- `.hv-button--icon-only`
- `.hv-button--icon-only.hv-button--sm`
- `.hv-button--icon-only.hv-button--lg`
- `.hv-button--full-width`
### 交互状态
保留 `data-hovered`、`data-pressed`、`data-focused`、`data-focus-visible`、`data-pending` 状态;键盘焦点样式与鼠标焦点区分。加载期间保留焦点并阻止重复点击,通过 aria-disabled 呈现半透明的原变体颜色。
按钮同时支持 CSS 伪类与 data 属性:
- **Hover**:`:hover` 或 `[data-hovered="true"]`
- **Active/Pressed**:`:active` 或 `[data-pressed="true"]`(含缩放变换)
- **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]`(显示焦点环)
- **Disabled**:`:disabled` 或 `[aria-disabled="true"]`(降低透明度,禁用指针事件)
- **Pending**:`[data-pending="true"]`(加载期间禁用指针事件)
加载期间保留焦点并阻止重复点击,通过 `aria-disabled` 呈现半透明的原变体颜色。
## API 参考
@@ -139,4 +186,10 @@ Vue 使用 `@click` 和默认作用域插槽。插槽提供 `isPending`、`isPre
## 相关组件
[Card 卡片](./card) · [Input 输入框](./input) · [Switch 开关](./switch)
[Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip) · [Form 表单](./form)
## 相关案例
以下卡片链接至上游 React 案例(新窗口)。
<DocsRelatedShowcases component="Button" />
+10 -10
View File
@@ -261,12 +261,12 @@ Calendar 保留固定基线的主要属性与部件,以 Vue 模型、具名部
年份选择器支持日期格式与窗口选项。独立部件直接从包根导入,不需要 React 上下文。
| Component | Prop | 类型 | 默认值 | 描述 |
| ---------------------------------- | -------------- | ---------------------------- | ------------------- | -------------------------------------------------------------------------- |
| `CalendarYearPickerTriggerHeading` | `format` | `Intl.DateTimeFormatOptions` | - | 自定义月/年标签(如 `{month: 'short'}`) |
| `CalendarYearPickerTriggerHeading` | `offset` | `{months?: number}` | - | 相对聚焦日期偏移标题(多月布局) |
| `CalendarYearPickerGrid` | `format` | `Intl.DateTimeFormatOptions` | `{year: 'numeric'}` | 自定义年份单元格标签(纪元、历法等) |
| `CalendarYearPickerGrid` | `visibleYears` | `number` | min–max 跨度 | 滑动窗口中显示的年份数。同时设置 `minValue` 与 `maxValue` 时默认为完整范围 |
| Component | Prop | 类型 | 默认值 | 描述 |
| ---------------------------------- | -------------- | ---------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `CalendarYearPickerTriggerHeading` | `format` | `Intl.DateTimeFormatOptions` | - | 自定义月/年标签(如 `{month: 'short'}`) |
| `CalendarYearPickerTriggerHeading` | `offset` | `{months?: number}` | - | 相对聚焦日期偏移标题(多月布局) |
| `CalendarYearPickerGrid` | `format` | `Intl.DateTimeFormatOptions` | `{year: 'numeric'}` | 自定义年份单元格标签(纪元、历法等) |
| `CalendarYearPickerGrid` | `visibleYears` | `number` | min–max 完整范围 | 以焦点年为中心的滑动窗口年份数;缺省显示 min–max 完整范围(未设约束时为 1900–2099)。上游文档写“min–max 跨度或 `20`”,本实现没有 `20` 的回退分支 |
### CalendarCell 作用域插槽
@@ -288,8 +288,8 @@ Calendar 保留固定基线的主要属性与部件,以 Vue 模型、具名部
### Related packages
- [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) — 所有日期组件使用的日期类型(`CalendarDate`、`CalendarDateTime`、`ZonedDateTime`)与工具
- 本库 `ConfigProvider` — 覆盖子树的 locale
- 本库 `ConfigProvider` — 统一 locale 与布局方向
- 本库 `ConfigProvider` — 覆盖子树的 locale 与布局方向
- 本库 `useLocale()` — 读取当前 `ConfigProvider` 的 `locale` / `dir`(未包裹时回退 `en-US` / `ltr`,与组件继承链一致),供 `startOfWeek`、`isWeekend`、`DateFormatter` 等本地化计算使用
## Vue 模型、DOM 与当前差异
@@ -298,12 +298,12 @@ Calendar 保留固定基线的主要属性与部件,以 Vue 模型、具名部
- `locale`、`dir` 优先于 ConfigProvider;`timeZone` 用于“今天”标记。显示历法与公开模型历法分离;默认上下界按公历 1900-01-01 至 2099-12-31 转换到显示历法,与上游部分历法的近似年份偏移算法有差异。
- 根为 `role="group"`,网格为语义 table/grid,CalendarCell 输出 td/gridcell + 原生 button。`class`、ARIA、DOM 事件落在真正可交互按钮;取消 Cell 的键盘或点击事件可阻止默认处理,祖先需使用捕获事件取消。`isDateDisabled` 完全禁用日期;`isDateUnavailable` 保留焦点但阻止选择。
- 左右/上下键移动日期,Home/End 到周边界,PageUp/PageDown 移动月份,Shift+PageUp/PageDown 移动年份;Enter/Space 选择。年份层为三列,方向键与 Home/End 移动,Escape 关闭并恢复触发器。
- Calendar 本身不产生原生命名表单输入,也不消费 Label/FieldError 的字段协议;表单字段与 Picker 后续共享 DateField 基建。RangeCalendar 与 TimeField 已有独立公共组件;DatePicker、DateRangePicker 尚未迁移。
- Calendar 本身不产生原生命名表单输入,也不消费 Label/FieldError 的字段协议;表单字段由 DateField 体系承载,DatePicker、DateRangePicker 复用同一套 DateField 部件。RangeCalendar、TimeField、DatePicker、DateRangePicker 均有独立公共组件。
- `weeksInMonth` 是行数下限,不裁掉真实月份日期。`visibleYears` 是以聚焦年份为中心的窗口;默认显示完整 min/max 年份范围。复杂 era 可通过年份插槽中的 `date` 传给 CalendarYearPickerCell,避免仅凭数字年份混淆。
- 键盘适配层针对安装版 Reka 缺少 week/day view、年份层及原生取消缺口使用本地日期视图算法;不运行 React,也不承诺完整 React Aria 类型或全部读屏行为等价。
## 相关组件
[DateField 日期字段](./date-field) · [Select 选择器](./select) · [Popover 弹出框](./popover)
[RangeCalendar 范围日历](./range-calendar) · [DateField 日期字段](./date-field) · [DatePicker 日期选择器](./date-picker)
Root 默认插槽还提供 `value`、`isDisabled`、`isReadOnly`、`isInvalid`、`focusedValue`、`visibleRange` 与 `isYearPickerOpen`。Cell 插槽还提供 `date`、`isOutsideVisibleRange`、`isToday`、`isHovered`、`isPressed`、`isFocused`、`isFocusVisible`。使用 `defaultFocusedValue`、`locale`、`dir`、`timeZone`、`isDateDisabled` 可显式设置初始视图、国际化和禁用规则。
+15 -2
View File
@@ -94,6 +94,13 @@ Card 提供语义变体,描述 prominence 级别而非具体视觉样式,允
| CardContent | `.hv-card__content` | `card-content` | div |
| CardFooter | `.hv-card__footer` | `card-footer` | div |
#### 变体类 [!toc]
- `.hv-card--transparent` - 透明背景、无边框与无阴影(遮罩层与自定义背景场景)
- `.hv-card--default` - 默认表面(`bg-surface`)
- `.hv-card--secondary` - 次级表面(`bg-surface-secondary`)
- `.hv-card--tertiary` - 三级表面(`bg-surface-tertiary`)
## API 参考
### Card
@@ -106,7 +113,13 @@ Card 提供语义变体,描述 prominence 级别而非具体视觉样式,允
### CardHeader / CardTitle / CardDescription / CardContent / CardFooter
各部件支持 `as`、默认插槽和原生属性。默认标签见上表。Vue 使用独立命名导出替代 `Card.Header` 等 React 部件访问方式。
| 属性 | 类型 | 默认值 | 描述 |
| -------- | --------------------------- | ---------------- | ------------------------------------------ |
| `as` | `string` | 见上表默认元素列 | 渲染的 HTML 元素 |
| `class` | `string \| Array \| Object` | — | 额外的 CSS 类,合并到部件根元素 |
| 默认插槽 | - | - | 部件内容;`$attrs`(ARIA、事件)透传根元素 |
各部件无业务状态或事件;类名与 `data-slot` 见样式参考表。Vue 使用独立命名导出替代 `Card.Header` 等 React 部件访问方式。
## 无障碍
@@ -118,4 +131,4 @@ Card 提供语义变体,描述 prominence 级别而非具体视觉样式,允
## 相关组件
[Button 按钮](./button) · [Input 输入框](./input)
[Surface 表面](./surface) · [Avatar 头像](./avatar) · [Form 表单](./form)
+1 -1
View File
@@ -200,4 +200,4 @@ render 自定义根类型未支持;基线 div+data-custom 示例以 Vue 根属
## 相关组件
[Checkbox](./checkbox) · [CheckboxGroup](./checkbox-group) · [RadioGroup](./radio-group) · [Fieldset](./fieldset)
[Checkbox 复选框](./checkbox) · [Label 标签](./label) · [Fieldset 字段组](./fieldset)
+1 -1
View File
@@ -266,4 +266,4 @@ render 自定义根类型未支持;基线 div+data-custom 示例以 Vue 根属
## 相关组件
[Checkbox](./checkbox) · [CheckboxGroup](./checkbox-group) · [RadioGroup](./radio-group) · [Fieldset](./fieldset)
[Label 标签](./label) · [CheckboxGroup 复选框组](./checkbox-group) · [Description 描述](./description)
+1 -1
View File
@@ -157,4 +157,4 @@ Chip 支持组合变体与颜色类(如 `.hv-chip--secondary.hv-chip--accent`
## 相关组件
[Card 卡片](./card) · [Avatar 头像](./avatar)
[Avatar 头像](./avatar) · [CloseButton 关闭按钮](./close-button) · [Separator 分隔符](./separator)
+1 -1
View File
@@ -106,4 +106,4 @@ CloseButton 是原生 `button`,`type` 固定为 `"button"`。常用属性包
## 相关组件
[Button 按钮](./button) · [Card 卡片](./card)
[Alert 警告](./alert) · [AlertDialog 警告对话框](./alert-dialog) · [Chip 标签](./chip)
+3 -1
View File
@@ -178,4 +178,6 @@ Vue 版写作 `ColorAreaThumb`(对应上游 `ColorArea.Thumb`)。
## 相关组件
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider) 与 [ColorSwatch 颜色色块](/components/color-swatch)。ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未公开。
[ColorSwatch 颜色色块](./color-swatch) · [ColorSwatchPicker 颜色色块选择器](./color-swatch-picker) · [ColorField 颜色输入框](./color-field)
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)、[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker)。颜色家族共用同一颜色 owner,Picker 的 Trigger/Popover 组合可嵌套上述任意子组件。
+49 -5
View File
@@ -266,23 +266,67 @@ color.toString("hex");
color.getChannelValue("red");
```
本页部件和 Props,以及 `ColorFieldRenderProps`、`ColorFieldRenderState`、`ColorFieldSlots`、`ColorFieldExpose`、`colorFieldVariants`、`colorInputGroupVariants`、`ColorFieldVariants`、`ColorInputGroupVariants` 均从包根公开。ColorInputGroup 与 ColorField 的对应部件共享实现。ColorPicker/ColorSwatchPicker 尚未公开。
本页部件和 Props,以及 `ColorFieldRenderProps`、`ColorFieldRenderState`、`ColorFieldSlots`、`ColorFieldExpose`、`colorFieldVariants`、`colorInputGroupVariants`、`ColorFieldVariants`、`ColorInputGroupVariants` 均从包根公开。ColorInputGroup 与 ColorField 的对应部件共享实现。[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker) 均已公开。
## ColorField.Group Styling
使用 `.hv-color-input-group`、`__input`、`__prefix`、`__suffix` 定制各节点;primary/secondary/full-width 修饰符与上游视觉数值一致。根容器为 `.hv-color-field`。Group 负责 hover/focus-within/invalid/disabled 的样式,Input 自身去掉默认边框和焦点轮廓;焦点环展示在 Group。状态必须写在实际匹配 CSS 的节点。
根容器为 `.hv-color-field`,Group 为 `.hv-color-input-group`。Group 负责 hover/focus-within/invalid/disabled 的样式,Input 自身去掉默认边框和焦点轮廓;焦点环展示在 Group。状态必须写在实际匹配 CSS 的节点。primary/secondary/full-width 修饰符与上游视觉数值一致。
### Customizing the component classes
基础类驱动每个实例。使用 `@layer components` 一次性覆盖:
```css
@layer components {
.hv-color-input-group {
border-radius: var(--radius-field);
@apply inline-flex h-9 items-center overflow-hidden rounded-field border bg-field text-sm text-field-foreground shadow-field outline-none;
&:hover,
&[data-hovered="true"] {
@apply bg-field-hover;
}
&[data-focus-within="true"],
&:focus-within {
@apply status-focused-field;
}
&[data-invalid="true"] {
@apply status-invalid-field;
}
&[data-disabled="true"],
&[aria-disabled="true"] {
@apply status-disabled;
}
}
.hv-color-input-group__input {
font-variant-numeric: tabular-nums;
@apply flex min-w-0 flex-1 items-center rounded-none border-0 bg-transparent px-3 py-2 shadow-none outline-none;
}
.hv-color-input-group__prefix,
.hv-color-input-group__suffix {
@apply flex shrink-0 items-center text-field-placeholder;
}
}
```
### ColorField.Group CSS Classes
- `.hv-color-input-group` - 根容器样式
- `.hv-color-input-group__input` - Input 包装器样式(含 `min-w-0` 通道收窄)
- `.hv-color-input-group__prefix` - 前缀元素样式
- `.hv-color-input-group__suffix` - 后缀元素样式
- `.hv-color-input-group--primary` / `--secondary` / `--full-width` - 变体与宽度修饰符
### ColorField.Group Interactive States
- **Hover**:`:hover:not(:focus-within)` 或 `[data-hovered="true"]:not([data-focus-within="true"])`
- **Focus Within**:`[data-focus-within="true"]` 或 `:focus-within`
- **Invalid**:`[data-invalid="true"]`(与 `aria-invalid` 同步)
- **Disabled**:`[data-disabled="true"]` 或 `[aria-disabled="true"]`
## 相关组件
[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)。
[ColorSwatch 颜色色块](./color-swatch) · [ColorSwatchPicker 颜色色块选择器](./color-swatch-picker) · [ColorPicker 颜色选择器](./color-picker)
+271
View File
@@ -0,0 +1,271 @@
---
title: ColorPicker 颜色选择器
description: 可组合的颜色选择器,在多个颜色组件间同步颜色值
component: color-picker
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import {
ColorArea,
ColorAreaThumb,
ColorPicker,
ColorPickerPopover,
ColorPickerTrigger,
ColorSlider,
ColorSliderOutput,
ColorSliderThumb,
ColorSliderTrack,
ColorSwatch,
Label,
} from "@heroui-vue/components";
</script>
<template>
<ColorPicker default-value="#0485F7">
<ColorPickerTrigger>
<ColorSwatch size="lg" />
<Label>选择颜色</Label>
</ColorPickerTrigger>
<ColorPickerPopover>
<ColorArea
aria-label="取色区域"
color-space="hsb"
x-channel="saturation"
y-channel="brightness"
>
<ColorAreaThumb />
</ColorArea>
<ColorSlider channel="hue" color-space="hsb">
<Label>色相</Label>
<ColorSliderOutput />
<ColorSliderTrack>
<ColorSliderThumb />
</ColorSliderTrack>
</ColorSlider>
</ColorPickerPopover>
</ColorPicker>
</template>
```
<ComponentPreview name="color-picker-basic" />
## 组件结构
ColorPicker 是组合多个颜色组件的可组合组件:固定源使用 `ColorPicker.Trigger` 对象组合;Vue 版提供同名具名组件,Root 别名 `ColorPickerRoot` 与 `ColorPicker` 共用实现。省略全部自身值属性的 [ColorArea](/components/color-area)、[ColorSlider](/components/color-slider)、[ColorField](/components/color-field)、[ColorSwatch](/components/color-swatch)、[ColorSwatchPicker](/components/color-swatch-picker) 会共享同一个颜色 owner。
```vue
<script setup lang="ts">
import {
ColorArea,
ColorAreaThumb,
ColorPicker,
ColorPickerPopover,
ColorPickerTrigger,
ColorSlider,
ColorSliderThumb,
ColorSliderTrack,
ColorSwatch,
Label,
} from "@heroui-vue/components";
</script>
<template>
<ColorPicker default-value="#0485F7">
<ColorPickerTrigger>
<ColorSwatch />
<Label>选择颜色</Label>
</ColorPickerTrigger>
<ColorPickerPopover>
<ColorArea
color-space="hsb"
x-channel="saturation"
y-channel="brightness"
>
<ColorAreaThumb />
</ColorArea>
<ColorSlider channel="hue" color-space="hsb">
<ColorSliderTrack>
<ColorSliderThumb />
</ColorSliderTrack>
</ColorSlider>
</ColorPickerPopover>
</ColorPicker>
</template>
```
## 示例
### 受控组件
<ComponentPreview name="color-picker-controlled" />
### 带色板
<ComponentPreview name="color-picker-with-swatches" />
### 带输入字段
使用 `ColorField` 允许用户编辑单个颜色通道值,配合 `Select` 切换颜色空间。
<ComponentPreview name="color-picker-with-fields" />
### 带滑块
使用多个 `ColorSlider` 组件调整颜色值的各通道。
<ComponentPreview name="color-picker-with-sliders" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="color-picker-custom-styles" />
### 全局 CSS
可使用 `@layer components` 指令自定义 ColorPicker 组件类。
[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
```css
@layer components {
.hv-color-picker {
@apply inline-flex;
}
.hv-color-picker__trigger {
@apply inline-flex items-center gap-4 rounded-lg;
}
.hv-color-picker__popover {
@apply p-4 rounded-xl;
}
}
```
## 样式参考
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`,`colorPickerVariants` 只有 `base`/`trigger`/`popover` 三个槽位,与固定源一致(无 size/variant 变体)。
### CSS 类
ColorPicker 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/color-picker.css)):
#### 基础类 [!toc]
- `.hv-color-picker` - 基础容器(inline-flex)
- `.hv-color-picker__trigger` - 触发按钮(间距、圆角、focus/disabled 状态)
- `.hv-color-picker__popover` - 弹出层容器(`min-w-62`、纵向滚动、`overscroll-contain`、`bg-overlay`、圆角与阴影)
弹出层高度适配可用空间(`--reka-popover-content-available-height`),退出动画期间保持 `pointer-events: none`,定位原点使用 `--reka-popper-transform-origin`;`data-side` 与固定源的 `data-placement` 对应,供方向性进入动画选择滑入方向。
### 交互状态
组件同时支持 CSS 伪类与 data 属性:
- **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]`
- **Disabled**:`:disabled` 或 `[data-disabled="true"]`(Trigger);根节点输出 `[data-disabled="true"]`
- **Read-only**:根节点输出 `[data-readonly="true"]`
- **Entering / Exiting**:`[data-entering="true"]` / `[data-exiting="true"]`(缩放淡入淡出,reduced-motion 停用)
## API 参考
### ColorPicker
对应固定源的 [React Aria ColorPicker](https://react-spectrum.adobe.com/react-aria/ColorPicker.html):共享颜色 owner + `DialogTrigger`/`Popover` 组合。普通颜色值使用 `v-model`,输出本库 `Color`。
| Prop | 类型 | 默认值 | 描述 |
| -------------- | ------------------------------------------------------------------ | ----------- | ------------------------------------------------------------------- |
| `modelValue` | `string \| Color` | - | 当前接受颜色(`v-model`;受控) |
| `value` | `string \| Color` | - | 低优先级受控别名;`modelValue` 存在时优先 |
| `defaultValue` | `string \| Color` | `"#000000"` | 非受控初值;未提供时使用固定源默认黑值 |
| `open` | `boolean` | - | 受控展开;拒绝打开时仍发出 `update:open`/`openChange` |
| `isOpen` | `boolean` | - | 展开别名;`open` 与 `isOpen` 同时存在时 `open` 优先,不会双输入竞争 |
| `defaultOpen` | `boolean` | `false` | 非受控初始展开 |
| `isDisabled` | `boolean` | `false` | 禁用整个组合(库扩展,作用于自身子组件) |
| `disabled` | `boolean` | `false` | `isDisabled` 别名 |
| `isReadOnly` | `boolean` | `false` | 只读:保留展示与程序化赋值,阻止子控件编辑(库扩展) |
| `name` | `string` | - | Vue 扩展:单个隐藏输入提交完整精度颜色 |
| `form` | `string` | - | Vue 扩展:关联外部表单 id |
| `as` | `string` | `"div"` | 自定义根元素标签 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
| 默认作用域插槽 | `({ color, isOpen, close, isDisabled, isReadOnly }) => VNodeChild` | - | 根渲染状态 |
事件:
| 事件 | 参数 | 时机 |
| ---------------------------------------------- | --------- | ------------------------------------------------------------------------ |
| `update:modelValue` / `change` | `Color` | 子控件提出不同颜色时一起触发(`v-model` 使用前者);受控父组件可拒绝提案 |
| `changeEnd` | `Color` | 有颜色提案的手势正常结束时传出最后提案;不表示父组件已接受,取消时不触发 |
| `update:open` / `update:isOpen` / `openChange` | `boolean` | 展开状态提案;受控拒绝时保持提案事件,不改变实际展开 |
受控拒绝、相同提案重试、外部替换与事务取消的行为与共享颜色 owner 一致:父组件不接受提案时坐标、滑块、字段文本、预览与表单值保持接受值,提案不会冒充已接受颜色,也不会经 hex 往返量化。
### ColorPickerTrigger
| Prop | 类型 | 默认值 | 描述 |
| -------------- | --------------------------------------- | ---------- | -------------------------------- |
| `as` | `string` | `"button"` | 自定义根元素标签 |
| `asChild` | `boolean` | `false` | 把触发器属性合并到默认插槽根节点 |
| `isDisabled` | `boolean` | `false` | 额外禁用;owner 禁用时同样禁用 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
| 默认作用域插槽 | `({ color, isDisabled }) => VNodeChild` | - | 触发器内容状态 |
触发器渲染为真实 `button[type=button]`,不会意外提交外层表单;固定源的 Button render props(`isHovered`/`isPressed` 等)在 Vue 版收敛为 `color`/`isDisabled` 两个插槽状态,差异已记录。
### ColorPickerPopover
| Prop | 类型 | 默认值 | 描述 |
| --------------------------- | ----------------------------------- | --------------- | ---------------------------- |
| `placement` | `OverlayPlacement` | `"bottom left"` | 弹出层位置(RTL 下自动镜像) |
| `offset` | `number` | `8` | 与锚点的间距 |
| `crossOffset` | `number` | `0` | 交叉轴偏移 |
| `shouldFlip` | `boolean` | `true` | 视口碰撞时翻转 |
| `containerPadding` | `number` | `12` | 碰撞计算的容器留白 |
| `to` | `string \| HTMLElement` | - | 自定义 Teleport 目标 |
| `isNonModal` | `boolean` | `false` | 非模态:不锁定焦点与滚动 |
| `isDismissable` | `boolean` | `true` | 允许外部点击关闭 |
| `isKeyboardDismissDisabled` | `boolean` | `false` | 禁用 Esc 关闭 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
| 默认作用域插槽 | `({ isOpen, close }) => VNodeChild` | - | 弹层内容状态 |
弹层内容通过 Teleport 渲染,Surface 默认上下文穿过 Teleport;嵌套的 `Select`/`ListBox` 等内层弹层各自独立处理 Esc、外部点击与焦点恢复,不会误关外层 ColorPicker。
### Render Props
| 插槽状态 | 类型 | 含义 |
| -------------------------------------------- | --------------------------- | ------------------------------ |
| `color`(根) | `Color` | 当前接受颜色(组合不允许空值) |
| `isOpen` / `isDisabled` / `isReadOnly`(根) | `boolean` | 真实状态 |
| `close`(根 / 弹层) | `() => void` | 关闭弹层 |
| `color` / `isDisabled`(Trigger) | `Color \| null` / `boolean` | 触发器内容状态 |
| `isOpen`(Popover) | `boolean` | 弹层展开状态 |
Root 实例通过 `defineExpose` 提供 `element`(真实根 DOM)与 `color`(接受颜色)。不暴露颜色 owner、事务 token 或弹层内部状态。
### 展开与焦点
| 操作 | 行为 |
| ------------------- | ---------------------------------------------------------------- |
| 触发器 click | 切换弹层;可取消的 `click`(`preventDefault`)会阻止打开 |
| `Esc` | 先恢复/丢弃子控件草稿,再关闭弹层并把焦点还给触发器 |
| 外部点击 | 关闭弹层;未结束的颜色事务立即取消,不补发虚假 `changeEnd` |
| `Tab` / `Shift+Tab` | 焦点在弹层内循环(模态);嵌套 Select 的内层选项可正常聚焦与选择 |
| 焦点恢复 | 关闭后焦点回到触发器;退出动画期间弹层保持不可交互 |
### 表单
`name`/`form` 是本库 Vue 扩展(固定源 ColorPicker 不提供表单提交 API):开启后渲染单个 `input[type=hidden]`,提交完整精度序列化(如 `hsba(270, 0%, 50%, 0.123456789)`)。`form.reset()` 恢复初值并同步真实 DOM;禁用时不参与提交;继承的子控件不重复提交完整颜色。未提供 `name` 时没有成功控件,FormData 保持为空。
### Color 与 parseColor
`Color`、`parseColor`、`ColorValue` 等类型从包根导出,与 [ColorSwatch](/components/color-swatch) 共用同一颜色模型;公开子集的方法表见该页。固定源 `Color` 的感知色名等接口不在公开子集内。取色区域轴名、滑块输出等本地化文案跟随 `ConfigProvider` 的 `locale`(默认 `en-US`),与 [ColorArea](/components/color-area) / [ColorSlider](/components/color-slider) 一致。
## 相关组件
[ColorArea 颜色区域](./color-area) · [ColorSlider 颜色滑块](./color-slider) · [ColorSwatch 颜色色块](./color-swatch)
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)、[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker)。颜色家族共用同一颜色 owner,Picker 的 Trigger/Popover 组合可嵌套上述任意子组件。
+3 -1
View File
@@ -281,4 +281,6 @@ ColorSlider 实现 ARIA slider 模式,提供:
## 相关组件
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider) 与 [ColorSwatch 颜色色块](/components/color-swatch)。ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未公开。
[ColorSwatch 颜色色块](./color-swatch) · [ColorSwatchPicker 颜色色块选择器](./color-swatch-picker) · [ColorPicker 颜色选择器](./color-picker)
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)、[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker)。颜色家族共用同一颜色 owner,Picker 的 Trigger/Popover 组合可嵌套上述任意子组件。
+270
View File
@@ -0,0 +1,270 @@
---
title: ColorSwatchPicker 颜色色块选择器
description: 允许用户从预置调色板中选择颜色的 swatch 列表
component: color-swatch-picker
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import {
ColorSwatchPicker,
ColorSwatchPickerIndicator,
ColorSwatchPickerItem,
ColorSwatchPickerSwatch,
} from "@heroui-vue/components";
</script>
<template>
<ColorSwatchPicker>
<ColorSwatchPickerItem color="#F43F5E">
<ColorSwatchPickerSwatch />
<ColorSwatchPickerIndicator />
</ColorSwatchPickerItem>
</ColorSwatchPicker>
</template>
```
<ComponentPreview name="color-swatch-picker-basic" />
## 组件结构
固定源使用 `ColorSwatchPicker.Item` 对象组合;Vue 版提供同名具名组件,Root 别名 `ColorSwatchPickerRoot` 与 `ColorSwatchPicker` 共用实现。
```vue
<script setup lang="ts">
import {
ColorSwatchPicker,
ColorSwatchPickerIndicator,
ColorSwatchPickerItem,
ColorSwatchPickerSwatch,
} from "@heroui-vue/components";
</script>
<template>
<ColorSwatchPicker>
<ColorSwatchPickerItem color="#F43F5E">
<ColorSwatchPickerSwatch />
<ColorSwatchPickerIndicator />
</ColorSwatchPickerItem>
<ColorSwatchPickerItem color="#D946EF">
<ColorSwatchPickerSwatch />
<ColorSwatchPickerIndicator />
</ColorSwatchPickerItem>
<ColorSwatchPickerItem color="#8B5CF6">
<ColorSwatchPickerSwatch />
<ColorSwatchPickerIndicator />
</ColorSwatchPickerItem>
</ColorSwatchPicker>
</template>
```
## 示例
### 变体
<ComponentPreview name="color-swatch-picker-variants" />
### 尺寸
<ComponentPreview name="color-swatch-picker-sizes" />
### 禁用
<ComponentPreview name="color-swatch-picker-disabled" />
### 堆叠布局
<ComponentPreview name="color-swatch-picker-stack-layout" />
### 默认值
<ComponentPreview name="color-swatch-picker-default-value" />
### 受控组件
<ComponentPreview name="color-swatch-picker-controlled" />
### 自定义指示器
<ComponentPreview name="color-swatch-picker-custom-indicator" />
### 渲染函数
上游 `render` 用于替换根元素或附加属性;Vue 版通过 `as` 更换元素类型,`data-*`、`aria-*` 与事件直接透传,并使用作用域插槽透出真实状态(根与项两级)。
<ComponentPreview name="color-swatch-picker-render-function" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="color-swatch-picker-custom-styles" />
### 全局 CSS
可使用 `@layer components` 指令自定义 ColorSwatchPicker 组件类。
[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
```css
@layer components {
.hv-color-swatch-picker {
@apply gap-4;
}
.hv-color-swatch-picker__item {
@apply shadow-md;
}
.hv-color-swatch-picker__swatch {
@apply border-2 border-white;
}
}
```
## 样式参考
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
### CSS 类
ColorSwatchPicker 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/color-swatch-picker.css)):
#### 基础与结构 [!toc]
- `.hv-color-swatch-picker` - 基础容器(flex 布局)
- `.hv-color-swatch-picker__item` - 单个 swatch 包裹层
- `.hv-color-swatch-picker__swatch` - swatch 视觉元素
- `.hv-color-swatch-picker__indicator` - 选中指示器
#### 尺寸类 [!toc]
- `.hv-color-swatch-picker--xs` - 特小(16px)
- `.hv-color-swatch-picker--sm` - 小(24px)
- `.hv-color-swatch-picker--md` - 中(32px,默认)
- `.hv-color-swatch-picker--lg` - 大(36px)
- `.hv-color-swatch-picker--xl` - 特大(40px)
#### 形状变体 [!toc]
- `.hv-color-swatch-picker--circle` - 圆形(默认)
- `.hv-color-swatch-picker--square` - 圆角方形
#### 布局类 [!toc]
- `.hv-color-swatch-picker--grid` - 横向换行网格(默认)
- `.hv-color-swatch-picker--stack` - 纵向堆叠
### 交互状态
组件同时支持 CSS 伪类与 data 属性:
- **Hover**:`:hover` 或 `[data-hovered="true"]` - 缩放至 1.1(选中状态以选中缩放为准)
- **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]` - 焦点环
- **Selected**:`[data-selected="true"]` - 与 swatch 同色的内边框,swatch 缩至 0.77 显出间隔
- **Disabled**:`[data-disabled="true"]` - 降低透明度并禁用交互
透明颜色保留 ColorSwatch 的棋盘格底纹;`--color-swatch-current` 写在每个项与色块节点上,供选中边框与棋盘底色使用。
## API 参考
### ColorSwatchPicker
对应固定源的 [React Aria ColorSwatchPicker](https://react-spectrum.adobe.com/react-aria/ColorSwatchPicker.html)(`listbox` / `option` 语义,单项选择且不允许清空)。
| Prop | 类型 | 默认值 | 描述 |
| -------------- | ------------------------------------------------------------------------------- | ----------- | -------------------------------------------------------------- |
| `modelValue` | `string \| Color \| null` | - | 当前接受颜色(`v-model`;受控) |
| `value` | `string \| Color \| null` | - | 低优先级受控别名,与共享颜色模型一致 |
| `defaultValue` | `string \| Color \| null` | `"#000000"` | 非受控初值;未提供时使用固定源默认黑值,不会自动选中第一个候选 |
| `layout` | `"grid" \| "stack"` | `"grid"` | 布局方向(视觉 flex 布局,ARIA 方向固定为 vertical) |
| `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | swatch 尺寸 |
| `variant` | `"circle" \| "square"` | `"circle"` | swatch 形状 |
| `isDisabled` | `boolean` | `false` | 禁用整个选择器(库扩展) |
| `disabled` | `boolean` | `false` | `isDisabled` 别名 |
| `isReadOnly` | `boolean` | `false` | 只读:保留选择与焦点,阻止新的选择(库扩展) |
| `dir` | `"ltr" \| "rtl"` | - | 方向;影响水平方向键映射 |
| `as` | `string` | `"div"` | 自定义根元素标签;对应上游 `render` 的元素替换 |
| `aria-label` | `string` | - | 列表名称;省略且没有 `aria-labelledby` 时使用本地化默认名称 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
| 默认作用域插槽 | `({ color, isEmpty, isDisabled, isReadOnly, isFocused, layout }) => VNodeChild` | - | 根渲染状态 |
`change` 事件与 `update:modelValue` 一起在选择被接受时触发,参数为本库 `Color`,保留候选色自身的颜色空间与精度。选择比较使用固定源的 hexa 键(8 位 RGB + alpha):等价格式(hex/rgb/hsl)视为同一颜色,alpha 按 1/255 量化比较,灰色的色相在比较中折叠;接受值本身不会被反写或量化。
省略全部自身值属性时继承最近的颜色 owner(例如 [ColorField](/components/color-field) 家族共享的私有 ColorPicker 组合);显式 `value`/`modelValue` 覆盖继承,动态增删属性可切换归属。显式 `null` 表示受控空值(不选中任何项);固定源把 `null` 视为非受控,此项差异已记录。
### ColorSwatchPicker.Item
| Prop | 类型 | 默认值 | 描述 |
| -------------- | ------------------------- | ------- | ---------------------------------------------------------- |
| `color` | `string \| Color \| null` | - | 候选颜色;省略或空字符串渲染透明色块(对应固定源 `#0000`) |
| `isDisabled` | `boolean` | `false` | 禁用该项(不可聚焦、不可选择、方向键跳过) |
| `as` | `string` | `"div"` | 自定义根元素标签 |
| `aria-label` | `string` | - | 覆盖自动生成的项名称 |
| 默认作用域插槽 | `(state) => VNodeChild` | - | 项状态,见下方 Render Props |
### ColorSwatchPicker.Swatch
| Prop | 类型 | 默认值 | 描述 |
| ----------- | ------------------------- | ------- | -------------------------------------- |
| `color` | `string \| Color \| null` | - | 覆盖颜色;省略时使用所属项的颜色 |
| `colorName` | `string` | - | 颜色的可访问名称(覆盖自动生成的描述) |
| `as` | `string` | `"div"` | 自定义根元素标签 |
### ColorSwatchPicker.Indicator
| Prop | 类型 | 默认值 | 描述 |
| -------------- | ----------------------- | -------- | ---------------------------- |
| `as` | `string` | `"span"` | 自定义根元素标签 |
| 默认作用域插槽 | `(state) => VNodeChild` | - | 替换默认勾选图标,接收项状态 |
默认图标是固定源的勾选 SVG;`[data-light-color="true"]` 由色块相对亮度(> 0.5)决定,浅色背景使用黑色勾选。指示器始终渲染在 DOM 中,由 CSS 在选中时缩放显示。
### Render Props
| 插槽状态 | 类型 | 含义 |
| ---------------------------------------------------------------------------------------- | ------------------- | -------------- |
| `color`(项) | `Color` | 该项的候选颜色 |
| `isSelected` / `isDisabled` / `isFocused` / `isFocusVisible` / `isPressed` / `isHovered` | `boolean` | 项的真实状态 |
| `color`(根) | `Color \| null` | 当前接受颜色 |
| `isEmpty` / `isDisabled` / `isReadOnly` / `isFocused` | `boolean` | 根的真实状态 |
| `layout`(根) | `"grid" \| "stack"` | 当前布局 |
Root 实例通过 `defineExpose` 提供 `element`(真实根 DOM)与 `focus()`(按入口规则聚焦项);Item 提供 `element`。不暴露颜色 owner、事务 token 或内部集合键。
### 选择与焦点
| 操作 | 行为 |
| --------------------- | ----------------------------------------------------------------------------------------------------------------- |
| 鼠标主键按下 | 选择该项;仅主键(`button === 0`)激活,右键/中键保留原生行为;可取消的 `mousedown`(`preventDefault`)会阻止选择 |
| `Enter` / `Space` | 选择当前聚焦项(按下即选中) |
| `Tab` / `Shift+Tab` | 整个列表是一个 tab 停靠点;进入时聚焦已选项或首/末可用项 |
| `↑` / `↓` | 只移动焦点不选择;grid 按几何在换行行间移动,stack 按顺序移动 |
| `←` / `→` | grid 按顺序移动(RTL 反向);stack 交给浏览器滚动 |
| `Home` / `End` | 聚焦首/末可用项 |
| `PageUp` / `PageDown` | 容器不可滚动时跳到首/末项,可滚动时按页移动 |
| `click`(`detail=0`) | 辅助技术/程序化的 click-only 激活选择当前项;正常鼠标/键盘的兼容 click 不重复提案 |
| 输入字符 | 按项名称前缀匹配并聚焦(名称差异见下) |
| 边界 | 不循环;到边界后保持当前项 |
焦点与选择分离:方向键只移动焦点,`aria-selected` 与指示器只反映接受颜色。父级拒绝提案后,选择样式、`aria-selected` 与 DOM 保持接受状态,同一手势可重试。窗口失焦或指针取消会清除按压状态与点击去重归属,恢复后可以立即重试。
### 可访问名称差异
固定源使用 React Aria 的感知色名(`getColorName`)作为项与色块的自动名称。本库未实现感知色名表:自动名称使用 `hex`/`hexa` 或“透明”文案,并接受显式 `aria-label` / `colorName` 覆盖。列表本身在省略 `aria-label` 时使用本地化默认名称“颜色色块选择器”。
### 表单
固定源 ColorSwatchPicker 不提供 `name`/`form` 提交、表单重置或 required/validate 字段 API,本库同样不新增这些字段 API(明确差异)。需要表单提交时请与共享颜色 owner 组合:由 owner 的隐藏值提交完整精度颜色,选择器不重复提交或接管重置,组合中的 reset 会恢复真实 DOM 状态。
### Color 与 parseColor
`Color`、`parseColor`、`ColorValue` 等类型从包根导出,与 [ColorSwatch](/components/color-swatch) 共用同一颜色模型;详见该页的公共接口表。
## 相关组件
[ColorSwatch 颜色色块](./color-swatch) · [ColorField 颜色输入框](./color-field) · [ColorArea 颜色区域](./color-area)
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)、[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker)。颜色家族共用同一颜色 owner,Picker 的 Trigger/Popover 组合可嵌套上述任意子组件。
+3 -1
View File
@@ -152,4 +152,6 @@ ColorSwatch 组件使用以下 CSS 类([查看源码样式](https://github.com
## 相关组件
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider) 与 [ColorSwatch 颜色色块](/components/color-swatch)。ColorPicker 与 ColorSwatchPicker 仍为私有颜色协议,尚未公开。
[ColorSwatchPicker 颜色色块选择器](./color-swatch-picker) · [ColorField 颜色输入框](./color-field) · [ColorArea 颜色区域](./color-area)
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)、[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker)。颜色家族共用同一颜色 owner,Picker 的 Trigger/Popover 组合可嵌套上述任意子组件。
+5 -3
View File
@@ -133,6 +133,8 @@ import {
<ComponentPreview name="combo-box-asynchronous-loading" />
示例的本地数据源模拟固定源的 SWAPI 请求状态机(搜索过滤、游标分页、加载中、滚动到底自动增量加载、取消旧请求与过期响应保护、失败重试);与 SWAPI 的差异是数据为固定 12 条本地角色、延迟为模拟值,失败由「模拟加载失败」开关注入。加载行位于 ListBox 之外(固定源为 `ListBoxLoadMoreItem` 行内哨兵),自动触发语义一致。
### 默认选中项
<ComponentPreview name="combo-box-default-selected-key" />
@@ -314,7 +316,7 @@ ComboBox 组件使用以下 CSS 类([查看源码样式](https://github.com/he
| `placeholder` | `string` | `'Select an item'` | `ComboBoxValue` 的缺省占位文本(上游根上没有该 prop,由 `ComboBoxValue` 的 placeholder 表达) |
| `as` | `string` | `'div'` | 自定义根元素标签 |
| `as-child` | `boolean` | `false` | 使用唯一子元素作为根节点并合并属性 |
| 默认插槽 | `{ isOpen, inputValue, selectedKey, selectedKeys }` | - | 组件内容;作用域提供当前状态 |
| 默认插槽 | `{ isOpen, inputValue, selectedKey, selectedKeys, selectedItem }` | - | 组件内容;作用域提供当前状态 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
事件:
@@ -334,7 +336,7 @@ ComboBox 组件使用以下 CSS 类([查看源码样式](https://github.com/he
### 作用域插槽与渲染状态
默认插槽提供 `{ isOpen, inputValue, selectedKey, selectedKeys }`。上游的 `Render Props` 表格里还有 `state` 与 `selectedItem`:本库不暴露 React Aria 的 state 对象,选中项数据可从 `records`/`selectedKeys` 派生(示例见 `@update:model-value` 与 `ComboBoxValue` 的作用域插槽),该差异不另设等价 prop。
默认插槽提供 `{ isOpen, inputValue, selectedKey, selectedKeys, selectedItem }`。上游的 `Render Props` 表格里还有 `state` 与 `selectedItem`:`selectedItem` 以作用域数据补齐(根 `items` 中与单选 key 匹配的源数据项;多选或自定义值时为 `null`,`ComboBoxValue` 的 `selectedItems` 条目也携带同源 `item`),调用方可直接用自己的数据对象组合展示,无需按键反查;本库不暴露 React Aria 的 state 对象,该差异不另设等价 prop。
### ComboBoxInputGroup
@@ -350,7 +352,7 @@ ComboBox 组件使用以下 CSS 类([查看源码样式](https://github.com/he
| Prop | 类型 | 默认值 | 描述 |
| ------------- | ---------------------------------- | -------------------- | ----------------------------- |
| `placeholder` | `string`(上游为 `ReactNode`) | 根上的 `placeholder` | 未选中任何项时的占位文本 |
| 默认插槽 | `{ isPlaceholder, selectedItems }` | - | 自定义已选值展示 |
| 默认插槽 | `{ isPlaceholder, selectedItems }` | - | 自定义已选值展示;`selectedItems` 条目为 `{ key, textValue, item? }`(`item` 为根 `items` 中的源数据项) |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
### ComboBoxTrigger
+7 -7
View File
@@ -213,12 +213,12 @@ DateField 使用 Vue 日期值、作用域插槽和共享字段协议。与固
#### Format Props
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------- | ------- | ----------------------------------------------------------- |
| `granularity` | `Granularity` | - | 显示的最小单位。日期默认为 `"day"`,时间默认为 `"minute"`。 |
| `hourCycle` | `12 \| 24` | - | 以 12 或 24 小时制显示时间;默认由语言环境决定。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区缩写。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------- | ------- | --------------------------------------------------------------------------- |
| `granularity` | `Granularity` | - | 显示的最小单位;未传时随值推断:纯日期默认 `"day"`,含时间默认 `"minute"`。 |
| `hourCycle` | `12 \| 24` | - | 以 12 或 24 小时制显示时间;默认由语言环境决定。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区缩写。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
#### State Props
@@ -464,7 +464,7 @@ DateFieldSuffix 接受标准 HTML `div` 属性:
## 相关组件
[TextField 文本输入框](./text-field) · [NumberField 数字输入框](./number-field) · [Select 选择器](./select)
[DatePicker 日期选择器](./date-picker) · [Calendar 日历](./calendar) · [Label 标签](./label)
## Vue 兼容说明
+12 -12
View File
@@ -187,7 +187,7 @@ DatePicker 支持与真实 Vue/Reka 状态同步的 data 属性与伪状态:
- **Open**:触发器上 `[data-open="true"]`
- **Disabled**:触发器上 `[data-disabled="true"]` 或 `[aria-disabled="true"]`
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`。聚焦时按真实 DOM 的 `:focus-visible` 判定,鼠标与键盘路径区分;关闭弹层恢复焦点时同样遵循浏览器判定
- **Hover**:触发器上 `:hover`
- **Invalid**:根容器上 `[data-invalid="true"]` 或 `[aria-invalid="true"]`
- **Read only**:根容器上 `[data-readonly="true"]`
@@ -230,16 +230,16 @@ DatePicker 继承固定基线的日期字段与弹层能力,通过 Vue `v-mode
#### Format Props
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------------------------------------------------------- | ------------------------- | ----------------------------------------------- |
| `granularity` | `'day' \| 'hour' \| 'minute' \| 'second'` | `'day'` | 显示的日期/时间粒度;只改变显示,不截断接受值。 |
| `hourCycle` | `12 \| 24` | 由 locale 决定 | 以 12 或 24 小时制显示时间。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区名称。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
| `locale` | `string` | ConfigProvider 或 `en-US` | 显示历法与格式。 |
| `dir` | `'ltr' \| 'rtl'` | ConfigProvider 或 `ltr` | 排列与方向键方向。 |
| `firstDayOfWeek` | `'sun' \| 'mon' \| 'tue' \| 'wed' \| 'thu' \| 'fri' \| 'sat'` | 由 locale 决定 | 覆盖内嵌 Calendar 的一周起始日。 |
| `pageBehavior` | `'visible' \| 'single'` | `'visible'` | 内嵌 Calendar 翻页按可见范围或单步前进。 |
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------------------------------------------------------- | --------------------------------------- | ----------------------------------------------- |
| `granularity` | `'day' \| 'hour' \| 'minute' \| 'second'` | 随值推断:纯日期 `day`、含时间 `minute` | 显示的日期/时间粒度;只改变显示,不截断接受值。 |
| `hourCycle` | `12 \| 24` | 由 locale 决定 | 以 12 或 24 小时制显示时间。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区名称。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
| `locale` | `string` | ConfigProvider 或 `en-US` | 显示历法与格式。 |
| `dir` | `'ltr' \| 'rtl'` | ConfigProvider 或 `ltr` | 排列与方向键方向。 |
| `firstDayOfWeek` | `'sun' \| 'mon' \| 'tue' \| 'wed' \| 'thu' \| 'fri' \| 'sat'` | 由 locale 决定 | 覆盖内嵌 Calendar 的一周起始日。 |
| `pageBehavior` | `'visible' \| 'single'` | `'visible'` | 内嵌 Calendar 翻页按可见范围或单步前进。 |
#### State & Form Props
@@ -313,7 +313,7 @@ DatePicker 继承固定基线的日期字段与弹层能力,通过 Vue `v-mode
## 相关组件
[Calendar 日历](./calendar) · [DateField 日期字段](./date-field) · [TimeField 时间字段](./time-field)
[Calendar 日历](./calendar) · [RangeCalendar 范围日历](./range-calendar) · [DateField 日期字段](./date-field)
## Vue 公共契约与差异
+13 -12
View File
@@ -199,7 +199,7 @@ DateRangePicker 支持与真实 Vue/Reka 状态同步的 data 属性与伪状态
- **Open**:触发器上 `[data-open="true"]`
- **Disabled**:触发器上 `[data-disabled="true"]` 或 `[aria-disabled="true"]`
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`。聚焦时按真实 DOM 的 `:focus-visible` 判定,鼠标与键盘路径区分;关闭弹层恢复焦点时同样遵循浏览器判定
- **Hover**:触发器上 `:hover`
- **Invalid**:根容器上 `[data-invalid="true"]` 或 `[aria-invalid="true"]`
- **Read only**:根容器上 `[data-readonly="true"]`
@@ -244,16 +244,16 @@ DateRangePicker 继承固定基线的双端点日期字段、范围日历与弹
#### Format Props
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------------------------------------------------------- | ------------------------- | ----------------------------------------------- |
| `granularity` | `'day' \| 'hour' \| 'minute' \| 'second'` | 由接受值推断 | 显示的日期/时间粒度;只改变显示,不截断接受值。 |
| `hourCycle` | `12 \| 24` | 由 locale 决定 | 以 12 或 24 小时制显示时间。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区名称。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
| `locale` | `string` | ConfigProvider 或 `en-US` | 显示历法与格式。 |
| `dir` | `'ltr' \| 'rtl'` | ConfigProvider 或 `ltr` | 排列与方向键方向。 |
| `firstDayOfWeek` | `'sun' \| 'mon' \| 'tue' \| 'wed' \| 'thu' \| 'fri' \| 'sat'` | 由 locale 决定 | 覆盖内嵌 RangeCalendar 的一周起始日。 |
| `pageBehavior` | `'visible' \| 'single'` | `'visible'` | 内嵌 RangeCalendar 翻页按可见范围或单步前进。 |
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------------------------------------------------------- | --------------------------------------- | ----------------------------------------------- |
| `granularity` | `'day' \| 'hour' \| 'minute' \| 'second'` | 随值推断:纯日期 `day`、含时间 `minute` | 显示的日期/时间粒度;只改变显示,不截断接受值。 |
| `hourCycle` | `12 \| 24` | 由 locale 决定 | 以 12 或 24 小时制显示时间。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区名称。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
| `locale` | `string` | ConfigProvider 或 `en-US` | 显示历法与格式。 |
| `dir` | `'ltr' \| 'rtl'` | ConfigProvider 或 `ltr` | 排列与方向键方向。 |
| `firstDayOfWeek` | `'sun' \| 'mon' \| 'tue' \| 'wed' \| 'thu' \| 'fri' \| 'sat'` | 由 locale 决定 | 覆盖内嵌 RangeCalendar 的一周起始日。 |
| `pageBehavior` | `'visible' \| 'single'` | `'visible'` | 内嵌 RangeCalendar 翻页按可见范围或单步前进。 |
#### State & Form Props
@@ -348,10 +348,11 @@ DateRangePicker 继承固定基线的双端点日期字段、范围日历与弹
- [`@internationalized/date`](https://react-aria.adobe.com/internationalized/date/) — 所有日期组件使用的日期类型(`CalendarDate`、`CalendarDateTime`、`ZonedDateTime`)与工具
- 本库 `ConfigProvider` — 为子树覆盖 locale、书写方向与 Portal 目标
- 本库 `useLocale()` — 读取当前 `ConfigProvider` 的 `locale` / `dir`(未包裹时回退 `en-US` / `ltr`),供 `DateFormatter`、`startOfWeek`、`isWeekend` 等本地化计算使用
## 相关组件
[DateField 日期字段](./date-field) · [RangeCalendar 范围日历](./range-calendar) · [DatePicker 日期选择器](./date-picker) · [TimeField 时间字段](./time-field)
[RangeCalendar 范围日历](./range-calendar) · [Calendar 日历](./calendar) · [DateField 日期字段](./date-field)
## Vue 公共契约与差异
+3 -1
View File
@@ -83,6 +83,8 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
Description 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/description.css)):
> 变体映射 `descriptionVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `DescriptionVariants` 类型);组件渲染的类名由该映射生成。
#### 基础类 [!toc]
- `.hv-description` - 基础描述样式,使用 `muted` 文本颜色
@@ -109,4 +111,4 @@ Description 组件通过以下方式增强无障碍性:
## 相关组件
[TextField 文本输入框](./text-field) · [Label 标签](./label) · [FieldError 字段错误](./field-error)
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [TextArea 多行文本框](./textarea)
+9 -4
View File
@@ -33,7 +33,7 @@ import {
</template>
```
<ComponentPreview name="disclosure-group-basic" />
<ComponentPreview name="disclosure-group-basic" minHeight="580px" />
## 组件结构
@@ -57,7 +57,7 @@ import { Disclosure, DisclosureGroup } from "@heroui-vue/components";
可使用 `expandedKeys` 与 `update:expandedKeys` 配合 `useDisclosureGroupNavigation` 外部导航。
<ComponentPreview name="disclosure-group-controlled" />
<ComponentPreview name="disclosure-group-controlled" minHeight="580px" />
`useDisclosureGroupNavigation` 为公开 composable:提供 `currentIndex`、`isPrevDisabled`、`isNextDisabled`、`onPrevious`、`onNext`。单选替换集合,多选增量添加;不修改传入集合。
@@ -111,5 +111,10 @@ import { Disclosure, DisclosureGroup } from "@heroui-vue/components";
## 相关组件
- [Disclosure 折叠面板](./disclosure)
- [Accordion 手风琴](./accordion)
[Accordion 手风琴](./accordion) · [Disclosure 折叠面板](./disclosure) · [Button 按钮](./button)
## 相关案例
以下卡片链接至上游 React 案例(新窗口)。
<DocsRelatedShowcases component="DisclosureGroup" />
+8 -3
View File
@@ -33,7 +33,7 @@ import {
</template>
```
<ComponentPreview name="disclosure-basic" />
<ComponentPreview name="disclosure-basic" minHeight="440px" />
## 组件结构
@@ -170,5 +170,10 @@ Body 提供基线内边距与内层包装。Indicator 默认为基线 Chevron
## 相关组件
- [DisclosureGroup 折叠面板组](./disclosure-group)
- [Accordion 手风琴](./accordion)
[Accordion 手风琴](./accordion) · [DisclosureGroup 折叠面板组](./disclosure-group) · [Button 按钮](./button)
## 相关案例
以下卡片链接至上游 React 案例(新窗口)。
<DocsRelatedShowcases component="Disclosure" />
+1 -2
View File
@@ -264,5 +264,4 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论。类名前缀 `hv-`。
## 相关组件
- [Modal 模态框](./modal)
- [AlertDialog 警告对话框](./alert-dialog)
[Modal 模态框](./modal) · [Button 按钮](./button) · [CloseButton 关闭按钮](./close-button)
+4 -5
View File
@@ -370,6 +370,7 @@ Dropdown 使用 Menu、MenuItem 与 MenuSection 作为底层组件。以下类
| Slots / Props | 说明 |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 默认插槽 | 第一个子节点是触发条目,其余子节点渲染进子菜单内容 |
| `delay` | 悬停展开延迟(毫秒),默认 `200`(与固定源 `useSubmenuTrigger` 一致);键盘展开立即生效并取消挂起的悬停展开,指针离开取消 |
| `class`/ARIA | 合并到触发条目元素上 |
| 面板参数 | 嵌套 `DropdownPopover` 的 `offset`/`crossOffset`/`shouldFlip`/`containerPadding`/`loop`/`to`、`class`/`style`/`id`/`data-*`/ARIA 与事件都会传给子菜单面板;`isKeyboardDismissDisabled` 为真时 Esc 既不关子层也不关父层,`shouldCloseOnInteractOutside` 返回 `false` 时外部交互不关闭 |
@@ -408,14 +409,12 @@ Dropdown 组件实现 ARIA 菜单模式,并提供:
- 部件导出为具名组件(`DropdownRoot` / `DropdownTrigger` / …),触发器需要显式包裹,官方是把 `Button` 直接放在 `Dropdown` 下。
- `Selection`/`Set` 改为 `MenuKey[]`;`onAction`/`onSelectionChange`/`onClose` 改为 Vue 事件;`isOpen`/`onOpenChange` 改为 `open` + `v-model:open`。
- 官方 `items` + 渲染函数的数据驱动集合用 `v-for` 表达;`renderEmptyState` 对应 `empty` 插槽。不提供 React Collection 对象模型。
- 子菜单悬停展开延迟由底层固定为 100ms,未暴露官方 `delay`(默认 200ms);子菜单面板的 `side`/`align` 由底层固定,只有偏移与碰撞参数可调。
- 子菜单悬停展开延迟由 `DropdownSubmenuTrigger` 的 `delay` 配置(默认 200ms,与固定源 `useSubmenuTrigger` 一致):底层 Reka 的固定 100ms 悬停计时被重定为该延迟,键盘展开立即生效并取消挂起的悬停展开,指针离开取消;子菜单面板的 `side`/`align` 由底层固定(贴父项向右、RTL 反向),只有偏移与碰撞参数可调。
- `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()` 会终止后续处理器,均为原生事件语义。
## 相关组件
- [Button 按钮](./button)
- [Popover 弹出层](./popover)
- [Separator 分隔线](./separator)
[Button 按钮](./button) · [Popover 弹出框](./popover) · [Separator 分隔符](./separator)
+7 -9
View File
@@ -35,14 +35,10 @@ import { EmptyState } from "@heroui-vue/components";
默认插槽为空、仅包含注释或空白文本时,回退到源码默认文案 `No results found`。只要存在有效内容(文本、数字或元素),就渲染调用方内容,不额外包裹结构。
> 兼容说明:固定源的 React 实现用真值判断(`children || "No results found"`),数字 `0` 会回退默认文案、纯空白字符串原样渲染;本库把 `0` 视为有效内容照常渲染、纯空白回退默认文案。这是有意的 Vue 适配边界,两处与上游不同。
## 示例
### 默认回退
不提供内容时展示源码默认文案。
<ComponentPreview name="empty-state-default" />
### 自定义文案
<ComponentPreview name="empty-state-custom-content" />
@@ -53,14 +49,16 @@ import { EmptyState } from "@heroui-vue/components";
<ComponentPreview name="empty-state-conditional" />
### 自定义样式
### 集合为空
`class` 与 `$attrs` 合并到根元素,可叠加边框、背景、间距与对齐工具类。
把 `EmptyState` 放进集合组件的空槽(如 ListBox 的 `#empty`),作为搜索无结果或数据为空时的占位。过滤输入改变集合内容即可看到回退效果。
<ComponentPreview name="empty-state-custom-styles" />
<ComponentPreview name="empty-state-collection" />
## 自定义样式
`class` 与 `$attrs` 合并到根元素,可叠加边框、背景、间距与对齐工具类。
### Tailwind CSS
<ComponentPreview name="empty-state-custom-styles" />
+1 -1
View File
@@ -121,4 +121,4 @@ ErrorMessage 组件使用以下 CSS 类([查看源码样式](https://github.co
## 相关组件
[FieldError 字段错误](./field-error) · [Description 描述](./description) · [TagGroup 标签组](./tag-group)
[TagGroup 标签组](./tag-group)
+7 -1
View File
@@ -178,6 +178,8 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
FieldError 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/field-error.css)):
> 变体映射 `fieldErrorVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `FieldErrorVariants` 类型);组件渲染的类名由该映射生成。
#### 基础类 [!toc]
- `.hv-field-error` - 基础错误样式,danger 色
@@ -209,4 +211,8 @@ FieldError 组件通过以下方式确保无障碍性:
## 相关组件
[TextField 文本输入框](./text-field) · [Label 标签](./label) · [Description 描述](./description)
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [TextArea 多行文本框](./textarea)
### validationDetails
作用域插槽还提供 `validationDetails?: ValidityState`。TextField/SearchField 使用真实控件的原生快照,OTP 可显式传入详情(优先)或读取其提交代理快照;其他尚未接入详情的字段为 undefined。可读取 `valueMissing`、`patternMismatch`、`typeMismatch`、`customError` 等原生标志,而不复制字段状态。详情本身不替代 `isInvalid` 或错误文本。
+2 -2
View File
@@ -123,8 +123,8 @@ Fieldset 复合组件暴露以下 CSS 选择器:
三个部件使用对应 BEM 基础类,class 接受字符串、数组和对象。命名导出替代 React 对象式子部件;原生属性直接传递,不使用 nativeProps 对象。根元素固定为语义化原生元素,暂不提供 React render 根元素替换。
Fieldset 不维护字段值或校验队列。请使用 Form + TextField / SearchField,提交与 reset 沿用原生表单;示例展示实际 FormData 与成功反馈,不执行后台保存。
Fieldset 不维护字段值或校验队列。请使用 Form + TextField / SearchField,提交与 reset 沿用原生表单;示例以 `alert` 给出成功反馈,不执行后台保存。
## 相关组件
[TextField](./text-field) · [SearchField](./search-field) · [Input](./input)
[TextField 文本输入框](./text-field) · [Label 标签](./label) · [CheckboxGroup 复选框组](./checkbox-group)
+185
View File
@@ -0,0 +1,185 @@
---
title: Form 表单
description: 用于表单校验与提交处理的包裹组件
component: form
stylesSource: false
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import { Form } from "@heroui-vue/components";
</script>
```
<ComponentPreview name="form-basic" />
## 组件结构
```vue
<script setup lang="ts">
import { Form, Button } from "@heroui-vue/components";
</script>
<template>
<Form>
<!-- 表单字段 -->
<Button type="submit">提交</Button>
<Button type="reset">重置</Button>
</Form>
</template>
```
## 示例
### 渲染函数
上游 `render={(props) => <form {...props} data-custom="foo" />}` 在 Vue 中直接通过 `data-custom="foo"` 透传到同一个原生 `<form>`;无需为添加属性替换根元素。Form 始终保留表单语义,不提供 React `render` prop 或替换为非表单元素的 API。
<ComponentPreview name="form-render-function" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="form-custom-styles" />
### 全局 CSS
要自定义表单布局与间距,可在 `<Form>` 上使用 `class`,或通过 `@layer components` 添加项目级类。
`Form` 渲染原生 `<form>` 元素,聚焦校验与提交。本库样式包中无专用 BEM 类;从全局 CSS 应用容器样式,控件级自定义请使用字段组件。
```css
@layer components {
.form-layout {
@apply flex flex-col gap-4 rounded-xl border border-border bg-surface p-4 shadow-sm;
}
}
```
```vue
<Form class="form-layout" @submit.prevent="handleSubmit">
<!-- TextField、Input、Button 等 -->
</Form>
```
分组字段与共享布局请使用 [Fieldset](./fieldset),并定位 `.hv-fieldset`、`.hv-fieldset__legend` 等相关类。单个控件请参阅 [TextField](./text-field)、[Input](./input)、[Label](./label)、[FieldError](./field-error) 的全局 CSS 部分。
## 样式参考
本库对提供样式的组件遵循 BEM 方法论。
`Form` 渲染原生 `<form>` 元素,无专用 BEM 类或 variants。通过 `class` 应用布局、间距与表面样式。字段外观与校验状态来自 `TextField`、`Input`、`Label`、`Description`、`FieldError` 等子组件。结构化多字段布局请与 Fieldset 组合使用。
## API 参考
### Form / FormRoot
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 |
公开类型包含 `FormProps`、`FormRootProps`、`FormSlots`、`FormExpose`。实例能力是 Vue 扩展:
| 实例成员 | 类型 | 说明 |
| ------------------ | ------------------------------ | -------------------------------------------------------------------------------------- |
| `element` | `HTMLFormElement \| undefined` | 挂载后实际 form |
| `checkValidity()` | `() => boolean` | 按 native/aria 策略检查并产生 invalid;不自动聚焦 |
| `reportValidity()` | `() => boolean` | 检查并聚焦首个无效字段,除非调用方取消;错误由 FieldError 展示,不重复调用原生气泡校验 |
| `reset()` | `() => void` | 调用原生 form.reset(),遵守取消与既有受控值协议 |
### Form Validation
Form 支持:
- 内置 HTML5 校验属性(`required`、`minLength`、`pattern` 等)。
- TextField 的同步 `validate(value)` 校验函数。
- FieldError 展示字段错误。
- 校验通过后处理提交。
- `validationErrors` 提供服务端校验结果。
#### Validation Behavior
`validationBehavior` 控制校验展示方式:
- **`native`**(默认):有错误时阻止提交,提交尝试后显示错误并聚焦首个无效字段。
- **`aria`**:实时显示错误语义,允许提交,由调用方处理。
可在表单级或单个字段级设置。Form 在实际 DOM 上使用 `novalidate` 接管验证,再按每个控件的 `data-validation-behavior` 或表单默认值检查,因此允许混合两种策略。调用方显式 `novalidate`、提交按钮的 `formnovalidate` 可跳过提交检查。即使监听 `@submit.capture`,无效提交也先由 Form 拦截。
`validationErrors` 使用新的响应对象更新。编辑一个字段只忽略当前响应里该字段的错误,不修改传入对象。同步 `validate` 不接受 Promise;异步请求和竞态由调用方管理。原生外部 `form` 关联的控件也在验证集合中;字段的服务端错误上下文仍按 Vue 组件祖先继承,DOM form 关联不会跨组件树注入上下文。
### Form Submission
表单支持传统 `action` 提交、JavaScript 事件处理及 FormData API:
```vue
<script setup lang="ts">
function handleSubmit(event: SubmitEvent) {
const formData = new FormData(event.currentTarget as HTMLFormElement);
const data = Object.fromEntries(formData);
console.log("Form data:", data);
}
</script>
<template>
<Form @submit.prevent="handleSubmit">
<!-- 表单字段 -->
</Form>
</template>
```
默认插槽不维护第二份表单值。禁用控件不进入 FormData,只读控件保留。reset 恢复非受控初始值,受控值仍由父级决定;取消 reset 会保留当前值。`element.submit()` 遵循浏览器行为并绕过校验与 submit 事件,常规提交应使用按钮或 `element.requestSubmit()`。
### Integration with Form Fields
Form 与共享字段组件协作:
- **TextField**:带标签与校验的文本输入。
- **Checkbox / CheckboxGroup**:布尔选择及多选集合。
- **RadioGroup**:多选一。
- **Switch**:开关控件。
- **Button**:提交与重置。
值、错误关联与重置使用各字段现有协议;复杂日期、颜色、数值和集合字段的具体差异仍以各自组件页为准。
### Advanced Usage
可组合第三方校验库,将结果映射到 `validationErrors`;无需为使用 Input 强制引入其他库。自定义错误焦点使用 `@invalid` 并调用 `event.preventDefault()`。共享上下文和集成验证示例见[字段与表单基础](/fields)。不提供 React Form Context、React 函数 action 或完整 React Aria ValidationResult。
## 无障碍
- 原生 `<form>` 语义。
- 使用 `aria-label` 或 `aria-labelledby` 提供 form landmark 名称。
- 无效提交默认聚焦首个无效字段;组合字段聚焦其可操作部件。
- 错误通过 FieldError 与真实控件的 ARIA 描述关联。
- `validationBehavior="aria"` 保留错误语义但不阻止提交。
三个预览沿用固定源的字段、文案、校验、布局与提交反馈:有效提交以 `alert` 展示表单数据,`reset` 重置字段与校验错误。React 专属机制按上述 Vue 方式适配。当前仅支持浏览器客户端;未将完整读屏矩阵或逐像素比较视为已完成。
## 相关案例
[字段与表单基础](/fields)提供服务端错误注入、原生 FormData 和重置的额外组合示例。
## 相关组件
[Button 按钮](./button) · [Fieldset 字段组](./fieldset) · [TextField 文本输入框](./text-field)
+14 -8
View File
@@ -25,7 +25,7 @@ import { Header } from "@heroui-vue/components";
`Header` 是集合/分组标题部件,不是带 Logo、导航和用户菜单的应用顶栏。固定基线的 React Aria Components `Header` 渲染原生 `<header>` 元素(不是任意 heading 级别),常出现在 Dropdown、ListBox、ComboBox、Autocomplete 的分组中。
Vue 版导出 `Header` 与 `HeaderRoot`(同一实现)。菜单 / ListBox 尚未迁移时,可用语义容器解释组合边界,例如在分组列表或表单分区前放置标题:
Vue 版导出 `Header` 与 `HeaderRoot`(同一实现)。在真实集合分组中,`Header` 自动充当分组标签:位于 `DropdownSection` / `MenuSection` 内时自动生成 id 并注册为分组的 `aria-labelledby` 目标(显式传入 `id` 时沿用并注册该 id,卸载时注销);位于 `ListBoxSection` 内时由分组扫描子节点取 `Header` 的 id 关联 `aria-labelledby`。脱离集合使用时它就是普通标题元素,也可用语义容器解释组合边界,例如在分组列表或表单分区前放置标题:
<ComponentPreview name="header-semantic" />
@@ -46,6 +46,12 @@ import { Header } from "@heroui-vue/components";
## 示例
### 集合分组
在 `DropdownSection`(菜单分组)与 `ListBoxSection`(列表分组)中,`Header` 自动成为分组标签:菜单分组经注册表把 `Header` 的 id 关联到 `aria-labelledby`,列表分组扫描子节点取 `Header` 的 id 关联。查看示例 DOM 可见分组元素的 `aria-labelledby` 指向对应 `Header`。
<ComponentPreview name="header-collection-grouping" />
### 自定义 class
<ComponentPreview name="header-custom-class" />
@@ -82,16 +88,16 @@ import { Header } from "@heroui-vue/components";
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
| 默认插槽 | - | - | 标题内容 |
根元素同时接收其余 `$attrs`(`aria-*`、`data-*`、`id`、`style`、事件等)。本组件没有业务值,不提供 `v-model`、表单提交或焦点状态。
根元素同时接收其余 `$attrs`(`aria-*`、`data-*`、`id`、`style`、事件等)。本组件没有业务值,不提供 `v-model`、表单提交或焦点状态。`id` 在 `MenuSection` / `DropdownSection` 内未显式传入时自动生成,并注册为该分组的 `aria-labelledby` 标签;其他场景不主动输出 id。
### 上游差异
| 上游 React 能力 | Vue 实现 |
| --------------------------- | ------------------------------------------ |
| `Header.Root` 对象子部件 | 独立具名导出 `Header` / `HeaderRoot` |
| RAC Collection 叶子节点 | 语义 HTML 封装;集合上下文由未来菜单族提供 |
| `className` / `children` | `class` / 默认插槽 |
| `render` / `DOMRenderProps` | `as` 更换元素,属性直接透传 |
| 上游 React 能力 | Vue 实现 |
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------- |
| 具名导出 `Header`(无 `.Root` 对象子部件) | 具名导出 `Header` / `HeaderRoot`(同一实现) |
| RAC Collection 叶子节点(分组标题注册) | `MenuSection` 内自动注册 id 为分组标签;`ListBoxSection` 扫描子节点取 `Header` id 关联 `aria-labelledby` |
| `className` / `children` | `class` / 默认插槽 |
| `render` / `DOMRenderProps` | `as` 更换元素,属性直接透传 |
## 无障碍
+80 -3
View File
@@ -167,10 +167,87 @@ InputGroup 会自动反映父级 TextField 的无效状态。
多行输入请使用 **InputGroupTextArea**,并搭配前缀与后缀。当存在 textarea 时,容器高度会自动适应内容,并将前缀/后缀与顶部对齐。
上游示例中的 Tooltip 由原生 `title` 与 `aria-label` 适配(Tooltip 组件尚未迁移)。
<ComponentPreview name="input-group-with-textarea" />
### 用法示例
图标前缀加确认按钮后缀的完整组合:
```vue
<script setup lang="ts">
import { IconCheck, IconMail } from "@tabler/icons-vue";
import {
Button,
InputGroup,
InputGroupInput,
InputGroupPrefix,
InputGroupSuffix,
Label,
TextField,
} from "@heroui-vue/components";
</script>
<template>
<TextField>
<Label>邮箱</Label>
<InputGroup>
<InputGroupPrefix>
<IconMail class="size-4 text-muted" />
</InputGroupPrefix>
<InputGroupInput placeholder="name@email.com" />
<InputGroupSuffix>
<Button is-icon-only aria-label="确认" size="sm" variant="ghost">
<IconCheck class="size-4" />
</Button>
</InputGroupSuffix>
</InputGroup>
</TextField>
</template>
```
### 文本域用法示例
带字符计数与 500 字上限校验的反馈文本域:
```vue
<script setup lang="ts">
import { ref } from "vue";
import { IconMail } from "@tabler/icons-vue";
import {
Description,
FieldError,
InputGroup,
InputGroupPrefix,
InputGroupTextArea,
Label,
TextField,
} from "@heroui-vue/components";
const feedback = ref("");
</script>
<template>
<TextField full-width name="feedback" :is-invalid="feedback.length > 500">
<Label>你的反馈</Label>
<InputGroup full-width>
<InputGroupPrefix>
<IconMail class="size-4 text-muted" />
</InputGroupPrefix>
<InputGroupTextArea
v-model="feedback"
class="resize-none"
placeholder="分享你的想法、建议或问题……"
:rows="5"
/>
</InputGroup>
<Description class="flex w-full items-center justify-between px-1">
<span>最多 500 个字符。</span>
<span class="ms-auto">{{ feedback.length }}/500</span>
</Description>
<FieldError>反馈不能超过 500 个字符</FieldError>
</TextField>
</template>
```
## 自定义样式
### Tailwind CSS
@@ -296,4 +373,4 @@ InputGroup 会根据状态自动管理以下 data 属性:
## 相关组件
[Input 输入框](./input) · [Surface 表面](./surface) · [Button 按钮](./button)
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [Label 标签](./label)
+108 -38
View File
@@ -51,7 +51,12 @@ import {
## 示例
### 尺寸变体
### 变体
InputOTP 组件支持两种视觉变体:
- **`primary`**(默认)- 标准样式带阴影,适用于大多数场景
- **`secondary`** - 低强调变体无阴影,适用于 Surface 组件内
<ComponentPreview name="input-otp-variants" />
@@ -77,7 +82,7 @@ import {
<ComponentPreview name="input-otp-on-complete" />
`@complete` 在**首次填满**时触发一次;替换已满值、重复同值或父级同步同一值不会重复触发。示例使用模拟验证(定时器),不发送真实验证码。
`@complete` 在已接受值**从未满变为满值**时触发一次;替换已满值、重复同值或父级同步同一值不会重复触发。示例使用模拟验证(定时器),不发送真实验证码。
### 表单示例
@@ -89,7 +94,7 @@ import {
<ComponentPreview name="input-otp-with-pattern" />
`pattern` 过滤单字符输入,可使用导出的正则常量。
`pattern` 检查整个候选字符串,可使用导出的正则常量;不匹配时拒绝整次编辑。
### 表单验证
@@ -103,47 +108,98 @@ import {
`inputClassName` 落在真实 `<input>` 上;视觉槽位用 `class` 落在 `InputOTPSlot` 根节点。二者不会合并到同一节点。
### 全局 CSS
可使用 `@layer components` 指令自定义 InputOTP 组件类;下面的类与状态选择器都来自当前样式表:
```css
@layer components {
.hv-input-otp {
@apply gap-3;
}
.hv-input-otp__slot {
@apply rounded-lg border-accent;
@apply size-12 rounded-xl border-2 font-bold;
}
.hv-input-otp__slot[data-active="true"] {
@apply border-accent ring-2 ring-accent/30;
}
.hv-input-otp__separator {
@apply h-1 w-2 rounded-full bg-separator;
}
}
```
## 样式参考
类名前缀为 `hv-`。
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
- `.hv-input-otp` / `.hv-input-otp--primary` / `.hv-input-otp--secondary`
- `.hv-input-otp__group` / `.hv-input-otp__slot` / `.hv-input-otp__slot-value`
- `.hv-input-otp__caret` / `.hv-input-otp__separator` / `.hv-input-otp__input`
### CSS 类
状态:`data-active`、`data-filled`、`data-disabled`、`data-invalid`、`data-complete`。
InputOTP 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/input-otp.css)):
#### 基础类 [!toc]
- `.hv-input-otp` - 基础容器
- `.hv-input-otp__group` - slot 组
- `.hv-input-otp__slot` - 单个输入 slot
- `.hv-input-otp__slot-value` - slot 内的字符
- `.hv-input-otp__caret` - 闪烁光标指示器
- `.hv-input-otp__separator` - 组之间的视觉分隔符
- `.hv-input-otp__input` - 真实 `<input>` 的透明覆盖层(Reka PinInput 多 input 底座的适配类,替代上游 `input-otp` 库的 `__container`)
#### 变体类 [!toc]
- `.hv-input-otp--primary` - 标准变体(默认)
- `.hv-input-otp--secondary` - 低强调变体
#### 状态类 [!toc]
- `.hv-input-otp__slot[data-active="true"]` - 当前激活的 slot
- `.hv-input-otp__slot[data-filled="true"]` - 含字符的 slot
- `.hv-input-otp__slot[data-disabled="true"]` - 禁用的 slot
- `.hv-input-otp__slot[data-invalid="true"]` - 无效的 slot
- `.hv-input-otp[data-disabled="true"]` / `[data-invalid="true"]` - 根容器的禁用与错误标记
### 交互状态
组件同时支持 CSS 伪类与 data 属性:
- **Hover**:slot 上 `:hover` 或 `[data-hovered="true"]`
- **Active**:slot 上 `[data-active="true"]`(当前聚焦)
- **Filled**:slot 上 `[data-filled="true"]`(含字符)
- **Disabled**:根与 slot 上 `[data-disabled="true"]`
- **Invalid**:根与 slot 上 `[data-invalid="true"]`(slot 另输出 `[data-readonly]`)
## API 参考
### InputOTP / InputOTPRoot
| Prop | 类型 | 默认值 | 描述 |
| ------------------ | -------------------------- | ----------- | ---------------------------------------------------------------- |
| `modelValue` | `string` | - | 受控字符串值;下标对应槽位 |
| `defaultValue` | `string` | `''` | 非受控初始值 |
| `maxLength` | `number` | 必填 | 槽位数量 / 最大长度 |
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 外观变体 |
| `isDisabled` | `boolean` | `false` | 禁用 |
| `isInvalid` | `boolean` | `false` | 无效展示状态 |
| `validationErrors` | `string[]` | `[]` | 校验错误消息 |
| `inputClassName` | `string` | - | 附加到真实 input 的类 |
| `name` | `string` | - | 表单字段名(隐藏 input 提交一份完整值) |
| `required` | `boolean` | `false` | 原生必填 |
| `pattern` | `string \| RegExp` | - | 字符过滤正则 |
| `mask` | `boolean` | `false` | 密码样式(Reka `mask`) |
| `otp` | `boolean` | `false` | 一次性验证码自动填充(`autocomplete="one-time-code"`) |
| `placeholder` | `string` | `''` | 空位占位符 |
| `id` | `string` | 自动 | 提交桥 id;真实输入派生为 id-slot-index,内部 Label 自动关联首格 |
| Prop | 类型 | 默认值 | 描述 |
| ------------------- | ------------------------------- | ------------ | ---------------------------------------------------------------- |
| `modelValue` | `string` | - | 受控字符串值;下标对应槽位 |
| `defaultValue` | `string` | `''` | 非受控初始值 |
| `maxLength` | `number` | 必填 | 槽位数量 / 最大长度 |
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 外观变体 |
| `isDisabled` | `boolean` | `false` | 禁用 |
| `isInvalid` | `boolean` | `false` | 无效展示状态 |
| `validationErrors` | `string[]` | `[]` | 校验错误消息 |
| `autoFocus` | `boolean` | `false` | 挂载后聚焦真实 input |
| `pasteTransformer` | `(text: string) => string` | - | 粘贴转换先于正则检查 |
| `textAlign` | `'left' \| 'center' \| 'right'` | `'left'` | 真实 input 对齐 |
| `validationDetails` | `ValidityState` | 原生代理快照 | 显式校验标志优先,供 FieldError 读取 |
| `inputClassName` | `string` | - | 附加到真实 input 的类 |
| `name` | `string` | - | 表单字段名(隐藏 input 提交一份完整值) |
| `required` | `boolean` | `false` | 原生必填 |
| `pattern` | `string \| RegExp` | - | 整个候选字符串的正则判定 |
| `mask` | `boolean` | `false` | 密码样式(Reka `mask`) |
| `otp` | `boolean` | `false` | 一次性验证码自动填充(`autocomplete="one-time-code"`) |
| `placeholder` | `string` | `''` | 空位占位符 |
| `id` | `string` | 自动 | 提交桥 id;真实输入派生为 id-slot-index,内部 Label 自动关联首格 |
事件:`update:modelValue` / `change`(字符串)、`complete`(首次填满)。
事件:`update:modelValue` / `change`(字符串)、`complete`(已接受值从未满变满)。
### InputOTPGroup / InputOTPSeparator
@@ -161,14 +217,17 @@ import {
### 上游差异
| 上游 React 能力 | Vue 实现 |
| ----------------------------- | ------------------------------------------ |
| `input-otp` 单隐藏 input | Reka PinInput 多 input + 隐藏提交 input |
| `value` / `onChange` 字符串 | `v-model` / `update:modelValue` / `change` |
| `onComplete` 跨过长度阈值 | `complete` 仅在首次填满触发 |
| `pattern` 整串校验 | 单字符过滤(同样接受导出常量) |
| `render` / `OTPInputContext` | 具名插槽部件;槽位状态经上下文 |
| `pushPasswordManagerStrategy` | 未提供;`otp` 覆盖 one-time-code 自动填充 |
| 上游 React 能力 | Vue 实现 |
| ------------------------------------ | ------------------------------------------------------------------------- |
| `input-otp` 单隐藏 input | Reka PinInput 多 input + 隐藏提交 input |
| `value` / `onChange` 字符串 | `v-model` / `update:modelValue` / `change` |
| `onComplete` 跨过长度阈值 | `complete` 在已接受值从未满变满时触发;满值替换不重复触发 |
| `pattern` 整串校验 | 整个候选字符串按 pattern 检查,拒绝整次不匹配编辑 |
| `render` / `OTPInputContext` | 具名插槽部件;槽位状态经上下文 |
| `pushPasswordManagerStrategy` | 未提供;`otp` 覆盖 one-time-code 自动填充 |
| `validationDetails`(ValidityState) | 作为 prop 传入并通过共享 FieldError 插槽暴露;缺省读取原生校验代理 |
| `textAlign` / `pasteTransformer` | 均已提供;转换后的整值再做 pattern 检查 |
| `autoFocus` / `containerClassName` | 提供 autoFocus;containerClassName 被上游公共类型显式 Omit,不新增该 prop |
## 字段与表单
@@ -187,6 +246,17 @@ Slot 的 keydown/paste 用户处理器在底座编辑前的 capture 边界协调
## 相关组件
- [TextField 文本输入框](./text-field)
- [Label 标签](./label)
- [FieldError 字段错误](./field-error)
[Input 输入框](./input) · [Form 表单](./form) · [Surface 表面](./surface)
## 粘贴、对齐与完成事件
- `autoFocus?: boolean`:挂载后聚焦真实槽输入;保留 PinInput 的焦点导航。
- `pasteTransformer?: (pastedText: string) => string`:先转换剪贴板文本,再限制到 maxLength 并检查整个候选字符串。例如 `text => text.replaceAll('-', '')` 可接收带分隔符的验证码。不匹配的编辑整次拒绝,不从非法文本中悄悄筛出部分字符;空字符串始终可清空。
- `textAlign?: 'left' | 'center' | 'right'`(默认 left):用于各真实透明 input 的文字/选区对齐,视觉 slot 仍按移植 CSS 居中。多 input 结构不伪装为单 input。
- `validationDetails?: ValidityState`:传入全部原生 validity 标志,由 FieldError 的作用域插槽读取;显式值优先于校验代理快照。它本身不改变 isInvalid;错误文本和无效状态沿用已有字段协议。
`complete` 只跟随已接受值从长度不足变为 maxLength 的变化:父级拒绝满值提案不会触发;满值替换或重复相同值不触发;清空/删除后重新填满会再次触发。父级主动设置的已接受值也遵循同一阈值规则。禁用/只读不运行粘贴转换或编辑。
保留 PinInput 编辑约定:一份完整代码的粘贴从首格替换,短粘贴从当前格替换;完成后焦点位于末格或下一待填格,当前格字符可选择。单 input 的任意跨格文本选区与密码管理器徽标避让不承诺等价;`pushPasswordManagerStrategy` 未提供。`containerClassName` 在固定上游公共类型中已 Omit,不新增。
`validationErrors` 显式数组由调用方管理;Form 下同名服务端错误在有效编辑提案或 reset 时忽略当前响应,新响应会重新显示。原生 required/错误通过现有提交代理和共享 FieldError 关联;受控 reset 保留父值、非受控恢复 defaultValue,取消 reset 不改变值。
+3 -3
View File
@@ -16,7 +16,7 @@ import { Input } from "@heroui-vue/components";
<ComponentPreview name="input-basic" />
::: info 字段组合
校验、标签与错误消息由 TextField 体系负责。TextField 尚未迁移,当前请使用原生 label、aria-describedby 和 aria-invalid 关联。
校验、标签与错误消息请参阅 [TextField 文本字段](/components/text-field)。
:::
## 示例
@@ -91,8 +91,8 @@ Input 接受标准 HTML input 属性,以及以下 props:
`update:modelValue` 传递字符串;`@input` / `@change` 保留原生事件。`focus()` 可通过模板引用调用。原生表单 reset 还原非受控初始值;受控值由父组件管理。
不把 React 的 `value` + `onChange` 直接复制为 Vue 状态 API。`className` 改为 `class`。TextField 上下文的自动继承尚未实现。
不把 React 的 `value` + `onChange` 直接复制为 Vue 状态 API。`className` 改为 `class`。Input 作为 TextField 的控件自动接入其字段上下文(id、name、aria-describedby、禁用/只读/必填等状态继承)。
## 相关组件
[Button 按钮](./button) · [Card 卡片](./card)
[TextField 文本输入框](./text-field) · [TextArea 多行文本框](./textarea) · [Label 标签](./label)
-4
View File
@@ -136,7 +136,3 @@ Kbd 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-
| | | `end` | |
上游文档表格曾写作 `Kbd.Key` 与 `title`/`children`;实际实现与全部演示使用 `KbdAbbr` 的 `keyValue` 与 `KbdContent`。本库按实现迁移,并同时导出 `kbdKeysMap`、`kbdKeysLabelMap` 与 `KbdKey` 类型。
## 相关组件
[Button 按钮](./button) · [Link 链接](./link)
+4 -2
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>
```
@@ -88,6 +88,8 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
Label 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/label.css)):
> 变体映射 `labelVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `LabelVariants` 类型);组件渲染的类名由该映射生成,状态修饰类随 `isDisabled` / `isInvalid` / `isRequired` 输出。
#### 基础类 [!toc]
- `.hv-label` — 基础标签文本样式
@@ -127,4 +129,4 @@ Label 基于原生 HTML `<label>`,并遵循 WAI-ARIA 最佳实践:
## 相关组件
[TextField 文本输入框](./text-field) · [Description 描述](./description) · [FieldError 字段错误](./field-error)
[Input 输入框](./input) · [TextArea 多行文本框](./textarea) · [Fieldset 字段组](./fieldset)
+3 -3
View File
@@ -132,14 +132,14 @@ Link 使用以下 CSS 类:
| `target` | `string` | — | 在何处打开链接文档;省略时使用浏览器同窗口默认行为,不输出 target 属性 |
| `rel` | `string` | - | 当前文档与链接文档的关系 |
| `download` | `boolean \| string` | - | 触发下载而非导航;`true` 渲染 `download`,`false`/未传省略属性 |
| `isDisabled` | `boolean` | `false` | 禁用指针与键盘交互;保留可聚焦与 `aria-disabled` |
| `isDisabled` | `boolean` | `false` | 禁用激活,移除导航/下载属性;保留 `aria-disabled` 与程序化聚焦 |
| `asChild` | `boolean` | `false` | 合并到默认插槽唯一元素,并补充 `role="link"` 与 `tabindex="0"` |
| `autoFocus` | `boolean` | - | 挂载后聚焦真实 DOM 根元素(含 asChild) |
| `class` | `string` | - | 与默认样式合并的自定义类 |
默认插槽渲染链接内部内容。作用域插槽提供 `isDisabled`、`isHovered`、`isPressed`、`isFocused`、`isFocusVisible`。`@click` 等 DOM 事件通过 attrs 透传;`isDisabled` 时阻止激活(含 Vue 合并后的监听器数组)。React Aria 的 `onPress` / `PressEvent` 由原生 `click` 适配,不等价。
`asChild` 适用于 `<a>`、`RouterLink` 等已具备导航能力的元素,以及需要自定义外观的 `span`/`div`:非原生可激活元素会获得 `role="link"`、`tabindex="0"`,Enter 触发一次激活(与点击同一 `click` 路径)。自定义元素上的 `href` 不会由浏览器直接导航,请用 `a` / 路由组件作为 asChild 目标,或在 `@click` 中自行处理跳转。禁用时仍可聚焦以便读出 `aria-disabled`,但不会激活。
`asChild` 适用于 `<a>`、`RouterLink` 等已具备导航能力的元素,以及需要自定义外观的 `span`/`div`:非原生可激活元素会获得 `role="link"`、`tabindex="0"`,Enter 触发一次激活(与点击同一 `click` 路径)。自定义元素上的 `href` 不会由浏览器直接导航,请用 `a` / 路由组件作为 asChild 目标,或在 `@click` 中自行处理跳转。禁用时移除根元素的 `href`、`target`、`download`,包括 asChild 子元素自带的对应属性;`tabindex="-1"` 排除 Tab 顺序,仍可通过暴露的 `focus()` 程序化聚焦。重新启用后恢复属性,保留用户处理器和子元素 ref。自定义路由组件应把合并后的属性透传到真实根元素,不应自行覆盖禁用态的导航属性。
### LinkIcon
@@ -203,4 +203,4 @@ import { RouterLink } from "vue-router";
## 相关组件
[Button 按钮](./button) · [Card 卡片](./card)
[Breadcrumbs 面包屑](./breadcrumbs)
+40 -5
View File
@@ -77,10 +77,27 @@ import {
ListBox 通过 `virtualized` 仅渲染视口附近的行,高效展示大数据集。下面保留基线的 1000 条数据、50px 固定行高和 400px 视口。完整数据传给 `items`,首字母导航、全选和范围选择使用完整集合。
Vue 使用现有 VueUse 虚拟列表适配,不导出 React 的 `Virtualizer` / `ListLayout`。当前支持竖向固定行高列表;可变行高、虚拟分组标题和拖放布局尚未支持。
Vue 使用与 Table 共用的虚拟行几何与 ResizeObserver 测量适配,不导出 React 的 `Virtualizer` / `ListLayout`;布局参数在 ListBox 上直接提供(见下文 ListLayout 映射)。支持竖向固定与可变行高、数据驱动的虚拟分组标题(`items` 项的 `heading` 字段)、`#loader` 加载行以及 `gap` / `padding` 行流布局。拖放布局(放置指示线)在 Vue 侧没有对应实现,`dropIndicatorThickness` 不提供(见 ListLayout 映射记录)。滚动容器自动探测:列表自身可滚时绑定自身,否则绑定最近的滚动祖先(例如弹层整体滚动并配 sticky 搜索框的 Autocomplete)。
<ComponentPreview name="list-box-virtualization" />
#### ListLayout 映射
不导出 React Aria 的 `ListLayout` 实例;等价布局参数直接在 ListBox 上提供,单位均为 px。固定源布局默认 rowHeight 48、headingHeight 48、loaderHeight 48、gap 0、padding 0;Vue ListBox 沿用数据模式 rowHeight 默认 50,其余对应默认保持。上游三个虚拟化示例的显式值(Table 42、ListBox/Autocomplete 50)是示例传值而非布局默认值,示例保持原值不机械统一。
| ListLayout 参数 | Vue 对应 | 更新语义 |
| --- | --- | --- |
| `rowHeight` | `rowHeight`(number 或 `(index) => number \| undefined`) | 每次布局重读;响应式高度变化无需重挂载。 |
| `estimatedRowHeight` | `estimatedRowHeight` | 函数行高返回 `undefined` 时先估算(数据模式默认 50),挂载后按自然内容测量并修正。 |
| `headingHeight` | `headingHeight`(number 或函数) | 按条目索引指定标题高度;返回 `undefined` 开启自然测量。非虚拟分组仍用 `ListBoxSection`。 |
| `estimatedHeadingHeight` | `estimatedHeadingHeight` | `headingHeight` 函数返回 `undefined` 时使用的初始估算(默认 48);随后测量真实标题。 |
| `loaderHeight` | `loaderHeight` + `#loader` 插槽 | `#loader` 存在时渲染为行流末尾的内容行。 |
| `dropIndicatorThickness` | 不提供 | Vue 侧 ListBox/Table 没有拖放实现,无放置指示线可度量;不补空参数冒充能力。 |
| `gap` | `gap` | 内容行之间的间距,计入较早一行的行占位;padding 行不计。 |
| `padding` | `padding` | 行流两端的占位行,不计 gap。 |
虚拟分组标题是数据驱动的(`items` 项的 `heading` 字段);动态过滤与异步追加后,条目按逻辑 `id` 保持身份、选择与键盘导航,`aria-posinset` / `aria-setsize` 始终相对完整可见集合计算,窗口外未挂载的行不丢失身份。
### 自定义勾选图标
<ComponentPreview name="list-box-custom-check-icon" />
@@ -163,10 +180,16 @@ Vue 使用 `as` 修改原生标签,普通和作用域插槽组合内容;状
| `loop` | `boolean` | `false` | 方向键到边界后循环。 |
| `variant` | `"default" \| "danger"` | `"default"` | 视觉变体。 |
| `as` | `string` | `"div"` | 根原生标签。 |
| `items` | `readonly T[]`,`T extends ListBoxDataItem` | — | 数据集合,具备唯一的 `id`;作用域插槽接收 `item` 和 `index`。 |
| `virtualized` | `boolean` | `false` | 开启竖向固定行高虚拟列表,必须提供 `items`。 |
| `rowHeight` | `number` | `50` | 每行高度(px),必须为正数。 |
| `overscan` | `number` | `5` | 视口外额外渲染的行数,初始化时确定。 |
| `items` | `readonly T[]`,`T extends ListBoxDataItem` | — | 数据集合,具备唯一的 `id`;作用域插槽接收 `item` 和 `index`。虚拟模式下可选 `heading` 字段在其行前渲染分组标题行(仅 `headingHeight` 计高,不参与选择与 `aria-posinset` 索引)。 |
| `virtualized` | `boolean` | `false` | 开启竖向虚拟列表,必须提供 `items`。 |
| `rowHeight` | `number \| (index: number) => number \| undefined` | `50` | 每行高度(px)。函数映射行索引到可变行高,返回 `undefined` 时先估算再按自然内容测量;响应式高度无需重挂载。 |
| `estimatedRowHeight` | `number` | `rowHeight` 数值或 `50` | 可变行高函数返回 `undefined` 时的回退高度(px)。 |
| `headingHeight` | `number \| (index: number) => number \| undefined` | `48` | 虚拟分组标题行高度(px)。 |
| `estimatedHeadingHeight` | `number` | `48` | 未知标题挂载前的估算(px),自然测量后修正。 |
| `loaderHeight` | `number` | `48` | `#loader` 加载行高度(px)。 |
| `gap` | `number` | `0` | 内容行(条目/标题/加载行)之间的间距(px);padding 行不计 gap。 |
| `padding` | `number` | `0` | 列表内边距(px),渲染为行流两端的占位行。 |
| `overscan` | `number` | `5` | 视口外额外渲染的行数,初始化时确定。 |
| `aria-label` / `aria-labelledby` | `string` | — | 根列表框的可访问名称。 |
| `class` / `style` / DOM 事件 | Vue 原生属性 | — | 透传到根 role=listbox 节点,类增量合并。 |
@@ -182,6 +205,7 @@ Vue 使用 `as` 修改原生标签,普通和作用域插槽组合内容;状
| --------------- | ------------------------------------- | -------------------------------------------- |
| 默认插槽 | 数据模式 `{ item: T, index: number }` | 静态部件模式直接放置 Item / Section。 |
| `empty` | 无 | items 为空时的内容。 |
| `loader` | 无 | 虚拟行流末尾的加载行(如「加载更多」),按 `loaderHeight` 计高。 |
| `focus(key?)` | `ListBoxKey?` | 聚焦根或指定可用项;虚拟项先滚动到可见范围。 |
| `selectAll()` | 无 | 多选模式下提出全选,跳过禁用项。 |
| `element` | `HTMLElement` | 根元素引用。 |
@@ -234,3 +258,14 @@ Item 和 ItemIndicator 的默认插槽共享以下状态:
列表使用 role=listbox / option / group,支持单一 Tab 入口、方向键、Home/End、按视口移动的 PageUp/PageDown、Enter/Space、首字母搜索与 IME 避让。多选支持 Ctrl/Command+A 和 Shift 范围选择。横向导航遵循 dir,禁用项不可激活;只读项仍可聚焦。
node SSR 输出选中状态、名称和描述;虚拟列表首屏为滚动容器,挂载后按测量显示可见行。读屏、触屏和完整视觉比较的已验证范围见仓库验证报告,不声明已经完整兼容 React Aria。
## 相关组件
[Select 选择器](./select) · [ComboBox 组合框](./combo-box) · [Avatar 头像](./avatar)
### 未知高度与滚动容器
`row-height` 或 `heading-height` 函数返回 `undefined` 时,先按对应 estimated 高度建立窗口,挂载后使用 ResizeObserver 测量自然内容。显式数字高度由调用方保证适合内容;不要同时给未知高度条目强制固定 CSS 高度。`gap` 是内容行之间的空白,不计入条目自己的内容高度;标题、条目和加载行均参与行流,padding 在两端。
测量缓存按保留类型的逻辑 key 存储,数字 `0` 与字符串 `"0"` 不会串用。容器宽度改变后重测可见内容、失效窗口外的旧宽度缓存;测量修正会保持当前滚动锚点。父滚动容器在空集合时也按 overflow 配置绑定,异步追加不需要重挂载;支持列表自滚与 Autocomplete sticky 搜索框的整体滚动。PageUp/PageDown 使用可见视口和实际行偏移计算目标。`overscan` 可响应式更新。
-5
View File
@@ -187,8 +187,3 @@ Meter 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/
| `style` | `StyleValue` | - | 与计算宽度合并 |
渲染为 `div[data-slot="meter-fill"]`,宽度为 `percentage%`。
## 相关组件
- [ProgressBar 进度条](./progress-bar)
- [ProgressCircle 环形进度条](./progress-circle)
+1 -1
View File
@@ -304,4 +304,4 @@ ModalDialog 的 ARIA/DOM 事件落在实际 role=dialog 的节点。isDismissabl
## 相关组件
[Modal 模态框](./modal) · [Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip)
[Button 按钮](./button) · [Tooltip 工具提示](./tooltip) · [Select 选择器](./select)
+2 -4
View File
@@ -379,9 +379,7 @@ NumberFieldDecrementButton 支持原生 button 属性、事件、`isDisabled`
## 相关组件
- [Input 输入框](./input)
- [TextField 文本输入框](./text-field)
- [FieldError 字段错误](./field-error)
[Label 标签](./label) · [Description 描述](./description) · [FieldError 字段错误](./field-error)
## Vue 适配说明
@@ -392,7 +390,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 -3
View File
@@ -291,6 +291,4 @@ Pagination 使用以下 CSS 类:
## 相关组件
- [Button 按钮](./button)
- [Breadcrumbs 面包屑](./breadcrumbs)
- [Separator 分隔符](./separator)
[Button 按钮](./button) · [Link 链接](./link)
+1 -1
View File
@@ -176,4 +176,4 @@ PopoverContent 的 isNonModal 默认 false,也可在 Popover Root 设置默认
## 相关组件
[Modal 模态框](./modal) · [Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip)
[Button 按钮](./button) · [Tooltip 工具提示](./tooltip) · [Select 选择器](./select)
+1 -6
View File
@@ -85,7 +85,7 @@ import {
<ComponentPreview name="progress-bar-custom-value" />
> 基线差异:上游示例使用 `NumberField` 与 `Select` 调节数值与格式;这两个组件尚未迁移。本示例以原生 `input[type=number]` / `select` 搭配 `hv-input` 样式临时替代,交互与布局对齐基线,控件本身不是本库已发布的 NumberField/Select。
> 控件说明:该示例与上游一致,使用本库公共 `NumberField` 与 `Select` 调节数值与格式。清空或无效输入草稿被拒绝并恢复上一个接受值;越界输入收敛到当前最小/最大值范围内,不会产生 NaN 或进度显示失配。
## 自定义样式
@@ -199,8 +199,3 @@ ProgressBar 使用以下 CSS 类([查看源码样式](https://github.com/herou
| `style` | `StyleValue` | - | 与计算宽度合并 |
渲染为 `div[data-slot="progress-bar-fill"]`。确定进度时宽度为 `percentage%`;不确定进度时不设置宽度,由 CSS 动画驱动。
## 相关组件
- [ProgressCircle 环形进度条](./progress-circle)
- [Meter 计量条](./meter)
-5
View File
@@ -197,8 +197,3 @@ ProgressCircle 组件使用以下 CSS 类([查看源码样式](https://github.
| `class` | `string \| Array \| Object` | - | 合并到 `circle` |
渲染为 `circle[data-slot="progress-circle-fill-circle"]`。
## 相关组件
- [ProgressBar 进度条](./progress-bar)
- [Meter 计量条](./meter)
+14 -14
View File
@@ -207,7 +207,7 @@ RadioGroup 使用以下 CSS 类([查看源码样式](https://github.com/heroui
| `modelValue` | `string \| undefined` | 非受控 | 当前值,使用 v-model |
| `defaultValue` | `string \| undefined` | `undefined` | 非受控初始值副本 |
| `name` / `form` / `id` | `string` | - / - / 自动 | 统一原生提交键、表单归属及组 ID |
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 组视觉样式;Checkbox 成员可显式覆盖 |
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 组视觉样式;Radio 成员可显式覆盖 |
| `isDisabled` / `disabled` | `boolean` | `false` | 合并 Fieldset 禁用,后代不能解除 |
| `isReadOnly` | `boolean` | `false` | 阻止成员点击、空格和方向键修改 |
| `isRequired` / `isInvalid` | `boolean` | `false` | 要求至少一项可用选择 / 错误展示 |
@@ -232,14 +232,14 @@ Radio 必须在 RadioGroup 中使用。不为未选中的 Radio 输出 data-sele
### 事件与暴露
| 接口 | 行为 |
| ------------------------------ | ---------------------------------------------------------------------- |
| `update:modelValue` / `change` | 发出新的数组或标量;不修改传入数组;父级拒绝后恢复所有原生 checked |
| `focus()` / `element` | 聚焦选中可用成员或首个可用成员;空组聚焦组根。element 是组 HTMLElement |
| 接口 | 行为 |
| ------------------------------ | ------------------------------------------------------------------------ |
| `update:modelValue` / `change` | 发出新的标量值(`string`);不修改传入值;父级拒绝后恢复所有原生 checked |
| `focus()` / `element` | 聚焦选中可用成员或首个可用成员;空组聚焦组根。element 是组 HTMLElement |
CheckboxGroup 按原生约定提交同名重复条目,通过 FormData.getAll(name) 获取;RadioGroup 只提交一个选中可用值。未指定 name 不产生提交值。每个成员 value 必须唯一;重复或动态改成重复值会抛出明确错误。不为移除的选择自动选择别的成员;模型保留调用者的值,FormData 只包含实际存在的可用成员。
RadioGroup 按原生约定只提交一个选中可用值,通过 FormData.get(name) 获取;不同于 CheckboxGroup 的同名重复条目。未指定 name 不产生提交值。每个成员 value 必须唯一;重复或动态改成重复值会抛出明确错误。不为移除的选择自动选择别的成员;模型保留调用者的值,FormData 只包含实际存在的可用成员。
required 检查整个组,不能让每个 Checkbox 都变成必选;native 无效提交聚焦第一个可用成员,空组聚焦根。只读保留提交值并跳过必填/自定义约束。reset 尊重 preventDefault,受控值不覆盖,非受控恢复初始副本。动态 name/form 会更新提交和 reset 归属。
required 检查整个组,不能让每个 Radio 都变成必选;native 无效提交聚焦第一个可用成员,空组聚焦根。只读保留提交值并跳过必填/自定义约束。reset 尊重 preventDefault,受控值不覆盖,非受控恢复初始副本。动态 name/form 会更新提交和 reset 归属。
Label 在组中渲染 span 并注册 aria-labelledby;不要手写 for 指向组 div。每个成员独立隔离 Description/FieldError,同时合并组描述和当前组错误。后端错误使用 Form.validationErrors 按 name 映射,编辑后忽略当前响应,新对象可恢复错误。暂不提供异步 validate 或完整 validationDetails。
@@ -251,15 +251,15 @@ Label 在组中渲染 span 并注册 aria-labelledby;不要手写 for 指向
| Control | span,默认插槽 | class/style/DOM 属性与事件 |
| Indicator | span,默认作用域插槽 | 装饰 aria-hidden;自定义内容替换基线指示器 |
具名导出使用 RadioContent、RadioControl、RadioIndicator;不使用 React 对象式子部件。class 均支持字符串、数组和对象。默认图形精确来自基线,文档自定义图标使用 Tabler。Content 输出 selected/indeterminate/hovered/pressed/focus-visible 状态标记供定制样式使用。
具名导出使用 RadioContent、RadioControl、RadioIndicator;不使用 React 对象式子部件。class 均支持字符串、数组和对象。默认图形精确来自基线,文档自定义图标使用 Tabler。Content 输出 selected/hovered/pressed/focus-visible 状态标记供定制样式使用(indeterminate 状态标记仅 Checkbox 输出)。
### 作用域插槽状态
| 参数 | 类型 | 说明 |
| ---------------------------------------------------------- | --------- | ------------------------------ |
| `isSelected` / `isIndeterminate` | `boolean` | 选中 / 半选(半选仅 Checkbox) |
| `isDisabled` / `isReadOnly` / `isRequired` / `isInvalid` | `boolean` | 当前状态 |
| `isHovered` / `isPressed` / `isFocused` / `isFocusVisible` | `boolean` | 单成员交互状态 |
| 参数 | 类型 | 说明 |
| ---------------------------------------------------------- | --------- | -------------------------------------------------- |
| `isSelected` / `isIndeterminate` | `boolean` | 选中 / 半选(Radio 的 isIndeterminate 恒为 false) |
| `isDisabled` / `isReadOnly` / `isRequired` / `isInvalid` | `boolean` | 当前状态 |
| `isHovered` / `isPressed` / `isFocused` / `isFocusVisible` | `boolean` | 单成员交互状态 |
组作用域提供 value、validationErrors、isDisabled/isReadOnly/isRequired/isInvalid,以及 state.value/state.setValue;单成员另提供 state.isSelected/state.setSelected/state.toggle。不把组值和单成员状态混用。
@@ -269,4 +269,4 @@ render 自定义根类型未支持;基线 div+data-custom 示例以 Vue 根属
## 相关组件
[Checkbox](./checkbox) · [CheckboxGroup](./checkbox-group) · [RadioGroup](./radio-group) · [Fieldset](./fieldset)
[Fieldset 字段组](./fieldset) · [Surface 表面](./surface) · [Description 描述](./description)
+7 -7
View File
@@ -270,12 +270,12 @@ RangeCalendar 保留固定基线的主要属性,通过 Vue 模型、具名部
年份选择器复用公共 CalendarYearPicker 部件,支持以下格式化属性。
| 组件 | 属性 | 类型 | 默认值 | 描述 |
| ---------------------------------- | -------------- | ---------------------------- | ------------------- | -------------------------------------------------------------------------------------------- |
| `CalendarYearPickerTriggerHeading` | `format` | `Intl.DateTimeFormatOptions` | - | 自定义月/年标题(如 `{month: 'short'}`)。 |
| `CalendarYearPickerTriggerHeading` | `offset` | `{months?: number}` | - | 相对聚焦日期偏移标题(多月布局)。 |
| `CalendarYearPickerGrid` | `format` | `Intl.DateTimeFormatOptions` | `{year: 'numeric'}` | 自定义年份单元格标签(纪元、历法系统等)。 |
| `CalendarYearPickerGrid` | `visibleYears` | `number` | min–max 跨度或 `20` | 滑动窗口中显示的年份数量。当同时设置 `minValue` 与 `maxValue` 时,默认为二者之间的完整范围。 |
| 组件 | 属性 | 类型 | 默认值 | 描述 |
| ---------------------------------- | -------------- | ---------------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CalendarYearPickerTriggerHeading` | `format` | `Intl.DateTimeFormatOptions` | - | 自定义月/年标题(如 `{month: 'short'}`)。 |
| `CalendarYearPickerTriggerHeading` | `offset` | `{months?: number}` | - | 相对聚焦日期偏移标题(多月布局)。 |
| `CalendarYearPickerGrid` | `format` | `Intl.DateTimeFormatOptions` | `{year: 'numeric'}` | 自定义年份单元格标签(纪元、历法系统等)。 |
| `CalendarYearPickerGrid` | `visibleYears` | `number` | min–max 完整范围 | 滑动窗口中显示的年份数量;缺省显示 min–max 完整范围(未设约束时为 1900–2099),传入数字时以焦点年为中心。上游文档写“或 `20`”,本实现没有该回退分支 |
### RangeCalendarCell 作用域插槽
@@ -303,7 +303,7 @@ RangeCalendar 保留固定基线的主要属性,通过 Vue 模型、具名部
## 相关组件
[Calendar 日历](./calendar) · [DateField 日期字段](./date-field) · [TimeField 时间字段](./time-field)
[Calendar 日历](./calendar) · [DateField 日期字段](./date-field) · [DatePicker 日期选择器](./date-picker)
## Vue 公共契约与差异
-4
View File
@@ -160,7 +160,3 @@ const { attributes } = useScrollShadow({ containerRef: element });
</div>
</template>
```
## 相关组件
[ScrollShadow 滚动阴影](./scroll-shadow) · [Tabs 标签页](./tabs)
+12 -3
View File
@@ -103,7 +103,7 @@ SearchField 组件支持两种视觉变体:
### 表单示例
完整的表单集成示例,包含校验、实际 FormData 和模拟提交反馈;没有后台搜索请求。
完整的表单集成示例,包含校验与模拟提交(提交值输出到控制台);没有后台搜索请求。
<ComponentPreview name="search-field-form-example" />
@@ -217,6 +217,7 @@ SearchField 与 TextField 共用文本字段内核、表单策略和 ID 协议
| 属性 | 类型 | 默认值 | 描述 |
| ------------------------------------- | -------------------------------------------------------------------- | ---------------------- | ------------------------------------------------- |
| `validationErrors` | `string \| string[]` | - | 字段级外部错误,与 Form 同名错误合并 |
| `modelValue` / `defaultValue` | `string` | - | 受控值 / 非受控初始值 |
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 根与 Group 的视觉变体 |
| `fullWidth` | `boolean` | `false` | 根与 Group 全宽 |
@@ -232,7 +233,7 @@ SearchField 与 TextField 共用文本字段内核、表单策略和 ID 协议
| `class` / `style` | Vue class / style 绑定 | - | 根节点属性;ARIA 下发到输入 |
| 默认插槽 | 作用域插槽 | - | 字段部件及状态 |
服务端错误通过 Form 的 validationErrors 按 name 映射;不提供 SearchField 独立 validationErrors 数组。validate 暂不接受 Promise;FieldError 无完整 React Aria validationDetails。
字段级 `validationErrors`(字符串或数组)与 Form 按 name 提供的错误共同接入;`validate` 暂不接受 Promise。FieldError 可读取真实控件的 `validationDetails`(ValidityState 快照)。
### 事件与暴露
@@ -269,4 +270,12 @@ SearchField 与 TextField 共用文本字段内核、表单策略和 ID 协议
## 相关组件
[TextField](./text-field) · [InputGroup](./input-group) · [FieldError](./field-error)
[Label 标签](./label) · [Description 描述](./description) · [FieldError 字段错误](./field-error)
## 字段级错误与焦点
`autoFocus?: boolean` 在挂载后聚焦真实 input/textarea(禁用控件不聚焦),不落到字段 div。默认插槽提供 `value`、`isFocusWithin`、`isFocusVisible`、`validationErrors` 和 `validationDetails`;根的 `data-focus-within` / `data-focus-visible` 与实际组内焦点和浏览器判定同步。
`validationErrors?: string | string[]` 用于字段级外部错误;显示顺序为字段错误、Form 中该 name 的错误、已触发的 validate/原生错误,字段与 Form 的重复消息去重。native 策略下外部错误写入真实控件的 customValidity,aria 策略只显示语义错误。`isInvalid` 仍只控制展示,不单独设置 customValidity。
改变值的输入事件会忽略当前字段错误响应与 Form 错误响应,reset 也会清除它们;新数组/对象引用视为新响应,重新显示。相同响应引用的原地修改不用于重新投递已忽略的错误。字段级响应只影响当前字段,Form 的其他字段错误保留。FieldError 的 `validationDetails` 是只读的原生 ValidityState 标志快照,不是第二套字段值。
+2 -2
View File
@@ -341,8 +341,8 @@ 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。
## 相关组件
[ListBox](/components/list-box)、[Popover](/components/popover)、[Fieldset](/components/fieldset)、[Label](/components/label)、[FieldError](/components/field-error)
[ListBox 列表框](./list-box) · [Popover 弹出框](./popover) · [Label 标签](./label)
+1 -1
View File
@@ -102,4 +102,4 @@ Separator 使用以下 CSS 类([查看源码样式](https://github.com/heroui-
## 相关组件
[Surface 表面](./surface) · [Card 卡片](./card)
[Card 卡片](./card) · [Chip 标签](./chip) · [Avatar 头像](./avatar)
+1 -1
View File
@@ -182,4 +182,4 @@ Skeleton 支持三种动画类型,视觉效果各不相同:
## 相关组件
[Card 卡片](./card) · [Spinner 加载指示器](./spinner)
[Card 卡片](./card) · [Avatar 头像](./avatar)
+4
View File
@@ -233,3 +233,7 @@ React 的 `render` 通过 Vue 的 `as`、属性绑定和插槽表达。
- 尊重 reduced-motion;数据和 ARIA 首屏可直接 SSR。完整读屏、触屏设备和 Nuxt 验收状态见验证报告。
实现差异:Reka 2.11 的 Collection Thumb 无法在服务端提供显式索引,也没有单项禁用;本组件采用原生输入与轨道局部指针适配,未引入第二套底座库。来源是固定版本英文正文和中文演示,完整差异与验证见仓库的 SLIDER-01 报告。
## 相关组件
[Label 标签](./label) · [Form 表单](./form) · [Description 描述](./description)
-4
View File
@@ -88,7 +88,3 @@ Spinner 使用以下 CSS 类:
| `class` | `string` | - | 额外的 CSS 类名 |
根节点默认 `role="status"` 与 `aria-label="Loading"`,可通过 attrs 覆盖。内部 SVG 标记 `aria-hidden`,使用 `currentColor` 渐变;嵌入 Button 时保持所选尺寸(如 `size="sm"` 为 16px),不被 Button 的普通 SVG 规则覆盖。
## 相关组件
[Button 按钮](./button) · [Input 输入框](./input)
+1 -1
View File
@@ -104,4 +104,4 @@ const surface = inject(surfaceContextKey, undefined);
## 相关组件
[Card 卡片](./card) · [Input 输入框](./input) · [Button 按钮](./button)
[CheckboxGroup 复选框组](./checkbox-group) · [Fieldset 字段组](./fieldset) · [InputOTP 验证码输入](./input-otp)
+85 -5
View File
@@ -29,7 +29,11 @@ import {
```vue
<Switch>
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
<SwitchControl>
<SwitchThumb>
<SwitchIcon /> <!-- 可选:滑块内图标 -->
</SwitchThumb>
</SwitchControl>
启用通知
</SwitchContent>
<Description>允许接收通知</Description>
@@ -38,6 +42,25 @@ import {
请把 SwitchControl 与标签文本放入 SwitchContent;Description 作为其兄弟节点。Vue 底座使用原生 button 承载 role="switch",不是 React Aria 的 label 结构。
要对多个 Switch 进行分组,请使用 `SwitchGroup` 组件:
```vue
<SwitchGroup>
<Switch v-model:checked="option1">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
选项一
</SwitchContent>
</Switch>
<Switch v-model:checked="option2">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
选项二
</SwitchContent>
</Switch>
</SwitchGroup>
```
## 示例
### 尺寸
@@ -104,17 +127,74 @@ Vue 使用 `asChild` 合并根容器属性,默认插槽必须只有一个自
### 全局 CSS
若要自定义组件类,可使用 `@layer components` 指令;下面的类名与状态选择器都来自当前样式表:
```css
@layer components {
.hv-switch {
--switch-control-bg: var(--default);
--switch-control-bg-checked: var(--accent);
}
.hv-switch__control {
border-radius: 12px;
@apply h-5 w-8;
}
.hv-switch__thumb {
@apply bg-white shadow-sm;
}
.hv-switch__content {
@apply inline-flex items-center gap-3;
}
.hv-switch__icon {
@apply h-3 w-3 text-current;
}
}
```
## 样式参考
保留字段根容器、Content、Control、Thumb、Icon 的组合结构和 data-slot;类名前缀为 `hv-`。选中状态使用 `data-selected="true"`,禁用使用 `data-disabled="true"`。尺寸与滑块比例移植自基线 CSS。
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
### CSS 类
#### Switch 类 [!toc]
Switch 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/switch.css)):
- `.hv-switch` - Switch 根容器(字段)
- `.hv-switch__content` - 包裹控件与标签文本的 `button[role="switch"]`
- `.hv-switch__control` - Switch 轨道
- `.hv-switch__thumb` - 可移动的滑块
- `.hv-switch__icon` - 滑块内可选图标
- `.hv-switch--sm` - 小尺寸变体
- `.hv-switch--md` - 中尺寸变体(默认)
- `.hv-switch--lg` - 大尺寸变体
#### SwitchGroup 类 [!toc]
SwitchGroup 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/switch-group.css)):
- `.hv-switch-group` - Switch 组容器
- `.hv-switch-group__items` - Switch 项容器
- `.hv-switch-group--horizontal` - 横向布局
- `.hv-switch-group--vertical` - 纵向布局(默认)
> 变体映射 `switchGroupVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `SwitchGroupVariants` 类型),提供 `base` / `items` 两个槽;组件渲染的类名由该映射生成。
### 交互状态
该 Switch 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制:
- **已选中**:根上 `[data-selected="true"]` 或 `[aria-checked="true"]`(滑块位置与背景色变化)
- **悬停**:`:hover` 或 SwitchContent 上 `[data-hovered="true"]`(作用于 Control 轨道)
- **聚焦**:`:focus-visible` 或 SwitchContent 上 `[data-focus-visible="true"]`(在轨道上显示焦点环)
- **禁用**:根上 `[data-disabled="true"]`(降低透明度,包括帮助文本)
- **按压**:`:active` 或 SwitchContent 上 `[data-pressed="true"]`
只读与错误另有根上 `[data-readonly]`、`[data-invalid]` 标记。选中且禁用的组合配色由 `[data-selected="true"][data-disabled="true"]` 等复合规则提供。
## API 参考
@@ -172,8 +252,8 @@ SwitchGroup 是布局容器,每个 Switch 独立维护值;请提供 aria-lab
### 当前差异
`disabled` / `required` / `defaultChecked` 作为兼容别名保留。`change` 事件传递 boolean;React Aria 的 PressEvent 仍不等价于 DOM click。根组件的 class/style/data-* 作用于字段容器,ARIA 与 DOM 事件作用于 Content 按钮;Content 上的显式属性可覆盖默认透传。`asChild` 替代 React render prop。FieldError 当前仅接入 Switch 字段,尚未提供完整 TextField / Form 体系。
`disabled` / `required` / `defaultChecked` 作为兼容别名保留。`change` 事件传递 boolean;React Aria 的 PressEvent 仍不等价于 DOM click。根组件的 class/style/data-* 作用于字段容器,ARIA 与 DOM 事件作用于 Content 按钮;Content 上的显式属性可覆盖默认透传。`asChild` 替代 React render prop。Label / Description / FieldError 通过共享字段上下文接入 Switch;Form 的 `validationErrors` 按 name 映射、reset 与 `validationBehavior` 继承均已接入。
## 相关组件
[Button 按钮](./button) · [Input 输入框](./input)
[Label 标签](./label) · [Description 描述](./description) · [Button 按钮](./button)
+52 -21
View File
@@ -60,6 +60,8 @@ import {
在 `TableColumn` 上使用 `allows-sorting` 属性可启用列排序。在 `TableContent` 上使用 `sort-descriptor` 与 `update:sort-descriptor` 管理排序状态。将标签包裹在 `TableSortableColumnHeader` 中,并传入列的 `sort-direction` 以渲染默认升序/降序指示器。
列头是唯一的排序入口:点击、Enter、Space 各触发一次排序(`TableSortableColumnHeader` 的触发按钮承担键盘焦点,点击经冒泡汇入列的单一排序路径)。焦点环显示在列头 `th` 上(基线位置):触发按钮把真实 `:focus-visible` 状态转发到 `th` 的 `[data-focus-visible]` 钩子,按钮自身的 UA 轮廓在列内被抑制。
<ComponentPreview name="table-sorting" minHeight="380px" />
### 选择
@@ -82,7 +84,7 @@ import {
### 列宽调整
将表格包裹在 `TableResizableContainer` 中,并在每个可调整宽度的列内添加 `TableColumnResizer`。列可用 `default-width="1fr"` 表示弹性初始宽度(映射为原生 `width: auto`,共享剩余空间;不实现 RAC 的 fr 权重比例)。
将表格包裹在 `TableResizableContainer` 中,并在每个可调整宽度的列内添加 `TableColumnResizer`。列可用 `default-width="Nfr"` 表示按权重分配剩余宽度(与固定源一致):数字为 px、`N%` 为百分比,`Nfr` 列共享扣除固定/百分比列后的剩余宽度并按权重比例分配;未显式设置宽度的列在存在 `fr` 列时按 `1fr` 参与分配。`min-width` / `max-width` 对每列份额生效(超出时按 flex 语义冻结违规列并把余量再分配),容器缩放会重新分配、拖动后的列冻结为其像素宽度,RTL 下几何一致、拖动方向相反。
<ComponentPreview name="table-column-resizing" minHeight="420px" />
@@ -94,7 +96,7 @@ import {
### 虚拟滚动
仅渲染视口内可见行,从而高效展示大数据集。本库使用固定行高窗口替代 React Aria `Virtualizer`。
仅渲染视口内可见行,从而高效展示大数据集。本库以 `useVirtualRows` 行几何组合式替代 React Aria `Virtualizer`,支持固定与可变行高、`gap` / `padding` 与加载行预留(见下文 TableLayout 映射)。示例保留基线的 42px 显式行高、300px 视口与外层滚动容器:原生 `<table>` 不能作为滚动容器(`height` 是最小高度且 `overflow` 需要确定高度,实测 300px 被内容撑到 45036px),而固定源滚动的是虚拟网格元素;列宽用 `minWidth`(fr 语义由 TableContent 列布局承担),长文本按列宽截断。
<ComponentPreview name="table-virtualization" minHeight="380px" />
@@ -223,25 +225,25 @@ Table 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制
### TableColumn
| Prop / 事件 | 类型 | 默认值 | 描述 |
| ------------------------------- | ------------------ | ------- | --------------------------------------------------------------------- |
| `as` | `string` | `'th'` | 列头标签,scope=col |
| `id` | `string` | — | 排序与树形列 id |
| `allowsSorting` / `isRowHeader` | `boolean` | `false` | 排序列 / 对应正文单元格为 th[scope=row] |
| `width` / `defaultWidth` | `number \| string` | — | 受控宽度 / 非受控初始宽度;数字为 px,`Nfr` 为弹性 auto(非权重比例) |
| `minWidth` / `maxWidth` | `number` | — | 宽度上下限,优先于 Resizer 的缺省边界 |
| `update:width` | `number` | — | 拖动/键盘提出的宽度,可使用 v-model:width |
| 默认插槽 | 内容 | — | 列标签及排序、调整手柄 |
| Prop / 事件 | 类型 | 默认值 | 描述 |
| ------------------------------- | ------------------ | ------- | ---------------------------------------------------------------------------------------------------------------------- |
| `as` | `string` | `'th'` | 列头标签,scope=col |
| `id` | `string` | — | 排序与树形列 id |
| `allowsSorting` / `isRowHeader` | `boolean` | `false` | 排序列 / 对应正文单元格为 th[scope=row] |
| `width` / `defaultWidth` | `number \| string` | — | 受控宽度 / 非受控初始宽度;数字为 px,`N%` 为百分比,`Nfr` 按权重分配剩余宽度(存在 fr 列时未设宽度的列按 `1fr` 参与) |
| `minWidth` / `maxWidth` | `number` | — | 宽度上下限,优先于 Resizer 的缺省边界 |
| `update:width` | `number` | — | 拖动/键盘提出的宽度,可使用 v-model:width |
| 默认插槽 | 内容 | — | 列标签及排序、调整手柄 |
### TableBody
| Prop / 插槽 | 类型 | 默认值 | 描述 |
| ----------- | ------------------ | --------- | --------------------------------------------------------------------------- |
| `as` | `string` | `'tbody'` | 正文根 |
| `empty` | `boolean` | 自动判断 | 为 `true` 时强制空状态;省略时若默认插槽未渲染任何行则视为空 |
| `colspan` | `number \| string` | `1` | 空状态单元格跨列数 |
| 默认插槽 | 行内容 | — | 动态行使用 v-for |
| `#empty` | 空状态 | — | 空数据时渲染;包在 `role="presentation"` 行内,不参与选择、行计数与键盘导航 |
| Prop / 插槽 | 类型 | 默认值 | 描述 |
| ----------- | ------------------ | -------------------- | -------------------------------------------------------------------------------------------- |
| `as` | `string` | `'tbody'` | 正文根 |
| `empty` | `boolean` | 自动判断 | 为 `true` 时强制空状态;省略时若默认插槽未渲染任何行则视为空 |
| `colspan` | `number \| string` | 自动(实际叶子列数) | 空状态单元格跨列数;缺省跨全部实际叶子列(含选择列与包装渲染的列,随列增减更新),显式值优先 |
| 默认插槽 | 行内容 | — | 动态行使用 v-for |
| `#empty` | 空状态 | — | 空数据时渲染;包在 `role="presentation"` 行内,不参与选择、行计数与键盘导航 |
### TableRow
@@ -249,6 +251,7 @@ Table 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制
| --------------- | ---------- | ------- | ------------------------------ |
| `as` | `string` | `'tr'` | 行标签 |
| `rowKey` | `TableKey` | 必填 | 稳定逻辑 key;代替 React 的 id |
| `height` | `number` | — | 精确虚拟行高(px);省略保留自然高度,未知行使用 measureRow 测量。 |
| `isDisabled` | `boolean` | `false` | 行禁用,不抢子控件事件 |
| `level` | `number` | — | 树形行层级,从 1 开始 |
| `hasChildItems` | `boolean` | `false` | 是否有树子项 |
@@ -330,7 +333,19 @@ Table 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制
### TableLayout 与 Vue 虚拟滚动
未导出 React Aria TableLayout 类。示例使用固定 42px 行高、300px 滚动视口和 overscan 窗口(对齐上游 `layoutOptions.rowHeight/headingHeight = 42`),按完整 rowKeys 处理键盘请求;aria-rowcount 包括表头,aria-rowindex 为逻辑位置。仅当前窗口挂载。可变高度、拖放指标与 RAC 虚拟布局扩展暂不支持,不能把固定行高示例用于多行自动换高的数据。TanStack 示例使用可选 table-core 数据模型(含 `getPaginationRowModel`),库运行时不依赖它。
未导出 React Aria TableLayout 类;行几何由公共组合式 `useVirtualRows` / `bindVirtualRows` 提供(共享测量与行几何,不引入选择状态内核:选择、身份与焦点仍归集合/表格模型)。示例使用固定 42px 行高、300px 滚动视口和 overscan 窗口(对齐上游 `layoutOptions.rowHeight/headingHeight = 42`;42 是示例显式值,布局默认 48),按完整 rowKeys 处理键盘请求;aria-rowcount 包括表头,aria-rowindex 为逻辑位置。仅当前窗口挂载。TanStack 示例使用可选 table-core 数据模型(含 `getPaginationRowModel`),库运行时不依赖它。
| `useVirtualRows` 选项 | 类型 | 默认值 | 描述 |
| --- | --- | --- | --- |
| `count` | `MaybeRefOrGetter<number>` | — | 表体行数;getter 响应式更新行流。 |
| `rowHeight` | `number \| (index: number) => number \| undefined` | — | 行高(px);函数映射行索引到可变行高,返回 `undefined` 回退 `estimatedRowHeight`。每次布局重读。 |
| `estimatedRowHeight` | `number \| (index: number) => number` | `48` | 未知行挂载前的估算高度(px),测量后修正。 |
| `loaderHeight` | `number` | `0` | 行流末尾的加载行预留(px),在最后一行的 gap 之后、尾部 padding 之前;计入 `totalHeight` 与 `window.padBottom`。 |
| `gap` | `number` | `0` | 行之间的间距(px),计入较早一行的 `rowExtentOf`;padding 不计 gap。 |
| `padding` | `number` | `0` | 列表内边距(px),计入行流两端(`padTop` 含头部、`padBottom` 含尾部)。 |
| `overscan` | `number` | `8` | 视口外额外渲染的行数。 |
`window` 提供 `start` / `end` / `padTop` / `padBottom`(渲染 `<tr>` 占位的 spacer 高度,padTop + 已渲染行占位(含 gap)+ padBottom 恒等于 `totalHeight`),`scrollToIndex` 按行偏移滚动并夹在行流内,`bindVirtualRows` 把窗口更新绑定到滚动容器(滚动与容器缩放)。TableHeader 始终挂载,表头高度通过实际 DOM 行流起点测量,不增加一个脱离真实表头的估算参数;可用 TableHeader 的 style 设置高度(本例 42px)。`dropIndicatorThickness` 同 ListBox——Vue 侧无拖放实现,不提供空参数。
## 无障碍
@@ -338,5 +353,21 @@ Table 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制
## 相关组件
- [Pagination 分页](./pagination)
- [Button 按钮](./button)
[Pagination 分页](./pagination) · [Checkbox 复选框](./checkbox) · [Chip 标签](./chip)
### 自然测量与精确行高
`useVirtualRows` 只管理布局几何,选择与键盘身份仍由 TableContent 的完整 `rowKeys` 管理。新增能力:
| API | 说明 |
| --- | --- |
| `keys?: MaybeRefOrGetter<readonly (string \| number)[]>` | 与行索引对应的稳定身份,保留数字/字符串类型;缺省按索引缓存。 |
| `measureRow(index, element)` | 绑定自然高度行的 DOM/组件 ref。rowHeight 函数返回 undefined 时,先估算,再观察真实行高。 |
| `resetMeasurements()` | 调用方批量替换窗口外内容后,主动失效旧尺寸缓存。 |
| `bindVirtualRows(rows, viewport, { content?, scrollPaddingStart? })` | content 是行流原点,表格默认识别真实 tbody;sticky 遮挡高度可传数字或 getter。绑定负责 scroll、resize 和清理。 |
| `TableRow.height?: number` | 显式虚拟行高度(px)。内部保留原生 th/td,并用内容盒承接 padding,避免 42px 行被原生单元格最小内容撑成 45px;省略时保留原有自然布局。 |
未知高度行使用 `:ref="el => rows.measureRow(index, el)"`,并省略 `TableRow.height`;已知高度行传 `:height="height"`。已知行高不应小于需要展示的内容。`gap` 属于行间距:Table 消费方可用不参与导航的 presentation spacer 行渲染;加载行在行流尾部预留中渲染,不要重复叠加高度。示例保留原生滚动 div,移除额外 table-fixed/ellipsis 限制,42px 的模型与实际行高一致。
滚动定位会计入 tbody/表头原点及 sticky 遮挡;未知目标挂载测量后会进一步校准。宽度变化会重测自然行并失效窗口外旧尺寸;测量修正保持滚动锚点。使用组合式函数时应处于 Vue setup/effectScope 中,以随组件清理测量观察器。
+23 -9
View File
@@ -13,7 +13,8 @@ group: 组件
import { Tabs } from "@heroui-vue/components";
```
<ComponentPreview name="tabs-basic" />
<ComponentPreview
isBgSolid name="tabs-basic" />
## 组件结构
@@ -54,37 +55,44 @@ import {
### 垂直布局
<ComponentPreview name="tabs-vertical" />
<ComponentPreview
isBgSolid name="tabs-vertical" />
### 溢出
当标签列表超出可用空间时,`TabsListContainer` 会自动渲染滚动箭头与渐隐边缘,使用户可以导航到被隐藏的标签。水平与垂直方向均支持此行为。
<ComponentPreview name="tabs-overflow" />
<ComponentPreview
isBgSolid name="tabs-overflow" />
### 禁用 Tab
<ComponentPreview name="tabs-disabled" />
<ComponentPreview
isBgSolid name="tabs-disabled" />
### 带分隔线
在每个 `<TabsTab>` 内(第一项除外)添加 `<TabsSeparator />`,用于在标签之间显示分隔线。
<ComponentPreview name="tabs-with-separator" />
<ComponentPreview
isBgSolid name="tabs-with-separator" />
### 次要类型
<ComponentPreview name="tabs-secondary" />
<ComponentPreview
isBgSolid name="tabs-secondary" />
### 次要类型(垂直)
<ComponentPreview name="tabs-secondary-vertical" />
<ComponentPreview
isBgSolid name="tabs-secondary-vertical" />
### 对齐方式
标签内容默认居中。使用 `align` 可将其对齐到 `start` 或 `end`,这在垂直的侧边栏式导航中尤其有用。单个标签仍可通过 `TabsTab` 上的 `class` 覆盖。
<ComponentPreview name="tabs-vertical-alignment" />
<ComponentPreview
isBgSolid name="tabs-vertical-alignment" />
### 渲染函数
@@ -237,4 +245,10 @@ RAC 的集合 render-prop API 不作逐字复制,列表用 v-for,DOM render
## 相关组件
[ScrollShadow 滚动阴影](./scroll-shadow) · [Tabs 标签页](./tabs)
[Breadcrumbs 面包屑](./breadcrumbs)
## 相关案例
以下卡片链接至上游 React 案例(新窗口)。
<DocsRelatedShowcases component="Tabs" />
+1 -1
View File
@@ -282,4 +282,4 @@ TagGroup 组件使用以下 CSS 类([查看源码样式](https://github.com/he
## 相关组件
[Chip 标签](./chip) · [Description 描述](./description) · [ErrorMessage 错误消息](./error-message) · [Label 标签](./label)
[Label 标签](./label) · [Description 描述](./description) · [ErrorMessage 错误消息](./error-message)
+15 -3
View File
@@ -133,6 +133,8 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
- `.hv-textfield` – 根容器,样式极少(`flex flex-col gap-1`)
> 变体映射 `textFieldVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `TextFieldVariants` 类型);`full-width` 输出 `.hv-textfield--full-width`,组件根类名由该映射生成。
> **提示:** 子组件([Label](/components/label)、[Input](/components/input)、[TextArea](/components/textarea)、[Description](/components/description)、[FieldError](/components/field-error))各自拥有 CSS 类与样式,定制方式请参见对应文档。
### 交互状态
@@ -151,6 +153,8 @@ TextField 会根据状态自动管理以下 data 属性:
| Prop | 类型 | 默认值 | 描述 |
| ------------------------------------- | -------------------------------------------------------------------- | -------------------------- | -------------------------------------------------- |
| 默认插槽 | `Component` | - | 子组件(Label、Input、Description、FieldError 等) |
| `validationErrors` | `string \| string[]` | - | 字段级外部错误,与 Form 同名错误合并 |
| `autoFocus` | `boolean` | `false` | 挂载后聚焦真实文本控件 |
| `modelValue` | `string` | - | 当前值(受控;`v-model`) |
| `defaultValue` | `string` | - | 默认值(非受控) |
| `name` | `string` | - | 用于 HTML 表单提交的 input 名称 |
@@ -170,7 +174,7 @@ TextField 会根据状态自动管理以下 data 属性:
| `form` | `string` | - | 关联外部 form 的 id(下发到真实控件) |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
值使用 `v-model`(`update:modelValue`)。受控值由父级决定,拒绝更新时恢复实际 DOM 值。`name`、原生约束、`autoComplete` / `inputMode` / `form` 与 ARIA 落在真实 `input`/`textarea` 上。服务端/外部错误通过 Form 的 `validation-errors`(按 name 映射)接入,不是 TextField 的 `validationErrors` 数组。
值使用 `v-model`(`update:modelValue`)。受控值由父级决定,拒绝更新时恢复实际 DOM 值。`name`、原生约束、`autoComplete` / `inputMode` / `form` 与 ARIA 落在真实 `input`/`textarea` 上。服务端/外部错误既可由字段 `validationErrors`(字符串或数组)传入,也可由 Form 的 `validation-errors` 按 name 映射。
### 事件
@@ -232,8 +236,16 @@ const hasError = ref(false);
| `isInvalid` | `boolean` | 是否无效 |
| `validationErrors` | `string[]` | 当前错误列表 |
与上游 `TextFieldRenderProps` 的差异:Vue 使用作用域插槽而非 render prop;无 `isFocusWithin` / `isFocusVisible`(聚焦状态由控件自身管理)。
Vue 使用类型可解析的作用域插槽;`TextFieldRenderProps` 包含 `value`、`isFocusWithin`、`isFocusVisible` 与 `validationDetails`。组内焦点移动保持 focus-within,移出整个字段才清除。
## 相关组件
[Input 输入框](./input) · [TextArea 多行文本框](./textarea) · [Label 标签](./label) · [FieldError 字段错误](./field-error)
[Input 输入框](./input) · [TextArea 多行文本框](./textarea) · [Fieldset 字段组](./fieldset)
## 字段级错误与焦点
`autoFocus?: boolean` 在挂载后聚焦真实 input/textarea(禁用控件不聚焦),不落到字段 div。默认插槽提供 `value`、`isFocusWithin`、`isFocusVisible`、`validationErrors` 和 `validationDetails`;根的 `data-focus-within` / `data-focus-visible` 与实际组内焦点和浏览器判定同步。
`validationErrors?: string | string[]` 用于字段级外部错误;显示顺序为字段错误、Form 中该 name 的错误、已触发的 validate/原生错误,字段与 Form 的重复消息去重。native 策略下外部错误写入真实控件的 customValidity,aria 策略只显示语义错误。`isInvalid` 仍只控制展示,不单独设置 customValidity。
改变值的输入事件会忽略当前字段错误响应与 Form 错误响应,reset 也会清除它们;新数组/对象引用视为新响应,重新显示。相同响应引用的原地修改不用于重新投递已忽略的错误。字段级响应只影响当前字段,Form 的其他字段错误保留。FieldError 的 `validationDetails` 是只读的原生 ValidityState 标志快照,不是第二套字段值。
+1 -1
View File
@@ -125,4 +125,4 @@ TextArea 接受所有标准 HTML `<textarea>` 属性,以及以下属性:
## 相关组件
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [InputGroup 输入框组](./input-group)
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [Label 标签](./label)
+2 -2
View File
@@ -442,7 +442,7 @@ TimeFieldSuffix 接受标准 HTML `div` 属性:
## 相关组件
[DateField](/components/date-field) · [Calendar](/components/calendar)
[Label 标签](./label) · [FieldError 字段错误](./field-error) · [Description 描述](./description)
## Vue 兼容说明
@@ -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 不重复发送已经接受的值。
+8 -9
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
@@ -351,5 +351,4 @@ React 对象部件改具名导出,ReactNode 改 VNodeChild,onPress 改 DOM c
## 相关组件
- [Button 按钮](./button)
- [Spinner 加载指示器](./spinner)
[Button 按钮](./button) · [Alert 警告](./alert) · [CloseButton 关闭按钮](./close-button)
+1 -4
View File
@@ -173,7 +173,4 @@ ToggleButtonGroup 组件使用以下 CSS 类:
## 相关组件
- [ToggleButton 切换按钮](./toggle-button)
- [ButtonGroup 按钮组](./button-group)
- [CheckboxGroup 复选框组](./checkbox-group)
- [RadioGroup 单选框组](./radio-group)
[ToggleButton 切换按钮](./toggle-button) · [ButtonGroup 按钮组](./button-group) · [Button 按钮](./button)
+2 -4
View File
@@ -93,7 +93,7 @@ ToggleButton 组件使用以下 CSS 类:
- **悬停**`:hover` 或 `[data-hovered="true"]`
- **激活/按下**:`:active` 或 `[data-pressed="true"]`(包含缩放变换)
- **聚焦**:`:focus-visible` 或 `[data-focus-visible="true"]`(显示焦点环)
- **禁用**:`:disabled` 或 `[data-disabled="true"]`(降低透明度,禁用指针事件)
- **禁用**:`:disabled` 或 `[aria-disabled="true"]`(降低透明度,禁用指针事件;组件同时输出 `[data-disabled="true"]` 标记,但基线样式选择器是前两者)
## API 参考
@@ -134,6 +134,4 @@ ToggleButton 组件使用以下 CSS 类:
## 相关组件
- [ToggleButtonGroup 切换按钮组](./toggle-button-group)
- [ButtonGroup 按钮组](./button-group)
- [Switch 开关](./switch)
[Button 按钮](./button) · [Switch 开关](./switch) · [Checkbox 复选框](./checkbox)
+1 -4
View File
@@ -92,7 +92,4 @@ Toolbar 使用以下 CSS 类:
## 相关组件
- [ButtonGroup 按钮组](./button-group)
- [ToggleButtonGroup 切换按钮组](./toggle-button-group)
- [Separator 分隔符](./separator)
- [Tabs 标签页](./tabs)
[ButtonGroup 按钮组](./button-group) · [ToggleButtonGroup 切换按钮组](./toggle-button-group) · [Separator 分隔符](./separator)
+1 -1
View File
@@ -178,4 +178,4 @@ showArrow 选择带箭头的默认偏移(7px,否则 3px),仍需显式放
## 相关组件
[Modal 模态框](./modal) · [Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip)
[Button 按钮](./button) · [Popover 弹出框](./popover)
-4
View File
@@ -187,7 +187,3 @@ Typography 组件使用以下 CSS 类([查看源码样式](https://github.com/
| 默认插槽 | - | - | 常规 HTML 富文本内容。 |
`TypographyProse` 固定渲染 `div`,内部标题、段落、列表、引用、代码块、链接、图片等使用基线排版规则。`$attrs` 透传至该 `div`。
## 相关组件
[Card 卡片](./card) · [Kbd 键盘按键](./kbd)
+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>
@@ -9,6 +9,7 @@ import {
AutocompletePopover,
AutocompleteTrigger,
AutocompleteValue,
createBaseContains,
Description,
EmptyState,
Label,
@@ -20,6 +21,7 @@ import {
SearchFieldGroup,
SearchFieldInput,
SearchFieldSearchIcon,
useLocale,
type ListBoxKey,
} from "@heroui-vue/components";
@@ -97,15 +99,19 @@ const allUsers = generateUsers(1000);
const selectedKey = ref<ListBoxKey | null>(null);
const searchQuery = ref("");
// 与 AutocompleteFilter 默认谓词共用同一实现(locale 敏感、大小写与变音折叠,
// 例如 cafe 能匹配 Café);本示例自行过滤以驱动虚拟滚动,故关闭集合二次过滤。
const { locale } = useLocale();
const contains = computed(() => createBaseContains(locale.value));
const filteredUsers = computed(() => {
const query = searchQuery.value.trim().toLocaleLowerCase();
const query = searchQuery.value.trim();
if (!query) return allUsers;
return allUsers.filter(
(user) =>
user.name.toLocaleLowerCase().includes(query) ||
user.email.toLocaleLowerCase().includes(query),
contains.value(user.name, query) || contains.value(user.email, query),
);
});
@@ -150,12 +156,10 @@ const keepResults = () => true;
<SearchFieldClearButton />
</SearchFieldGroup>
</SearchField>
<ListBox
:items="filteredUsers"
class="max-h-[320px] overflow-y-auto"
:row-height="50"
virtualized
>
<!-- The popover scrolls as a whole (pinned layout): the virtual
window binds to that scrolling ancestor, keeping the search
field sticky at its top. -->
<ListBox :items="filteredUsers" :row-height="50" virtualized>
<template #default="{ item }">
<ListBoxItem :id="item.id" :text-value="item.name" class="h-full">
<div class="flex flex-col">
+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>

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