Skip to content

Commit

Permalink
feat!: Allow additional background colours for Avatar and remove dark…
Browse files Browse the repository at this point in the history
… blue option (#1257)
  • Loading branch information
RubenSibon authored Jun 12, 2024
1 parent 478508a commit a1a3c8f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
35 changes: 30 additions & 5 deletions packages/css/src/components/avatar/avatar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
vertical-align: middle; /* Remove ‘phantom’ white space when image doesn’t load */
}

.ams-avatar--black {
background-color: var(--ams-avatar-black-background-color);
color: var(--ams-avatar-black-color);
}

.ams-avatar--blue {
background-color: var(--ams-avatar-blue-background-color);
color: var(--ams-avatar-blue-color);
}

.ams-avatar--dark-blue {
background-color: var(--ams-avatar-dark-blue-background-color);
color: var(--ams-avatar-dark-blue-color);
}

.ams-avatar--dark-green {
background-color: var(--ams-avatar-dark-green-background-color);
color: var(--ams-avatar-dark-green-color);
Expand All @@ -48,6 +48,26 @@
color: var(--ams-avatar-green-color);
}

.ams-avatar--grey-1 {
background-color: var(--ams-avatar-grey-1-background-color);
color: var(--ams-avatar-grey-1-color);
}

.ams-avatar--grey-2 {
background-color: var(--ams-avatar-grey-2-background-color);
color: var(--ams-avatar-grey-2-color);
}

.ams-avatar--grey-3 {
background-color: var(--ams-avatar-grey-3-background-color);
color: var(--ams-avatar-grey-3-color);
}

.ams-avatar--light-blue {
background-color: var(--ams-avatar-light-blue-background-color);
color: var(--ams-avatar-light-blue-color);
}

.ams-avatar--magenta {
background-color: var(--ams-avatar-magenta-background-color);
color: var(--ams-avatar-magenta-color);
Expand All @@ -68,6 +88,11 @@
color: var(--ams-avatar-red-color);
}

.ams-avatar--white {
background-color: var(--ams-avatar-white-background-color);
color: var(--ams-avatar-white-color);
}

.ams-avatar--yellow {
background-color: var(--ams-avatar-yellow-background-color);
color: var(--ams-avatar-yellow-color);
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Avatar/Avatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('Avatar', () => {

const component = container.querySelector(':only-child')

expect(component).toHaveClass('ams-avatar--dark-blue')
expect(component).toHaveClass('ams-avatar--blue')
})

avatarColors.map((color) =>
Expand Down
12 changes: 7 additions & 5 deletions packages/react/src/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ import { Image } from '../Image'
import { VisuallyHidden } from '../VisuallyHidden'

export const avatarColors = [
'black',
'blue',
'dark-blue',
'dark-green',
'green',
'grey-1',
'grey-2',
'grey-3',
'light-blue',
'magenta',
'orange',
'purple',
'red',
'white',
'yellow',
] as const

Expand Down Expand Up @@ -52,10 +57,7 @@ export type AvatarProps = {
} & HTMLAttributes<HTMLSpanElement>

export const Avatar = forwardRef(
(
{ label, imageSrc, className, color = 'dark-blue', ...restProps }: AvatarProps,
ref: ForwardedRef<HTMLSpanElement>,
) => {
({ label, imageSrc, className, color = 'blue', ...restProps }: AvatarProps, ref: ForwardedRef<HTMLSpanElement>) => {
const initials = label.slice(0, 2).toUpperCase()

const a11yLabel = initials.length === 0 ? 'Gebruiker' : `Initialen gebruiker: ${initials}`
Expand Down
28 changes: 24 additions & 4 deletions proprietary/tokens/src/components/ams/avatar.tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"line-height": { "value": "{ams.text.level.6.line-height}" },
"padding-block": { "value": "0.25rem" },
"padding-inline": { "value": "0.25rem" },
"blue": {
"background-color": { "value": "{ams.color.blue}" },
"color": { "value": "{ams.color.primary-black}" }
"black": {
"background-color": { "value": "{ams.color.primary-black}" },
"color": { "value": "{ams.color.primary-white}" }
},
"dark-blue": {
"blue": {
"background-color": { "value": "{ams.color.primary-blue}" },
"color": { "value": "{ams.color.primary-white}" }
},
Expand All @@ -24,6 +24,22 @@
"background-color": { "value": "{ams.color.green}" },
"color": { "value": "{ams.color.primary-black}" }
},
"grey-1": {
"background-color": { "value": "{ams.color.neutral-grey1}" },
"color": { "value": "{ams.color.primary-black}" }
},
"grey-2": {
"background-color": { "value": "{ams.color.neutral-grey2}" },
"color": { "value": "{ams.color.primary-black}" }
},
"grey-3": {
"background-color": { "value": "{ams.color.neutral-grey3}" },
"color": { "value": "{ams.color.primary-white}" }
},
"light-blue": {
"background-color": { "value": "{ams.color.blue}" },
"color": { "value": "{ams.color.primary-black}" }
},
"magenta": {
"background-color": { "value": "{ams.color.magenta}" },
"color": { "value": "{ams.color.primary-white}" }
Expand All @@ -40,6 +56,10 @@
"background-color": { "value": "{ams.color.primary-red}" },
"color": { "value": "{ams.color.primary-white}" }
},
"white": {
"background-color": { "value": "{ams.color.primary-white}" },
"color": { "value": "{ams.color.primary-black}" }
},
"yellow": {
"background-color": { "value": "{ams.color.yellow}" },
"color": { "value": "{ams.color.primary-black}" }
Expand Down

0 comments on commit a1a3c8f

Please sign in to comment.