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 truncated props in Badge #2603

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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/funny-eyes-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@channel.io/bezier-react': patch
---

Add truncated props in the Badge
21 changes: 21 additions & 0 deletions packages/bezier-react/src/components/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { AppleIcon } from '@channel.io/bezier-icons'
import { type Meta, type StoryFn, type StoryObj } from '@storybook/react'

import { Box } from '~/src/components/Box'

import { Badge } from './Badge'
import { type BadgeProps } from './Badge.types'

Expand All @@ -14,6 +16,12 @@ const Template: StoryFn<BadgeProps> = ({ children, ...badgeProps }) => (
<Badge {...badgeProps}>{children}</Badge>
)

const Truncated: StoryFn<BadgeProps> = ({ children, ...badgeProps }) => (
<Box width={200}>
<Badge {...badgeProps}>{children}</Badge>
</Box>
)

export const Primary: StoryObj<BadgeProps> = {
render: Template,

Expand All @@ -24,3 +32,16 @@ export const Primary: StoryObj<BadgeProps> = {
variant: 'default',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Primary에서도 배포버전에서 truncated: set object 의 control이 생깁니다. 없앨 예정입니다.

},
}

export const Secondary: StoryObj<BadgeProps> = {
render: Truncated,

args: {
children: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
size: 'm',
icon: AppleIcon,
variant: 'default',
truncated: true,
},
name: 'Truncated',
}
3 changes: 2 additions & 1 deletion packages/bezier-react/src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const BADGE_TEST_ID = 'bezier-badge'
*/
export const Badge = memo(
forwardRef<HTMLDivElement, BadgeProps>(function Badge(
{ size = 'm', variant = 'default', icon, children, ...rest },
{ size = 'm', variant = 'default', truncated ,icon, children, ...rest },
forwardedRef
) {
return (
Expand All @@ -48,6 +48,7 @@ export const Badge = memo(
<BaseTagBadgeText
size={size}
marginHorizontal={3}
truncated={truncated}
>
{children}
</BaseTagBadgeText>
Expand Down
6 changes: 6 additions & 0 deletions packages/bezier-react/src/components/Badge/Badge.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ interface BadgeOwnProps {
* Icon to be shown on the left side of the badge.
*/
icon?: BezierIcon
/**
* Whether the text is truncated.
* If it is a positive integer, it means the maximum number of lines.
* @default false
*/
truncated?: boolean | number
}

export interface BadgeProps
Expand Down
Loading