Skip to content

Commit fa49001

Browse files
committed
Add support for sub-themes
e.g. ``` baseFontSize: '16px' subThemes: { blog: { baseFontSize: '18px' bodyFontFamily: 'Open Sans' }} ```
1 parent cdbb4ad commit fa49001

File tree

5 files changed

+229
-137
lines changed

5 files changed

+229
-137
lines changed

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
"gray-percentage": "^1.1.2",
1313
"is-array": "^1.0.1",
1414
"is-string": "^1.0.4",
15-
"modularscale": "^1.0.2"
15+
"isobject": "^1.0.0",
16+
"lodash": "^3.9.3",
17+
"modularscale": "^1.0.2",
18+
"object-assign": "^3.0.0",
19+
"shallow-copy": "0.0.1",
20+
"shelljs": "^0.5.3"
1621
},
1722
"devDependencies": {
1823
"chai": "^3.0.0",
@@ -30,7 +35,6 @@
3035
"node-libs-browser": "^0.5.2",
3136
"object-assign": "^3.0.0",
3237
"parse-unit": "^1.0.1",
33-
"pre-commit": "^1.0.7",
3438
"qs": "^3.1.0",
3539
"react": "^0.13.3",
3640
"react-headroom": "^1.6.1",
@@ -47,8 +51,7 @@
4751
"webpack-dev-server": "^1.9.0"
4852
},
4953
"directories": {
50-
"example": "examples",
51-
"test": "test"
54+
"example": "examples"
5255
},
5356
"homepage": "https://github.com/KyleAMathews/react-typography",
5457
"keywords": [
@@ -65,8 +68,6 @@
6568
"url": "https://github.com/KyleAMathews/react-typography.git"
6669
},
6770
"scripts": {
68-
"test": "node_modules/.bin/coffeelint test/* & NODE_ENV=test node_modules/.bin/mocha --recursive --compilers coffee:coffee-script/register -R mocha-unfunk-reporter",
69-
"test-watch": "NODE_ENV=test node_modules/.bin/mocha -w --recursive --compilers coffee:coffee-script/register -R mocha-unfunk-reporter",
7071
"watch": "./node_modules/.bin/webpack-dev-server --hot"
7172
}
7273
}

src/components/GoogleFont.cjsx renamed to src/components/GoogleFont.coffee

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ module.exports = (options) ->
1818
fontsStr = fonts.join('|')
1919

2020
if fontsStr
21-
<link
22-
href="//fonts.googleapis.com/css?family=#{fontsStr}"
23-
rel="stylesheet"
24-
type="text/css"
25-
/>
21+
React.DOM.link({
22+
href: "//fonts.googleapis.com/css?family=#{fontsStr}"
23+
rel: "stylesheet"
24+
type: "text/css"
25+
})
2626
else
2727
null

src/components/TypographyStyle.cjsx renamed to src/components/TypographyStyle.coffee

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = (styles) ->
1010
displayName: "TypographyStyle"
1111

1212
render: ->
13-
<style
14-
id="typography.js"
15-
dangerouslySetInnerHTML={{__html: styles}}
16-
/>
13+
React.DOM.style({
14+
id: "typography.js"
15+
dangerouslySetInnerHTML:
16+
__html: styles
17+
})

src/index.coffee

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
React = require 'react'
2-
objectAssign = require('react/lib/Object.assign')
2+
objectAssign = require('object-assign')
33
VerticalRhythm = require 'compass-vertical-rhythm'
44
ms = require 'modularscale'
55
isArray = require 'is-array'
6+
isObject = require 'isobject'
7+
copy = require 'shallow-copy'
68

7-
module.exports = (options) ->
9+
createStyles = require('./utils/createStyles')
10+
11+
module.exports = test = (options) ->
812
defaults =
913
baseFontSize: '18px'
1014
baseLineHeight: '28.5px'
@@ -24,14 +28,23 @@ module.exports = (options) ->
2428
boldWeight: 700
2529
fontFaces: []
2630

27-
options = objectAssign defaults, options
31+
options = objectAssign(defaults, options)
32+
33+
if options.subThemes? and isObject(options.subThemes)
34+
for name, theme of options.subThemes
35+
options.subThemes[name] = objectAssign(copy(options), theme, rhythmUnit: 'px')
2836

2937
unless isArray options.modularScales
3038
options.modularScales = [options.modularScales]
3139

40+
# Create styles for base theme + each subtheme.
3241
vr = VerticalRhythm(options)
42+
styles = createStyles(vr, options)
3343

34-
styles = require('./utils/createStyles')(vr, options)
44+
if options.subThemes? and isObject(options.subThemes)
45+
for name, theme of options.subThemes
46+
vr = VerticalRhythm(theme)
47+
styles += createStyles(vr, theme, name, options)
3548

3649
return {
3750
options: options
@@ -49,3 +62,11 @@ module.exports = (options) ->
4962
node.innerHTML = styles
5063
document.head.appendChild(node)
5164
}
65+
66+
#console.log test({
67+
#baseFontSize: '16px'
68+
#subThemes:
69+
#blog:
70+
#baseFontSize: '18px'
71+
#bodyFontFamily: 'Open Sans'
72+
#}).styles

0 commit comments

Comments
 (0)