@ztwoint/z-ui 0.1.44 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/avatar/avatar.d.ts +185 -0
- package/dist/components/avatar/avatar.js +55 -0
- package/dist/css/styles/tailwind.css +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -23
- package/dist/types/components/avatar/avatar.d.ts +185 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Props for the Avatar Root component.
|
|
3
|
+
* @interface RootProps
|
|
4
|
+
*/
|
|
5
|
+
interface RootProps {
|
|
6
|
+
/** Size variant of the avatar. Affects width, height, border radius, and text size */
|
|
7
|
+
size: 'xxs' | 'xs' | 'sm' | 'md';
|
|
8
|
+
/** Color theme of the avatar using design system color tokens */
|
|
9
|
+
color: 'orange' | 'purple' | 'green' | 'blue';
|
|
10
|
+
/** Child components, typically Avatar.Label or Avatar.Element */
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
/** Additional CSS classes for custom styling */
|
|
13
|
+
className?: string;
|
|
14
|
+
/** Ref object for the root div element */
|
|
15
|
+
ref?: React.RefObject<HTMLDivElement>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Avatar Root component - the container for avatar content.
|
|
19
|
+
*
|
|
20
|
+
* @param props - The component props
|
|
21
|
+
* @param props.size - Size variant (xxs: 18px, xs: 22px, sm: 26px, md: 30px)
|
|
22
|
+
* @param props.color - Color theme using design system tokens
|
|
23
|
+
* @param props.children - Child components (typically Avatar.Label)
|
|
24
|
+
* @param props.className - Additional CSS classes
|
|
25
|
+
* @param props.ref - Ref for the root div element
|
|
26
|
+
* @returns The rendered avatar container
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <Avatar.Root size="sm" color="orange">
|
|
31
|
+
* <Avatar.Label label="JD" />
|
|
32
|
+
* </Avatar.Root>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function Root({ size, color, children, className, ref, ...props }: RootProps): import("react/jsx-runtime").JSX.Element;
|
|
36
|
+
/**
|
|
37
|
+
* Props for the Avatar Element component.
|
|
38
|
+
* @interface ElementProps
|
|
39
|
+
*/
|
|
40
|
+
interface ElementProps {
|
|
41
|
+
/** Text content to display in the avatar (typically initials) */
|
|
42
|
+
label: string;
|
|
43
|
+
/** Additional CSS classes for custom styling */
|
|
44
|
+
className?: string;
|
|
45
|
+
/** Ref object for the span element */
|
|
46
|
+
ref?: React.RefObject<HTMLSpanElement>;
|
|
47
|
+
/** When true, merges props with the first child instead of rendering a span */
|
|
48
|
+
asChild?: boolean;
|
|
49
|
+
/** Child components (only used when asChild is true) */
|
|
50
|
+
children?: React.ReactNode;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Avatar Element component - flexible text/content renderer with asChild support.
|
|
54
|
+
*
|
|
55
|
+
* @param props - The component props
|
|
56
|
+
* @param props.label - Text to display (typically user initials)
|
|
57
|
+
* @param props.className - Additional CSS classes
|
|
58
|
+
* @param props.ref - Ref for the element
|
|
59
|
+
* @param props.asChild - When true, uses Radix Slot to merge with first child
|
|
60
|
+
* @param props.children - Child components (only when asChild is true)
|
|
61
|
+
* @returns The rendered element with avatar text styling
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```tsx
|
|
65
|
+
* <Avatar.Element label="JD" />
|
|
66
|
+
*
|
|
67
|
+
* // With asChild for custom elements
|
|
68
|
+
* <Avatar.Element label="JD" asChild>
|
|
69
|
+
* <button>Custom Button</button>
|
|
70
|
+
* </Avatar.Element>
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare function Element({ label, className, ref, asChild, children, ...props }: ElementProps): import("react/jsx-runtime").JSX.Element;
|
|
74
|
+
/**
|
|
75
|
+
* Props for the Avatar Label component.
|
|
76
|
+
* @interface LabelProps
|
|
77
|
+
*/
|
|
78
|
+
interface LabelProps {
|
|
79
|
+
/** Text content to display in the avatar (typically user initials) */
|
|
80
|
+
label: string;
|
|
81
|
+
/** Additional CSS classes for custom styling */
|
|
82
|
+
className?: string;
|
|
83
|
+
/** Ref object for the span element */
|
|
84
|
+
ref?: React.RefObject<HTMLSpanElement>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Avatar Label component - simplified wrapper around Avatar.Element.
|
|
88
|
+
*
|
|
89
|
+
* @param props - The component props
|
|
90
|
+
* @param props.label - Text to display (typically user initials)
|
|
91
|
+
* @param props.className - Additional CSS classes
|
|
92
|
+
* @param props.ref - Ref for the span element
|
|
93
|
+
* @returns The rendered label with avatar text styling
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```tsx
|
|
97
|
+
* <Avatar.Label label="JD" />
|
|
98
|
+
* <Avatar.Label label="AB" className="text-yellow-300" />
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare function Label({ label, className, ref, ...props }: LabelProps): import("react/jsx-runtime").JSX.Element;
|
|
102
|
+
/**
|
|
103
|
+
* Props for the AvatarWithLabel convenience component.
|
|
104
|
+
* @interface AvatarWithLabelProps
|
|
105
|
+
*/
|
|
106
|
+
interface AvatarWithLabelProps {
|
|
107
|
+
/** Text content to display in the avatar (typically user initials) */
|
|
108
|
+
label: string;
|
|
109
|
+
/** Size variant of the avatar. Affects width, height, border radius, and text size */
|
|
110
|
+
size: 'xxs' | 'xs' | 'sm' | 'md';
|
|
111
|
+
/** Color theme of the avatar using design system color tokens */
|
|
112
|
+
color: 'orange' | 'purple' | 'green' | 'blue';
|
|
113
|
+
/** Additional CSS classes for custom styling */
|
|
114
|
+
className?: string;
|
|
115
|
+
/** Ref object for the root div element */
|
|
116
|
+
ref?: React.RefObject<HTMLDivElement>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* AvatarWithLabel - A convenience component that combines Avatar.Root and Avatar.Label.
|
|
120
|
+
* Perfect for simple use cases where you just need an avatar with text.
|
|
121
|
+
*
|
|
122
|
+
* @param props - The component props
|
|
123
|
+
* @param props.label - Text to display (typically user initials)
|
|
124
|
+
* @param props.size - Size variant (xxs: 18px, xs: 22px, sm: 26px, md: 30px)
|
|
125
|
+
* @param props.color - Color theme using design system tokens
|
|
126
|
+
* @param props.className - Additional CSS classes
|
|
127
|
+
* @param props.ref - Ref for the root div element
|
|
128
|
+
* @returns The rendered avatar with label
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```tsx
|
|
132
|
+
* <AvatarWithLabel label="JD" size="sm" color="orange" />
|
|
133
|
+
* <AvatarWithLabel label="AB" size="md" color="blue" className="rounded-full" />
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare function AvatarWithLabel({ label, size, color, className, ref, ...props }: AvatarWithLabelProps): import("react/jsx-runtime").JSX.Element;
|
|
137
|
+
/**
|
|
138
|
+
* Avatar compound component with multiple variants for flexible usage.
|
|
139
|
+
*
|
|
140
|
+
* @namespace Avatar
|
|
141
|
+
* @property {React.ComponentType<RootProps>} Root - Container component for avatar content
|
|
142
|
+
* @property {React.ComponentType<ElementProps>} Element - Flexible text/content renderer with asChild support
|
|
143
|
+
* @property {React.ComponentType<LabelProps>} Label - Simplified text renderer (wrapper around Element)
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```tsx
|
|
147
|
+
* // Basic usage
|
|
148
|
+
* <Avatar.Root size="sm" color="orange">
|
|
149
|
+
* <Avatar.Label label="JD" />
|
|
150
|
+
* </Avatar.Root>
|
|
151
|
+
*
|
|
152
|
+
* // With custom styling
|
|
153
|
+
* <Avatar.Root size="md" color="blue" className="rounded-full border-2 border-white">
|
|
154
|
+
* <Avatar.Label label="AB" className="text-yellow-300" />
|
|
155
|
+
* </Avatar.Root>
|
|
156
|
+
*
|
|
157
|
+
* // Using Element with asChild for custom components
|
|
158
|
+
* <Avatar.Root size="sm" color="green">
|
|
159
|
+
* <Avatar.Element label="CD" asChild>
|
|
160
|
+
* <button onClick={handleClick}>Clickable Avatar</button>
|
|
161
|
+
* </Avatar.Element>
|
|
162
|
+
* </Avatar.Root>
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
declare const Avatar: {
|
|
166
|
+
Root: typeof Root;
|
|
167
|
+
Element: typeof Element;
|
|
168
|
+
Label: typeof Label;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* @fileoverview Avatar component library providing both compound and convenience components.
|
|
172
|
+
*
|
|
173
|
+
* This module exports:
|
|
174
|
+
* - Avatar: A compound component with Root, Element, and Label sub-components
|
|
175
|
+
* - AvatarWithLabel: A convenience component that combines Root and Label
|
|
176
|
+
*
|
|
177
|
+
* Features:
|
|
178
|
+
* - Multiple sizes (xxs, xs, sm, md) with responsive scaling
|
|
179
|
+
* - Color themes using design system tokens
|
|
180
|
+
* - Customizable styling via className
|
|
181
|
+
* - Radix Slot support for advanced composition
|
|
182
|
+
* - TypeScript support with comprehensive prop types
|
|
183
|
+
* - Optimized typography for readability at all sizes
|
|
184
|
+
*/
|
|
185
|
+
export { Avatar, AvatarWithLabel, ElementProps, LabelProps, RootProps, AvatarWithLabelProps };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { cva as i } from "class-variance-authority";
|
|
3
|
+
import { cn as l } from "../../lib/utils.js";
|
|
4
|
+
import { Slot as f } from "@radix-ui/react-slot";
|
|
5
|
+
const d = i("px-[.375rem] aspect-square flex items-center justify-center", {
|
|
6
|
+
variants: {
|
|
7
|
+
size: {
|
|
8
|
+
xxs: "size-[1.125rem] rounded-[.3125rem] text-[8px]",
|
|
9
|
+
xs: "size-[1.375rem] rounded-md text-sm",
|
|
10
|
+
sm: "size-[1.625rem] rounded-lg text-sm",
|
|
11
|
+
md: "size-[1.875rem] rounded-[.625rem] text-base"
|
|
12
|
+
},
|
|
13
|
+
color: {
|
|
14
|
+
orange: "bg-[var(--surface-warning-default)]",
|
|
15
|
+
purple: "bg-[var(--surface-purple-default)]",
|
|
16
|
+
green: "bg-[var(--surface-success-default)]",
|
|
17
|
+
blue: "bg-[var(--surface-accent-default)]"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: {
|
|
21
|
+
size: "sm",
|
|
22
|
+
color: "orange"
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
function p({ size: t, color: a, children: r, className: e, ref: n, ...s }) {
|
|
26
|
+
const m = d({ size: t, color: a });
|
|
27
|
+
return /* @__PURE__ */ o("div", { "data-slot": "avatar-root", className: l(m, e), ref: n, ...s, children: r });
|
|
28
|
+
}
|
|
29
|
+
function u({ label: t, className: a, ref: r, asChild: e = !1, children: n, ...s }) {
|
|
30
|
+
return /* @__PURE__ */ o(
|
|
31
|
+
e ? f : "span",
|
|
32
|
+
{
|
|
33
|
+
"data-slot": "avatar-element",
|
|
34
|
+
className: l(e ? "" : "text-white text-center font-primary text-xs font-[450] leading-none tracking-[-0.0125rem] uppercase", a),
|
|
35
|
+
ref: r,
|
|
36
|
+
...s,
|
|
37
|
+
children: e ? n : t
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
function x({ label: t, className: a, ref: r, ...e }) {
|
|
42
|
+
return /* @__PURE__ */ o(u, { label: t, className: a, ref: r, ...e });
|
|
43
|
+
}
|
|
44
|
+
function C({ label: t, size: a, color: r, className: e, ref: n, ...s }) {
|
|
45
|
+
return /* @__PURE__ */ o(c.Root, { size: a, color: r, className: e, ref: n, ...s, children: /* @__PURE__ */ o(c.Label, { label: t }) });
|
|
46
|
+
}
|
|
47
|
+
const c = {
|
|
48
|
+
Root: p,
|
|
49
|
+
Element: u,
|
|
50
|
+
Label: x
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
c as Avatar,
|
|
54
|
+
C as AvatarWithLabel
|
|
55
|
+
};
|