Skip to content

Commit

Permalink
feat(Breakpoint): add component
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter committed Jul 18, 2017
1 parent 1a52e98 commit 6e17efd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// Addons
export {
default as Breakpoint,
BreakpointPoints,
BreakpointProps,
BreakpointOnUpdateData
} from './dist/commonjs/addons/Breakpoint';
export { default as Confirm, ConfirmProps } from './dist/commonjs/addons/Confirm';
export { default as Portal, PortalProps } from './dist/commonjs/addons/Portal';
export { default as Radio, RadioProps } from './dist/commonjs/addons/Radio';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"satisfied": "^1.1.0",
"semantic-ui-css": "^2.2.11",
"simulant": "^0.2.2",
"sinon": "^2.1.0",
"sinon": "^2.3.8",
"sinon-chai": "^2.11.0",
"ta-scripts": "^2.5.2",
"through2": "^2.0.2",
Expand Down
4 changes: 1 addition & 3 deletions src/addons/Breakpoint/Breakpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default class Breakpoint extends Component {
// ----------------------------------------

visible = () => {
const { only } = this.props
const { only = '' } = this.props
const points = only.replace('large screen', 'largeScreen').split(' ')

return _.some(points, point => _.invoke(this, point))
Expand Down Expand Up @@ -147,5 +147,3 @@ export default class Breakpoint extends Component {
return null
}
}


2 changes: 1 addition & 1 deletion src/addons/Breakpoint/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default, BreakpointPoints, BreakpointProps } from './Breakpoint';
export { default, BreakpointPoints, BreakpointProps, BreakpointOnUpdateData } from './Breakpoint';
12 changes: 10 additions & 2 deletions src/lib/customPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export const demand = (requiredProps) => {
* @param {string[]} possible An array of possible values to prop.
*/
export const onlyProp = possible => {
return (props, propName, componentName) => {
const typeChecker = (required, props, propName, componentName) => {
if (!Array.isArray(possible)) {
throw new Error([
'Invalid argument supplied to some, expected an instance of array.',
Expand All @@ -252,7 +252,10 @@ export const onlyProp = possible => {
const propValue = props[propName]

// skip if prop is undefined
if (_.isNil(propValue) || propValue === false) return
if (_.isNil(propValue) || propValue === false) {
if (required) throw new Error(`Required \`${propName}\` prop was not specified in \`${componentName}\`.`)
return
}

const values = propValue
.replace('large screen', 'large-screen')
Expand All @@ -265,6 +268,11 @@ export const onlyProp = possible => {
return new Error(`\`${propName}\` prop in \`${componentName}\` has invalid values: \`${invalid.join('`, `')}\`.`)
}
}

const chainedCheckType = typeChecker.bind(null, false)
chainedCheckType.isRequired = typeChecker.bind(null, true)

return chainedCheckType
}

/**
Expand Down
8 changes: 4 additions & 4 deletions test/specs/addons/Breakpoint/Breakpoint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { domEvent, sandbox } from 'test/utils'
const { points } = Breakpoint.defaultProps
const requiredProps = { only: 'mobile' }

beforeEach(() => {
sandbox.stub(window, 'innerWidth').value(points.mobile)
})

describe('Breakpoint', () => {
beforeEach(() => {
sandbox.stub(window, 'innerWidth').value(points.mobile)
})

common.isConformant(Breakpoint, { requiredProps })
common.rendersChildren(Breakpoint, { requiredProps })

Expand Down

0 comments on commit 6e17efd

Please sign in to comment.