(function Avatar(
const avatarInitials = nameToInitials(name);
const ariaProps = name
- ? {
- role: "img",
- "aria-label": name,
- }
+ ? render
+ ? {
+ "aria-label": name,
+ }
+ : {
+ role: "img",
+ "aria-label": name,
+ }
: {};
return (
- (function Avatar(
{...rest}
>
{children || avatarInitials || fallbackIcon}
-
+
);
});
diff --git a/packages/core/stories/avatar/avatar.stories.tsx b/packages/core/stories/avatar/avatar.stories.tsx
index 4399fffd0f4..c212369bf71 100644
--- a/packages/core/stories/avatar/avatar.stories.tsx
+++ b/packages/core/stories/avatar/avatar.stories.tsx
@@ -7,7 +7,7 @@ import {
} from "@salt-ds/core";
import { UserGroupSolidIcon } from "@salt-ds/icons";
import type { Meta, StoryFn } from "@storybook/react-vite";
-import type { ReactNode } from "react";
+import type { ComponentProps, ReactNode } from "react";
import persona1 from "../assets/avatar.png";
export default {
@@ -20,6 +20,10 @@ const Template: StoryFn = (args) => {
return ;
};
+const CustomAvatarButton = (props: ComponentProps<"button">) => (
+
+);
+
export const Default = Template.bind({});
export const Sizes: StoryFn = (args) => {
@@ -65,6 +69,20 @@ WithCustomSvg.args = {
children: CustomSVG,
};
+export const RenderElement = Template.bind({});
+RenderElement.args = {
+ name: "Alex Brailescu",
+ render: ,
+};
+
+export const RenderProp = Template.bind({});
+RenderProp.args = {
+ name: "Alex Brailescu",
+ render: (props) => (
+
+ ),
+};
+
export const WithCustomImg: StoryFn = () => {
const src = "bad_url";
const status = useAvatarImage({ src });
diff --git a/site/docs/components/avatar/examples.mdx b/site/docs/components/avatar/examples.mdx
index 4b58f441706..1cfa61b01ff 100644
--- a/site/docs/components/avatar/examples.mdx
+++ b/site/docs/components/avatar/examples.mdx
@@ -31,6 +31,16 @@ The `color` prop can be used to change Avatar's background to one of the 20 [cat
+## Interactive
+
+Avatar can be made interactive using the `render` prop. Props defined on the JSX element will be merged with props from the Avatar.
+
+### Best practices
+
+- Ensure the Avatar has a meaningful accessible name so screen reader users understand what action will occur.
+
+
+
## Sizes
You can use the `size` prop to modify the avatar size. Each avatar variant has a default size across all four densities, equal to the [size foundation](/salt/foundations/size) `size-base`: 20px (HD), 28px (MD), 36px (LD), and 44px (TD). The size property acts as a multiplier of the base size.
diff --git a/site/src/examples/avatar/Interactive.tsx b/site/src/examples/avatar/Interactive.tsx
new file mode 100644
index 00000000000..eb8c681ef8d
--- /dev/null
+++ b/site/src/examples/avatar/Interactive.tsx
@@ -0,0 +1,40 @@
+import {
+ Avatar,
+ Divider,
+ Menu,
+ MenuItem,
+ MenuPanel,
+ MenuTrigger,
+} from "@salt-ds/core";
+import { ExportIcon, NotificationIcon, SettingsIcon } from "@salt-ds/icons";
+import type { ReactElement } from "react";
+
+export const Interactive = (): ReactElement => {
+ return (
+
+ );
+};
diff --git a/site/src/examples/avatar/index.ts b/site/src/examples/avatar/index.ts
index 74e47c7aa6a..66a9c8760bc 100644
--- a/site/src/examples/avatar/index.ts
+++ b/site/src/examples/avatar/index.ts
@@ -2,4 +2,5 @@ export * from "./Categories";
export * from "./CustomFallbackIcon";
export * from "./Image";
export * from "./Initials";
+export * from "./Interactive";
export * from "./Sizes";