Skip to content

Commit 02a6533

Browse files
acidiolaurkim
authored andcommitted
[List] Add spacing property (Shopify#7939)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? This PR is a follow up of[compact list](https://shopify.slack.com/archives/C4Y8N30KD/p1670936155108179) [the conversation about having a more](https://shopify.slack.com/archives/C4Y8N30KD/p1671128757572269?thread_ts=1670952079.108219&cid=C4Y8N30KD) for places in admin where we have limited space and where the page can get really long because of the amount of items on it. <details> <summary>Current example</summary> ![current](https://user-images.githubusercontent.com/551895/208129966-d3dd26e2-d694-4c03-93d1-fbd527ec32fa.png) </details> <details> <summary>Intended example</summary> ![intended](https://user-images.githubusercontent.com/551895/208129994-6efb0f36-4f38-469d-bbbb-5e25e6229a56.png) </details> <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? Adding a `spacing` property to the `List` component allowing us to have a more compact version of the list. The `spacing` options are `extraTight | loose`, the last been the default one so it doesn't break current usage. | Before | After | | - | - | | ![image](https://user-images.githubusercontent.com/551895/208134389-a6a621aa-fd05-449f-9c4a-65b1eb06d421.png) | ![image](https://user-images.githubusercontent.com/551895/208134833-f401c315-87b0-4665-8bfd-bbeb1d02baae.png) | <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> <!-- ℹ️ Delete the following for small / trivial changes --> ### How to 🎩 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) <!-- Give as much information as needed to experiment with the component in the playground. --> <details> <summary>Copy-paste this code in <code>playground/Playground.tsx</code>:</summary> ```jsx import React from 'react'; import {List, Page} from '../src'; export function Playground() { return ( <Page title="Playground"> <List spacing="extraTight"> <List.Item>Yellow shirt</List.Item> <List.Item>Red shirt</List.Item> <List.Item>Green shirt</List.Item> </List> </Page> ); } ``` </details> ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [x] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide Co-authored-by: Lo Kim <lo.kim@shopify.com>
1 parent 9e02584 commit 02a6533

File tree

7 files changed

+971
-910
lines changed

7 files changed

+971
-910
lines changed

.changeset/weak-insects-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
Added support for `spacing` prop to List component allowing for a more compact list

polaris-react/src/components/List/List.scss

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
}
1616

1717
.Item {
18-
margin-bottom: var(--p-space-2);
19-
20-
&:last-child {
21-
margin-bottom: 0;
22-
}
23-
2418
.List:first-child {
2519
margin-top: var(--p-space-2);
2620
}
2721
}
22+
23+
.spacingLoose {
24+
.Item {
25+
margin-bottom: var(--p-space-2);
26+
}
27+
}
28+
29+
.Item:last-child {
30+
margin-bottom: 0;
31+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ export function Numbered() {
2525
</List>
2626
);
2727
}
28+
29+
export function ExtraTight() {
30+
return (
31+
<List spacing="extraTight">
32+
<List.Item>Yellow shirt</List.Item>
33+
<List.Item>Red shirt</List.Item>
34+
<List.Item>Green shirt</List.Item>
35+
</List>
36+
);
37+
}

polaris-react/src/components/List/List.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ import styles from './List.scss';
77

88
type Type = 'bullet' | 'number';
99

10+
type Spacing = 'extraTight' | 'loose';
11+
1012
export interface ListProps {
13+
/**
14+
* Determines the space between list items
15+
* @default 'loose'
16+
*/
17+
spacing?: Spacing;
1118
/**
1219
* Type of list to display
1320
* @default 'bullet'
@@ -19,9 +26,10 @@ export interface ListProps {
1926

2027
export const List: React.FunctionComponent<ListProps> & {
2128
Item: typeof Item;
22-
} = function List({children, type = 'bullet'}: ListProps) {
29+
} = function List({children, spacing = 'loose', type = 'bullet'}: ListProps) {
2330
const className = classNames(
2431
styles.List,
32+
spacing && styles[variationName('spacing', spacing)],
2533
type && styles[variationName('type', type)],
2634
);
2735

polaris.shopify.com/content/components/list.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ examples:
1616
- fileName: list-numbered.tsx
1717
title: Numbered
1818
description: Use for a text-only list of related items when an inherent order, priority, or sequence needs to be communicated.
19+
- fileName: list-extra-tight.tsx
20+
title: Extra Tight
21+
description: Use when there is limited space for a text-only list of related items when an inherent order, priority, or sequence needs to be communicated.
1922
---
2023

2124
## Best practices
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {List} from '@shopify/polaris';
2+
import React from 'react';
3+
import {withPolarisExample} from '../../src/components/PolarisExampleWrapper';
4+
5+
function ListExtraTightExample() {
6+
return (
7+
<List spacing="extraTight">
8+
<List.Item>Yellow shirt</List.Item>
9+
<List.Item>Red shirt</List.Item>
10+
<List.Item>Green shirt</List.Item>
11+
</List>
12+
);
13+
}
14+
15+
export default withPolarisExample(ListExtraTightExample);

0 commit comments

Comments
 (0)