Skip to content

Commit 1dce847

Browse files
authored
Merge pull request #131 from xsnippet/bemi-2
Add bemi to all components
2 parents 997341c + c195bff commit 1dce847

File tree

12 files changed

+130
-94
lines changed

12 files changed

+130
-94
lines changed

src/components/Header.jsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import React from 'react'
22
import { NavLink } from 'react-router-dom'
33

4-
import '../styles/Header.styl'
4+
import bemi from 'bemi'
5+
56
import Logo from '../assets/icons/xsnippet.svg'
67

8+
import '../styles/Header.styl'
9+
10+
const header = bemi('header')
11+
712
const Header = () => (
8-
<header className="header" key="header">
9-
<div className="header-logo">
13+
<header className={header.b()}>
14+
<div className={header.e('logo')}>
1015
<NavLink exact to="/">
1116
<img src={Logo} alt="XSnippet" />
1217
</NavLink>
1318
</div>
14-
<div className="header-inner">
15-
<div className="header-slogan">
16-
<span className="header-slogan-x">X</span>SNIPPET
19+
<div className={header.e('inner')}>
20+
<div className={header.e('slogan')}>
21+
<span className={header.e('slogan-x')}>X</span>SNIPPET
1722
</div>
18-
<div className="header-sign-in">
23+
<div className={header.e('sign-in')}>
1924
<NavLink to="/sign-in">
2025
<span>Sign in</span>
2126
<i className="icon-user" />

src/components/NewSnippet.jsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useRef, useMemo } from 'react'
22
import { connect } from 'react-redux'
33
import AceEditor from 'react-ace'
44
import { WithContext as Tags } from 'react-tag-input'
5+
import bemi from 'bemi'
56

67
import 'brace/theme/textmate'
78

@@ -24,6 +25,8 @@ import '../styles/NewSnippet.styl'
2425

2526
const ListBoxWithSearch = withSearch(ListBox)
2627

