Skip to content

Commit b79d30d

Browse files
committed
Improve documentation
1 parent 4f93557 commit b79d30d

File tree

12 files changed

+97
-47
lines changed

12 files changed

+97
-47
lines changed

src/components/App.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React, { Component } from 'react';
22

3-
import HelloWorld from './HelloWorld/HelloWorld';
4-
import FooBar from './FooBar/FooBar';
5-
3+
import ScopedSelectors from './ScopedSelectors/ScopedSelectors';
4+
import ClassInheritance from './ClassInheritance/ClassInheritance';
65
import InheritanceOverrides from './InheritanceOverrides/InheritanceOverrides';
7-
8-
import BouncingBall from './BouncingBall/BouncingBall';
6+
import ScopedAnimations from './ScopedAnimations/ScopedAnimations';
97

108
export default class App extends Component {
119

@@ -14,23 +12,27 @@ export default class App extends Component {
1412
<div>
1513
<h1>CSS Modules Example</h1>
1614

17-
<p>Below we have two components: <strong>HelloWorld</strong> and <strong>FooBar</strong>.</p>
18-
<p>Both of these components have <strong>locally scoped CSS</strong> that inherit from a common set of CSS Modules.</p>
19-
<p>Since CSS Modules can be composed, the resulting markup is optimised by <b>reusing classes between components</b>.</p>
15+
<h2>Scoped Selectors</h2>
16+
<p>In CSS Modules, selectors are scoped by default.</p>
17+
<p>The following component uses two classes, <strong>.root</strong> and <strong>.text</strong>, both of which would typically be too vague in a larger project.</p>
18+
<p>CSS Module semantics ensure that these <strong>classes are locally scoped</strong> to the component and don't collide with other classes in the global scope.</p>
19+
<ScopedSelectors />
2020

21-
<HelloWorld />
22-
<br />
23-
<FooBar />
21+
<h2>Class Inheritance</h2>
22+
<p>Both of the components below have <strong>locally scoped CSS</strong> that <strong>inherits from a common set of CSS Modules.</strong></p>
23+
<p>Since CSS Modules can be composed, the resulting markup is optimised by <b>reusing classes between components</b>.</p>
24+
<ClassInheritance />
2425

26+
<h2>Inheritance Overrides</h2>
2527
<p>When extending classes, <strong>inherited style properties can be overridden</strong> as you'd expect.</p>
2628
<p>The following component extends two different classes, but provides overrides which then take precedence.</p>
2729
<InheritanceOverrides />
2830

29-
<p>CSS Modules even provide <strong>locally scoped animations</strong>, which are typically defined in the global scope.</p>
30-
<p>The following <strong>BouncingBall</strong> component extends a <strong>".bounce"</strong> class from a separate animations module.</p>
31-
<p>The <strong>"bounce"</strong> keyframes are private to the animations module, only exposed via the <strong>".bounce"</strong> class to those that either extend from it or import it.</p>
31+
<h2>Scoped Animations</h2>
3232

33-
<BouncingBall />
33+
<p>CSS Modules even provide <strong>locally scoped animations</strong>, which are typically defined in the global scope.</p>
34+
<p>The animation's keyframes are private to the animations module, only exposed publicly via a class which this component inherits from.</p>
35+
<ScopedAnimations />
3436

3537
</div>
3638
);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React, { Component } from 'react';
2+
3+
import StyleVariantA from './StyleVariantA/StyleVariantA';
4+
import StyleVariantB from './StyleVariantB/StyleVariantB';
5+
6+
export default class ClassInheritance extends Component {
7+
8+
render() {
9+
return (
10+
<div>
11+
<StyleVariantA />
12+
<br />
13+
<StyleVariantB />
14+
</div>
15+
);
16+
}
17+
18+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import styles from './StyleVariantA.css';
2+
3+
import React, { Component } from 'react';
4+
5+
export default class StyleVariantA extends Component {
6+
7+
render() {
8+
return (
9+
<div className={styles.root}>
10+
<p className={styles.text}>Style Variant A</p>
11+
</div>
12+
);
13+
}
14+
15+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import styles from './StyleVariantB.css';
2+
3+
import React, { Component } from 'react';
4+
5+
export default class StyleVariantB extends Component {
6+
7+
render() {
8+
return (
9+
<div className={styles.root}>
10+
<p className={styles.text}>Style Variant B</p>
11+
</div>
12+
);
13+
}
14+
15+
};

src/components/FooBar/FooBar.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/components/HelloWorld/HelloWorld.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/components/BouncingBall/BouncingBall.js renamed to src/components/ScopedAnimations/ScopedAnimations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import styles from './BouncingBall.css';
1+
import styles from './ScopedAnimations.css';
22

33
import React, { Component } from 'react';
44

5-
export default class BouncingBall extends Component {
5+
export default class ScopedAnimations extends Component {
66

77
render() {
88
return (

0 commit comments

Comments
 (0)