Files
decky-frontend-lib/src/components/Focusable.ts

22 lines
850 B
TypeScript
Raw Normal View History

import { HTMLAttributes, ReactNode, RefAttributes, FC } from 'react';
2022-10-24 20:33:40 -04:00
import { Export, findModuleExport } from '../webpack';
2022-10-24 20:33:40 -04:00
import { FooterLegendProps } from './FooterLegend';
2024-06-26 22:28:58 -04:00
import { createPropListRegex } from '../utils';
2022-06-08 21:40:19 -04:00
export interface FocusableProps extends HTMLAttributes<HTMLDivElement>, FooterLegendProps {
children: ReactNode;
2022-10-24 20:33:40 -04:00
'flow-children'?: string;
focusClassName?: string;
focusWithinClassName?: string;
noFocusRing?: boolean;
onActivate?: (e: CustomEvent) => void;
onCancel?: (e: CustomEvent) => void;
2022-06-08 21:40:19 -04:00
}
2024-06-26 22:28:58 -04:00
const focusableRegex = createPropListRegex(["flow-children", "onActivate", "onCancel", "focusClassName", "focusWithinClassName"]);
2024-05-12 15:48:13 -04:00
export const Focusable = findModuleExport((e: Export) =>
2024-06-26 22:28:58 -04:00
e?.render?.toString && focusableRegex.test(e.render.toString())
) as FC<FocusableProps & RefAttributes<HTMLDivElement>>;