@totalsoft/rocket-ui
Version:
A set of reusable and composable React components built on top of Material UI core for developing fast and friendly web applications interfaces.
28 lines • 1.65 kB
JavaScript
import React, { forwardRef, useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import { Checkbox, Tooltip } from '@mui/material';
import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
import CheckBoxIcon from '@mui/icons-material/CheckBox';
const Option = forwardRef(function Option(props, ref) {
const optionRef = useRef(undefined);
const [isOverflow, setIsOverflow] = useState(false);
useEffect(() => {
setIsOverflow(optionRef?.current?.scrollWidth > optionRef?.current?.clientWidth);
}, []);
const { label, liProps, selected, withCheckboxes, option } = props;
const { key, ...rest } = liProps; // Warning: key must be passed directly to a JSX element and not by a spread operator
return (React.createElement(Tooltip, { title: label, disableHoverListener: !isOverflow, placement: "right" },
React.createElement("li", { key: key, ...rest, "aria-disabled": option?.isDisabled, ref: ref },
React.createElement("div", { ref: optionRef },
withCheckboxes && (React.createElement(Checkbox, { icon: React.createElement(CheckBoxOutlineBlankIcon, { fontSize: "small" }), checkedIcon: React.createElement(CheckBoxIcon, { fontSize: "small" }), style: { marginRight: 8 }, checked: selected })),
label))));
});
Option.propTypes = {
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
liProps: PropTypes.object.isRequired,
selected: PropTypes.bool,
withCheckboxes: PropTypes.bool,
option: PropTypes.any.isRequired
};
export default Option;
//# sourceMappingURL=Option.js.map