2021-02-16 10:29:08 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
2021-03-15 12:17:56 +00:00
|
|
|
import ButtonTabComponent, {
|
|
|
|
|
ButtonTabOption,
|
|
|
|
|
} from "components/ads/ButtonTabComponent";
|
2021-02-16 10:29:08 +00:00
|
|
|
import produce from "immer";
|
|
|
|
|
|
|
|
|
|
class ButtonTabControl extends BaseControl<ButtonTabControlProps> {
|
|
|
|
|
selectButton = (value: string) => {
|
2021-05-13 08:35:39 +00:00
|
|
|
const { defaultValue, propertyValue } = this.props;
|
2021-02-16 10:29:08 +00:00
|
|
|
const values: string[] = propertyValue
|
|
|
|
|
? propertyValue.split(",")
|
|
|
|
|
: defaultValue
|
|
|
|
|
? defaultValue.split(",")
|
|
|
|
|
: [];
|
|
|
|
|
if (values.includes(value)) {
|
|
|
|
|
values.splice(values.indexOf(value), 1);
|
|
|
|
|
this.updateProperty(this.props.propertyName, values.join(","));
|
|
|
|
|
} else {
|
|
|
|
|
const updatedValues: string[] = produce(values, (draft: string[]) => {
|
|
|
|
|
draft.push(value);
|
|
|
|
|
});
|
|
|
|
|
this.updateProperty(this.props.propertyName, updatedValues.join(","));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
render() {
|
2021-05-13 08:35:39 +00:00
|
|
|
const { options, propertyValue } = this.props;
|
2021-02-16 10:29:08 +00:00
|
|
|
return (
|
2021-03-15 12:17:56 +00:00
|
|
|
<ButtonTabComponent
|
|
|
|
|
options={options}
|
|
|
|
|
selectButton={this.selectButton}
|
2022-02-10 19:00:20 +00:00
|
|
|
values={propertyValue ? propertyValue.split(",") : []}
|
2021-03-15 12:17:56 +00:00
|
|
|
/>
|
2021-02-16 10:29:08 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getControlType() {
|
|
|
|
|
return "BUTTON_TABS";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ButtonTabControlProps extends ControlProps {
|
|
|
|
|
options: ButtonTabOption[];
|
|
|
|
|
defaultValue: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ButtonTabControl;
|