refactor(ui): extract reusable component package
This commit is contained in:
parent
87261b5a3f
commit
2664804e91
86 changed files with 102 additions and 85 deletions
32
packages/ui/src/components/ModuleCard.tsx
Normal file
32
packages/ui/src/components/ModuleCard.tsx
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { useId } from "react";
|
||||
import type { UiModuleBlock } from "../types";
|
||||
import { IconGlyph } from "./IconGlyph";
|
||||
|
||||
export interface ModuleCardProps {
|
||||
module: UiModuleBlock;
|
||||
}
|
||||
|
||||
export function ModuleCard({ module }: ModuleCardProps) {
|
||||
const generatedId = useId();
|
||||
const titleId = `${generatedId}-title`;
|
||||
const ariaLabel = module.title ? undefined : module.label || module.id;
|
||||
|
||||
return (
|
||||
<aside
|
||||
className="module-card"
|
||||
data-severity={module.severity || "neutral"}
|
||||
data-model-id={module.id}
|
||||
aria-labelledby={module.title ? titleId : undefined}
|
||||
aria-label={ariaLabel}
|
||||
>
|
||||
<div>
|
||||
{module.title ? <h2 id={titleId}>{module.title}</h2> : null}
|
||||
{module.value ? <strong>{module.value}</strong> : null}
|
||||
{module.detail || module.label ? (
|
||||
<p>{module.detail || module.label}</p>
|
||||
) : null}
|
||||
</div>
|
||||
{module.icon ? <IconGlyph name={module.icon} size="lg" /> : null}
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue