DetailCell.tsx 1.13 KB
import type { ReactNode } from 'react';
import { UTag } from '@uj/ui';
import type { StatusMeta } from './dictionaries';

/** 一个「标签 + 值」的详情项:value 与 tag 二选一,code 让长单号走等宽字体。 */
export interface DetailValue {
  label: ReactNode;
  value?: string;
  /** 状态这类要带颜色的项,值交给徽标显示。 */
  tag?: StatusMeta;
  code?: boolean;
}

export function DetailCell({ cell }: { cell: DetailValue }) {
  return (
    <div className="uj-points-detail-item">
      <dt>{cell.label}</dt>
      <dd>
        {cell.tag ? (
          <UTag color={cell.tag.color} style={{ borderRadius: 6 }}>
            {cell.tag.label}
          </UTag>
        ) : (
          <span className={cell.code ? 'uj-code' : undefined}>{cell.value}</span>
        )}
      </dd>
    </div>
  );
}

/** 三列一行的详情网格;弹窗与子页面用的是同一个栅格。 */
export function DetailGrid({ cells }: { cells: DetailValue[] }) {
  return (
    <dl className="uj-points-detail-grid">
      {cells.map((cell) => (
        <DetailCell key={String(cell.label)} cell={cell} />
      ))}
    </dl>
  );
}