Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion packages/lib/src/avatar/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,73 @@ const fontSizeMap = {
xxlarge: "36px",
};

export const getFontSize = (size: AvatarPropsType["size"]) => (size ? fontSizeMap[size] : "var(--typography-label-l)");
const iconSizeMap = {
xsmall: "var(--height-xxs)",
small: "var(--height-xs)",
medium: "var(--height-s)",
large: "var(--height-xl)",
xlarge: "var(--height-xxl)",
xxlarge: "52px",
};

const outlineWidthMap = {
xsmall: "var(--border-width-m)",
small: "var(--border-width-m)",
medium: "var(--border-width-m)",
large: "var(--border-width-l)",
xlarge: "var(--border-width-l)",
xxlarge: "var(--border-width-l)",
};

const borderWidthMap = {
xsmall: "var(--border-width-s)",
small: "var(--border-width-s)",
medium: "var(--border-width-s)",
large: "var(--border-width-m)",
xlarge: "var(--border-width-m)",
xxlarge: "var(--border-width-m)",
};

const modeColorMap = {
default: "var(--color-fg-neutral-strong)",
info: "var(--color-fg-secondary-medium)",
success: "var(--color-fg-success-medium)",
warning: "var(--color-fg-warning-strong)",
error: "var(--color-fg-error-medium)",
};

export const getColor = (color: AvatarPropsType["color"]) =>
color && contextualColorMap[color] ? contextualColorMap[color].text : contextualColorMap.neutral.text;

export const getBackgroundColor = (color: AvatarPropsType["color"]) =>
color && contextualColorMap[color] ? contextualColorMap[color].background : contextualColorMap.neutral.background;

export const getBorderRadius = (shape: AvatarPropsType["shape"], size: AvatarPropsType["size"]) => {
if (shape === "circle") {
return "100%";
}
if (shape === "square") {
return size ? borderRadiusMap[size] : "var(--border-radius-m)";
}
return "100%";
};

export const getSize = (size: AvatarPropsType["size"]) => (size && sizeMap[size] ? sizeMap[size] : "var(--height-xl)");

export const getFontSize = (size: AvatarPropsType["size"]) =>
size && fontSizeMap[size] ? fontSizeMap[size] : "var(--typography-label-l)";

export const getIconSize = (size: AvatarPropsType["size"]) =>
size && iconSizeMap[size] ? iconSizeMap[size] : "var(--height-s)";

export const getBorderWidth = (size: AvatarPropsType["size"]) =>
size && borderWidthMap[size] ? borderWidthMap[size] : "var(--border-width-s)";

export const getOutlineWidth = (size: AvatarPropsType["size"]) =>
size && outlineWidthMap[size] ? outlineWidthMap[size] : "var(--border-width-m)";

export const getModeColor = (mode: Required<AvatarPropsType>["status"]["mode"]) =>
mode && modeColorMap[mode] ? modeColorMap[mode] : "var(--color-fg-neutral-strong)";

export const getInitials = (label?: string): string => {
if (!label) return "";
Expand Down
Loading