Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions frontend/__tests__/LogoutButton.test.js
Original file line number Diff line number Diff line change
@@ -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(
/<button[^>]*>/,
)[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"');
});
});
1 change: 1 addition & 0 deletions frontend/__tests__/exports.test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
94 changes: 94 additions & 0 deletions frontend/src/components/LogoutButton.css
Original file line number Diff line number Diff line change
@@ -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;
}
110 changes: 12 additions & 98 deletions frontend/src/components/LogoutButton.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import useAuth from '../hooks/useAuth';
import './LogoutButton.css';
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

const LogoutButton = ({
design = 'modern',
Expand Down Expand Up @@ -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 (
Expand All @@ -181,25 +109,11 @@ const LogoutButton = ({
)}

<button
type="button"
onClick={handleLogout}
disabled={isLoggingOut}
style={buttonStyle}
className={buttonClasses}
title={`Sign out ${user.username}`}
onMouseEnter={(e) => {
if (!isLoggingOut) {
const design = getButtonStyle().buttonStyle;
if (design[':hover']) {
Object.assign(e.target.style, design[':hover']);
}
}
}}
onMouseLeave={(e) => {
if (!isLoggingOut) {
const design = getButtonStyle().buttonStyle;
e.target.style.backgroundColor = design.backgroundColor;
e.target.style.color = design.color;
}
}}
>
{isLoggingOut ? 'Signing out...' : 'Sign Out'}
</button>
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"require": "./dist/frontend/index.js"
}
},
"sideEffects": false,
"sideEffects": [
"**/*.css"
],
"files": [
"dist/",
"frontend/index.js",
Expand Down