Skip to content

Commit f248735

Browse files
authored
Merge pull request #135 from xsnippet/tags
[TAGS] Separate tags into component to be able to reuse
2 parents 4ea5666 + 8b26fef commit f248735

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

src/components/RecentSnippetItem.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from 'react'
22
import { Link } from 'react-router-dom'
33
import bemi from 'bemi'
44

5+
import SnippetTags from './common/SnippetTags'
6+
57
import { downloadSnippet } from '../misc/download'
68
import { getCurrentModeCaption } from '../misc/modes'
79
import { getSnippetTitle, formatDate } from '../misc/snippet'
@@ -21,9 +23,7 @@ const RecentSnippetItem = ({ snippet }) => {
2123
<div className={rsi.e('meta')}>
2224
<div>
2325
<Link to={`${snippet.get('id')}`} className={rsi.e('meta-title')}>{title}</Link>
24-
<div className={rsi.e('meta-tags')}>
25-
{snippet.get('tags').map(item => <span className={rsi.e('meta-tag')} key={item}>{item}</span>)}
26-
</div>
26+
<SnippetTags className={rsi} snippet={snippet} />
2727
</div>
2828
<span className={rsi.e('meta-info')}>{formatDate(snippet.get('created_at'))}, by Guest</span>
2929
</div>

src/components/Snippet.jsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import bemi from 'bemi'
55

66
import 'brace/theme/textmate'
77

8+
import SnippetTags from './common/SnippetTags'
89
import Spinner from './common/Spinner'
910

1011
import { fetchSnippet } from '../actions'
@@ -69,20 +70,14 @@ const Snippet = ({ snippet, fetchSnippet, match }) => {
6970
</div>
7071
)
7172

72-
const renderTags = () => (
73-
<div className={block.e('data-tags')}>
74-
{snippet.get('tags').map(item => <span className={block.e('data-tag')} key={item}>{item}</span>)}
75-
</div>
76-
)
77-
7873
const renderMetadata = () => (<span className={block.e('data-meta')}>{formatDate(snippet.get('created_at'))}, by Guest</span>)
7974

8075
return (
8176
<div className={block.b()}>
8277
<div className={block.e('header')}>
8378
<div className={block.e('data')}>
8479
<span className={block.e('data-title')}>{title}</span>
85-
{renderTags()}
80+
<SnippetTags className={block} snippet={snippet} />
8681
{renderMetadata()}
8782
</div>
8883
<div className={block.e('data-actions')}>

src/components/common/SnippetTags.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react'
2+
3+
const SnippetTags = ({ className, snippet }) => {
4+
return (
5+
<div className={className.e('meta-tags')}>
6+
{snippet.get('tags').map(item => <span className={className.e('meta-tag')} key={item}>{item}</span>)}
7+
</div>
8+
)
9+
}
10+
11+
export default SnippetTags

src/styles/Snippet.styl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ button-group-width = 312px
1919
border-left: 40px solid snippet-header-border
2020
font-family: font-roboto
2121

22+
&__meta
23+
&-tags
24+
margin: 10px 0
25+
&-tag
26+
margin-right: 5px
27+
padding: 3px 8px
28+
font-size: 12px
29+
font-weight: 300
30+
color: text-light
31+
border-radius: 9.5px
32+
background-color: rgba(text-light, .2)
33+
letter-spacing: .4px
34+
&:last-shild
35+
margin-right: 0
36+
2237
&__data
2338
display: flex
2439
flex-flow: column nowrap
@@ -32,8 +47,6 @@ button-group-width = 312px
3247
display: block
3348
margin-top: 7px
3449
font-size: 14px
35-
&-tags
36-
margin: 10px 0
3750
&-actions
3851
display: flex
3952
flex-flow: column nowrap
@@ -45,17 +58,6 @@ button-group-width = 312px
4558
color: snippet-header-data
4659
font-size: 12px
4760
font-weight: 300
48-
&-tag
49-
margin-right: 5px
50-
padding: 3px 8px
51-
font-size: 12px
52-
font-weight: 300
53-
color: text-light
54-
border-radius: 9.5px
55-
background-color: rgba(text-light, .2)
56-
letter-spacing: .4px
57-
&:last-shild
58-
margin-right: 0
5961

6062
&__button
6163
margin-right: 10px

0 commit comments

Comments
 (0)