Skip to content

Commit e8b9c2c

Browse files
committed
feat(plugins/plugin-client-common): allow wizard header to be collapsed
1) hide description 2) reduce font size and margins a bit Ideally, it would be nice to pin this content and let the wizard content scroll. Given the current DOM structure, where the markdown is rendered deeply inside of Blocks etc.... this will be too hard for this PR. So let's start with at least allowing the user to reduce the amount of space taken up by the wizard header.
1 parent c61f9a5 commit e8b9c2c

File tree

4 files changed

+143
-21
lines changed

4 files changed

+143
-21
lines changed

packages/test/src/api/Wizard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
export default class Wizard {
1818
public readonly wizard = '.kui--wizard'
19-
private readonly title = '.pf-c-wizard__title'
20-
private readonly _description = '.pf-c-wizard__description'
19+
private readonly title = '.kui--wizard-header-title'
20+
private readonly _description = '.kui--wizard-header-description'
2121
private readonly _navItem = '.pf-c-wizard__nav-item'
2222
private readonly _navItemTitle = '.pf-c-wizard__nav-link'
2323
public readonly isCurrentStep = 'pf-m-current'

plugins/plugin-client-common/src/components/Content/Markdown/components/Wizard/index.tsx

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ import { onTabSwitch, offTabSwitch } from '../tabbed'
2424
import { OrderedGraph, blocks, compile, order, sequence } from '../code/graph'
2525

2626
import Card from '../../../../spi/Card'
27+
import Icons from '../../../../spi/Icons'
2728
import { MiniProgressStepper, StepperProps } from '../../../MiniProgressStepper'
2829
import { ProgressStepState, statusFromStatusVector } from '../../../ProgressStepper'
2930
import { subscribeToLinkUpdates, unsubscribeToLinkUpdates } from '../../../LinkStatus'
3031

32+
import '../../../../../../web/scss/components/Wizard/_index.scss'
3133
import '../../../../../../web/scss/components/Wizard/PatternFly.scss'
3234

3335
const PatternFlyWizard = React.lazy(() => import('@patternfly/react-core').then(_ => ({ default: _.Wizard })))
@@ -37,6 +39,9 @@ type Status = ProgressStepState['status']
3739
type Props = WizardProps & { uuid: string }
3840

3941
export interface State {
42+
/** Is the wizard in "collapsed" mode, where we only show the title and progress bar? */
43+
collapsedHeader: boolean
44+
4045
/** Graph of code blocks across all steps */
4146
graph: OrderedGraph
4247

@@ -85,6 +90,7 @@ export default class Wizard extends React.PureComponent<Props, State> {
8590
return {
8691
status,
8792
choices,
93+
collapsedHeader: !state ? false : state.collapsedHeader,
8894
codeBlocksPerStep: noChangeToCodeBlocks ? state.codeBlocksPerStep : codeBlocksPerStep,
8995
graph: noChangeToCodeBlocks ? state.graph : order(sequence(codeBlocks.filter(Boolean)))
9096
}
@@ -189,6 +195,43 @@ export default class Wizard extends React.PureComponent<Props, State> {
189195
return (props.children || []).slice(1)
190196
}
191197

198+
private readonly _toggleCollapsedHeader = () =>
199+
this.setState(curState => ({ collapsedHeader: !curState.collapsedHeader }))
200+
201+
private headerActions() {
202+
return (
203+
<div className="kui--wizard-header-action-buttons">
204+
<a className="kui--wizard-collapse-button kui--block-action" onClick={this._toggleCollapsedHeader}>
205+
<Icons icon={this.state.collapsedHeader ? 'WindowMaximize' : 'WindowMinimize'} />
206+
</a>
207+
</div>
208+
)
209+
}
210+
211+
private title() {
212+
const label = this.props['data-kui-title'].trim()
213+
return (
214+
<div className="kui--wizard-header-title" aria-label={label}>
215+
{label}
216+
</div>
217+
)
218+
}
219+
220+
private description() {
221+
return <div className="kui--wizard-header-description">{this.props.children[0]}</div>
222+
}
223+
224+
private header() {
225+
return (
226+
<div className="kui--wizard-header kui--inverted-color-context">
227+
{this.headerActions()}
228+
{this.title()}
229+
{this.description()}
230+
{this.progress()}
231+
</div>
232+
)
233+
}
234+
192235
private wizard() {
193236
const steps = Wizard.children(this.props).map((_, stepIdx) => ({
194237
name: _.props['data-kui-title'],
@@ -198,25 +241,18 @@ export default class Wizard extends React.PureComponent<Props, State> {
198241
component: <Card className="kui--markdown-tab-card">{_.props && _.props.children}</Card>
199242
}))
200243

201-
const progress = this.progress()
202-
203244
// onGoToStep={this._onWizardStepChange} onNext={this._onWizardStepChange} onBack={this._onWizardStepChange}
204245
return (
205-
<PatternFlyWizard
206-
hideClose
207-
steps={steps.length === 0 ? [{ name: '', component: '' }] : steps}
208-
className="kui--wizard"
209-
data-hide-cancel={true}
210-
data-bottom-margin={!progress /* no bottom margin if we're showing a progress bar */}
211-
footer={this.footer()}
212-
title={this.props['data-kui-title'].trim()}
213-
description={
214-
<React.Fragment>
215-
{this.props.children[0]}
216-
{progress}
217-
</React.Fragment>
218-
}
219-
/>
246+
<div className="kui--wizard" data-collapsed-header={this.state.collapsedHeader || undefined}>
247+
{this.header()}
248+
<div className="kui--wizard-main-content">
249+
<PatternFlyWizard
250+
steps={steps.length === 0 ? [{ name: '', component: '' }] : steps}
251+
data-hide-cancel={true}
252+
footer={this.footer()}
253+
/>
254+
</div>
255+
</div>
220256
)
221257
}
222258

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2022 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@import 'mixins';
18+
@import '../Terminal/mixins';
19+
20+
@include Wizard {
21+
display: flex;
22+
flex-direction: column;
23+
24+
@include CollapsedHeader {
25+
@include WizardHeader {
26+
padding: 1.75em;
27+
@include WizardDescription {
28+
font-size: $terminal-font-size;
29+
max-height: 2em;
30+
max-width: $max-column-width;
31+
overflow: hidden;
32+
33+
.paragraph {
34+
overflow: hidden;
35+
white-space: nowrap;
36+
text-overflow: ellipsis;
37+
}
38+
}
39+
}
40+
41+
@include WizardTitle {
42+
font-size: var(--pf-global--FontSize--xl);
43+
margin-bottom: 0.5em;
44+
}
45+
}
46+
}
47+
48+
@include WizardHeaderActionButtons {
49+
position: absolute;
50+
top: 1em;
51+
right: 1em;
52+
}
53+
54+
@include WizardHeader {
55+
position: relative;
56+
padding: 2em;
57+
}
58+
59+
@include WizardTitle {
60+
font-size: var(--pf-global--FontSize--3xl);
61+
margin-bottom: 1em;
62+
}

plugins/plugin-client-common/web/scss/components/Wizard/_mixins.scss

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,38 @@
2020
}
2121
}
2222

23+
@mixin WizardTitle {
24+
.kui--wizard-header-title {
25+
@content;
26+
}
27+
}
28+
2329
@mixin WizardHeader {
24-
.pf-c-wizard__header {
30+
.kui--wizard-header {
31+
@content;
32+
}
33+
}
34+
35+
@mixin CollapsedHeader {
36+
&[data-collapsed-header] {
37+
@content;
38+
}
39+
}
40+
41+
@mixin WizardHeaderActionButtons {
42+
.kui--wizard-header-action-buttons {
2543
@content;
2644
}
2745
}
2846

2947
@mixin WizardDescription {
30-
.pf-c-wizard__description {
48+
.kui--wizard-header-description {
49+
@content;
50+
}
51+
}
52+
53+
@mixin WizardMainContent {
54+
.kui--wizard-main-content {
3155
@content;
3256
}
3357
}

0 commit comments

Comments
 (0)