@cerberus-design/react 0.8.1-next-a0decf7 → 0.8.1-next-97f2c1c

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.
@@ -6,6 +6,7 @@ import { Announcements } from '@dnd-kit/core';
6
6
  import { applyModifiers } from '@dnd-kit/core';
7
7
  import { AutoScrollActivator } from '@dnd-kit/core';
8
8
  import { AutoScrollOptions } from '@dnd-kit/core';
9
+ import { AvatarVariantProps } from '@cerberus/styled-system/recipes';
9
10
  import { ButtonHTMLAttributes } from 'react';
10
11
  import { ButtonVariantProps } from '@cerberus/styled-system/recipes';
11
12
  import { CancelDrop } from '@dnd-kit/core';
@@ -157,6 +158,49 @@ export { AutoScrollActivator }
157
158
 
158
159
  export { AutoScrollOptions }
159
160
 
161
+ /**
162
+ * The Avatar component is used to represent a user or entity. It will show an image if src provided, otherwise it will show the ariaLabel of the ariaLabel. If the ariaLabel is empty, it will show a `defineIcons().avatar` icon.
163
+ * @definition [Avatar docs](https://cerberus.digitalu.design/react/avatar)
164
+ * @example
165
+ * ```tsx
166
+ * <Avatar
167
+ * ariaLabel="Protector Cerberus"
168
+ * src="https://cerberus.digitalu.design/logo.svg"
169
+ * />
170
+ * ```
171
+ */
172
+ declare function Avatar(props: AvatarProps): JSX_2.Element;
173
+ export { Avatar }
174
+ export { Avatar as Avatar_alias_1 }
175
+
176
+ declare type AvatarAsProps = {
177
+ as: ReactNode;
178
+ ariaLabel?: never;
179
+ src?: never;
180
+ width?: never;
181
+ height?: never;
182
+ };
183
+ export { AvatarAsProps }
184
+ export { AvatarAsProps as AvatarAsProps_alias_1 }
185
+
186
+ /**
187
+ * This module contains the Avatar component.
188
+ * @module
189
+ */
190
+ declare type AvatarImageProps = HtmlHTMLAttributes<HTMLImageElement> & {
191
+ ariaLabel: string;
192
+ as?: never;
193
+ src: string;
194
+ width?: number;
195
+ height?: number;
196
+ };
197
+ export { AvatarImageProps }
198
+ export { AvatarImageProps as AvatarImageProps_alias_1 }
199
+
200
+ declare type AvatarProps = (HtmlHTMLAttributes<HTMLDivElement> & AvatarVariantProps) & (AvatarImageProps | AvatarAsProps);
201
+ export { AvatarProps }
202
+ export { AvatarProps as AvatarProps_alias_1 }
203
+
160
204
  declare interface BaseNotificationDescriptionProps extends HTMLAttributes<HTMLParagraphElement> {
161
205
  }
