-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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] feat(PanelStack): add renderCurrentPanelOnly prop #3768
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
display: flex; | ||
flex-shrink: 0; | ||
align-items: center; | ||
z-index: 1; | ||
box-shadow: 0 1px $pt-divider-black; | ||
height: $pt-grid-size * 3; | ||
|
||
|
@@ -48,6 +47,7 @@ | |
@include position-all(absolute, 0); | ||
display: flex; | ||
flex-direction: column; | ||
z-index: 1; | ||
|
||
// border between panels, visible during transition | ||
margin-right: -1px; | ||
|
@@ -59,6 +59,10 @@ | |
.#{$ns}-dark & { | ||
background-color: $dark-gray4; | ||
} | ||
|
||
&:nth-last-child(n + 4) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All but last 3. Why 3? When one removes the top panel, the bottom two should be visible to animate properly. The rest can be hidden as a layering optimization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can you provide any evidence that we actually need this optimization? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
display: none; | ||
} | ||
} | ||
|
||
// PUSH transition: enter from right (100%), existing panel moves off left. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,12 @@ export interface IPanelStackProps extends IProps { | |
*/ | ||
onOpen?: (addedPanel: IPanel) => void; | ||
|
||
/** | ||
* If false, PanelStack will render all panels in the stack to the DOM, allowing their React component trees to maintain state as a user navigates through the stack. Panels other than the currently active one will be invisible. | ||
* @default true | ||
*/ | ||
renderCurrentPanelOnly?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's change this name to mirror a similar prop for the |
||
|
||
/** | ||
* Whether to show the header with the "back" button in each panel. | ||
* @default true | ||
|
@@ -93,7 +99,7 @@ export class PanelStack extends AbstractPureComponent2<IPanelStackProps, IPanelS | |
); | ||
return ( | ||
<TransitionGroup className={classes} component="div"> | ||
{this.renderCurrentPanel()} | ||
{this.renderPanels()} | ||
</TransitionGroup> | ||
); | ||
} | ||
|
@@ -110,25 +116,35 @@ export class PanelStack extends AbstractPureComponent2<IPanelStackProps, IPanelS | |
} | ||
} | ||
|
||
private renderCurrentPanel() { | ||
const { showPanelHeader = true } = this.props; | ||
private renderPanels() { | ||
const { renderCurrentPanelOnly = true } = this.props; | ||
const { stack } = this.state; | ||
if (stack.length === 0) { | ||
return null; | ||
} | ||
const [activePanel, previousPanel] = stack; | ||
const panelsToRender = renderCurrentPanelOnly ? [stack[0]] : stack; | ||
const panelViews = panelsToRender.map(this.renderPanel).reverse(); | ||
return panelViews; | ||
} | ||
|
||
private renderPanel = (panel: IPanel, index: number) => { | ||
const { showPanelHeader = true } = this.props; | ||
const { stack } = this.state; | ||
const active = index === 0; | ||
const layer = stack.length - index; | ||
const key = `${layer}-${active}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The I'm not sure how to tackle this issue in a good way. A somewhat hacky may include an additional field in the state to remember the active index (last fired There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused, what does key have to do with CSSTransition? I don't see it in the docs http://reactcommunity.org/react-transition-group/css-transition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is that with This |
||
return ( | ||
<CSSTransition classNames={Classes.PANEL_STACK} key={stack.length} timeout={400}> | ||
<CSSTransition classNames={Classes.PANEL_STACK} key={key} timeout={400}> | ||
<PanelView | ||
onClose={this.handlePanelClose} | ||
onOpen={this.handlePanelOpen} | ||
panel={activePanel} | ||
previousPanel={previousPanel} | ||
panel={panel} | ||
previousPanel={stack[index + 1]} | ||
showHeader={showPanelHeader} | ||
/> | ||
</CSSTransition> | ||
); | ||
} | ||
}; | ||
|
||
private handlePanelClose = (panel: IPanel) => { | ||
const { stack } = this.state; | ||
|
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.
Why was this removed? This breaks the box-shadow from the next line when the panel view's content has a background.
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.
@invliD It was quite a while ago, but it seems it got moved to
.#{$ns}-panel-stack-view
below. If it's a problem at the moment, I think you should file a new issue about that.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.
I did see it got added to the view, but that doesn't explain why it was removed here. I added it here for exactly this reason when I wrote the panel stack; guess I'll just add it back…