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:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user