Skip to content
This repository was archived by the owner on May 16, 2022. It is now read-only.

Commit 4656eef

Browse files
committed
Added: embed fields, footer, image and thumbnail
1 parent b6141e5 commit 4656eef

4 files changed

Lines changed: 157 additions & 17 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
- [ ] Embeds
3434
- [x] Title
3535
- [x] Author
36-
- [ ] Description
37-
- [ ] Fields
36+
- [x] Description
37+
- [x] Fields
3838
- [ ] Inside markdown
39-
- [ ] Footer
40-
- [ ] Color
39+
- [x] Footer
40+
- [x] Color
4141

4242
The following components can be used on other cases like a "channel selector"
4343
- [ ] Other components

example/src/App.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const App = () => {
2424
<ThemeProvider theme={isDark ? dark : light}>
2525
<MessageWrapper style={{
2626
borderRadius: 3,
27-
boxShadow: `2px 2px 13px 3px rgba(0, 0, 0, 0.3)`
27+
boxShadow: `2px 2px 13px 3px rgba(0, 0, 0, 0.3)`,
28+
maxWidth: 800
2829
}}>
2930
<Message
3031
avatar={'https://cdn.discordapp.com/avatars/205873263258107905/62b8cf8c20107e61b51b8194ac716c53.webp?size=256'}
@@ -49,15 +50,44 @@ const App = () => {
4950
verified: true
5051
}}
5152
>
52-
{/*oi eu sou um bot muito **bobão***/}
53+
5354
<MessageEmbed
5455
title="bobao"
5556
author={{
5657
name: 'pipipi popopo',
5758
icon: 'https://cdn.discordapp.com/attachments/696797678356398671/744044111157526548/20200814_192551.jpg'
5859
}}
60+
footer={{
61+
text: 'bom dia amigo',
62+
icon: 'https://cdn.discordapp.com/attachments/696797678356398671/744778541245268038/unknown.png'
63+
}}
64+
color="#03fc84"
65+
thumbnail="https://cdn.discordapp.com/attachments/696797678356398671/745052530714869780/IMG-20200817-WA0021.jpeg"
66+
image="https://cdn.discordapp.com/attachments/696797678356398671/744681438649122866/FB_IMG_1597616284534.jpg"
67+
fields={[
68+
{
69+
name: 'bom dia',
70+
value: 'teste'
71+
},
72+
{
73+
name: 'bom dia',
74+
value: 'teste'
75+
},
76+
{
77+
name: 'pedro é oq',
78+
value: 'bobao',
79+
inline: true
80+
},
81+
{
82+
name: 'davi tb?',
83+
value: 'ss',
84+
inline: true
85+
}
86+
]}
5987
>
60-
aa
88+
Mussum Ipsum, cacilds vidis litro abertis. Si num tem leite então bota uma pinga aí cumpadi! Nec orci ornare
89+
consequat. Praesent lacinia ultrices consectetur. Sed non ipsum felis. Quem num gosta di mim que vai caçá
90+
sua turmis! Suco de cevadiss deixa as pessoas mais interessantis.
6191
</MessageEmbed>
6292
</MessageContent>
6393
</Message>

src/components/FieldsWrapper.jsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react'
2+
import styled from 'styled-components'
3+
4+
const Wrapper = styled.div`
5+
display: flex;
6+
flex-direction: row;
7+
flex-wrap: wrap;
8+
`
9+
10+
const Field = styled.div`
11+
margin-top: 8px;
12+
`;
13+
14+
const FieldTitle = styled.span`
15+
font-weight: 600;
16+
margin-bottom: 2px;
17+
font-size: 0.875rem;
18+
line-height: 1.125rem;
19+
min-width: 0;
20+
display: block;
21+
color: ${({ theme }) => theme.palette.embed.header}
22+
`
23+
24+
const FieldValue = styled.span`
25+
font-size: 0.875rem;
26+
line-height: 1.125rem;
27+
font-weight: 400;
28+
white-space: pre-line;
29+
min-width: 0;
30+
`
31+
32+
function FieldsWrapper(props) {
33+
return <Wrapper>
34+
{
35+
props.fields.map(field => <Field style={field.inline ? {
36+
flex: 1,
37+
minWidth: 150,
38+
flexBasis: 'auto'
39+
} : {
40+
flex: 0,
41+
minWidth: '100%',
42+
maxWidth: 506
43+
}}>
44+
<FieldTitle>{field.name}</FieldTitle>
45+
<FieldValue>{field.value}</FieldValue>
46+
</Field>)
47+
}
48+
</Wrapper>
49+
}
50+
51+
export default FieldsWrapper

