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

Add labelWrap prop to Button #4527

Merged
merged 9 commits into from
Jun 14, 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
5 changes: 5 additions & 0 deletions .changeset/ninety-mice-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Add `truncation` prop to `Button` to allow for ellipses overflow or text wrapping for long button labels
6 changes: 6 additions & 0 deletions packages/react/src/Button/Button.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
"type": "'default'\n| 'primary'\n| 'danger'\n| 'invisible'",
"defaultValue": "'default'",
"description": "Change the visual style of the button."
},
{
"name": "labelWrap",
"type": "boolean",
"defaultValue": "false",
"description": "Whether the button label should wrap to multiple lines of it is longer than the button width."
}
],
"passthrough": {
Expand Down
23 changes: 22 additions & 1 deletion packages/react/src/Button/Button.features.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {EyeIcon, TriangleDownIcon, HeartIcon} from '@primer/octicons-react'
import React, {useState} from 'react'
import {Button} from '.'
import {announce} from '@primer/live-region-element'
import {Stack} from '../Stack/Stack'
import Link from '../Link'
import {announce} from '@primer/live-region-element'

export default {
title: 'Components/Button/Features',
Expand Down Expand Up @@ -135,3 +136,23 @@ export const Small = () => <Button size="small">Default</Button>
export const Medium = () => <Button size="medium">Default</Button>

export const Large = () => <Button size="large">Default</Button>

export const LabelWrap = () => {
return (
<Stack style={{width: '200px'}}>
<Button labelWrap>This button label will wrap if the label is too long</Button>
<Button size="small" labelWrap>
This small button label will wrap if the label is too long
</Button>
<Button size="large" labelWrap>
This large button label will wrap if the label is too long
</Button>
<Button labelWrap leadingVisual={HeartIcon} trailingVisual={EyeIcon}>
This button label will wrap if the label is too long
</Button>
<Button labelWrap trailingAction={TriangleDownIcon}>
This button label will wrap if the label is too long
</Button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe include one that isn't wrapping to show along with the wrapping ones?

</Stack>
)
}
6 changes: 6 additions & 0 deletions packages/react/src/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ Playground.argTypes = {
type: 'boolean',
},
},
labelWrap: {
control: {
type: 'boolean',
},
},
leadingVisual: OcticonArgType([EyeClosedIcon, EyeIcon, SearchIcon, XIcon, HeartIcon]),
trailingVisual: OcticonArgType([EyeClosedIcon, EyeIcon, SearchIcon, XIcon, HeartIcon]),
trailingAction: OcticonArgType([TriangleDownIcon]),
Expand All @@ -62,6 +67,7 @@ Playground.args = {
trailingVisual: null,
leadingVisual: null,
trailingAction: null,
labelWrap: false,
}

export const Default = () => <Button>Default</Button>
2 changes: 2 additions & 0 deletions packages/react/src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ButtonBase = forwardRef(
alignContent = 'center',
block = false,
inactive,
labelWrap,
...rest
} = props

Expand Down Expand Up @@ -73,6 +74,7 @@ const ButtonBase = forwardRef(
data-size={size === 'small' || size === 'large' ? size : undefined}
data-no-visuals={!LeadingVisual && !TrailingVisual && !TrailingAction ? true : undefined}
data-inactive={inactive ? true : undefined}
data-label-wrap={labelWrap}
>
{Icon ? (
<Icon />
Expand Down
Loading
Loading