-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #723 from deepfence/feat/modal-slide-left
added to slide modal from left
- Loading branch information
Showing
5 changed files
with
82 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 34 additions & 43 deletions
77
deepfence_frontend/packages/ui-components/src/components/avatar/Avatar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,50 @@ | ||
import cx from 'classnames'; | ||
import { forwardRef } from 'react'; | ||
import { IconContext } from 'react-icons'; | ||
import { HiOutlineUser } from 'react-icons/hi'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
import { Typography } from '@/components/typography/Typography'; | ||
|
||
type AvatarType = { | ||
asChild?: boolean; | ||
alt?: string; | ||
src?: string; | ||
className?: string; | ||
children?: React.ReactNode; | ||
onClick?: () => void; | ||
}; | ||
|
||
const Child = ({ children }: { children: AvatarType['children'] }) => { | ||
return ( | ||
<> | ||
{children ? ( | ||
children | ||
) : ( | ||
<IconContext.Provider | ||
value={{ | ||
className: cx(`w-6 h-6`, {}), | ||
}} | ||
> | ||
<HiOutlineUser /> | ||
</IconContext.Provider> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export const Avatar = (props: AvatarType) => { | ||
const { | ||
asChild = false, | ||
children = undefined, | ||
src = '', | ||
alt = '', | ||
className = '', | ||
onClick, | ||
} = props; | ||
const DefaultIcon = () => ( | ||
<IconContext.Provider | ||
value={{ | ||
className: cx(`w-6 h-6`, {}), | ||
}} | ||
> | ||
<HiOutlineUser /> | ||
</IconContext.Provider> | ||
); | ||
|
||
return ( | ||
<button | ||
onClick={onClick} | ||
className={twMerge( | ||
cx( | ||
`inline-flex overflow-hidden relative justify-center items-center w-10 h-10 bg-gray-100 rounded-full dark:bg-gray-600`, | ||
`text-gray-700 dark:text-gray-100 ${Typography.size.lg}`, | ||
), | ||
className, | ||
)} | ||
> | ||
{!asChild ? <img src={src} alt={alt} className="p-2" /> : <Child>{children}</Child>} | ||
</button> | ||
); | ||
}; | ||
export const Avatar = forwardRef<HTMLButtonElement, AvatarType>( | ||
({ children = <DefaultIcon />, src = '', alt = '', className = '', onClick }, ref) => { | ||
return ( | ||
<button | ||
ref={ref} | ||
onClick={onClick} | ||
className={twMerge( | ||
cx( | ||
`inline-flex overflow-hidden relative justify-center items-center w-10 h-10 bg-gray-100 rounded-full dark:bg-gray-600`, | ||
`text-gray-700 dark:text-gray-100 ${Typography.size.lg}`, | ||
'outline-none focus-visible:ring-1 focus-visible:ring-gray-900 dark:focus-visible:ring-2 dark:focus-visible:ring-gray-400', | ||
), | ||
className, | ||
)} | ||
> | ||
{!src || src.trim().length === 0 ? ( | ||
<>{children}</> | ||
) : ( | ||
<img src={src} alt={alt} className="p-2" /> | ||
)} | ||
</button> | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters