Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 12 additions & 43 deletions packages/dev/s2-docs/src/ComponentCardView.tsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,35 @@
/* eslint-disable rulesdir/imports */
/* eslint-disable monorepo/no-internal-import */
'use client';

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

export interface ComponentCardItem {
id: string,
name: string,
href: string,
description?: string
description?: string,
date?: string
}

interface ComponentCardGridProps {
items: ComponentCardItem[],
ariaLabel?: string,
size?: 'S' | 'M' | 'L',
onAction?: (key: Key) => void,
styles?: any,
renderEmptyState?: () => React.ReactNode
}

export function ComponentCardView({items, ariaLabel = 'Items', size = 'S', onAction, renderEmptyState}: ComponentCardGridProps) {
export function ComponentCardView({items, ariaLabel = 'Items', size = 'S', onAction, styles, renderEmptyState}: ComponentCardGridProps) {
return (
<InternalCardViewContext.Provider value={{ElementType: ListBoxItem, layout: 'grid'}}>
<ListBox
Comment on lines 26 to 27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to keep this as a ListBox for the virtual focus to work right? What was broken here that made this change necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gah, how have so many merges gone wrong in this pr.... i didn't notice this locally it should only have the date in the type

aria-label={ariaLabel}
layout="grid"
onAction={onAction}
className={style({
display: {
default: 'grid',
isEmpty: 'flex'
},
gridTemplateColumns: {
default: 'repeat(auto-fill, minmax(150px, 1fr))',
md: 'repeat(auto-fill, minmax(200px, 1fr))'
},
gridAutoRows: 'max-content',
gap: 16,
padding: {
default: 12,
md: 16
},
marginX: {
default: -12,
md: 0
},
alignItems: {
isEmpty: 'center'
},
justifyContent: {
default: 'space-between',
isEmpty: 'center'
},
overflow: 'auto',
flexGrow: 1
})}
renderEmptyState={renderEmptyState}
items={items}>
<CardView aria-label={ariaLabel} onAction={onAction} styles={styles} renderEmptyState={renderEmptyState}>
<Collection items={items}>
{(item) => <ComponentCard id={item.id} name={item.name.trim()} href={item.href} description={item.description} size={size} />}
</ListBox>
</InternalCardViewContext.Provider>
</Collection>
</CardView>
);
}
38 changes: 35 additions & 3 deletions packages/dev/s2-docs/src/MobileSearchMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ function MobileNav({pages, currentPage}: PageProps) {
return matchedPages.sort((a, b) => {
let aNameMatch = title(a).toLowerCase().startsWith(searchLower);
let bNameMatch = title(b).toLowerCase().startsWith(searchLower);
if (a.date && b.date) {
let aDate = new Date(a.date);
let bDate = new Date(b.date);
return bDate.getTime() - aDate.getTime();
} else if (a.date && !b.date) {
return 1;
} else if (!a.date && b.date) {
return -1;
}

if (aNameMatch && !bNameMatch) {
return -1;
Expand All @@ -325,16 +334,29 @@ function MobileNav({pages, currentPage}: PageProps) {
let filteredPages = filterPages(pages, searchValue);

return filteredPages
.sort((a, b) => title(a).localeCompare(title(b)))
.map(page => ({id: page.url.replace(/^\//, ''), name: title(page), href: page.url, description: page.exports?.description}));
.sort((a, b) => {
return title(a).localeCompare(title(b));
})
.map(page => ({id: page.url.replace(/^\//, ''), name: title(page), href: page.url, description: page.exports?.description, date: page.exports?.date}));
};

let getAllContent = (libraryId: string, searchValue: string = ''): ComponentCardItem[] => {
let librarySections = getSectionsForLibrary(libraryId);
let allPages = Array.from(librarySections.values()).flat();
let filteredPages = filterPages(allPages, searchValue);
return filteredPages
.sort((a, b) => title(a).localeCompare(title(b)))
.sort((a, b) => {
if (a.date && b.date) {
let aDate = new Date(a.date);
let bDate = new Date(b.date);
return bDate.getTime() - aDate.getTime();
} else if (a.date && !b.date) {
return 1;
} else if (!a.date && b.date) {
return -1;
}
return title(a).localeCompare(title(b));
})
.map(page => ({id: page.url.replace(/^\//, ''), name: title(page), href: page.url, description: page.exports?.description}));
};

Expand All @@ -355,6 +377,16 @@ function MobileNav({pages, currentPage}: PageProps) {
const aIsIntro = a.name === 'Introduction';
const bIsIntro = b.name === 'Introduction';

if (a.date && b.date) {
let aDate = new Date(a.date);
let bDate = new Date(b.date);
return bDate.getTime() - aDate.getTime();
} else if (a.date && !b.date) {
return 1;
} else if (!a.date && b.date) {
return -1;
}

if (aIsIntro && !bIsIntro) {
return -1;
}
Expand Down