File tree Expand file tree Collapse file tree 4 files changed +26
-1
lines changed
packages/components/src/Chip Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ( / \b r o l e \b / ) ) . toHaveStyle ( 'font-weight: 400' )
42+ } )
43+
3944test ( 'Chip onDelete renders correctly' , ( ) => {
4045 const onDeleteTrigger = jest . fn ( )
4146
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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+
7185export const ChipButtons = ( ) => {
7286 const handleClick = ( ) => alert ( 'Clicked!' )
7387 const handleDelete = ( ) => alert ( 'Deleted!' )
You can’t perform that action at this time.
0 commit comments