PromucFlow_constructor/app/client/src/components/propertyControls/IconTabControl.tsx
Pawan Kumar d6305bad82
chore: chat widget polish fixes (#37124)
- [x] Fix button variant control in the property pane #37005
- [x] elevatedBackground for chat should work the same as for statbox
- [x] Markdown polishing. We need to fix lists, inline code, etc. Check
how it works with a table.

/ok-to-test tags="@tag.Anvil"

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced a new `noPadding` property for the `ContainerComponent`,
allowing for conditional styling.
- Enhanced styling for segmented controls and input components for
improved visual clarity and responsiveness.

- **Bug Fixes**
- Refined CSS selectors for separators in segmented controls to improve
visual representation.

- **Style**
- Adjusted styles for input groups and inline code elements for better
alignment and visual feedback.

- **Documentation**
- Updated Storybook configuration for the `Markdown` component to
reflect new formatting changes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11571964148>
> Commit: 29bac9bcdc0b95d4a6a4da2b4f503aa9494d7bcb
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11571964148&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Anvil`
> Spec:
> <hr>Tue, 29 Oct 2024 10:51:44 UTC
<!-- end of auto-generated comment: Cypress test results  -->
2024-10-29 16:21:54 +05:30

100 lines
2.5 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 {
gap: 0;
}
> .ads-v2-segmented-control__segments-container {
flex: 1 1 auto;
}
> .ads-v2-segmented-control__segments-container:has(.ads-v2-text) span {
padding: 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;