Skip to content

Commit

Permalink
Change all components to pass down unknow props to children (dfee#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
couds authored Dec 20, 2017
1 parent 57d09db commit 7fd24fe
Show file tree
Hide file tree
Showing 84 changed files with 238 additions and 358 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "single"],
"no-console": 0,
"no-console": 2,
"no-param-reassign": 0,
"react/jsx-filename-extension": 0,
"import/no-extraneous-dependencies": 0,
Expand Down
4 changes: 2 additions & 2 deletions src/components/box/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export default class Box extends PureComponent {
const {
children,
className,
style,
renderAs,
...props
} = this.props;
const Element = renderAs;
return (
<Element
style={style}
{...props}
className={classnames('box', className)}
>
{children}
Expand Down
2 changes: 2 additions & 0 deletions src/components/breadcrumb/__test__/breadcrumb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const Anchor = ({

describe('Breadcrumb component', () => {
beforeEach(() => {
// eslint-disable-next-line no-console
console.warn = jest.genMockFn();
});
afterAll(() => {
// eslint-disable-next-line no-console
console.warn.mockRestore();
});
it('Should be a Breadcrumb', () => {
Expand Down
9 changes: 5 additions & 4 deletions src/components/breadcrumb/breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ export default class Breadcrumb extends PureComponent {
render() {
const {
className,
style,
items,
renderAs,
hrefAttr,
separator,
size,
align,
...props
} = this.props;
if (renderAs !== 'a' && !hrefAttr) {
// eslint-disable-next-line no-console
console.warn('if renderAs is different the anchor (a), hrefAttr is required. Check Breadcrumb props');
}
const Element = renderAs;
return (
<nav
style={style}
{...props}
className={classnames('breadcrumb', className, {
[`has-${separator}-separator`]: separator,
[`is-${size}`]: size,
Expand All @@ -59,7 +60,7 @@ export default class Breadcrumb extends PureComponent {
<ul>
{
items.map((item) => {
const props = {
const p = {
[renderAs === 'a' ? 'href' : hrefAttr]: item.url,
};
return (
Expand All @@ -69,7 +70,7 @@ export default class Breadcrumb extends PureComponent {
'is-active': item.active,
})}
>
<Element {...props}>
<Element {...p}>
{item.name}
</Element>
</li>
Expand Down
3 changes: 3 additions & 0 deletions src/components/button/__test__/button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ describe('Button component', () => {
expect(component.toJSON()).toMatchSnapshot();
});
it('Should throw a console.error if no hrefAttr is defined when renderAs different as A and href attr is defined', () => {
// eslint-disable-next-line no-console
console.error = jest.genMockFn();
renderer.create(
<Button renderAs={Link} href="http://google.com" color="danger" >
TEST
</Button>);
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalled();
// eslint-disable-next-line no-console
console.error.mockRestore();
});
it('Should render be disabled', () => {
Expand Down
5 changes: 1 addition & 4 deletions src/components/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ export default class Button extends PureComponent {
const {
children,
className,
style,
renderAs,
onClick,
color,
size,
outlined,
Expand All @@ -84,6 +82,7 @@ export default class Button extends PureComponent {
if (href) {
otherProps[renderAs === 'a' ? 'href' : hrefAttr] = href;
if (renderAs !== 'a' && !hrefAttr) {
// eslint-disable-next-line no-console
console.error('warning: if renderAs is different the anchor (a), hrefAttr is required. Check Button props');
}
}
Expand All @@ -100,9 +99,7 @@ export default class Button extends PureComponent {
<Element
{...props}
{...otherProps}
style={style}
disabled={disabled}
onClick={onClick}
className={classnames(className, {
'is-link': link,
[`is-${color}`]: color,
Expand Down
4 changes: 1 addition & 3 deletions src/components/card/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ export default class Card extends PureComponent {
const {
className,
children,
style,
type,
renderAs,
...props
} = this.props;
if (type === 'image') {
return <CardImage {...props} style={style} className={className} />;
return <CardImage {...props} className={className} />;
}
const Element = renderAs;
return (
<Element
style={style}
className={classnames(className, {
[`card-${type}`]: type,
card: !type,
Expand Down
2 changes: 2 additions & 0 deletions src/components/columns/__test__/columns.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import Columns from '..';

describe('Columns component', () => {
beforeEach(() => {
// eslint-disable-next-line no-console
console.warn = jest.genMockFn();
});
afterAll(() => {
// eslint-disable-next-line no-console
console.warn.mockRestore();
});
it('Should have columns classname', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/columns/columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ export default class Columns extends PureComponent {
const {
children,
className,
style,
breakpoint,
gapless,
multiline,
centered,
...props
} = this.props;
return (
<div
{...props}
className={classNames(className, 'columns', {
[`is-${breakpoint}`]: breakpoint,
'is-gapless': gapless,
'is-multiline': multiline,
'is-centered': centered,
})}
style={style}
>
{children}
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/columns/components/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ export default class Column extends PureComponent {
const {
children,
className,
style,
size,
offset,
narrow,
Expand All @@ -163,7 +162,6 @@ export default class Column extends PureComponent {
desktop,
widescreen,
fullhd,

mobileSize,
tabletSize,
desktopSize,
Expand All @@ -174,14 +172,17 @@ export default class Column extends PureComponent {
desktopOffset,
widescreenOffset,
fullhdOffset,
...props
} = this.props;

if (mobileSize || tabletSize || desktopSize || widescreenSize || fullhdSize || mobileOffset || tabletOffset || desktopOffset || widescreenOffset || fullhdOffset) {
// eslint-disable-next-line no-console
console.warn('DEPRECATION Warning: The props: mobileSize tabletSize desktopSize widescreenSize fullhdSize mobileOffset tabletOffset desktopOffset widescreenOffset fullhdOffset are deprecated, please use the mobile.size... alternatives');
}

return (
<div
{...props}
className={classNames(className, 'column', {
[`is-${size}`]: size,
[`is-${mobile.size || mobileSize}-mobile`]: mobile.size || mobileSize,
Expand All @@ -202,7 +203,6 @@ export default class Column extends PureComponent {
'is-narrow-widescreen': widescreen.narrow,
'is-narrow-fullhd': fullhd.narrow,
})}
style={style}
>
{children}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/container/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export default class Container extends PureComponent {
fluid,
breakpoint,
className,
style,
renderAs,
...props
} = this.props;
const Element = renderAs;
return (
<Element
style={style}
{...props}
className={classnames('container', className, {
'is-fluid': fluid,
[`is-${breakpoint}`]: breakpoint,
Expand Down
4 changes: 2 additions & 2 deletions src/components/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export default class Content extends PureComponent {
const {
children,
className,
style,
renderAs,
size,
...props
} = this.props;
const Element = renderAs;
return (
<Element
style={style}
{...props}
className={classnames('content', className, {
[`is-${size}`]: size,
})}
Expand Down
4 changes: 4 additions & 0 deletions src/components/dropdown/__test__/dropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('Dropdown component', () => {
expect(component.toJSON()).toMatchSnapshot();
});
it('Should print error if value is passed but no onChange Handler', () => {
// eslint-disable-next-line no-console
console.error = jest.genMockFn();
renderer.create(
<Dropdown value="value" style={{ width: 400 }}>
Expand All @@ -70,6 +71,7 @@ describe('Dropdown component', () => {
</Dropdown.Item>
</Dropdown>);
expect(global.console.error).toBeCalled();
// eslint-disable-next-line no-console
console.error.mockRestore();
});
it('Should have divider', () => {
Expand Down Expand Up @@ -154,6 +156,7 @@ describe('Dropdown component', () => {
expect(component.state('open')).toBe(false);
});
it('Should change display error message if props change has value but no onChange Handler', () => {
// eslint-disable-next-line no-console
console.error = jest.genMockFn();
const component = shallow(
<Dropdown value="value" style={{ width: 400 }} onChange={() => {}}>
Expand All @@ -166,6 +169,7 @@ describe('Dropdown component', () => {
expect(global.console.error).not.toBeCalled();
component.setProps({ value: 'other', onChange: null });
expect(global.console.error).toBeCalled();
// eslint-disable-next-line no-console
console.error.mockRestore();
});
});
4 changes: 2 additions & 2 deletions src/components/dropdown/components/divider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export default class DropdownDivider extends PureComponent {
}

render() {
const { style, className } = this.props;
const { className, ...props } = this.props;
return (
<hr
style={style}
{...props}
className={classnames('dropdown-divider', className)}
/>
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/dropdown/components/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export default class DropdownItem extends PureComponent {

static defaultProps = {
active: false,
onClick: null,
onClick: undefined,
children: null,
}

render() {
const { active, children, value, onClick } = this.props;
const { active, children, value, ...props } = this.props;
return (
<div
title={value}
onClick={onClick}
{...props}
role="presentation"
className={classnames('dropdown-item', {
'is-active': active,
Expand Down
7 changes: 4 additions & 3 deletions src/components/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export default class Dropdown extends PureComponent {

checkProps = (props) => {
if (props.value && !props.onChange) {
// eslint-disable-next-line no-console
console.error('Warning: This is a controlled component without onChange listener, please check the props of the Dropdown component');
}
}

close = (evt) => {
// IDK yet how to test using the ref in enzime
/* istanbul ignore next */
if (this.props.hoverable || (evt && evt.path.find(node => node === this.htmlElement))) {
return;
}
Expand All @@ -91,13 +91,14 @@ export default class Dropdown extends PureComponent {

render() {
const {
style,
className,
children,
value,
color,
align,
hoverable,
onChange,
...props
} = this.props;
let current = null;

Expand All @@ -113,8 +114,8 @@ export default class Dropdown extends PureComponent {

return (
<div
{...props}
ref={(node) => { this.htmlElement = node; }}
style={style}
className={classnames('dropdown', className, {
'is-active': this.state.open,
[`is-${align}`]: align,
Expand Down
4 changes: 2 additions & 2 deletions src/components/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export default class Footer extends PureComponent {
const {
children,
className,
style,
renderAs,
...props
} = this.props;
const Element = renderAs;
return (
<Element
style={style}
{...props}
className={classnames('footer', className)}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ exports[`Checkbox component Should have checkbox classname 1`] = `
<input
disabled={false}
name={null}
onBlur={[Function]}
onChange={[Function]}
onClick={[Function]}
onFocus={[Function]}
type="checkbox"
value=""
/>
Expand Down
Loading

0 comments on commit 7fd24fe

Please sign in to comment.