## Description Rename `design-system` package to `@appsmith/ads` ## Automation /ok-to-test tags="@tag.All" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/10319507327> > Commit: 65d9664dd75b750496458a6e1652e0da858e1fc6 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10319507327&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Fri, 09 Aug 2024 13:47:50 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No
91 lines
2.4 KiB
TypeScript
91 lines
2.4 KiB
TypeScript
import React from "react";
|
|
import styled from "styled-components";
|
|
import type { ControlData, ControlProps } from "./BaseControl";
|
|
import BaseControl from "./BaseControl";
|
|
import type { SegmentedControlOption } from "@appsmith/ads";
|
|
import { SegmentedControl } from "@appsmith/ads";
|
|
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<IconTabControlProps> {
|
|
componentRef = React.createRef<HTMLDivElement>();
|
|
|
|
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<DSEventDetail>) => {
|
|
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, value, isUpdatedViaKeyboard);
|
|
}
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<StyledSegmentedControl
|
|
isFullWidth={this.props.fullWidth}
|
|
onChange={this.selectOption}
|
|
options={this.props.options}
|
|
ref={this.componentRef}
|
|
value={this.props.propertyValue || this.props.defaultValue}
|
|
/>
|
|
);
|
|
}
|
|
|
|
static getControlType() {
|
|
return "ICON_TABS";
|
|
}
|
|
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
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;
|