2021-08-05 11:16:26 +00:00
|
|
|
import * as React from "react";
|
|
|
|
|
|
2022-06-16 09:47:35 +00:00
|
|
|
import BaseControl, { ControlData, ControlProps } from "./BaseControl";
|
2022-06-24 14:23:02 +00:00
|
|
|
import { TooltipComponent } from "design-system";
|
2022-05-04 09:45:57 +00:00
|
|
|
import { boxShadowOptions } from "constants/ThemeConstants";
|
|
|
|
|
import CloseLineIcon from "remixicon-react/CloseLineIcon";
|
2022-08-04 10:30:36 +00:00
|
|
|
import { ButtonTab } from "design-system";
|
2022-07-14 05:00:30 +00:00
|
|
|
import {
|
|
|
|
|
DSEventDetail,
|
|
|
|
|
DSEventTypes,
|
|
|
|
|
DS_EVENT,
|
|
|
|
|
emitInteractionAnalyticsEvent,
|
|
|
|
|
} from "utils/AppsmithUtils";
|
2021-08-05 11:16:26 +00:00
|
|
|
export interface BoxShadowOptionsControlProps extends ControlProps {
|
2022-05-04 09:45:57 +00:00
|
|
|
propertyValue: string | undefined;
|
2021-08-05 11:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-04 09:45:57 +00:00
|
|
|
const options = Object.keys(boxShadowOptions).map((optionKey) => ({
|
|
|
|
|
icon: (
|
|
|
|
|
<TooltipComponent
|
|
|
|
|
content={
|
|
|
|
|
<div>
|
|
|
|
|
<div>{optionKey}</div>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
key={optionKey}
|
|
|
|
|
openOnTargetFocus={false}
|
|
|
|
|
>
|
2022-05-06 11:24:33 +00:00
|
|
|
<button tabIndex={-1}>
|
2022-05-04 09:45:57 +00:00
|
|
|
<div
|
|
|
|
|
className="flex items-center justify-center w-5 h-5 bg-white"
|
|
|
|
|
style={{ boxShadow: boxShadowOptions[optionKey] }}
|
|
|
|
|
>
|
|
|
|
|
{boxShadowOptions[optionKey] === "none" && (
|
|
|
|
|
<CloseLineIcon className="text-gray-700" />
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipComponent>
|
|
|
|
|
),
|
|
|
|
|
value: boxShadowOptions[optionKey],
|
|
|
|
|
}));
|
2021-08-24 05:37:16 +00:00
|
|
|
|
2022-06-16 09:47:35 +00:00
|
|
|
const optionsValues = new Set(Object.values(boxShadowOptions));
|
|
|
|
|
|
2021-08-05 11:16:26 +00:00
|
|
|
class BoxShadowOptionsControl extends BaseControl<
|
|
|
|
|
BoxShadowOptionsControlProps
|
|
|
|
|
> {
|
2022-07-14 05:00:30 +00:00
|
|
|
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 === "ButtonTab" &&
|
|
|
|
|
e.detail.event === DSEventTypes.KEYPRESS
|
|
|
|
|
) {
|
|
|
|
|
emitInteractionAnalyticsEvent(this.componentRef.current, {
|
|
|
|
|
key: e.detail.meta.key,
|
|
|
|
|
});
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-05 11:16:26 +00:00
|
|
|
static getControlType() {
|
|
|
|
|
return "BOX_SHADOW_OPTIONS";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
|
return (
|
2022-08-04 10:30:36 +00:00
|
|
|
<ButtonTab
|
2022-05-04 09:45:57 +00:00
|
|
|
options={options}
|
2022-07-14 05:00:30 +00:00
|
|
|
ref={this.componentRef}
|
|
|
|
|
selectButton={(value, isUpdatedViaKeyboard = false) => {
|
|
|
|
|
this.updateProperty(
|
|
|
|
|
this.props.propertyName,
|
|
|
|
|
value,
|
|
|
|
|
isUpdatedViaKeyboard,
|
|
|
|
|
);
|
2022-05-04 09:45:57 +00:00
|
|
|
}}
|
|
|
|
|
values={this.props.evaluatedValue ? [this.props.evaluatedValue] : []}
|
|
|
|
|
/>
|
2021-08-05 11:16:26 +00:00
|
|
|
);
|
|
|
|
|
}
|
2022-06-16 09:47:35 +00:00
|
|
|
|
|
|
|
|
static canDisplayValueInUI(config: ControlData, value: any): boolean {
|
|
|
|
|
return optionsValues.has(value);
|
|
|
|
|
}
|
2021-08-05 11:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default BoxShadowOptionsControl;
|