-
Notifications
You must be signed in to change notification settings - Fork 10
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
#373 Avatar component #375
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ff54236
#373 Avatar component
4a6bf25
Introduce gap for StoryDescriptor to avoid margin issues. Decrease th…
11d479a
Use locked colors for custom background Avatar
253737c
Set status position the same for all sizes per shape
99b29a1
Properly handle situation in which type is set to image but src is mi…
7f4ba5a
Add unit tests
712d84b
Fix test name
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 additions & 0 deletions
16
packages/react-components/src/components/Avatar/Avatar.helpers.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getContrast } from 'polished'; | ||
|
||
export function getInitials(name = '', count = 2): string { | ||
return name | ||
.split(' ') | ||
.map((el) => el.charAt(0)) | ||
.join('') | ||
.substring(0, count) | ||
.toUpperCase(); | ||
} | ||
|
||
export function getFontColor(color: string): string { | ||
return getContrast(color, '#FFFFFF') > 4.5 | ||
? 'var(--content-white-locked)' | ||
: 'var(--content-subtle)'; | ||
} |
316 changes: 316 additions & 0 deletions
316
packages/react-components/src/components/Avatar/Avatar.module.scss
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,316 @@ | ||
$base-class: 'avatar'; | ||
|
||
.#{$base-class} { | ||
align-items: center; | ||
background-color: var(--surface-basic-disabled); | ||
display: flex; | ||
font-weight: 600; | ||
justify-content: center; | ||
position: relative; | ||
|
||
&__status { | ||
$status-class: &; | ||
|
||
border: 1px solid var(--background); | ||
border-radius: 50%; | ||
position: absolute; | ||
|
||
&--available { | ||
background: var(--color-positive-default); | ||
} | ||
|
||
&--unavailable { | ||
background: var(--color-negative-default); | ||
} | ||
|
||
&--unknown { | ||
background: var(--surface-secondary-default); | ||
} | ||
|
||
&--xxxsmall { | ||
height: 8px; | ||
width: 8px; | ||
|
||
&#{$status-class}--circle { | ||
bottom: 62.5%; | ||
left: 62.5%; | ||
} | ||
|
||
&#{$status-class}--rounded-square { | ||
bottom: 62.5%; | ||
left: 62.5%; | ||
} | ||
} | ||
|
||
&--xxsmall { | ||
height: 8px; | ||
width: 8px; | ||
|
||
&#{$status-class}--circle { | ||
bottom: 60%; | ||
left: 60%; | ||
} | ||
|
||
&#{$status-class}--rounded-square { | ||
bottom: 70%; | ||
left: 70%; | ||
} | ||
} | ||
|
||
&--xsmall { | ||
height: 8px; | ||
width: 8px; | ||
|
||
&#{$status-class}--circle { | ||
bottom: 66.67%; | ||
left: 66.67%; | ||
} | ||
|
||
&#{$status-class}--rounded-square { | ||
bottom: 75%; | ||
left: 75%; | ||
} | ||
} | ||
|
||
&--small { | ||
height: 10px; | ||
width: 10px; | ||
|
||
&#{$status-class}--circle { | ||
bottom: 68.75%; | ||
left: 68.75%; | ||
} | ||
|
||
&#{$status-class}--rounded-square { | ||
bottom: 75%; | ||
left: 75%; | ||
} | ||
} | ||
|
||
&--medium { | ||
height: 12px; | ||
width: 12px; | ||
|
||
&#{$status-class}--circle { | ||
bottom: 66.67%; | ||
left: 66.67%; | ||
} | ||
|
||
&#{$status-class}--rounded-square { | ||
bottom: 72.92%; | ||
left: 72.92%; | ||
} | ||
} | ||
|
||
&--large { | ||
height: 16px; | ||
width: 16px; | ||
|
||
&#{$status-class}--circle { | ||
bottom: 66.67%; | ||
left: 66.67%; | ||
} | ||
|
||
&#{$status-class}--rounded-square { | ||
bottom: 72.92%; | ||
left: 72.92%; | ||
} | ||
} | ||
|
||
&--xlarge { | ||
height: 16px; | ||
width: 16px; | ||
|
||
&#{$status-class}--circle { | ||
bottom: 75%; | ||
left: 75%; | ||
} | ||
|
||
&#{$status-class}--rounded-square { | ||
bottom: 81.25%; | ||
left: 81.25%; | ||
} | ||
} | ||
|
||
&--xxlarge { | ||
height: 24px; | ||
width: 24px; | ||
|
||
&#{$status-class}--circle { | ||
bottom: 75%; | ||
left: 75%; | ||
} | ||
|
||
&#{$status-class}--rounded-square { | ||
bottom: 81.25%; | ||
left: 81.25%; | ||
} | ||
} | ||
} | ||
|
||
&__rim { | ||
background: transparent; | ||
border-color: var(--color-negative-default); | ||
border-radius: inherit; | ||
border-style: solid; | ||
box-sizing: content-box; | ||
display: block; | ||
left: 50%; | ||
position: absolute; | ||
top: 50%; | ||
transform: translate(-50%, -50%); | ||
|
||
&--xxxsmall, | ||
&--xxsmall, | ||
&--xsmall { | ||
border-width: 2px; | ||
height: calc(100% + 2px); | ||
width: calc(100% + 2px); | ||
} | ||
|
||
&--small, | ||
&--medium, | ||
&--large { | ||
border-width: 3px; | ||
height: calc(100% + 4px); | ||
width: calc(100% + 4px); | ||
} | ||
|
||
&--xlarge, | ||
&--xxlarge { | ||
border-width: 4px; | ||
height: calc(100% + 8px); | ||
width: calc(100% + 8px); | ||
} | ||
} | ||
|
||
&__image { | ||
border-radius: inherit; | ||
height: 100%; | ||
object-fit: cover; | ||
width: 100%; | ||
} | ||
|
||
&--circle { | ||
border-radius: 50%; | ||
} | ||
|
||
&--rounded-square { | ||
border-radius: 4px; | ||
} | ||
|
||
&--xxxsmall, | ||
&--xxsmall, | ||
&--xsmall { | ||
margin: 3px; | ||
} | ||
|
||
&--small, | ||
&--medium, | ||
&--large { | ||
margin: 5px; | ||
} | ||
|
||
&--xlarge, | ||
&--xxlarge { | ||
margin: 8px; | ||
} | ||
|
||
&--xxxsmall { | ||
font-size: 12px; | ||
height: 16px; | ||
line-height: 20px; | ||
width: 16px; | ||
} | ||
|
||
&--xxsmall { | ||
font-size: 12px; | ||
height: 20px; | ||
line-height: 20px; | ||
width: 20px; | ||
} | ||
|
||
&--xsmall { | ||
font-size: 12px; | ||
height: 24px; | ||
line-height: 20px; | ||
width: 24px; | ||
} | ||
|
||
&--small { | ||
font-size: 15px; | ||
height: 32px; | ||
line-height: 22px; | ||
width: 32px; | ||
} | ||
|
||
&--medium { | ||
font-size: 15px; | ||
height: 36px; | ||
line-height: 22px; | ||
width: 36px; | ||
} | ||
|
||
&--large { | ||
font-size: 18px; | ||
height: 48px; | ||
line-height: 24px; | ||
width: 48px; | ||
} | ||
|
||
&--xlarge { | ||
font-size: 24px; | ||
height: 64px; | ||
line-height: 32px; | ||
width: 64px; | ||
} | ||
|
||
&--xxlarge { | ||
font-size: 32px; | ||
height: 96px; | ||
line-height: 40px; | ||
width: 96px; | ||
} | ||
|
||
&__icon { | ||
&--xxxsmall svg { | ||
height: 8px; | ||
width: 8px; | ||
} | ||
|
||
&--xxsmall svg { | ||
height: 10px; | ||
width: 10px; | ||
} | ||
|
||
&--xsmall svg { | ||
height: 12px; | ||
width: 12px; | ||
} | ||
|
||
&--small svg { | ||
height: 16px; | ||
width: 16px; | ||
} | ||
|
||
&--medium svg { | ||
height: 18px; | ||
width: 18px; | ||
} | ||
|
||
&--large svg { | ||
height: 24px; | ||
width: 24px; | ||
} | ||
|
||
&--xlarge svg { | ||
height: 32px; | ||
width: 32px; | ||
} | ||
|
||
&--xxlarge svg { | ||
height: 48px; | ||
width: 48px; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this moment it does not support diacritics or emojis.