|
|
|
@ -3,15 +3,6 @@ import styled from 'styled-components';
|
|
|
|
|
import { Flex } from '../basic/Flex';
|
|
|
|
|
// 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<{
|
|
|
|
|
filledSize: number;
|
|
|
|
|
outlineOffset: number;
|
|
|
|
@ -19,23 +10,29 @@ const StyledInput = styled.input<{
|
|
|
|
|
}>`
|
|
|
|
|
opacity: 0;
|
|
|
|
|
position: absolute;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
cursor: ${props => (props.disabled ? 'not-allowed' : 'pointer')};
|
|
|
|
|
width: ${props => props.filledSize + props.outlineOffset}px;
|
|
|
|
|
height: ${props => props.filledSize + props.outlineOffset}px;
|
|
|
|
|
|
|
|
|
|
: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
|
|
|
|
|
|
|
|
|
|
const StyledLabel = styled.label<{
|
|
|
|
|
disabled: boolean;
|
|
|
|
|
filledSize: number;
|
|
|
|
|
outlineOffset: number;
|
|
|
|
|
beforeMargins?: string;
|
|
|
|
|
}>`
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
color: var(--text-primary-color);
|
|
|
|
|
color: ${props => (props.disabled ? 'var(--disabled-color)' : 'var(--text-primary-color)')};
|
|
|
|
|
|
|
|
|
|
:before {
|
|
|
|
|
content: '';
|
|
|
|
@ -51,16 +48,26 @@ const StyledLabel = styled.label<{
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const SessionRadio = (props: Props) => {
|
|
|
|
|
const { label, inputName, value, active, onClick, beforeMargins } = props;
|
|
|
|
|
type SessionRadioProps = {
|
|
|
|
|
label: string;
|
|
|
|
|
value: string;
|
|
|
|
|
active: boolean;
|
|
|
|
|
inputName?: string;
|
|
|
|
|
beforeMargins?: string;
|
|
|
|
|
onClick?: (value: string) => void;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function clickHandler(e: ChangeEvent<any>) {
|
|
|
|
|
if (onClick) {
|
|
|
|
|
export const SessionRadio = (props: SessionRadioProps) => {
|
|
|
|
|
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
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onClick(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const filledSize = 15 / 2;
|
|
|
|
|
const outlineOffset = 2;
|
|
|
|
@ -76,6 +83,7 @@ export const SessionRadio = (props: Props) => {
|
|
|
|
|
onChange={clickHandler}
|
|
|
|
|
filledSize={filledSize * 2}
|
|
|
|
|
outlineOffset={outlineOffset}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
data-testid={`input-${value}`}
|
|
|
|
|
/>
|
|
|
|
|
<StyledLabel
|
|
|
|
@ -85,6 +93,7 @@ export const SessionRadio = (props: Props) => {
|
|
|
|
|
outlineOffset={outlineOffset}
|
|
|
|
|
beforeMargins={beforeMargins}
|
|
|
|
|
aria-label={label}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
data-testid={`label-${value}`}
|
|
|
|
|
>
|
|
|
|
|
{label}
|
|
|
|
@ -94,7 +103,7 @@ export const SessionRadio = (props: Props) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const StyledInputOutlineSelected = styled(StyledInput)`
|
|
|
|
|
color: var(--text-primary-color);
|
|
|
|
|
color: ${props => (props.disabled ? 'var(--disabled-color)' : 'var(--text-primary-color)')};
|
|
|
|
|
label:before,
|
|
|
|
|
label:before {
|
|
|
|
|
outline: none;
|
|
|
|
@ -105,7 +114,12 @@ const StyledInputOutlineSelected = styled(StyledInput)`
|
|
|
|
|
`;
|
|
|
|
|
const StyledLabelOutlineSelected = styled(StyledLabel)<{ selectedColor: string }>`
|
|
|
|
|
: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 */
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
@ -120,8 +134,9 @@ export const SessionRadioPrimaryColors = (props: {
|
|
|
|
|
onClick: (value: string) => void;
|
|
|
|
|
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
|
|
|
|
|
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>) {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
@ -144,6 +159,7 @@ export const SessionRadioPrimaryColors = (props: {
|
|
|
|
|
outlineOffset={outlineOffset}
|
|
|
|
|
selectedColor={color}
|
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<StyledLabelOutlineSelected
|
|
|
|
@ -152,6 +168,7 @@ export const SessionRadioPrimaryColors = (props: {
|
|
|
|
|
selectedColor={color}
|
|
|
|
|
filledSize={filledSize}
|
|
|
|
|
outlineOffset={outlineOffset}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
>
|
|
|
|
|
{''}
|
|
|
|
|
</StyledLabelOutlineSelected>
|
|
|
|
|