-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typescript support for avatar (#524)
- Loading branch information
Showing
6 changed files
with
75 additions
and
93 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
1 change: 0 additions & 1 deletion
1
...es/core-react/src/Avatar/Avatar.tokens.js → ...es/core-react/src/Avatar/Avatar.tokens.ts
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,4 +1,3 @@ | ||
// @ts-nocheck | ||
export const avatar = { | ||
enabled: { | ||
border: { | ||
|
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, { forwardRef } from 'react' | ||
import styled, { css } from 'styled-components' | ||
import { avatar as tokens } from './Avatar.tokens' | ||
|
||
const { | ||
enabled: { border }, | ||
disabled: { image: disabledImage }, | ||
} = tokens | ||
|
||
type StyledAvatarProps = { | ||
size: number | ||
disabled: boolean | ||
} | ||
|
||
const StyledAvatar = styled.div<StyledAvatarProps>` | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-shrink: 0; | ||
overflow: hidden; | ||
border-radius: ${border.radius}; | ||
${({ size }) => | ||
css` | ||
height: ${size}px; | ||
width: ${size}px; | ||
`} | ||
` | ||
|
||
type StyledImageProps = { | ||
alt: string | ||
src: string | ||
disabled: boolean | ||
} | ||
|
||
const StyledImage = styled.img<StyledImageProps>` | ||
height: 100%; | ||
text-align: center; | ||
color: transparent; | ||
${({ disabled }) => | ||
disabled && | ||
css` | ||
opacity: ${disabledImage.opacity}; | ||
`}; | ||
` | ||
|
||
type Props = { | ||
alt: string | ||
/** Image source | ||
@default null */ | ||
src?: string | ||
/** Avatar size | ||
@default 24 */ | ||
size?: 16 | 24 | 32 | 40 | 48 | ||
/** @default false */ | ||
disabled?: boolean | ||
} | ||
|
||
export const Avatar = forwardRef<HTMLHRElement, Props>((props, ref) => { | ||
const { src = null, alt, size = 24, disabled = false, ...rest } = props | ||
|
||
return ( | ||
<StyledAvatar size={size} disabled={disabled} ref={ref} {...rest}> | ||
<StyledImage src={src} alt={alt} disabled={disabled} /> | ||
</StyledAvatar> | ||
) | ||
}) | ||
|
||
Avatar.displayName = 'Avatar' |
1 change: 0 additions & 1 deletion
1
libraries/core-react/src/Avatar/index.js → libraries/core-react/src/Avatar/index.ts
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,2 +1 @@ | ||
// @ts-nocheck | ||
export { Avatar } from './Avatar' |
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