session-desktop/ts/components/session/settings/SessionSettingListItem.tsx

154 lines
4.1 KiB
TypeScript
Raw Normal View History

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';
2020-01-14 07:42:04 +01:00
2020-01-09 02:15:12 +01:00
interface Props {
title: string;
description?: string;
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;
2020-02-03 04:19:37 +01:00
confirmationDialogParams?: 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-09 02:15:12 +01:00
2020-01-20 03:03:50 +01:00
const inline =
!!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
{description && (
2020-01-09 02:15:12 +01:00
<div className="session-settings-item__description">
{description}
2020-01-09 02:15:12 +01:00
</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 && (
<div className="session-sessings-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}
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
initalItem={content.options.initalItem}
group={content.options.group}
items={content.options.items}
onClick={this.handleClick}
/>
)}
2020-01-16 02:08:31 +01:00
2020-02-21 00:37:58 +01:00
{type === SessionSettingType.Slider && title === 'messageTTL' ? (
2020-01-16 02:08:31 +01:00
<div className="slider-wrapper">
<Slider
2020-01-20 04:36:46 +01:00
dots={true}
2020-01-16 02:08:31 +01:00
step={6}
min={12}
max={96}
defaultValue={currentSliderValue}
2020-01-20 04:36:46 +01:00
onAfterChange={sliderValue => {
this.handleSlider(sliderValue);
}}
2020-01-16 02:08:31 +01:00
/>
2020-01-16 02:08:31 +01:00
<div className="slider-info">
<p>{`${currentSliderValue} Hours`}</p>
</div>
</div>
2020-02-21 00:37:58 +01:00
):type === SessionSettingType.Slider ? (
<div>
<Slider
dots={true}
step={20}
min={60}
max={200}
defaultValue={currentSliderValue}
2020-02-21 00:53:57 +01:00
onChange={sliderValue => {
2020-02-21 00:37:58 +01:00
this.handleSlider(sliderValue);
}}
/>
<div className="slider-info">
<p>{`% ${currentSliderValue} Zoom Level`}</p>
</div>
</div>
):
null}
</div>
2020-01-09 01:38:48 +01:00
</div>
);
}
2020-01-14 03:28:31 +01:00
private handleClick() {
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-02-21 00:37:58 +01:00
if(this.props.title !== 'messageTTL' && this.state.sliderValue!==null) {
window.setZoomFactor(this.state.sliderValue/100)
}
2020-01-16 02:08:31 +01:00
}
2020-01-09 01:38:48 +01:00
}