import * as React from 'react';
import { BackgroundControlsProps } from '../types/controls';
import { ModeEnum } from '../types/modeEnum';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Switch from '@material-ui/core/Switch';
import ColorComponent from './sub/Color';
import LinearGradientComponent from './sub/LinearGradient';
import ImageComponent from './sub/Image';
import { BottomToolbar } from 'ory-editor-ui';
import ThemeProvider, { darkTheme } from 'ory-editor-ui/lib/ThemeProvider';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import ImageIcon from '@material-ui/icons/Landscape';
import ColorIcon from '@material-ui/icons/ColorLens';
import GradientIcon from '@material-ui/icons/Gradient';
import Typography from '@material-ui/core/Typography';
import Slider from '@material-ui/lab/Slider';
export interface BackgroundDefaultControlsState {
mode: ModeEnum;
}
class BackgroundDefaultControls extends React.Component<
BackgroundControlsProps,
BackgroundDefaultControlsState
> {
constructor(props: BackgroundControlsProps) {
super(props);
this.state = {
mode: props.defaultMode,
};
}
public render() {
const {
Renderer,
focused,
readOnly,
state: {
hasPadding = this.props.defaultHasPadding,
modeFlag = this.props.defaultModeFlag,
darken = this.props.defaultDarken,
lighten = this.props.defaultLighten,
},
} = this.props;
let darkenFinal =
this.props.darkenPreview !== undefined
? this.props.darkenPreview
: darken;
let lightenFinal =
this.props.lightenPreview !== undefined
? this.props.lightenPreview
: lighten;
return (
{!readOnly && (
{(this.props.enabledModes & ModeEnum.IMAGE_MODE_FLAG) > 0 && (
0
? 'secondary'
: undefined
}
/>
}
label="Image"
value={ModeEnum.IMAGE_MODE_FLAG}
/>
)}
{(this.props.enabledModes & ModeEnum.COLOR_MODE_FLAG) > 0 && (
0
? 'secondary'
: undefined
}
/>
}
label="Color"
value={ModeEnum.COLOR_MODE_FLAG}
/>
)}
{(this.props.enabledModes & ModeEnum.GRADIENT_MODE_FLAG) >
0 && (
0
? 'secondary'
: undefined
}
/>
}
label="Gradient"
value={ModeEnum.GRADIENT_MODE_FLAG}
/>
)}
{this.renderUI()}
Darken ({(darkenFinal * 100).toFixed(0)}
%)
this.props.handleChangeDarkenPreview(value)
}
onDragEnd={this.props.handleChangeDarken}
step={0.01}
min={0}
max={1}
/>
Lighten ({(lightenFinal * 100).toFixed(0)}
%)
this.props.handleChangeLightenPreview(value)
}
onDragEnd={this.props.handleChangeLighten}
step={0.01}
min={0}
max={1}
/>
}
label="Use padding"
/>
)}
);
}
renderModeSwitch = () => {
const {
state: { modeFlag = this.props.defaultModeFlag },
} = this.props;
let label = 'ON/OFF';
switch (this.state.mode) {
case ModeEnum.COLOR_MODE_FLAG:
// label = 'Use color'
break;
case ModeEnum.IMAGE_MODE_FLAG:
// label = 'Use image'
break;
case ModeEnum.GRADIENT_MODE_FLAG:
// label = 'Use gradient'
break;
default:
label = 'Unknown mode';
break;
}
return (
}
label={label}
/>
);
}
renderUI = () => {
switch (this.state.mode) {
case ModeEnum.COLOR_MODE_FLAG:
return (
{this.renderModeSwitch()}
);
case ModeEnum.GRADIENT_MODE_FLAG:
return (
{this.renderModeSwitch()}
);
case ModeEnum.IMAGE_MODE_FLAG:
default:
return (
{this.renderModeSwitch()}
);
}
}
ensureModeOn = (mode: ModeEnum) => () => {
const {
state: { modeFlag = this.props.defaultModeFlag },
} = this.props;
if ((modeFlag & mode) === 0) {
this.props.handleChangeModeSwitch(mode, modeFlag)();
}
}
handleChangeMode = (e: React.ChangeEvent, mode: number) =>
this.setState({ mode })
}
export default BackgroundDefaultControls;