Add more checkbox styles (#7058)

Add a "kind" param for StyledCheckbox, allowing designers to choose different styles of checkbox as needed.  In addition to the preexisting default kind (now called Solid), there's an Outline kind with a green checkmark and a transparent fill.  This is used in the device trust view, since the default checkbox style looks too much like the green "verified" shield and it's awkward to have those next to each other.
pull/21833/head
Faye Duxovni 2021-10-29 21:57:32 -04:00 committed by GitHub
parent d88b8efd19
commit 71244f3b3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 21 deletions

View File

@ -48,23 +48,21 @@ limitations under the License.
box-sizing: border-box;
border-radius: $border-radius;
img {
.mx_Checkbox_checkmark {
display: none;
height: 100%;
width: 100%;
filter: invert(100%);
mask-image: url('$(res)/img/feather-customised/check.svg');
mask-position: center;
mask-size: 100%;
mask-repeat: no-repeat;
}
}
&:checked + label > .mx_Checkbox_background {
background: $accent-color;
border-color: $accent-color;
img {
&:checked + label > .mx_Checkbox_background .mx_Checkbox_checkmark {
display: block;
}
}
& + label > *:not(.mx_Checkbox_background) {
margin-left: 10px;
@ -75,11 +73,6 @@ limitations under the License.
cursor: not-allowed;
}
&:checked:disabled + label > .mx_Checkbox_background {
background-color: $accent-color;
border-color: $accent-color;
}
&.focus-visible {
& + label .mx_Checkbox_background {
@mixin unreal-focus;
@ -87,3 +80,25 @@ limitations under the License.
}
}
}
.mx_Checkbox.mx_Checkbox_kind_solid input[type=checkbox] {
& + label > .mx_Checkbox_background .mx_Checkbox_checkmark {
background: #ffffff;
}
&:checked + label > .mx_Checkbox_background {
background: $accent-color;
border-color: $accent-color;
}
}
.mx_Checkbox.mx_Checkbox_kind_outline input[type=checkbox] {
& + label > .mx_Checkbox_background .mx_Checkbox_checkmark {
background: $accent-color;
}
&:checked + label > .mx_Checkbox_background {
background: transparent;
border-color: $accent-color;
}
}

View File

@ -17,8 +17,15 @@ limitations under the License.
import React from "react";
import { randomString } from "matrix-js-sdk/src/randomstring";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import classnames from 'classnames';
export enum CheckboxStyle {
Solid = "solid",
Outline = "outline",
}
interface IProps extends React.InputHTMLAttributes<HTMLInputElement> {
kind?: CheckboxStyle;
}
interface IState {
@ -40,13 +47,21 @@ export default class StyledCheckbox extends React.PureComponent<IProps, IState>
public render() {
/* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */
const { children, className, ...otherProps } = this.props;
return <span className={"mx_Checkbox " + className}>
const { children, className, kind = CheckboxStyle.Solid, ...otherProps } = this.props;
const newClassName = classnames(
"mx_Checkbox",
className,
{
"mx_Checkbox_hasKind": kind,
[`mx_Checkbox_kind_${kind}`]: kind,
},
);
return <span className={newClassName}>
<input id={this.id} {...otherProps} type="checkbox" />
<label htmlFor={this.id}>
{ /* Using the div to center the image */ }
<div className="mx_Checkbox_background">
<img src={require("../../../../res/img/feather-customised/check.svg")} />
<div className="mx_Checkbox_checkmark" />
</div>
<div>
{ this.props.children }

View File

@ -21,6 +21,7 @@ import { _t } from '../../../languageHandler';
import { MatrixClientPeg } from '../../../MatrixClientPeg';
import { formatDate } from '../../../DateUtils';
import StyledCheckbox from '../elements/StyledCheckbox';
import { CheckboxStyle } from '../elements/StyledCheckbox';
import { replaceableComponent } from "../../../utils/replaceableComponent";
import AccessibleButton from "../elements/AccessibleButton";
import Field from "../elements/Field";
@ -153,7 +154,7 @@ export default class DevicesPanelEntry extends React.Component<IProps, IState> {
<span className={"mx_DevicesPanel_icon mx_E2EIcon " + iconClass} />
</div> :
<div className="mx_DevicesPanel_checkbox">
<StyledCheckbox onChange={this.onDeviceToggled} checked={this.props.selected} />
<StyledCheckbox kind={CheckboxStyle.Outline} onChange={this.onDeviceToggled} checked={this.props.selected} />
</div>;
const buttons = this.state.renaming ?

View File

@ -243,7 +243,7 @@ exports[`FontScalingPanel renders the font scaling UI 1`] = `
onChange={[Function]}
>
<span
className="mx_Checkbox "
className="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
>
<input
checked={false}
@ -258,8 +258,8 @@ exports[`FontScalingPanel renders the font scaling UI 1`] = `
<div
className="mx_Checkbox_background"
>
<img
src="image-file-stub"
<div
className="mx_Checkbox_checkmark"
/>
</div>
<div>