Skip to content

Commit

Permalink
feat(panels): Adds passthroughs for className, id, and style
Browse files Browse the repository at this point in the history
className, id, and style passthrough to the panel and
innerClassName passes through to the panel-body

[Finishes #98986988]
  • Loading branch information
Caroline Taymor and Kenny Wang authored and Geoff Pleiss and Matt Royal committed Jul 20, 2015
1 parent c4aa1b6 commit 174c544
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
26 changes: 23 additions & 3 deletions spec/pivotal-ui-react/panels/panels_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,24 @@ describe('Panel', function() {
});
});

describe('when a className is provided', function() {
describe('when attributes are provided', function() {
beforeEach(function() {
React.render(<Panel className="foo myClass">Sup</Panel>, root);
React.render(<Panel className="foo myClass" innerClassName="inner-class"
id="outer-id"
style={{opacity: '0.5'}}>Sup</Panel>, root);
});

it('sets the className as a class on the panel', function() {
it('sets className, id, and style on the panel outer div', function() {
expect('.panel').toHaveClass('foo');
expect('.panel').toHaveClass('myClass');
expect('.panel').toHaveAttr('id', 'outer-id');
expect('.panel').toHaveCss({opacity: '0.5'});
});

it('sets innerClassName on the panel-body div', () => {
expect('.panel-body').toHaveClass('inner-class');
});

});

describe('when padding is provided', function() {
Expand Down Expand Up @@ -100,6 +109,17 @@ describe('Panel', function() {
});
});
});

describe('when scrollable is not set', () => {
beforeEach(function() {
React.render(<Panel>Sup</Panel>, root);
});

it('does not add the class "panel-scrollable"', () => {
expect('.panel').not.toHaveClass('panel-scrollable');
});
});

});

describe('ShadowPanel', function() {
Expand Down
18 changes: 8 additions & 10 deletions src/pivotal-ui-react/panels/panels.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,23 @@ var Panel = React.createClass({
},

render() {
var {kind, padding, scrollable, children, ...other} = this.props;

var bodyClasses = classnames('panel-body', padding);
const {kind, innerClassName, padding, scrollable, children, ...other} = this.props;
const panelStyle = (typeof scrollable === 'number') ? {maxHeight: `${scrollable}px`} : null;
const props = mergeProps(other, {
className: ['panel', kind, {'panel-scrollable': scrollable}],
style: panelStyle
});

var title = this.props.title ? (
const title = this.props.title ? (
<div className="panel-header">
<h5 className="panel-title-alt">{this.props.title}</h5>
</div>
) : null;

var props = mergeProps(other, {
className: ['panel', kind, {'panel-scrollable': scrollable}],
style: (scrollable ? {maxHeight: scrollable} : {})
});

return (
<div {...props}>
{title}
<div className={bodyClasses}>{children}</div>
<div className={classnames('panel-body', padding, innerClassName)}>{children}</div>
</div>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/pivotal-ui/components/panels/panels.scss
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ See examples below.
<UI.Panel className="bg-neutral-8">
<p>Base Panel</p>
</UI.Panel>
<UI.Panel className="bg-neutral-8 optional-class"
innerClassName="opt-inner-class">
<p>Base Panel</p>
</UI.Panel>
```
*/

Expand Down Expand Up @@ -727,6 +732,7 @@ Add a "padding" attribute (i.e. `pal`, `pbn`, etc.) to change the padding on the
<UI.Panel className="bg-neutral-8" padding="paxxl">
<p>Base Panel</p>
</UI.Panel>
```
*/
Expand Down

0 comments on commit 174c544

Please sign in to comment.