Skip to content

Commit

Permalink
feat: add static decorator dynamic CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 15, 2018
1 parent 381d4fd commit 5ef8a08
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .storybook/decorator.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ class Static extends Component<any, any> {
}
}

@css
class Static2 extends Component<any, any> {
static css = {
border: '1px dashed blue',
};

css () {
return {
color: this.props.color
};
}

render () {
return <div>Hello there</div>;
}
}

storiesOf('@css decorator', module)
.add('Default', () =>
<CssTest />
Expand All @@ -55,3 +72,6 @@ storiesOf('@css decorator', module)
.add('Static decorator', () =>
<Static />
)
.add('Static dynamic styles', () =>
<Static2 color='blue' />
)
7 changes: 7 additions & 0 deletions addon/decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ exports.addon = function (renderer) {
if (isComponent) {
if (a.css) transformComponentStatic(renderer, a.prototype, a.css);

var componentWillMount_ = a.prototype.componentWillMount;

a.prototype.componentWillMount = function () {
if (this.css) transformComponentDynamic(renderer, a, this.css.bind(this));
if (componentWillMount_) componentWillMount_.apply(this);
};

return a;
}

Expand Down

0 comments on commit 5ef8a08

Please sign in to comment.