UNPKG

@kubit-ui-web/react-components

Version:

Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience

47 lines 2.34 kB
import { jsx as _jsx } from "react/jsx-runtime"; import React from 'react'; import { STYLES_NAME } from '../../constants/stylesName/stylesName'; import { useStyles } from '../../hooks/useStyles/useStyles'; import { ErrorBoundary } from '../../provider/errorBoundary/errorBoundary'; import { FallbackComponent } from '../../provider/errorBoundary/fallbackComponent'; import { useGenericComponents } from '../../provider/genericComponents/genericComponentsProvider'; import { OptionStandAlone } from './optionStandAlone'; import { OptionStateType } from './types/state'; export const OptionComponent = React.forwardRef(({ variant, focus, onFocus, onBlur, ctv, ...props }, ref) => { const styles = useStyles(STYLES_NAME.OPTION, variant, ctv); const hasFocusStyles = !!styles?.[OptionStateType.FOCUS]; const { LINK: genericLinkComponent } = useGenericComponents(); const innerRef = React.useRef(); const [hover, setHover] = React.useState(false); const [focused, setFocused] = React.useState(false); React.useImperativeHandle(ref, () => { return innerRef.current; }, []); React.useEffect(() => { if (focus) { innerRef.current?.focus(); } }, [focus]); const _onFocus = (event) => { onFocus?.(event); setFocused(hasFocusStyles); }; const _onBlur = (event) => { onBlur?.(event); setFocused(false); }; return (_jsx(OptionStandAlone, { ...props, ref: innerRef, componentLink: genericLinkComponent, focus: focused, hover: hover, styles: styles, onBlur: _onBlur, onFocus: _onFocus, onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false) })); }); OptionComponent.displayName = 'OptionComponent'; const OptionBoundary = (props, ref) => (_jsx(ErrorBoundary, { fallBackComponent: _jsx(FallbackComponent, { children: _jsx(OptionStandAlone, { ...props, ref: ref }) }), children: _jsx(OptionComponent, { ...props, ref: ref }) })); const Option = React.forwardRef(OptionBoundary); /** * @description * Option component is used to create a list of options. * You can combine with ItemRove component to create a list of options with keyboard navigation. * @link ItemRove * @param {React.PropsWithChildren<IOption<V>>} props * @returns {JSX.Element} */ export { Option }; //# sourceMappingURL=option.js.map