import * as React from "react"; import { FormElementProps, FormElementRegistration } from "@vertigis/workflow"; import Button from '@mui/material/Button'; /** * The generic type argument provided to `FormElementProps` controls the type * of `props.value` and `props.setValue(value)`. If your element doesn't need a * `value`, you can omit the type argument. * * You can also declare additional public properties of your element by adding * properties to this interface. The properties will be managed by the Workflow * runtime, and passed in as `props`. You can update the properties by using * `props.setProperty(key, value)`. */ interface HeaderwithHelpProps extends FormElementProps { setting?: settingConfig //Following NOT necessary, to be Compatible with old header only backgroundColor?: string imgSrc?: string text?: string; imgPosition?: string; divHeight?: string; margin?: string; padding?: string; fontSize?: string; fontWeight?: string; fontFamily?: string; fontColor?: string; borderRaius?: string; align?: string; innermargin?: string; } /** * A Workflow element built using React. * @displayName HeaderwithHelp * @description Header to display icon and title, optional to provide help video if available. * @param props The props that will be provided by the Workflow runtime. For new header, give value to property "setting"; for existing header, copy the old load activities and add new setting for help button, then assign click events. */ interface settingConfig { headerText?: string, headerIcon?: string, smallSize?: boolean, helpIcon?: string, backgroundColor?: string, helpTitle?: string, helpUrl?: string, } function HeaderwithHelp(props: HeaderwithHelpProps): React.ReactElement { const { raiseEvent } = props; const helpInfo = { title: props.setting?.helpTitle || '!!please contact GIS Admin to provide setting.helpTitle', url: props.setting?.helpUrl || "https://descriptusercontent.com/published/e09ca015-acd7-4980-b4b4-7ca72ebb7208/original.mp4" } const handleHelpClick = () => { raiseEvent("clicked", JSON.stringify(helpInfo)); // Pass the entire item data structure }; function addLengths(...lengths) { if (lengths.length === 0) return '0px'; // Handle no input case let total = 0; let baseUnit = ''; lengths.forEach(length => { const match: string = length.match(/(\d+)([a-zA-Z%]+)/); if (match) { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const value = parseFloat(length.toString()); const unit = match[2]; if (baseUnit === '') { baseUnit = unit; // Set the base unit from the first input } if (baseUnit === 'rem') { baseUnit = 'px'; // Set the base unit to px if first rem } if (unit === baseUnit) { total += value; // Add directly if units are the same } else if (unit === 'rem' && baseUnit === 'px') { total += value * 10; // Convert rem to px } else { throw new Error(`Unsupported unit: ${unit}`); } } else { throw new Error(`Invalid length format: ${length}`); } }); return total + baseUnit; // Return total with the original base unit } // Example usage: let helpButtonHeight:string = '' if (props.divHeight && props.padding) { helpButtonHeight = addLengths(props.divHeight, props.padding, props.padding) } const helpExist: boolean = Boolean(props.setting?.helpTitle) || Boolean(props.setting?.helpUrl) const smallStyle = Boolean(props.setting && props.setting.smallSize) const helpIconHeight =helpButtonHeight !== '' ? parseFloat(helpButtonHeight)/2 + 'px' : (smallStyle ? '24px' : '30px') return ( <>
{props.text !== undefined ? props.text : (props.setting && props.setting.headerText ? props.setting.headerText : 'edit setting.headerText ')}
{ helpExist ? : <> }
); } const HeaderwithHelpElementRegistration: FormElementRegistration = { component: HeaderwithHelp, id: "HeaderwithHelp", }; export default HeaderwithHelpElementRegistration;