Skip to content

Commit 6f12cad

Browse files
authored
[ResourceItem] Fix type errors and add example (#7731)
Quick PR to add a story for chromatic while I rebuild `ResourceItem`. Also fixes some annoying type errors
1 parent 1e5a2b6 commit 6f12cad

File tree

1 file changed

+68
-7
lines changed

1 file changed

+68
-7
lines changed

polaris-react/src/components/ResourceItem/ResourceItem.stories.tsx

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
import React, {useState} from 'react';
22
import type {ComponentMeta} from '@storybook/react';
3-
import {Avatar, Card, ResourceItem, ResourceList, Text} from '@shopify/polaris';
3+
import {
4+
Avatar,
5+
Card,
6+
ResourceItem,
7+
ResourceList,
8+
ResourceListProps,
9+
Text,
10+
} from '@shopify/polaris';
411

512
export default {
613
component: ResourceItem,
714
} as ComponentMeta<typeof ResourceItem>;
815

916
export function Default() {
10-
const [selectedItems, setSelectedItems] = useState([]);
17+
const [selectedItems, setSelectedItems] = useState<
18+
ResourceListProps['selectedItems']
19+
>([]);
1120

1221
return (
1322
<Card>
1423
<ResourceList
1524
resourceName={{singular: 'blog post', plural: 'blog posts'}}
1625
items={[
1726
{
18-
id: 6,
27+
id: '6',
1928
url: 'posts/6',
2029
title: 'How To Get Value From Wireframes',
2130
author: 'Jonathan Mangrove',
@@ -55,7 +64,7 @@ export function WithMedia() {
5564
resourceName={{singular: 'customer', plural: 'customers'}}
5665
items={[
5766
{
58-
id: 145,
67+
id: '145',
5968
url: 'customers/145',
6069
avatarSource:
6170
'https://burst.shopifycdn.com/photos/freelance-designer-working-on-laptop.jpg?width=746',
@@ -102,7 +111,58 @@ export function WithShortcutActions() {
102111
resourceName={{singular: 'customer', plural: 'customers'}}
103112
items={[
104113
{
105-
id: 145,
114+
id: '145',
115+
url: 'customers/145',
116+
avatarSource:
117+
'https://burst.shopifycdn.com/photos/freelance-designer-working-on-laptop.jpg?width=746',
118+
name: 'Yi So-Yeon',
119+
location: 'Gwangju, South Korea',
120+
latestOrderUrl: 'orders/1456',
121+
},
122+
]}
123+
renderItem={(item) => {
124+
const {id, url, avatarSource, name, location, latestOrderUrl} = item;
125+
126+
return (
127+
<ResourceItem
128+
id={id}
129+
url={url}
130+
media={
131+
<Avatar
132+
customer
133+
size="medium"
134+
name={name}
135+
source={avatarSource}
136+
/>
137+
}
138+
shortcutActions={[
139+
{content: 'View latest order', url: latestOrderUrl},
140+
]}
141+
accessibilityLabel={`View details for ${name}`}
142+
name={name}
143+
>
144+
<h3>
145+
<Text variant="bodyMd" fontWeight="bold" as="span">
146+
{name}
147+
</Text>
148+
</h3>
149+
<div>{location}</div>
150+
</ResourceItem>
151+
);
152+
}}
153+
/>
154+
</Card>
155+
);
156+
}
157+
158+
export function WithPersistedShortcutActions() {
159+
return (
160+
<Card>
161+
<ResourceList
162+
resourceName={{singular: 'customer', plural: 'customers'}}
163+
items={[
164+
{
165+
id: '145',
106166
url: 'customers/145',
107167
avatarSource:
108168
'https://burst.shopifycdn.com/photos/freelance-designer-working-on-laptop.jpg?width=746',
@@ -115,7 +175,7 @@ export function WithShortcutActions() {
115175
const {id, url, avatarSource, name, location, latestOrderUrl} = item;
116176
const shortcutActions = latestOrderUrl
117177
? [{content: 'View latest order', url: latestOrderUrl}]
118-
: null;
178+
: undefined;
119179

120180
return (
121181
<ResourceItem
@@ -129,6 +189,7 @@ export function WithShortcutActions() {
129189
source={avatarSource}
130190
/>
131191
}
192+
persistActions
132193
shortcutActions={shortcutActions}
133194
accessibilityLabel={`View details for ${name}`}
134195
name={name}
@@ -154,7 +215,7 @@ export function WithVerticalAlignment() {
154215
resourceName={{singular: 'customer', plural: 'customers'}}
155216
items={[
156217
{
157-
id: 145,
218+
id: '145',
158219
url: 'customers/145',
159220
avatarSource:
160221
'https://burst.shopifycdn.com/photos/freelance-designer-working-on-laptop.jpg?width=746',

0 commit comments

Comments
 (0)