import React from 'react' import type { CSSProperties, ReactElement } from 'react' import classNames from 'classnames' export interface NativeProps { className?: string style?: CSSProperties & Partial> tabIndex?: number } export function withNativeProps

( props: P, element: ReactElement ) { const p = { ...element.props, } if (props.className) { p.className = classNames(element.props.className, props.className) } if (props.style) { p.style = { ...p.style, ...props.style, } } if (props.tabIndex !== undefined) { p.tabIndex = props.tabIndex } for (const key in props) { if (!props.hasOwnProperty(key)) continue if (key.startsWith('data-') || key.startsWith('aria-')) { p[key] = props[key] } } return React.cloneElement(element, p) }