fix(gallery): improve watermark contrast and add status badges to style cards (#573) (#594)

This commit is contained in:
FanYu 2026-11-24 12:09:36 +08:00 committed by GitHub
parent e8b065f0f3
commit f2f7266b07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 45 additions and 2 deletions

View File

@ -3,6 +3,7 @@
import { StyleData } from "@/lib/types";
import { hasTextSelectionIn, isNestedControlClick } from "@/lib/nestedControl";
import { StyleCardTitle } from "./StyleCardTitle";
import { StyleStatusBadge } from "./StyleStatusBadge";
import { StylePreview } from "./StylePreview";
import { ColorPalette } from "./ColorPalette";
import { MetadataBadges } from "./MetadataBadges";
@ -33,6 +34,7 @@ export function StyleCard({ style, onSelect }: StyleCardProps) {
onOpen={onSelect ? () => onSelect(style) : undefined}
/>
<div className="flex items-center gap-1.5 shrink-0">
<StyleStatusBadge status={style.status} />
<span className="text-[10px] px-2 py-0.5 rounded-full bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400">
{style.type}
</span>

View File

@ -70,8 +70,8 @@ export function StylePreview({ style }: StylePreviewProps) {
</div>
{/* Style name overlay */}
<div className="absolute bottom-0 left-0 right-0 px-3 py-1.5 bg-gradient-to-t from-black/40 to-transparent">
<span className="text-[10px] font-medium text-white/80">
<div className="absolute bottom-0 left-0 right-0 px-3 py-1.5 bg-gradient-to-t from-black/60 to-transparent">
<span className="text-[10px] font-semibold text-white/95">
Preview
</span>
</div>

View File

@ -0,0 +1,22 @@
interface StyleStatusBadgeProps {
status: string;
}
export function StyleStatusBadge({ status }: StyleStatusBadgeProps) {
if (!status) return null;
const colorClass =
status === "deprecated"
? "bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400"
: status === "supplemental"
? "bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400"
: "bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400";
return (
<span
className={`text-[10px] px-2 py-0.5 rounded-full font-medium ${colorClass}`}
>
{status}
</span>
);
}

View File

@ -4,6 +4,7 @@ import { renderToStaticMarkup } from "react-dom/server";
import { hasTextSelectionIn, isNestedControlClick } from "../lib/nestedControl";
import { StyleCardTitle } from "./StyleCardTitle";
import { StyleStatusBadge } from "./StyleStatusBadge";
// Stands in for a DOM element: closest() returns a marker node when the
// element itself, or one of the ancestors listed in `path`, matches one of the
@ -70,3 +71,20 @@ test("a click that ends a text selection does not open the detail dialog", () =>
assert.equal(hasTextSelectionIn({ isCollapsed: false, anchorNode: elsewhere }, card), false);
assert.equal(hasTextSelectionIn(null, card), false);
});
test("style status badge renders corresponding semantic colors for status types", () => {
const activeMarkup = renderToStaticMarkup(<StyleStatusBadge status="active" />);
assert.match(activeMarkup, /bg-green-100/);
assert.match(activeMarkup, />active<\/span>/);
const supplementalMarkup = renderToStaticMarkup(<StyleStatusBadge status="supplemental" />);
assert.match(supplementalMarkup, /bg-blue-100/);
assert.match(supplementalMarkup, />supplemental<\/span>/);
const deprecatedMarkup = renderToStaticMarkup(<StyleStatusBadge status="deprecated" />);
assert.match(deprecatedMarkup, /bg-red-100/);
assert.match(deprecatedMarkup, />deprecated<\/span>/);
const emptyMarkup = renderToStaticMarkup(<StyleStatusBadge status="" />);
assert.equal(emptyMarkup, "");
});

View File

@ -24,6 +24,7 @@
"components/MetadataBadges.tsx",
"components/FilterBar.tsx",
"components/StyleCardTitle.tsx",
"components/StyleStatusBadge.tsx",
"components/metadata-badges.test.tsx",
"components/style-card.test.tsx"
]