@@ -17,6 +17,7 @@ import StudioButton from 'src/components/button';
17
17
import { cx } from 'src/lib/cx' ;
18
18
import { getIpcApi } from 'src/lib/get-ipc-api' ;
19
19
import { useGetBlueprints } from 'src/stores/wpcom-api' ;
20
+ import { useOverflowItems } from '../hooks/use-overflow-items' ;
20
21
21
22
interface Blueprint {
22
23
slug : string ;
@@ -47,7 +48,48 @@ interface AddSiteBlueprintProps {
47
48
onFileBlueprintSelect ?: ( blueprint : Blueprint ) => void ;
48
49
}
49
50
50
- const MAX_BLUEPRINTS_CATEGORIES = 3 ;
51
+ function CategoryBadges ( { categories } : { categories : string [ ] } ) {
52
+ const { __ } = useI18n ( ) ;
53
+ const containerRef = useRef < HTMLDivElement > ( null ) ;
54
+ const { visible, hidden, hiddenCount, itemRefs } = useOverflowItems ( categories , containerRef ) ;
55
+
56
+ return (
57
+ < HStack ref = { containerRef } spacing = { 3 } alignment = "left" className = "w-full" >
58
+ { categories . map ( ( category , index ) => (
59
+ < Text
60
+ as = "span"
61
+ key = { category }
62
+ ref = { ( el ) => {
63
+ itemRefs . current [ index ] = el ;
64
+ } }
65
+ className = "px-2.5 py-1 text-xs bg-gray-100 text-gray-700 rounded-sm flex items-center flex-shrink-0 max-w-32 truncate"
66
+ style = { {
67
+ visibility : index < visible . length ? 'visible' : 'hidden' ,
68
+ position : index >= visible . length ? 'absolute' : 'static' ,
69
+ } }
70
+ >
71
+ { category }
72
+ </ Text >
73
+ ) ) }
74
+ { hiddenCount > 0 && (
75
+ < Tooltip
76
+ text = { hidden . join ( ', ' ) }
77
+ delay = { 200 }
78
+ placement = "top-end"
79
+ className = "max-w-xs"
80
+ >
81
+ < Text
82
+ as = "span"
83
+ className = "px-2.5 py-1 text-xs bg-gray-100 text-gray-700 rounded-sm flex items-center font-medium whitespace-nowrap flex-shrink-0"
84
+ >
85
+ { /* translators: %d: Number of hidden categories */ }
86
+ { sprintf ( __ ( '+%d more' ) , hiddenCount ) }
87
+ </ Text >
88
+ </ Tooltip >
89
+ ) }
90
+ </ HStack >
91
+ ) ;
92
+ }
51
93
52
94
export function AddSiteBlueprintSelector ( {
53
95
blueprints,
@@ -108,6 +150,7 @@ export function AddSiteBlueprintSelector( {
108
150
alt = { item . title }
109
151
className = { cx (
110
152
'w-full h-32 object-cover object-top cursor-pointer transition-all duration-150 rounded-lg group' ,
153
+ '[@media(min-height:680px)]:h-48' ,
111
154
'hover:shadow-md hover:outline hover:outline-2 hover:outline-blue-500' ,
112
155
'transition-transform duration-150' ,
113
156
'hover:scale-105' ,
@@ -154,37 +197,7 @@ export function AddSiteBlueprintSelector( {
154
197
const categories = ( item . blueprint . meta ?. categories || [ ] ) . filter (
155
198
( category ) => category !== 'Studio'
156
199
) ;
157
- const visibleCategories = categories . slice ( 0 , MAX_BLUEPRINTS_CATEGORIES ) ;
158
- const remainingCount = categories . length - MAX_BLUEPRINTS_CATEGORIES ;
159
-
160
- return (
161
- < HStack spacing = { 3 } wrap alignment = "left" >
162
- { visibleCategories . map ( ( category ) => (
163
- < Text
164
- as = "span"
165
- key = { category }
166
- className = "px-2.5 py-1 text-xs bg-gray-100 text-gray-700 rounded-sm flex items-center"
167
- >
168
- { category }
169
- </ Text >
170
- ) ) }
171
- { remainingCount > 0 && (
172
- < Tooltip
173
- text = { categories . slice ( MAX_BLUEPRINTS_CATEGORIES ) . join ( ', ' ) }
174
- delay = { 200 }
175
- position = "top right"
176
- className = "max-w-xs"
177
- >
178
- < Text
179
- as = "span"
180
- className = "px-2.5 py-1 text-xs bg-gray-100 text-gray-700 rounded-sm flex items-center font-medium"
181
- >
182
- +{ remainingCount } more
183
- </ Text >
184
- </ Tooltip >
185
- ) }
186
- </ HStack >
187
- ) ;
200
+ return < CategoryBadges categories = { categories } /> ;
188
201
} ,
189
202
} ,
190
203
{
@@ -357,7 +370,7 @@ export function AddSiteBlueprintSelector( {
357
370
) }
358
371
</ HStack >
359
372
360
- < div className = "w-full px-3 [&_.dataviews-view-grid]:!grid [&_.dataviews-view-grid]:!grid-cols-3 [&_.dataviews-view-grid]:!gap-4 [&_.dataviews-view-grid]:!items-start [&_.components-badge]:!bg-transparent [&_.components-badge]:!p-0" >
373
+ < div className = "w-full px-3 [&_.dataviews-view-grid]:!grid [&_.dataviews-view-grid]:!grid-cols-3 [&_.dataviews-view-grid]:!gap-4 [&_.dataviews-view-grid]:!items-start [&_.components-badge]:!bg-transparent [&_.components-badge]:!p-0 [&_.components-badge]:!w-full [&_.components-badge_.components-badge__content]:!w-full [&_.components-badge>*]:!w-full " >
361
374
{ isFetchingBlueprints && (
362
375
< Text className = "text-[14px] block text-center py-[100px]" >
363
376
{ __ ( 'Loading blueprints...' ) }
0 commit comments