import React from "react"; import styled from "styled-components"; import type { ControlData, ControlProps } from "./BaseControl"; import BaseControl from "./BaseControl"; import type { SegmentedControlOption } from "design-system"; import { SegmentedControl } from "design-system"; import type { DSEventDetail } from "utils/AppsmithUtils"; import { DSEventTypes, DS_EVENT, emitInteractionAnalyticsEvent, } from "utils/AppsmithUtils"; const StyledSegmentedControl = styled(SegmentedControl)` > .ads-v2-segmented-control__segments-container { flex: 1 1 0%; } `; export interface IconTabControlProps extends ControlProps { options: SegmentedControlOption[]; defaultValue: string; fullWidth: boolean; } class IconTabControl extends BaseControl { componentRef = React.createRef(); componentDidMount() { this.componentRef.current?.addEventListener( DS_EVENT, this.handleAdsEvent as (arg0: Event) => void, ); } componentWillUnmount() { this.componentRef.current?.removeEventListener( DS_EVENT, this.handleAdsEvent as (arg0: Event) => void, ); } handleAdsEvent = (e: CustomEvent) => { if ( e.detail.component === "ButtonGroup" && e.detail.event === DSEventTypes.KEYPRESS ) { emitInteractionAnalyticsEvent(this.componentRef.current, { key: e.detail.meta.key, }); e.stopPropagation(); } }; selectOption = (value: string, isUpdatedViaKeyboard = false) => { if (this.props.propertyValue === value) { this.updateProperty( this.props.propertyName, this.props.defaultValue, isUpdatedViaKeyboard, ); } else { this.updateProperty(this.props.propertyName, value, isUpdatedViaKeyboard); } }; render() { return ( ); } static getControlType() { return "ICON_TABS"; } static canDisplayValueInUI(config: ControlData, value: any): boolean { if ( (config as IconTabControlProps)?.options ?.map((x: { value: string }) => x.value) .includes(value) ) return true; return false; } } export default IconTabControl;