dc859fb8ae
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.
91 lines
3.5 KiB
TypeScript
91 lines
3.5 KiB
TypeScript
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();
|
|
});
|
|
});
|