28+
const newSnippet = bemi('new-snippet')
29+
2730
const NewSnippet = ({ dispatch, history, syntaxes }) => {
2831
const snippetHeader = useRef()
2932
const {
@@ -54,7 +57,7 @@ const NewSnippet = ({ dispatch, history, syntaxes }) => {
5457
const recalcLangHeaderHeight = () => {
5558
const height = snippetHeader.current.offsetHeight
5659

57-
document.getElementsByClassName('new-snippet-lang-header')[0]
60+
document.getElementsByClassName(newSnippet.e('lang-header'))[0]
5861
.setAttribute('style', `height:${height}px`)
5962
}
6063

@@ -86,13 +89,13 @@ const NewSnippet = ({ dispatch, history, syntaxes }) => {
8689

8790
return (
8891
<form
89-
className="new-snippet"
92+
className={newSnippet.b()}
9093
key="New Snippet"
9194
onSubmit={handleSubmit}
9295
role="presentation"
9396
>
94-
<div className="new-snippet-code-wrapper">
95-
<div className="new-snippet-code-header" ref={snippetHeader}>
97+
<div className={newSnippet.e('code-wrapper')}>
98+
<div className={newSnippet.e('code-header')} ref={snippetHeader}>
9699
<input
97100
className="input"
98101
placeholder="Title"
@@ -110,7 +113,7 @@ const NewSnippet = ({ dispatch, history, syntaxes }) => {
110113
delimiters={delimeterKeys}
111114
/>
112115
</div>
113-
<div className="new-snippet-code">
116+
<div className={newSnippet.e('code')}>
114117
<AceEditor
115118
mode={getCurrentModeName(syntax)}
116119
width="100%"
@@ -123,15 +126,15 @@ const NewSnippet = ({ dispatch, history, syntaxes }) => {
123126
value={content}
124127
onChange={(value) => handleChange(value, handleContent)}
125128
/>
126-
<div className="new-snippet-code-bottom-bar">
129+
<div className={newSnippet.e('code-bottom-bar')}>
127130
{renderValidationError()}
128131
<input type="submit" value="POST SNIPPET" />
129132
</div>
130133
</div>
131134
</div>
132-
<div className="new-snippet-lang-wrapper">
135+
<div className={newSnippet.e('lang-wrapper')}>
133136
<ListBoxWithSearch
134-
className="new-snippet-lang"
137+
className={newSnippet.e('lang')}
135138
items={memoizedSyntaxes}
136139
onClick={(syntax) => handleChange(syntax, handleSyntax)}
137140
/>

src/components/RecentSnippetItem.jsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import React from 'react'
22
import { Link } from 'react-router-dom'
3+
import bemi from 'bemi'
34

45
import { downloadSnippet } from '../misc/download'
56
import { getCurrentModeCaption } from '../misc/modes'
67
import { getSnippetTitle, formatDate } from '../misc/snippet'
78
import { getRawUrl } from '../misc/url'
89

10+
const rsi = bemi('recent-snippet')
11+
912
const RecentSnippetItem = ({ snippet }) => {
1013
const syntax = getCurrentModeCaption(snippet.get('syntax'))
1114
const title = getSnippetTitle(snippet)
@@ -14,22 +17,22 @@ const RecentSnippetItem = ({ snippet }) => {
1417
const download = () => downloadSnippet(snippet)
1518

1619
return (
17-
<li className="recent-snippet-item">
18-
<div className="recent-snippet-meta">
20+
<li className={rsi.e('item')}>
21+
<div className={rsi.e('meta')}>
1922
<div>
20-
<Link to={`${snippet.get('id')}`} className="recent-snippet-meta-title">{title}</Link>
21-
<div className="recent-snippet-meta-tags">
22-
{snippet.get('tags').map(item => <span className="recent-snippet-meta-tag" key={item}>{item}</span>)}
23+
<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>)}
2326
</div>
2427
</div>
25-
<span className="recent-snippet-meta-info">{formatDate(snippet.get('created_at'))}, by Guest</span>
28+
<span className={rsi.e('meta-info')}>{formatDate(snippet.get('created_at'))}, by Guest</span>
2629
</div>
27-
<div className="recent-snippet-actions">
28-
<span className="recent-snippet-lang">{syntax}</span>
30+
<div className={rsi.e('actions')}>
31+
<span className={rsi.e('lang')}>{syntax}</span>
2932
<div>
30-
<a href={rawUrl} className="recent-snippet-button light">Raw</a>
31-
<button className="recent-snippet-button light" onClick={download}>Download</button>
32-
<Link to={`${snippet.get('id')}`} className="recent-snippet-button">Show</Link>
33+
<a href={rawUrl} className={rsi.e('button', 'light')}>Raw</a>
34+
<button className={rsi.e('button', 'light')} onClick={download}>Download</button>
35+
<Link to={`${snippet.get('id')}`} className={rsi.e('button')}>Show</Link>
3336
</div>
3437
</div>
3538
</li>

src/components/RecentSnippets.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { Fragment, useEffect } from 'react'
22
import { connect } from 'react-redux'
3+
import bemi from 'bemi'
34

45
import RecentSnippetItem from './RecentSnippetItem'
56

@@ -11,6 +12,9 @@ const scrollTop = () => {
1112
window.scroll({ top: 0, behavior: 'smooth' })
1213
}
1314

15+
const rsi = bemi('recent-snippet')
16+
const pag = bemi('pagination')
17+
1418
const RecentSnippets = ({ dispatch, pagination, snippets, recent }) => {
1519
const older = pagination.get('next')
1620
const newer = pagination.get('prev')
@@ -46,24 +50,24 @@ const RecentSnippets = ({ dispatch, pagination, snippets, recent }) => {
4650
}
4751

4852
const renderRecentSnippets = () => (
49-
<ul className="recent-snippet" key="recent-snippet">
53+
<ul className={rsi.b()}>
5054
{recent.map(id => <RecentSnippetItem key={id} snippet={snippets.get(id)} />)}
5155
</ul>
5256
)
5357

5458
return (
5559
<Fragment>
5660
{renderRecentSnippets()}
57-
<div className="pagination" key="pagination">
61+
<div className={pag.b()}>
5862
<span
59-
className={`pagination-item next ${newer ? '' : 'disabled'}`}
63+
className={pag.e('item', { next: true, disabled: !newer })}
6064
onClick={newerSetOfSnippets}
6165
role="presentation"
6266
>
6367
&lsaquo; Newer
6468
</span>
6569
<span
66-
className={`pagination-item prev ${older ? '' : 'disabled'}`}
70+
className={pag.e('item', { prev: true, disabled: !older })}
6771
onClick={olderSetOfSnippets}
6872
role="presentation"
6973
>

src/components/Sidebar.jsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import React from 'react'
22
import { NavLink } from 'react-router-dom'
3+
import bemi from 'bemi'
34

45
import '../styles/Sidebar.styl'
56

7+
const sidebar = bemi('sidebar')
8+
69
const Sidebar = () => (
7-
<nav className="sidebar" key="navigation">
8-
<ul className="sidebar-list">
9-
<li className="sidebar-item">
10+
<nav className={sidebar.b()}>
11+
<ul className={sidebar.e('list')}>
12+
<li className={sidebar.e('item')}>
1013
<NavLink exact to="/" activeClassName="active" title="New Snippet">
1114
<i className="icon-new" />
1215
</NavLink>
1316
</li>
14-
<li className="sidebar-item sidebar-item-border">
17+
<li className={sidebar.e('item', 'border')}>
1518
<NavLink to="/recent" activeClassName="active" title="Recent Snippets">
1619
<i className="icon-recent" />
1720
</NavLink>
1821
</li>
19-
<li className="sidebar-item">
22+
<li className={sidebar.e('item')}>
2023
<NavLink to="/about" activeClassName="active" title="About">
2124
<i className="icon-about" />
2225
</NavLink>

src/components/Snippet.jsx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useEffect, useState, useRef } from 'react'
22
import { connect } from 'react-redux'
33
import AceEditor from 'react-ace'
4+
import bemi from 'bemi'
45

56
import 'brace/theme/textmate'
67

@@ -18,6 +19,8 @@ import { existingSnippetOptions } from '../entries/aceEditorOptions'
1819

1920
import '../styles/Snippet.styl'
2021

22+
const block = bemi('snippet')
23+
2124
const Snippet = props => {
2225
const { snippet, dispatch } = props
2326
const [ isShowEmbed, setIsShowEmbed ] = useState(false)
@@ -49,10 +52,10 @@ const Snippet = props => {
4952
const rawUrl = getRawUrl(snippet.get('id'))
5053

5154
const renderEmbed = () => (
52-
<div className={`snippet-embed ${isShowEmbed}`}>
53-
<div className="snippet-embed-content">
54-
<span className="snippet-embed-close" onClick={toggleEmbed} role="presentation" />
55-
<p className="snippet-embed-text">
55+
<div className={block.e('embed', { show: isShowEmbed, hide: !isShowEmbed })}>
56+
<div className={block.e('embed-content')}>
57+
<span className={block.e('embed-close')} onClick={toggleEmbed} role="presentation" />
58+
<p className={block.e('embed-text')}>
5659
In order to embed this content into your website or blog,
5760
simply copy and paste code provided below:
5861
</p>
@@ -62,36 +65,36 @@ const Snippet = props => {
6265
type="text"
6366
defaultValue={`<script src='http://xsnippet.org/${snippet.get('id')}/embed/'></script>`}
6467
/>
65-
<button className="snippet-button embed" onClick={copyToClipboard}>Copy</button>
68+
<button className={block.e('button', 'embed')} onClick={copyToClipboard}>Copy</button>
6669
</div>
6770
</div>
6871
)
6972

7073
const renderTags = () => (
71-
<div className="snippet-data-tags">
72-
{snippet.get('tags').map(item => <span className="snippet-data-tag" key={item}>{item}</span>)}
74+
<div className={block.e('data-tags')}>
75+
{snippet.get('tags').map(item => <span className={block.e('data-tag')} key={item}>{item}</span>)}
7376
</div>
7477
)
7578

76-
const renderMetadata = () => (<span className="snippet-data-meta">{formatDate(snippet.get('created_at'))}, by Guest</span>)
79+
const renderMetadata = () => (<span className={block.e('data-meta')}>{formatDate(snippet.get('created_at'))}, by Guest</span>)
7780

7881
return (
79-
<div className="snippet" key="Snippet">
80-
<div className="snippet-header">
81-
<div className="snippet-data">
82-
<span className="snippet-data-title">{title}</span>
82+
<div className={block.b()}>
83+
<div className={block.e('header')}>
84+
<div className={block.e('data')}>
85+
<span className={block.e('data-title')}>{title}</span>
8386
{renderTags()}
8487
{renderMetadata()}
8588
</div>
86-
<div className="snippet-data-actions">
87-
<span className="snippet-data-lang">{syntax}</span>
89+
<div className={block.e('data-actions')}>
90+
<span className={block.e('data-lang')}>{syntax}</span>
8891
<div>
89-
<a href={rawUrl} className="snippet-button">Raw</a>
90-
<button className="snippet-button snippet-button-download" onClick={download}>
92+
<a href={rawUrl} className={block.e('button')}>Raw</a>
93+
<button className={block.e('button', 'download')} onClick={download}>
9194
Download
9295
</button>
9396
<button
94-
className={`toggle-embed snippet-button ${isShowEmbed}`}
97+
className={`${block.e('button', { show: isShowEmbed, hide: !isShowEmbed })} toggle-embed`}
9598
key="snippet-details"
9699
onClick={toggleEmbed}
97100
onKeyPress={toggleEmbed}
@@ -102,7 +105,7 @@ const Snippet = props => {
102105
</div>
103106
</div>
104107
{renderEmbed()}
105-
<div className="snippet-code">
108+
<div className={block.e('code')}>
106109
<AceEditor
107110
mode={snippet.get('syntax')}
108111
width="100%"

src/styles/Header.styl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
height: offset
1414
z-index: 5
1515
box-shadow: 0 2px 2px 0 border-dark
16-
&-inner
16+
17+
&__inner
1718
display: flex
1819
flex-flow: row nowrap
1920
justify-content: space-between
2021
align-items: center
2122
width: "calc(100% - %s)" % offset
22-
&-logo
23+
24+
&__logo
2325
width: offset
2426
height: offset
2527
background-color: header-logo-bg
@@ -30,7 +32,8 @@
3032
align-items: center
3133
& img
3234
width: 78%
33-
&-slogan
35+
36+
&__slogan
3437
color:text-dark
3538
font-family: font-raleway
3639
font-size: 23px
@@ -39,7 +42,8 @@
3942
letter-spacing: .6px
4043
&-x
4144
color: text-green
42-
&-sign-in
45+
46+
&__sign-in
4347
display: none
4448
pointer-events: none
4549
margin-right: 20px

0 commit comments

Comments
 (0)