Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/weak-insects-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

Added support for `spacing` prop to List component allowing for a more compact list
16 changes: 10 additions & 6 deletions polaris-react/src/components/List/List.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
}

.Item {
margin-bottom: var(--p-space-2);

&:last-child {
margin-bottom: 0;
}

.List:first-child {
margin-top: var(--p-space-2);
}
}

.spacingLoose {
.Item {
margin-bottom: var(--p-space-2);
}
}

.Item:last-child {
margin-bottom: 0;
}
10 changes: 10 additions & 0 deletions polaris-react/src/components/List/List.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ export function Numbered() {
</List>
);
}

export function ExtraTight() {
return (
<List spacing="extraTight">
<List.Item>Yellow shirt</List.Item>
<List.Item>Red shirt</List.Item>
<List.Item>Green shirt</List.Item>
</List>
);
}
10 changes: 9 additions & 1 deletion polaris-react/src/components/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import styles from './List.scss';

type Type = 'bullet' | 'number';

type Spacing = 'extraTight' | 'loose';

export interface ListProps {
/**
* Determines the space between list items
* @default 'loose'
Copy link
Contributor

Choose a reason for hiding this comment

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

Tysm for adding context with JSDoc! 💯 🌟

*/
spacing?: Spacing;
/**
* Type of list to display
* @default 'bullet'
Expand All @@ -19,9 +26,10 @@ export interface ListProps {

export const List: React.FunctionComponent<ListProps> & {
Item: typeof Item;
} = function List({children, type = 'bullet'}: ListProps) {
} = function List({children, spacing = 'loose', type = 'bullet'}: ListProps) {
const className = classNames(
styles.List,
spacing && styles[variationName('spacing', spacing)],
type && styles[variationName('type', type)],
);

Expand Down
3 changes: 3 additions & 0 deletions polaris.shopify.com/content/components/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ examples:
- fileName: list-numbered.tsx
title: Numbered
description: Use for a text-only list of related items when an inherent order, priority, or sequence needs to be communicated.
- fileName: list-extra-tight.tsx
title: Extra Tight
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.
---

## Best practices
Expand Down
15 changes: 15 additions & 0 deletions polaris.shopify.com/pages/examples/list-extra-tight.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {List} from '@shopify/polaris';
import React from 'react';
import {withPolarisExample} from '../../src/components/PolarisExampleWrapper';

function ListExtraTightExample() {
return (
<List spacing="extraTight">
<List.Item>Yellow shirt</List.Item>
<List.Item>Red shirt</List.Item>
<List.Item>Green shirt</List.Item>
</List>
);
}

export default withPolarisExample(ListExtraTightExample);
Loading