UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

27 lines (25 loc) 712 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStateAttributesProps = getStateAttributesProps; function getStateAttributesProps(state, customMapping) { const props = {}; /* eslint-disable-next-line guard-for-in */ for (const key in state) { const value = state[key]; if (customMapping?.hasOwnProperty(key)) { const customProps = customMapping[key](value); if (customProps != null) { Object.assign(props, customProps); } continue; } if (value === true) { props[`data-${key.toLowerCase()}`] = ''; } else if (value) { props[`data-${key.toLowerCase()}`] = value.toString(); } } return props; }