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.

21 lines (20 loc) 580 B
export 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; }