Skip to content

Commit ac954b6

Browse files
makarenyagakimball
authored andcommitted
Pass all props to result html (#20)
* Pass all props to result html * Fixes
1 parent f18324a commit ac954b6

File tree

13 files changed

+31
-47
lines changed

13 files changed

+31
-47
lines changed

package-lock.json

Lines changed: 6 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
"homepage": "https://github.com/gakimball/react-inky#readme",
3333
"dependencies": {
3434
"classnames": "^2.2.6",
35-
"prop-types": "^15.6.2",
36-
"react-attrs-filter": "^0.1.2"
35+
"prop-types": "^15.6.2"
3736
},
3837
"devDependencies": {
3938
"babel-cli": "^6.26.0",
39+
"babel-core": "^6.26.3",
4040
"babel-preset-env": "^1.7.0",
4141
"babel-preset-react": "^6.11.1",
4242
"babel-register": "^6.26.0",

src/components/Button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function Button(props) {
66
const expanded = props.className.match('expand') !== null;
77

88
return (
9-
<table {...getAttrs(props, 'table', 'button')}>
9+
<table {...getAttrs(props, ['href', 'target', 'children'], 'button')}>
1010
<tr>
1111
<td>
1212
<table>

src/components/Callout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import getAttrs from '../util/getAttrs';
44

55
export default function Callout(props) {
66
return (
7-
<table {...getAttrs(props, 'table', 'callout')}>
7+
<table {...getAttrs(props, ['children'], 'callout')}>
88
<tr>
99
<th className="callout-inner">{props.children}</th>
1010
<th className="expander"/>

src/components/Column.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function Column(props) {
2828
return (
2929
<ContainerContext.Consumer>
3030
{({columnCount}) => (
31-
<th {...getAttrs(props, 'th', getColumnClasses(props, columnCount))}>
31+
<th {...getAttrs(props, ['children', 'expander', 'first', 'last'], getColumnClasses(props, columnCount))}>
3232
<table>
3333
<tr>
3434
<th>{props.children}</th>

src/components/Container.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ const Container = props => (
2121
strictMode: props.strictMode
2222
}}
2323
>
24-
<table align="center" {...getAttrs(props, 'table', 'container')}>
24+
<table align="center" {...getAttrs(props, ['columnCount', 'strictMode', 'children'], 'container')}>
2525
<tbody>
2626
<tr>
2727
<td>{props.children}</td>
2828
</tr>
2929
</tbody>
3030
</table>
31-
</ContainerContext.Provider>
32-
);
31+
</ContainerContext.Provider>);
3332

3433
/**
3534
* Prop types for `<Container />`.

src/components/Item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import getAttrs from '../util/getAttrs';
44

55
export default function Item(props) {
66
return (
7-
<th {...getAttrs(props, 'th', 'menu-item')}>
7+
<th {...getAttrs(props, ['href', 'target', 'children'], 'menu-item')}>
88
<a href={props.href} target={props.target}>{props.children}</a>
99
</th>
1010
);

src/components/Menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import getAttrs from '../util/getAttrs';
55

66
export default function Menu(props) {
77
return (
8-
<table {...getAttrs(props, 'table', 'menu')}>
8+
<table {...getAttrs(props, ['children'], 'menu')}>
99
<tr>
1010
<td>
1111
<table>

src/components/Row.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Column from './Column';
1616
*/
1717
export default function Row(props) {
1818
return (
19-
<table {...getAttrs(props, 'table', 'row')}>
19+
<table {...getAttrs(props, ['children'], 'row')}>
2020
<tbody>
2121
{/* `first` and `last` props are added to the first and last child in the row, respectively */}
2222
<tr>{Children.map(props.children, (child, index) => {

src/components/Spacer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import ContainerContext from '../util/containerContext';
77
const createSpacer = (props, size, state = false) => (
88
<ContainerContext.Consumer>
99
{({strictMode}) => (
10-
<table {...getAttrs(props, 'table', classnames('spacer', state && `${state}-for-large`))}>
10+
<table {...getAttrs(props, ['size', 'sizeSm', 'sizeLg', 'children'],
11+
classnames('spacer', state && `${state}-for-large`))}
12+
>
1113
<tbody>
1214
<tr>
1315
<td

src/components/Wrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import getAttrs from '../util/getAttrs';
44

55
export default function Wrapper(props) {
66
return (
7-
<table align="center" {...getAttrs(props, 'table', 'wrapper')}>
7+
<table align="center" {...getAttrs(props, ['children'], 'wrapper')}>
88
<tr>
99
<td className="wrapper-inner">{props.children}</td>
1010
</tr>

src/util/__tests__/getAttrs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('getAttrs()', () => {
1212
className: 'header',
1313
align: 'center'
1414
};
15-
output = getAttrs(props, 'table', 'row');
15+
output = getAttrs(props, ['large', 'small'], 'row');
1616
});
1717

1818
it('returns an object', () => {

src/util/getAttrs.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import {filterPropsFor} from 'react-attrs-filter';
21
import classnames from 'classnames';
32

43
/**
54
* Compile attributes for a component's root element, based on its tag and default class name.
65
* @param {Object} props - Component props.
7-
* @param {String} tag - Component root element.
6+
* @param {Array} excluded - List of excluded attributes.
87
* @param {String} className - Component root class name.
98
* @returns {Object} Filtered props.
109
*
@@ -18,28 +17,20 @@ import classnames from 'classnames';
1817
*
1918
* // Only returns "style" and "className", because the other two are custom props
2019
* // The class "header" is added to the base "row"
21-
* const attrs = getAttrs(props, 'table', 'row'); // => { style: ..., className: 'row header' }
20+
* const attrs = getAttrs(props, ['children'], 'row'); // => { style: ..., className: 'row header' }
2221
* <table {...attrs}></table>
2322
*/
24-
export default function getAttrs(props, tag, className = '') {
25-
// Filter out non-HTML attributes
26-
const output = filterPropsFor(props, tag);
23+
export default function getAttrs(props, excluded, className = '') {
24+
// Filter out attributes
25+
const output = {};
26+
for (const k in props) {
27+
if (excluded.indexOf(k) === -1) {
28+
output[k] = props[k];
29+
}
30+
}
2731

2832
// Append class names in props to base classes
2933
output.className = classnames(className, props.className);
3034

31-
// `style` isn't included in `filterPropsFor` and must be copied manually
32-
if (props.style) {
33-
output.style = props.style;
34-
}
35-
36-
// Same with `align` and `valign`, since they are deprecated attributes
37-
if (props.align) {
38-
output.align = props.align;
39-
}
40-
if (props.valign) {
41-
output.valign = props.valign;
42-
}
43-
4435
return output;
4536
}

0 commit comments

Comments
 (0)