Files
newsui/packages/components/src/Media/PullQuote.tsx
T

72 lines
2.0 KiB
TypeScript
Raw Normal View History

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 PullQuoteProps {
weight?: 'High' | 'Medium';
span?: number;
2026-05-20 01:30:41 +08:00
spanAllColumns?: boolean; // 在多栏 BodyText 内跨所有栏
2026-05-19 21:09:56 +08:00
author?: string;
2026-05-20 01:30:41 +08:00
align?: 'left' | 'center';
className?: string;
style?: CSSProperties;
children: ReactNode;
2026-05-19 21:09:56 +08:00
}
export const PullQuote: React.FC<PullQuoteProps> = ({
2026-05-20 01:30:41 +08:00
weight = 'High', span, spanAllColumns = false, author, align = 'left',
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.PullQuote[weight]!;
const cols = span ? clampSpan(span, section.columns) : undefined;
2026-05-19 21:09:56 +08:00
return (
<aside
2026-05-20 01:30:41 +08:00
className={cx(
'nui-pullquote nui-avoid-break nui-tnum',
spanAllColumns && 'nui-span-all-columns',
className,
)}
2026-05-19 21:09:56 +08:00
style={{
margin: config.margin,
2026-05-20 01:30:41 +08:00
padding: 'var(--nui-space-4) 0',
borderTop: '1px solid var(--nui-rule-hairline)',
borderBottom: '1px solid var(--nui-rule-hairline)',
textAlign: align,
gridColumn: cols ? `span ${cols}` : undefined,
...style,
2026-05-19 21:09:56 +08:00
}}
>
2026-05-20 01:30:41 +08:00
<p
style={{
fontFamily: `var(${config.fontFamily})`,
fontSize: resolveFontSize(config.fontSize),
fontWeight: config.fontWeight,
lineHeight: config.lineHeight,
letterSpacing: config.letterSpacing,
color: `var(${config.color})`,
margin: 0,
textWrap: 'balance' as CSSProperties['textWrap'],
}}
>
2026-05-19 21:09:56 +08:00
{children}
2026-05-20 01:30:41 +08:00
</p>
2026-05-19 21:09:56 +08:00
{author && (
2026-05-20 01:30:41 +08:00
<footer
className="nui-small-caps"
2026-05-19 21:09:56 +08:00
style={{
2026-05-20 01:30:41 +08:00
marginTop: 'var(--nui-space-2)',
fontSize: '11px',
color: 'var(--nui-text-muted)',
letterSpacing: '0.08em',
2026-05-19 21:09:56 +08:00
}}
>
{author}
2026-05-20 01:30:41 +08:00
</footer>
2026-05-19 21:09:56 +08:00
)}
</aside>
);
};