Enhance WizardView component by adding support for custom action buttons, sideBarGrow functionality, and a disabled state. Refactor layout styles for better responsiveness and usability.
This commit is contained in:
parent
b7bb6121b7
commit
e114a45348
@ -1,7 +1,15 @@
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useMediaQuery } from 'react-responsive'
|
import { useMediaQuery } from 'react-responsive'
|
||||||
import { Typography, Flex, Steps, Divider, Progress } from 'antd'
|
import {
|
||||||
|
Typography,
|
||||||
|
Flex,
|
||||||
|
Steps,
|
||||||
|
Divider,
|
||||||
|
Progress,
|
||||||
|
Button,
|
||||||
|
Dropdown
|
||||||
|
} from 'antd'
|
||||||
import NewObjectButtons from './NewObjectButtons'
|
import NewObjectButtons from './NewObjectButtons'
|
||||||
|
|
||||||
const { Title } = Typography
|
const { Title } = Typography
|
||||||
@ -15,7 +23,10 @@ const WizardView = ({
|
|||||||
loading,
|
loading,
|
||||||
sideBar = null,
|
sideBar = null,
|
||||||
submitText = 'Done',
|
submitText = 'Done',
|
||||||
progress = 0
|
progress = 0,
|
||||||
|
actions = [],
|
||||||
|
sideBarGrow = false,
|
||||||
|
disabled = false
|
||||||
}) => {
|
}) => {
|
||||||
const [currentStep, setCurrentStep] = useState(0)
|
const [currentStep, setCurrentStep] = useState(0)
|
||||||
const isMobile = useMediaQuery({ maxWidth: 768 })
|
const isMobile = useMediaQuery({ maxWidth: 768 })
|
||||||
@ -26,7 +37,7 @@ const WizardView = ({
|
|||||||
sideBar != null ? (
|
sideBar != null ? (
|
||||||
sideBar
|
sideBar
|
||||||
) : (
|
) : (
|
||||||
<div style={{ minWidth: '160px' }}>
|
<div style={{ minWidth: sideBarGrow == true ? '100%' : '160px' }}>
|
||||||
<Steps
|
<Steps
|
||||||
current={currentStep}
|
current={currentStep}
|
||||||
items={steps}
|
items={steps}
|
||||||
@ -45,7 +56,13 @@ const WizardView = ({
|
|||||||
vertical
|
vertical
|
||||||
justify='space-between'
|
justify='space-between'
|
||||||
gap={'middle'}
|
gap={'middle'}
|
||||||
style={{ width: '100%' }}
|
style={
|
||||||
|
sideBarGrow == false
|
||||||
|
? { width: '100%' }
|
||||||
|
: isMobile
|
||||||
|
? { width: '100%' }
|
||||||
|
: { width: '400px' }
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Flex vertical gap='middle' style={{ flexGrow: 1, width: '100%' }}>
|
<Flex vertical gap='middle' style={{ flexGrow: 1, width: '100%' }}>
|
||||||
<Title level={2} style={{ margin: 0 }}>
|
<Title level={2} style={{ margin: 0 }}>
|
||||||
@ -63,8 +80,37 @@ const WizardView = ({
|
|||||||
percent={progress}
|
percent={progress}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
{(actions || []).map((action) => {
|
||||||
|
if (action.steps.includes(steps[currentStep].key)) {
|
||||||
|
if (action.children) {
|
||||||
|
return (
|
||||||
|
<Dropdown menu={{ items: action.children }} key={action.key}>
|
||||||
|
<Button
|
||||||
|
onClick={action?.onClick}
|
||||||
|
disabled={action?.disabled || disabled}
|
||||||
|
loading={action?.loading || false}
|
||||||
|
>
|
||||||
|
{action.label}
|
||||||
|
</Button>
|
||||||
|
</Dropdown>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
key={action.key}
|
||||||
|
onClick={action?.onClick}
|
||||||
|
disabled={action?.disabled || disabled}
|
||||||
|
loading={action?.loading || false}
|
||||||
|
>
|
||||||
|
{action.label}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
})}
|
||||||
|
|
||||||
<NewObjectButtons
|
<NewObjectButtons
|
||||||
|
disabled={disabled}
|
||||||
currentStep={currentStep}
|
currentStep={currentStep}
|
||||||
totalSteps={steps.length}
|
totalSteps={steps.length}
|
||||||
onPrevious={() => setCurrentStep((prev) => prev - 1)}
|
onPrevious={() => setCurrentStep((prev) => prev - 1)}
|
||||||
@ -87,9 +133,12 @@ WizardView.propTypes = {
|
|||||||
showSteps: PropTypes.bool,
|
showSteps: PropTypes.bool,
|
||||||
title: PropTypes.string,
|
title: PropTypes.string,
|
||||||
loading: PropTypes.bool,
|
loading: PropTypes.bool,
|
||||||
|
disabled: PropTypes.bool,
|
||||||
sideBar: PropTypes.node,
|
sideBar: PropTypes.node,
|
||||||
submitText: PropTypes.string,
|
submitText: PropTypes.string,
|
||||||
progress: PropTypes.number
|
progress: PropTypes.number,
|
||||||
|
actions: PropTypes.array,
|
||||||
|
sideBarGrow: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
export default WizardView
|
export default WizardView
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user