diff --git a/apps/website/screens/components/chip/code/ChipCodePage.tsx b/apps/website/screens/components/chip/code/ChipCodePage.tsx index 9f25f914f..41151ff8b 100644 --- a/apps/website/screens/components/chip/code/ChipCodePage.tsx +++ b/apps/website/screens/components/chip/code/ChipCodePage.tsx @@ -4,7 +4,23 @@ import DocFooter from "@/common/DocFooter"; import Example from "@/common/example/Example"; import basicUsage from "./examples/basicUsage"; import icons from "./examples/icons"; -import Code, { TableCode } from "@/common/Code"; +import Code, { ExtendedTableCode, TableCode } from "@/common/Code"; + +const avatarTypeString = `{ + color?: 'primary' | 'secondary' | 'tertiary' | + 'success' | 'info' | 'neutral' | 'warning' | 'error'; + disabled?: boolean; + icon?: string | SVG; + imgSrc?: string; + label?: string; + linkHref?: string; + onClick??: () => void; + shape?: 'circle' | 'square'; + size?: 'xsmall' | 'small' | 'medium' | + 'large' | 'xlarge' | 'xxlarge'; + tabIndex?: number'; + title?: string; +}`; const sections = [ { @@ -20,6 +36,19 @@ const sections = [ + + avatar + + {avatarTypeString} + + + Avatar that will be placed before the chip label only when the chip size is 'medium' or{" "} + 'large'. + + + false + + disabled @@ -80,9 +109,9 @@ const sections = [ Material Symbol {" "} - name or SVG element as the icon that will be placed before the chip label. When using Material Symbols, - replace spaces with underscores. By default they are outlined if you want it to be filled prefix the - symbol name with "filled_". + name or SVG element as the icon that will be placed before the chip label when an avatar is + not provided. When using Material Symbols, replace spaces with underscores. By default they are outlined + if you want it to be filled prefix the symbol name with "filled_". - diff --git a/apps/website/screens/components/chip/overview/ChipOverviewPage.tsx b/apps/website/screens/components/chip/overview/ChipOverviewPage.tsx index 406df4d57..aba3f28d4 100644 --- a/apps/website/screens/components/chip/overview/ChipOverviewPage.tsx +++ b/apps/website/screens/components/chip/overview/ChipOverviewPage.tsx @@ -28,16 +28,72 @@ const sections = [ Chip anatomy - Prefix (Optional): the prefix can be an icon or an action icon that provides - additional context or functionality. + Container (Required): + + The outer wrapper of the chip. + + Defines: + + Overall size (Small / Medium / Large) + + Interactive area (default, focus, hover, active and disabled) + + + + + Acts as the main clickable surface when no action icon is present. + + - Label: the primary text that conveys the chip's meaning, such as a tag name or a selected - option. It should be concise, clear, and relevant to the chip's function. + Left Element (Optional): Supported types: + + + Icon + + Allowed in Small, Medium and Large. + Used for status, category, or action hint. + + + + + Avatar + + Allowed only in Medium and Large. + Represents people, entities or profiles. + + + + Small size supports icons only to preserve compactness and clarity. - Suffix (Optional): the suffix can be an icon or an action icon that enhances - interactivity. + Label (Required) + + Text content displayed inside the chip + + Characteristics: + + Short, concise text + Single-line only(no-wrapping) + Truncated when exceeding maximum width + Tooltip appears on hover/focus when truncated + + + Serves as the primary identifier of the chip. + + + + Action Icon (Optional) - Appears at the end of the chip. Common usage: + + Remove / clear action (✕) + Secondary inline action (if applicable) + + Behavior: + + Has its own interaction target + Does not trigger the main chip action + Disabled when the chip is disabled + diff --git a/packages/lib/src/action-icon/ActionIcon.tsx b/packages/lib/src/action-icon/ActionIcon.tsx index b4b521dce..11330e460 100644 --- a/packages/lib/src/action-icon/ActionIcon.tsx +++ b/packages/lib/src/action-icon/ActionIcon.tsx @@ -20,6 +20,7 @@ const ActionIconContainer = styled.div< hasAction?: boolean; size: ActionIconPropTypes["size"]; disabled?: ActionIconPropTypes["disabled"]; + isAvatar?: boolean; } & React.AnchorHTMLAttributes >` position: relative; @@ -40,15 +41,12 @@ const ActionIconContainer = styled.div< color: inherit; outline: none; } - ${({ hasAction, disabled, size }) => + + ${({ hasAction, disabled, size, isAvatar }) => !disabled && hasAction && css` cursor: pointer; - &:hover > div:first-child > div:first-child, - &:active > div:first-child > div:first-child { - display: block; - } &:focus:enabled > div:first-child, &:active:enabled > div:first-child { outline-style: solid; @@ -59,15 +57,37 @@ const ActionIconContainer = styled.div< &:focus-visible:enabled { outline: none; } + ${isAvatar + ? css` + &:hover > div:first-child > div:first-child, + &:active > div:first-child > div:first-child { + display: block; + } + ` + : css` + &:hover > div:first-child, + &:active > div:first-child { + background-color: var(--color-bg-alpha-light); + } + `} `} - ${({ disabled }) => + + ${({ disabled, isAvatar }) => disabled && css` cursor: not-allowed; - & > div:first-child > div:first-child { - display: block; - background-color: rgba(255, 255, 255, 0.5); - } + ${isAvatar + ? css` + & > div:first-child > div:first-child { + display: block; + background-color: rgba(255, 255, 255, 0.5); + } + ` + : css` + & > div:first-child > div:first-child { + color: var(--color-fg-neutral-medium); + } + `} `} `; @@ -155,9 +175,10 @@ const ForwardedActionIcon = forwardRef( aria-label={(onClick || linkHref) && (ariaLabel || title || "Action Icon")} disabled={disabled} ref={ref} + isAvatar={color !== "transparent"} > - {(!!onClick || !!linkHref) &&