@@ -36,9 +36,6 @@ interface MultiSelectCellProps {
3636 readonly allowDuplicates ?: boolean ;
3737}
3838
39- const BUBBLE_HEIGHT = 20 ;
40- const BUBBLE_PADDING = 6 ;
41- const BUBBLE_MARGIN = 4 ;
4239/* This prefix is used when allowDuplicates is enabled to make sure that
4340all underlying values are unique. */
4441const VALUE_PREFIX = "__value" ;
@@ -229,14 +226,14 @@ const Editor: ReturnType<ProvideEditorCallback<MultiSelectCell>> = p => {
229226 return {
230227 ...styles ,
231228 backgroundColor : data . color ?? theme . bgBubble ,
232- borderRadius : `${ theme . roundingRadius ?? BUBBLE_HEIGHT / 2 } px` ,
229+ borderRadius : `${ theme . roundingRadius ?? theme . bubbleHeight / 2 } px` ,
233230 } ;
234231 } ,
235232 multiValueLabel : ( styles , { data, isDisabled } ) => {
236233 return {
237234 ...styles ,
238- paddingRight : isDisabled ? BUBBLE_PADDING : 0 ,
239- paddingLeft : BUBBLE_PADDING ,
235+ paddingRight : isDisabled ? theme . bubblePadding : 0 ,
236+ paddingLeft : theme . bubblePadding ,
240237 paddingTop : 0 ,
241238 paddingBottom : 0 ,
242239 color : data . color
@@ -251,7 +248,7 @@ const Editor: ReturnType<ProvideEditorCallback<MultiSelectCell>> = p => {
251248 justifyContent : "center" ,
252249 alignItems : "center" ,
253250 display : "flex" ,
254- height : BUBBLE_HEIGHT ,
251+ height : theme . bubbleHeight ,
255252 } ;
256253 } ,
257254 multiValueRemove : ( styles , { data, isDisabled, isFocused } ) => {
@@ -270,7 +267,7 @@ const Editor: ReturnType<ProvideEditorCallback<MultiSelectCell>> = p => {
270267 : "white"
271268 : theme . textBubble ,
272269 backgroundColor : undefined ,
273- borderRadius : isFocused ? `${ theme . roundingRadius ?? BUBBLE_HEIGHT / 2 } px` : undefined ,
270+ borderRadius : isFocused ? `${ theme . roundingRadius ?? theme . bubbleHeight / 2 } px` : undefined ,
274271 ":hover" : {
275272 cursor : "pointer" ,
276273 } ,
@@ -398,32 +395,32 @@ const renderer: CustomRenderer<MultiSelectCell> = {
398395 width : rect . width - 2 * theme . cellHorizontalPadding ,
399396 height : rect . height - 2 * theme . cellVerticalPadding ,
400397 } ;
401- const rows = Math . max ( 1 , Math . floor ( drawArea . height / ( BUBBLE_HEIGHT + BUBBLE_PADDING ) ) ) ;
398+ const rows = Math . max ( 1 , Math . floor ( drawArea . height / ( theme . bubbleHeight + theme . bubblePadding ) ) ) ;
402399
403400 let { x } = drawArea ;
404401 let row = 1 ;
405402
406403 let y =
407404 rows === 1
408- ? drawArea . y + ( drawArea . height - BUBBLE_HEIGHT ) / 2
409- : drawArea . y + ( drawArea . height - rows * BUBBLE_HEIGHT - ( rows - 1 ) * BUBBLE_PADDING ) / 2 ;
405+ ? drawArea . y + ( drawArea . height - theme . bubbleHeight ) / 2
406+ : drawArea . y + ( drawArea . height - rows * theme . bubbleHeight - ( rows - 1 ) * theme . bubblePadding ) / 2 ;
410407 for ( const value of values ) {
411408 const matchedOption = options . find ( t => t . value === value ) ;
412409 const color = matchedOption ?. color ?? ( highlighted ? theme . bgBubbleSelected : theme . bgBubble ) ;
413410 const displayText = matchedOption ?. label ?? value ;
414411 const metrics = measureTextCached ( displayText , ctx ) ;
415- const width = metrics . width + BUBBLE_PADDING * 2 ;
416- const textY = BUBBLE_HEIGHT / 2 ;
412+ const width = metrics . width + theme . bubblePadding * 2 ;
413+ const textY = theme . bubbleHeight / 2 ;
417414
418415 if ( x !== drawArea . x && x + width > drawArea . x + drawArea . width && row < rows ) {
419416 row ++ ;
420- y += BUBBLE_HEIGHT + BUBBLE_PADDING ;
417+ y += theme . bubbleHeight + theme . bubblePadding ;
421418 x = drawArea . x ;
422419 }
423420
424421 ctx . fillStyle = color ;
425422 ctx . beginPath ( ) ;
426- roundedRect ( ctx , x , y , width , BUBBLE_HEIGHT , theme . roundingRadius ?? BUBBLE_HEIGHT / 2 ) ;
423+ roundedRect ( ctx , x , y , width , theme . bubbleHeight , theme . roundingRadius ?? theme . bubbleHeight / 2 ) ;
427424 ctx . fill ( ) ;
428425
429426 // If a color is set for this option, we use either black or white as the text color depending on the background.
@@ -433,33 +430,38 @@ const renderer: CustomRenderer<MultiSelectCell> = {
433430 ? "#000000"
434431 : "#ffffff"
435432 : theme . textBubble ;
436- ctx . fillText ( displayText , x + BUBBLE_PADDING , y + textY + getMiddleCenterBias ( ctx , theme ) ) ;
433+ ctx . fillText ( displayText , x + theme . bubblePadding , y + textY + getMiddleCenterBias ( ctx , theme ) ) ;
437434
438- x += width + BUBBLE_MARGIN ;
435+ x += width + theme . bubbleMargin ;
439436 if ( x > drawArea . x + drawArea . width + theme . cellHorizontalPadding && row >= rows ) {
440437 break ;
441438 }
442439 }
443440
444441 return true ;
445442 } ,
446- measure : ( ctx , cell , t ) => {
443+ measure : ( ctx , cell , theme ) => {
447444 const { values, options } = cell . data ;
448445
449446 if ( ! values ) {
450- return t . cellHorizontalPadding * 2 ;
447+ return theme . cellHorizontalPadding * 2 ;
451448 }
452449
453450 // Resolve the values to the actual display labels:
454451 const labels = resolveValues ( values , prepareOptions ( options ?? [ ] ) , cell . data . allowDuplicates ) . map (
455452 x => x . label ?? x . value
456453 ) ;
457454
458- return (
459- labels . reduce ( ( acc , data ) => ctx . measureText ( data ) . width + acc + BUBBLE_PADDING * 2 + BUBBLE_MARGIN , 0 ) +
460- 2 * t . cellHorizontalPadding -
461- 4
455+ const bubblesWidth = labels . reduce (
456+ ( acc , data ) => ctx . measureText ( data ) . width + acc + theme . bubblePadding * 2 + theme . bubbleMargin ,
457+ 0
462458 ) ;
459+
460+ if ( labels . length === 0 ) {
461+ return theme . cellHorizontalPadding * 2 ;
462+ }
463+
464+ return bubblesWidth + 2 * theme . cellHorizontalPadding - theme . bubbleMargin ;
463465 } ,
464466 provideEditor : ( ) => ( {
465467 editor : Editor ,
0 commit comments