-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] feat: PanelStack2 component (#4541)
- Loading branch information
Showing
22 changed files
with
896 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/core/src/components/panel-stack2/_panel-stack2.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright 2021 Palantir Technologies, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
@import "../../common/variables"; | ||
@import "~@blueprintjs/core/src/common/react-transition"; | ||
|
||
.#{$ns}-panel-stack2 { | ||
overflow: hidden; | ||
position: relative; | ||
} | ||
|
||
.#{$ns}-panel-stack2-header { | ||
align-items: center; | ||
box-shadow: 0 1px $pt-divider-black; | ||
display: flex; | ||
flex-shrink: 0; | ||
height: $pt-grid-size * 3; | ||
z-index: 1; | ||
|
||
.#{$ns}-dark & { | ||
box-shadow: 0 1px $pt-dark-divider-white; | ||
} | ||
|
||
// two span children act as spacers to keep the title centered. | ||
> span { | ||
align-items: stretch; | ||
display: flex; | ||
flex: 1; | ||
} | ||
|
||
.#{$ns}-heading { | ||
margin: 0 ($pt-grid-size / 2); | ||
} | ||
} | ||
|
||
.#{$ns}-button.#{$ns}-panel-stack2-header-back { | ||
margin-left: $pt-grid-size / 2; | ||
padding-left: 0; | ||
white-space: nowrap; | ||
|
||
.#{$ns}-icon { | ||
// reduce margins around icon so it fits better in tight header | ||
margin: 0 2px; | ||
} | ||
} | ||
|
||
.#{$ns}-panel-stack2-view { | ||
@include position-all(absolute, 0); | ||
|
||
background-color: $white; | ||
border-right: 1px solid $pt-divider-black; | ||
display: flex; | ||
flex-direction: column; | ||
|
||
// border between panels, visible during transition | ||
margin-right: -1px; | ||
overflow-y: auto; | ||
z-index: 1; | ||
|
||
.#{$ns}-dark & { | ||
background-color: $dark-gray4; | ||
} | ||
|
||
&:nth-last-child(n + 4) { | ||
display: none; | ||
} | ||
} | ||
|
||
// PUSH transition: enter from right (100%), existing panel moves off left. | ||
.#{$ns}-panel-stack2-push { | ||
@include react-transition-phase( | ||
"#{$ns}-panel-stack2", | ||
"enter", | ||
(transform: translateX(100%) translate(0%), opacity: 0 1), | ||
$easing: ease, | ||
$duration: $pt-transition-duration * 4 | ||
); | ||
@include react-transition-phase( | ||
"#{$ns}-panel-stack2", | ||
"exit", | ||
(transform: translateX(-50%) translate(0%), opacity: 0 1), | ||
$easing: ease, | ||
$duration: $pt-transition-duration * 4 | ||
); | ||
} | ||
|
||
// POP transition: enter from left (-50%), existing panel moves off right. | ||
.#{$ns}-panel-stack2-pop { | ||
@include react-transition-phase( | ||
"#{$ns}-panel-stack2", | ||
"enter", | ||
(transform: translateX(-50%) translate(0%), opacity: 0 1), | ||
$easing: ease, | ||
$duration: $pt-transition-duration * 4 | ||
); | ||
@include react-transition-phase( | ||
"#{$ns}-panel-stack2", | ||
"exit", | ||
(transform: translateX(100%) translate(0%), opacity: 0 1), | ||
$easing: ease, | ||
$duration: $pt-transition-duration * 4 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
tag: new | ||
--- | ||
|
||
@# Panel stack (v2) | ||
|
||
<div class="@ns-callout @ns-intent-warning @ns-icon-warning-sign"> | ||
<h4 class="@ns-heading">This API requires React 16.8+</h4> | ||
</div> | ||
|
||
<div class="@ns-callout @ns-intent-primary @ns-icon-info-sign"> | ||
<h4 class="@ns-heading"> | ||
|
||
Migrating from [PanelStack](#core/components/panel-stack)? | ||
|
||
</h4> | ||
|
||
PanelStack2 is a replacement for PanelStack. It will become the standard | ||
API in Blueprint core v4. You are encouraged to use this new API now to ease the | ||
transition to the next major version of Blueprint. See the full | ||
[migration guide](https://github.com/palantir/blueprint/wiki/PanelStack2-migration) on the wiki. | ||
|
||
</div> | ||
|
||
|
||
`PanelStack2` manages a stack of panels and displays only the topmost panel. | ||
|
||
Each panel appears with a header containing a "back" button to return to the | ||
previous panel. The bottom-most `initialPanel` cannot be closed or removed from | ||
the stack. Panels use | ||
[`CSSTransition`](http://reactcommunity.org/react-transition-group/css-transition) | ||
for seamless transitions. | ||
|
||
By default, only the currently active panel is rendered to the DOM. This means | ||
that other panels are unmounted and can lose their component state as a user | ||
transitions between the panels. You can notice this in the example below as | ||
the numeric counter is reset. To render all panels to the DOM and keep their | ||
React trees mounted, change the `renderActivePanelOnly` prop. | ||
|
||
@reactExample PanelStack2Example | ||
|
||
@## Panels | ||
|
||
Panels are supplied as `Panel<T>` objects, where `renderPanel` and `props` are | ||
used to render the panel element and `title` will appear in the header and back button. | ||
This breakdown allows the component to avoid cloning elements. | ||
Note that each panel is only mounted when it is atop the stack and is unmounted when | ||
it is closed or when a panel opens above it. | ||
|
||
`PanelStack2` injects panel action callbacks into each panel renderer in addition to | ||
the `props` defined by `Panel<T>`. These allow you to close the current panel or open a | ||
new one on top of it during the panel's lifecycle. For example: | ||
|
||
```tsx | ||
import { PanelProps } from "@blueprintjs/core"; | ||
|
||
type SettingsPanelInfo = { | ||
// ... | ||
}; | ||
|
||
const SettingsPanel: React.FC<PanelProps<SettingsPanelInfo>> = props => { | ||
const { openPanel, closePanel, ...info } = props; | ||
// ... | ||
} | ||
``` | ||
|
||
@interface Panel | ||
|
||
@interface PanelActions | ||
|
||
@## Props | ||
|
||
PanelStack2 can be operated as a controlled or uncontrolled component. | ||
|
||
@interface PanelStack2Props |
Oops, something went wrong.
f959561
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[core] feat: PanelStack2 component (#4541)
Previews: documentation | landing | table