Skip to content

Commit 427389d

Browse files
avelinelaurkim
authored andcommitted
[Layout] Update ActionList to use Layout primitives (#7805)
Fixes #7458 Co-authored-by: Lo Kim <lo.kim@shopify.com>
1 parent 6abcb84 commit 427389d

File tree

6 files changed

+259
-250
lines changed

6 files changed

+259
-250
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/polaris': minor
3+
'polaris.shopify.com': patch
4+
---
5+
6+
Rebuilt `ActionList` to use layout primitives

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

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,5 @@
11
@import '../../styles/common';
22

3-
.ActionList {
4-
outline: none;
5-
list-style: none;
6-
margin: 0;
7-
padding: 0;
8-
}
9-
10-
.Section:not(:first-child) {
11-
border-top: var(--p-border-divider);
12-
13-
// stylelint-disable-next-line selector-max-class, selector-max-combinators, selector-max-specificity -- generated by polaris-migrator DO NOT COPY
14-
> .Section-withoutTitle .Actions {
15-
padding-top: var(--p-space-2);
16-
}
17-
}
18-
19-
.Actions {
20-
outline: none;
21-
list-style: none;
22-
margin: 0;
23-
padding: var(--p-space-2);
24-
}
25-
26-
.ActionList,
27-
.Section:first-child {
28-
// stylelint-disable-next-line selector-max-class, selector-max-combinators, selector-max-specificity -- generated by polaris-migrator DO NOT COPY
29-
> .Section-withoutTitle .Actions {
30-
border-top: none;
31-
padding-top: var(--p-space-2);
32-
}
33-
}
34-
35-
.ActionList .Section {
36-
// stylelint-disable-next-line selector-max-class, selector-max-combinators -- generated by polaris-migrator DO NOT COPY
37-
.Actions {
38-
padding-top: 0;
39-
}
40-
}
41-
423
.Item {
434
// stylelint-disable -- Polaris component custom properties
445
--pc-action-list-image-size: 20px;
@@ -131,13 +92,6 @@
13192
}
13293
}
13394