src/components/MessageEmbed.jsx

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import styled from 'styled-components'
3+
import FieldsWrapper from './FieldsWrapper'
34

45
const Embed = styled.div`
56
max-wdth: 520px;
@@ -10,6 +11,10 @@ const Embed = styled.div`
1011
line-height: 1.375rem;
1112
`
1213

14+
const EmbedWrapper = styled.div`
15+
display: flex;
16+
`
17+
1318
const EmbedTitle = styled.span`
1419
display: block;
1520
font-weight: 600;
@@ -42,27 +47,81 @@ const AuthorIcon = styled.img`
4247
height: 24px;
4348
object-fit: contain;
4449
border-radius: 50%;
45-
}
50+
`
51+
52+
const FooterWrapper = styled.div`
53+
margin-top: 8px;
54+
display: flex;
55+
`
56+
57+
const FooterText = styled.span`
58+
font-size: 0.75rem;
59+
font-weight: 500;
60+
`
61+
62+
const FooterIcon = styled.img`
63+
margin-right: 8px;
64+
width: 20px;
65+
height: 20px;
66+
-o-object-fit: contain;
67+
object-fit: contain;
68+
border-radius: 50%;
69+
`
70+
71+
const Media = styled.img`
72+
max-width: 520px;
73+
border-radius: 4px;
74+
margin-top: 16px;
75+
`
76+
77+
const Thumbnail = styled.img`
78+
width: 80px;
79+
height: 80px;
80+
margin-left: 16px;
81+
margin-top: 8px;
82+
border-radius: 4px;
4683
`
4784

4885
function MessageEmbed(props) {
4986
return <Embed style={{
5087
borderColor: props.color
5188
}}>
52-
{
53-
props.author && props.author.name && <EmbedAuthorWrapper>
89+
<EmbedWrapper>
90+
<div>
5491
{
55-
props.author.icon && <AuthorIcon src={props.author.icon} />
92+
props.author && props.author.name && <EmbedAuthorWrapper>
93+
{
94+
props.author.icon && <AuthorIcon src={props.author.icon} />
95+
}
96+
<EmbedAuthor>{props.author.name}</EmbedAuthor>
97+
</EmbedAuthorWrapper>
5698
}
57-
<EmbedAuthor>{props.author.name}</EmbedAuthor>
58-
</EmbedAuthorWrapper>
99+
{
100+
props.title && <EmbedTitle>{props.title}</EmbedTitle>
101+
}
102+
<EmbedContent>
103+
{props.children}
104+
</EmbedContent>
105+
{
106+
props.fields && props.fields.length && <FieldsWrapper fields={props.fields} />
107+
}
108+
</div>
109+
{
110+
props.thumbnail && <Thumbnail src={props.thumbnail} />
111+
}
112+
</EmbedWrapper>
113+
114+
{
115+
props.image && <Media src={props.image} />
59116
}
60117
{
61-
props.title && <EmbedTitle>{props.title}</EmbedTitle>
118+
props.footer && props.footer.text && <FooterWrapper>
119+
{
120+
props.footer.icon && <FooterIcon src={props.footer.icon} />
121+
}
122+
<FooterText>{props.footer.text}</FooterText>
123+
</FooterWrapper>
62124
}
63-
<EmbedContent>
64-
{props.children}
65-
</EmbedContent>
66125
</Embed>
67126
}
68127

0 commit comments

Comments
 (0)