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

[Core] Add position prop to Drawer component, deprecate vertical prop #3386

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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/core/src/common/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const MULTILINE = `${NS}-multiline`;
export const ROUND = `${NS}-round`;
export const SMALL = `${NS}-small`;
export const VERTICAL = `${NS}-vertical`;
export const REVERSE = `${NS}-reverse`;

export const ELEVATION_0 = elevationClass(Elevation.ZERO);
export const ELEVATION_1 = elevationClass(Elevation.ONE);
Expand Down
114 changes: 80 additions & 34 deletions packages/core/src/components/drawer/_drawer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,95 @@ $drawer-default-size: 50%;
}

&:not(.#{$ns}-vertical) {
@include react-transition-phase(
"#{$ns}-overlay",
"enter",
(transform: (translateX(100%), translateX(0))),
$pt-transition-duration * 2,
$pt-transition-ease,
$before: "&"
);
@include react-transition-phase(
"#{$ns}-overlay",
"exit",
(transform: (translateX(100%), translateX(0))),
$pt-transition-duration,
$before: "&"
);

top: 0;
right: 0;
bottom: 0;
width: $drawer-default-size;

&:not(.#{$ns}-reverse) {
@include react-transition-phase(
"#{$ns}-overlay",
"enter",
(transform: (translateX(100%), translateX(0))),
$pt-transition-duration * 2,
$pt-transition-ease,
$before: "&"
);
@include react-transition-phase(
"#{$ns}-overlay",
"exit",
(transform: (translateX(100%), translateX(0))),
$pt-transition-duration,
$before: "&"
);

right: 0;
}

&.#{$ns}-reverse {
@include react-transition-phase(
"#{$ns}-overlay",
"enter",
(transform: (translateX(-100%), translateX(0))),
$pt-transition-duration * 2,
$pt-transition-ease,
$before: "&"
);
@include react-transition-phase(
"#{$ns}-overlay",
"exit",
(transform: (translateX(-100%), translateX(0))),
$pt-transition-duration,
$before: "&"
);

left: 0;
}
}

&.#{$ns}-vertical {
@include react-transition-phase(
"#{$ns}-overlay",
"enter",
(transform: (translateY(100%), translateY(0))),
$pt-transition-duration * 2,
$pt-transition-ease,
$before: "&"
);
@include react-transition-phase(
"#{$ns}-overlay",
"exit",
(transform: (translateY(100%), translateY(0))),
$pt-transition-duration,
$before: "&"
);

right: 0;
bottom: 0;
left: 0;
height: $drawer-default-size;

&:not(.#{$ns}-reverse) {
@include react-transition-phase(
"#{$ns}-overlay",
"enter",
(transform: (translateY(100%), translateY(0))),
$pt-transition-duration * 2,
$pt-transition-ease,
$before: "&"
);
@include react-transition-phase(
"#{$ns}-overlay",
"exit",
(transform: (translateY(100%), translateY(0))),
$pt-transition-duration,
$before: "&"
);

bottom: 0;
}

&.#{$ns}-reverse {
@include react-transition-phase(
"#{$ns}-overlay",
"enter",
(transform: (translateY(-100%), translateY(0))),
$pt-transition-duration * 2,
$pt-transition-ease,
$before: "&"
);
@include react-transition-phase(
"#{$ns}-overlay",
"exit",
(transform: (translateY(-100%), translateY(0))),
$pt-transition-duration,
$before: "&"
);

top: 0;
}
}

&.#{$ns}-dark,
Expand Down
20 changes: 18 additions & 2 deletions packages/core/src/components/drawer/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export interface IDrawerProps extends IOverlayableProps, IBackdropProps, IProps
*/
isOpen: boolean;

/**
* Whether the drawer should appear on the reversed side.
* Depending on the `vertical` prop, it will show on the left side (instead of the right),
* or on the top (instead of the bottom).
* @default false
*/
reverse?: boolean;

/**
* CSS size of the drawer. This sets `width` if `vertical={false}` (default)
* and `height` otherwise.
Expand Down Expand Up @@ -80,6 +88,7 @@ export class Drawer extends AbstractPureComponent<IDrawerProps, {}> {
public static defaultProps: IDrawerProps = {
canOutsideClickClose: true,
isOpen: false,
reverse: false,
style: {},
vertical: false,
};
Expand All @@ -89,8 +98,15 @@ export class Drawer extends AbstractPureComponent<IDrawerProps, {}> {
public static readonly SIZE_LARGE = "90%";

public render() {
const { size, style, vertical } = this.props;
const classes = classNames(Classes.DRAWER, { [Classes.VERTICAL]: vertical }, this.props.className);
const { size, style, vertical, reverse } = this.props;
const classes = classNames(
Classes.DRAWER,
{
[Classes.VERTICAL]: vertical,
[Classes.REVERSE]: reverse,
},
this.props.className,
);
const styleProp = size == null ? style : { ...style, [vertical ? "height" : "width"]: size };
return (
<Overlay {...this.props} className={Classes.OVERLAY_CONTAINER}>
Expand Down
9 changes: 9 additions & 0 deletions packages/core/test/drawer/drawerTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ describe("<Drawer>", () => {
assert.isTrue(drawer.find(`.${Classes.VERTICAL}`).exists());
});

it("reverse adds class", () => {
const drawer = mount(
<Drawer isOpen={true} usePortal={false} reverse={true}>
{createDrawerContents()}
</Drawer>,
);
assert.isTrue(drawer.find(`.${Classes.REVERSE}`).exists());
});

it("portalClassName appears on Portal", () => {
const TEST_CLASS = "test-class";
const drawer = mount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface IDrawerExampleState {
enforceFocus: boolean;
hasBackdrop: boolean;
isOpen: boolean;
reverse: boolean;
size: string;
usePortal: boolean;
vertical: boolean;
Expand All @@ -29,6 +30,7 @@ export class DrawerExample extends React.PureComponent<IExampleProps<IBlueprintE
enforceFocus: true,
hasBackdrop: true,
isOpen: false,
reverse: false,
size: undefined,
usePortal: true,
vertical: false,
Expand All @@ -40,6 +42,7 @@ export class DrawerExample extends React.PureComponent<IExampleProps<IBlueprintE
private handleEscapeKeyChange = handleBooleanChange(canEscapeKeyClose => this.setState({ canEscapeKeyClose }));
private handleUsePortalChange = handleBooleanChange(usePortal => this.setState({ usePortal }));
private handleOutsideClickChange = handleBooleanChange(val => this.setState({ canOutsideClickClose: val }));
private handleReverseChange = handleBooleanChange(reverse => this.setState({ reverse }));
private handleVerticalChange = handleBooleanChange(vertical => this.setState({ vertical }));
private handleSizeChange = handleStringChange(size => this.setState({ size }));

Expand Down Expand Up @@ -100,6 +103,7 @@ export class DrawerExample extends React.PureComponent<IExampleProps<IBlueprintE
<HTMLSelect options={SIZES} onChange={this.handleSizeChange} />
</Label>
<Switch checked={this.state.vertical} label="Vertical" onChange={this.handleVerticalChange} />
<Switch checked={this.state.reverse} label="Reverse" onChange={this.handleReverseChange} />
<Divider />
<Switch checked={autoFocus} label="Auto focus" onChange={this.handleAutoFocusChange} />
<Switch checked={enforceFocus} label="Enforce focus" onChange={this.handleEnforceFocusChange} />
Expand Down