@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
28 lines • 1.16 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { isKeyEnterPressed, isKeySpacePressed } from '../../utils/keyboard/keyboard.utility';
import { PillControlled } from './pillControlled';
/**
* @deprecated Try the new PillV2 component
*/
export const PillUnControlled = ({ initialState = false, focus, ...props }) => {
const ref = React.useRef(null);
const [selected, setSelected] = React.useState(initialState);
const setPillSelected = checked => {
setSelected(checked);
};
React.useEffect(() => {
if (focus) {
ref.current?.focus();
}
}, [focus]);
const handleOnKeyDown = value => event => {
if (isKeyEnterPressed(event.key) || isKeySpacePressed(event.key)) {
event.preventDefault();
props.onPillChange?.(true, value);
}
};
return (_jsx(PillControlled, { ...props, ref: ref, selected: props.selected ?? selected, onKeyDown: handleOnKeyDown, onPillChange: props.onPillChange ?? setPillSelected, children: props.children }));
};
export { PillUnControlled as Pill };
//# sourceMappingURL=pillUnControlled.js.map