diff --git a/static/app/components/core/text/text.mdx b/static/app/components/core/text/text.mdx index 758462ca34cc2e..91c6cc27e4d3de 100644 --- a/static/app/components/core/text/text.mdx +++ b/static/app/components/core/text/text.mdx @@ -202,6 +202,40 @@ Handle text overflow with the `ellipsis` prop to truncate long text with an elli ``` +## Wrapping + +Use the `textWrap` prop to control how the text wraps, and the `wordBreak` prop to control where the text is split during wrapping. + + + + + + A URL string that breaks on word boundaries: + https://example.com/path/?marketingParam1=value1&marketingParam2=some-awkward-long-value + + + + + Balanced text wrapping for a string of words of varying lengths + + + + +```jsx + + + A URL string that breaks on word boundaries: + https://example.com/path/?marketingParam1=value1&marketingParam2=some-awkward-long-value + + + + + + Balanced text wrapping for a string of words of varying lengths + + +``` + ## Monospace Use `monospace` for fixed-width text. diff --git a/static/app/components/core/text/text.tsx b/static/app/components/core/text/text.tsx index 4c3bd8f1425ea0..9174ef5f19dc7f 100644 --- a/static/app/components/core/text/text.tsx +++ b/static/app/components/core/text/text.tsx @@ -84,6 +84,12 @@ export interface BaseTextProps { */ variant?: keyof Theme['tokens']['content']; + /** + * Determines where line breaks appear when wrapping the text. + * @default undefined + */ + wordBreak?: 'normal' | 'break-all' | 'keep-all' | 'break-word'; + /** * Determines text wrapping. */ @@ -132,6 +138,7 @@ export const Text = styled( text-overflow: ${p => (p.ellipsis ? 'ellipsis' : undefined)}; white-space: ${p => (p.wrap ? p.wrap : p.ellipsis ? 'nowrap' : undefined)}; text-wrap: ${p => p.textWrap ?? undefined}; + word-break: ${p => p.wordBreak ?? undefined}; width: ${p => (p.ellipsis ? '100%' : undefined)}; display: ${p => p.as === 'div'