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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
};
|