![onno-react](https://raw.githubusercontent.com/wagerfield/onno/master/assets/onno-react.png)
![License](https://img.shields.io/github/license/wagerfield/onno.svg?color=4C8&style=flat-square)
Onno propTypes
for React
yarn add onno-react
Usage
You can use onno-react
in place of onno
since it re-exports the API:
import styled from "styled-components"
import { display, padding } from "onno-react"
const Box = styled.div(display, padding)
<Box display="flex" padding="10px" />
<Box d="grid" p="20em" />
To add propTypes
for onno's render functions to your components:
import styled from "styled-components"
import { display, padding, propTypes } from "onno-react"
const Box = styled.div(display, padding)
Box.propTypes = propTypes(display, padding)
<Box display={true} padding={[false]} />
<Box d={true} p={[false]} />
Render functions can be passed to propTypes
as an array or list of arguments:
import { display, padding, propTypes } from "onno-react"
const propTypes2 = propTypes([display, padding])
const propTypes1 = propTypes(display, padding)
Following DRY principles, wrap your render functions in an array or use onno's compose
method:
import styled from "styled-components"
import { display, padding, compose, propTypes } from "onno-react"
const styles = [display, padding]
const boxSet = compose(styles)
const Box1 = styled.div(...styles)
Box1.propTypes = propTypes(styles)
const Box2 = styled.div(boxSet)
Box2.propTypes = propTypes(boxSet)
To add other propTypes
alongside the render function props:
import styled from "styled-components"
import { display, padding, propTypes } from "onno-react"
import { number, string } from "prop-types"
const styles = [display, padding]
const Box = styled.div(...styles)
Box.propTypes = {
...propTypes(styles),
foo: string.isRequired,
bar: number.isRequired
}
Author
Matthew Wagerfield
License
MIT