Skip to content

Commit 2a56cc2

Browse files
committed
'disabled' button state added
1 parent 6d014e8 commit 2a56cc2

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

example/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const navButtonStyle = { background: 'gray', color: 'white' }
2323
// customStyle = { customStyle }
2424
// navButtonStyle = { navButtonStyle }
2525
// showButtonNav
26-
// showTitles
2726

2827
const App = () => (
2928
<div className='container'>
3029
<MultiStep
30+
showTitles
3131
steps={steps}
3232
activeStep={2}
3333
showButtonNav

src/MultiStep.jsx

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Breadcrumbs = styled('ol')`
1212
padding-bottom: 2.2rem;
1313
list-style-type: none;
1414
`
15-
const NavButtons = styled('ol')`
15+
const Navigation = styled('ol')`
1616
margin: 0;
1717
list-style-type: none;
1818
`
@@ -68,16 +68,16 @@ const Done = css`
6868
background-color: #33C3F0;
6969
}
7070
`
71-
const NavButton = css`
71+
const NavButton = styled('button')`
7272
background: #33C3F0;
7373
border-color: silver;
7474
color: white;
75-
`
76-
const NavButtonDisabled = css`
77-
background: silver;
78-
border-color: gray;
79-
color: gray;
80-
cursor: no-drop;
75+
76+
&:disabled {
77+
background: silver;
78+
border-color: gray;
79+
color: gray;
80+
}
8181
`
8282

8383
const getStep = (newIndex, length) => {
@@ -122,15 +122,14 @@ const getButtonsState = (indx, length) => {
122122

123123
// cloneElement(
124124
// step,
125-
// { nextButton: "next!" }
125+
// { nextButton: enabled? }
126126
// )
127127

128128
export default function MultiStep(props) {
129129
// todo: stepCustomStyle needs to be incorporated in goober styles
130130
// const stepCustomStyle = typeof props.stepCustomStyle === 'undefined' ? {} : props.stepCustomStyle
131131
const showTitles = typeof props.showTitles === 'undefined' ? false : true
132-
const showButtonNav = typeof props.showButtonNav === 'undefined' ? false : true
133-
const navButtonStyle = typeof props.navButtonStyle === 'undefined' ? { background: 'white', color: 'red' } : props.prevStyle
132+
const showNav = typeof props.showButtonNav === 'undefined' ? false : true
134133

135134
const [activeStep, _] = useState(getStep(props.activeStep, props.steps.length));
136135
const [stylesState, setStyles] = useState(getTopNavStyles(activeStep, props.steps.length))
@@ -139,7 +138,7 @@ export default function MultiStep(props) {
139138

140139
useEffect(() => {
141140
setStepState(activeStep)
142-
//setNextNavButton(props.nextDisabled)
141+
//setNextButton(props.disabled)
143142
}, [activeStep])
144143

145144
const setStepState = (indx) => {
@@ -180,30 +179,27 @@ export default function MultiStep(props) {
180179
}
181180
)
182181

183-
const renderNavButtons = (show) =>
184-
show && (
182+
const renderNavButtons = () =>
183+
showNav && (
185184
<>
186-
<button
187-
className={buttonsState.showPrevious ? NavButton : NavButtonDisabled}
188-
onClick={previous}
189-
>
190-
Prev
191-
</button>
192-
193-
<button
194-
className={buttonsState.showNext ? NavButton : NavButtonDisabled}
195-
onClick={next}
196-
>
197-
Next
198-
</button>
185+
{
186+
buttonsState.showPrevious ?
187+
<NavButton onClick={previous}>Prev</NavButton> :
188+
<NavButton disabled>Prev</NavButton>
189+
}
190+
{
191+
buttonsState.showNext ?
192+
<NavButton onClick={next}>Next</NavButton> :
193+
<NavButton disabled>next</NavButton>
194+
}
199195
</>
200196
)
201197

202198
return (
203199
<Multistep background={'orange'}>
204200
<Breadcrumbs>{renderBreadcrumbs()}</Breadcrumbs>
205201
{props.steps[compState].component}
206-
<NavButtons>{renderNavButtons(showButtonNav)}</NavButtons>
202+
<Navigation>{renderNavButtons()}</Navigation>
207203
</Multistep>
208204
)
209205
}

0 commit comments

Comments
 (0)