134-
.Content {
135-
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
136-
display: flex;
137-
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
138-
align-items: center;
139-
}
140-
14195
.Prefix {
14296
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
14397
@include recolor-icon(var(--p-icon));
@@ -168,13 +122,6 @@
168122
.Suffix {
169123
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
170124
@include recolor-icon(var(--p-icon));
171-
margin-left: var(--p-space-4);
172-
}
173-
174-
.ContentBlock,
175-
.ContentBlockInner {
176-
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
177-
display: block;
178125
}
179126

180127
.Text {

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import {
66
} from '../../utilities/focus';
77
import {KeypressListener} from '../KeypressListener';
88
import {ActionListItemDescriptor, ActionListSection, Key} from '../../types';
9-
import {classNames} from '../../utilities/css';
9+
import {Box} from '../Box';
1010

1111
import {Section, Item} from './components';
1212
import type {ItemProps} from './components';
13-
import styles from './ActionList.scss';
1413

1514
export interface ActionListProps {
1615
/** Collection of actions for list */
@@ -40,10 +39,7 @@ export function ActionList({
4039
finalSections = sections;
4140
}
4241

43-
const className = classNames(styles.ActionList);
44-
4542
const hasMultipleSections = finalSections.length > 1;
46-
const Element = hasMultipleSections ? 'ul' : 'div';
4743
const elementRole =
4844
hasMultipleSections && actionRole === 'menuitem' ? 'menu' : undefined;
4945
const elementTabIndex =
@@ -57,6 +53,7 @@ export function ActionList({
5753
hasMultipleSections={hasMultipleSections}
5854
actionRole={actionRole}
5955
onActionAnyItem={onActionAnyItem}
56+
isFirst={index === 0}
6057
/>
6158
) : null;
6259
});
@@ -102,15 +99,15 @@ export function ActionList({
10299
) : null;
103100

104101
return (
105-
<Element
102+
<Box
103+
as={hasMultipleSections ? 'ul' : 'div'}
106104
ref={actionListRef}
107-
className={className}
108105
role={elementRole}
109106
tabIndex={elementTabIndex}
110107
>
111108
{listeners}
112109
{sectionMarkup}
113-
</Element>
110+
</Box>
114111
);
115112
}
116113

polaris-react/src/components/ActionList/components/Item/Item.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {Badge} from '../../../Badge';
99
import {Text} from '../../../Text';
1010
import styles from '../../ActionList.scss';
1111
import {handleMouseUpByBlurring} from '../../../../utilities/focus';
12+
import {Inline} from '../../../Inline';
13+
import {Box} from '../../../Box';
1214

1315
export type ItemProps = ActionListItemDescriptor;
1416

@@ -61,12 +63,12 @@ export function Item({
6163
const contentText = ellipsis && content ? `${content}…` : content;
6264

6365
const contentMarkup = helpText ? (
64-
<span className={styles.ContentBlock}>
65-
<span className={styles.ContentBlockInner}>{contentText}</span>
66+
<>
67+
<Box>{contentText}</Box>
6668
<Text variant="bodyMd" color="subdued" as="span">
6769
{helpText}
6870
</Text>
69-
</span>
71+
</>
7072
) : (
7173
contentText
7274
);
@@ -78,18 +80,20 @@ export function Item({
7880
);
7981

8082
const suffixMarkup = suffix && (
81-
<span className={styles.Suffix}>{suffix}</span>
83+
<Box paddingInlineStart="4">
84+
<span className={styles.Suffix}>{suffix}</span>
85+
</Box>
8286
);
8387

8488
const textMarkup = <span className={styles.Text}>{contentMarkup}</span>;
8589

8690
const contentElement = (
87-
<span className={styles.Content}>
91+
<Inline blockAlign="center" gap="0">
8892
{prefixMarkup}
8993
{textMarkup}
9094
{badgeMarkup}
9195
{suffixMarkup}
92-
</span>
96+
</Inline>
9397
);
9498

9599
const scrollMarkup = active ? <Scrollable.ScrollTo /> : null;

polaris-react/src/components/ActionList/components/Section/Section.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
ActionListItemDescriptor,
88
ActionListSection,
99
} from '../../../../types';
10-
import styles from '../../ActionList.scss';
1110

1211
export interface SectionProps {
1312
/** Section of action items */
@@ -18,11 +17,14 @@ export interface SectionProps {
1817
actionRole?: 'option' | 'menuitem' | string;
1918
/** Callback when any item is clicked or keypressed */
2019
onActionAnyItem?: ActionListItemDescriptor['onAction'];
20+
/** Whether it is the first in a group of sections */
21+
isFirst?: boolean;
2122
}
2223

2324
export function Section({
2425
section,
2526
hasMultipleSections,
27+
isFirst,
2628
actionRole,
2729
onActionAnyItem,
2830
}: SectionProps) {
@@ -55,8 +57,6 @@ export function Section({
5557
},
5658
);
5759

58-
const className = section.title ? undefined : styles['Section-withoutTitle'];
59-
6060
const titleMarkup = section.title ? (
6161
<Box
6262
paddingBlockStart="4"
@@ -70,7 +70,7 @@ export function Section({
7070
</Box>
7171
) : null;
7272

73-
let sectionRole;
73+
let sectionRole: 'menu' | 'presentation' | undefined;
7474
switch (actionRole) {
7575
case 'option':
7676
sectionRole = 'presentation';
@@ -84,22 +84,29 @@ export function Section({
8484
}
8585

8686
const sectionMarkup = (
87-
<div className={className}>
87+
<>
8888
{titleMarkup}
89-
<ul
90-
className={styles.Actions}
91-
role={sectionRole}
89+
<Box
90+
as="ul"
91+
padding="2"
92+
{...(hasMultipleSections && {paddingBlockStart: '0'})}
93+
{...(sectionRole && {role: sectionRole})}
9294
tabIndex={!hasMultipleSections ? -1 : undefined}
9395
>
9496
{actionMarkup}
95-
</ul>
96-
</div>
97+
</Box>
98+
</>
9799
);
98100

99101
return hasMultipleSections ? (
100-
<li className={styles.Section} role="presentation">
102+
<Box
103+
as="li"
104+
role="presentation"
105+
{...(!isFirst && {borderBlockStart: 'divider'})}
106+
{...(!section.title && {paddingBlockStart: '2'})}
107+
>
101108
{sectionMarkup}
102-
</li>
109+
</Box>
103110
) : (
104111
sectionMarkup
105112
);

0 commit comments

Comments
 (0)