import * as React from "react"; import Select from "@material-ui/core/Select"; import MenuItem from "@material-ui/core/MenuItem"; import InputLabel from "@material-ui/core/InputLabel"; import FormControl from "@material-ui/core/FormControl"; import { makeStyles, withStyles } from "@material-ui/core/styles"; import InputBase from "@material-ui/core/InputBase"; import Icon, { IconTypes } from "@sc/plugins/webcomponents/v2/Icon"; import theme from "@sc/components/ui/theme"; import { ItemComponentTypes, ItemComponentProps } from "./types"; const BootstrapInput = withStyles((theme) => ({ root: { "label + &": { marginTop: 18, }, }, input: { border: "none", }, }))(InputBase); export const DefaultItemComponent: React.FC = ({ type = ItemComponentTypes.TEXT, caption = "", isHovering, isExpanded, containerStyle = { position: "absolute", marginTop: -43, marginLeft: 12, width: 240, }, inputStyle = { padding: "2px 10px", border: "none", width: "100%", backgroundColor: "transparent", fontSize: "12pt", }, data = [], icon, placeholder, children, onAdd = () => null, onBlur = () => null, onChange = () => null, onMouseEnter = () => null, onMouseLeave = () => null, toggleExpansion, }) => { const color = isExpanded ? theme.primaryColor : "inherit"; const label = caption.length > 27 ? `${caption.substring(0, 25).trim()}...` : caption; const styles: { wrap: React.CSSProperties } = { wrap: { padding: "2px 10px", fontWeight: isExpanded ? "bold" : "normal", color, }, }; return (
{type === ItemComponentTypes.INPUT && ( e.stopPropagation()} onKeyUp={(e) => { if (e.which === 13) { onAdd(); } }} onChange={(e) => onChange(e.target.value)} onBlur={(e) => onBlur(e.target.value)} defaultValue={label} /> )} {type === ItemComponentTypes.TEXT && ( {label} )} {type === ItemComponentTypes.DROPDOWN && ( {label || placeholder || "Select an item..."} )}
{isExpanded && children}
); };