Skip to content
This repository was archived by the owner on Jun 17, 2021. It is now read-only.

Commit 98e31c5

Browse files
committed
add editorconfig and update variants system
1 parent b92dfd2 commit 98e31c5

File tree

5 files changed

+55
-20
lines changed

5 files changed

+55
-20
lines changed

.editorconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
8+
[*]
9+
# change these settings to your own preference
10+
indent_style = space
11+
indent_size = 2
12+
13+
# we recommend you to keep these unchanged
14+
end_of_line = lf
15+
charset = utf-8
16+
trim_trailing_whitespace = true
17+
insert_final_newline = true
18+
19+
[*.md]
20+
trim_trailing_whitespace = false
21+
22+
# PHP should follow the PSR-2 standard
23+
# https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
24+
[*.php]
25+
indent_size = 4
26+
27+
[{package,bower}.json]
28+
indent_style = space
29+
indent_size = 2

src/components/App/App.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ class App extends Component {
2929
const slug = val.split('/')[val.split('/').length - 1];
3030
const content = this.getMarkup(val, slug);
3131
const config = yaml.load(this.fixPath(`${val}/${slug}.yml`));
32-
const variants = config && config.variants ? config.variants.map((variant) => this.getMarkup(val, `${slug}-${variant}`)) : null;
32+
const variants = config && config.variants ? Object.keys(config.variants).map((key) => {
33+
return {
34+
title: config.variants[key],
35+
twig: this.getMarkup(val, `${slug}-${key}`),
36+
};
37+
}) : null;
38+
console.log(variants);
3339
const component = { config, content, slug, variants };
3440

3541
if (val.includes('/atoms/')) acc.atoms.push(component);

src/views/Item/Item.css

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
.tlbx-item {
2-
border: 1px solid #ccc;
3-
border-radius: 3px;
4-
padding: 20px;
5-
background: #fff;
6-
}
7-
81
.tlbx-item-code {
92
margin: 2rem 0 0;
103
}

src/views/Item/Item.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ registerLanguage('html', xml);
1111

1212
class Item extends Component {
1313
render() {
14+
const title = this.props.title && <h3 className="tlbx-item-title">{this.props.title}</h3>;
15+
1416
return (
1517
<div className="tlbx-item">
18+
{title}
1619
<div className="tlbx-item-preview" dangerouslySetInnerHTML={{ __html: this.props.children }} />
1720
<div className="tlbx-item-code">
18-
<SyntaxHighlighter
19-
language='html'
21+
<SyntaxHighlighter
22+
language='html'
2023
style={atomOneDark}
2124
>
2225
{this.props.children}
@@ -27,4 +30,4 @@ class Item extends Component {
2730
}
2831
}
2932

30-
export default inject('store')(observer(Item));
33+
export default inject('store')(observer(Item));

src/views/Single/Single.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Single extends Component {
3434

3535
getContent(props) {
3636
const params = props.match.params;
37-
const components = props.store.components[params.type];
37+
const components = props.store.components[params.type];
3838
const component = components.find(item => item.slug === params.slug);
3939

4040
this.setState({ component, variants: [] });
@@ -44,9 +44,15 @@ class Single extends Component {
4444
});
4545

4646
if (component.variants) {
47-
component.variants.forEach((variant) => {
48-
variant.then(twig => {
49-
this.setState({ variants: [...this.state.variants, twig.render(this.props.store.data)] });
47+
component.variants.forEach((variant, key) => {
48+
variant.twig.then(twig => {
49+
this.setState({ variants: [
50+
...this.state.variants,
51+
{
52+
title: variant.title,
53+
markup: twig.render(this.props.store.data)
54+
}
55+
]});
5056
});
5157
});
5258
}
@@ -55,10 +61,8 @@ class Single extends Component {
5561
render() {
5662
const variants = this.state.variants.length > 0 && (
5763
<div>
58-
<h2 className="tlbx-h2">Variants</h2>
59-
6064
{this.state.variants.map((variant, key) => {
61-
return <Item key={key}>{variant}</Item>;
65+
return <Item key={key} title={variant.title}>{variant.markup}</Item>;
6266
})}
6367
</div>
6468
);
@@ -67,7 +71,7 @@ class Single extends Component {
6771
<div>
6872
<h1 className="tlbx-h1">{this.state.component.config.title}</h1>
6973
<p className="tlbx-notes">{this.state.component.config.notes}</p>
70-
74+
7175
<Item>{this.state.content}</Item>
7276

7377
{variants}
@@ -80,4 +84,4 @@ Single.propTypes = {
8084
components: PropTypes.object,
8185
};
8286

83-
export default inject('store')(observer(Single));
87+
export default inject('store')(observer(Single));

0 commit comments

Comments
 (0)