From 8a2e3865316636a47974b1c9595f1e0034ada63a Mon Sep 17 00:00:00 2001 From: alunturner <56027671+alunturner@users.noreply.github.com> Date: Thu, 19 Jan 2023 09:24:29 +0000 Subject: [PATCH] Add disabled button state to rich text editor (#9930) * add disabled css state * conditionally apply disabled css state * hides disabled tooltips --- .../components/_FormattingButtons.pcss | 6 ++++ .../components/FormattingButtons.tsx | 28 ++++++++++--------- .../components/FormattingButtons-test.tsx | 27 ++++++++++++++++-- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/res/css/views/rooms/wysiwyg_composer/components/_FormattingButtons.pcss b/res/css/views/rooms/wysiwyg_composer/components/_FormattingButtons.pcss index fa8078279f..8e3dd22c99 100644 --- a/res/css/views/rooms/wysiwyg_composer/components/_FormattingButtons.pcss +++ b/res/css/views/rooms/wysiwyg_composer/components/_FormattingButtons.pcss @@ -50,6 +50,12 @@ limitations under the License. } } + .mx_FormattingButtons_disabled { + .mx_FormattingButtons_Icon { + color: $quinary-content; + } + } + .mx_FormattingButtons_Icon { --size: 16px; height: var(--size); diff --git a/src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx b/src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx index 7c1601b441..11c797d646 100644 --- a/src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx +++ b/src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx @@ -15,7 +15,7 @@ limitations under the License. */ import React, { MouseEventHandler, ReactNode } from "react"; -import { FormattingFunctions, AllActionStates } from "@matrix-org/matrix-wysiwyg"; +import { FormattingFunctions, AllActionStates, ActionState } from "@matrix-org/matrix-wysiwyg"; import classNames from "classnames"; import { Icon as BoldIcon } from "../../../../../../res/img/element-icons/room/composer/bold.svg"; @@ -53,21 +53,23 @@ function Tooltip({ label, keyCombo }: TooltipProps): JSX.Element { interface ButtonProps extends TooltipProps { icon: ReactNode; - isActive: boolean; + actionState: ActionState; onClick: MouseEventHandler; } -function Button({ label, keyCombo, onClick, isActive, icon }: ButtonProps): JSX.Element { +function Button({ label, keyCombo, onClick, actionState, icon }: ButtonProps): JSX.Element { return ( void} title={label} className={classNames("mx_FormattingButtons_Button", { - mx_FormattingButtons_active: isActive, - mx_FormattingButtons_Button_hover: !isActive, + mx_FormattingButtons_active: actionState === "reversed", + mx_FormattingButtons_Button_hover: actionState === "enabled", + mx_FormattingButtons_disabled: actionState === "disabled", })} tooltip={keyCombo && } + forceHide={actionState === "disabled"} alignment={Alignment.Top} > {icon} @@ -85,53 +87,53 @@ export function FormattingButtons({ composer, actionStates }: FormattingButtonsP return (