supMDX/components/mdx.tsx

13 lines
428 B
TypeScript
Raw Normal View History

2022-11-04 21:44:29 +09:00
/** <S $="span" _=".a.b.c" className="extra class-name">...</S> */
export function S<E extends React.ElementType='span'>({
$: TagName = 'span',
_: modifier = '',
className, children, ...props
}: {
$?: string,
_?: string,
} & React.ComponentProps<E>) {
const cls = [className, ...(modifier.match(/\.(\w+)/g) ?? [])].map(s => s.slice(1)).join(' ');
return <TagName className={cls} {...props}>{children}</TagName>;
}