import * as React from 'react'; import { FormElementProps, FormElementRegistration } from "@vertigis/workflow"; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; import Tooltip from '@mui/material/Tooltip'; import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft'; import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter'; import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight'; import FormatAlignJustifyIcon from '@mui/icons-material/FormatAlignJustify'; interface ToggleButtonGroupOption { value: string; label: string; icon: React.ReactElement | string; disabled?: boolean; tooltip?: string; } interface MuiToggleButtonGroupProps extends FormElementProps { options: ToggleButtonGroupOption[]; } const renderIcon = (icon: React.ReactElement | string) => { if (typeof icon === 'string') { return ; } return icon; }; const renderTooltipButton = (option: ToggleButtonGroupOption) => { const button = ( {renderIcon(option.icon)} ); return button} /** * A Workflow element for single choice toggle buttons with tooltips. * @displayName Mui Single Toggle Button * @description Version 1.4 - Single choice toggle button group with tooltips * @param props The props that will be provided by the Workflow runtime. */ function MuiSingleToggleButtonGroup(props: MuiToggleButtonGroupProps): React.ReactElement { const { setValue, value, options } = props; const handleChange = ( event: React.MouseEvent, newValue: string | null, ) => { setValue(newValue || ""); }; return ( {options.map(renderTooltipButton)} ); } /** * A Workflow element for multiple choice toggle buttons with tooltips. * @displayName Mui Multiple Toggle Button * @description Version 1.2 - Multiple choice toggle button group with tooltips * @param props The props that will be provided by the Workflow runtime. */ function MuiMultipleToggleButtonGroup(props: MuiToggleButtonGroupProps): React.ReactElement { const { setValue, value, options } = props; const handleChange = ( event: React.MouseEvent, newValue: string[], ) => { setValue(newValue); }; return ( {options.map(renderTooltipButton)} ); } const MuiSingleToggleButtonGroupElementRegistration: FormElementRegistration = { component: MuiSingleToggleButtonGroup, getInitialProperties: () => ({ value: "", options: [ { value: "left", label: "Left Aligned", icon: , tooltip: "Align Left" }, { value: "center", label: "Centered", icon: , tooltip: "Align Center" }, { value: "right", label: "Right Aligned", icon: , tooltip: "Align Right" }, { value: "justify", label: "Justified", icon: , disabled: true, tooltip: "Justify" }, ], }), id: "MuiSingleToggleButtonGroup", }; const MuiMultipleToggleButtonGroupElementRegistration: FormElementRegistration = { component: MuiMultipleToggleButtonGroup, getInitialProperties: () => ({ value: [], options: [ { value: "bold", label: "Bold", icon: , tooltip: "Bold" }, { value: "italic", label: "Italic", icon: , tooltip: "Italic" }, { value: "underline", label: "Underline", icon: , tooltip: "Underline" }, ], }), id: "MuiMultipleToggleButtonGroup", }; export { MuiSingleToggleButtonGroupElementRegistration, MuiMultipleToggleButtonGroupElementRegistration };