PromucFlow_constructor/app/client/src/components/propertyControls/StepControl.tsx

67 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-04-15 11:42:11 +00:00
import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
import StepComponent from "components/ads/StepComponent";
const MIN = 0;
const MAX = 100;
2020-04-15 11:42:11 +00:00
class StepControl extends BaseControl<StepControlProps> {
getStepTypeControls = () => {
const { stepType } = this.props;
if (stepType === "ZOOM_PERCENTAGE") {
return {
min: MIN,
max: MAX,
2020-04-15 11:42:11 +00:00
steps: 5,
displayFormat: (value: number): string => {
return `${value}%`;
},
};
}
return {
min: MIN,
max: MAX,
2020-04-15 11:42:11 +00:00
steps: 1,
displayFormat: (value: number): string => {
return `${value}`;
},
};
};
render() {
const { displayFormat, max, min, steps } = this.getStepTypeControls();
2020-04-15 11:42:11 +00:00
return (
<StepComponent
displayFormat={displayFormat}
2020-04-15 11:42:11 +00:00
max={max}
min={min}
2020-04-15 11:42:11 +00:00
onChange={(value: number) => {
this.updateProperty(this.props.propertyName, value);
}}
steps={steps}
value={this.props.propertyValue}
2020-04-15 11:42:11 +00:00
/>
);
}
static getControlType() {
return "STEP";
}
static canDisplayValueInUI(config: StepControlProps, value: any): boolean {
let steps = 1;
if (config.stepType === "ZOOM_PERCENTAGE") {
steps = 5;
}
return value >= MIN && value <= MAX && value % steps === 0;
}
2020-04-15 11:42:11 +00:00
}
export type StepType = "ZOOM_PERCENTAGE";
export interface StepControlProps extends ControlProps {
stepType: StepType;
}
export default StepControl;