Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/feat-text-no-wrap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clickhouse/click-ui': patch
---

Add noWrap prop to Text to control white-space wrapping
8 changes: 8 additions & 0 deletions src/components/Text/Text.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
width: 100%;
}

.text_no-wrap {
white-space: nowrap;
}

.text_wrap {
white-space: normal;
}

/* font shorthand depends on both size and weight; one class per pairing
mirrors the single `font:` declaration emitted by styled-components. */

Expand Down
11 changes: 11 additions & 0 deletions src/components/Text/Text.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,14 @@ export const FillWidth: Story = {
</TextHarness>
),
};

export const NoWrap: Story = {
render: () => (
<div
data-testid="text-harness"
style={{ display: 'inline-block', padding: '8px', width: '120px' }}
>
<Text noWrap>{sample}</Text>
</div>
),
};
12 changes: 11 additions & 1 deletion src/components/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export interface TextProps<T extends ElementType = 'p'> {
component?: T;
/** Whether the text should fill the full width of its container */
fillWidth?: boolean;
/** Whether the text should stay on a single line */
noWrap?: boolean;
}

type TextPolymorphicComponent = <T extends ElementType = 'p'>(
Expand All @@ -53,6 +55,10 @@ const textVariants = cva(styles.text, {
fillWidth: {
true: styles['text_fill-width'],
},
noWrap: {
true: styles['text_no-wrap'],
false: styles['text_wrap'],
},
size: {
xs: '',
sm: '',
Expand Down Expand Up @@ -107,6 +113,7 @@ const _Text = <T extends ElementType = 'p'>(
children,
component,
fillWidth,
noWrap,
...props
}: Omit<ComponentProps<T>, keyof TextProps<T>> & TextProps<T>,
ref: ComponentPropsWithRef<T>['ref']
Expand All @@ -116,7 +123,10 @@ const _Text = <T extends ElementType = 'p'>(
<Component
ref={ref}
{...props}
className={cn(textVariants({ color, align, size, weight, fillWidth }), className)}
className={cn(
textVariants({ color, align, size, weight, fillWidth, noWrap }),
className
)}
>
{children}
</Component>
Expand Down
1 change: 1 addition & 0 deletions tests/display/text.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const variants = [
{ story: 'align-center', name: 'align-center' },
{ story: 'align-right', name: 'align-right' },
{ story: 'fill-width', name: 'fill-width' },
{ story: 'no-wrap', name: 'no-wrap' },
] as const;

describe('Text Visual Regression', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading