Skip to content

Commit 7f5439d

Browse files
committed
handle core components + styled components
1 parent 9e83aa3 commit 7f5439d

File tree

21 files changed

+177
-291
lines changed

21 files changed

+177
-291
lines changed

app/components/Sections/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Sections extends Component {
2828
}
2929

3030
render () {
31-
var componentsObj = contents.allComponents;
31+
var componentsObj = Object.assign({}, contents.allComponents, contents.allStyledComponents);
3232
return (
3333
<div>
3434
{this.getContents().map((Content, i) => {

app/utils/contents.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// component-requires.js is a generated file in rsg.js that contains
22
// the list of required user-defined components
33
import Components from '../../rcs-tmp/component-requires'
4+
import StyledComponents from '../../rcs-tmp/styled-component-requires'
45
import reactPropMeta from '../../rcs-tmp/propsdoc'
56

7+
let StyledContents = StyledComponents ? StyledComponents
8+
.map((Content) => Content.default || Content) : false;
69
// for `commonStrict` module formatter
710
// https://babeljs.io/docs/usage/modules/#interop
811
let Contents = Components
9-
.map((Content) => Content.default || Content)
12+
.map((Content) => Content.default || Content)
1013
.sort((a, b) => {
1114

1215
a.styleguide = a.styleguide ? a.styleguide : {};
@@ -132,7 +135,19 @@ var contentObj = {
132135
prevVal[currentValName] = currentVal;
133136
return prevVal;
134137
}, {})
138+
})(),
139+
140+
allStyledComponents: (() => {
141+
if (StyledContents) {
142+
return StyledContents.reduce(function(prevVal, currentVal, idx) {
143+
Object.assign(prevVal, currentVal);
144+
return prevVal;
145+
}, {})
146+
} else {
147+
return {}
148+
}
135149
})()
150+
136151
};
137152

138153
export default contentObj;

bin/rcs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ var log
2323
files: argv.f || argv.files,
2424
config: argv.c || argv.config,
2525
dev: argv.d || argv.dev,
26-
verbose: argv.v || argv.verbose
26+
verbose: argv.v || argv.verbose,
27+
styleComponents: argv.s || argv.styleComponents
2728
}
2829

2930
log = require('../lib/logger')('bin', { debug: true })

example/components/Buttons/Button.js

Lines changed: 13 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,12 @@
11
import React, { PropTypes } from 'react';
2-
import ClassNames from 'classnames/bind';
3-
import style from './button.css';
42

53
/**
64
* Creates a reusable, customizable button.
75
*/
8-
const Button = ({className, outline, href, loading, primary, secondary, success, warning, danger, link, large, small, block, disabled, children, ...others}) => {
9-
10-
const element = href ? 'a' : 'button';
11-
const cx = ClassNames.bind(style);
12-
let classNames = cx({
13-
large,
14-
small,
15-
block,
16-
disabled,
17-
className
18-
});
19-
20-
if (outline) {
21-
classNames += ' ' + cx({
22-
primary_outline: !secondary && !success && !warning && !danger && !link,
23-
secondary,
24-
success_outline: success,
25-
warning_outline: warning,
26-
danger_outline: danger,
27-
link_outline: link
28-
});
29-
} else {
30-
classNames += ' ' + cx({
31-
primary: !secondary && !success && !warning && !danger && !link,
32-
secondary,
33-
success,
34-
warning,
35-
danger,
36-
link
37-
});
38-
}
39-
40-
41-
let role;
42-
if (element === 'a') {
43-
role = 'button';
44-
}
45-
const props = {
46-
...others,
47-
href,
48-
className: classNames,
49-
disabled: disabled || loading,
50-
role
51-
};
52-
53-
return React.createElement(element, props,
54-
children
55-
);
6+
const Button = ({loading, disabled, children, theme, className, ...props}) => {
567

8+
var disabledStyle = disabled || loading ? theme.disabled : '';
9+
return <button {...props} className={`${theme.base} ${disabledStyle} ${className}`}>{children}</button>
5710
};
5811

5912
Button.displayName = 'Button';
@@ -64,44 +17,10 @@ Button.styleguide = {
6417
example: `
6518
<section>
6619
<p>Regular Buttons</p>
67-
<Button>Button</Button>
68-
<Button>Secondary</Button>
69-
<Button>Success</Button>
70-
<Button>Warning</Button>
71-
<Button>Danger</Button>
72-
73-
<p>Disabled Regular Buttons</p>
74-
<Button disabled >Button</Button>
75-
<Button disabled>Secondary</Button>
76-
<Button disabled >Success</Button>
77-
<Button disabled >Warning</Button>
78-
<Button disabled >Danger</Button>
79-
80-
<p>Outline Buttons</p>
81-
<Button>Button</Button>
82-
<Button>Secondary</Button>
83-
<Button>Success</Button>
84-
<Button>Warning</Button>
85-
<Button>Danger</Button>
86-
87-
<p>Disabled Outline Buttons</p>
88-
<Button disabled>Button</Button>
89-
<Button disabled>Secondary</Button>
90-
<Button disabled>Success</Button>
91-
<Button disabled>Warning</Button>
92-
<Button disabled>Danger</Button>
93-
94-
<p>Large Buttons</p>
95-
<Button>Button</Button>
96-
<Button>Secondary</Button>
97-
98-
<p>Small Buttons</p>
99-
<Button>Button</Button>
100-
<Button>Secondary</Button>
101-
102-
<p>Block Level Buttons</p>
103-
<Button>Button</Button>
104-
<Button>Secondary</Button>
20+
<PrimaryButton>PrimaryButton</PrimaryButton>
21+
<SecondaryButton>Secondary</SecondaryButton>
22+
<div style={{clear: 'both'}}> </div>
23+
<Button>Core 'unstyled' Button with primary theme as default</Button>
10524
</section>
10625
`
10726
};
@@ -126,34 +45,7 @@ Button.propTypes = {
12645
* Use outline styled button
12746
* @examples <Button outline>
12847
*/
129-
outline: PropTypes.bool,
130-
/**
131-
* Define button href if anchor
132-
* @examples '#', 'http://some-website.com/'
133-
*/
134-
href: PropTypes.string,
135-
/**
136-
* Set loading animation on button
137-
* @examples <Button loading>
138-
*/
139-
loading: PropTypes.bool,
140-
/**
141-
* Use primary style button (button is set to this by default)
142-
* @examples <Button primary>
143-
*/
144-
primary: PropTypes.bool,
145-
type: PropTypes.string,
146-
/**
147-
* Use secondary style button
148-
* @examples <Button secondary>
149-
*/
150-
secondary: PropTypes.bool,
151-
success: PropTypes.bool,
152-
warning: PropTypes.bool,
153-
danger: PropTypes.bool,
154-
link: PropTypes.bool,
155-
large: PropTypes.bool,
156-
small: PropTypes.bool
48+
theme: PropTypes.object
15749
};
15850

15951
Button.defaultProps = {
@@ -170,8 +62,11 @@ Button.defaultProps = {
17062
danger: false,
17163
link: false,
17264
large: false,
173-
small: false
174-
65+
small: false,
66+
theme: {
67+
base: "",
68+
disabled: ""
69+
}
17570
};
17671

17772
export default Button;

example/components/Buttons/button.css

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

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"scripts": {
55
"start": "npm run styleguide && npm run serve",
6-
"styleguide": "node ../bin/rcs \"components/**/*.js\" -v -r /atlas -c ./styleguide.js -d",
6+
"styleguide": "node ../bin/rcs \"components/**/*.js\" -v -s \"styledComponents/**/*.js\" -c ./styleguide.js -d",
77
"serve": "serve ./styleguide"
88
},
99
"dependencies": {

0 commit comments

Comments
 (0)