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 { clampSpan, cx } from '@newspaperui/utils';
|
|
|
|
|
|
import { useSection } from '../layout/Section';
|
2026-05-19 21:09:56 +08:00
|
|
|
|
|
|
|
|
|
|
export interface QuoteProps {
|
2026-05-20 01:30:41 +08:00
|
|
|
|
variant?: 'block' | 'inline';
|
2026-05-19 21:09:56 +08:00
|
|
|
|
weight?: 'High' | 'Medium';
|
|
|
|
|
|
span?: number;
|
2026-05-20 01:30:41 +08:00
|
|
|
|
cite?: string;
|
|
|
|
|
|
className?: string;
|
|
|
|
|
|
style?: CSSProperties;
|
|
|
|
|
|
children: ReactNode;
|
2026-05-19 21:09:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-20 14:22:14 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* Quote — 引用(block 左缩进 / inline italic)
|
|
|
|
|
|
*
|
|
|
|
|
|
* - block 模式:渲染为 blockquote,支持 cite 属性和 span 跨栏
|
|
|
|
|
|
* - inline 模式:渲染为 em 标签,适合行内引用
|
|
|
|
|
|
* - 字号和样式由 visualWeights 数据驱动
|
|
|
|
|
|
*
|
|
|
|
|
|
* @example
|
|
|
|
|
|
* <Quote variant="block" weight="High" cite="https://source.com">
|
|
|
|
|
|
* "The truth is rarely pure and never simple."
|
|
|
|
|
|
* </Quote>
|
|
|
|
|
|
*/
|
2026-05-19 21:09:56 +08:00
|
|
|
|
export const Quote: React.FC<QuoteProps> = ({
|
2026-05-20 01:30:41 +08:00
|
|
|
|
variant = 'block', weight = 'Medium', span, cite, className, style, children,
|
2026-05-19 21:09:56 +08:00
|
|
|
|
}) => {
|
|
|
|
|
|
const section = useSection();
|
2026-05-20 01:30:41 +08:00
|
|
|
|
const config = visualWeights.Quote[weight]!;
|
|
|
|
|
|
const cols = span ? clampSpan(span, section.columns) : undefined;
|
2026-05-19 21:09:56 +08:00
|
|
|
|
|
2026-05-20 01:30:41 +08:00
|
|
|
|
if (variant === 'inline') {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<em className={cx('nui-quote nui-quote--inline', className)} style={style}>
|
|
|
|
|
|
{children}
|
|
|
|
|
|
</em>
|
|
|
|
|
|
);
|
2026-05-19 21:09:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<blockquote
|
2026-05-20 01:30:41 +08:00
|
|
|
|
cite={cite}
|
|
|
|
|
|
className={cx('nui-quote nui-quote--block 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,
|
|
|
|
|
|
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
|
|
|
|
gridColumn: cols ? `span ${cols}` : undefined,
|
|
|
|
|
|
borderLeft: 'none',
|
|
|
|
|
|
...style,
|
2026-05-19 21:09:56 +08:00
|
|
|
|
}}
|
|
|
|
|
|
data-weight={weight}
|
|
|
|
|
|
>
|
|
|
|
|
|
{children}
|
|
|
|
|
|
</blockquote>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|