core/kind
Provides the core/kindcore/kind.kind method to create components
Members
Section titled “Members ”kind Function
Section titled “kind   Function ”kind( config ) → Component(Props)Creates a new component with some helpful declarative syntactic sugar.
Example:
import css from './Button.module.less';
const Button = kind({
name: 'Button',
// Return a functional component
functional: true,
// expect color and onClick properties but neither required
propTypes: {
color: PropTypes.string
},
// if no color is provided, it'll be green
defaultProps: {
color: 'green'
},
// expect backgroundColor via context
contextType: React.createContext({ backgroundColor }),
// configure styles with the static className to merge with user className
styles: {
// include the CSS modules map so 'button' can be resolved to the local name
css,
className: 'button'
},
// add event handlers that are cached between calls to prevent recreating each call. Any
// handlers are added to the props passed to `render()`. See core/handle.
handlers: {
onKeyDown: (evt, props) => { .... }
},
// add some computed properties, these are added to props passed to `render()`
computed: {
// border color will be the color prepended by 'light'
borderColor: ({color}) => 'light' + color,
// background color will be the contextual background color if specified
color: ({color}, context) => context.backgroundColor || color
},
// Render the thing, already!
render: ({color, borderColor, children, ...rest}) => (
<button
{...rest}
style={{backgroundColor: color, borderColor}}
>
{children}
</button>
)
});1 Param
- config KindConfig
Component configuration
Returns
- Component(Props)
Component
Type Definitions
Section titled “Type Definitions ”ComputedPropFunction Function
Section titled “ComputedPropFunction   Function ”ComputedPropFunction(props, context)
Section titled “ComputedPropFunction(props, context)”2 Params
- props Object(string, any)
- context Object(string, any)
Returns
- any
any
HandlerFunction Function
Section titled “HandlerFunction   Function ”HandlerFunction(event, props, context)
Section titled “HandlerFunction(event, props, context)”3 Params
- event any
- props Object(string, any)
- context Object(string, any)
Returns
KindConfig Object
Section titled “KindConfig   Object ”The name of the component
Boolean controlling whether the returned component should be a functional component
Specifies expected props
Sets the default props
Specifies context type
Configures styles with the static className to merge with user className
Adds event handlers that are cached between calls to prevent recreating each call.
Any handlers are added to the props passed to render(). See core/handlecore/handle.handle.
Adds some computed properties, these are added to props passed to render()
The render function
RenderFunction Function
Section titled “RenderFunction   Function ”RenderFunction(props, context)
Section titled “RenderFunction(props, context)”2 Params
- props Object(string, any)
- context Object(string, any)
Returns
- any
React.Element|null
StylesBlock Object
Section titled “StylesBlock   Object ”Configuration for CSS class name mapping
The CSS of the component
The className of the component
Specifies which class names are overridable.
If this value is true, all the class names of the component CSS will become public.