Add hover / active state on avatsetting upload button (#12590)

pull/28217/head
David Baker 2024-06-07 17:16:41 +01:00 committed by GitHub
parent aeea4bb8e1
commit 7091ca02b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 10 deletions

View File

@ -51,7 +51,7 @@ limitations under the License.
height: 28px; height: 28px;
border-radius: 32px; border-radius: 32px;
border: 1px solid var(--cpd-color-bg-canvas-default); border: 1px solid var(--cpd-color-bg-canvas-default);
background-color: var(--cpd-color-bg-subtle-primary); background-color: var(--cpd-color-bg-canvas-default);
position: absolute; position: absolute;
bottom: 0; bottom: 0;
@ -64,6 +64,11 @@ limitations under the License.
top: 3px; top: 3px;
} }
} }
.mx_AvatarSetting_uploadButton:hover,
.mx_AvatarSetting_uploadButton_active {
background-color: var(--cpd-color-bg-subtle-primary);
}
} }
.mx_AvatarSetting_removeMenuItem svg, .mx_AvatarSetting_removeMenuItem svg,

View File

@ -19,6 +19,7 @@ import { Icon as EditIcon } from "@vector-im/compound-design-tokens/icons/edit.s
import { Icon as UploadIcon } from "@vector-im/compound-design-tokens/icons/share.svg"; import { Icon as UploadIcon } from "@vector-im/compound-design-tokens/icons/share.svg";
import { Icon as DeleteIcon } from "@vector-im/compound-design-tokens/icons/delete.svg"; import { Icon as DeleteIcon } from "@vector-im/compound-design-tokens/icons/delete.svg";
import { Menu, MenuItem } from "@vector-im/compound-web"; import { Menu, MenuItem } from "@vector-im/compound-web";
import classNames from "classnames";
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
import { mediaFromMxc } from "../../../customisations/Media"; import { mediaFromMxc } from "../../../customisations/Media";
@ -31,15 +32,17 @@ interface MenuProps {
trigger: ReactNode; trigger: ReactNode;
onUploadSelect: () => void; onUploadSelect: () => void;
onRemoveSelect?: () => void; onRemoveSelect?: () => void;
menuOpen: boolean;
onOpenChange: (newOpen: boolean) => void;
} }
const AvatarSettingContextMenu: React.FC<MenuProps> = ({ trigger, onUploadSelect, onRemoveSelect }) => { const AvatarSettingContextMenu: React.FC<MenuProps> = ({
const [menuOpen, setMenuOpen] = useState(false); trigger,
onUploadSelect,
const onOpenChange = useCallback((newOpen: boolean) => { onRemoveSelect,
setMenuOpen(newOpen); menuOpen,
}, []); onOpenChange,
}) => {
return ( return (
<Menu <Menu
trigger={trigger} trigger={trigger}
@ -153,6 +156,12 @@ const AvatarSetting: React.FC<IProps> = ({
fileInputRef.current?.click(); fileInputRef.current?.click();
}, [fileInputRef]); }, [fileInputRef]);
const [menuOpen, setMenuOpen] = useState(false);
const onOpenChange = useCallback((newOpen: boolean) => {
setMenuOpen(newOpen);
}, []);
let avatarElement = ( let avatarElement = (
<AccessibleButton <AccessibleButton
element="div" element="div"
@ -181,8 +190,11 @@ const AvatarSetting: React.FC<IProps> = ({
let uploadAvatarBtn: JSX.Element | undefined; let uploadAvatarBtn: JSX.Element | undefined;
if (!disabled) { if (!disabled) {
const uploadButtonClasses = classNames("mx_AvatarSetting_uploadButton", {
mx_AvatarSetting_uploadButton_active: menuOpen,
});
uploadAvatarBtn = ( uploadAvatarBtn = (
<div className="mx_AvatarSetting_uploadButton"> <div className={uploadButtonClasses}>
<EditIcon width="20px" height="20px" /> <EditIcon width="20px" height="20px" />
</div> </div>
); );
@ -201,7 +213,13 @@ const AvatarSetting: React.FC<IProps> = ({
return ( return (
<> <>
<AvatarSettingContextMenu trigger={content} onUploadSelect={uploadAvatar} onRemoveSelect={removeAvatar} /> <AvatarSettingContextMenu
trigger={content}
onUploadSelect={uploadAvatar}
onRemoveSelect={removeAvatar}
menuOpen={menuOpen}
onOpenChange={onOpenChange}
/>
<input <input
type="file" type="file"
style={{ display: "none" }} style={{ display: "none" }}