-
Notifications
You must be signed in to change notification settings - Fork 74
/
ArtworkSidebarArtists.tsx
78 lines (70 loc) · 1.88 KB
/
ArtworkSidebarArtists.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Serif } from "@artsy/palette"
import React from "react"
import { createFragmentContainer, graphql } from "react-relay"
import { FollowIcon } from "Styleguide/Components"
import { Box } from "Styleguide/Elements"
import { ArtworkSidebarArtists_artwork } from "__generated__/ArtworkSidebarArtists_artwork.graphql"
export interface ArtistsProps {
artwork: ArtworkSidebarArtists_artwork
}
type Artist = ArtworkSidebarArtists_artwork["artists"][0]
export class ArtworkSidebarArtists extends React.Component<ArtistsProps> {
private renderArtistName(artist: Artist) {
return artist.href ? (
<Serif size="5t" display="inline-block" weight="semibold">
<a href={artist.href}>{artist.name}</a>
</Serif>
) : (
<Serif size="5t" display="inline-block" weight="semibold">
{artist.name}
</Serif>
)
}
private renderSingleArtist(artist: Artist) {
return (
<React.Fragment>
{this.renderArtistName(artist)}
<FollowIcon is_followed={artist.is_followed} />
</React.Fragment>
)
}
renderMultipleArtists() {
const {
artwork: { artists },
} = this.props
return artists.map((artist, index) => {
return (
<React.Fragment key={artist.__id}>
{this.renderArtistName(artist)}
{index !== artists.length - 1 && ", "}
</React.Fragment>
)
})
}
render() {
const {
artwork: { artists },
} = this.props
return (
<Box pb={2}>
{artists.length === 1
? this.renderSingleArtist(artists[0])
: this.renderMultipleArtists()}
</Box>
)
}
}
export const ArtworkSidebarArtistsFragmentContainer = createFragmentContainer(
ArtworkSidebarArtists,
graphql`
fragment ArtworkSidebarArtists_artwork on Artwork {
artists {
__id
id
name
is_followed
href
}
}
`
)