2020-01-09 01:38:48 +01:00
|
|
|
import React from 'react';
|
2020-01-14 07:42:04 +01:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2020-01-16 02:08:31 +01:00
|
|
|
import Slider from 'rc-slider';
|
|
|
|
|
2020-01-09 01:38:48 +01:00
|
|
|
import { SessionToggle } from '../SessionToggle';
|
2020-01-15 02:26:14 +01:00
|
|
|
import { SessionButton } from '../SessionButton';
|
2020-01-14 03:28:31 +01:00
|
|
|
import { SessionSettingType } from './SessionSettings';
|
2020-01-15 02:26:14 +01:00
|
|
|
import { SessionRadioGroup } from '../SessionRadioGroup';
|
2021-06-11 09:02:02 +02:00
|
|
|
import { SessionConfirmDialogProps } from '../SessionConfirm';
|
2020-01-14 07:42:04 +01:00
|
|
|
|
2020-01-09 02:15:12 +01:00
|
|
|
interface Props {
|
2020-10-15 07:43:51 +02:00
|
|
|
title?: string;
|
2020-01-09 02:15:12 +01:00
|
|
|
description?: string;
|
2020-01-20 01:08:16 +01:00
|
|
|
type: SessionSettingType | undefined;
|
2020-01-14 03:28:31 +01:00
|
|
|
value: any;
|
|
|
|
options?: Array<any>;
|
2020-01-09 02:15:12 +01:00
|
|
|
onClick?: any;
|
2020-01-16 02:08:31 +01:00
|
|
|
onSliderChange?: any;
|
2020-01-15 02:26:14 +01:00
|
|
|
content: any;
|
2021-06-11 09:02:02 +02:00
|
|
|
confirmationDialogParams?: SessionConfirmDialogProps;
|
|
|
|
|
|
|
|
// for updating modal in redux
|
2021-06-17 08:51:59 +02:00
|
|
|
updateConfirmModal?: any;
|
2020-01-09 02:15:12 +01:00
|
|
|
}
|
2020-01-09 01:38:48 +01:00
|
|
|
|
2020-01-16 02:08:31 +01:00
|
|
|
interface State {
|
|
|
|
sliderValue: number | null;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class SessionSettingListItem extends React.Component<Props, State> {
|
2020-01-14 07:42:04 +01:00
|
|
|
public static defaultProps = {
|
|
|
|
inline: true,
|
2020-01-15 03:49:07 +01:00
|
|
|
};
|
|
|
|
|
2020-01-09 01:38:48 +01:00
|
|
|
public constructor(props: Props) {
|
|
|
|
super(props);
|
2020-01-16 02:08:31 +01:00
|
|
|
this.state = {
|
|
|
|
sliderValue: null,
|
|
|
|
};
|
2020-01-14 03:28:31 +01:00
|
|
|
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
2020-01-09 01:38:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public render(): JSX.Element {
|
2020-01-15 03:49:07 +01:00
|
|
|
const { title, description, type, value, content } = this.props;
|
2020-01-20 03:03:50 +01:00
|
|
|
const inline =
|
2021-04-22 10:03:58 +02:00
|
|
|
!!type && ![SessionSettingType.Options, SessionSettingType.Slider].includes(type);
|
2020-01-15 02:26:14 +01:00
|
|
|
|
2020-01-16 02:08:31 +01:00
|
|
|
const currentSliderValue =
|
|
|
|
type === SessionSettingType.Slider && (this.state.sliderValue || value);
|
|
|
|
|
2020-01-09 01:38:48 +01:00
|
|
|
return (
|
2020-01-15 02:26:14 +01:00
|
|
|
<div className={classNames('session-settings-item', inline && 'inline')}>
|
2020-01-15 03:49:07 +01:00
|
|
|
<div className="session-settings-item__info">
|
|
|
|
<div className="session-settings-item__title">{title}</div>
|
2020-01-09 01:38:48 +01:00
|
|
|
|
2021-04-22 10:03:58 +02:00
|
|
|
{description && <div className="session-settings-item__description">{description}</div>}
|
2020-01-09 01:38:48 +01:00
|
|
|
</div>
|
|
|
|
|
2020-01-15 02:26:14 +01:00
|
|
|
<div className="session-settings-item__content">
|
|
|
|
{type === SessionSettingType.Toggle && (
|
2020-08-24 11:11:26 +02:00
|
|
|
<div className="session-settings-item__selection">
|
2020-01-15 03:49:07 +01:00
|
|
|
<SessionToggle
|
|
|
|
active={Boolean(value)}
|
|
|
|
onClick={this.handleClick}
|
2020-02-03 04:19:37 +01:00
|
|
|
confirmationDialogParams={this.props.confirmationDialogParams}
|
2021-06-11 09:02:02 +02:00
|
|
|
updateConfirmModal={this.props.updateConfirmModal}
|
2020-01-15 03:49:07 +01:00
|
|
|
/>
|
2020-01-15 02:26:14 +01:00
|
|
|
</div>
|
|
|
|
)}
|
2020-01-09 02:15:12 +01:00
|
|
|
|
2020-01-15 02:26:14 +01:00
|
|
|
{type === SessionSettingType.Button && (
|
|
|
|
<SessionButton
|
|
|
|
text={content.buttonText}
|
|
|
|
buttonColor={content.buttonColor}
|
|
|
|
onClick={this.handleClick}
|
|
|
|
/>
|
|
|
|
)}
|
2020-01-14 07:42:04 +01:00
|
|
|
|
2020-01-15 02:26:14 +01:00
|
|
|
{type === SessionSettingType.Options && (
|
|
|
|
<SessionRadioGroup
|
2021-03-02 05:25:38 +01:00
|
|
|
initialItem={content.options.initalItem}
|
2020-01-15 02:26:14 +01:00
|
|
|
group={content.options.group}
|
|
|
|
items={content.options.items}
|
2021-03-02 05:25:38 +01:00
|
|
|
onClick={(selectedRadioValue: string) => {
|
|
|
|
this.props.onClick(selectedRadioValue);
|
|
|
|
}}
|
2020-01-15 02:26:14 +01:00
|
|
|
/>
|
|
|
|
)}
|
2020-01-16 02:08:31 +01:00
|
|
|
|
|
|
|
{type === SessionSettingType.Slider && (
|
|
|
|
<div className="slider-wrapper">
|
|
|
|
<Slider
|
2020-01-20 04:36:46 +01:00
|
|
|
dots={true}
|
2020-02-28 00:20:56 +01:00
|
|
|
step={content.step}
|
|
|
|
min={content.min}
|
|
|
|
max={content.max}
|
2020-01-20 04:10:28 +01:00
|
|
|
defaultValue={currentSliderValue}
|
2020-03-09 13:41:02 +01:00
|
|
|
onAfterChange={sliderValue => {
|
2020-01-20 04:36:46 +01:00
|
|
|
this.handleSlider(sliderValue);
|
|
|
|
}}
|
2020-01-16 02:08:31 +01:00
|
|
|
/>
|
2020-02-26 03:30:56 +01:00
|
|
|
|
2020-01-16 02:08:31 +01:00
|
|
|
<div className="slider-info">
|
2020-02-28 00:54:21 +01:00
|
|
|
<p>{content.info(currentSliderValue)}</p>
|
2020-01-16 02:08:31 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-01-15 02:26:14 +01:00
|
|
|
</div>
|
2020-01-09 01:38:48 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-01-14 03:28:31 +01:00
|
|
|
|
|
|
|
private handleClick() {
|
2020-01-16 02:05:09 +01:00
|
|
|
if (this.props.onClick) {
|
|
|
|
this.props.onClick();
|
|
|
|
}
|
2020-01-14 03:28:31 +01:00
|
|
|
}
|
2020-01-16 02:08:31 +01:00
|
|
|
|
|
|
|
private handleSlider(value: any) {
|
2020-01-20 04:36:46 +01:00
|
|
|
if (this.props.onSliderChange) {
|
|
|
|
this.props.onSliderChange(value);
|
|
|
|
}
|
2020-01-16 02:08:31 +01:00
|
|
|
|
|
|
|
this.setState({
|
|
|
|
sliderValue: value,
|
|
|
|
});
|
|
|
|
}
|
2020-01-09 01:38:48 +01:00
|
|
|
}
|