Skip to content

Commit b0a9dd8

Browse files
feat(Drawer): Add pill version (#12091)
1 parent 2409ed1 commit b0a9dd8

File tree

11 files changed

+171
-15
lines changed

11 files changed

+171
-15
lines changed

packages/react-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"tslib": "^2.8.1"
5555
},
5656
"devDependencies": {
57-
"@patternfly/patternfly": "6.5.0-prerelease.11",
57+
"@patternfly/patternfly": "6.5.0-prerelease.12",
5858
"case-anything": "^3.1.2",
5959
"css": "^3.0.0",
6060
"fs-extra": "^11.3.0"

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export interface DrawerProps extends React.HTMLProps<HTMLDivElement> {
1717
isExpanded?: boolean;
1818
/** Indicates if the content element and panel element are displayed side by side. */
1919
isInline?: boolean;
20+
/** @beta Indicates if the drawer will have pill styles */
21+
isPill?: boolean;
2022
/** Indicates if the drawer will always show both content and panel. */
2123
isStatic?: boolean;
2224
/** Position of the drawer panel. left and right are deprecated, use start and end instead. */
@@ -50,6 +52,7 @@ export const Drawer: React.FunctionComponent<DrawerProps> = ({
5052
children,
5153
isExpanded = false,
5254
isInline = false,
55+
isPill = false,
5356
isStatic = false,
5457
position = 'end',
5558
onExpand = () => {},
@@ -65,6 +68,7 @@ export const Drawer: React.FunctionComponent<DrawerProps> = ({
6568
styles.drawer,
6669
isExpanded && styles.modifiers.expanded,
6770
isInline && styles.modifiers.inline,
71+
isPill && styles.modifiers.pill,
6872
isStatic && styles.modifiers.static,
6973
(position === 'left' || position === 'start') && styles.modifiers.panelLeft,
7074
position === 'bottom' && styles.modifiers.panelBottom,

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import {
1010
DrawerPanelContent,
1111
DrawerColorVariant
1212
} from '../';
13-
import { render } from '@testing-library/react';
13+
import { screen, render } from '@testing-library/react';
1414
import userEvent from '@testing-library/user-event';
1515
import { KeyTypes } from '../../../helpers';
16+
import styles from '@patternfly/react-styles/css/components/Drawer/drawer';
1617

1718
jest.mock('../../../helpers/GenerateId/GenerateId');
1819

@@ -162,3 +163,27 @@ test('Resizeable DrawerPanelContent can be wrapped in a context without causing
162163

163164
expect(consoleError).not.toHaveBeenCalled();
164165
});
166+
167+
test(`Renders with ${styles.modifiers.pill} class when specified`, () => {
168+
const panelContent = (
169+
<DrawerPanelContent>
170+
<DrawerHead>
171+
<span>drawer-panel</span>
172+
<DrawerActions>
173+
<DrawerCloseButton />
174+
</DrawerActions>
175+
</DrawerHead>
176+
<DrawerPanelBody>drawer-panel</DrawerPanelBody>
177+
</DrawerPanelContent>
178+
);
179+
180+
render(
181+
<Drawer data-testid="drawer" isExpanded={true} position="left" isPill>
182+
<DrawerContent panelContent={panelContent}>
183+
<DrawerContentBody>Drawer content text</DrawerContentBody>
184+
</DrawerContent>
185+
</Drawer>
186+
);
187+
188+
expect(screen.getByTestId('drawer')).toHaveClass(styles.modifiers.pill);
189+
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ propComponents:
1717
]
1818
section: components
1919
---
20+
2021
import { Fragment, useRef, useState } from 'react';
2122
import accessibility from '@patternfly/react-styles/css/utilities/Accessibility/accessibility';
2223

@@ -143,3 +144,15 @@ To customize which element receives focus when the drawer panel expands, use the
143144
```ts file="./DrawerFocusTrap.tsx"
144145

145146
```
147+
148+
### Pill
149+
150+
```ts file="./DrawerBasicPill.tsx"
151+
152+
```
153+
154+
### Pill inline
155+
156+
```ts file="./DrawerPillInline.tsx"
157+
158+
```
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Fragment, useRef, useState } from 'react';
2+
import {
3+
Drawer,
4+
DrawerPanelContent,
5+
DrawerContent,
6+
DrawerContentBody,
7+
DrawerHead,
8+
DrawerActions,
9+
DrawerCloseButton,
10+
Button
11+
} from '@patternfly/react-core';
12+
13+
export const DrawerBasicPill: React.FunctionComponent = () => {
14+
const [isExpanded, setIsExpanded] = useState(false);
15+
const drawerRef = useRef<HTMLDivElement>(undefined);
16+
17+
const onExpand = () => {
18+
drawerRef.current && drawerRef.current.focus();
19+
};
20+
21+
const onClick = () => {
22+
setIsExpanded(!isExpanded);
23+
};
24+
25+
const onCloseClick = () => {
26+
setIsExpanded(false);
27+
};
28+
29+
const panelContent = (
30+
<DrawerPanelContent>
31+
<DrawerHead>
32+
<span tabIndex={isExpanded ? 0 : -1} ref={drawerRef}>
33+
Drawer panel header
34+
</span>
35+
<DrawerActions>
36+
<DrawerCloseButton onClick={onCloseClick} />
37+
</DrawerActions>
38+
</DrawerHead>
39+
</DrawerPanelContent>
40+
);
41+
42+
const drawerContent =
43+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pretium est a porttitor vehicula. Quisque vel commodo urna. Morbi mattis rutrum ante, id vehicula ex accumsan ut. Morbi viverra, eros vel porttitor facilisis, eros purus aliquet erat,nec lobortis felis elit pulvinar sem. Vivamus vulputate, risus eget commodo eleifend, eros nibh porta quam, vitae lacinia leo libero at magna. Maecenas aliquam sagittis orci, et posuere nisi ultrices sit amet. Aliquam ex odio, malesuada sed posuere quis, pellentesque at mauris. Phasellus venenatis massa ex, eget pulvinar libero auctor pretium. Aliquam erat volutpat. Duis euismod justo in quam ullamcorper, in commodo massa vulputate.';
44+
45+
return (
46+
<Fragment>
47+
<Button aria-expanded={isExpanded} onClick={onClick}>
48+
Toggle drawer
49+
</Button>
50+
<Drawer isExpanded={isExpanded} isPill onExpand={onExpand}>
51+
<DrawerContent panelContent={panelContent}>
52+
<DrawerContentBody>{drawerContent}</DrawerContentBody>
53+
</DrawerContent>
54+
</Drawer>
55+
</Fragment>
56+
);
57+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Fragment, useRef, useState } from 'react';
2+
import {
3+
Drawer,
4+
DrawerPanelContent,
5+
DrawerContent,
6+
DrawerContentBody,
7+
DrawerHead,
8+
DrawerActions,
9+
DrawerCloseButton,
10+
Button
11+
} from '@patternfly/react-core';
12+
13+
export const DrawerBasicPill: React.FunctionComponent = () => {
14+
const [isExpanded, setIsExpanded] = useState(false);
15+
const drawerRef = useRef<HTMLDivElement>(undefined);
16+
17+
const onExpand = () => {
18+
drawerRef.current && drawerRef.current.focus();
19+
};
20+
21+
const onClick = () => {
22+
setIsExpanded(!isExpanded);
23+
};
24+
25+
const onCloseClick = () => {
26+
setIsExpanded(false);
27+
};
28+
29+
const panelContent = (
30+
<DrawerPanelContent>
31+
<DrawerHead>
32+
<span tabIndex={isExpanded ? 0 : -1} ref={drawerRef}>
33+
Drawer panel header
34+
</span>
35+
<DrawerActions>
36+
<DrawerCloseButton onClick={onCloseClick} />
37+
</DrawerActions>
38+
</DrawerHead>
39+
</DrawerPanelContent>
40+
);
41+
42+
const drawerContent =
43+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pretium est a porttitor vehicula. Quisque vel commodo urna. Morbi mattis rutrum ante, id vehicula ex accumsan ut. Morbi viverra, eros vel porttitor facilisis, eros purus aliquet erat,nec lobortis felis elit pulvinar sem. Vivamus vulputate, risus eget commodo eleifend, eros nibh porta quam, vitae lacinia leo libero at magna. Maecenas aliquam sagittis orci, et posuere nisi ultrices sit amet. Aliquam ex odio, malesuada sed posuere quis, pellentesque at mauris. Phasellus venenatis massa ex, eget pulvinar libero auctor pretium. Aliquam erat volutpat. Duis euismod justo in quam ullamcorper, in commodo massa vulputate.';
44+
45+
return (
46+
<Fragment>
47+
<Button aria-expanded={isExpanded} onClick={onClick}>
48+
Toggle drawer
49+
</Button>
50+
<Drawer isExpanded={isExpanded} isPill isInline onExpand={onExpand}>
51+
<DrawerContent panelContent={panelContent}>
52+
<DrawerContentBody>{drawerContent}</DrawerContentBody>
53+
</DrawerContent>
54+
</Drawer>
55+
</Fragment>
56+
);
57+
};

packages/react-docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test:a11y": "patternfly-a11y --config patternfly-a11y.config"
2424
},
2525
"dependencies": {
26-
"@patternfly/patternfly": "6.5.0-prerelease.11",
26+
"@patternfly/patternfly": "6.5.0-prerelease.12",
2727
"@patternfly/react-charts": "workspace:^",
2828
"@patternfly/react-code-editor": "workspace:^",
2929
"@patternfly/react-core": "workspace:^",

packages/react-icons/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@fortawesome/free-brands-svg-icons": "^5.15.4",
3434
"@fortawesome/free-regular-svg-icons": "^5.15.4",
3535
"@fortawesome/free-solid-svg-icons": "^5.15.4",
36-
"@patternfly/patternfly": "6.5.0-prerelease.11",
36+
"@patternfly/patternfly": "6.5.0-prerelease.12",
3737
"fs-extra": "^11.3.0",
3838
"tslib": "^2.8.1"
3939
},

packages/react-styles/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"clean": "rimraf dist css"
2020
},
2121
"devDependencies": {
22-
"@patternfly/patternfly": "6.5.0-prerelease.11",
22+
"@patternfly/patternfly": "6.5.0-prerelease.12",
2323
"change-case": "^5.4.4",
2424
"fs-extra": "^11.3.0"
2525
},

packages/react-tokens/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
"devDependencies": {
3232
"@adobe/css-tools": "^4.4.4",
33-
"@patternfly/patternfly": "6.5.0-prerelease.11",
33+
"@patternfly/patternfly": "6.5.0-prerelease.12",
3434
"fs-extra": "^11.3.0"
3535
}
3636
}

0 commit comments

Comments
 (0)