feat: add Typography EmptyState and Breadcrumbs

This commit is contained in:
maoyingjie
2026-10-22 13:07:13 +08:00
parent bcadbeaf8c
commit e4d817ce55
50 changed files with 3130 additions and 90 deletions
@@ -0,0 +1,31 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
/* Base breadcrumbs container */
.hv-breadcrumbs {
@apply flex items-center gap-1.5;
/* Breadcrumb link */
.hv-breadcrumbs__link {
@apply relative text-sm leading-5 font-medium text-muted no-underline opacity-100;
&:hover,
&[data-hovered="true"] {
@apply underline;
}
&[data-current="true"] {
@apply text-link opacity-100;
}
}
/* Breadcrumb item wrapper */
.hv-breadcrumbs__item {
@apply flex shrink-0 items-center justify-center gap-1;
}
/* Separator icon */
.hv-breadcrumbs__separator {
@apply size-3 text-muted rtl:rotate-180;
}
}
@@ -0,0 +1,7 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
/* Base empty-state styles */
.hv-empty-state {
@apply p-2 text-sm text-muted;
}
+166
View File
@@ -0,0 +1,166 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
.hv-typography {
@apply text-foreground;
}
.hv-typography-prose {
@apply text-foreground;
}
.hv-typography-prose h1 {
@apply text-4xl font-semibold tracking-tight;
}
.hv-typography-prose h2 {
@apply text-3xl font-semibold tracking-tight;
}
.hv-typography-prose h3 {
@apply text-2xl font-semibold tracking-tight;
}
.hv-typography-prose h4 {
@apply text-xl font-semibold tracking-tight;
}
.hv-typography-prose h5 {
@apply text-lg font-semibold tracking-tight;
}
.hv-typography-prose h6 {
@apply text-base font-semibold tracking-tight;
}
.hv-typography-prose p {
@apply text-base leading-7;
}
.hv-typography-prose code {
@apply rounded-md bg-default px-1.5 py-0.5 font-mono text-sm text-foreground;
}
.hv-typography-prose a {
@apply font-medium text-link underline underline-offset-4;
}
.hv-typography-prose blockquote {
@apply mt-4 border-s-4 border-border ps-4 text-muted italic;
}
.hv-typography-prose ul {
@apply my-4 list-disc space-y-2 ps-6;
}
.hv-typography-prose ol {
@apply my-4 list-decimal space-y-2 ps-6;
}
.hv-typography-prose li {
@apply text-base leading-7;
}
.hv-typography-prose hr {
@apply my-8 border-separator;
}
.hv-typography-prose pre {
@apply my-4 overflow-x-auto rounded-xl bg-default p-4 font-mono text-sm leading-relaxed;
}
.hv-typography-prose strong {
@apply font-semibold text-foreground;
}
.hv-typography-prose em {
@apply italic;
}
.hv-typography-prose img {
@apply my-4 rounded-xl;
}
.hv-typography--h1 {
@apply text-4xl font-semibold tracking-tight;
}
.hv-typography--h2 {
@apply text-3xl font-semibold tracking-tight;
}
.hv-typography--h3 {
@apply text-2xl font-semibold tracking-tight;
}
.hv-typography--h4 {
@apply text-xl font-semibold tracking-tight;
}
.hv-typography--h5 {
@apply text-lg font-semibold tracking-tight;
}
.hv-typography--h6 {
@apply text-base font-semibold tracking-tight;
}
.hv-typography--body {
@apply text-base leading-7;
}
.hv-typography--body-sm {
@apply text-sm leading-6;
}
.hv-typography--body-xs {
@apply text-xs leading-5;
}
.hv-typography--code {
@apply rounded-md bg-default px-1.5 py-0.5 font-mono text-sm text-foreground;
}
.hv-typography--align-start {
@apply text-start;
}
.hv-typography--align-center {
@apply text-center;
}
.hv-typography--align-end {
@apply text-end;
}
.hv-typography--align-justify {
@apply text-justify;
}
.hv-typography--color-default {
@apply text-foreground;
}
.hv-typography--color-muted {
@apply text-muted;
}
.hv-typography--truncate {
@apply block truncate;
}
.hv-typography--weight-normal {
@apply font-normal;
}
.hv-typography--weight-medium {
@apply font-medium;
}
.hv-typography--weight-semibold {
@apply font-semibold;
}
.hv-typography--weight-bold {
@apply font-bold;
}
+8
View File
@@ -15,6 +15,10 @@
@import "./components/label.css" layer(components);
@import "./components/description.css" layer(components);
@import "./components/surface.css" layer(components);
/* Keep breadcrumbs before link.css, matching the baseline component order.
* Breadcrumb link rules then override Link defaults, while Link's disabled
* rule still applies to non-current breadcrumb links. */
@import "./components/breadcrumbs.css" layer(components);
@import "./components/link.css" layer(components);
@import "./components/spinner.css" layer(components);
@import "./components/avatar.css" layer(components);
@@ -65,6 +69,10 @@
@import "./components/search-field.css" layer(components);
@import "./components/typography.css" layer(components);
@import "./components/empty-state.css" layer(components);
/* Vue disabled scopes preserve native first-legend semantics. A label in the
* exempt legend must not pick up the baseline blanket ancestor opacity rule.
* Local and outer disabled labels still carry hv-label--disabled. */
+64
View File
@@ -639,3 +639,67 @@ export const radioGroupVariants = tv({
});
export type RadioGroupVariants = VariantProps<typeof radioGroupVariants>;
export const typographyVariants = tv({
defaultVariants: {
align: "start",
color: "default",
type: "body",
},
slots: {
base: "hv-typography",
prose: "hv-typography-prose",
},
variants: {
align: {
center: "hv-typography--align-center",
end: "hv-typography--align-end",
justify: "hv-typography--align-justify",
start: "hv-typography--align-start",
},
color: {
default: "hv-typography--color-default",
muted: "hv-typography--color-muted",
},
truncate: {
true: "hv-typography--truncate",
},
type: {
body: "hv-typography--body",
"body-sm": "hv-typography--body-sm",
"body-xs": "hv-typography--body-xs",
code: "hv-typography--code",
h1: "hv-typography--h1",
h2: "hv-typography--h2",
h3: "hv-typography--h3",
h4: "hv-typography--h4",
h5: "hv-typography--h5",
h6: "hv-typography--h6",
},
weight: {
bold: "hv-typography--weight-bold",
medium: "hv-typography--weight-medium",
normal: "hv-typography--weight-normal",
semibold: "hv-typography--weight-semibold",
},
},
});
export type TypographyVariants = VariantProps<typeof typographyVariants>;
export const breadcrumbsVariants = tv({
slots: {
base: "hv-breadcrumbs",
item: "hv-breadcrumbs__item",
link: "hv-breadcrumbs__link",
separator: "hv-breadcrumbs__separator",
},
});
export type BreadcrumbsVariants = VariantProps<typeof breadcrumbsVariants>;
export const emptyStateVariants = tv({
base: "hv-empty-state",
});
export type EmptyStateVariants = VariantProps<typeof emptyStateVariants>;
@@ -0,0 +1,95 @@
<script lang="ts">
import {
Fragment,
cloneVNode,
defineComponent,
h,
isVNode,
provide,
useAttrs,
type VNode,
type VNodeChild,
} from "vue";
import { breadcrumbsVariants } from "@heroui-vue/styles";
import { disabledContextKey, useInheritedDisabled } from "../field/disabled";
import BreadcrumbsItem from "./BreadcrumbsItem.vue";
function flattenChildren(
nodes: VNodeChild[],
out: VNodeChild[] = [],
): VNodeChild[] {
for (const child of nodes) {
if (Array.isArray(child)) {
flattenChildren(child, out);
continue;
}
if (
isVNode(child) &&
child.type === Fragment &&
Array.isArray(child.children)
) {
flattenChildren(child.children as VNodeChild[], out);
continue;
}
out.push(child);
}
return out;
}
function isBreadcrumbsItem(node: VNodeChild): node is VNode {
return isVNode(node) && node.type === BreadcrumbsItem;
}
export default defineComponent({
name: "Breadcrumbs",
inheritAttrs: false,
props: {
ariaLabel: {
type: String,
default: "Breadcrumbs",
},
isDisabled: {
type: Boolean,
default: false,
},
/** Render the list as a custom element instead of `ol`. */
as: {
type: String,
default: "ol",
},
},
setup(props, { attrs, slots }) {
const variants = breadcrumbsVariants();
// Merge with ancestor Fieldset/disabled scopes; never shadow parent true.
const disabled = useInheritedDisabled(() => props.isDisabled);
provide(disabledContextKey, disabled);
function render() {
const nodes = flattenChildren((slots.default?.() ?? []) as VNodeChild[]);
const total = nodes.filter(isBreadcrumbsItem).length;
let index = 0;
const children = nodes.map((node) => {
if (!isBreadcrumbsItem(node)) return node;
const isLast = ++index === total;
return cloneVNode(node, {
isLast,
separatorSlot: slots.separator,
});
});
return h(
props.as,
{
...attrs,
class: [variants.base(), attrs.class],
"aria-label": props.ariaLabel || "Breadcrumbs",
"data-slot": "breadcrumbs",
},
children,
);
}
return render;
},
});
</script>
@@ -0,0 +1,187 @@
<script lang="ts">
import {
Comment,
Fragment,
Text,
cloneVNode,
defineComponent,
h,
isVNode,
useAttrs,
type PropType,
type VNodeChild,
} from "vue";
import { breadcrumbsVariants } from "@heroui-vue/styles";
import { useInheritedDisabled } from "../field/disabled";
import Link from "../link/Link.vue";
import BreadcrumbsSeparatorIcon from "./BreadcrumbsSeparatorIcon.vue";
function flattenChildren(
nodes: VNodeChild[],
out: VNodeChild[] = [],
): VNodeChild[] {
for (const child of nodes) {
if (Array.isArray(child)) {
flattenChildren(child, out);
continue;
}
if (
isVNode(child) &&
child.type === Fragment &&
Array.isArray(child.children)
) {
flattenChildren(child.children as VNodeChild[], out);
continue;
}
out.push(child);
}
return out;
}
function isMeaningful(node: VNodeChild): boolean {
if (node == null || node === false || node === true) return false;
if (typeof node === "string") return node.trim() !== "";
if (typeof node === "number") return true;
if (!isVNode(node)) return true;
if (node.type === Comment) return false;
if (node.type === Text) return String(node.children ?? "").trim() !== "";
return true;
}
function toArray(content: VNodeChild): VNodeChild[] {
if (content == null || content === false || content === true) return [];
return Array.isArray(content) ? content : [content];
}
export default defineComponent({
name: "BreadcrumbsItem",
inheritAttrs: false,
props: {
href: {
type: String,
default: undefined,
},
target: {
type: String,
default: "_self",
},
rel: {
type: String,
default: undefined,
},
download: {
type: [Boolean, String] as PropType<boolean | string>,
default: undefined,
},
isDisabled: {
type: Boolean,
default: false,
},
/** Set by Breadcrumbs for the final item. */
isLast: {
type: Boolean,
default: false,
},
/** Set by Breadcrumbs from the `separator` slot. */
separatorSlot: {
type: Function as PropType<() => VNodeChild>,
default: undefined,
},
/** Render the item as a custom element instead of `li`. */
as: {
type: String,
default: "li",
},
},
setup(props, { attrs, slots }) {
const variants = breadcrumbsVariants();
const disabled = useInheritedDisabled(
() => props.isDisabled || props.isLast,
);
function renderSeparator(): VNodeChild {
const nodes = flattenChildren(
toArray(props.separatorSlot?.() as VNodeChild),
);
const meaningful = nodes.filter(isMeaningful);
if (meaningful.length === 0) {
return h(BreadcrumbsSeparatorIcon, {
class: variants.separator(),
"data-slot": "breadcrumbs-separator",
});
}
if (meaningful.length === 1 && isVNode(meaningful[0])) {
return cloneVNode(meaningful[0], {
class: variants.separator(),
"data-slot": "breadcrumbs-separator",
});
}
return meaningful;
}
function render() {
const current = props.isLast;
// RAC Link renders a span when disabled or when no href is provided.
const nonNavigable = current || disabled.value || !props.href;
const callerClass = attrs.class;
const rootAttrs: Record<string, unknown> = {};
const linkAttrs: Record<string, unknown> = {};
for (const [key, value] of Object.entries(attrs)) {
if (key === "class") continue;
if (/^on[A-Z]/.test(key)) linkAttrs[key] = value;
else rootAttrs[key] = value;
}
const content =
slots.default?.({
isCurrent: current,
isDisabled: disabled.value,
}) ?? [];
const link = h(
Link,
{
// Reka Primitive picks the Slot/element branch once in setup.
// A stable key per structural mode remounts Link when switching
// between navigable <a> and non-navigable <span>.
key: nonNavigable
? "breadcrumbs-link-static"
: "breadcrumbs-link-nav",
...linkAttrs,
asChild: nonNavigable,
...(current ? { "aria-current": "page" } : {}),
...(current ? { "data-current": "true" } : {}),
...(disabled.value ? { "data-disabled": "true" } : {}),
...(nonNavigable ? {} : { href: props.href }),
...(nonNavigable ? {} : { target: props.target }),
...(nonNavigable ? {} : { rel: props.rel }),
...(nonNavigable ? {} : { download: props.download }),
isDisabled: current || disabled.value,
class: [variants.link(), callerClass],
},
{
default: () => (nonNavigable ? h("span", content) : content),
},
);
return h(
props.as,
{
...rootAttrs,
class: [variants.item(), callerClass],
"data-slot": "breadcrumbs-item",
"data-current": current ? "true" : undefined,
"data-disabled": disabled.value ? "true" : undefined,
},
[link, current ? null : renderSeparator()],
);
}
return render;
},
});
</script>
@@ -0,0 +1,18 @@
<template>
<svg
aria-hidden="true"
fill="none"
height="16"
role="presentation"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M5.47 2.97a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 1 1-1.06-1.06L9.44 8 5.47 4.03a.75.75 0 0 1 0-1.06Z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</template>
@@ -0,0 +1,79 @@
<script lang="ts">
import {
Comment,
Fragment,
Text,
defineComponent,
h,
isVNode,
type VNodeChild,
} from "vue";
import { emptyStateVariants } from "@heroui-vue/styles";
function flattenChildren(
nodes: VNodeChild[],
out: VNodeChild[] = [],
): VNodeChild[] {
for (const child of nodes) {
if (Array.isArray(child)) {
flattenChildren(child, out);
continue;
}
if (
isVNode(child) &&
child.type === Fragment &&
Array.isArray(child.children)
) {
flattenChildren(child.children as VNodeChild[], out);
continue;
}
out.push(child);
}
return out;
}
function isMeaningful(node: VNodeChild): boolean {
if (node == null || node === false || node === true) return false;
if (typeof node === "string") return node.trim() !== "";
if (typeof node === "number") return true;
if (!isVNode(node)) return true;
if (node.type === Comment) return false;
if (node.type === Text) return String(node.children ?? "").trim() !== "";
return true;
}
export default defineComponent({
name: "EmptyState",
inheritAttrs: false,
props: {
/** Render a custom root element instead of `div`. */
as: {
type: String,
default: "div",
},
},
setup(props, { attrs, slots }) {
/** Re-read the slot each render so conditional content updates its fallback. */
function render() {
const children = flattenChildren(
(slots.default?.() ?? []) as VNodeChild[],
);
const content: VNodeChild[] = children.some(isMeaningful)
? children
: ["No results found"];
return h(
props.as,
{
...attrs,
class: [emptyStateVariants(), attrs.class],
"data-slot": "empty-state",
},
content,
);
}
return render;
},
});
</script>
+1 -1
View File
@@ -259,7 +259,7 @@ defineExpose({
:as-child="asChild"
v-bind="passthroughAttrs"
:href="href"
:target="target"
:target="href ? target : undefined"
:rel="rel"
:download="downloadAttr"
:class="slots.base()"
@@ -0,0 +1,68 @@
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import {
typographyVariants,
type TypographyVariants,
} from "@heroui-vue/styles";
defineOptions({ inheritAttrs: false });
type TypographyType = NonNullable<TypographyVariants["type"]>;
const props = withDefaults(
defineProps<{
type?: TypographyType;
align?: NonNullable<TypographyVariants["align"]>;
color?: NonNullable<TypographyVariants["color"]>;
weight?: TypographyVariants["weight"];
truncate?: boolean;
/** Render a different element while keeping the visual type. */
as?: string;
}>(),
{
type: "body",
align: "start",
color: "default",
truncate: false,
},
);
const defaultElementByType: Record<TypographyType, string> = {
body: "p",
"body-sm": "p",
"body-xs": "p",
code: "code",
h1: "h1",
h2: "h2",
h3: "h3",
h4: "h4",
h5: "h5",
h6: "h6",
};
const attrs = useAttrs();
const element = computed(() => props.as ?? defaultElementByType[props.type]);
const baseClass = computed(() =>
typographyVariants({
align: props.align,
color: props.color,
truncate: props.truncate,
type: props.type,
weight: props.weight,
}).base(),
);
</script>
<template>
<component
:is="element"
v-bind="attrs"
:class="baseClass"
data-slot="typography"
:data-type="type"
>
<slot />
</component>
</template>
@@ -0,0 +1,35 @@
<script setup lang="ts">
import type { TypographyVariants } from "@heroui-vue/styles";
import Typography from "./Typography.vue";
defineOptions({ inheritAttrs: false });
withDefaults(
defineProps<{
align?: NonNullable<TypographyVariants["align"]>;
color?: NonNullable<TypographyVariants["color"]>;
weight?: TypographyVariants["weight"];
truncate?: boolean;
as?: string;
}>(),
{
align: "start",
color: "default",
truncate: false,
},
);
</script>
<template>
<Typography
v-bind="$attrs"
type="code"
:align="align"
:color="color"
:weight="weight"
:truncate="truncate"
:as="as"
>
<slot />
</Typography>
</template>
@@ -0,0 +1,42 @@
<script setup lang="ts">
import { computed } from "vue";
import type { TypographyVariants } from "@heroui-vue/styles";
import Typography from "./Typography.vue";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
level?: 1 | 2 | 3 | 4 | 5 | 6;
align?: NonNullable<TypographyVariants["align"]>;
color?: NonNullable<TypographyVariants["color"]>;
weight?: TypographyVariants["weight"];
truncate?: boolean;
as?: string;
}>(),
{
level: 1,
align: "start",
color: "default",
truncate: false,
},
);
const type = computed(
() => `h${props.level}` as NonNullable<TypographyVariants["type"]>,
);
</script>
<template>
<Typography
v-bind="$attrs"
:type="type"
:align="align"
:color="color"
:weight="weight"
:truncate="truncate"
:as="as"
>
<slot />
</Typography>
</template>
@@ -0,0 +1,47 @@
<script setup lang="ts">
import { computed } from "vue";
import type { TypographyVariants } from "@heroui-vue/styles";
import Typography from "./Typography.vue";
defineOptions({ inheritAttrs: false });
type ParagraphSize = "base" | "sm" | "xs";
const props = withDefaults(
defineProps<{
size?: ParagraphSize;
align?: NonNullable<TypographyVariants["align"]>;
color?: NonNullable<TypographyVariants["color"]>;
weight?: TypographyVariants["weight"];
truncate?: boolean;
as?: string;
}>(),
{
size: "base",
align: "start",
color: "default",
truncate: false,
},
);
const type = computed(
() =>
(props.size === "base" ? "body" : `body-${props.size}`) as NonNullable<
TypographyVariants["type"]
>,
);
</script>
<template>
<Typography
v-bind="$attrs"
:type="type"
:align="align"
:color="color"
:weight="weight"
:truncate="truncate"
:as="as"
>
<slot />
</Typography>
</template>
@@ -0,0 +1,15 @@
<script setup lang="ts">
import { useAttrs } from "vue";
import { typographyVariants } from "@heroui-vue/styles";
defineOptions({ inheritAttrs: false });
const attrs = useAttrs();
const slots = typographyVariants();
</script>
<template>
<div v-bind="attrs" :class="slots.prose()" data-slot="prose">
<slot />
</div>
</template>
+29
View File
@@ -262,3 +262,32 @@ export {
type RadioVariants,
type RadioGroupVariants,
} from "@heroui-vue/styles";
export { default as Typography } from "./components/typography/Typography.vue";
export { default as TypographyHeading } from "./components/typography/TypographyHeading.vue";
export { default as TypographyParagraph } from "./components/typography/TypographyParagraph.vue";
export { default as TypographyCode } from "./components/typography/TypographyCode.vue";
export { default as TypographyProse } from "./components/typography/TypographyProse.vue";
export type {
TypographyProps,
TypographyHeadingProps,
TypographyParagraphProps,
TypographyCodeProps,
TypographyProseProps,
} from "./types";
export { default as EmptyState } from "./components/empty-state/EmptyState.vue";
export type { EmptyStateProps } from "./types";
export { default as Breadcrumbs } from "./components/breadcrumbs/Breadcrumbs.vue";
export { default as BreadcrumbsItem } from "./components/breadcrumbs/BreadcrumbsItem.vue";
export type { BreadcrumbsProps, BreadcrumbsItemProps } from "./types";
export {
typographyVariants,
breadcrumbsVariants,
emptyStateVariants,
type TypographyVariants,
type BreadcrumbsVariants,
type EmptyStateVariants,
} from "@heroui-vue/styles";
+28
View File
@@ -119,6 +119,34 @@ export type FieldsetActionsProps = InstanceType<
import type SearchField from "./components/search-field/SearchField.vue";
export type SearchFieldProps = InstanceType<typeof SearchField>["$props"];
import type Typography from "./components/typography/Typography.vue";
import type TypographyHeading from "./components/typography/TypographyHeading.vue";
import type TypographyParagraph from "./components/typography/TypographyParagraph.vue";
import type TypographyCode from "./components/typography/TypographyCode.vue";
import type TypographyProse from "./components/typography/TypographyProse.vue";
import type EmptyState from "./components/empty-state/EmptyState.vue";
import type Breadcrumbs from "./components/breadcrumbs/Breadcrumbs.vue";
import type BreadcrumbsItem from "./components/breadcrumbs/BreadcrumbsItem.vue";
export type TypographyProps = InstanceType<typeof Typography>["$props"];
export type TypographyHeadingProps = InstanceType<
typeof TypographyHeading
>["$props"];
export type TypographyParagraphProps = InstanceType<
typeof TypographyParagraph
>["$props"];
export type TypographyCodeProps = InstanceType<typeof TypographyCode>["$props"];
export type TypographyProseProps = InstanceType<
typeof TypographyProse
>["$props"];
export type EmptyStateProps = InstanceType<typeof EmptyState>["$props"];
export type BreadcrumbsProps = InstanceType<typeof Breadcrumbs>["$props"];
/** Public item props; Root injects `isLast` / `separatorSlot` internally. */
export type BreadcrumbsItemProps = Omit<
InstanceType<typeof BreadcrumbsItem>["$props"],
"isLast" | "separatorSlot"
>;
import type SearchFieldGroup from "./components/search-field/SearchFieldGroup.vue";
export type SearchFieldGroupProps = InstanceType<
typeof SearchFieldGroup