Files
newsui/packages/components/src/Text/Subhead.tsx
T

43 lines
1.2 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 SubheadProps {
weight?: 'High' | 'Medium';
span?: number;
2026-05-20 01:30:41 +08:00
as?: 'h2' | 'h3' | 'h4' | 'p';
className?: string;
style?: CSSProperties;
children: ReactNode;
2026-05-19 21:09:56 +08:00
}
export const Subhead: React.FC<SubheadProps> = ({
2026-05-20 01:30:41 +08:00
weight = 'Medium', span, as = 'p', 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.Subhead[weight]!;
const Tag = as as keyof JSX.IntrinsicElements;
const cols = span ? clampSpan(span, section.columns) : undefined;
2026-05-19 21:09:56 +08:00
return (
2026-05-20 01:30:41 +08:00
<Tag
className={cx('nui-subhead 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
gridColumn: cols ? `span ${cols}` : undefined,
...style,
2026-05-19 21:09:56 +08:00
}}
data-weight={weight}
>
{children}
2026-05-20 01:30:41 +08:00
</Tag>
2026-05-19 21:09:56 +08:00
);
};