mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 11:23:10 +02:00
# Description of Changes Changes the strategy for autoformatting to reject PRs if they are not formatted correctly instead of allowing them to merge and then spawning a new PR to fix the formatting. The old strategy just caused more work for us because we'd have to manually approve the followup PR and get it merged, which required 2 reviewers so in practice it rarely got done and just meant everyone's PRs ended up containing reformatting for unrelated files, which makes code review unnecessarily difficult. If the PR's code is not formatted correctly after this PR, a comment will be added automatically to tell the author how to run the formatter script to fix their code so it can go in. This also enables autoformatting for the frontend code, using Prettier. I've enabled it for pretty much everything in the frontend folder, other than 3rd party files and files it doesn't make sense for. I also excluded Markdown because it sounds likely to be more annoying to have to autoformat the Markdown in the frontend folder but nowhere else. Open to changing this though if people disagree. > [!note] > > Advice to reviewers: The first commit contains all of the actual logic I've introduced (CI changes, Prettier config, etc.) > The second commit is just the reformatting of the entire frontend folder. > The first commit needs proper review, the second one just give it a spot-check that it's doing what you'd expect.
102 lines
2.2 KiB
TypeScript
102 lines
2.2 KiB
TypeScript
import React from "react";
|
|
import { Box } from "@mantine/core";
|
|
|
|
interface BadgeProps {
|
|
children: React.ReactNode;
|
|
size?: "sm" | "md" | "lg";
|
|
variant?: "default" | "colored";
|
|
color?: string;
|
|
textColor?: string;
|
|
backgroundColor?: string;
|
|
className?: string;
|
|
style?: React.CSSProperties;
|
|
}
|
|
|
|
const Badge: React.FC<BadgeProps> = ({
|
|
children,
|
|
size = "sm",
|
|
variant = "default",
|
|
color,
|
|
textColor,
|
|
backgroundColor,
|
|
className,
|
|
style,
|
|
}) => {
|
|
const getSizeStyles = () => {
|
|
switch (size) {
|
|
case "sm":
|
|
return {
|
|
padding: "0.125rem 0.5rem",
|
|
fontSize: "0.75rem",
|
|
fontWeight: 700,
|
|
borderRadius: "0.5rem",
|
|
};
|
|
case "md":
|
|
return {
|
|
padding: "0.25rem 0.75rem",
|
|
fontSize: "0.875rem",
|
|
fontWeight: 700,
|
|
borderRadius: "0.625rem",
|
|
};
|
|
case "lg":
|
|
return {
|
|
padding: "0.375rem 1rem",
|
|
fontSize: "1rem",
|
|
fontWeight: 700,
|
|
borderRadius: "0.75rem",
|
|
};
|
|
default:
|
|
return {};
|
|
}
|
|
};
|
|
|
|
const getVariantStyles = () => {
|
|
// If explicit colors are provided, use them
|
|
if (textColor && backgroundColor) {
|
|
return {
|
|
backgroundColor,
|
|
color: textColor,
|
|
};
|
|
}
|
|
|
|
// If a single color is provided, use it for text and 20% opacity for background
|
|
if (color) {
|
|
return {
|
|
backgroundColor: `color-mix(in srgb, ${color} 20%, transparent)`,
|
|
color: color,
|
|
};
|
|
}
|
|
|
|
// If variant is colored but no color provided, use default colored styling
|
|
if (variant === "colored") {
|
|
return {
|
|
backgroundColor: `color-mix(in srgb, var(--category-color-default) 15%, transparent)`,
|
|
color: "var(--category-color-default)",
|
|
borderColor: `color-mix(in srgb, var(--category-color-default) 30%, transparent)`,
|
|
border: "1px solid",
|
|
};
|
|
}
|
|
|
|
// Default styling
|
|
return {
|
|
background: "var(--tool-header-badge-bg)",
|
|
color: "var(--tool-header-badge-text)",
|
|
};
|
|
};
|
|
|
|
return (
|
|
<Box
|
|
className={className}
|
|
style={{
|
|
...getSizeStyles(),
|
|
...getVariantStyles(),
|
|
...style,
|
|
}}
|
|
>
|
|
{children}
|
|
</Box>
|
|
);
|
|
};
|
|
|
|
export default Badge;
|