From 74efd1a82575b73903b5f816a68afd8cfbf5ca56 Mon Sep 17 00:00:00 2001 From: Red Adaya Date: Thu, 3 Oct 2024 10:32:29 +0800 Subject: [PATCH] mixins for avatar --- frontend/app/element/avatar.less | 8 +++- frontend/app/element/avatar.tsx | 6 ++- frontend/app/element/list.stories.tsx | 6 +-- frontend/app/mixins.less | 57 +++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/frontend/app/element/avatar.less b/frontend/app/element/avatar.less index 705346fa7..d888b9f10 100644 --- a/frontend/app/element/avatar.less +++ b/frontend/app/element/avatar.less @@ -1,3 +1,8 @@ +// Copyright 2024, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +@import "@/app/mixins.less"; + .avatar { position: relative; width: 50px; @@ -10,7 +15,6 @@ color: var(--main-text-color); font-size: 18px; text-transform: uppercase; - margin-right: 10px; .avatar-image { width: 100%; @@ -48,4 +52,6 @@ background-color: var(--warning-color); } } + + .avatar-dims-mixin(); } diff --git a/frontend/app/element/avatar.tsx b/frontend/app/element/avatar.tsx index 82b924aea..34b20bc90 100644 --- a/frontend/app/element/avatar.tsx +++ b/frontend/app/element/avatar.tsx @@ -2,15 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 import { memo } from "react"; +import clsx from "clsx"; import "./avatar.less"; interface AvatarProps { name: string; status: "online" | "offline" | "busy" | "away"; + className?: string; imageUrl?: string; } -const Avatar = memo(({ name, status = "offline", imageUrl }: AvatarProps) => { +const Avatar = memo(({ name, status = "offline", className, imageUrl }: AvatarProps) => { const getInitials = (name: string) => { const nameParts = name.split(" "); const initials = nameParts.map((part) => part[0]).join(""); @@ -18,7 +20,7 @@ const Avatar = memo(({ name, status = "offline", imageUrl }: AvatarProps) => { }; return ( -
+
{imageUrl ? ( {`${name}'s ) : ( diff --git a/frontend/app/element/list.stories.tsx b/frontend/app/element/list.stories.tsx index 63b11c4b1..c14a66ffa 100644 --- a/frontend/app/element/list.stories.tsx +++ b/frontend/app/element/list.stories.tsx @@ -198,17 +198,17 @@ export const NestedWithClickHandlers: Story = { const avatarItems = [ { text: "John Doe", - icon: , + icon: , onClick: () => console.log("John Doe clicked"), }, { text: "Jane Smith", - icon: , + icon: , onClick: () => console.log("Jane Smith clicked"), }, { text: "Robert Brown", - icon: , + icon: , onClick: () => console.log("Robert Brown clicked"), }, ]; diff --git a/frontend/app/mixins.less b/frontend/app/mixins.less index 9e39a68c9..9117c5c74 100644 --- a/frontend/app/mixins.less +++ b/frontend/app/mixins.less @@ -209,3 +209,60 @@ font-weight: 700; } } + +.avatar-dims-mixin() { + &.size-xs { + width: 20px; + height: 20px; + font-size: 7px; // 18px * (20 / 50) + + .status-indicator { + width: 5px; // scaled indicator size + height: 5px; + } + } + + &.size-sm { + width: 30px; + height: 30px; + font-size: 11px; // 18px * (30 / 50) + + .status-indicator { + width: 7px; + height: 7px; + } + } + + &.size-md { + width: 40px; + height: 40px; + font-size: 14px; // 18px * (40 / 50) + + .status-indicator { + width: 9px; + height: 9px; + } + } + + &.size-lg { + width: 45px; + height: 45px; + font-size: 16px; // 18px * (45 / 50) + + .status-indicator { + width: 10px; + height: 10px; + } + } + + &.size-xl { + width: 50px; + height: 50px; + font-size: 18px; // base size + + .status-indicator { + width: 12px; + height: 12px; + } + } +}