Skip to content

Commit 58b0888

Browse files
committed
Use ListBox for ComponentCardView
1 parent 894d847 commit 58b0888

File tree

3 files changed

+62
-29
lines changed

3 files changed

+62
-29
lines changed
Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
/* eslint-disable rulesdir/imports */
2-
/* eslint-disable monorepo/no-internal-import */
31
'use client';
42

5-
import {CardView, Collection} from '@react-spectrum/s2';
63
import {ComponentCard} from './ComponentCard';
7-
import {Key} from 'react-aria-components';
4+
import {InternalCardViewContext} from '../../../@react-spectrum/s2/src/Card';
5+
import {Key, ListBox, ListBoxItem} from 'react-aria-components';
86
import React from 'react';
7+
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
98

109
export interface ComponentCardItem {
1110
id: string,
@@ -19,16 +18,49 @@ interface ComponentCardGridProps {
1918
ariaLabel?: string,
2019
size?: 'S' | 'M' | 'L',
2120
onAction?: (key: Key) => void,
22-
styles?: any,
2321
renderEmptyState?: () => React.ReactNode
2422
}
2523

26-
export function ComponentCardView({items, ariaLabel = 'Items', size = 'S', onAction, styles, renderEmptyState}: ComponentCardGridProps) {
24+
export function ComponentCardView({items, ariaLabel = 'Items', size = 'S', onAction, renderEmptyState}: ComponentCardGridProps) {
2725
return (
28-
<CardView aria-label={ariaLabel} onAction={onAction} styles={styles} renderEmptyState={renderEmptyState}>
29-
<Collection items={items}>
26+
<InternalCardViewContext.Provider value={{ElementType: ListBoxItem, layout: 'grid'}}>
27+
<ListBox
28+
aria-label={ariaLabel}
29+
layout="grid"
30+
onAction={onAction}
31+
className={style({
32+
display: {
33+
default: 'grid',
34+
isEmpty: 'flex'
35+
},
36+
gridTemplateColumns: {
37+
default: 'repeat(auto-fill, minmax(150px, 1fr))',
38+
md: 'repeat(auto-fill, minmax(200px, 1fr))'
39+
},
40+
gridAutoRows: 'max-content',
41+
gap: 16,
42+
padding: {
43+
default: 12,
44+
md: 16
45+
},
46+
marginX: {
47+
default: -12,
48+
md: 0
49+
},
50+
alignItems: {
51+
isEmpty: 'center'
52+
},
53+
justifyContent: {
54+
default: 'space-between',
55+
isEmpty: 'center'
56+
},
57+
overflow: 'auto',
58+
flexGrow: 1
59+
})}
60+
renderEmptyState={renderEmptyState}
61+
items={items}>
3062
{(item) => <ComponentCard id={item.id} name={item.name.trim()} href={item.href} description={item.description} size={size} />}
31-
</Collection>
32-
</CardView>
63+
</ListBox>
64+
</InternalCardViewContext.Provider>
3365
);
3466
}

packages/dev/s2-docs/src/SearchMenu.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -272,22 +272,23 @@ export function SearchMenu(props: SearchMenuProps) {
272272
{orderedTabs.map((tab, i) => (
273273
<TabPanel key={tab.id} id={tab.id}>
274274
<Autocomplete>
275-
<div className={style({margin: 'auto', width: '[fit-content]', paddingBottom: 4})}>
276-
<SearchField
277-
value={searchValue}
278-
onChange={setSearchValue}
279-
ref={searchRef}
280-
size="L"
281-
aria-label={`Search ${tab.label}`}
282-
UNSAFE_style={{marginInlineEnd: 296, viewTransitionName: i === 0 ? 'search-menu-search-field' : 'none'} as CSSProperties}
283-
styles={style({width: '[500px]'})} />
284-
</div>
275+
<div className={style({display: 'flex', flexDirection: 'column', height: 'full'})}>
276+
<div className={style({flexShrink: 0, marginStart: 16, marginEnd: 64})}>
277+
<SearchField
278+
value={searchValue}
279+
onChange={setSearchValue}
280+
ref={searchRef}
281+
size="L"
282+
aria-label={`Search ${tab.label}`}
283+
placeholder={`Search ${tab.label}`}
284+
UNSAFE_style={{marginInlineEnd: 296, viewTransitionName: i === 0 ? 'search-menu-search-field' : 'none'} as CSSProperties}
285+
styles={style({width: 500})} />
286+
</div>
285287

286-
<CloseButton onClose={onClose} />
288+
<CloseButton onClose={onClose} />
287289

288-
<div className={style({height: 'full', overflow: 'auto', paddingX: 16, paddingBottom: 16})}>
289290
{sections.length > 0 && (
290-
<div className={style({position: 'sticky', top: 0, zIndex: 1, backgroundColor: 'layer-2', paddingY: 8})}>
291+
<div className={style({flexShrink: 0, zIndex: 1, backgroundColor: 'layer-2', paddingTop: 16})}>
291292
<SelectableCollectionContext.Provider value={null}>
292293
<TagGroup
293294
selectionMode="single"
@@ -296,7 +297,7 @@ export function SearchMenu(props: SearchMenuProps) {
296297
onSelectionChange={handleSectionSelectionChange}
297298
aria-label="Select section"
298299
items={tags}
299-
styles={style({marginX: 12})}>
300+
styles={style({marginX: 16})}>
300301
{(tag) => (
301302
<Tag key={tag.id} id={tag.id}>
302303
{tag.name}
@@ -307,10 +308,7 @@ export function SearchMenu(props: SearchMenuProps) {
307308
</div>
308309
)}
309310
<ComponentCardView
310-
onAction={() => {
311-
setSearchValue('');
312-
onClose();
313-
}}
311+
onAction={onClose}
314312
items={selectedItems.map(item => ({
315313
id: item.id,
316314
name: item.name,

packages/dev/s2-docs/src/SearchMenuTrigger.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import {Button, ButtonProps, Modal, ModalOverlay} from 'react-aria-components';
44
import {fontRelative, style} from '@react-spectrum/s2/style' with { type: 'macro' };
5+
import {getLibraryFromPage, getLibraryLabel} from './library';
56
import {Page} from '@parcel/rsc';
67
import React, {CSSProperties, lazy, useCallback, useEffect, useState} from 'react';
78
import Search from '@react-spectrum/s2/icons/Search';
@@ -138,7 +139,8 @@ export default function SearchMenuTrigger({onOpen, onClose, isSearchOpen, overla
138139
className={({isHovered, isFocusVisible}) => style({
139140
height: 40,
140141
boxSizing: 'border-box',
141-
paddingX: 'edge-to-text',
142+
paddingStart: 'pill',
143+
paddingEnd: 8,
142144
fontSize: 'ui-lg',
143145
borderRadius: 'full',
144146
borderWidth: 2,
@@ -177,6 +179,7 @@ export default function SearchMenuTrigger({onOpen, onClose, isSearchOpen, overla
177179
'--iconPrimary': {type: 'fill', value: 'currentColor'},
178180
flexShrink: 0
179181
}))} />
182+
<span className={style({font: 'ui-lg', color: 'gray-600'})}>Search {getLibraryLabel(getLibraryFromPage(props.currentPage))}</span>
180183
<kbd
181184
className={style({
182185
marginStart: 'auto',

0 commit comments

Comments
 (0)