Skip to content
Enact

Provides the core/kindcore/kind.kind method to create components

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
configKindConfig

Component configuration

Returns
Component(Props)

Component

any
2 Params
propsObject(string, any)
contextObject(string, any)
Returns
any

any

3 Params
eventany
propsObject(string, any)
contextObject(string, any)
Returns
Optionalname
String

The name of the component


Optionalfunctional
Boolean

Boolean controlling whether the returned component should be a functional component


OptionalpropTypes
Object(string, Function)

Specifies expected props


OptionaldefaultProps
Object(string, any)

Sets the default props


OptionalcontextType
Object

Specifies context type


Optionalstyles
StylesBlock

Configures styles with the static className to merge with user className


Optionalhandlers
Object(string, HandlerFunction)

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.


Optionalcomputed
Object(string, ComputedPropFunction)

Adds some computed properties, these are added to props passed to render()


Required Propertyrender
RenderFunction

The render function

any
2 Params
propsObject(string, any)
contextObject(string, any)
Returns
any

React.Element|null

Configuration for CSS class name mapping

Required Propertycss
Object(string, string)

The CSS of the component


OptionalclassName
String

The className of the component


OptionalpublicClassNames
Boolean | String | Array(String)

Specifies which class names are overridable. If this value is true, all the class names of the component CSS will become public.