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.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import * as lib from "@heroui-vue/components";
|
||||
import * as stylesLib from "@heroui-vue/styles";
|
||||
|
||||
const checks = JSON.parse(
|
||||
readFileSync(new URL("./client-checks.json", import.meta.url), "utf8"),
|
||||
@@ -202,10 +203,7 @@ for (const id of process.argv.slice(2)) {
|
||||
assert(lib.ColorSwatchPickerSwatch);
|
||||
assert(lib.ColorSwatchPickerIndicator);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants()
|
||||
.base()
|
||||
.includes("hv-color-swatch-picker"),
|
||||
lib.colorSwatchPickerVariants().base().includes("hv-color-swatch-picker"),
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
@@ -214,19 +212,16 @@ for (const id of process.argv.slice(2)) {
|
||||
.includes("hv-color-swatch-picker--stack"),
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants({ size: "xs" })
|
||||
.item() === "hv-color-swatch-picker__item",
|
||||
lib.colorSwatchPickerVariants({ size: "xs" }).item() ===
|
||||
"hv-color-swatch-picker__item",
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants()
|
||||
.swatch() === "hv-color-swatch-picker__swatch",
|
||||
lib.colorSwatchPickerVariants().swatch() ===
|
||||
"hv-color-swatch-picker__swatch",
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.colorSwatchPickerVariants()
|
||||
.indicator() === "hv-color-swatch-picker__indicator",
|
||||
lib.colorSwatchPickerVariants().indicator() ===
|
||||
"hv-color-swatch-picker__indicator",
|
||||
);
|
||||
const pickerDts = readFileSync(
|
||||
new URL(
|
||||
@@ -360,5 +355,52 @@ for (const id of process.argv.slice(2)) {
|
||||
);
|
||||
}
|
||||
}
|
||||
if (id === "shared-styles") {
|
||||
// The five shared mappings are importable from both entry points and are
|
||||
// the same functions the components consume.
|
||||
for (const name of spec.exports)
|
||||
assert.equal(
|
||||
stylesLib[name],
|
||||
lib[name],
|
||||
`${name} must match styles entry`,
|
||||
);
|
||||
// Variant outputs must mirror the classes the components actually emit.
|
||||
assert.equal(lib.labelVariants(), "hv-label");
|
||||
assert.equal(
|
||||
lib.labelVariants({
|
||||
isRequired: false,
|
||||
isDisabled: false,
|
||||
isInvalid: false,
|
||||
}),
|
||||
"hv-label",
|
||||
);
|
||||
assert(
|
||||
lib.labelVariants({ isRequired: true }).includes("hv-label--required"),
|
||||
);
|
||||
assert(
|
||||
lib.labelVariants({ isDisabled: true }).includes("hv-label--disabled"),
|
||||
);
|
||||
assert(
|
||||
lib.labelVariants({ isInvalid: true }).includes("hv-label--invalid"),
|
||||
);
|
||||
assert.equal(lib.descriptionVariants(), "hv-description");
|
||||
assert.equal(lib.fieldErrorVariants(), "hv-field-error");
|
||||
assert(lib.textFieldVariants().includes("hv-textfield"));
|
||||
assert(!lib.textFieldVariants().includes("full-width"));
|
||||
assert(
|
||||
lib
|
||||
.textFieldVariants({ fullWidth: true })
|
||||
.includes("hv-textfield--full-width"),
|
||||
);
|
||||
const group = lib.switchGroupVariants();
|
||||
assert(group.base().includes("hv-switch-group--vertical"));
|
||||
assert.equal(group.items(), "hv-switch-group__items");
|
||||
assert(
|
||||
lib
|
||||
.switchGroupVariants({ orientation: "horizontal" })
|
||||
.base()
|
||||
.includes("hv-switch-group--horizontal"),
|
||||
);
|
||||
}
|
||||
console.log(`${id}: packed ESM exports and CSS passed (client scope)`);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,27 @@
|
||||
".hv-popover"
|
||||
]
|
||||
},
|
||||
"shared-styles": {
|
||||
"exports": [
|
||||
"labelVariants",
|
||||
"descriptionVariants",
|
||||
"fieldErrorVariants",
|
||||
"textFieldVariants",
|
||||
"switchGroupVariants"
|
||||
],
|
||||
"css": [
|
||||
"border-color:var(--border,currentColor)",
|
||||
".hv-label--required",
|
||||
".hv-label--disabled",
|
||||
".hv-label--invalid",
|
||||
".hv-description",
|
||||
".hv-field-error",
|
||||
".hv-textfield--full-width",
|
||||
".hv-switch-group__items",
|
||||
".hv-switch-group--horizontal",
|
||||
".hv-switch-group--vertical"
|
||||
]
|
||||
},
|
||||
"b01-menu-dropdown": {
|
||||
"exports": [
|
||||
"DropdownRoot",
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# Shared styles 独立产物验收(styles 导出与全局边框回退)
|
||||
|
||||
先运行 `node scripts/check-package.mjs shared-styles`(可与受影响契约合跑)统一构建、打包、安装和类型验收;它会把本夹具放入独立消费者并打印路径和 Vite 命令。按输出显式选空闲端口启动,不另外复制安装流程;入口不会自动启动服务。main.js 只从包根/发布 CSS 导入,不用源码 alias、私有路径或 Vue 模板编译器。
|
||||
|
||||
在真实浏览器核对:
|
||||
|
||||
1. `#default-border`(无显式 border 颜色)的计算 `border-color` 等于当前主题的 `--border`(浅/深两值不同)。
|
||||
2. `#explicit-border` 的显式红边框不被全局回退覆盖。
|
||||
3. `#override-border` 的调用方普通 CSS(无 `!important`)覆盖生效;另在页面注入与库规则**同等选择器**的普通样式,验证库规则不是高优先级、不破坏消费者定制。
|
||||
4. `#fallback-border`(`--border: initial`)边框色回退为 `currentColor`(元素文字色)。
|
||||
5. `#component-border` 内 `.hv-input-otp__slot` 的显式 `var(--field-border)`(默认 transparent)不被全局回退覆盖;点 `#theme-toggle` 切深色后上述 `--border` 期望值同步变化。
|
||||
|
||||
记录计算样式实值与截图;不能因 CSS 文本包含 `var(--border` 就通过。类型正反例使用上级 `shared-styles-contract.ts` 的两种解析模式。
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Shared styles 独立产物验收</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,85 @@
|
||||
import { createApp, defineComponent, h, shallowRef } from "vue";
|
||||
import {
|
||||
Button,
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSlot,
|
||||
} from "@heroui-vue/components";
|
||||
import "@heroui-vue/styles/css";
|
||||
import "./style.css";
|
||||
|
||||
const theme = shallowRef("light");
|
||||
|
||||
const app = defineComponent({
|
||||
setup() {
|
||||
const toggleTheme = () => {
|
||||
theme.value = theme.value === "light" ? "dark" : "light";
|
||||
document.documentElement.dataset.theme = theme.value;
|
||||
};
|
||||
return () =>
|
||||
h("main", {}, [
|
||||
h(
|
||||
Button,
|
||||
{ id: "theme-toggle", variant: "secondary", onClick: toggleTheme },
|
||||
{ default: () => `主题:${theme.value}` },
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{
|
||||
id: "default-border",
|
||||
class: "box default-border",
|
||||
"data-testid": "default-border",
|
||||
},
|
||||
"默认边框(无显式颜色)",
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{
|
||||
id: "explicit-border",
|
||||
class: "box explicit-border",
|
||||
"data-testid": "explicit-border",
|
||||
},
|
||||
"显式 border 颜色",
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{
|
||||
id: "override-border",
|
||||
class: "box override-border",
|
||||
"data-testid": "override-border",
|
||||
},
|
||||
"调用方覆盖",
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{
|
||||
id: "fallback-border",
|
||||
class: "box fallback-border",
|
||||
"data-testid": "fallback-border",
|
||||
},
|
||||
"缺少 --border 时回退 currentColor",
|
||||
),
|
||||
h("div", { id: "component-border" }, [
|
||||
h(
|
||||
InputOTP,
|
||||
{ "aria-label": "验证码", "max-length": 4, modelValue: "" },
|
||||
{
|
||||
default: () =>
|
||||
h(
|
||||
InputOTPGroup,
|
||||
{},
|
||||
{
|
||||
default: () =>
|
||||
[0, 1, 2, 3].map((index) =>
|
||||
h(InputOTPSlot, { index, key: index }),
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
createApp(app).mount("#app");
|
||||
@@ -0,0 +1,35 @@
|
||||
/* Consumer-side CSS: plain unlayered rules must override the library's
|
||||
* base-layer border fallback without !important. */
|
||||
main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
padding: 32px;
|
||||
}
|
||||
|
||||
.box {
|
||||
padding: 8px;
|
||||
border-style: solid;
|
||||
border-width: 2px;
|
||||
}
|
||||
|
||||
/* 1. default border: no explicit color -> theme --border */
|
||||
.default-border {
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
/* 2. explicit color survives the global fallback */
|
||||
.explicit-border {
|
||||
border-color: rgb(200, 0, 0);
|
||||
}
|
||||
|
||||
/* 3. consumer override wins without !important */
|
||||
.override-border {
|
||||
border-color: rgb(0, 128, 0);
|
||||
}
|
||||
|
||||
/* 4. missing --border falls back to currentColor */
|
||||
.fallback-border {
|
||||
--border: initial;
|
||||
color: rgb(0, 0, 255);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
descriptionVariants,
|
||||
fieldErrorVariants,
|
||||
labelVariants,
|
||||
switchGroupVariants,
|
||||
textFieldVariants,
|
||||
type DescriptionVariants,
|
||||
type FieldErrorVariants,
|
||||
type LabelVariants,
|
||||
type SwitchGroupVariants,
|
||||
type TextFieldVariants,
|
||||
type VariantProps,
|
||||
} from "@heroui-vue/styles";
|
||||
import {
|
||||
labelVariants as componentsLabelVariants,
|
||||
type LabelVariants as ComponentsLabelVariants,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const required: LabelVariants = { isRequired: true, isDisabled: false };
|
||||
labelVariants(required);
|
||||
labelVariants({ isInvalid: true });
|
||||
descriptionVariants();
|
||||
fieldErrorVariants();
|
||||
const wide: TextFieldVariants = { fullWidth: true };
|
||||
textFieldVariants(wide);
|
||||
const horizontal: SwitchGroupVariants = { orientation: "horizontal" };
|
||||
switchGroupVariants(horizontal);
|
||||
switchGroupVariants({ orientation: "vertical" }).items();
|
||||
|
||||
// Components re-export the same mapping and type.
|
||||
const viaComponents: ComponentsLabelVariants = { isDisabled: true };
|
||||
componentsLabelVariants(viaComponents);
|
||||
|
||||
type Description = VariantProps<typeof descriptionVariants>;
|
||||
const base: Description = {};
|
||||
descriptionVariants(base);
|
||||
|
||||
// @ts-expect-error variant flags stay boolean-typed
|
||||
const badRequired: LabelVariants = { isRequired: "yes" };
|
||||
// @ts-expect-error unknown label variant keys stay rejected
|
||||
const badLabelKey: LabelVariants = { isDanger: true };
|
||||
// @ts-expect-error fullWidth stays boolean-typed
|
||||
const badWidth: TextFieldVariants = { fullWidth: "yes" };
|
||||
// @ts-expect-error orientation stays a closed union
|
||||
const badOrientation: SwitchGroupVariants = { orientation: "diagonal" };
|
||||
// @ts-expect-error the exported description shape stays non-nullable object-typed
|
||||
const badDescription: DescriptionVariants = null;
|
||||
// @ts-expect-error the exported field-error shape stays non-nullable object-typed
|
||||
const badFieldError: FieldErrorVariants = null;
|
||||
void badRequired;
|
||||
void badLabelKey;
|
||||
void badWidth;
|
||||
void badOrientation;
|
||||
void badDescription;
|
||||
void badFieldError;
|
||||
@@ -0,0 +1,90 @@
|
||||
import { expect, it, describe } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import {
|
||||
descriptionVariants,
|
||||
fieldErrorVariants,
|
||||
labelVariants,
|
||||
switchGroupVariants,
|
||||
textFieldVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
|
||||
import Label from "../packages/vue/src/components/label/Label.vue";
|
||||
import Description from "../packages/vue/src/components/description/Description.vue";
|
||||
import FieldError from "../packages/vue/src/components/field/FieldError.vue";
|
||||
import SwitchGroup from "../packages/vue/src/components/switch/SwitchGroup.vue";
|
||||
import {
|
||||
labelVariants as componentsLabelVariants,
|
||||
descriptionVariants as componentsDescriptionVariants,
|
||||
fieldErrorVariants as componentsFieldErrorVariants,
|
||||
textFieldVariants as componentsTextFieldVariants,
|
||||
switchGroupVariants as componentsSwitchGroupVariants,
|
||||
} from "../packages/vue/src";
|
||||
|
||||
describe("shared field style mappings", () => {
|
||||
it("mirror the pinned upstream variant sets and defaults", () => {
|
||||
expect(labelVariants()).toBe("hv-label");
|
||||
expect(labelVariants({ isRequired: true })).toContain("hv-label--required");
|
||||
expect(labelVariants({ isDisabled: true })).toContain("hv-label--disabled");
|
||||
expect(labelVariants({ isInvalid: true })).toContain("hv-label--invalid");
|
||||
expect(labelVariants({ isRequired: false })).toBe("hv-label");
|
||||
expect(descriptionVariants()).toBe("hv-description");
|
||||
expect(fieldErrorVariants()).toBe("hv-field-error");
|
||||
expect(textFieldVariants()).toContain("hv-textfield");
|
||||
expect(textFieldVariants()).not.toContain("full-width");
|
||||
expect(textFieldVariants({ fullWidth: true })).toContain(
|
||||
"hv-textfield--full-width",
|
||||
);
|
||||
const group = switchGroupVariants();
|
||||
expect(group.base()).toContain("hv-switch-group--vertical");
|
||||
expect(group.items()).toBe("hv-switch-group__items");
|
||||
expect(switchGroupVariants({ orientation: "horizontal" }).base()).toContain(
|
||||
"hv-switch-group--horizontal",
|
||||
);
|
||||
});
|
||||
|
||||
it("are re-exported unchanged from the components entry", () => {
|
||||
expect(componentsLabelVariants).toBe(labelVariants);
|
||||
expect(componentsDescriptionVariants).toBe(descriptionVariants);
|
||||
expect(componentsFieldErrorVariants).toBe(fieldErrorVariants);
|
||||
expect(componentsTextFieldVariants).toBe(textFieldVariants);
|
||||
expect(componentsSwitchGroupVariants).toBe(switchGroupVariants);
|
||||
});
|
||||
|
||||
it("components render exactly the shared mapping output for their states", () => {
|
||||
const label = mount(Label, {
|
||||
props: { isRequired: true, isInvalid: true },
|
||||
slots: { default: "名称" },
|
||||
attachTo: document.body,
|
||||
});
|
||||
expect(label.classes().sort()).toEqual(
|
||||
labelVariants({ isRequired: true, isInvalid: true }).split(" ").sort(),
|
||||
);
|
||||
label.unmount();
|
||||
|
||||
const description = mount(Description, {
|
||||
slots: { default: "说明" },
|
||||
attachTo: document.body,
|
||||
});
|
||||
expect(description.classes()).toEqual(descriptionVariants().split(" "));
|
||||
description.unmount();
|
||||
|
||||
const error = mount(FieldError, {
|
||||
slots: { default: "错误" },
|
||||
attachTo: document.body,
|
||||
});
|
||||
expect(error.classes()).toContain("hv-field-error");
|
||||
error.unmount();
|
||||
|
||||
const group = mount(SwitchGroup, {
|
||||
props: { orientation: "horizontal" },
|
||||
slots: { default: "选项" },
|
||||
attachTo: document.body,
|
||||
});
|
||||
const expected = switchGroupVariants({ orientation: "horizontal" });
|
||||
expect(group.classes().sort()).toEqual(expected.base().split(" ").sort());
|
||||
expect(group.find('[data-slot="switch-group-items"]').classes()).toEqual(
|
||||
expected.items().split(" "),
|
||||
);
|
||||
group.unmount();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user