Block, Element, Modifying Your JavaScript Components

Mark Dalgleish
Apr 30, 2015 · 6 min read
<div class="my-page">
<header class="header">
<h1 class="heading header__heading">...</h1>
</header>
<article class="post">
<header class="post__header">
<h1 class="heading post__header__heading">Hello World</h1>
</header>
<section class="post__content">...</section>
</article>
<footer class="footer">...</footer>
</div>

“Thinking in components” is fundamentally different to how we’ve worked before.


Soon enough we find that we’ve created a wide gulf between how we picture our ever-growing asset graph, and how it’s actually described in code.


import MyComponent from ‘./MyComponent’;
require('./MyComponent.less');import { Component } from 'react';export default class MyComponent extends Component {
render() {
return (
<div className="MyComponent">
<div className="MyComponent__Icon">Icon</div>
...
</div>
);
}
}
.MyComponent__Icon {
background-image: url('icon.svg');
background-position: 0 50%;
background-size: fit;
height: 50px;
}
// webpack.config.js:loaders: [
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style',
'css!autoprefixer!less')
},
{
test: /\.svg$/,
loader: 'url?limit=10000&mimetype=image/svg+xml'
},
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
}
]

Blocks should only be used inside a component of the same name.


require('./MyPage.less');import { Component } from 'react';import Header from 'Header';
import Post from 'Post';
import Footer from 'Footer';
export default class MyPage extends Component {
render() {
return (
<div className="MyPage">
<Header />
<Post title="Hello World" content="..." />
<Footer />
</div>
);
}
};


SEEK blog

At SEEK we’ve created a community of valued, talented…

Thanks to Michael Taranto

Mark Dalgleish

Written by

CSS Modules co-creator, @MelbJS organiser, DesignOps Lead at @seekjobs.

SEEK blog

SEEK blog

At SEEK we’ve created a community of valued, talented, diverse individuals that really know their stuff. Enjoy our Product & Technical insights…

Mark Dalgleish

Written by

CSS Modules co-creator, @MelbJS organiser, DesignOps Lead at @seekjobs.

SEEK blog

SEEK blog

At SEEK we’ve created a community of valued, talented, diverse individuals that really know their stuff. Enjoy our Product & Technical insights…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store