Skip to content

Commit ea224ef

Browse files
committed
updated css-modules example
1 parent 144389c commit ea224ef

File tree

3 files changed

+48
-35
lines changed

3 files changed

+48
-35
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ Local HTTP dev server with hot-reload out-of-the-box - highly reliable and scala
3636
If you are coding in a NO-IDE environment (notepad/vim) or expecting to have a common way across a team to target a specific version of typescript compiler even while using different Editors/IDEs, you can utilize __CLI type-checking workflow__ using `tsc -p src --watch` command for fast incremental type-checking or `tsc -p src` command for project-wide type-check, there is no JS emit so it will not clutter your project or disrupt different build processes based on various IDE plugins or gulp/grunt based tasks.
3737
(animated gif placeholder...)
3838

39-
### TYPED-CSS-MODULES
40-
My concept to achieve locally scoped CSS styles with some enhancements using (csjs)[https://github.com/rtsao/csjs#faq]
41-
Full CSS support with all features like pseudo-classes & media queries, encapsulated in TypeScript (ES6 modules) can be easily imported by your UI components.
42-
BONUS: statically typed class names helping with auto-completion, simple type-checking, easy refactoring and doc comments.
39+
### CSS-MODULES WITH TYPED CLASS-NAMES
40+
My concept to achieve locally scoped CSS styles with some TypeScript enhancements using (csjs)[https://github.com/rtsao/csjs#faq]
41+
Full CSS support with all features like pseudo-classes & media queries, encapsulated in ES6 modules can be easily imported by your UI components.
42+
BONUS: statically typed class names - solid auto-completion, type-checking, easy refactoring. You can also add doc comments and auto-generate docs of your styles library for your team or utilize some powerful IDE support.
4343
EXAMPLE: (about-container component)[src/containers/about-container/index.tsx] and it's (about-styles css-module)[src/containers/about-container/about-styles.tsx]
4444
(animated gif placeholder...)
4545

src/containers/about-container/about-styles.tsx

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,82 @@ import csjs from 'csjs';
22
import insertCss from 'insert-css';
33
import colors from '../../themes/colors';
44

5-
interface IStyles {
5+
interface AboutStyles {
6+
/** main content container */
67
container: string;
7-
well: string;
8+
textCentered: string;
9+
/** text with fancy highlight */
810
glowingText: string;
9-
visibleWell: string;
10-
supriseWell: string;
11+
/** dark background with border */
12+
darkBg: string;
13+
/** elevate element using box-shadow */
14+
effect__elevate: string;
15+
/** hide element on mobile screen */
16+
effect__hideOnMobile: string;
17+
/** show element on mobile screen */
18+
effect__showOnMobile: string;
1119
}
1220

13-
export const styles: IStyles = csjs`
21+
export const aboutStyles: AboutStyles = csjs`
1422
15-
.container {
23+
.textCentered {
1624
text-align: center;
1725
}
1826
.glowingText {
1927
color: ${colors.textColor};
2028
text-shadow: ${colors.textColor} 0 0 10px;
2129
white-space: nowrap;
2230
}
23-
.well {
31+
.darkBg {
2432
border-radius: 5px;
2533
border: 1px solid ${colors.borderColor};
2634
background-color: ${colors.backgroundColor};
35+
}
36+
37+
.effect__elevate {
2738
box-shadow: none;
39+
transition: box-shadow 0.5s linear;
2840
}
29-
.well:hover {
41+
.effect__elevate:hover {
3042
box-shadow: 0 6px 20px 0 ${colors.shadowColor};
3143
}
3244
33-
.visibleWell extends .well {
45+
.effect__hideOnMobile {
3446
margin: 0px 30px;
3547
opacity: 1;
3648
transition:
3749
margin 1s 0.5s,
38-
opacity 1s 0.5s,
39-
box-shadow 0.5s linear;
50+
opacity 1s 0.5s;
4051
}
4152
42-
.supriseWell extends .well {
53+
.effect__showOnMobile {
4354
margin: 0px 50px;
4455
opacity: 0;
4556
transition:
4657
margin 1s,
47-
opacity 1s,
48-
box-shadow 0.5s linear;
58+
opacity 1s;
4959
}
5060
5161
@media (max-width: 450px) {
52-
.supriseWell {
62+
.effect__hideOnMobile {
63+
margin: 0px 50px;
64+
opacity: 0;
65+
transition:
66+
margin 1s,
67+
opacity 1s,
68+
box-shadow 0.5s linear;
69+
}
70+
71+
.effect__showOnMobile {
5372
margin: 0px 30px;
5473
opacity: 1;
5574
transition:
5675
margin 1s 0.5s,
5776
opacity 1s 0.5s,
5877
box-shadow 0.5s linear;
5978
}
60-
.visibleWell {
61-
margin: 0px 50px;
62-
opacity: 0;
63-
transition:
64-
margin 1s,
65-
opacity 1s,
66-
box-shadow 0.5s linear;
67-
}
6879
}
6980
7081
`;
7182

72-
insertCss(csjs.getCss(styles));
83+
insertCss(csjs.getCss(aboutStyles));

src/containers/about-container/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import * as React from 'react';
22
import { PageSection } from '../../components/page-section';
33
import { PageHeader } from '../../components/page-header';
4-
import { styles } from './about-styles';
4+
import { aboutStyles } from './about-styles';
55

66

77
export function AboutContainer() {
88
return (
99
<article>
1010
<PageHeader>About</PageHeader>
11-
<PageSection>
12-
<div className={styles.container}>
13-
<div className={styles.visibleWell}>
14-
<p className={styles.glowingText}>
11+
<PageSection className={aboutStyles.textCentered}>
12+
<div className={aboutStyles.effect__hideOnMobile}>
13+
<div className={[aboutStyles.darkBg, aboutStyles.effect__elevate].join(' ')}>
14+
<p className={aboutStyles.glowingText}>
1515
Shrink your window
1616
</p>
1717
</div>
18-
<div className={styles.supriseWell}>
19-
<p className={styles.glowingText}>
18+
</div>
19+
<div className={aboutStyles.effect__showOnMobile}>
20+
<div className={[aboutStyles.darkBg, aboutStyles.effect__elevate].join(' ')}>
21+
<p className={aboutStyles.glowingText}>
2022
SUPRISE!!!
2123
</p>
2224
</div>

0 commit comments

Comments
 (0)