Skip to content

Commit

Permalink
Adds React FlexGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
roblevintennis committed Sep 20, 2020
1 parent 86f479d commit a17b730
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions agnosticui-react/__mocks__/fileMock.js
@@ -0,0 +1,2 @@
module.exports = 'file-stub';

2 changes: 2 additions & 0 deletions agnosticui-react/__mocks__/styleMock.js
@@ -0,0 +1,2 @@
module.exports = {};

6 changes: 5 additions & 1 deletion agnosticui-react/package.json
Expand Up @@ -39,6 +39,7 @@
"babel-jest": "^26.3.0",
"babel-loader": "^8.0.5",
"clean-webpack-plugin": "^3.0.0",
"core-js": "^3.6.5",
"css-loader": "^4.2.2",
"identity-obj-proxy": "^3.0.0",
"jest": "^26.4.2",
Expand All @@ -50,6 +51,9 @@
"webpack-dev-server": "^3.2.1"
},
"jest": {
"setupFilesAfterEnv": [
"./setupTests.js"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "identity-obj-proxy"
Expand All @@ -58,4 +62,4 @@
"^.+\\.js$": "babel-jest"
}
}
}
}
2 changes: 2 additions & 0 deletions agnosticui-react/setupTests.js
@@ -0,0 +1,2 @@
import 'core-js/stable';
import 'regenerator-runtime/runtime';
7 changes: 6 additions & 1 deletion agnosticui-react/src/stories/FlexGrid/FlexGrid.js
Expand Up @@ -25,10 +25,15 @@ const propTypes = {
const FlexGrid = (props) => {
const containerClass = getClass('flexgrid-container')
const classNames = [props.className, containerClass]
const gridPropsCreated = createProps(propTypes, props, classNames)

// We're essentially taking the props passed in and:
// - rejecting any props passed in that are not in propTypes
// - adding classNames to our new react element below
// - allowing for a custom tagName or falling back to 'div'
return React.createElement(
props.tagName || 'div',
createProps(propTypes, props, classNames)
gridPropsCreated
)
}

Expand Down
3 changes: 2 additions & 1 deletion agnosticui-react/src/stories/FlexGrid/FlexRow.js
Expand Up @@ -49,7 +49,8 @@ function getRowClassNames(props) {
}

export function getRowProps(props) {
return createProps(propTypes, props, getRowClassNames(props))
const rowPropsCreated = createProps(propTypes, props, getRowClassNames(props))
return rowPropsCreated;
}

const FlexRow = (props) => {
Expand Down
27 changes: 27 additions & 0 deletions agnosticui-react/src/stories/FlexGrid/createProps.test.js
@@ -0,0 +1,27 @@
import PropTypes from 'prop-types';
import createProps from './createProps';

const propTypes = {
b: PropTypes.bool,
s: PropTypes.string,
children: PropTypes.node,
}
test('removes prop types besides children', async () => {
const classNames = ['class_a', 'class_b']
const props = {
s: 'string', // expected: gets removed
b: true, // expected: gets removed
style: 'color: hotpink;', // expected: preserved
children: 'le children',
}

const result = createProps(propTypes, props, classNames)
expect(result.children).toEqual('le children')
expect(result.className).toEqual('class_a class_b')
// keys that are not in propTypes are preserved
expect(result.style).toBeDefined();

// only the children component prop (and props not in propTypes) are preserved
expect(result.b).toBeUndefined()
expect(result.s).toBeUndefined()
})

0 comments on commit a17b730

Please sign in to comment.