Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Drawer): consumed Penta updates #10036

Merged
merged 6 commits into from
Feb 1, 2024
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
1 change: 1 addition & 0 deletions packages/react-core/src/components/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { css } from '@patternfly/react-styles';

export enum DrawerColorVariant {
default = 'default',
secondary = 'secondary',
noBackground = 'no-background'
}

Expand Down
6 changes: 3 additions & 3 deletions packages/react-core/src/components/Drawer/DrawerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ export interface DrawerContentProps extends React.HTMLProps<HTMLDivElement> {
/** Content rendered in the drawer panel. */
panelContent: React.ReactNode;
/** Color variant of the background of the drawer panel */
colorVariant?: DrawerColorVariant | 'no-background' | 'default';
colorVariant?: DrawerColorVariant | 'no-background' | 'default' | 'secondary';
}

export const DrawerContent: React.FunctionComponent<DrawerContentProps> = ({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
className = '',
className,
children,
panelContent,
colorVariant = DrawerColorVariant.default,
Expand All @@ -31,6 +30,7 @@ export const DrawerContent: React.FunctionComponent<DrawerContentProps> = ({
className={css(
styles.drawerContent,
colorVariant === DrawerColorVariant.noBackground && styles.modifiers.noBackground,
colorVariant === DrawerColorVariant.secondary && styles.modifiers.secondary,
className
)}
ref={drawerContentRef}
Expand Down
12 changes: 3 additions & 9 deletions packages/react-core/src/components/Drawer/DrawerHead.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import * as React from 'react';
import styles from '@patternfly/react-styles/css/components/Drawer/drawer';
import { css } from '@patternfly/react-styles';
import { DrawerPanelBody } from './DrawerPanelBody';

export interface DrawerHeadProps extends React.HTMLProps<HTMLDivElement> {
/** Additional classes added to the drawer head. */
className?: string;
/** Content to be rendered in the drawer head */
children?: React.ReactNode;
/** Indicates if there should be no padding around the drawer panel body of the head*/
hasNoPadding?: boolean;
}

export const DrawerHead: React.FunctionComponent<DrawerHeadProps> = ({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
className = '',
children,
hasNoPadding = false,
...props
}: DrawerHeadProps) => (
<DrawerPanelBody hasNoPadding={hasNoPadding}>
<div className={css(styles.drawerHead, className)} {...props}>
{children}
</div>
</DrawerPanelBody>
<div className={css(styles.drawerHead, className)} {...props}>
{children}
</div>
);
DrawerHead.displayName = 'DrawerHead';
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
'2xl'?: 'width_25' | 'width_33' | 'width_50' | 'width_66' | 'width_75' | 'width_100';
};
/** Color variant of the background of the drawer panel */
colorVariant?: DrawerColorVariant | 'no-background' | 'default';
colorVariant?: DrawerColorVariant | 'no-background' | 'default' | 'secondary';
/** Adds and customizes a focus trap on the drawer panel content. */
focusTrap?: DrawerPanelFocusTrapObject;
}
let isResizing: boolean = null;
let newSize: number = 0;

export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps> = ({
className = '',
className,
id,
children,
hasNoBorder = false,
Expand Down Expand Up @@ -242,7 +242,7 @@
drawerRef.current.classList.remove(css(styles.modifiers.resizing));
isResizing = false;
onResize && onResize(e, currWidth, id);
setInitialVals = true;

Check warning on line 245 in packages/react-core/src/components/Drawer/DrawerPanelContent.tsx

View workflow job for this annotation

GitHub Actions / lint

Assignments to the 'setInitialVals' variable from inside React Hook React.useCallback will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside React.useCallback
document.removeEventListener('mousemove', callbackMouseMove);
document.removeEventListener('mouseup', callbackMouseUp);
};
Expand All @@ -258,7 +258,7 @@
document.removeEventListener('touchend', callbackTouchEnd);
};

const callbackMouseMove = React.useCallback(handleMouseMove, []);

Check warning on line 261 in packages/react-core/src/components/Drawer/DrawerPanelContent.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook React.useCallback has missing dependencies: 'handleControlMove' and 'position'. Either include them or remove the dependency array
const callbackTouchEnd = React.useCallback(handleTouchEnd, []);
const callbackTouchMove = React.useCallback(handleTouchMove, []);
const callbackMouseUp = React.useCallback(handleMouseup, []);
Expand Down Expand Up @@ -367,6 +367,7 @@
hasNoBorder && styles.modifiers.noBorder,
formatBreakpointMods(widths, styles),
colorVariant === DrawerColorVariant.noBackground && styles.modifiers.noBackground,
colorVariant === DrawerColorVariant.secondary && styles.modifiers.secondary,
className
)}
onTransitionEnd={(ev) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import styles from '@patternfly/react-styles/css/components/Drawer/drawer';
import { css } from '@patternfly/react-styles';

/** Provides a description within the drawer panel. This should typically follow the drawer head. */

export interface DrawerPanelDescriptionProps extends React.HTMLProps<HTMLDivElement> {
/** Additional classes added to the drawer description. */
className?: string;
/** Content to be rendered in the drawer description */
children: React.ReactNode;
}

export const DrawerPanelDescription: React.FunctionComponent<DrawerPanelDescriptionProps> = ({
className,
children,
...props
}: DrawerPanelDescriptionProps) => (
<div className={css(styles.drawerDescription, className)} {...props}>
{children}
</div>
);
DrawerPanelDescription.displayName = 'DrawerPanelDescription';
3 changes: 2 additions & 1 deletion packages/react-core/src/components/Drawer/DrawerSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface DrawerSectionProps extends React.HTMLProps<HTMLDivElement> {
/** Content to be rendered in the drawer section. */
children?: React.ReactNode;
/** Color variant of the background of the drawer Section */
colorVariant?: DrawerColorVariant | 'no-background' | 'default';
colorVariant?: DrawerColorVariant | 'no-background' | 'default' | 'secondary';
}

export const DrawerSection: React.FunctionComponent<DrawerSectionProps> = ({
Expand All @@ -23,6 +23,7 @@ export const DrawerSection: React.FunctionComponent<DrawerSectionProps> = ({
className={css(
styles.drawerSection,
colorVariant === DrawerColorVariant.noBackground && styles.modifiers.noBackground,
colorVariant === DrawerColorVariant.secondary && styles.modifiers.secondary,
className
)}
{...props}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
DrawerContentBody,
DrawerHead,
DrawerPanelBody,
DrawerPanelContent
DrawerPanelContent,
DrawerColorVariant
} from '../';
import React from 'react';
import { render } from '@testing-library/react';
Expand Down Expand Up @@ -70,15 +71,14 @@ test(`Drawer expands from bottom`, () => {
expect(asFragment()).toMatchSnapshot();
});

// TODO: Update/renable with issue #9979
xtest(`Drawer has resizable css and color variants`, () => {
test(`Drawer has resizable css and color variants`, () => {
const panelContent = (
<DrawerPanelContent
isResizable
minSize={'200px'}
defaultSize={'300px'}
maxSize={'400px'}
// colorVariant={DrawerColorVariant.light200}
colorVariant={DrawerColorVariant.secondary}
>
<DrawerHead>
<span>drawer-panel</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import { DrawerPanelContent } from '../DrawerPanelContent';
import { Drawer } from '../Drawer';
import styles from '@patternfly/react-styles/css/components/Drawer/drawer';

test(`Renders with only class ${styles.drawerPanel} by default`, () => {
render(
<Drawer isExpanded>
<DrawerPanelContent>Drawer panel content</DrawerPanelContent>
</Drawer>
);

expect(screen.getByText('Drawer panel content')).toHaveClass(styles.drawerPanel, { exact: true });
});

test(`Renders with class ${styles.modifiers.noBackground} when colorVariant="no-background"`, () => {
render(
<Drawer isExpanded>
<DrawerPanelContent colorVariant="no-background">Drawer panel content</DrawerPanelContent>
</Drawer>
);

expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.noBackground);
});

test(`Renders with class ${styles.modifiers.secondary} when colorVariant="secondary"`, () => {
render(
<Drawer isExpanded>
<DrawerPanelContent colorVariant="secondary">Drawer panel content</DrawerPanelContent>
</Drawer>
);

expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.secondary);
});

test('Does not render with aria-labelledby by default', () => {
render(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { DrawerPanelDescription } from '../DrawerPanelDescription';
import styles from '@patternfly/react-styles/css/components/Drawer/drawer';

test(`Renders with only class ${styles.drawerDescription} by default`, () => {
render(<DrawerPanelDescription>description content</DrawerPanelDescription>);

expect(screen.getByText('description content')).toHaveClass(styles.drawerDescription, { exact: true });
});

test(`Renders with custom class when className is passed`, () => {
render(<DrawerPanelDescription className="test-class">description content</DrawerPanelDescription>);

expect(screen.getByText('description content')).toHaveClass('test-class');
});

test(`Spreads props`, () => {
render(<DrawerPanelDescription id="test-id">description content</DrawerPanelDescription>);

expect(screen.getByText('description content')).toHaveAttribute('id', 'test-id');
});

test(`Matches snapshot`, () => {
const { asFragment } = render(<DrawerPanelDescription>description content</DrawerPanelDescription>);

expect(asFragment()).toMatchSnapshot();
});
Loading
Loading