-
Notifications
You must be signed in to change notification settings - Fork 646
AvatarStack #575
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
Merged
Merged
AvatarStack #575
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
031e25d
Add AvatarStack
1dc2a67
add avatar-more functionality
8bd45b4
add d inline block to wrapper
c5adc4b
use React.Children to map
8a17443
give AvatarStack COMMON props
d574605
update docs
5f46d70
refactor child API
a33b0dc
add alignRight prop
43d4d93
clean up
be90da0
update docs
2de1806
add tests
f4a78d1
add types
3451b8d
lint
dd1868b
update snapshot
6bb4be3
add alt text to docs
9ce7952
typo
128452a
update docs
9f4d490
typo
223f82d
Update src/AvatarStack.js
66f6d79
Update src/AvatarStack.js
9f4f818
Update src/AvatarStack.js
38fa9d0
change class names
711cbdf
AvatarItem-more changes
b6cbd8d
fix theme gets
004593e
return React.Children.map
34d8a97
docs update
e90df22
update snaps & lint
043be50
get rid of AvatarStack.Item
f1759a8
Merge branch 'release-14.4.0' into avatar-stack
0404c9f
merge conflicts
716ff99
update tests
a3000be
update snapshot
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 hidden or 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,26 @@ | ||
| --- | ||
| title: AvatarStack | ||
| --- | ||
|
|
||
| AvatarStack is used to display more than one Avatar in an inline stack. | ||
|
|
||
| AvatarStack | ||
| ```jsx live | ||
| <AvatarStack> | ||
| <img alt="Primer" src="https://avatars.githubusercontent.com/primer"/> | ||
| <img alt="GitHub" src="https://avatars.githubusercontent.com/github"/> | ||
| <img alt="Atom" src="https://avatars.githubusercontent.com/atom"/> | ||
| <img alt="Desktop" src="https://avatars.githubusercontent.com/desktop"/> | ||
| </AvatarStack> | ||
| ``` | ||
|
|
||
| ## System props | ||
|
|
||
| AvatarStack components get `COMMON` system props, AvatarStack.Item components do not get any system props. Read our [System Props](/system-props) doc page for a full list of available props. | ||
|
|
||
|
|
||
| ## AvatarStack Component props | ||
|
|
||
| | Name | Type | Default | Description | | ||
| | :- | :- | :-: | :- | | ||
| | alignRight | Boolean | | Creates right aligned AvatarStack | |
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,158 @@ | ||
| import React from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import styled from 'styled-components' | ||
| import {get, COMMON} from './constants' | ||
| import theme from './theme' | ||
|
|
||
| const alignRightStyles = theme => { | ||
| return ` | ||
| right: 0; | ||
| flex-direction: row-reverse; | ||
|
|
||
| &:hover .AvatarItem { | ||
| margin-right: 0; | ||
| margin-left: 3px; | ||
| } | ||
|
|
||
| .AvatarItem-more { | ||
| background: ${get('colors.gray.3')(theme)}; | ||
|
|
||
| &::before { | ||
| width: 5px; | ||
| } | ||
|
|
||
| &::after { | ||
| background: ${get('colors.gray.1')(theme)}; | ||
| width: 2px; | ||
| } | ||
| } | ||
|
|
||
| .AvatarItem { | ||
| margin-right: 0; | ||
| margin-left: -11px; | ||
| border-right: 0; | ||
| border-left: ${get('borders.1')(theme)} ${get('colors.white')(theme)}; | ||
| } | ||
| ` | ||
| } | ||
|
|
||
| const transformChildren = children => { | ||
| const count = children.length | ||
| return React.Children.map(children, (child, index) => { | ||
| return ( | ||
| <> | ||
| {count > 3 && index === 2 && <div className="AvatarItem-more AvatarItem" />} | ||
| {React.cloneElement(child, {className: 'AvatarItem'})} | ||
| </> | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| const AvatarStackWrapper = styled.span` | ||
| display: inline-block; | ||
| position: relative; | ||
| min-width: ${props => (props.count === 1 ? '26px' : props.count === 2 ? '36px' : '46px')}; | ||
| height: 20px; | ||
| ${COMMON} | ||
| ` | ||
|
|
||
| const AvatarStackBody = styled.span` | ||
| display: flex; | ||
| position: absolute; | ||
| background: white; | ||
|
|
||
| &:hover { | ||
| .AvatarItem { | ||
| margin-right: 3px; | ||
| } | ||
|
|
||
| .AvatarItem:nth-child(n + 4) { | ||
| display: flex; | ||
| opacity: 1; | ||
| } | ||
|
|
||
| .AvatarItem-more { | ||
| display: none !important; | ||
| } | ||
| } | ||
|
|
||
| .AvatarItem { | ||
| position: relative; | ||
| z-index: 2; | ||
| display: flex; | ||
| width: 20px; | ||
| height: 20px; | ||
| box-sizing: content-box; | ||
| margin-right: -11px; | ||
| background-color: ${get('colors.white')}; | ||
| border-right: ${get('borders.1')} ${get('colors.white')}; | ||
| border-radius: 2px; | ||
| transition: margin 0.1s ease-in-out; | ||
|
|
||
| &:first-child { | ||
| z-index: 3; | ||
| } | ||
|
|
||
| &:last-child { | ||
| z-index: 1; | ||
| border-right: 0; | ||
| } | ||
|
|
||
| img { | ||
| border-radius: 2px; | ||
| width: inherit; | ||
| } | ||
|
|
||
| // Account for 4+ avatars | ||
| &:nth-child(n + 4) { | ||
| display: none; | ||
| opacity: 0; | ||
| } | ||
| } | ||
|
|
||
| .AvatarItem-more { | ||
| z-index: 1; | ||
| margin-right: 0; | ||
| background: ${get('colors.gray.1')}; | ||
|
|
||
| &::before, | ||
| &::after { | ||
| position: absolute; | ||
| display: block; | ||
| height: 20px; | ||
| content: ''; | ||
| border-radius: 2px; | ||
| outline: ${get('borders.1')} ${get('colors.white')}; | ||
| } | ||
|
|
||
| &::before { | ||
| width: 17px; | ||
| background: ${get('colors.gray.2')}; | ||
| } | ||
|
|
||
| &::after { | ||
| width: 14px; | ||
| background: ${get('colors.gray.3')}; | ||
| } | ||
| } | ||
| ${props => (props.alignRight ? alignRightStyles(props.theme) : '')} | ||
| ` | ||
| const AvatarStack = ({children = [], alignRight, ...rest}) => { | ||
| return ( | ||
| <AvatarStackWrapper count={children.length} {...rest}> | ||
| <AvatarStackBody alignRight={alignRight} className="AvatarStackBody"> | ||
| {transformChildren(children)} | ||
| </AvatarStackBody> | ||
| </AvatarStackWrapper> | ||
| ) | ||
| } | ||
|
|
||
| AvatarStack.defaultProps = { | ||
| theme | ||
| } | ||
|
|
||
| AvatarStack.propTypes = { | ||
| ...COMMON.propTypes, | ||
| alignRight: PropTypes.bool | ||
| } | ||
| export default AvatarStack | ||
This file contains hidden or 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,41 @@ | ||
| /* eslint-disable jsx-a11y/alt-text */ | ||
| import React from 'react' | ||
| import AvatarStack from '../AvatarStack' | ||
| import {render} from '../utils/testing' | ||
| import {COMMON} from '../constants' | ||
|
|
||
| const avatarComp = ( | ||
| <AvatarStack> | ||
| <img src="https://avatars.githubusercontent.com/primer" /> | ||
| <img src="https://avatars.githubusercontent.com/github" /> | ||
| <img src="https://avatars.githubusercontent.com/primer" /> | ||
| <img src="https://avatars.githubusercontent.com/github" /> | ||
| </AvatarStack> | ||
| ) | ||
|
|
||
| const rightAvatarComp = ( | ||
| <AvatarStack alignRight> | ||
| <img src="https://avatars.githubusercontent.com/primer" /> | ||
| <img src="https://avatars.githubusercontent.com/github" /> | ||
| <img src="https://avatars.githubusercontent.com/primer" /> | ||
| <img src="https://avatars.githubusercontent.com/github" /> | ||
| </AvatarStack> | ||
| ) | ||
|
|
||
| describe('Avatar', () => { | ||
| it('implements common system props', () => { | ||
| expect(AvatarStack).toImplementSystemProps(COMMON) | ||
| }) | ||
|
|
||
| it('has default theme', () => { | ||
| expect(AvatarStack).toSetDefaultTheme() | ||
| }) | ||
|
|
||
| it('matches snapshot', () => { | ||
| expect(render(avatarComp)).toMatchSnapshot() | ||
| }) | ||
|
|
||
| it('respects alignRight props', () => { | ||
| expect(render(rightAvatarComp)).toMatchSnapshot() | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.