-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathStepGroup.js
97 lines (80 loc) · 2.15 KB
/
StepGroup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import _ from 'lodash'
import cx from 'classnames'
import PropTypes from 'prop-types'
import React from 'react'
import {
childrenUtils,
customPropTypes,
getElementType,
getUnhandledProps,
META,
SUI,
useValueAndKey,
useKeyOnly,
} from '../../lib'
import Step from './Step'
/**
* A set of steps.
*/
function StepGroup(props) {
const {
children,
className,
fluid,
items,
ordered,
size,
stackable,
unstackable,
vertical,
} = props
const classes = cx(
'ui',
size,
useKeyOnly(fluid, 'fluid'),
useKeyOnly(ordered, 'ordered'),
useKeyOnly(unstackable, 'unstackable,'),
useKeyOnly(vertical, 'vertical'),
useValueAndKey(stackable, 'stackable'),
'steps',
className,
)
const rest = getUnhandledProps(StepGroup, props)
const ElementType = getElementType(StepGroup, props)
if (!childrenUtils.isNil(children)) {
return <ElementType {...rest} className={classes}>{children}</ElementType>
}
const content = _.map(items, item => {
const key = item.key || [item.title, item.description].join('-')
return <Step key={key} {...item} />
})
return <ElementType {...rest} className={classes}>{content}</ElementType>
}
StepGroup._meta = {
name: 'StepGroup',
parent: 'Step',
type: META.TYPES.ELEMENT,
}
StepGroup.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,
/** Primary content. */
children: PropTypes.node,
/** Additional classes. */
className: PropTypes.string,
/** A fluid step takes up the width of its container. */
fluid: PropTypes.bool,
/** Shorthand array of props for Step. */
items: customPropTypes.collectionShorthand,
/** A step can show a ordered sequence of steps. */
ordered: PropTypes.bool,
/** Steps can have different sizes. */
size: PropTypes.oneOf(_.without(SUI.SIZES, 'medium')),
/** A step can stack vertically only on smaller screens. */
stackable: PropTypes.oneOf(['tablet']),
/** A step can prevent itself from stacking on mobile. */
unstackable: PropTypes.bool,
/** A step can be displayed stacked vertically. */
vertical: PropTypes.bool,
}
export default StepGroup