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

Update getLineClamp in Text.styles.ts to support 1 liner #3151

Merged
merged 4 commits into from
Dec 12, 2022
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: 1 addition & 1 deletion docs/src/docs/theming/mantine-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ and global styles (`withGlobalStyles`). It is recommended to enable these option
- background-color to `theme.colors.dark[7]` in dark color scheme and `theme.white` in light
- color to `theme.colors.dark[0]` in dark color scheme and `theme.black` in light
- font-family and font-smoothing based on theme
- font-size to `theme.fontSize.md`
- font-size to `theme.fontSizes.md`

```tsx
import { MantineProvider } from '@mantine/core';
Expand Down
15 changes: 15 additions & 0 deletions src/mantine-core/src/Text/Text.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface TextStylesParams {
variant: 'text' | 'link' | 'gradient';
size: MantineNumberSize;
lineClamp: number;
truncate: boolean;
inline: boolean;
inherit: boolean;
underline: boolean;
Expand Down Expand Up @@ -74,6 +75,18 @@ function getLineClamp(lineClamp: number): CSSObject {
return null;
}

function getTruncate(truncate: boolean): CSSObject {
if (truncate) {
return {
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};
}

return null;
}

export default createStyles(
(
theme,
Expand All @@ -82,6 +95,7 @@ export default createStyles(
variant,
size,
lineClamp,
truncate,
inline,
inherit,
underline,
Expand All @@ -100,6 +114,7 @@ export default createStyles(
...theme.fn.fontStyles(),
...theme.fn.focusStyles(),
...getLineClamp(lineClamp),
...getTruncate(truncate),
color: getTextColor({ color, theme, variant }),
fontFamily: inherit ? 'inherit' : theme.fontFamily,
fontSize:
Expand Down
5 changes: 5 additions & 0 deletions src/mantine-core/src/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export interface TextProps extends DefaultProps {
/** CSS -webkit-line-clamp property */
lineClamp?: number;

/** CSS truncate overflowing text with an ellipsis */
truncate?: boolean;

/** Sets line-height to 1 for centering */
inline?: boolean;

Expand Down Expand Up @@ -71,6 +74,7 @@ export const _Text = forwardRef<HTMLDivElement, TextProps>((props, ref) => {
align,
variant,
lineClamp,
truncate,
gradient,
inline,
inherit,
Expand All @@ -90,6 +94,7 @@ export const _Text = forwardRef<HTMLDivElement, TextProps>((props, ref) => {
color,
size,
lineClamp,
truncate,
inline,
inherit,
underline,
Expand Down