Skip to content

Commit d7c46c8

Browse files
committed
feat(ActionList): Add isVertical variant
1 parent fe63802 commit d7c46c8

4 files changed

Lines changed: 60 additions & 1 deletion

File tree

packages/react-core/src/components/ActionList/ActionList.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,27 @@ export interface ActionListProps extends React.HTMLProps<HTMLDivElement> {
88
isIconList?: boolean;
99
/** Additional classes added to the action list */
1010
className?: string;
11+
/** Whether the layout of children is vertical or horizontal. */
12+
isVertical?: boolean;
1113
}
1214

1315
export const ActionList: React.FunctionComponent<ActionListProps> = ({
1416
children,
1517
isIconList,
1618
className,
19+
isVertical = false,
1720
...props
1821
}: ActionListProps) => (
19-
<div className={css(styles.actionList, isIconList && styles.modifiers.icons, className)} {...props}>
22+
<div
23+
className={css(
24+
styles.actionList,
25+
isIconList && styles.modifiers.icons,
26+
// @ts-expect-error: Vertical modifier does not yet exist
27+
isVertical && styles.modifiers.vertical,
28+
className
29+
)}
30+
{...props}
31+
>
2032
{children}
2133
</div>
2234
);

packages/react-core/src/components/ActionList/__tests__/ActionList.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ test(`Renders with class ${styles.modifiers.icons} when isIconList is true`, ()
3737
expect(screen.getByText('Test')).toHaveClass(styles.modifiers.icons);
3838
});
3939

40+
test(`Does not render with class ${styles.modifiers.vertical} by default`, () => {
41+
render(<ActionList>Test</ActionList>);
42+
43+
expect(screen.getByText('Test')).not.toHaveClass(styles.modifiers.vertical);
44+
});
45+
46+
test(`Renders with class ${styles.modifiers.vertical} when isVertical is true`, () => {
47+
render(<ActionList isVertical={true}>Test</ActionList>);
48+
49+
expect(screen.getByText('Test')).toHaveClass(styles.modifiers.vertical);
50+
});
51+
4052
test('Renders with inherited element props spread to the component', () => {
4153
render(<ActionList aria-label="Test label">Test</ActionList>);
4254

packages/react-core/src/components/ActionList/examples/ActionList.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-ico
3535
```ts file="./ActionListWithCancelButton.tsx"
3636

3737
```
38+
39+
### Action list vertical
40+
41+
```ts file="./ActionListVertical.tsx"
42+
43+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { ActionList, ActionListGroup, ActionListItem, Button } from '@patternfly/react-core';
2+
import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';
3+
import OutlinedPlusSquare from '@patternfly/react-icons/dist/esm/icons/outlined-plus-square-icon';
4+
import OutlinedCopy from '@patternfly/react-icons/dist/esm/icons/outlined-copy-icon';
5+
import OutlinedQuestionCircleIcon from '@patternfly/react-icons/dist/esm/icons/outlined-question-circle-icon';
6+
7+
export const ActionListVertical: React.FunctionComponent = () => (
8+
<>
9+
<h4>Vertical</h4>
10+
<ActionList isVertical>
11+
<ActionListGroup>
12+
<ActionListItem>
13+
<Button variant="plain" icon={<PlayIcon />} />
14+
</ActionListItem>
15+
<ActionListItem>
16+
<Button variant="plain" icon={<OutlinedPlusSquare />} />
17+
</ActionListItem>
18+
</ActionListGroup>
19+
<ActionListGroup>
20+
<ActionListItem>
21+
<Button variant="plain" icon={<OutlinedQuestionCircleIcon />} />
22+
</ActionListItem>
23+
<ActionListItem>
24+
<Button variant="plain" icon={<OutlinedCopy />} />
25+
</ActionListItem>
26+
</ActionListGroup>
27+
</ActionList>
28+
</>
29+
);

0 commit comments

Comments
 (0)