162
206
  export { BaseNotificationDescriptionProps }
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/components/Avatar.tsx
21
+ var Avatar_exports = {};
22
+ __export(Avatar_exports, {
23
+ Avatar: () => Avatar
24
+ });
25
+ module.exports = __toCommonJS(Avatar_exports);
26
+ var import_css = require("@cerberus/styled-system/css");
27
+ var import_patterns = require("@cerberus/styled-system/patterns");
28
+ var import_recipes = require("@cerberus/styled-system/recipes");
29
+ var import_icons = require("@cerberus/icons");
30
+
31
+ // src/components/Show.tsx
32
+ var import_react = require("react");
33
+ function Show(props) {
34
+ const { when, children, fallback } = props;
35
+ const condition = (0, import_react.useMemo)(() => when ?? false, [when]);
36
+ return (0, import_react.useMemo)(() => {
37
+ if (condition) return children;
38
+ return fallback ?? null;
39
+ }, [condition, children, fallback]);
40
+ }
41
+
42
+ // src/components/Avatar.tsx
43
+ var import_jsx_runtime = require("react/jsx-runtime");
44
+ function Avatar(props) {
45
+ const { ariaLabel, as, gradient, size, src, width, height, ...nativeProps } = props;
46
+ const initials = (ariaLabel || "").split(" ").map((word) => word[0]).join("").slice(0, 2);
47
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
48
+ "div",
49
+ {
50
+ ...nativeProps,
51
+ className: (0, import_css.cx)(
52
+ nativeProps.className,
53
+ (0, import_recipes.avatar)({ gradient, size }),
54
+ (0, import_patterns.circle)()
55
+ ),
56
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
57
+ Show,
58
+ {
59
+ when: Boolean(src) || Boolean(as),
60
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
61
+ Show,
62
+ {
63
+ when: Boolean(initials),
64
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
65
+ import_icons.UserFilled,
66
+ {
67
+ size: iconSizeMap[size]
68
+ }
69
+ ),
70
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: initials })
71
+ }
72
+ ),
73
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
74
+ Show,
75
+ {
76
+ when: Boolean(as),
77
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
78
+ "img",
79
+ {
80
+ alt: props.ariaLabel,
81
+ className: (0, import_css.css)({
82
+ h: "full",
83
+ objectFit: "cover",
84
+ w: "full"
85
+ }),
86
+ decoding: "async",
87
+ loading: "lazy",
88
+ src,
89
+ height,
90
+ width
91
+ }
92
+ ),
93
+ children: as
94
+ }
95
+ )
96
+ }
97
+ )
98
+ }
99
+ );
100
+ }
101
+ var iconSizeMap = {
102
+ xs: 16,
103
+ sm: 16,
104
+ md: 20,
105
+ lg: 34,
106
+ xl: 32,
107
+ "2xl": 32,
108
+ "3xl": 32,
109
+ "4xl": 32
110
+ };
111
+ // Annotate the CommonJS export names for ESM import in node:
112
+ 0 && (module.exports = {
113
+ Avatar
114
+ });
115
+ //# sourceMappingURL=Avatar.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Avatar.tsx","../../../src/components/Show.tsx"],"sourcesContent":["import { css, cx } from '@cerberus/styled-system/css'\nimport { circle } from '@cerberus/styled-system/patterns'\nimport {\n avatar,\n type AvatarVariantProps,\n} from '@cerberus/styled-system/recipes'\nimport { UserFilled } from '@cerberus/icons'\nimport type { HtmlHTMLAttributes, ReactNode } from 'react'\nimport { Show } from './Show'\n\n/**\n * This module contains the Avatar component.\n * @module\n */\n\nexport type AvatarImageProps = HtmlHTMLAttributes<HTMLImageElement> & {\n ariaLabel: string\n as?: never\n src: string\n width?: number\n height?: number\n}\nexport type AvatarAsProps = {\n as: ReactNode\n ariaLabel?: never\n src?: never\n width?: never\n height?: never\n}\n\nexport type AvatarProps = (HtmlHTMLAttributes<HTMLDivElement> &\n AvatarVariantProps) &\n (AvatarImageProps | AvatarAsProps)\n\n/**\n * The Avatar component is used to represent a user or entity. It will show an image if src provided, otherwise it will show the ariaLabel of the ariaLabel. If the ariaLabel is empty, it will show a `defineIcons().avatar` icon.\n * @definition [Avatar docs](https://cerberus.digitalu.design/react/avatar)\n * @example\n * ```tsx\n * <Avatar\n * ariaLabel=\"Protector Cerberus\"\n * src=\"https://cerberus.digitalu.design/logo.svg\"\n * />\n * ```\n */\nexport function Avatar(props: AvatarProps) {\n const { ariaLabel, as, gradient, size, src, width, height, ...nativeProps } =\n props\n const initials = (ariaLabel || '')\n .split(' ')\n .map((word) => word[0])\n .join('')\n .slice(0, 2)\n\n return (\n <div\n {...nativeProps}\n className={cx(\n nativeProps.className,\n avatar({ gradient, size }),\n circle(),\n )}\n >\n <Show\n when={Boolean(src) || Boolean(as)}\n fallback={\n <Show\n when={Boolean(initials)}\n fallback={\n <UserFilled\n size={iconSizeMap[size as keyof typeof iconSizeMap]}\n />\n }\n >\n <>{initials}</>\n </Show>\n }\n >\n <Show\n when={Boolean(as)}\n fallback={\n <img\n alt={props.ariaLabel}\n className={css({\n h: 'full',\n objectFit: 'cover',\n w: 'full',\n })}\n decoding=\"async\"\n loading=\"lazy\"\n src={src}\n height={height}\n width={width}\n />\n }\n >\n {as}\n </Show>\n </Show>\n </div>\n )\n}\n\nconst iconSizeMap = {\n xs: 16,\n sm: 16,\n md: 20,\n lg: 34,\n xl: 32,\n '2xl': 32,\n '3xl': 32,\n '4xl': 32,\n}\n","'use client'\n\nimport { useMemo, type PropsWithChildren, type ReactNode } from 'react'\n\nexport interface ShowProps {\n when: boolean | null | undefined\n fallback?: ReactNode\n}\n\n/**\n * Conditionally render its children or an optional fallback component\n * based on the SolidJS component.\n * @definition [Show docs](https://cerberus.digitalu.design/react/show)\n * @example\n * ```tsx\n * <Show when={condition}>\n * <div>Content</div>\n * </Show>\n */\nexport function Show(props: PropsWithChildren<ShowProps>): ReactNode {\n const { when, children, fallback } = props\n const condition = useMemo(() => when ?? false, [when])\n\n return useMemo(() => {\n if (condition) return children\n return fallback ?? null\n }, [condition, children, fallback])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAwB;AACxB,sBAAuB;AACvB,qBAGO;AACP,mBAA2B;;;ACJ3B,mBAAgE;AAiBzD,SAAS,KAAK,OAAgD;AACnE,QAAM,EAAE,MAAM,UAAU,SAAS,IAAI;AACrC,QAAM,gBAAY,sBAAQ,MAAM,QAAQ,OAAO,CAAC,IAAI,CAAC;AAErD,aAAO,sBAAQ,MAAM;AACnB,QAAI,UAAW,QAAO;AACtB,WAAO,YAAY;AAAA,EACrB,GAAG,CAAC,WAAW,UAAU,QAAQ,CAAC;AACpC;;;AD0Cc;AAxBP,SAAS,OAAO,OAAoB;AACzC,QAAM,EAAE,WAAW,IAAI,UAAU,MAAM,KAAK,OAAO,QAAQ,GAAG,YAAY,IACxE;AACF,QAAM,YAAY,aAAa,IAC5B,MAAM,GAAG,EACT,IAAI,CAAC,S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