Skip to content

Commit

Permalink
feat(react): Introduce React typography components
Browse files Browse the repository at this point in the history
* Add Heading generator and three type systems which
wrap it (Default, Alternate, Marketing)
* Add JSX support in the style guide
* Point hologram to a fork for jsx support

[Finishes #84033714]

Signed-off-by: Paul Meskers <pmeskers@pivotal.io>
  • Loading branch information
stubbornella committed Dec 12, 2014
1 parent 297cf79 commit 64ccd18
Show file tree
Hide file tree
Showing 7 changed files with 470 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'hologram', git: 'https://github.com/gpleiss/hologram.git', branch: 'develop'
gem 'hologram', git: 'https://github.com/pmeskers/hologram.git', branch: 'jsx-templates'
gem 'haml'
gem 'sass'
gem 'compass', '~> 1.0.1'
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/gpleiss/hologram.git
revision: 64b3baf29654476425947967d982e070b2199061
branch: develop
remote: https://github.com/pmeskers/hologram.git
revision: 9de4273497a5ea61f0c335969ab661cd0fa2f54e
branch: jsx-templates
specs:
hologram (1.2.0)
redcarpet (>= 2.2, < 4.0)
Expand Down Expand Up @@ -52,8 +52,8 @@ GEM
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
redcarpet (3.2.0)
rouge (1.7.2)
redcarpet (3.2.1)
rouge (1.7.4)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
Expand Down
1 change: 1 addition & 0 deletions hologram/doc_assets/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<script src="pivotal-ui-react.js"></script>
<script src="styleguide/styleguide.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.0.js"></script>
</head>
<body>
<nav class="styleguide-header">
Expand Down
103 changes: 103 additions & 0 deletions src/pivotal-ui/components/typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,106 @@ a:hover.type-inverse {
color: $error-color !important;
}

/*doc
---
title: React Typography
name: type_react
category: Beta
---
We have three type systems. Which one you choose depends on your product.
* Marketing sites should use the largest styles, for example `<MarketingH1>A Top Level Heading</MarketingH1>`
* Most sites will use our default headings, for example `<DefaultH1>A Top Level Heading</DefaultH1>`
* Rarely, sites will need a smaller type scale, for example `<AlternateH1>A Top Level Heading</AlternateH1>`
*/

/*doc
---
title: Alternate Typography
name: type_react_alt
parent: type_react
---
```html_example_table
<div id="alternate-typography-h1-example"></div>
<div id="alternate-typography-h2-example"></div>
<div id="alternate-typography-h3-example"></div>
```
```jsx_example
React.render(
<AlternateH1>h1 31px</AlternateH1>,
document.getElementById('alternate-typography-h1-example')
);
React.render(
<AlternateH2>h2 18px</AlternateH2>,
document.getElementById('alternate-typography-h2-example')
);
React.render(
<AlternateH3>h3 18px</AlternateH3>,
document.getElementById('alternate-typography-h3-example')
);
```
*/

/*doc
---
title: Default Typography
name: type_react_default
parent: type_react
---
```html_example_table
<div id="default-typography-h1-example"></div>
<div id="default-typography-h2-example"></div>
<div id="default-typography-h3-example"></div>
```
```jsx_example
React.render(
<DefaultH1>h1 31px</DefaultH1>,
document.getElementById('default-typography-h1-example')
);
React.render(
<DefaultH2>h2 18px</DefaultH2>,
document.getElementById('default-typography-h2-example')
);
React.render(
<DefaultH3>h3 18px</DefaultH3>,
document.getElementById('default-typography-h3-example')
);
```
*/

/*doc
---
title: Custom Headings
name: type_react_custom
parent: type_react
---
Usually, you want to use the provided headings. If your mock doesn't exactly match, you should try the normal headings,
and see if it still looks ok. If it doesn't (this should be rare!) you can use our custom type generator.
You may want to wrap this in a custom reusable React component rather than calling it directly.
```html_example_table
<div id="typography-h1-example"></div>
```
```jsx_example
React.render(
<Heading element="h1" bold="high" color="type-dark-1">This is an h1 on most apps</Heading>,
document.getElementById('typography-h1-example')
);
```
*/
11 changes: 11 additions & 0 deletions src/pivotal-ui/javascripts/pivotal-ui-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ require('./back-to-top')();

global.React = require('react');
global.TableSortable = global.React.createFactory(require('./table-sortable.jsx'));

global.Heading = require('./typography.jsx').Heading;

global.AlternateH1 = require('./typography.jsx').AlternateH1;
global.AlternateH2 = require('./typography.jsx').AlternateH2;
global.AlternateH3 = require('./typography.jsx').AlternateH3;

global.DefaultH1 = require('./typography.jsx').DefaultH1;
global.DefaultH2 = require('./typography.jsx').DefaultH2;
global.DefaultH3 = require('./typography.jsx').DefaultH3;

153 changes: 153 additions & 0 deletions src/pivotal-ui/javascripts/typography.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
'use strict';

var React = require('react');
var _ = require('lodash');


var Heading = React.createClass({
acceptedSizeClasses: ['title', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'small'],
acceptedBoldClasses: ['low', 'default', 'high', 'max'],
render: function render() {
var classes = [];

if(this.props.className) {
classes.push(this.props.className);
}

if (_.contains(this.acceptedSizeClasses, this.props.size)) {
classes.push(this.props.size);
}

if (_.contains(this.acceptedBoldClasses, this.props.bold)) {
classes.push("em-" + this.props.bold);
}

if (this.props.allcaps) {
classes.push("em-alt");
}

if (this.props.color) {
classes.push(this.props.color);
}

var joinedClasses = classes.join(' ');

switch(this.props.element) {
case "h1":
return (<h1 {...this.props} className={joinedClasses}>{this.props.children}</h1>);
case "h2":
return (<h2 {...this.props} className={joinedClasses}>{this.props.children}</h2>);
case "h3":
return (<h3 {...this.props} className={joinedClasses}>{this.props.children}</h3>);
case "h4":
return (<h4 {...this.props} className={joinedClasses}>{this.props.children}</h4>);
case "h5":
return (<h5 {...this.props} className={joinedClasses}>{this.props.children}</h5>);
case "h6":
return (<h6 {...this.props} className={joinedClasses}>{this.props.children}</h6>);
default:
return (<p {...this.props} className={joinedClasses}> {this.props.children}</p>);
}
}
});

var AlternateH1 = React.createClass({
getDefaultProps: function () {
return {
bold: 'high',
color: 'type-dark-1'
}
},

render: function render() {
return (
<Heading element="h1" {...this.props}>{this.props.children}</Heading>
);
}
});

var AlternateH2 = React.createClass({
getDefaultProps: function () {
return {
bold: 'high',
size: 'h4',
allcaps: true
}
},

render: function render() {
return (
<Heading element="h2" {...this.props}>{this.props.children}</Heading>
);
}
});

var AlternateH3 = React.createClass({
getDefaultProps: function () {
return {
bold: 'high',
size: 'h4'
}
},

render: function render() {
return (
<Heading element="h3" {...this.props}>{this.props.children}</Heading>
);
}
});

var DefaultH1 = React.createClass({
getDefaultProps: function () {
return {
bold: 'high'
}
},

render: function render() {
return (
<Heading element="h1" {...this.props}>{this.props.children}</Heading>
);
}
});

var DefaultH2 = React.createClass({
getDefaultProps: function () {
return {
color: 'type-dark-1',
bold: 'high'
}
},

render: function render() {
return (
<Heading element="h2" {...this.props}>{this.props.children}</Heading>
);
}
});

var DefaultH3 = React.createClass({
getDefaultProps: function () {
return {
color: 'type-dark-1',
size: 'h4',
bold: 'high'
}
},

render: function render() {
return (
<Heading element="h3" {...this.props}>{this.props.children}</Heading>
);
}
});

module.exports = {
AlternateH1: AlternateH1,
AlternateH2: AlternateH2,
AlternateH3: AlternateH3,
DefaultH1: DefaultH1,
DefaultH2: DefaultH2,
DefaultH3: DefaultH3,
Heading: Heading
};
Loading

0 comments on commit 64ccd18

Please sign in to comment.