File size: 594 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { ARIA_STATES, ARIA_PROPERTIES } from './constants';
import type {
	AriaProps,
	AriaAttributes,
	AriaState,
	AriaProperty,
	RawAriaState,
	RawAriaProperty,
} from './types';

export default function useAriaProps( props: AriaProps ): AriaAttributes {
	const attrs = {} as AriaAttributes;

	for ( const key in props ) {
		if ( ARIA_STATES.includes( key as RawAriaState ) ) {
			attrs[ `aria-${ key }` as AriaState ] = !! props[ key ];
		} else if ( ARIA_PROPERTIES.includes( key as RawAriaProperty ) ) {
			attrs[ `aria-${ key }` as AriaProperty ] = props[ key ];
		}
	}

	return attrs;
}