-
Notifications
You must be signed in to change notification settings - Fork 1.4k
docs: add new S2 components to example apps #7244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f9b930c
fix README typos
reidbarber cf6db61
add examples to S2 Parcel example app
reidbarber 74cd642
add to webpack example
reidbarber 73ff9e5
remove branch filters
reidbarber 0936023
fix filenames in webpack example
reidbarber d9e1c9a
add React import for webpack
reidbarber f03c6b7
Revert "remove branch filters"
reidbarber 63ba101
use DisclosureTitle and add action button
reidbarber b111dc2
Revert "Revert "remove branch filters""
reidbarber 0ae6102
Revert "Revert "Revert "remove branch filters"""
reidbarber 39a31e2
Merge remote-tracking branch 'origin/main' into s2-example-apps-new-c…
reidbarber 76a9afa
fix segmented control selection
reidbarber bfa3131
Revert "Revert "Revert "Revert "remove branch filters""""
reidbarber 3bcb6ce
Revert "Revert "Revert "Revert "Revert "remove branch filters"""""
reidbarber d1d37f7
Merge remote-tracking branch 'origin/main' into s2-example-apps-new-c…
reidbarber 280a283
add aria-label to SegmentedControl
reidbarber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
examples/s2-parcel-example/src/components/CardViewExample.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| /* | ||
| * Copyright 2024 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { ActionMenu, Avatar, Card, CardPreview, CardView, Collection, CollectionCardPreview, Content, Image, MenuItem, SkeletonCollection, Text } from '@react-spectrum/s2'; | ||
| import Folder from '@react-spectrum/s2/icons/Folder'; | ||
| import ErrorIcon from '@react-spectrum/s2/illustrations/linear/AlertNotice'; | ||
| import { style } from "@react-spectrum/s2/style" with { type: "macro" }; | ||
| import { useAsyncList } from 'react-stately'; | ||
|
|
||
| const cardViewStyles = style({ | ||
| width: 'full', | ||
| maxWidth: '[800px]', | ||
| height: '[800px]', | ||
| margin: 32 | ||
| }); | ||
|
|
||
| const avatarSize = { | ||
| XS: 16, | ||
| S: 20, | ||
| M: 24, | ||
| L: 28, | ||
| XL: 32 | ||
| }; | ||
|
|
||
| function PhotoCard({item, layout}) { | ||
| return ( | ||
| <Card id={item.id} textValue={item.description || item.alt_description}> | ||
| {({size}) => (<> | ||
| <CardPreview> | ||
| <Image | ||
| src={item.urls.regular} | ||
| styles={style({ | ||
| width: 'full', | ||
| pointerEvents: 'none' | ||
| })} | ||
| // TODO - should we have a safe `dynamicStyles` or something for this? | ||
| UNSAFE_style={{ | ||
| aspectRatio: layout === 'waterfall' ? `${item.width} / ${item.height}` : '4/3', | ||
| objectFit: layout === 'waterfall' ? 'contain' : 'cover' | ||
| }} | ||
| renderError={() => ( | ||
| <div className={style({display: 'flex', alignItems: 'center', justifyContent: 'center', size: 'full'})}> | ||
| <ErrorIcon size="S" /> | ||
| </div> | ||
| )} /> | ||
| </CardPreview> | ||
| <Content> | ||
| <Text slot="title">{item.description || item.alt_description}</Text> | ||
| {size !== 'XS' && <ActionMenu> | ||
| <MenuItem>Test</MenuItem> | ||
| </ActionMenu>} | ||
| <div className={style({display: 'flex', alignItems: 'center', gap: 8, gridArea: 'description'})}> | ||
| <Avatar src={item.user.profile_image.small} size={avatarSize[size]} /> | ||
| <Text slot="description">{item.user.name}</Text> | ||
| </div> | ||
| </Content> | ||
| </>)} | ||
| </Card> | ||
| ); | ||
| } | ||
|
|
||
| export const CardViewExample = (props) => { | ||
| let list = useAsyncList({ | ||
| async load({signal, cursor, items}) { | ||
| let page = cursor || 1; | ||
| let res = await fetch( | ||
| `https://api.unsplash.com/topics/nature/photos?page=${page}&per_page=30&client_id=AJuU-FPh11hn7RuumUllp4ppT8kgiLS7LtOHp_sp4nc`, | ||
| {signal} | ||
| ); | ||
| let nextItems = await res.json(); | ||
| // Filter duplicates which might be returned by the API. | ||
| let existingKeys = new Set(items.map(i => i.id)); | ||
| nextItems = nextItems.filter(i => !existingKeys.has(i.id) && (i.description || i.alt_description)); | ||
| return {items: nextItems, cursor: nextItems.length ? page + 1 : null}; | ||
| } | ||
| }); | ||
|
|
||
| let loadingState = props.loadingState === 'idle' ? list.loadingState : props.loadingState; | ||
| let items = loadingState === 'loading' ? [] : list.items; | ||
|
|
||
| return ( | ||
| <CardView | ||
| aria-label="Nature photos" | ||
| {...props} | ||
| loadingState={loadingState} | ||
| onLoadMore={props.loadingState === 'idle' ? list.loadMore : undefined} | ||
| styles={cardViewStyles}> | ||
| <Collection items={items} dependencies={[props.layout]}> | ||
| {item => <PhotoCard item={item} layout={props.layout || 'grid'} />} | ||
| </Collection> | ||
| {(loadingState === 'loading' || loadingState === 'loadingMore') && ( | ||
| <SkeletonCollection> | ||
| {() => ( | ||
| <PhotoCard | ||
| item={{ | ||
| id: Math.random(), | ||
| user: {name: 'Devon Govett', profile_image: {small: ''}}, | ||
| urls: {regular: ''}, | ||
| description: 'This is a fake description. Kinda long so it wraps to a new line.', | ||
| alt_description: '', | ||
| width: 400, | ||
| height: 200 + Math.max(0, Math.round(Math.random() * 400)) | ||
| }} | ||
| layout={props.layout || 'grid'} /> | ||
| )} | ||
| </SkeletonCollection> | ||
| )} | ||
| </CardView> | ||
| ); | ||
| }; | ||
|
|
||
| function TopicCard({topic}) { | ||
| return ( | ||
| <Card href={topic.links.html} target="_blank" textValue={topic.title}> | ||
| <CollectionCardPreview> | ||
| {topic.preview_photos.slice(0, 4).map(photo => ( | ||
| <Image key={photo.id} alt="" src={photo.urls.small} /> | ||
| ))} | ||
| </CollectionCardPreview> | ||
| <Content> | ||
| <Text slot="title">{topic.title}</Text> | ||
| <div className={style({display: 'flex', alignItems: 'center', gap: 8})}> | ||
| <Folder /> | ||
| <Text slot="description">{topic.total_photos.toLocaleString()} photos</Text> | ||
| </div> | ||
| </Content> | ||
| </Card> | ||
| ); | ||
| } | ||
|
|
||
| export const CollectionCardsExample = (props) => { | ||
| let list = useAsyncList({ | ||
| async load({signal, cursor}) { | ||
| let page = cursor || 1; | ||
| let res = await fetch( | ||
| `https://api.unsplash.com/topics?page=${page}&per_page=30&client_id=AJuU-FPh11hn7RuumUllp4ppT8kgiLS7LtOHp_sp4nc`, | ||
| {signal} | ||
| ); | ||
| let items = (await res.json()).filter((topic) => !!topic.preview_photos); | ||
| return {items, cursor: items.length ? page + 1 : null}; | ||
| } | ||
| }); | ||
|
|
||
| let loadingState = props.loadingState === 'idle' ? list.loadingState : props.loadingState; | ||
| let items = loadingState === 'loading' ? [] : list.items; | ||
|
|
||
| return ( | ||
| <CardView | ||
| aria-label="Topics" | ||
| {...props} | ||
| loadingState={loadingState} | ||
| onLoadMore={props.loadingState === 'idle' ? list.loadMore : undefined} | ||
| styles={cardViewStyles}> | ||
| <Collection items={items}> | ||
| {topic => <TopicCard topic={topic} />} | ||
| </Collection> | ||
| {(loadingState === 'loading' || loadingState === 'loadingMore') && ( | ||
| <SkeletonCollection> | ||
| {() => ( | ||
| <TopicCard | ||
| topic={{ | ||
| id: Math.random().toString(36), | ||
| title: 'Topic title', | ||
| total_photos: 80, | ||
| links: {html: ''}, | ||
| preview_photos: [ | ||
| {id: 'a', urls: {small: ''}}, | ||
| {id: 'b', urls: {small: ''}}, | ||
| {id: 'c', urls: {small: ''}}, | ||
| {id: 'd', urls: {small: ''}} | ||
| ] | ||
| }} /> | ||
| )} | ||
| </SkeletonCollection> | ||
| )} | ||
| </CardView> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.