From dc859fb8aeacac7eb3a798676356cb2c387e5d45 Mon Sep 17 00:00:00 2001 From: maoyingjie Date: Wed, 28 Oct 2026 23:36:59 +0800 Subject: [PATCH] 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. --- apps/docs/components/description.md | 2 + apps/docs/components/field-error.md | 2 + apps/docs/components/label.md | 2 + apps/docs/components/switch.md | 2 + apps/docs/components/text-field.md | 2 + apps/docs/styling.md | 16 ++++ docs/compatibility.md | 4 + docs/upstream.md | 5 ++ packages/styles/base/base.css | 17 ++++ packages/styles/index.css | 3 + packages/styles/src/index.ts | 71 +++++++++++++++ .../components/description/Description.vue | 8 +- .../vue/src/components/field/FieldError.vue | 3 +- .../vue/src/components/field/useTextField.ts | 7 +- packages/vue/src/components/label/Label.vue | 14 +-- .../vue/src/components/switch/SwitchGroup.vue | 23 ++--- packages/vue/src/index.ts | 10 +++ scripts/check-package.mjs | 4 +- tests/package/check-client.mjs | 68 +++++++++++--- tests/package/client-checks.json | 21 +++++ .../shared-styles-consumer-app/README.md | 13 +++ .../shared-styles-consumer-app/index.html | 12 +++ .../shared-styles-consumer-app/main.js | 85 ++++++++++++++++++ .../shared-styles-consumer-app/style.css | 35 ++++++++ tests/package/shared-styles-contract.ts | 55 ++++++++++++ tests/shared-field-styles.test.ts | 90 +++++++++++++++++++ 26 files changed, 538 insertions(+), 36 deletions(-) create mode 100644 packages/styles/base/base.css create mode 100644 tests/package/shared-styles-consumer-app/README.md create mode 100644 tests/package/shared-styles-consumer-app/index.html create mode 100644 tests/package/shared-styles-consumer-app/main.js create mode 100644 tests/package/shared-styles-consumer-app/style.css create mode 100644 tests/package/shared-styles-contract.ts create mode 100644 tests/shared-field-styles.test.ts diff --git a/apps/docs/components/description.md b/apps/docs/components/description.md index 6fec73e..29937c5 100644 --- a/apps/docs/components/description.md +++ b/apps/docs/components/description.md @@ -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` 文本颜色 diff --git a/apps/docs/components/field-error.md b/apps/docs/components/field-error.md index 6b25949..6411198 100644 --- a/apps/docs/components/field-error.md +++ b/apps/docs/components/field-error.md @@ -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 色 diff --git a/apps/docs/components/label.md b/apps/docs/components/label.md index d62b690..847e439 100644 --- a/apps/docs/components/label.md +++ b/apps/docs/components/label.md @@ -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` — 基础标签文本样式 diff --git a/apps/docs/components/switch.md b/apps/docs/components/switch.md index 5401699..acd66da 100644 --- a/apps/docs/components/switch.md +++ b/apps/docs/components/switch.md @@ -182,6 +182,8 @@ SwitchGroup 组件使用以下 CSS 类([查看源码样式](https://github.com - `.hv-switch-group--horizontal` - 横向布局 - `.hv-switch-group--vertical` - 纵向布局(默认) +> 变体映射 `switchGroupVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `SwitchGroupVariants` 类型),提供 `base` / `items` 两个槽;组件渲染的类名由该映射生成。 + ### 交互状态 该 Switch 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制: diff --git a/apps/docs/components/text-field.md b/apps/docs/components/text-field.md index 06de43b..21a5cf3 100644 --- a/apps/docs/components/text-field.md +++ b/apps/docs/components/text-field.md @@ -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 类与样式,定制方式请参见对应文档。 ### 交互状态 diff --git a/apps/docs/styling.md b/apps/docs/styling.md index 20cdd62..dfc74aa 100644 --- a/apps/docs/styling.md +++ b/apps/docs/styling.md @@ -115,6 +115,22 @@ React 的函数式 `className` / `style` 和 render props 不直接用于 Vue。 库 CSS 使用 `theme, base, components, utilities` 层顺序。需要确保覆盖优先级时,应检查实际层、选择器与导入顺序;无层的应用 CSS 会优先于普通有层规则。Vue scoped 样式触及嵌套部件时使用 `:deep()` 或直接给该部件添加类,不在文档壳中隐藏组件问题。 +库的基础层还提供全局边框色回退(与固定源一致): + +```css +*, +::after, +::before, +::backdrop, +::file-selector-button { + border-color: var(--border, currentColor); +} +``` + +没有显式 `border-color` 的边框默认使用主题的 `--border`(未定义时回退 `currentColor`)。该规则位于 `base` 层且不带 `!important`,组件规则、工具类与调用方 CSS 都能正常覆盖它;显式边框色(包括 `transparent` 的字段边框)不受影响。 + +组件与类名的变体映射从 `@heroui-vue/styles` 公开(`buttonVariants`、`labelVariants`、`descriptionVariants`、`fieldErrorVariants`、`textFieldVariants`、`switchGroupVariants` 等),`@heroui-vue/components` 再导出同一组函数与 `*Variants` 类型;组件内部消费的也是这些映射,状态类只有这一处来源。 + ## 创建包装组件 使用公开 Props 类型与 `tv` 扩展变体。包装组件需要显式管理 `$attrs`、插槽、事件和需要公开的方法,不能把 DOM `ref` 当作普通属性传递。 diff --git a/docs/compatibility.md b/docs/compatibility.md index 336f476..a75bc0b 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -290,3 +290,7 @@ ComboBox/Autocomplete的正式组合、原30项返修和本轮定位/ref/ARIA/lo 固定源六篇56章节的实现证据与差异见 [Handbook审计](handbook-audit.md)。修复 data-scrollbar 三模式、八类浮层/Skeleton/Drawer 的减少动效与动态取消动画后的进入标记清理。按需 CSS 子路径、公共 useTheme、局部主题自动跨 Teleport 及 Skeleton 动画变量的局部/动态读取仍未提供;不声明所有组件已完成全部规范的浏览器验收。逐项场景与实际验证见 [任务结果](tasks/results/HANDBOOK-IMPLEMENTATION-AUDIT.md)。 HD-01(2026-10-28):按钮/切换组与导航示例已恢复固定cn基线;ButtonGroup内Dropdown保留根attrs/事件,以容器位置适配接缝。HD01-R1已关闭;不升级整族API兼容状态,详见[结果](tasks/results/HD-01-BUTTON-NAV-DEMOS.md)。 + +## HD-05 styles 导出与全局边框回退(2026-10-28) + +`@heroui-vue/styles` 增量补齐固定源缺失的 5 个 tv 映射与类型:`labelVariants`/`descriptionVariants`/`fieldErrorVariants`/`textFieldVariants`/`switchGroupVariants`(hv- 命名空间,变体集合与默认值与 `heroui/packages/styles/src/components/{label,description,field-error,textfield,switch-group}/*.styles.ts` 逐键一致),`@heroui-vue/components` 再导出同一组函数与 `*Variants` 类型。Label/Description/FieldError/useTextField/SwitchGroup 改为消费同一映射,状态类只保留一处来源,渲染类输出不变(tests/shared-field-styles.test.ts 钉住映射输出与组件输出一致)。恢复 `base` 层全局边框色回退 `border-color: var(--border, currentColor)`(与固定源 base/base.css 同选择器、同层序:preflight 之后);独立 tarball 消费者真实浏览器验证浅/深 `--border`、显式边框色(含字段透明边框)、调用方普通 CSS 覆盖(含与库同选择器的注入规则)与 `--border` 缺失时的 currentColor 回退,CSSOM 确认规则位于 base 层且无 `!important`。`view-transition-name`/`::view-transition` 两条上游全局规则经核查无使用证据(库与文档站均未使用 View Transitions API),不迁移、不建专项。chip `size:"md"`、kbd `variant:"default"` 等效默认类、reduced-motion、Spinner 定尺、Table th 行头、定位补偿与 HD-01~HD-04 成果均未改动。见 [任务结果](tasks/results/HD-05-STYLES.md)。 diff --git a/docs/upstream.md b/docs/upstream.md index 64c8ac8..caa3285 100644 --- a/docs/upstream.md +++ b/docs/upstream.md @@ -356,3 +356,8 @@ CSS/tv 仅加 `hv-` 前缀与 Apache-2.0 来源;`colorPickerVariants` 保持 ## HD-01 示例与 Dropdown 组合(2026-10-28) Button/ButtonGroup/ToggleButton/ToggleButtonGroup与指定Accordion/Disclosure示例按ce90ea3的cn源码恢复,保留Tabler图标适配。Vue Dropdown根容器承载attrs/原生事件;ButtonGroup CSS增加仅作用于标记直接成员的位置规则,圆角/outline数值沿用基线,来源许可保留。行为和证据见HD-01任务结果。 + +## HD-05 来源(2026-10-28) + +- packages/styles/src/index.ts 的 `labelVariants`/`descriptionVariants`/`fieldErrorVariants`/`textFieldVariants`/`switchGroupVariants`:移植 `heroui/packages/styles/src/components/{label/label,description/description,field-error/field-error,textfield/textfield,switch-group/switch-group}.styles.ts`,仅加 `hv-` 前缀;变体键、默认值与 slot 集合逐键保留(Apache-2.0,见 third-party/HEROUI-LICENSE)。 +- packages/styles/base/base.css:移植 `heroui/packages/styles/base/base.css` 的边框色继承规则(`*, ::after, ::before, ::backdrop, ::file-selector-button { border-color: var(--border, currentColor) }`),导入序保持 preflight 之后的 base 层。同文件的 `:root { view-transition-name: none }` 与 `::view-transition { pointer-events: none }` 未移植:库与文档站均无 View Transitions API 使用证据,按 HD-05 约定记录无需修改,不建立专项。 diff --git a/packages/styles/base/base.css b/packages/styles/base/base.css new file mode 100644 index 0000000..42597bc --- /dev/null +++ b/packages/styles/base/base.css @@ -0,0 +1,17 @@ +/* Adapted from HeroUI ce90ea3, packages/styles/base/base.css. + * Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE. */ + +/* Border color inheritance + * + * Every border without an explicit color resolves to the theme border token + * instead of `currentColor`. This lives in the base layer right after + * Tailwind preflight, so component rules (components layer), utilities and + * consumer CSS all override it normally — no !important required. When + * `--border` is undefined the declaration falls back to `currentColor`. */ +*, +::after, +::before, +::backdrop, +::file-selector-button { + border-color: var(--border, currentColor); +} diff --git a/packages/styles/index.css b/packages/styles/index.css index a8e072c..38a48ef 100644 --- a/packages/styles/index.css +++ b/packages/styles/index.css @@ -1,6 +1,9 @@ @layer theme, base, components, utilities; @import "tailwindcss/theme.css" layer(theme); @import "tailwindcss/preflight.css" layer(base); +/* Base defaults follow preflight so they win same-layer ties (border color + * fallback); upstream keeps them in base/base.css in the same order. */ +@import "./base/base.css" layer(base); @import "./themes/shared/theme.css"; @import "./themes/default/variables.css"; /* Mode overrides must follow theme defaults so an explicit mode on a theme root wins. */ diff --git a/packages/styles/src/index.ts b/packages/styles/src/index.ts index 4a3e61b..093ed98 100644 --- a/packages/styles/src/index.ts +++ b/packages/styles/src/index.ts @@ -119,6 +119,28 @@ export const switchVariants = tv({ export type SwitchVariants = VariantProps; +export const switchGroupVariants = tv({ + defaultVariants: { + orientation: "vertical", + }, + slots: { + base: "hv-switch-group", + items: "hv-switch-group__items", + }, + variants: { + orientation: { + horizontal: { + base: "hv-switch-group--horizontal", + }, + vertical: { + base: "hv-switch-group--vertical", + }, + }, + }, +}); + +export type SwitchGroupVariants = VariantProps; + export { tv, cn, type VariantProps } from "tailwind-variants"; export const closeButtonVariants = tv({ @@ -199,6 +221,21 @@ export const textAreaVariants = tv({ export type TextAreaVariants = VariantProps; +export const textFieldVariants = tv({ + base: "hv-textfield", + defaultVariants: { + fullWidth: false, + }, + variants: { + fullWidth: { + false: "", + true: "hv-textfield--full-width", + }, + }, +}); + +export type TextFieldVariants = VariantProps; + export const avatarVariants = tv({ defaultVariants: { color: "default", @@ -1746,6 +1783,40 @@ export const errorMessageVariants = tv({ export type ErrorMessageVariants = VariantProps; +export const labelVariants = tv({ + base: "hv-label", + defaultVariants: { + isDisabled: false, + isInvalid: false, + isRequired: false, + }, + variants: { + isDisabled: { + true: "hv-label--disabled", + }, + isInvalid: { + true: "hv-label--invalid", + }, + isRequired: { + true: "hv-label--required", + }, + }, +}); + +export type LabelVariants = VariantProps; + +export const descriptionVariants = tv({ + base: "hv-description", +}); + +export type DescriptionVariants = VariantProps; + +export const fieldErrorVariants = tv({ + base: "hv-field-error", +}); + +export type FieldErrorVariants = VariantProps; + export const comboBoxVariants = tv({ defaultVariants: { fullWidth: false, diff --git a/packages/vue/src/components/description/Description.vue b/packages/vue/src/components/description/Description.vue index 5999b68..f64cd39 100644 --- a/packages/vue/src/components/description/Description.vue +++ b/packages/vue/src/components/description/Description.vue @@ -1,12 +1,18 @@ diff --git a/packages/vue/src/components/field/FieldError.vue b/packages/vue/src/components/field/FieldError.vue index 6c2a942..3f39d4e 100644 --- a/packages/vue/src/components/field/FieldError.vue +++ b/packages/vue/src/components/field/FieldError.vue @@ -1,5 +1,6 @@