2026-05-20 01:30:41 +08:00
|
|
|
|
'use client';
|
|
|
|
|
|
import React, { ReactNode, CSSProperties } from 'react';
|
2026-05-19 21:09:56 +08:00
|
|
|
|
import { visualWeights, resolveFontSize } from '@newspaperui/theme';
|
2026-05-20 01:30:41 +08:00
|
|
|
|
import { cx } from '@newspaperui/utils';
|
2026-05-19 21:09:56 +08:00
|
|
|
|
|
|
|
|
|
|
export interface CaptionProps {
|
2026-05-20 01:30:41 +08:00
|
|
|
|
credit?: string; // e.g. "Photograph by Jane Doe"
|
|
|
|
|
|
className?: string;
|
|
|
|
|
|
style?: CSSProperties;
|
|
|
|
|
|
children: ReactNode;
|
2026-05-19 21:09:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-20 14:22:14 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* Caption — 图片说明(italic + credit small-caps)
|
|
|
|
|
|
*
|
|
|
|
|
|
* - 主体文字为 italic 衬线,描述图片内容
|
|
|
|
|
|
* - credit 部分以 small-caps 显示摄影师/来源信息
|
|
|
|
|
|
* - 渲染为 figcaption,语义化配合 Figure 使用
|
|
|
|
|
|
*
|
|
|
|
|
|
* @example
|
|
|
|
|
|
* <Caption credit="Photograph by Jane Doe">
|
|
|
|
|
|
* A view of the city skyline at sunset.
|
|
|
|
|
|
* </Caption>
|
|
|
|
|
|
*/
|
2026-05-20 01:30:41 +08:00
|
|
|
|
export const Caption: React.FC<CaptionProps> = ({ credit, className, style, children }) => {
|
|
|
|
|
|
const config = visualWeights.Caption.Standard!;
|
2026-05-19 21:09:56 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<figcaption
|
2026-05-20 01:30:41 +08:00
|
|
|
|
className={cx('nui-caption nui-osf', className)}
|
2026-05-19 21:09:56 +08:00
|
|
|
|
style={{
|
2026-05-20 01:30:41 +08:00
|
|
|
|
fontFamily: `var(${config.fontFamily})`,
|
2026-05-19 21:09:56 +08:00
|
|
|
|
fontSize: resolveFontSize(config.fontSize),
|
|
|
|
|
|
fontWeight: config.fontWeight,
|
2026-05-20 01:30:41 +08:00
|
|
|
|
fontStyle: config.fontStyle,
|
2026-05-19 21:09:56 +08:00
|
|
|
|
lineHeight: config.lineHeight,
|
2026-05-20 01:30:41 +08:00
|
|
|
|
color: `var(${config.color})`,
|
2026-05-19 21:09:56 +08:00
|
|
|
|
margin: config.margin,
|
2026-05-20 01:30:41 +08:00
|
|
|
|
...style,
|
2026-05-19 21:09:56 +08:00
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{children}
|
2026-05-20 01:30:41 +08:00
|
|
|
|
{credit && (
|
|
|
|
|
|
<span
|
|
|
|
|
|
className="nui-small-caps"
|
|
|
|
|
|
style={{
|
|
|
|
|
|
display: 'inline-block',
|
|
|
|
|
|
marginLeft: 'var(--nui-space-2)',
|
|
|
|
|
|
fontSize: '11px',
|
|
|
|
|
|
color: 'var(--nui-text-muted)',
|
|
|
|
|
|
fontStyle: 'normal',
|
|
|
|
|
|
letterSpacing: '0.06em',
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{credit}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
2026-05-19 21:09:56 +08:00
|
|
|
|
</figcaption>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|