diff --git a/src/components/ResourceHeader/index.tsx b/src/components/ResourceHeader/index.tsx index 6735ed0..1cfd7ee 100644 --- a/src/components/ResourceHeader/index.tsx +++ b/src/components/ResourceHeader/index.tsx @@ -1,5 +1,6 @@ import React from "react" +import { StackedAvatars } from "../StackedAvatars" import ChevronUp from "../../icons/chevron-up.svg" import * as SC from "./styles" @@ -29,11 +30,7 @@ export function ResourceHeader({ {title} - - {authors.map(author => ( - - ))} - + {authors.length} contributor{authors.lenght > 1 && "s"} diff --git a/src/components/ResourceHeader/styles.tsx b/src/components/ResourceHeader/styles.tsx index 71162d0..2474f28 100644 --- a/src/components/ResourceHeader/styles.tsx +++ b/src/components/ResourceHeader/styles.tsx @@ -19,17 +19,6 @@ export const Title = styled.h1` letter-spacing: -1.75px; ` -export const AuthorAvatars = styled.div` - margin-right: 16px; -` - -export const AuthorAvatar = styled.img` - width: 32px; - height: 32px; - border: 2px solid #fff; - border-radius: 50%; -` - export const Meta = styled.div` & + &::before { content: "•"; diff --git a/src/components/StackedAvatars/index.tsx b/src/components/StackedAvatars/index.tsx new file mode 100644 index 0000000..091bf6f --- /dev/null +++ b/src/components/StackedAvatars/index.tsx @@ -0,0 +1,17 @@ +import React from "react" + +import * as SC from "./styles" + +interface StackedAvatarsProps { + authors: any +} + +export function StackedAvatars({ authors }: StackedAvatarsProps) { + return ( + + {authors.map((author, index) => ( + + ))} + + ) +} diff --git a/src/components/StackedAvatars/styles.tsx b/src/components/StackedAvatars/styles.tsx new file mode 100644 index 0000000..b918fc6 --- /dev/null +++ b/src/components/StackedAvatars/styles.tsx @@ -0,0 +1,28 @@ +import styled from "styled-components" + +const AVATAR_SIZE = 32 +const OVERLAP_AMOUT = 0.4 // 0 to 1 + +function containerWidth(count: number): number { + if (count === 0) { + return 0 + } + + return AVATAR_SIZE + count * AVATAR_SIZE * (1 - OVERLAP_AMOUT) +} + +export const StackedAvatarsWrapper = styled.div<{ count: number }>` + display: flex; + margin-right: 16px; + width: ${props => containerWidth(props.count)}px; +` + +export const AuthorAvatar = styled.img<{ index: number }>` + position: relative; + width: ${AVATAR_SIZE}px; + height: ${AVATAR_SIZE}px; + border: 2px solid #fff; + border-radius: 50%; + z-index: ${props => props.index}; + left: -${props => AVATAR_SIZE * OVERLAP_AMOUT * props.index}px; +`