Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/wsdev 4132 avatar #279

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions CHANGELOG.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ Prefix the change with one of these keywords:

- Card Loader: page card loader was missing shadow

### Changed

- Avatar: replaced rounded prop with isCircle
- Avatar: updated styles

### Deprecated

- Avatar: removed hasShadow and hasBorder props

## [0.9.6]

### Fixed
Expand Down
495 changes: 0 additions & 495 deletions lib/_deprecated/TopNav/TopNav.stories.tsx

This file was deleted.

262 changes: 0 additions & 262 deletions lib/_deprecated/TopNav/TopNav.tsx

This file was deleted.

33 changes: 1 addition & 32 deletions lib/components/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react'
import type { Meta, StoryObj } from '@storybook/react'
import { Avatar } from './Avatar'

Expand Down Expand Up @@ -39,16 +40,6 @@ Default.args = {
},
}

export const RoundedCorners: Story = {}

RoundedCorners.args = {
user: { ...user },
rounded: 'lg',
onClick: () => {
alert('I am an alert ')
},
}

export const FullCircle: Story = {}

FullCircle.args = {
Expand All @@ -59,28 +50,6 @@ FullCircle.args = {
},
}

export const WithShadow: Story = {}

WithShadow.args = {
user: { ...user },
rounded: 'lg',
hasShadow: true,
onClick: () => {
alert('I am an alert ')
},
}

export const WithBorder: Story = {}

WithBorder.args = {
user: { ...user },
rounded: 'lg',
borderWidth: '4',
onClick: () => {
alert('I am an alert ')
},
}

export const NoImage: Story = {}

NoImage.args = {
Expand Down
27 changes: 9 additions & 18 deletions lib/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import { rdsRounded, rdsBorderWidth, rdsBorderColor } from '../../utils/optionClasses'

export type ImageType = {
src: string | undefined
Expand All @@ -17,11 +16,8 @@ export type UserInfoType = {
}

export interface AvatarProps {
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '4xl'
rounded?: 'lg' | 'full'
borderWidth?: '1' | '2' | '4' | '8'
borderColor?: 'black' | 'white' | 'red' | 'grey' | 'dark-grey'
hasShadow?: boolean
size?: keyof typeof avatarSizes
isCircle?: boolean
user: UserInfoType
onClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void
}
Expand All @@ -37,12 +33,11 @@ const avatarSizes = {
}

const styles = {
core: `not-prose inline-block bg-cu-black-50 text-cu-black-800 overflow-hidden focus:ring-2 focus:ring-cu-black-100 focus:ring-offset-2`,
'no-image': `bg-cu-black-100 flex items-center justify-center font-semibold`,
shadow: `shadow-lg`,
core: `not-prose inline-block bg-cu-black-100 text-cu-black-800 overflow-hidden focus:ring-2 focus:ring-cu-black-100 focus:ring-offset-2`,
noImage: `flex items-center justify-center font-semibold`,
}

export const Avatar = ({ size = 'xl', rounded, borderWidth, borderColor, hasShadow, user, onClick }: AvatarProps) => {
export const Avatar = ({ size = 'xl', isCircle = false, user, onClick }: AvatarProps) => {
const { firstName, lastName, image } = user

let initials
Expand All @@ -59,27 +54,23 @@ export const Avatar = ({ size = 'xl', rounded, borderWidth, borderColor, hasShad
}
}
}
const shadowStyle = hasShadow ? styles.shadow : ''
const roundedStyle = rounded ? rdsRounded[rounded] : ''
const borderWidthStyle = borderWidth ? rdsBorderWidth[borderWidth] : ''
const borderColorStyle = borderColor ? rdsBorderColor[borderColor] : ''

const roundedStyle = isCircle ? 'rounded-full' : 'rounded-md'
const hasOnClick = onClick ? 'cursor-pointer' : ''

return (
<>
{image && (
<img
className={`${styles.core} ${avatarSizes[size]} ${roundedStyle} ${borderWidthStyle} ${borderColorStyle} ${borderColorStyle} ${shadowStyle} ${hasOnClick}`}
className={`${styles.core} ${avatarSizes[size]} ${roundedStyle} ${hasOnClick}`}
src={image.src}
alt={image.alt || `Avatar of ${firstName} ${lastName}`}
aria-hidden="true"
/>
)}

{!image && (
<div
className={`${styles.core} ${styles['no-image']} ${avatarSizes[size]} ${roundedStyle} ${borderWidthStyle} ${borderColorStyle} ${borderColorStyle} ${shadowStyle} ${hasOnClick}`}
>
<div className={`${styles.core} ${styles['noImage']} ${avatarSizes[size]} ${roundedStyle} ${hasOnClick}`}>
{initials}
</div>
)}
Expand Down
Loading
Loading