Skip to content

Commit 80b16ce

Browse files
authored
Chip supports prefix as props (#1406)
* first commit * add prefix to Chip prop * prop pefix added to Chip * update prefix to add space * added test
1 parent 46baf71 commit 80b16ce

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- update Chip to receive prop prefix
1213
- `useClickable` hook
1314
- `InputColor` now includes `name` in `onChange` response event
1415
- `InputChips` and `SelectMulti` chip selection and copy-pasting

packages/components/src/Chip/Chip.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ test('Chip renders disabled', () => {
3636
assertSnapshot(<Chip disabled>chip</Chip>)
3737
})
3838

39+
test('Chip accepts a prefix and renders it with correct style', () => {
40+
const { getByText } = renderWithTheme(<Chip prefix="role">admin</Chip>)
41+
expect(getByText(/\brole\b/)).toHaveStyle('font-weight: 400')
42+
})
43+
3944
test('Chip onDelete renders correctly', () => {
4045
const onDeleteTrigger = jest.fn()
4146

packages/components/src/Chip/Chip.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface ChipProps
4747
extends GenericClickProps<HTMLSpanElement>,
4848
TruncateProps {
4949
children: ReactNode
50+
prefix?: string
5051
onDelete?: (
5152
e?: MouseEvent<HTMLSpanElement> | KeyboardEvent<HTMLSpanElement>
5253
) => void
@@ -111,6 +112,7 @@ const ChipJSX = forwardRef(
111112
onDelete,
112113
onKeyUp,
113114
onKeyDown,
115+
prefix,
114116
truncate = true,
115117
...props
116118
}: ChipProps,
@@ -138,7 +140,10 @@ const ChipJSX = forwardRef(
138140
ref={ref}
139141
{...props}
140142
>
141-
<ChipLabel truncate={truncate}>{children}</ChipLabel>
143+
<ChipLabel truncate={truncate}>
144+
{prefix && <ChipLabel fontWeight="normal">{prefix}: </ChipLabel>}
145+
{children}
146+
</ChipLabel>
142147
{onDelete && !disabled && (
143148
<IconButton
144149
disabled={disabled}

storybook/src/Chip.stories.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const All = () => (
3838
<ClickAndDelete />
3939
<ChipButtons />
4040
<Removable />
41+
<ChipPrefix />
4142
</SpaceVertical>
4243
)
4344

@@ -68,6 +69,19 @@ export const ClickAndDelete = () => {
6869
)
6970
}
7071

72+
export const ChipPrefix = () => {
73+
return (
74+
<>
75+
<Heading>Prefix</Heading>
76+
<Space>
77+
<Chip>no prefix</Chip>
78+
<Chip prefix="role">admin</Chip>
79+
<Chip prefix="color">purple,purple:neat</Chip>
80+
</Space>
81+
</>
82+
)
83+
}
84+
7185
export const ChipButtons = () => {
7286
const handleClick = () => alert('Clicked!')
7387
const handleDelete = () => alert('Deleted!')

0 commit comments

Comments
 (0)