@behivetech/atoms.avatar 0.0.0-stage → 1.0.0

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.
@@ -0,0 +1,131 @@
1
+ import * as react from 'react';
2
+ import { HTMLAttributes, ReactNode } from 'react';
3
+ import * as _behivetech_blocks_core from '@behivetech/blocks.core';
4
+ import { StylesFor } from '@behivetech/blocks.core';
5
+
6
+ declare const avatar: _behivetech_blocks_core.Block<"BHT__Avatar", {
7
+ readonly display: "inline-flex";
8
+ readonly alignItems: "center";
9
+ readonly justifyContent: "center";
10
+ readonly flexShrink: 0;
11
+ readonly overflow: "hidden";
12
+ readonly backgroundColor: _behivetech_blocks_core.Token<"color">;
13
+ readonly color: _behivetech_blocks_core.Token<"color">;
14
+ readonly borderRadius: _behivetech_blocks_core.Token<"length">;
15
+ readonly fontFamily: _behivetech_blocks_core.Token<"font">;
16
+ readonly children: {
17
+ readonly image: {
18
+ readonly width: "100%";
19
+ readonly height: "100%";
20
+ readonly web: {
21
+ readonly objectFit: "cover";
22
+ };
23
+ };
24
+ readonly content: {
25
+ readonly display: "inline-flex";
26
+ readonly alignItems: "center";
27
+ readonly justifyContent: "center";
28
+ };
29
+ };
30
+ readonly variants: {
31
+ readonly sm: {
32
+ readonly web: {
33
+ readonly "--avatar-size": "2rem";
34
+ readonly "--avatar-font-size": "0.75rem";
35
+ };
36
+ readonly native: {
37
+ readonly width: "2rem";
38
+ readonly height: "2rem";
39
+ readonly fontSize: "0.75rem";
40
+ };
41
+ };
42
+ readonly md: {
43
+ readonly web: {
44
+ readonly "--avatar-size": "2.5rem";
45
+ readonly "--avatar-font-size": "0.875rem";
46
+ };
47
+ readonly native: {
48
+ readonly width: "2.5rem";
49
+ readonly height: "2.5rem";
50
+ readonly fontSize: "0.875rem";
51
+ };
52
+ };
53
+ readonly lg: {
54
+ readonly web: {
55
+ readonly "--avatar-size": "3.5rem";
56
+ readonly "--avatar-font-size": "1.25rem";
57
+ };
58
+ readonly native: {
59
+ readonly width: "3.5rem";
60
+ readonly height: "3.5rem";
61
+ readonly fontSize: "1.25rem";
62
+ };
63
+ };
64
+ readonly circle: {
65
+ readonly web: {
66
+ readonly "--avatar-radius": _behivetech_blocks_core.Token<"length">;
67
+ };
68
+ };
69
+ readonly square: {
70
+ readonly web: {
71
+ readonly "--avatar-radius": _behivetech_blocks_core.Token<"length">;
72
+ };
73
+ readonly native: {
74
+ readonly borderRadius: _behivetech_blocks_core.Token<"length">;
75
+ };
76
+ };
77
+ };
78
+ readonly web: {
79
+ readonly width: "var(--avatar-size, 2.5rem)";
80
+ readonly height: "var(--avatar-size, 2.5rem)";
81
+ readonly fontSize: "var(--avatar-font-size, 0.875rem)";
82
+ readonly fontWeight: _behivetech_blocks_core.Token<"weight">;
83
+ readonly lineHeight: "1";
84
+ readonly userSelect: "none";
85
+ };
86
+ readonly native: {
87
+ readonly fontWeight: _behivetech_blocks_core.Token<"weight">;
88
+ };
89
+ }>;
90
+
91
+ /**
92
+ * The first letters of a name's first two words, upper-cased.
93
+ *
94
+ * @param name A person's or organization's name
95
+ * @returns One or two letters, or an empty string for a blank name
96
+ */
97
+ declare const getInitials: (name: string) => string;
98
+
99
+ type AvatarSize = "sm" | "md" | "lg";
100
+ type AvatarShape = "circle" | "square";
101
+ interface AvatarProps extends HTMLAttributes<HTMLSpanElement> {
102
+ /** Additional class names to merge with the component root element */
103
+ className?: string;
104
+ /** Picture to show; when it is missing or fails to load, the initials of `name` show instead */
105
+ src?: string;
106
+ /** The person's or organization's name; its first letters are the fallback content */
107
+ name?: string;
108
+ /**
109
+ * Accessible name of the avatar, for example "Camp Greenwood". Without it the
110
+ * avatar is decorative and hidden from assistive technology, which is right
111
+ * when the name is written beside it.
112
+ */
113
+ alt?: string;
114
+ /** Shown when there is neither a loadable `src` nor a `name`, for example an icon */
115
+ fallback?: ReactNode;
116
+ /** Controls the size; defaults to md */
117
+ size?: AvatarSize;
118
+ /** "circle" for people, "square" for organizations; defaults to circle */
119
+ shape?: AvatarShape;
120
+ /** An override block made with `defineBlock`, typed to this component's children and variants; it wins over the block's own styles. */
121
+ styles?: StylesFor<typeof avatar>;
122
+ }
123
+
124
+ /**
125
+ * A picture, or the initials of a name, or a fallback, in a small circle or
126
+ * square. A picture that fails to load falls back to the initials, so a broken
127
+ * link never shows a broken image.
128
+ */
129
+ declare const Avatar: ({ className, src, name, alt, fallback, size, shape, styles, ...rest }: AvatarProps) => react.JSX.Element;
130
+
131
+ export { Avatar, type AvatarProps, type AvatarShape, type AvatarSize, getInitials };
package/dist/index.js ADDED
@@ -0,0 +1,101 @@
1
+ "use client";
2
+
3
+ // avatar.tsx
4
+ import { useState } from "react";
5
+ import { useBlock } from "@behivetech/blocks.core";
6
+
7
+ // avatar.block.ts
8
+ import { defineBlock, hook } from "@behivetech/blocks.core";
9
+ import { tokens } from "@behivetech/blocks.core/tokens";
10
+ var { color, shape, type } = tokens;
11
+ var avatarRadius = hook("avatar-radius", shape.cornerFull);
12
+ var avatar = defineBlock("BHT__Avatar", {
13
+ display: "inline-flex",
14
+ alignItems: "center",
15
+ justifyContent: "center",
16
+ flexShrink: 0,
17
+ overflow: "hidden",
18
+ backgroundColor: color.primaryContainer,
19
+ color: color.onPrimaryContainer,
20
+ borderRadius: avatarRadius,
21
+ fontFamily: type.labelLarge.font,
22
+ children: {
23
+ image: { width: "100%", height: "100%", web: { objectFit: "cover" } },
24
+ content: {
25
+ display: "inline-flex",
26
+ alignItems: "center",
27
+ justifyContent: "center"
28
+ }
29
+ },
30
+ // The size and the corner are custom properties on the web (a consumer sets `--avatar-size` and the like), and
31
+ // plain values on native, which has no cascade to read them from.
32
+ variants: {
33
+ sm: {
34
+ web: { "--avatar-size": "2rem", "--avatar-font-size": "0.75rem" },
35
+ native: { width: "2rem", height: "2rem", fontSize: "0.75rem" }
36
+ },
37
+ md: {
38
+ web: { "--avatar-size": "2.5rem", "--avatar-font-size": "0.875rem" },
39
+ native: { width: "2.5rem", height: "2.5rem", fontSize: "0.875rem" }
40
+ },
41
+ lg: {
42
+ web: { "--avatar-size": "3.5rem", "--avatar-font-size": "1.25rem" },
43
+ native: { width: "3.5rem", height: "3.5rem", fontSize: "1.25rem" }
44
+ },
45
+ circle: { web: { "--avatar-radius": shape.cornerFull } },
46
+ square: {
47
+ web: { "--avatar-radius": shape.cornerMedium },
48
+ native: { borderRadius: shape.cornerMedium }
49
+ }
50
+ },
51
+ web: {
52
+ width: "var(--avatar-size, 2.5rem)",
53
+ height: "var(--avatar-size, 2.5rem)",
54
+ fontSize: "var(--avatar-font-size, 0.875rem)",
55
+ fontWeight: type.labelLarge.weight,
56
+ lineHeight: "1",
57
+ userSelect: "none"
58
+ },
59
+ native: { fontWeight: type.labelLarge.weight }
60
+ });
61
+
62
+ // get-initials.ts
63
+ var MAX_INITIALS = 2;
64
+ var getInitials = (name) => name.trim().split(/\s+/).filter(Boolean).slice(0, MAX_INITIALS).map((word) => Array.from(word)[0]).join("").toUpperCase();
65
+
66
+ // avatar.tsx
67
+ import { jsx } from "react/jsx-runtime";
68
+ var Avatar = ({
69
+ className,
70
+ src,
71
+ name,
72
+ alt,
73
+ fallback,
74
+ size = "md",
75
+ shape: shape2 = "circle",
76
+ styles,
77
+ ...rest
78
+ }) => {
79
+ const [failedSrc, setFailedSrc] = useState();
80
+ const showImage = src !== void 0 && src !== failedSrc;
81
+ const initials = name === void 0 ? "" : getInitials(name);
82
+ const [rootProps, childProps] = useBlock(
83
+ avatar,
84
+ { [size]: true, [shape2]: true },
85
+ { className, styles }
86
+ );
87
+ const accessibleProps = alt === void 0 ? { "aria-hidden": true } : { role: "img", "aria-label": alt };
88
+ return /* @__PURE__ */ jsx("span", { ...rest, ...accessibleProps, ...rootProps, children: showImage ? /* @__PURE__ */ jsx(
89
+ "img",
90
+ {
91
+ ...childProps("image"),
92
+ src,
93
+ alt: "",
94
+ onError: () => setFailedSrc(src)
95
+ }
96
+ ) : /* @__PURE__ */ jsx("span", { ...childProps("content"), children: initials === "" ? fallback : initials }) });
97
+ };
98
+ export {
99
+ Avatar,
100
+ getInitials
101
+ };
@@ -0,0 +1,157 @@
1
+ // avatar.native.tsx
2
+ import { useBlock } from "@behivetech/blocks.core/native";
3
+ import { useState } from "react";
4
+ import {
5
+ Image,
6
+ Text,
7
+ View
8
+ } from "react-native";
9
+
10
+ // avatar.block.native.ts
11
+ import { createNativeBlock as __bhtCreateNativeBlock } from "@behivetech/blocks.core/native";
12
+ import { StyleSheet as __bhtStyleSheet } from "react-native";
13
+ var __bht0_shared = __bhtStyleSheet.create({
14
+ __image: { width: "100%", height: "100%" },
15
+ __content: {
16
+ display: "flex",
17
+ flexDirection: "row",
18
+ alignItems: "center",
19
+ justifyContent: "center"
20
+ },
21
+ "--sm": { width: 32, height: 32, fontSize: 12 },
22
+ "--sm~text": { fontSize: 12 },
23
+ "--md": { width: 40, height: 40, fontSize: 14 },
24
+ "--md~text": { fontSize: 14 },
25
+ "--lg": { width: 56, height: 56, fontSize: 20 },
26
+ "--lg~text": { fontSize: 20 },
27
+ "--square": {
28
+ borderTopLeftRadius: 12,
29
+ borderTopRightRadius: 12,
30
+ borderBottomRightRadius: 12,
31
+ borderBottomLeftRadius: 12
32
+ }
33
+ });
34
+ var __bht0_light = __bhtStyleSheet.create({
35
+ root: {
36
+ display: "flex",
37
+ flexDirection: "row",
38
+ alignItems: "center",
39
+ justifyContent: "center",
40
+ flexShrink: 0,
41
+ overflow: "hidden",
42
+ backgroundColor: "#e8ddff",
43
+ color: "#4c3e76",
44
+ borderTopLeftRadius: 9999,
45
+ borderTopRightRadius: 9999,
46
+ borderBottomRightRadius: 9999,
47
+ borderBottomLeftRadius: 9999,
48
+ fontFamily: "Inter",
49
+ fontWeight: "500"
50
+ },
51
+ "root~text": { color: "#4c3e76", fontFamily: "Inter", fontWeight: "500" }
52
+ });
53
+ var __bht0_dark = __bhtStyleSheet.create({
54
+ root: {
55
+ display: "flex",
56
+ flexDirection: "row",
57
+ alignItems: "center",
58
+ justifyContent: "center",
59
+ flexShrink: 0,
60
+ overflow: "hidden",
61
+ backgroundColor: "#4c3e76",
62
+ color: "#e8ddff",
63
+ borderTopLeftRadius: 9999,
64
+ borderTopRightRadius: 9999,
65
+ borderBottomRightRadius: 9999,
66
+ borderBottomLeftRadius: 9999,
67
+ fontFamily: "Inter",
68
+ fontWeight: "500"
69
+ },
70
+ "root~text": { color: "#e8ddff", fontFamily: "Inter", fontWeight: "500" }
71
+ });
72
+ var avatar = __bhtCreateNativeBlock("BHT__Avatar", {
73
+ structure: {
74
+ children: { image: {}, content: {} },
75
+ variants: {
76
+ sm: { children: {} },
77
+ md: { children: {} },
78
+ lg: { children: {} },
79
+ circle: { children: {} },
80
+ square: { children: {} }
81
+ }
82
+ },
83
+ sheets: {
84
+ light: { ...__bht0_shared, ...__bht0_light },
85
+ dark: { ...__bht0_shared, ...__bht0_dark }
86
+ },
87
+ plan: {
88
+ root: [
89
+ { key: "root" },
90
+ { key: "--sm", when: { variant: "sm" } },
91
+ { key: "--md", when: { variant: "md" } },
92
+ { key: "--lg", when: { variant: "lg" } },
93
+ { key: "--square", when: { variant: "square" } }
94
+ ],
95
+ children: {
96
+ image: [
97
+ { key: "root~text" },
98
+ { key: "--sm~text", when: { variant: "sm" } },
99
+ { key: "--md~text", when: { variant: "md" } },
100
+ { key: "--lg~text", when: { variant: "lg" } },
101
+ { key: "__image" }
102
+ ],
103
+ content: [
104
+ { key: "root~text" },
105
+ { key: "--sm~text", when: { variant: "sm" } },
106
+ { key: "--md~text", when: { variant: "md" } },
107
+ { key: "--lg~text", when: { variant: "lg" } },
108
+ { key: "__content" }
109
+ ]
110
+ }
111
+ }
112
+ });
113
+
114
+ // get-initials.ts
115
+ var MAX_INITIALS = 2;
116
+ var getInitials = (name) => name.trim().split(/\s+/).filter(Boolean).slice(0, MAX_INITIALS).map((word) => Array.from(word)[0]).join("").toUpperCase();
117
+
118
+ // avatar.native.tsx
119
+ import { jsx } from "react/jsx-runtime";
120
+ var Avatar = ({
121
+ src,
122
+ name,
123
+ alt,
124
+ fallback,
125
+ size = "md",
126
+ shape = "circle",
127
+ style,
128
+ styles,
129
+ ...rest
130
+ }) => {
131
+ const [failedSrc, setFailedSrc] = useState();
132
+ const showImage = src !== void 0 && src !== failedSrc;
133
+ const initials = name === void 0 ? "" : getInitials(name);
134
+ const [rootProps, childProps] = useBlock(
135
+ avatar,
136
+ { [size]: true, [shape]: true },
137
+ { style, styles }
138
+ );
139
+ const accessibleProps = alt === void 0 ? {
140
+ accessibilityElementsHidden: true,
141
+ importantForAccessibility: "no-hide-descendants"
142
+ } : { accessible: true, role: "img", accessibilityLabel: alt };
143
+ return /* @__PURE__ */ jsx(View, { ...rest, ...accessibleProps, ...rootProps, children: showImage ? /* @__PURE__ */ jsx(
144
+ Image,
145
+ {
146
+ ...childProps("image"),
147
+ source: { uri: src },
148
+ resizeMode: "cover",
149
+ accessible: false,
150
+ onError: () => setFailedSrc(src)
151
+ }
152
+ ) : /* @__PURE__ */ jsx(Text, { ...childProps("content"), children: initials === "" ? fallback : initials }) });
153
+ };
154
+ export {
155
+ Avatar,
156
+ getInitials
157
+ };
@@ -0,0 +1,84 @@
1
+ export declare const avatar: import("@behivetech/blocks.core").Block<"BHT__Avatar", {
2
+ readonly display: "inline-flex";
3
+ readonly alignItems: "center";
4
+ readonly justifyContent: "center";
5
+ readonly flexShrink: 0;
6
+ readonly overflow: "hidden";
7
+ readonly backgroundColor: import("@behivetech/blocks.core").Token<"color">;
8
+ readonly color: import("@behivetech/blocks.core").Token<"color">;
9
+ readonly borderRadius: import("@behivetech/blocks.core").Token<"length">;
10
+ readonly fontFamily: import("@behivetech/blocks.core").Token<"font">;
11
+ readonly children: {
12
+ readonly image: {
13
+ readonly width: "100%";
14
+ readonly height: "100%";
15
+ readonly web: {
16
+ readonly objectFit: "cover";
17
+ };
18
+ };
19
+ readonly content: {
20
+ readonly display: "inline-flex";
21
+ readonly alignItems: "center";
22
+ readonly justifyContent: "center";
23
+ };
24
+ };
25
+ readonly variants: {
26
+ readonly sm: {
27
+ readonly web: {
28
+ readonly "--avatar-size": "2rem";
29
+ readonly "--avatar-font-size": "0.75rem";
30
+ };
31
+ readonly native: {
32
+ readonly width: "2rem";
33
+ readonly height: "2rem";
34
+ readonly fontSize: "0.75rem";
35
+ };
36
+ };
37
+ readonly md: {
38
+ readonly web: {
39
+ readonly "--avatar-size": "2.5rem";
40
+ readonly "--avatar-font-size": "0.875rem";
41
+ };
42
+ readonly native: {
43
+ readonly width: "2.5rem";
44
+ readonly height: "2.5rem";
45
+ readonly fontSize: "0.875rem";
46
+ };
47
+ };
48
+ readonly lg: {
49
+ readonly web: {
50
+ readonly "--avatar-size": "3.5rem";
51
+ readonly "--avatar-font-size": "1.25rem";
52
+ };
53
+ readonly native: {
54
+ readonly width: "3.5rem";
55
+ readonly height: "3.5rem";
56
+ readonly fontSize: "1.25rem";
57
+ };
58
+ };
59
+ readonly circle: {
60
+ readonly web: {
61
+ readonly "--avatar-radius": import("@behivetech/blocks.core").Token<"length">;
62
+ };
63
+ };
64
+ readonly square: {
65
+ readonly web: {
66
+ readonly "--avatar-radius": import("@behivetech/blocks.core").Token<"length">;
67
+ };
68
+ readonly native: {
69
+ readonly borderRadius: import("@behivetech/blocks.core").Token<"length">;
70
+ };
71
+ };
72
+ };
73
+ readonly web: {
74
+ readonly width: "var(--avatar-size, 2.5rem)";
75
+ readonly height: "var(--avatar-size, 2.5rem)";
76
+ readonly fontSize: "var(--avatar-font-size, 0.875rem)";
77
+ readonly fontWeight: import("@behivetech/blocks.core").Token<"weight">;
78
+ readonly lineHeight: "1";
79
+ readonly userSelect: "none";
80
+ };
81
+ readonly native: {
82
+ readonly fontWeight: import("@behivetech/blocks.core").Token<"weight">;
83
+ };
84
+ }>;
@@ -0,0 +1,2 @@
1
+ import type { avatar as __bht0_source } from "./avatar.block";
2
+ export declare const avatar: typeof __bht0_source;
@@ -0,0 +1,35 @@
1
+ import { type HTMLAttributes, type ReactNode } from "react";
2
+ import { type StylesFor } from "@behivetech/blocks.core";
3
+ import { avatar } from "./avatar.block.native";
4
+ import { getInitials } from "./get-initials";
5
+ export type AvatarSize = "sm" | "md" | "lg";
6
+ export type AvatarShape = "circle" | "square";
7
+ export interface AvatarProps extends HTMLAttributes<HTMLSpanElement> {
8
+ /** Additional class names to merge with the component root element */
9
+ className?: string;
10
+ /** Picture to show; when it is missing or fails to load, the initials of `name` show instead */
11
+ src?: string;
12
+ /** The person's or organization's name; its first letters are the fallback content */
13
+ name?: string;
14
+ /**
15
+ * Accessible name of the avatar, for example "Camp Greenwood". Without it the
16
+ * avatar is decorative and hidden from assistive technology, which is right
17
+ * when the name is written beside it.
18
+ */
19
+ alt?: string;
20
+ /** Shown when there is neither a loadable `src` nor a `name`, for example an icon */
21
+ fallback?: ReactNode;
22
+ /** Controls the size; defaults to md */
23
+ size?: AvatarSize;
24
+ /** "circle" for people, "square" for organizations; defaults to circle */
25
+ shape?: AvatarShape;
26
+ /** An override block made with `defineBlock`, typed to this component's children and variants; it wins over the block's own styles. */
27
+ styles?: StylesFor<typeof avatar>;
28
+ }
29
+ export { getInitials };
30
+ /**
31
+ * A picture, or the initials of a name, or a fallback, in a small circle or
32
+ * square. A picture that fails to load falls back to the initials, so a broken
33
+ * link never shows a broken image.
34
+ */
35
+ export declare const Avatar: ({ className, src, name, alt, fallback, size, shape, styles, ...rest }: AvatarProps) => import("react").JSX.Element;
@@ -0,0 +1,36 @@
1
+ import { type StylesFor } from "@behivetech/blocks.core/native";
2
+ import { type ReactNode } from "react";
3
+ import { type StyleProp, type ViewProps, type ViewStyle } from "react-native";
4
+ import { avatar } from "./avatar.block.native";
5
+ import { getInitials } from "./get-initials";
6
+ import type { AvatarShape, AvatarSize } from "./avatar";
7
+ export type { AvatarShape, AvatarSize } from "./avatar";
8
+ export { getInitials };
9
+ export interface AvatarProps extends Omit<ViewProps, "style" | "children"> {
10
+ /** Picture to show; when it is missing or fails to load, the initials of `name` show instead */
11
+ src?: string;
12
+ /** The person's or organization's name; its first letters are the fallback content */
13
+ name?: string;
14
+ /**
15
+ * Accessible name of the avatar, for example "Camp Greenwood". Without it the
16
+ * avatar is decorative and hidden from assistive technology, which is right
17
+ * when the name is written beside it.
18
+ */
19
+ alt?: string;
20
+ /** Shown when there is neither a loadable `src` nor a `name`, for example an icon */
21
+ fallback?: ReactNode;
22
+ /** Controls the size; defaults to md */
23
+ size?: AvatarSize;
24
+ /** "circle" for people, "square" for organizations; defaults to circle */
25
+ shape?: AvatarShape;
26
+ /** Additional styles, appended after the block's own */
27
+ style?: StyleProp<ViewStyle>;
28
+ /** An override block made with `defineBlock`, typed to this component's children and variants; it wins over the block's own styles. */
29
+ styles?: StylesFor<typeof avatar>;
30
+ }
31
+ /**
32
+ * The React Native renderer of Avatar: the same block as the web one, with the same props. The initials, or a
33
+ * `fallback` of any kind, sit in a `Text` (an icon element nests in it), so a string, a number or a
34
+ * `FormattedMessage` cannot reach a bare `View`.
35
+ */
36
+ export declare const Avatar: ({ src, name, alt, fallback, size, shape, style, styles, ...rest }: AvatarProps) => import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The first letters of a name's first two words, upper-cased.
3
+ *
4
+ * @param name A person's or organization's name
5
+ * @returns One or two letters, or an empty string for a blank name
6
+ */
7
+ export declare const getInitials: (name: string) => string;
@@ -0,0 +1,2 @@
1
+ export { Avatar, getInitials } from "./avatar.native";
2
+ export type { AvatarProps, AvatarSize, AvatarShape } from "./avatar.native";
package/docs.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "$schema": "https://github.com/behivetech/bht-component-registry/docs.schema.json",
3
+ "version": 2,
4
+ "generatedAt": "2026-11-26T04:10:04.596Z",
5
+ "docs": [
6
+ {
7
+ "displayName": "Avatar",
8
+ "description": "A picture, or the initials of a name, or a fallback, in a small circle or\nsquare. A picture that fails to load falls back to the initials, so a broken\nlink never shows a broken image.",
9
+ "extendsNative": true,
10
+ "props": [
11
+ {
12
+ "name": "alt",
13
+ "type": "string",
14
+ "required": false,
15
+ "defaultValue": null,
16
+ "description": "Accessible name of the avatar, for example \"Camp Greenwood\". Without it the\navatar is decorative and hidden from assistive technology, which is right\nwhen the name is written beside it."
17
+ },
18
+ {
19
+ "name": "className",
20
+ "type": "string",
21
+ "required": false,
22
+ "defaultValue": null,
23
+ "description": "Additional class names to merge with the component root element"
24
+ },
25
+ {
26
+ "name": "fallback",
27
+ "type": "ReactNode",
28
+ "required": false,
29
+ "defaultValue": null,
30
+ "description": "Shown when there is neither a loadable `src` nor a `name`, for example an icon"
31
+ },
32
+ {
33
+ "name": "name",
34
+ "type": "string",
35
+ "required": false,
36
+ "defaultValue": null,
37
+ "description": "The person's or organization's name; its first letters are the fallback content"
38
+ },
39
+ {
40
+ "name": "shape",
41
+ "type": "\"circle\" | \"square\"",
42
+ "required": false,
43
+ "defaultValue": "circle",
44
+ "description": "\"circle\" for people, \"square\" for organizations; defaults to circle"
45
+ },
46
+ {
47
+ "name": "size",
48
+ "type": "\"sm\" | \"md\" | \"lg\"",
49
+ "required": false,
50
+ "defaultValue": "md",
51
+ "description": "Controls the size; defaults to md"
52
+ },
53
+ {
54
+ "name": "src",
55
+ "type": "string",
56
+ "required": false,
57
+ "defaultValue": null,
58
+ "description": "Picture to show; when it is missing or fails to load, the initials of `name` show instead"
59
+ },
60
+ {
61
+ "name": "styles",
62
+ "type": "StylesFor<Block<\"BHT__Avatar\", { readonly display: \"inline-flex\"; readonly alignItems: \"center\"; readonly justifyContent: \"center\"; readonly flexShrink: 0; readonly overflow: \"hidden\"; readonly backgroundColor: Token<...>; ... 6 more ...; readonly native: { ...; }; }>>",
63
+ "required": false,
64
+ "defaultValue": null,
65
+ "description": "An override block made with `defineBlock`, typed to this component's children and variants; it wins over the block's own styles."
66
+ }
67
+ ]
68
+ }
69
+ ],
70
+ "functions": [
71
+ {
72
+ "name": "getInitials",
73
+ "kind": "function",
74
+ "description": "The first letters of a name's first two words, upper-cased.",
75
+ "signatures": [
76
+ {
77
+ "text": "getInitials(name: string): string",
78
+ "params": [
79
+ {
80
+ "name": "name",
81
+ "type": "string",
82
+ "optional": false,
83
+ "defaultValue": null,
84
+ "description": "A person's or organization's name"
85
+ }
86
+ ],
87
+ "returns": {
88
+ "type": "string",
89
+ "description": "One or two letters, or an empty string for a blank name"
90
+ }
91
+ }
92
+ ],
93
+ "examples": []
94
+ }
95
+ ]
96
+ }
@@ -0,0 +1,18 @@
1
+ /** How many letters the initials show at most. */
2
+ const MAX_INITIALS = 2;
3
+
4
+ /**
5
+ * The first letters of a name's first two words, upper-cased.
6
+ *
7
+ * @param name A person's or organization's name
8
+ * @returns One or two letters, or an empty string for a blank name
9
+ */
10
+ export const getInitials = (name: string): string =>
11
+ name
12
+ .trim()
13
+ .split(/\s+/)
14
+ .filter(Boolean)
15
+ .slice(0, MAX_INITIALS)
16
+ .map((word) => Array.from(word)[0])
17
+ .join("")
18
+ .toUpperCase();
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { Avatar, getInitials } from "./avatar";
2
+ export type { AvatarProps, AvatarSize, AvatarShape } from "./avatar";