feat: added disabled state to right panel components

pull/2660/head
William Grant 3 years ago
parent 255b6225c9
commit 190c68d759

@ -3,15 +3,6 @@ import styled from 'styled-components';
import { Flex } from '../basic/Flex'; import { Flex } from '../basic/Flex';
// tslint:disable: react-unused-props-and-state // tslint:disable: react-unused-props-and-state
type Props = {
label: string;
value: string;
active: boolean;
inputName?: string;
beforeMargins?: string;
onClick?: (value: string) => void;
};
const StyledInput = styled.input<{ const StyledInput = styled.input<{
filledSize: number; filledSize: number;
outlineOffset: number; outlineOffset: number;
@ -19,23 +10,29 @@ const StyledInput = styled.input<{
}>` }>`
opacity: 0; opacity: 0;
position: absolute; position: absolute;
cursor: pointer; cursor: ${props => (props.disabled ? 'not-allowed' : 'pointer')};
width: ${props => props.filledSize + props.outlineOffset}px; width: ${props => props.filledSize + props.outlineOffset}px;
height: ${props => props.filledSize + props.outlineOffset}px; height: ${props => props.filledSize + props.outlineOffset}px;
:checked + label:before { :checked + label:before {
background: ${props => (props.selectedColor ? props.selectedColor : 'var(--primary-color)')}; background: ${props =>
props.disabled
? 'var(--disabled-color)'
: props.selectedColor
? props.selectedColor
: 'var(--primary-color)'};
} }
`; `;
// tslint:disable: use-simple-attributes // tslint:disable: use-simple-attributes
const StyledLabel = styled.label<{ const StyledLabel = styled.label<{
disabled: boolean;
filledSize: number; filledSize: number;
outlineOffset: number; outlineOffset: number;
beforeMargins?: string; beforeMargins?: string;
}>` }>`
cursor: pointer; cursor: pointer;
color: var(--text-primary-color); color: ${props => (props.disabled ? 'var(--disabled-color)' : 'var(--text-primary-color)')};
:before { :before {
content: ''; content: '';
@ -51,16 +48,26 @@ const StyledLabel = styled.label<{
} }
`; `;
export const SessionRadio = (props: Props) => { type SessionRadioProps = {
const { label, inputName, value, active, onClick, beforeMargins } = props; label: string;
value: string;
active: boolean;
inputName?: string;
beforeMargins?: string;
onClick?: (value: string) => void;
disabled?: boolean;
};
function clickHandler(e: ChangeEvent<any>) { export const SessionRadio = (props: SessionRadioProps) => {
if (onClick) { const { label, inputName, value, active, onClick, beforeMargins, disabled = false } = props;
const clickHandler = (e: ChangeEvent<any>) => {
if (!disabled && onClick) {
// let something else catch the event if our click handler is not set // let something else catch the event if our click handler is not set
e.stopPropagation(); e.stopPropagation();
onClick(value); onClick(value);
} }
} };
const filledSize = 15 / 2; const filledSize = 15 / 2;
const outlineOffset = 2; const outlineOffset = 2;
@ -76,6 +83,7 @@ export const SessionRadio = (props: Props) => {
onChange={clickHandler} onChange={clickHandler}
filledSize={filledSize * 2} filledSize={filledSize * 2}
outlineOffset={outlineOffset} outlineOffset={outlineOffset}
disabled={disabled}
data-testid={`input-${value}`} data-testid={`input-${value}`}
/> />
<StyledLabel <StyledLabel
@ -85,6 +93,7 @@ export const SessionRadio = (props: Props) => {
outlineOffset={outlineOffset} outlineOffset={outlineOffset}
beforeMargins={beforeMargins} beforeMargins={beforeMargins}
aria-label={label} aria-label={label}
disabled={disabled}
data-testid={`label-${value}`} data-testid={`label-${value}`}
> >
{label} {label}
@ -94,7 +103,7 @@ export const SessionRadio = (props: Props) => {
}; };
const StyledInputOutlineSelected = styled(StyledInput)` const StyledInputOutlineSelected = styled(StyledInput)`
color: var(--text-primary-color); color: ${props => (props.disabled ? 'var(--disabled-color)' : 'var(--text-primary-color)')};
label:before, label:before,
label:before { label:before {
outline: none; outline: none;
@ -105,7 +114,12 @@ const StyledInputOutlineSelected = styled(StyledInput)`
`; `;
const StyledLabelOutlineSelected = styled(StyledLabel)<{ selectedColor: string }>` const StyledLabelOutlineSelected = styled(StyledLabel)<{ selectedColor: string }>`
:before { :before {
background: ${props => (props.selectedColor ? props.selectedColor : 'var(--primary-color)')}; background: ${props =>
props.disabled
? 'var(--disabled-color)'
: props.selectedColor
? props.selectedColor
: 'var(--primary-color)'};
outline: 1px solid transparent; /* CSS variables don't work here */ outline: 1px solid transparent; /* CSS variables don't work here */
} }
`; `;
@ -120,8 +134,9 @@ export const SessionRadioPrimaryColors = (props: {
onClick: (value: string) => void; onClick: (value: string) => void;
ariaLabel: string; ariaLabel: string;
color: string; // by default, we use the theme accent color but for the settings screen we need to be able to force it color: string; // by default, we use the theme accent color but for the settings screen we need to be able to force it
disabled?: boolean;
}) => { }) => {
const { inputName, value, active, onClick, color, ariaLabel } = props; const { inputName, value, active, onClick, color, ariaLabel, disabled = false } = props;
function clickHandler(e: ChangeEvent<any>) { function clickHandler(e: ChangeEvent<any>) {
e.stopPropagation(); e.stopPropagation();
@ -144,6 +159,7 @@ export const SessionRadioPrimaryColors = (props: {
outlineOffset={outlineOffset} outlineOffset={outlineOffset}
selectedColor={color} selectedColor={color}
aria-label={ariaLabel} aria-label={ariaLabel}
disabled={disabled}
/> />
<StyledLabelOutlineSelected <StyledLabelOutlineSelected
@ -152,6 +168,7 @@ export const SessionRadioPrimaryColors = (props: {
selectedColor={color} selectedColor={color}
filledSize={filledSize} filledSize={filledSize}
outlineOffset={outlineOffset} outlineOffset={outlineOffset}
disabled={disabled}
> >
{''} {''}
</StyledLabelOutlineSelected> </StyledLabelOutlineSelected>

@ -2,10 +2,11 @@ import React, { ReactNode } from 'react';
import styled, { CSSProperties } from 'styled-components'; import styled, { CSSProperties } from 'styled-components';
// NOTE Used for descendant components // NOTE Used for descendant components
export const StyledContent = styled.div` export const StyledContent = styled.div<{ disabled: boolean }>`
display: flex; display: flex;
align-items: center; align-items: center;
width: 100%; width: 100%;
color: ${props => (props.disabled ? 'var(--disabled-color)' : 'inherit')};
`; `;
export const StyledText = styled.span` export const StyledText = styled.span`
@ -62,9 +63,10 @@ export const PanelButtonGroup = (props: PanelButtonGroupProps) => {
}; };
const StyledPanelButton = styled.button<{ const StyledPanelButton = styled.button<{
disableBg?: boolean; noBackgroundColor?: boolean;
disabled: boolean;
}>` }>`
cursor: pointer; cursor: ${props => (props.disabled ? 'not-allowed' : 'pointer')};
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
@ -76,7 +78,8 @@ const StyledPanelButton = styled.button<{
width: 100%; width: 100%;
transition: var(--default-duration); transition: var(--default-duration);
background-color: ${props => background-color: ${props =>
!props.disableBg ? 'var(--right-panel-item-background-hover-color) !important' : null}; !props.noBackgroundColor ? 'var(--right-panel-item-background-hover-color) !important' : null};
color: ${props => (props.disabled ? 'var(--disabled-color)' : 'inherit')};
:not(:last-child) { :not(:last-child) {
border-bottom: 1px solid var(--border-color); border-bottom: 1px solid var(--border-color);
@ -86,7 +89,8 @@ const StyledPanelButton = styled.button<{
export type PanelButtonProps = { export type PanelButtonProps = {
// https://styled-components.com/docs/basics#styling-any-component // https://styled-components.com/docs/basics#styling-any-component
className?: string; className?: string;
disableBg?: boolean; disabled?: boolean;
noBackgroundColor?: boolean;
children: ReactNode; children: ReactNode;
onClick: (...args: Array<any>) => void; onClick: (...args: Array<any>) => void;
dataTestId?: string; dataTestId?: string;
@ -94,12 +98,21 @@ export type PanelButtonProps = {
}; };
export const PanelButton = (props: PanelButtonProps) => { export const PanelButton = (props: PanelButtonProps) => {
const { className, disableBg, children, onClick, dataTestId, style } = props; const {
className,
disabled = false,
noBackgroundColor,
children,
onClick,
dataTestId,
style,
} = props;
return ( return (
<StyledPanelButton <StyledPanelButton
className={className} className={className}
disableBg={disableBg} noBackgroundColor={noBackgroundColor}
disabled={disabled}
onClick={onClick} onClick={onClick}
style={style} style={style}
data-testid={dataTestId} data-testid={dataTestId}

@ -8,11 +8,16 @@ interface PanelIconButton extends Omit<PanelButtonProps, 'children'> {
} }
export const PanelIconButton = (props: PanelIconButton) => { export const PanelIconButton = (props: PanelIconButton) => {
const { iconType, text, disableBg, onClick, dataTestId } = props; const { iconType, text, disabled = false, noBackgroundColor, onClick, dataTestId } = props;
return ( return (
<PanelButton disableBg={disableBg} onClick={onClick} dataTestId={dataTestId}> <PanelButton
<StyledContent> disabled={disabled}
noBackgroundColor={noBackgroundColor}
onClick={onClick}
dataTestId={dataTestId}
>
<StyledContent disabled={disabled}>
<SessionIcon iconType={iconType} iconSize="medium" /> <SessionIcon iconType={iconType} iconSize="medium" />
<StyledText>{text}</StyledText> <StyledText>{text}</StyledText>
</StyledContent> </StyledContent>

@ -44,23 +44,40 @@ interface PanelRadioButtonProps extends Omit<PanelButtonProps, 'children' | 'onC
} }
export const PanelRadioButton = (props: PanelRadioButtonProps) => { export const PanelRadioButton = (props: PanelRadioButtonProps) => {
const { value, text, subtitle, isSelected, onSelect, onUnselect, disableBg, dataTestId } = props; const {
value,
text,
subtitle,
isSelected,
onSelect,
onUnselect,
disabled = false,
noBackgroundColor,
dataTestId,
} = props;
return ( return (
<StyledPanelButton <StyledPanelButton
disableBg={disableBg} disabled={disabled}
noBackgroundColor={noBackgroundColor}
onClick={() => { onClick={() => {
isSelected ? onUnselect?.('bye') : onSelect?.('hi'); isSelected ? onUnselect?.('bye') : onSelect?.('hi');
}} }}
dataTestId={dataTestId} dataTestId={dataTestId}
> >
<StyledContent> <StyledContent disabled={disabled}>
<Flex container={true} width={'100%'} flexDirection={'column'} alignItems={'flex-start'}> <Flex container={true} width={'100%'} flexDirection={'column'} alignItems={'flex-start'}>
<StyledText>{text}</StyledText> <StyledText>{text}</StyledText>
{subtitle && <StyledSubtitle>{subtitle}</StyledSubtitle>} {subtitle && <StyledSubtitle>{subtitle}</StyledSubtitle>}
</Flex> </Flex>
<StyledCheckContainer> <StyledCheckContainer>
<SessionRadio active={isSelected} value={value} inputName={value} label="" /> <SessionRadio
active={isSelected}
value={value}
inputName={value}
label=""
disabled={disabled}
/>
</StyledCheckContainer> </StyledCheckContainer>
</StyledContent> </StyledContent>
</StyledPanelButton> </StyledPanelButton>

@ -336,7 +336,7 @@ export const OverlayRightPanelSettings = () => {
<PanelIconButton <PanelIconButton
iconType={'timer50'} iconType={'timer50'}
text={window.i18n('disappearingMessages')} text={window.i18n('disappearingMessages')}
disableBg={true} noBackgroundColor={true}
onClick={() => { onClick={() => {
dispatch(setRightOverlayMode('disappearing-messages')); dispatch(setRightOverlayMode('disappearing-messages'));
}} }}

Loading…
Cancel
Save