feat: add CloseButton Avatar and Skeleton components
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
/* ==========================================================================
|
||||
AvatarGroup - Stacked or grid layout for multiple avatars
|
||||
========================================================================== */
|
||||
|
||||
.hv-avatar-group {
|
||||
--avatar-group-overlap: 0.5rem;
|
||||
--avatar-group-seam: 2px;
|
||||
|
||||
@apply inline-flex items-center;
|
||||
}
|
||||
|
||||
/* Grid */
|
||||
.hv-avatar-group--grid {
|
||||
@apply flex-wrap gap-3;
|
||||
}
|
||||
|
||||
.hv-avatar-group:not(.hv-avatar-group--grid) > .hv-avatar + .hv-avatar,
|
||||
.hv-avatar-group:not(.hv-avatar-group--grid)
|
||||
> .hv-avatar
|
||||
+ .hv-avatar-group__count {
|
||||
margin-inline-start: calc(-1 * var(--avatar-group-overlap, 0.5rem));
|
||||
}
|
||||
|
||||
.hv-avatar-group__count {
|
||||
@apply shrink-0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
Overlap: ring
|
||||
-------------------------------------------------------------------------- */
|
||||
.hv-avatar-group--ring:not(.hv-avatar-group--grid) > .hv-avatar,
|
||||
.hv-avatar-group--ring:not(.hv-avatar-group--grid) > .hv-avatar-group__count {
|
||||
position: relative;
|
||||
box-shadow: 0 0 0 var(--avatar-group-seam, 2px) var(--background);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
Overlap: clip
|
||||
Cut sits on the inline-end edge (LTR: right / RTL: left). Optical nudge uses
|
||||
padding-inline-end so fallback glyphs stay logical in both directions.
|
||||
-------------------------------------------------------------------------- */
|
||||
.hv-avatar-group--clip:not(.hv-avatar-group--grid)
|
||||
> .hv-avatar:not(:last-child) {
|
||||
--avatar-group-cut-center: calc(
|
||||
100% + (var(--avatar-size, 2.5rem) / 2) -
|
||||
var(--avatar-group-overlap, 0.5rem)
|
||||
);
|
||||
--avatar-group-cut-radius: calc(
|
||||
(var(--avatar-size, 2.5rem) / 2) + var(--avatar-group-seam, 2px)
|
||||
);
|
||||
|
||||
-webkit-mask-image: radial-gradient(
|
||||
circle at var(--avatar-group-cut-center) 50%,
|
||||
transparent var(--avatar-group-cut-radius),
|
||||
#000 var(--avatar-group-cut-radius)
|
||||
);
|
||||
mask-image: radial-gradient(
|
||||
circle at var(--avatar-group-cut-center) 50%,
|
||||
transparent var(--avatar-group-cut-radius),
|
||||
#000 var(--avatar-group-cut-radius)
|
||||
);
|
||||
}
|
||||
|
||||
.hv-avatar-group--clip:not(.hv-avatar-group--grid):dir(rtl)
|
||||
> .hv-avatar:not(:last-child),
|
||||
:dir(rtl)
|
||||
.hv-avatar-group--clip:not(.hv-avatar-group--grid)
|
||||
> .hv-avatar:not(:last-child) {
|
||||
--avatar-group-cut-center: calc(
|
||||
0% - (var(--avatar-size, 2.5rem) / 2) + var(--avatar-group-overlap, 0.5rem)
|
||||
);
|
||||
}
|
||||
|
||||
.hv-avatar-group--clip:not(.hv-avatar-group--grid)
|
||||
> .hv-avatar:not(:last-child)
|
||||
.hv-avatar__fallback {
|
||||
box-sizing: border-box;
|
||||
padding-inline-end: calc(var(--avatar-group-overlap, 0.5rem) * 0.35);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
/* Base avatar styles */
|
||||
.hv-avatar {
|
||||
@apply relative flex size-10 shrink-0 items-center justify-center overflow-hidden rounded-3xl bg-default;
|
||||
}
|
||||
|
||||
/* Avatar fallback element */
|
||||
.hv-avatar__fallback {
|
||||
@apply flex size-full items-center justify-center bg-default text-sm font-medium;
|
||||
}
|
||||
|
||||
/* Avatar image element */
|
||||
.hv-avatar__image {
|
||||
@apply absolute inset-0 aspect-square size-full;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
*/
|
||||
@apply transition-opacity duration-250 motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
/* Size modifiers */
|
||||
.hv-avatar--sm {
|
||||
--avatar-size: 2rem; /* size-8 */
|
||||
|
||||
@apply size-8 rounded-2xl;
|
||||
|
||||
.hv-avatar__fallback {
|
||||
@apply text-xs;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-avatar--md {
|
||||
--avatar-size: 2.5rem; /* size-10 — same as base */
|
||||
|
||||
/* No layout styles as this is the default size */
|
||||
}
|
||||
|
||||
.hv-avatar--lg {
|
||||
--avatar-size: 3rem; /* size-12 */
|
||||
|
||||
@apply size-12 rounded-3xl;
|
||||
|
||||
.hv-avatar__fallback {
|
||||
@apply text-base;
|
||||
}
|
||||
}
|
||||
|
||||
/* Color modifiers for fallback */
|
||||
.hv-avatar__fallback--accent {
|
||||
@apply text-accent-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-avatar__fallback--default {
|
||||
@apply text-default-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-avatar__fallback--success {
|
||||
@apply text-success-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-avatar__fallback--warning {
|
||||
@apply text-warning-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-avatar__fallback--danger {
|
||||
@apply text-danger-soft-foreground;
|
||||
}
|
||||
|
||||
/* Variant modifiers */
|
||||
.hv-avatar--soft {
|
||||
@apply bg-transparent;
|
||||
}
|
||||
|
||||
.hv-avatar--soft .hv-avatar__fallback--accent {
|
||||
@apply bg-accent-soft text-accent-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-avatar--soft .hv-avatar__fallback--success {
|
||||
@apply bg-success-soft text-success-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-avatar--soft .hv-avatar__fallback--warning {
|
||||
@apply bg-warning-soft text-warning-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-avatar--soft .hv-avatar__fallback--default {
|
||||
@apply bg-default-soft text-default-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-avatar--soft .hv-avatar__fallback--danger {
|
||||
@apply bg-danger-soft text-danger-soft-foreground;
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
.hv-skeleton {
|
||||
@apply pointer-events-none relative overflow-hidden rounded-sm bg-surface-tertiary/70;
|
||||
}
|
||||
|
||||
/* Animation types */
|
||||
.hv-skeleton--shimmer {
|
||||
&::after {
|
||||
@apply absolute inset-0 -translate-x-full animate-skeleton bg-linear-to-r from-transparent via-surface-tertiary to-transparent content-[''];
|
||||
}
|
||||
|
||||
/* When applied to a parent container with multiple skeletons */
|
||||
&:has(.hv-skeleton) {
|
||||
&::after {
|
||||
content: none;
|
||||
}
|
||||
|
||||
/* Single synchronized shimmer that passes over all children */
|
||||
&::before {
|
||||
@apply absolute inset-0 -translate-x-full animate-skeleton content-[''];
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent 0%,
|
||||
rgba(255, 255, 255, 0.5) 50%,
|
||||
transparent 100%
|
||||
);
|
||||
z-index: 10;
|
||||
pointer-events: none;
|
||||
/* Use mix-blend-mode to only show over skeleton elements */
|
||||
mix-blend-mode: overlay;
|
||||
}
|
||||
|
||||
/* Ensure children don't have their own shimmer */
|
||||
& .hv-skeleton {
|
||||
&::after {
|
||||
content: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hv-skeleton--pulse {
|
||||
@apply animate-pulse;
|
||||
}
|
||||
|
||||
.hv-skeleton--none {
|
||||
}
|
||||
@@ -17,6 +17,9 @@
|
||||
@import "./components/surface.css" layer(components);
|
||||
@import "./components/link.css" layer(components);
|
||||
@import "./components/spinner.css" layer(components);
|
||||
@import "./components/avatar.css" layer(components);
|
||||
@import "./components/avatar-group.css" layer(components);
|
||||
@import "./components/skeleton.css" layer(components);
|
||||
/* The Vue Switch uses Reka's native button for its clickable content. */
|
||||
@layer components {
|
||||
.hv-switch:has(.hv-switch__content:focus-visible) .hv-switch__control {
|
||||
|
||||
@@ -198,3 +198,100 @@ export const textAreaVariants = tv({
|
||||
});
|
||||
|
||||
export type TextAreaVariants = VariantProps<typeof textAreaVariants>;
|
||||
|
||||
export const avatarVariants = tv({
|
||||
defaultVariants: {
|
||||
color: "default",
|
||||
size: "md",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-avatar",
|
||||
fallback: "hv-avatar__fallback",
|
||||
image: "hv-avatar__image",
|
||||
},
|
||||
variants: {
|
||||
color: {
|
||||
accent: {
|
||||
fallback: "hv-avatar__fallback--accent",
|
||||
},
|
||||
danger: {
|
||||
fallback: "hv-avatar__fallback--danger",
|
||||
},
|
||||
default: {
|
||||
fallback: "hv-avatar__fallback--default",
|
||||
},
|
||||
success: {
|
||||
fallback: "hv-avatar__fallback--success",
|
||||
},
|
||||
warning: {
|
||||
fallback: "hv-avatar__fallback--warning",
|
||||
},
|
||||
},
|
||||
size: {
|
||||
lg: {
|
||||
base: "hv-avatar--lg",
|
||||
},
|
||||
md: {
|
||||
base: "hv-avatar--md",
|
||||
},
|
||||
sm: {
|
||||
base: "hv-avatar--sm",
|
||||
},
|
||||
},
|
||||
variant: {
|
||||
default: {},
|
||||
soft: {
|
||||
base: "hv-avatar--soft",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type AvatarVariants = VariantProps<typeof avatarVariants>;
|
||||
|
||||
export const avatarGroupVariants = tv({
|
||||
defaultVariants: {
|
||||
isGrid: false,
|
||||
overlap: "clip",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-avatar-group",
|
||||
count: "hv-avatar-group__count",
|
||||
},
|
||||
variants: {
|
||||
isGrid: {
|
||||
false: {},
|
||||
true: {
|
||||
base: "hv-avatar-group--grid",
|
||||
},
|
||||
},
|
||||
overlap: {
|
||||
clip: {
|
||||
base: "hv-avatar-group--clip",
|
||||
},
|
||||
ring: {
|
||||
base: "hv-avatar-group--ring",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type AvatarGroupVariants = VariantProps<typeof avatarGroupVariants>;
|
||||
|
||||
export const skeletonVariants = tv({
|
||||
defaultVariants: {
|
||||
animationType: "shimmer",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-skeleton",
|
||||
},
|
||||
variants: {
|
||||
animationType: {
|
||||
none: "hv-skeleton--none",
|
||||
pulse: "hv-skeleton--pulse",
|
||||
shimmer: "hv-skeleton--shimmer",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type SkeletonVariants = VariantProps<typeof skeletonVariants>;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, provide, useAttrs } from "vue";
|
||||
import { AvatarRoot } from "reka-ui";
|
||||
import { avatarVariants, type AvatarVariants } from "@heroui-vue/styles";
|
||||
import { avatarContextKey, avatarGroupContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = defineProps<{
|
||||
color?: AvatarVariants["color"];
|
||||
size?: AvatarVariants["size"];
|
||||
variant?: AvatarVariants["variant"];
|
||||
/** Marks a direct AvatarGroup child (see AVATAR_GROUP_CHILD). */
|
||||
__avatar_group_child?: boolean;
|
||||
}>();
|
||||
|
||||
const attrs = useAttrs();
|
||||
const groupCtx = inject(avatarGroupContextKey, undefined);
|
||||
const isGroupChild = computed(() => props.__avatar_group_child === true);
|
||||
|
||||
const dataSlot = computed(() =>
|
||||
typeof attrs["data-slot"] === "string" ? attrs["data-slot"] : "avatar",
|
||||
);
|
||||
|
||||
const finalSize = computed(
|
||||
() => props.size ?? (isGroupChild.value ? groupCtx?.value.size : undefined),
|
||||
);
|
||||
const finalColor = computed(
|
||||
() => props.color ?? (isGroupChild.value ? groupCtx?.value.color : undefined),
|
||||
);
|
||||
const finalVariant = computed(
|
||||
() =>
|
||||
props.variant ?? (isGroupChild.value ? groupCtx?.value.variant : undefined),
|
||||
);
|
||||
|
||||
const slots = computed(() =>
|
||||
avatarVariants({
|
||||
color: finalColor.value,
|
||||
size: finalSize.value,
|
||||
variant: finalVariant.value,
|
||||
}),
|
||||
);
|
||||
|
||||
provide(avatarContextKey, { slots });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AvatarRoot v-bind="attrs" :class="slots.base()" :data-slot="dataSlot">
|
||||
<slot />
|
||||
</AvatarRoot>
|
||||
</template>
|
||||
@@ -0,0 +1,46 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { AvatarFallback } from "reka-ui";
|
||||
import { avatarVariants, type AvatarVariants } from "@heroui-vue/styles";
|
||||
import { avatarContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = defineProps<{
|
||||
delayMs?: number;
|
||||
color?: AvatarVariants["color"];
|
||||
}>();
|
||||
|
||||
const attrs = useAttrs();
|
||||
const ctx = inject(avatarContextKey, undefined);
|
||||
|
||||
// Built during render (not cached): key additions/removals on $attrs must not
|
||||
// depend on computed invalidation of an initially empty key set.
|
||||
function restAttrs() {
|
||||
const rest: Record<string, unknown> = {};
|
||||
for (const key of Object.keys(attrs)) {
|
||||
if (key !== "class") rest[key] = attrs[key];
|
||||
}
|
||||
return rest;
|
||||
}
|
||||
|
||||
// Single tv slot call so a local `color` replaces the inherited variant
|
||||
// instead of concatenating a second `--color` class (upstream composeSlotClassName).
|
||||
function fallbackClass() {
|
||||
const slotArgs: Record<string, unknown> = { class: attrs.class };
|
||||
if (props.color !== undefined) slotArgs.color = props.color;
|
||||
const slot = ctx?.slots.value.fallback ?? avatarVariants().fallback;
|
||||
return slot(slotArgs);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AvatarFallback
|
||||
v-bind="restAttrs()"
|
||||
:delay-ms="delayMs"
|
||||
:class="fallbackClass()"
|
||||
data-slot="avatar-fallback"
|
||||
>
|
||||
<slot />
|
||||
</AvatarFallback>
|
||||
</template>
|
||||
@@ -0,0 +1,150 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
Comment,
|
||||
Fragment,
|
||||
Text,
|
||||
cloneVNode,
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
isVNode,
|
||||
provide,
|
||||
useAttrs,
|
||||
type PropType,
|
||||
type VNode,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import {
|
||||
avatarGroupVariants,
|
||||
type AvatarGroupVariants,
|
||||
type AvatarVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
import { avatarGroupContextKey } from "./context";
|
||||
import AvatarGroupCount from "./AvatarGroupCount.vue";
|
||||
|
||||
function isCountNode(node: VNode): boolean {
|
||||
const type = node.type as { name?: string; __name?: string } | string;
|
||||
if (typeof type !== "object" || type === null) return false;
|
||||
return type.name === "AvatarGroupCount" || type.__name === "AvatarGroupCount";
|
||||
}
|
||||
|
||||
/** Keep only member-like elements; skip comments, text and other non-members. */
|
||||
function flattenChildren(nodes: VNodeChild[], out: VNode[] = []): VNode[] {
|
||||
for (const child of nodes) {
|
||||
if (Array.isArray(child)) {
|
||||
flattenChildren(child, out);
|
||||
continue;
|
||||
}
|
||||
if (!isVNode(child)) continue;
|
||||
if (child.type === Comment || child.type === Text) continue;
|
||||
if (child.type === Fragment && Array.isArray(child.children)) {
|
||||
flattenChildren(child.children as VNodeChild[], out);
|
||||
continue;
|
||||
}
|
||||
out.push(child);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "AvatarGroup",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
color: {
|
||||
type: String as PropType<AvatarVariants["color"]>,
|
||||
default: undefined,
|
||||
},
|
||||
size: {
|
||||
type: String as PropType<AvatarVariants["size"]>,
|
||||
default: "md",
|
||||
},
|
||||
variant: {
|
||||
type: String as PropType<AvatarVariants["variant"]>,
|
||||
default: undefined,
|
||||
},
|
||||
max: { type: Number, default: undefined },
|
||||
isGrid: { type: Boolean, default: false },
|
||||
overlap: {
|
||||
type: String as PropType<AvatarGroupVariants["overlap"]>,
|
||||
default: "clip",
|
||||
},
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const variantSlots = computed(() =>
|
||||
avatarGroupVariants({
|
||||
isGrid: props.isGrid,
|
||||
overlap: props.overlap,
|
||||
}),
|
||||
);
|
||||
|
||||
const countClass = computed(() => variantSlots.value.count());
|
||||
|
||||
const groupContext = computed(() => ({
|
||||
size: props.size,
|
||||
color: props.color,
|
||||
variant: props.variant,
|
||||
countClass: countClass.value,
|
||||
}));
|
||||
|
||||
provide(avatarGroupContextKey, groupContext);
|
||||
|
||||
/**
|
||||
* Re-read the default slot on every render. Slot-function identity is not a
|
||||
* reactive dependency, so caching in `computed` shows stale members after the
|
||||
* parent swaps the slot closure. Returning vnodes as `h()` children (not via
|
||||
* `<component :is="vnode">`) keeps patches in sync with the latest props.
|
||||
*/
|
||||
function render() {
|
||||
const flat = flattenChildren((slots.default?.() ?? []) as VNodeChild[]);
|
||||
|
||||
const avatarNodes: VNode[] = [];
|
||||
const countNodes: VNode[] = [];
|
||||
for (const node of flat) {
|
||||
if (isCountNode(node)) countNodes.push(node);
|
||||
else avatarNodes.push(node);
|
||||
}
|
||||
|
||||
const visible =
|
||||
props.max == null
|
||||
? avatarNodes
|
||||
: avatarNodes.slice(0, Math.max(0, props.max as number));
|
||||
const remaining =
|
||||
props.max == null
|
||||
? 0
|
||||
: Math.max(0, avatarNodes.length - visible.length);
|
||||
|
||||
const children: VNode[] = visible.map((child) =>
|
||||
cloneVNode(child, { __avatar_group_child: true }),
|
||||
);
|
||||
|
||||
const hasExplicitCount = countNodes.length > 0;
|
||||
if (hasExplicitCount) {
|
||||
children.push(...countNodes);
|
||||
} else if (remaining > 0) {
|
||||
children.push(
|
||||
h(
|
||||
AvatarGroupCount,
|
||||
{ key: "avatar-group-auto-count" },
|
||||
{
|
||||
default: () => `+${remaining}`,
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return h(
|
||||
"div",
|
||||
{
|
||||
...attrs,
|
||||
// Merge caller class with component classes (object spread would drop it).
|
||||
class: [variantSlots.value.base(), attrs.class],
|
||||
"data-slot": "avatar-group",
|
||||
},
|
||||
children,
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,56 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, useAttrs } from "vue";
|
||||
import { avatarGroupVariants, type AvatarVariants } from "@heroui-vue/styles";
|
||||
import Avatar from "./Avatar.vue";
|
||||
import AvatarFallback from "./AvatarFallback.vue";
|
||||
import { avatarGroupContextKey } from "./context";
|
||||
|
||||
defineOptions({
|
||||
inheritAttrs: false,
|
||||
name: "AvatarGroupCount",
|
||||
});
|
||||
|
||||
const props = defineProps<{
|
||||
color?: AvatarVariants["color"];
|
||||
size?: AvatarVariants["size"];
|
||||
variant?: AvatarVariants["variant"];
|
||||
}>();
|
||||
|
||||
const attrs = useAttrs();
|
||||
const group = inject(avatarGroupContextKey, undefined);
|
||||
|
||||
const finalSize = computed(() => props.size ?? group?.value.size);
|
||||
const finalColor = computed(() => props.color ?? group?.value.color);
|
||||
const finalVariant = computed(() => props.variant ?? group?.value.variant);
|
||||
|
||||
// Built during render (not cached): key additions/removals on $attrs must not
|
||||
// depend on computed invalidation of an initially empty key set.
|
||||
function restAttrs() {
|
||||
const rest: Record<string, unknown> = {};
|
||||
for (const key of Object.keys(attrs)) {
|
||||
if (key !== "class") rest[key] = attrs[key];
|
||||
}
|
||||
return rest;
|
||||
}
|
||||
|
||||
function countClass() {
|
||||
const base = group?.value.countClass ?? avatarGroupVariants().count();
|
||||
return [base, attrs.class];
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Avatar
|
||||
v-bind="restAttrs()"
|
||||
:color="finalColor"
|
||||
:size="finalSize"
|
||||
:variant="finalVariant"
|
||||
:__avatar_group_child="true"
|
||||
:class="countClass()"
|
||||
data-slot="avatar-group-count"
|
||||
>
|
||||
<AvatarFallback>
|
||||
<slot />
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</template>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, useAttrs } from "vue";
|
||||
import { AvatarImage } from "reka-ui";
|
||||
import { avatarContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
defineProps<{
|
||||
src: string;
|
||||
alt?: string;
|
||||
asChild?: boolean;
|
||||
crossOrigin?: "" | "anonymous" | "use-credentials";
|
||||
loading?: "eager" | "lazy";
|
||||
sizes?: string;
|
||||
srcSet?: string;
|
||||
referrerPolicy?: string;
|
||||
}>();
|
||||
|
||||
const attrs = useAttrs();
|
||||
const ctx = inject(avatarContextKey, undefined);
|
||||
const imageClass = computed(
|
||||
() => ctx?.slots.value.image() ?? "hv-avatar__image",
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AvatarImage
|
||||
v-bind="attrs"
|
||||
:src="src"
|
||||
:alt="alt"
|
||||
:as-child="asChild"
|
||||
:crossorigin="crossOrigin"
|
||||
:loading="loading"
|
||||
:sizes="sizes"
|
||||
:srcset="srcSet"
|
||||
:referrerpolicy="referrerPolicy"
|
||||
:class="imageClass"
|
||||
data-slot="avatar-image"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { ComputedRef, InjectionKey } from "vue";
|
||||
import type { AvatarVariants, avatarVariants } from "@heroui-vue/styles";
|
||||
|
||||
/** Marks direct children of AvatarGroup so nested Avatars do not inherit group props. */
|
||||
export const AVATAR_GROUP_CHILD = "__avatar_group_child" as const;
|
||||
|
||||
export type AvatarSlots = ReturnType<typeof avatarVariants>;
|
||||
|
||||
export interface AvatarPartsContext {
|
||||
slots: ComputedRef<AvatarSlots>;
|
||||
}
|
||||
|
||||
export const avatarContextKey: InjectionKey<AvatarPartsContext> =
|
||||
Symbol("HeroUIVue.Avatar");
|
||||
|
||||
export interface AvatarGroupContextValue {
|
||||
size?: AvatarVariants["size"];
|
||||
color?: AvatarVariants["color"];
|
||||
variant?: AvatarVariants["variant"];
|
||||
countClass: string;
|
||||
}
|
||||
|
||||
export type AvatarGroupContext = ComputedRef<AvatarGroupContextValue>;
|
||||
|
||||
export const avatarGroupContextKey: InjectionKey<AvatarGroupContext> = Symbol(
|
||||
"HeroUIVue.AvatarGroup",
|
||||
);
|
||||
@@ -0,0 +1,119 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, useAttrs, watch } from "vue";
|
||||
import {
|
||||
closeButtonVariants,
|
||||
type CloseButtonVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
variant?: CloseButtonVariants["variant"];
|
||||
isDisabled?: boolean;
|
||||
disabled?: boolean;
|
||||
}>(),
|
||||
{ variant: "default" },
|
||||
);
|
||||
|
||||
const attrs = useAttrs();
|
||||
const disabled = computed(() => props.isDisabled || props.disabled);
|
||||
const ariaLabel = computed(() =>
|
||||
typeof attrs["aria-label"] === "string" ? attrs["aria-label"] : "Close",
|
||||
);
|
||||
|
||||
const hovered = ref(false);
|
||||
const pressed = ref(false);
|
||||
const focused = ref(false);
|
||||
const focusVisible = ref(false);
|
||||
|
||||
watch(
|
||||
disabled,
|
||||
(isDisabled) => {
|
||||
if (isDisabled) {
|
||||
hovered.value = false;
|
||||
pressed.value = false;
|
||||
}
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
|
||||
function guard(e: MouseEvent) {
|
||||
if (disabled.value) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
}
|
||||
|
||||
function onKeydownGuard(e: KeyboardEvent) {
|
||||
if (disabled.value) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
if (e.key === " " || e.key === "Enter") pressed.value = true;
|
||||
}
|
||||
|
||||
function focus(e: FocusEvent) {
|
||||
focused.value = true;
|
||||
focusVisible.value = (e.target as HTMLElement).matches(":focus-visible");
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button
|
||||
v-bind="attrs"
|
||||
:type="'button'"
|
||||
:class="closeButtonVariants({ variant })"
|
||||
:disabled="disabled"
|
||||
:aria-disabled="disabled || undefined"
|
||||
:aria-label="ariaLabel"
|
||||
:data-hovered="(!disabled && hovered) || undefined"
|
||||
:data-pressed="(!disabled && pressed) || undefined"
|
||||
:data-focused="focused || undefined"
|
||||
:data-focus-visible="focusVisible || undefined"
|
||||
data-slot="close-button"
|
||||
@click.capture="guard"
|
||||
@keydown.capture="onKeydownGuard"
|
||||
@pointerenter="hovered = !disabled"
|
||||
@pointerleave="
|
||||
hovered = false;
|
||||
pressed = false;
|
||||
"
|
||||
@pointerdown="pressed = !disabled"
|
||||
@pointerup="pressed = false"
|
||||
@keyup="pressed = false"
|
||||
@focus="focus"
|
||||
@blur="
|
||||
focused = false;
|
||||
focusVisible = false;
|
||||
"
|
||||
>
|
||||
<slot
|
||||
:is-hovered="hovered"
|
||||
:is-pressed="pressed"
|
||||
:is-focused="focused"
|
||||
:is-focus-visible="focusVisible"
|
||||
:is-disabled="disabled"
|
||||
>
|
||||
<!-- Default close mark from the fixed baseline CloseIcon. -->
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
data-slot="close-button-icon"
|
||||
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="M3.47 3.47a.75.75 0 0 1 1.06 0L8 6.94l3.47-3.47a.75.75 0 1 1 1.06 1.06L9.06 8l3.47 3.47a.75.75 0 1 1-1.06 1.06L8 9.06l-3.47 3.47a.75.75 0 0 1-1.06-1.06L6.94 8 3.47 4.53a.75.75 0 0 1 0-1.06Z"
|
||||
fill="currentColor"
|
||||
fill-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</slot>
|
||||
</button>
|
||||
</template>
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, useAttrs } from "vue";
|
||||
import { skeletonVariants, type SkeletonVariants } from "@heroui-vue/styles";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = defineProps<{
|
||||
animationType?: SkeletonVariants["animationType"];
|
||||
}>();
|
||||
|
||||
const attrs = useAttrs();
|
||||
|
||||
const cssAnimationType = ref<SkeletonVariants["animationType"]>();
|
||||
|
||||
function readCssVariable() {
|
||||
if (typeof document === "undefined") return undefined;
|
||||
try {
|
||||
const value = getComputedStyle(document.documentElement)
|
||||
.getPropertyValue("--skeleton-animation")
|
||||
.trim();
|
||||
if (value === "shimmer" || value === "pulse" || value === "none") {
|
||||
return value;
|
||||
}
|
||||
return undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
const resolvedAnimationType = computed<SkeletonVariants["animationType"]>(
|
||||
() => props.animationType ?? cssAnimationType.value ?? "shimmer",
|
||||
);
|
||||
|
||||
const baseClass = computed(() =>
|
||||
skeletonVariants({ animationType: resolvedAnimationType.value }).base(),
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
if (props.animationType === undefined) {
|
||||
cssAnimationType.value = readCssVariable();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-bind="attrs" :class="baseClass" data-slot="skeleton">
|
||||
<slot />
|
||||
</div>
|
||||
</template>
|
||||
@@ -22,6 +22,10 @@ export {
|
||||
linkVariants,
|
||||
spinnerVariants,
|
||||
textAreaVariants,
|
||||
closeButtonVariants,
|
||||
avatarVariants,
|
||||
avatarGroupVariants,
|
||||
skeletonVariants,
|
||||
type ButtonVariants,
|
||||
type CardVariants,
|
||||
type InputVariants,
|
||||
@@ -30,6 +34,10 @@ export {
|
||||
type LinkVariants,
|
||||
type SpinnerVariants,
|
||||
type TextAreaVariants,
|
||||
type CloseButtonVariants,
|
||||
type AvatarVariants,
|
||||
type AvatarGroupVariants,
|
||||
type SkeletonVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
ButtonProps,
|
||||
@@ -43,6 +51,13 @@ export type {
|
||||
LinkIconProps,
|
||||
SpinnerProps,
|
||||
TextAreaProps,
|
||||
CloseButtonProps,
|
||||
AvatarProps,
|
||||
AvatarImageProps,
|
||||
AvatarFallbackProps,
|
||||
AvatarGroupProps,
|
||||
AvatarGroupCountProps,
|
||||
SkeletonProps,
|
||||
} from "./types";
|
||||
|
||||
export { tv, cn, type VariantProps } from "@heroui-vue/styles";
|
||||
@@ -59,3 +74,20 @@ export { default as Link } from "./components/link/Link.vue";
|
||||
export { default as LinkIcon } from "./components/link/LinkIcon.vue";
|
||||
export { default as Spinner } from "./components/spinner/Spinner.vue";
|
||||
export { default as TextArea } from "./components/textarea/TextArea.vue";
|
||||
|
||||
export { default as CloseButton } from "./components/close-button/CloseButton.vue";
|
||||
export { default as Avatar } from "./components/avatar/Avatar.vue";
|
||||
export { default as AvatarImage } from "./components/avatar/AvatarImage.vue";
|
||||
export { default as AvatarFallback } from "./components/avatar/AvatarFallback.vue";
|
||||
export { default as AvatarGroup } from "./components/avatar/AvatarGroup.vue";
|
||||
export { default as AvatarGroupCount } from "./components/avatar/AvatarGroupCount.vue";
|
||||
export {
|
||||
AVATAR_GROUP_CHILD,
|
||||
avatarContextKey,
|
||||
avatarGroupContextKey,
|
||||
type AvatarGroupContext,
|
||||
type AvatarGroupContextValue,
|
||||
type AvatarPartsContext,
|
||||
type AvatarSlots,
|
||||
} from "./components/avatar/context";
|
||||
export { default as Skeleton } from "./components/skeleton/Skeleton.vue";
|
||||
|
||||
@@ -7,6 +7,13 @@ import type Link from "./components/link/Link.vue";
|
||||
import type LinkIcon from "./components/link/LinkIcon.vue";
|
||||
import type Spinner from "./components/spinner/Spinner.vue";
|
||||
import type TextArea from "./components/textarea/TextArea.vue";
|
||||
import type CloseButton from "./components/close-button/CloseButton.vue";
|
||||
import type Avatar from "./components/avatar/Avatar.vue";
|
||||
import type AvatarImage from "./components/avatar/AvatarImage.vue";
|
||||
import type AvatarFallback from "./components/avatar/AvatarFallback.vue";
|
||||
import type AvatarGroup from "./components/avatar/AvatarGroup.vue";
|
||||
import type AvatarGroupCount from "./components/avatar/AvatarGroupCount.vue";
|
||||
import type Skeleton from "./components/skeleton/Skeleton.vue";
|
||||
|
||||
export type ButtonProps = InstanceType<typeof Button>["$props"];
|
||||
export type CardProps = InstanceType<typeof Card>["$props"];
|
||||
@@ -17,6 +24,15 @@ export type LinkProps = InstanceType<typeof Link>["$props"];
|
||||
export type LinkIconProps = InstanceType<typeof LinkIcon>["$props"];
|
||||
export type SpinnerProps = InstanceType<typeof Spinner>["$props"];
|
||||
export type TextAreaProps = InstanceType<typeof TextArea>["$props"];
|
||||
export type CloseButtonProps = InstanceType<typeof CloseButton>["$props"];
|
||||
export type AvatarProps = InstanceType<typeof Avatar>["$props"];
|
||||
export type AvatarImageProps = InstanceType<typeof AvatarImage>["$props"];
|
||||
export type AvatarFallbackProps = InstanceType<typeof AvatarFallback>["$props"];
|
||||
export type AvatarGroupProps = InstanceType<typeof AvatarGroup>["$props"];
|
||||
export type AvatarGroupCountProps = InstanceType<
|
||||
typeof AvatarGroupCount
|
||||
>["$props"];
|
||||
export type SkeletonProps = InstanceType<typeof Skeleton>["$props"];
|
||||
|
||||
import type SwitchGroup from "./components/switch/SwitchGroup.vue";
|
||||
import type Label from "./components/label/Label.vue";
|
||||
|
||||
Reference in New Issue
Block a user