Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/core] chore: add sizes to Title #6833

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/@docs/demos/src/demos/core/Title/Title.demo.size.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function Demo() {
</Title>
<Title size="h4">H1 heading with h4 font-size</Title>
<Title size="1rem">H1 heading with 1rem size</Title>
<Title size="xs">H1 heading with xs size</Title>
</>
);
}
Expand All @@ -25,6 +26,7 @@ function Demo() {
</Title>
<Title size="h4">H1 heading with h4 font-size</Title>
<Title size="1rem">H1 heading with 1rem size</Title>
<Title size="xs">H1 heading with xs size</Title>
</>
);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/@mantine/core/src/components/Title/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ElementProps,
factory,
Factory,
MantineSize,
StylesApiProps,
useProps,
useStyles,
Expand All @@ -13,7 +14,7 @@ import { getTitleSize } from './get-title-size';
import classes from './Title.module.css';

export type TitleOrder = 1 | 2 | 3 | 4 | 5 | 6;
export type TitleSize = `h${TitleOrder}` | React.CSSProperties['fontSize'];
export type TitleSize = `h${TitleOrder}` | React.CSSProperties['fontSize'] | MantineSize;

export type TitleStylesNames = 'root';
export type TitleCssVariables = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { rem } from '../../core';
import type { TitleOrder, TitleSize } from './Title';

const headings: unknown[] = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
const sizes: unknown[] = ['xs', 'sm', 'md', 'lg', 'xl'];

export interface GetTitleSizeResult {
fontSize: string;
fontWeight: string;
lineHeight: string;
}

export function getTitleSize(order: TitleOrder, size: TitleSize | undefined): GetTitleSizeResult {
export function getTitleSize(order: TitleOrder, size?: TitleSize): GetTitleSizeResult {
const titleSize = size !== undefined ? size : `h${order}`;

if (headings.includes(titleSize)) {
Expand All @@ -18,6 +19,12 @@ export function getTitleSize(order: TitleOrder, size: TitleSize | undefined): Ge
fontWeight: `var(--mantine-${titleSize}-font-weight)`,
lineHeight: `var(--mantine-${titleSize}-line-height)`,
};
} else if (sizes.includes(titleSize)) {
return {
fontSize: `var(--mantine-font-size-${titleSize})`,
fontWeight: `var(--mantine-h${order}-font-weight)`,
lineHeight: `var(--mantine-h${order}-line-height)`,
};
}

return {
Expand Down
Loading