import React from "react"; import { Alignment } from "@blueprintjs/core"; import type { SegmentedControlOption } from "design-system"; import { SegmentedControl } from "design-system"; import type { ControlProps } from "./BaseControl"; import BaseControl from "./BaseControl"; import type { DSEventDetail } from "utils/AppsmithUtils"; import { DSEventTypes, DS_EVENT, emitInteractionAnalyticsEvent, } from "utils/AppsmithUtils"; export interface LabelAlignmentOptionsControlProps extends ControlProps { propertyValue?: Alignment; options: SegmentedControlOption[]; defaultValue: Alignment; fullWidth?: boolean; } class LabelAlignmentOptionsControl extends BaseControl { componentRef = React.createRef(); constructor(props: LabelAlignmentOptionsControlProps) { super(props); this.handleAlign = this.handleAlign.bind(this); } 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(); } }; static getControlType() { return "LABEL_ALIGNMENT_OPTIONS"; } public render() { const { options, propertyValue } = this.props; return ( ); } private handleAlign(align: string, isUpdatedViaKeyboard = false) { this.updateProperty(this.props.propertyName, align, isUpdatedViaKeyboard); } } export default LabelAlignmentOptionsControl;