From c927f6e0b65bb3f23ef23cbe5fd3f1391a0a81fa Mon Sep 17 00:00:00 2001 From: "charlie.chinchay" Date: Wed, 18 Nov 2026 21:24:54 +0100 Subject: [PATCH 1/2] fix: move LogoutButton hover/disabled styles to CSS The designs object in LogoutButton.jsx used ':hover' and ':disabled' as inline-style keys, which React ignores. Hover was emulated with onMouseEnter/onMouseLeave and the disabled style never applied, so the button looked unchanged while signing out. Move base, size, design, hover and disabled styles to LogoutButton.css and apply them through logout-button, design-* and size-* classes, as SetPasswordButton already does. Hover only applies when the button is enabled, the disabled state is visibly lighter in every design, and a focus-visible outline replaces the removed outline: none. The button is now type="button". Closes #65 --- frontend/__tests__/LogoutButton.test.js | 53 +++++++++++ frontend/__tests__/exports.test.js | 1 + frontend/src/components/LogoutButton.css | 94 +++++++++++++++++++ frontend/src/components/LogoutButton.jsx | 110 +++-------------------- 4 files changed, 160 insertions(+), 98 deletions(-) create mode 100644 frontend/__tests__/LogoutButton.test.js create mode 100644 frontend/src/components/LogoutButton.css diff --git a/frontend/__tests__/LogoutButton.test.js b/frontend/__tests__/LogoutButton.test.js new file mode 100644 index 0000000..428a0f1 --- /dev/null +++ b/frontend/__tests__/LogoutButton.test.js @@ -0,0 +1,53 @@ +const React = require("react"); +const { renderToStaticMarkup } = require("react-dom/server"); + +jest.mock("../src/hooks/useAuth", () => ({ + __esModule: true, + default: jest.fn(), +})); +jest.mock("../src/components/LogoutButton.css", () => ({})); + +const useAuth = require("../src/hooks/useAuth").default; +const LogoutButton = require("../src/components/LogoutButton").default; + +const renderButton = (props) => + renderToStaticMarkup(React.createElement(LogoutButton, props)).match( + /]*>/, + )[0]; + +describe("LogoutButton", () => { + beforeEach(() => { + useAuth.mockReturnValue({ user: { username: "demo" }, signout: jest.fn() }); + }); + + it("uses the default design and size classes", () => { + expect(renderButton()).toContain( + 'class="logout-button design-modern size-medium"', + ); + }); + + it.each(["modern", "minimal", "outline", "rounded"])( + "applies the %s design class", + (design) => { + expect(renderButton({ design, size: "large" })).toContain( + `design-${design} size-large`, + ); + }, + ); + + it("has no inline styles or pseudo-selectors on the button", () => { + expect(renderButton()).not.toContain("style="); + const html = renderToStaticMarkup(React.createElement(LogoutButton)); + expect(html).not.toContain(":hover"); + expect(html).not.toContain(":disabled"); + }); + + it("renders nothing when the user is signed out", () => { + useAuth.mockReturnValue({ user: null }); + expect(renderToStaticMarkup(React.createElement(LogoutButton))).toBe(""); + }); + + it("is a non-submit button", () => { + expect(renderButton()).toContain('type="button"'); + }); +}); diff --git a/frontend/__tests__/exports.test.js b/frontend/__tests__/exports.test.js index 1007737..f0a1bc1 100644 --- a/frontend/__tests__/exports.test.js +++ b/frontend/__tests__/exports.test.js @@ -1,6 +1,7 @@ jest.mock('../src/components/AuthForm.css', () => ({})); jest.mock('../src/components/AuthStatus.css', () => ({})); jest.mock('../src/components/SetPasswordButton.css', () => ({})); +jest.mock('../src/components/LogoutButton.css', () => ({})); const frontend = require('../index'); const source = require('../src/index'); diff --git a/frontend/src/components/LogoutButton.css b/frontend/src/components/LogoutButton.css new file mode 100644 index 0000000..575b3b4 --- /dev/null +++ b/frontend/src/components/LogoutButton.css @@ -0,0 +1,94 @@ +.logout-button { + border: none; + border-radius: 6px; + cursor: pointer; + font-weight: 500; + transition: all 0.2s ease; + font-family: inherit; +} + +/* Size Variants */ +.logout-button.size-small { + padding: 6px 12px; + font-size: 14px; +} + +.logout-button.size-medium { + padding: 8px 16px; + font-size: 16px; +} + +.logout-button.size-large { + padding: 12px 24px; + font-size: 18px; +} + +/* Design */ +.logout-button.design-modern { + background-color: #dc2626; + color: white; +} + +.logout-button.design-minimal { + background-color: #e5e7eb; + color: #374151; +} + +.logout-button.design-outline { + background-color: transparent; + color: #dc2626; + border: 2px solid #dc2626; +} + +.logout-button.design-rounded { + background-color: #dc2626; + color: white; + border-radius: 50px; +} + +/* Hover Effects */ +.logout-button.design-modern:hover:not(:disabled) { + background-color: #b91c1c; +} + +.logout-button.design-minimal:hover:not(:disabled) { + background-color: #d1d5db; +} + +.logout-button.design-outline:hover:not(:disabled) { + background-color: #dc2626; + color: white; +} + +.logout-button.design-rounded:hover:not(:disabled) { + background-color: #b91c1c; +} + +/* Disabled State */ +.logout-button.design-modern:disabled { + background-color: #fca5a5; + cursor: not-allowed; +} + +.logout-button.design-minimal:disabled { + background-color: #f3f4f6; + color: #9ca3af; + cursor: not-allowed; +} + +.logout-button.design-outline:disabled { + border-color: #fca5a5; + color: #fca5a5; + cursor: not-allowed; +} + +.logout-button.design-rounded:disabled { + background-color: #fca5a5; + cursor: not-allowed; +} + +/* Focus State */ +.logout-button:focus-visible { + outline: 2px solid #dc2626; + outline-offset: 2px; +} diff --git a/frontend/src/components/LogoutButton.jsx b/frontend/src/components/LogoutButton.jsx index 594d671..510848b 100644 --- a/frontend/src/components/LogoutButton.jsx +++ b/frontend/src/components/LogoutButton.jsx @@ -1,5 +1,6 @@ import React, { useState } from 'react'; import useAuth from '../hooks/useAuth'; +import './LogoutButton.css'; const LogoutButton = ({ design = 'modern', @@ -82,91 +83,18 @@ const LogoutButton = ({ }; }; - // Design styles - const getButtonStyle = () => { - const baseButtonStyle = { - border: 'none', - borderRadius: '6px', - cursor: 'pointer', - fontWeight: '500', - transition: 'all 0.2s ease', - outline: 'none', - fontFamily: 'inherit' - }; - - const sizes = { - small: { padding: '6px 12px', fontSize: '14px' }, - medium: { padding: '8px 16px', fontSize: '16px' }, - large: { padding: '12px 24px', fontSize: '18px' } - }; - - const designs = { - modern: { - backgroundColor: '#dc2626', - color: 'white', - ':hover': { - backgroundColor: '#b91c1c' - }, - ':disabled': { - backgroundColor: '#fca5a5', - cursor: 'not-allowed' - } - }, - minimal: { - backgroundColor: '#e5e7eb', - color: '#374151', - ':hover': { - backgroundColor: '#d1d5db' - }, - ':disabled': { - backgroundColor: '#f3f4f6', - cursor: 'not-allowed' - } - }, - outline: { - backgroundColor: 'transparent', - color: '#dc2626', - border: '2px solid #dc2626', - ':hover': { - backgroundColor: '#dc2626', - color: 'white' - }, - ':disabled': { - borderColor: '#fca5a5', - color: '#fca5a5', - cursor: 'not-allowed' - } - }, - rounded: { - backgroundColor: '#dc2626', - color: 'white', - borderRadius: '50px', - ':hover': { - backgroundColor: '#b91c1c' - }, - ':disabled': { - backgroundColor: '#fca5a5', - cursor: 'not-allowed' - } - } - }; - - const userInfoStyle = { - fontSize: '14px', - color: '#6b7280' - }; + // Design, size, hover and disabled styles live in LogoutButton.css + const buttonClasses = [ + 'logout-button', + `design-${design}`, + `size-${size}` + ].join(' '); - return { - buttonStyle: { - ...baseButtonStyle, - ...sizes[size], - ...designs[design] - }, - userInfoStyle - }; + const userInfoStyle = { + fontSize: '14px', + color: '#6b7280' }; - const { buttonStyle, userInfoStyle } = getButtonStyle(); const containerStyle = getContainerStyle(); return ( @@ -181,25 +109,11 @@ const LogoutButton = ({ )} From 83461ba94dc0634d551710b49df1c42e3b7bbb60 Mon Sep 17 00:00:00 2001 From: "charlie.chinchay" Date: Wed, 18 Nov 2026 21:52:24 +0100 Subject: [PATCH 2/2] fix: mark CSS files as side effects so bundlers keep them With "sideEffects": false, webpack can drop bare stylesheet imports such as import './LogoutButton.css' in production builds. LogoutButton now relies on its stylesheet for all of its styling, so list CSS files as side effects to keep them in consumers' bundles. --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 98387b3..5fd4cb1 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,9 @@ "require": "./dist/frontend/index.js" } }, - "sideEffects": false, + "sideEffects": [ + "**/*.css" + ], "files": [ "dist/", "frontend/index.js",