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

feat(Avatar): add configurable avatar placeholder color #60

Merged
merged 1 commit into from
Mar 18, 2022
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
1 change: 1 addition & 0 deletions src/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Template: Story<AvatarProps> = (args) => {

export const Default = Template.bind({})
Default.args = {
color: 'primary',
src: 'http://daisyui.com/tailwind-css-component-profile-1@94w.png',
}

Expand Down
30 changes: 16 additions & 14 deletions src/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type AvatarProps = React.HTMLAttributes<HTMLDivElement> &
letters?: string
size?: ComponentSize
shape?: ComponentShape
color?: ComponentColor
border?: boolean
borderColor?: ComponentColor
online?: boolean
Expand All @@ -30,6 +31,7 @@ const Avatar = React.forwardRef<HTMLDivElement, AvatarProps>(
letters,
size,
shape,
color,
border,
borderColor,
online,
Expand Down Expand Up @@ -61,20 +63,20 @@ const Avatar = React.forwardRef<HTMLDivElement, AvatarProps>(
'w-10 h-10': size === 'xs',
})

const placeholderClasses = clsx(
'bg-neutral-focus',
'text-neutral-content',
{
'ring ring-offset-base-100 ring-offset-2': border,
[`ring-${borderColor}`]: borderColor,
'rounded-btn': shape === 'square',
'rounded-full': shape === 'circle',
'w-32 h-32 text-3xl': size === 'lg',
'w-24 h-24 text-xl': !size || size === 'md',
'w-14 h-14': size === 'sm',
'w-10 h-10': size === 'xs',
}
)
const placeholderClasses = clsx({
'bg-neutral-focus': !color,
'text-neutral-content': !color,
[`bg-${color}`]: color,
[`text-${color}-content`]: color,
'ring ring-offset-base-100 ring-offset-2': border,
[`ring-${borderColor}`]: borderColor,
'rounded-btn': shape === 'square',
'rounded-full': shape === 'circle',
'w-32 h-32 text-3xl': size === 'lg',
'w-24 h-24 text-xl': !size || size === 'md',
'w-14 h-14': size === 'sm',
'w-10 h-10': size === 'xs',
})

return (
<div
Expand Down