@targetprocess/confirmation 12.20.1-alpha.2 → 12.20.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -23
- package/Confirmation.jsx +220 -220
- package/__tests__/Confirmation.tests.jsx +78 -78
- package/dist/confirmation.es.js +52 -48
- package/dist/confirmation.js +52 -48
- package/index.js +4 -1
- package/package.json +5 -5
- package/style/index.css +53 -50
package/CHANGELOG.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
#### v7.19.0
|
|
2
|
-
|
|
3
|
-
- Added `getContainerElement` property
|
|
4
|
-
|
|
5
|
-
#### v7.1.0
|
|
6
|
-
|
|
7
|
-
- (breaking change) Now uses automatic style injection - no style import/`@global-import` is needed
|
|
8
|
-
|
|
9
|
-
#### v3.0.0
|
|
10
|
-
|
|
11
|
-
- Removed dependency on `lodash-es`.
|
|
12
|
-
|
|
13
|
-
#### 2.1.0
|
|
14
|
-
|
|
15
|
-
- Updated `@targetprocess/button`
|
|
16
|
-
|
|
17
|
-
#### 2.0.4
|
|
18
|
-
|
|
19
|
-
- Update box shadow colors to use transparency in `@targetprocess/global-constants`.
|
|
20
|
-
|
|
21
|
-
#### v2.0.0
|
|
22
|
-
|
|
23
|
-
- Fixed missing `module` field in `@targetprocess/popover` dependency `package.json`, which could affect some builds that rely on using CommonJS build of Popover.
|
|
1
|
+
#### v7.19.0
|
|
2
|
+
|
|
3
|
+
- Added `getContainerElement` property
|
|
4
|
+
|
|
5
|
+
#### v7.1.0
|
|
6
|
+
|
|
7
|
+
- (breaking change) Now uses automatic style injection - no style import/`@global-import` is needed
|
|
8
|
+
|
|
9
|
+
#### v3.0.0
|
|
10
|
+
|
|
11
|
+
- Removed dependency on `lodash-es`.
|
|
12
|
+
|
|
13
|
+
#### 2.1.0
|
|
14
|
+
|
|
15
|
+
- Updated `@targetprocess/button`
|
|
16
|
+
|
|
17
|
+
#### 2.0.4
|
|
18
|
+
|
|
19
|
+
- Update box shadow colors to use transparency in `@targetprocess/global-constants`.
|
|
20
|
+
|
|
21
|
+
#### v2.0.0
|
|
22
|
+
|
|
23
|
+
- Fixed missing `module` field in `@targetprocess/popover` dependency `package.json`, which could affect some builds that rely on using CommonJS build of Popover.
|
package/Confirmation.jsx
CHANGED
|
@@ -1,220 +1,220 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
import classNames from 'classnames'
|
|
4
|
-
import {Button} from '@targetprocess/button'
|
|
5
|
-
import * as CssAccessorsWithFallback from '@targetprocess/css-variables'
|
|
6
|
-
import {Popover} from '@targetprocess/popover'
|
|
7
|
-
|
|
8
|
-
import styles from './style/index.css'
|
|
9
|
-
|
|
10
|
-
function uppercaseFirst(input) {
|
|
11
|
-
if (typeof input !== 'string' || input.length === 0) {
|
|
12
|
-
return input
|
|
13
|
-
}
|
|
14
|
-
return input.slice(0, 1).toUpperCase() + input.slice(1)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const ConfirmationBody = ({
|
|
18
|
-
icon,
|
|
19
|
-
kind = 'second',
|
|
20
|
-
text,
|
|
21
|
-
description,
|
|
22
|
-
confirmButtonProps,
|
|
23
|
-
cancelButtonProps,
|
|
24
|
-
onConfirm,
|
|
25
|
-
onCancel,
|
|
26
|
-
confirmLabel,
|
|
27
|
-
cancelLabel
|
|
28
|
-
}) => (
|
|
29
|
-
<Popover.Body>
|
|
30
|
-
<div className={classNames(styles['confirmation'])}>
|
|
31
|
-
{icon && (
|
|
32
|
-
<div
|
|
33
|
-
className={classNames(styles['confirmation__icon'])}
|
|
34
|
-
style={{
|
|
35
|
-
backgroundColor:
|
|
36
|
-
CssAccessorsWithFallback[`${uppercaseFirst(kind)}100`] ||
|
|
37
|
-
CssAccessorsWithFallback.Second100
|
|
38
|
-
}}
|
|
39
|
-
>
|
|
40
|
-
{React.isValidElement(icon) && icon.type
|
|
41
|
-
? React.createElement(icon.type, {
|
|
42
|
-
color:
|
|
43
|
-
CssAccessorsWithFallback[`${uppercaseFirst(kind)}500`] ||
|
|
44
|
-
CssAccessorsWithFallback.Second500,
|
|
45
|
-
...icon.props
|
|
46
|
-
})
|
|
47
|
-
: icon}
|
|
48
|
-
</div>
|
|
49
|
-
)}
|
|
50
|
-
<div className={styles['confirmation__inner']}>
|
|
51
|
-
<div
|
|
52
|
-
className={classNames(
|
|
53
|
-
styles['confirmation__text'],
|
|
54
|
-
description && styles['confirmation__text--detailed']
|
|
55
|
-
)}
|
|
56
|
-
>
|
|
57
|
-
{text}
|
|
58
|
-
</div>
|
|
59
|
-
|
|
60
|
-
{description && (
|
|
61
|
-
<div className={classNames(styles['confirmation__description'])}>{description}</div>
|
|
62
|
-
)}
|
|
63
|
-
|
|
64
|
-
<div className={classNames(styles['confirmation__controls'])}>
|
|
65
|
-
<div className={classNames(styles['confirmation__controls__item'])}>
|
|
66
|
-
<Button kind={kind} {...confirmButtonProps} onClick={onConfirm}>
|
|
67
|
-
{confirmLabel}
|
|
68
|
-
</Button>
|
|
69
|
-
</div>
|
|
70
|
-
<div className={classNames(styles['confirmation__controls__item'])}>
|
|
71
|
-
<Button {...cancelButtonProps} onClick={onCancel}>
|
|
72
|
-
{cancelLabel}
|
|
73
|
-
</Button>
|
|
74
|
-
</div>
|
|
75
|
-
</div>
|
|
76
|
-
</div>
|
|
77
|
-
</div>
|
|
78
|
-
</Popover.Body>
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Confirmation can be used to display any kind of confirmation pop-up
|
|
83
|
-
* as popover with styled content and confirm and cancel buttons.
|
|
84
|
-
*
|
|
85
|
-
* In controlled mode, popover display can be adjusted with `isOpen` prop.
|
|
86
|
-
* In this mode, you are also responsible for closing the popover whenever
|
|
87
|
-
* any of the actions occur, if necessary:
|
|
88
|
-
* ```jsx
|
|
89
|
-
* <Confirmation
|
|
90
|
-
* text="Are you sure?"
|
|
91
|
-
* isOpen={this.state.isOpen}
|
|
92
|
-
* onCancel={() => this.setState({isOpen: false})}
|
|
93
|
-
* >
|
|
94
|
-
* <Button onClick={() => this.setState({isOpen: true})}>Delete</Button>
|
|
95
|
-
* </Confirmation>
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* In uncontrolled mode, you can use render prop children to determine
|
|
99
|
-
* whether confirmation is open, and to open or close it. In this mode,
|
|
100
|
-
* popover is opened by setOpened(true) from render callback. It is closed
|
|
101
|
-
* automatically whenever `onConfirm` or `onCancel` are to be invoked, this can
|
|
102
|
-
* be prevented by setting `closeOnAnyAction` to `false`.
|
|
103
|
-
* Clicking outside the popover is equivalent to clicking cancel button, this can
|
|
104
|
-
* be prevented by setting `cancelOnOuterAction` to `false`.
|
|
105
|
-
*
|
|
106
|
-
* ```jsx
|
|
107
|
-
* <Confirmation text="Are you sure?" onConfirm={doSomethingUseful}>
|
|
108
|
-
* {({isOpen, setOpened}) => (
|
|
109
|
-
* <Button onClick={() => setOpened(!isOpen)}>Do something</Button>
|
|
110
|
-
* )}
|
|
111
|
-
* </Confirmation>
|
|
112
|
-
* ```
|
|
113
|
-
*
|
|
114
|
-
* `text` property is a user prompt and is the only required field for confirmation.
|
|
115
|
-
* You can optionally include `description`, in which case `text` becomes a header and
|
|
116
|
-
* `description` is displayed as dimmed text below.
|
|
117
|
-
*
|
|
118
|
-
* You can also provide an `icon` that will be displayed to the left in a circle.
|
|
119
|
-
* Its `color` prop, if not present, will be overriden (via `cloneElement`) to the
|
|
120
|
-
* color of the appropriate confirmation `kind`.
|
|
121
|
-
*
|
|
122
|
-
* `kind` adjusts confirm button color, icon color and icon backdrop color. Any palette
|
|
123
|
-
* name is supported (i.e. `primary`, `danger`, etc.).
|
|
124
|
-
*
|
|
125
|
-
* `confirmButtonProps` and `cancelButtonProps` can be used to fine-tune individual button
|
|
126
|
-
* display, if necessary.
|
|
127
|
-
*/
|
|
128
|
-
export class Confirmation extends React.Component {
|
|
129
|
-
onConfirm = () => {
|
|
130
|
-
if (this.props.onConfirm) {
|
|
131
|
-
this.props.onConfirm()
|
|
132
|
-
}
|
|
133
|
-
if (this.props.closeOnAnyAction && this.setOpened) {
|
|
134
|
-
this.setOpened(false)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
onCancel = () => {
|
|
139
|
-
if (this.props.onCancel) {
|
|
140
|
-
this.props.onCancel()
|
|
141
|
-
}
|
|
142
|
-
if (this.props.closeOnAnyAction && this.setOpened) {
|
|
143
|
-
this.setOpened(false)
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
render() {
|
|
148
|
-
const {
|
|
149
|
-
isOpen: popoverOpen,
|
|
150
|
-
children,
|
|
151
|
-
popoverPosition,
|
|
152
|
-
cancelOnOuterAction,
|
|
153
|
-
getContainerElement,
|
|
154
|
-
...otherProps
|
|
155
|
-
} = this.props
|
|
156
|
-
|
|
157
|
-
return (
|
|
158
|
-
<Popover
|
|
159
|
-
isOpen={popoverOpen}
|
|
160
|
-
getPopoverPosition={popoverPosition}
|
|
161
|
-
getContainerElement={getContainerElement}
|
|
162
|
-
body={
|
|
163
|
-
<ConfirmationBody {...otherProps} onConfirm={this.onConfirm} onCancel={this.onCancel} />
|
|
164
|
-
}
|
|
165
|
-
onOuterAction={cancelOnOuterAction ? this.onCancel : this.props.onOuterAction}
|
|
166
|
-
zIndex={this.props.zIndex}
|
|
167
|
-
showTip
|
|
168
|
-
>
|
|
169
|
-
{({isOpen, setOpened}) => {
|
|
170
|
-
this.setOpened = setOpened
|
|
171
|
-
return typeof children === 'function' ? children({isOpen, setOpened}) : children
|
|
172
|
-
}}
|
|
173
|
-
</Popover>
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
Confirmation.propTypes = {
|
|
179
|
-
/** Whether the popover is currently open in controlled mode, undefined for uncontrolled mode */
|
|
180
|
-
isOpen: PropTypes.bool,
|
|
181
|
-
/** Color palette that is used for icon and confirm button */
|
|
182
|
-
kind: PropTypes.string,
|
|
183
|
-
/** Icon element (any SVG but `@targetprocess/icons` is preferred) */
|
|
184
|
-
icon: PropTypes.element,
|
|
185
|
-
/** Confirmation text */
|
|
186
|
-
text: PropTypes.node.isRequired,
|
|
187
|
-
/** Optional confirmation description */
|
|
188
|
-
description: PropTypes.node,
|
|
189
|
-
/** Callback invoked when confirm button is clicked */
|
|
190
|
-
onConfirm: PropTypes.func,
|
|
191
|
-
/** Callback invoked when cancel button is clicked, or clicked outside open popover */
|
|
192
|
-
onCancel: PropTypes.func,
|
|
193
|
-
/** Whether confirm and cancel actions should also close the popover in uncontrolled mode */
|
|
194
|
-
closeOnAnyAction: PropTypes.bool,
|
|
195
|
-
/** Whether cancel action is triggered on click outside of the popover */
|
|
196
|
-
cancelOnOuterAction: PropTypes.bool,
|
|
197
|
-
/** Text for confirm button */
|
|
198
|
-
confirmLabel: PropTypes.string.isRequired,
|
|
199
|
-
/** Text for cancel button */
|
|
200
|
-
cancelLabel: PropTypes.string.isRequired,
|
|
201
|
-
/** Object that will be spread into confirm button props */
|
|
202
|
-
confirmButtonProps: PropTypes.shape(Button.propTypes),
|
|
203
|
-
/** Object that will be spread into cancel button props */
|
|
204
|
-
cancelButtonProps: PropTypes.shape(Button.propTypes),
|
|
205
|
-
/** Popover position as string or function (see `Popover`'s `getPopovePosition` prop) */
|
|
206
|
-
popoverPosition: Popover.propTypes && Popover.propTypes.getPopoverPosition,
|
|
207
|
-
/** DOM element to append popover to. (see `Popover`'s `getContainerElement` prop)*/
|
|
208
|
-
getContainerElement: Popover.propTypes && Popover.propTypes.getContainerElement
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
Confirmation.defaultProps = {
|
|
212
|
-
kind: 'second',
|
|
213
|
-
confirmLabel: 'OK',
|
|
214
|
-
cancelLabel: 'Cancel',
|
|
215
|
-
closeOnAnyAction: true,
|
|
216
|
-
cancelOnOuterAction: true,
|
|
217
|
-
confirmButtonProps: {},
|
|
218
|
-
cancelButtonProps: {},
|
|
219
|
-
popoverPosition: 'bottomLeft'
|
|
220
|
-
}
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import classNames from 'classnames'
|
|
4
|
+
import {Button} from '@targetprocess/button'
|
|
5
|
+
import * as CssAccessorsWithFallback from '@targetprocess/css-variables'
|
|
6
|
+
import {Popover} from '@targetprocess/popover'
|
|
7
|
+
|
|
8
|
+
import styles from './style/index.css'
|
|
9
|
+
|
|
10
|
+
function uppercaseFirst(input) {
|
|
11
|
+
if (typeof input !== 'string' || input.length === 0) {
|
|
12
|
+
return input
|
|
13
|
+
}
|
|
14
|
+
return input.slice(0, 1).toUpperCase() + input.slice(1)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const ConfirmationBody = ({
|
|
18
|
+
icon,
|
|
19
|
+
kind = 'second',
|
|
20
|
+
text,
|
|
21
|
+
description,
|
|
22
|
+
confirmButtonProps,
|
|
23
|
+
cancelButtonProps,
|
|
24
|
+
onConfirm,
|
|
25
|
+
onCancel,
|
|
26
|
+
confirmLabel,
|
|
27
|
+
cancelLabel
|
|
28
|
+
}) => (
|
|
29
|
+
<Popover.Body>
|
|
30
|
+
<div className={classNames(styles['confirmation'])}>
|
|
31
|
+
{icon && (
|
|
32
|
+
<div
|
|
33
|
+
className={classNames(styles['confirmation__icon'])}
|
|
34
|
+
style={{
|
|
35
|
+
backgroundColor:
|
|
36
|
+
CssAccessorsWithFallback[`${uppercaseFirst(kind)}100`] ||
|
|
37
|
+
CssAccessorsWithFallback.Second100
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
{React.isValidElement(icon) && icon.type
|
|
41
|
+
? React.createElement(icon.type, {
|
|
42
|
+
color:
|
|
43
|
+
CssAccessorsWithFallback[`${uppercaseFirst(kind)}500`] ||
|
|
44
|
+
CssAccessorsWithFallback.Second500,
|
|
45
|
+
...icon.props
|
|
46
|
+
})
|
|
47
|
+
: icon}
|
|
48
|
+
</div>
|
|
49
|
+
)}
|
|
50
|
+
<div className={styles['confirmation__inner']}>
|
|
51
|
+
<div
|
|
52
|
+
className={classNames(
|
|
53
|
+
styles['confirmation__text'],
|
|
54
|
+
description && styles['confirmation__text--detailed']
|
|
55
|
+
)}
|
|
56
|
+
>
|
|
57
|
+
{text}
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
{description && (
|
|
61
|
+
<div className={classNames(styles['confirmation__description'])}>{description}</div>
|
|
62
|
+
)}
|
|
63
|
+
|
|
64
|
+
<div className={classNames(styles['confirmation__controls'])}>
|
|
65
|
+
<div className={classNames(styles['confirmation__controls__item'])}>
|
|
66
|
+
<Button kind={kind} {...confirmButtonProps} onClick={onConfirm}>
|
|
67
|
+
{confirmLabel}
|
|
68
|
+
</Button>
|
|
69
|
+
</div>
|
|
70
|
+
<div className={classNames(styles['confirmation__controls__item'])}>
|
|
71
|
+
<Button {...cancelButtonProps} onClick={onCancel}>
|
|
72
|
+
{cancelLabel}
|
|
73
|
+
</Button>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</Popover.Body>
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Confirmation can be used to display any kind of confirmation pop-up
|
|
83
|
+
* as popover with styled content and confirm and cancel buttons.
|
|
84
|
+
*
|
|
85
|
+
* In controlled mode, popover display can be adjusted with `isOpen` prop.
|
|
86
|
+
* In this mode, you are also responsible for closing the popover whenever
|
|
87
|
+
* any of the actions occur, if necessary:
|
|
88
|
+
* ```jsx
|
|
89
|
+
* <Confirmation
|
|
90
|
+
* text="Are you sure?"
|
|
91
|
+
* isOpen={this.state.isOpen}
|
|
92
|
+
* onCancel={() => this.setState({isOpen: false})}
|
|
93
|
+
* >
|
|
94
|
+
* <Button onClick={() => this.setState({isOpen: true})}>Delete</Button>
|
|
95
|
+
* </Confirmation>
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* In uncontrolled mode, you can use render prop children to determine
|
|
99
|
+
* whether confirmation is open, and to open or close it. In this mode,
|
|
100
|
+
* popover is opened by setOpened(true) from render callback. It is closed
|
|
101
|
+
* automatically whenever `onConfirm` or `onCancel` are to be invoked, this can
|
|
102
|
+
* be prevented by setting `closeOnAnyAction` to `false`.
|
|
103
|
+
* Clicking outside the popover is equivalent to clicking cancel button, this can
|
|
104
|
+
* be prevented by setting `cancelOnOuterAction` to `false`.
|
|
105
|
+
*
|
|
106
|
+
* ```jsx
|
|
107
|
+
* <Confirmation text="Are you sure?" onConfirm={doSomethingUseful}>
|
|
108
|
+
* {({isOpen, setOpened}) => (
|
|
109
|
+
* <Button onClick={() => setOpened(!isOpen)}>Do something</Button>
|
|
110
|
+
* )}
|
|
111
|
+
* </Confirmation>
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* `text` property is a user prompt and is the only required field for confirmation.
|
|
115
|
+
* You can optionally include `description`, in which case `text` becomes a header and
|
|
116
|
+
* `description` is displayed as dimmed text below.
|
|
117
|
+
*
|
|
118
|
+
* You can also provide an `icon` that will be displayed to the left in a circle.
|
|
119
|
+
* Its `color` prop, if not present, will be overriden (via `cloneElement`) to the
|
|
120
|
+
* color of the appropriate confirmation `kind`.
|
|
121
|
+
*
|
|
122
|
+
* `kind` adjusts confirm button color, icon color and icon backdrop color. Any palette
|
|
123
|
+
* name is supported (i.e. `primary`, `danger`, etc.).
|
|
124
|
+
*
|
|
125
|
+
* `confirmButtonProps` and `cancelButtonProps` can be used to fine-tune individual button
|
|
126
|
+
* display, if necessary.
|
|
127
|
+
*/
|
|
128
|
+
export class Confirmation extends React.Component {
|
|
129
|
+
onConfirm = () => {
|
|
130
|
+
if (this.props.onConfirm) {
|
|
131
|
+
this.props.onConfirm()
|
|
132
|
+
}
|
|
133
|
+
if (this.props.closeOnAnyAction && this.setOpened) {
|
|
134
|
+
this.setOpened(false)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
onCancel = () => {
|
|
139
|
+
if (this.props.onCancel) {
|
|
140
|
+
this.props.onCancel()
|
|
141
|
+
}
|
|
142
|
+
if (this.props.closeOnAnyAction && this.setOpened) {
|
|
143
|
+
this.setOpened(false)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
render() {
|
|
148
|
+
const {
|
|
149
|
+
isOpen: popoverOpen,
|
|
150
|
+
children,
|
|
151
|
+
popoverPosition,
|
|
152
|
+
cancelOnOuterAction,
|
|
153
|
+
getContainerElement,
|
|
154
|
+
...otherProps
|
|
155
|
+
} = this.props
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<Popover
|
|
159
|
+
isOpen={popoverOpen}
|
|
160
|
+
getPopoverPosition={popoverPosition}
|
|
161
|
+
getContainerElement={getContainerElement}
|
|
162
|
+
body={
|
|
163
|
+
<ConfirmationBody {...otherProps} onConfirm={this.onConfirm} onCancel={this.onCancel} />
|
|
164
|
+
}
|
|
165
|
+
onOuterAction={cancelOnOuterAction ? this.onCancel : this.props.onOuterAction}
|
|
166
|
+
zIndex={this.props.zIndex}
|
|
167
|
+
showTip
|
|
168
|
+
>
|
|
169
|
+
{({isOpen, setOpened}) => {
|
|
170
|
+
this.setOpened = setOpened
|
|
171
|
+
return typeof children === 'function' ? children({isOpen, setOpened}) : children
|
|
172
|
+
}}
|
|
173
|
+
</Popover>
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
Confirmation.propTypes = {
|
|
179
|
+
/** Whether the popover is currently open in controlled mode, undefined for uncontrolled mode */
|
|
180
|
+
isOpen: PropTypes.bool,
|
|
181
|
+
/** Color palette that is used for icon and confirm button */
|
|
182
|
+
kind: PropTypes.string,
|
|
183
|
+
/** Icon element (any SVG but `@targetprocess/icons` is preferred) */
|
|
184
|
+
icon: PropTypes.element,
|
|
185
|
+
/** Confirmation text */
|
|
186
|
+
text: PropTypes.node.isRequired,
|
|
187
|
+
/** Optional confirmation description */
|
|
188
|
+
description: PropTypes.node,
|
|
189
|
+
/** Callback invoked when confirm button is clicked */
|
|
190
|
+
onConfirm: PropTypes.func,
|
|
191
|
+
/** Callback invoked when cancel button is clicked, or clicked outside open popover */
|
|
192
|
+
onCancel: PropTypes.func,
|
|
193
|
+
/** Whether confirm and cancel actions should also close the popover in uncontrolled mode */
|
|
194
|
+
closeOnAnyAction: PropTypes.bool,
|
|
195
|
+
/** Whether cancel action is triggered on click outside of the popover */
|
|
196
|
+
cancelOnOuterAction: PropTypes.bool,
|
|
197
|
+
/** Text for confirm button */
|
|
198
|
+
confirmLabel: PropTypes.string.isRequired,
|
|
199
|
+
/** Text for cancel button */
|
|
200
|
+
cancelLabel: PropTypes.string.isRequired,
|
|
201
|
+
/** Object that will be spread into confirm button props */
|
|
202
|
+
confirmButtonProps: PropTypes.shape(Button.propTypes),
|
|
203
|
+
/** Object that will be spread into cancel button props */
|
|
204
|
+
cancelButtonProps: PropTypes.shape(Button.propTypes),
|
|
205
|
+
/** Popover position as string or function (see `Popover`'s `getPopovePosition` prop) */
|
|
206
|
+
popoverPosition: Popover.propTypes && Popover.propTypes.getPopoverPosition,
|
|
207
|
+
/** DOM element to append popover to. (see `Popover`'s `getContainerElement` prop)*/
|
|
208
|
+
getContainerElement: Popover.propTypes && Popover.propTypes.getContainerElement
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
Confirmation.defaultProps = {
|
|
212
|
+
kind: 'second',
|
|
213
|
+
confirmLabel: 'OK',
|
|
214
|
+
cancelLabel: 'Cancel',
|
|
215
|
+
closeOnAnyAction: true,
|
|
216
|
+
cancelOnOuterAction: true,
|
|
217
|
+
confirmButtonProps: {},
|
|
218
|
+
cancelButtonProps: {},
|
|
219
|
+
popoverPosition: 'bottomLeft'
|
|
220
|
+
}
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
/* eslint-env jest */
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import {mount} from 'enzyme'
|
|
4
|
-
import {Confirmation} from '../Confirmation'
|
|
5
|
-
import {Popover} from '@targetprocess/popover'
|
|
6
|
-
|
|
7
|
-
jest.mock('focus-trap', () => {
|
|
8
|
-
const trap = {
|
|
9
|
-
activate: () => trap,
|
|
10
|
-
deactivate: () => trap,
|
|
11
|
-
pause: () => {},
|
|
12
|
-
unpause: () => {}
|
|
13
|
-
}
|
|
14
|
-
return () => trap
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
describe('Confirmation', () => {
|
|
18
|
-
it('should render any children as pass-through', () => {
|
|
19
|
-
const wrapper = mount(
|
|
20
|
-
<Confirmation text="test">
|
|
21
|
-
<div className="child" />
|
|
22
|
-
</Confirmation>
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
expect(wrapper.find('.child')).toHaveLength(1)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('should work with render props and trigger correct events', () =>
|
|
29
|
-
Promise.all(
|
|
30
|
-
[true, false].map(async closeOnAnyAction => {
|
|
31
|
-
// beforeEach won't work here because this is a single test with 2 cases
|
|
32
|
-
document.body.innerHTML = ''
|
|
33
|
-
|
|
34
|
-
const onConfirmMock = jest.fn()
|
|
35
|
-
const onCancelMock = jest.fn()
|
|
36
|
-
const wrapper = mount(
|
|
37
|
-
<Confirmation
|
|
38
|
-
text="test"
|
|
39
|
-
onConfirm={onConfirmMock}
|
|
40
|
-
onCancel={onCancelMock}
|
|
41
|
-
body={<Popover.Body />}
|
|
42
|
-
confirmButtonProps={{className: 'confirm'}}
|
|
43
|
-
cancelButtonProps={{className: 'cancel'}}
|
|
44
|
-
closeOnAnyAction={closeOnAnyAction}
|
|
45
|
-
>
|
|
46
|
-
{({setOpened, isOpen}) => <button onClick={() => setOpened(!isOpen)}>open</button>}
|
|
47
|
-
</Confirmation>
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
expect(document.body.querySelectorAll('.popover-body')).toHaveLength(0)
|
|
51
|
-
wrapper.find('button').simulate('click')
|
|
52
|
-
// since react fiber actual popover rendering will be delayed
|
|
53
|
-
await new Promise(resolve => setTimeout(resolve, 100))
|
|
54
|
-
expect(document.body.querySelectorAll('.popover-body')).toHaveLength(1)
|
|
55
|
-
})
|
|
56
|
-
))
|
|
57
|
-
|
|
58
|
-
it('should call onCancel on outside click unless overriden', () =>
|
|
59
|
-
[true, false].forEach(cancelOnOuterAction => {
|
|
60
|
-
// beforeEach won't work here because this is a single test with 2 cases
|
|
61
|
-
document.body.innerHTML = ''
|
|
62
|
-
const onCancelMock = jest.fn()
|
|
63
|
-
const wrapper = mount(
|
|
64
|
-
<Confirmation
|
|
65
|
-
cancelOnOuterAction={cancelOnOuterAction}
|
|
66
|
-
text="test"
|
|
67
|
-
onCancel={onCancelMock}
|
|
68
|
-
body={<Popover.Body />}
|
|
69
|
-
>
|
|
70
|
-
{({setOpened, isOpen}) => <button onClick={() => setOpened(!isOpen)}>open</button>}
|
|
71
|
-
</Confirmation>
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
expect(document.body.querySelectorAll('.popover-body')).toHaveLength(0)
|
|
75
|
-
wrapper.find('button').simulate('click')
|
|
76
|
-
expect(document.body.querySelectorAll('.popover-body')).toHaveLength(1)
|
|
77
|
-
}))
|
|
78
|
-
})
|
|
1
|
+
/* eslint-env jest */
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import {mount} from 'enzyme'
|
|
4
|
+
import {Confirmation} from '../Confirmation'
|
|
5
|
+
import {Popover} from '@targetprocess/popover'
|
|
6
|
+
|
|
7
|
+
jest.mock('focus-trap', () => {
|
|
8
|
+
const trap = {
|
|
9
|
+
activate: () => trap,
|
|
10
|
+
deactivate: () => trap,
|
|
11
|
+
pause: () => {},
|
|
12
|
+
unpause: () => {}
|
|
13
|
+
}
|
|
14
|
+
return () => trap
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('Confirmation', () => {
|
|
18
|
+
it('should render any children as pass-through', () => {
|
|
19
|
+
const wrapper = mount(
|
|
20
|
+
<Confirmation text="test">
|
|
21
|
+
<div className="child" />
|
|
22
|
+
</Confirmation>
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
expect(wrapper.find('.child')).toHaveLength(1)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('should work with render props and trigger correct events', () =>
|
|
29
|
+
Promise.all(
|
|
30
|
+
[true, false].map(async closeOnAnyAction => {
|
|
31
|
+
// beforeEach won't work here because this is a single test with 2 cases
|
|
32
|
+
document.body.innerHTML = ''
|
|
33
|
+
|
|
34
|
+
const onConfirmMock = jest.fn()
|
|
35
|
+
const onCancelMock = jest.fn()
|
|
36
|
+
const wrapper = mount(
|
|
37
|
+
<Confirmation
|
|
38
|
+
text="test"
|
|
39
|
+
onConfirm={onConfirmMock}
|
|
40
|
+
onCancel={onCancelMock}
|
|
41
|
+
body={<Popover.Body />}
|
|
42
|
+
confirmButtonProps={{className: 'confirm'}}
|
|
43
|
+
cancelButtonProps={{className: 'cancel'}}
|
|
44
|
+
closeOnAnyAction={closeOnAnyAction}
|
|
45
|
+
>
|
|
46
|
+
{({setOpened, isOpen}) => <button onClick={() => setOpened(!isOpen)}>open</button>}
|
|
47
|
+
</Confirmation>
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
expect(document.body.querySelectorAll('.popover-body')).toHaveLength(0)
|
|
51
|
+
wrapper.find('button').simulate('click')
|
|
52
|
+
// since react fiber actual popover rendering will be delayed
|
|
53
|
+
await new Promise(resolve => setTimeout(resolve, 100))
|
|
54
|
+
expect(document.body.querySelectorAll('.popover-body')).toHaveLength(1)
|
|
55
|
+
})
|
|
56
|
+
))
|
|
57
|
+
|
|
58
|
+
it('should call onCancel on outside click unless overriden', () =>
|
|
59
|
+
[true, false].forEach(cancelOnOuterAction => {
|
|
60
|
+
// beforeEach won't work here because this is a single test with 2 cases
|
|
61
|
+
document.body.innerHTML = ''
|
|
62
|
+
const onCancelMock = jest.fn()
|
|
63
|
+
const wrapper = mount(
|
|
64
|
+
<Confirmation
|
|
65
|
+
cancelOnOuterAction={cancelOnOuterAction}
|
|
66
|
+
text="test"
|
|
67
|
+
onCancel={onCancelMock}
|
|
68
|
+
body={<Popover.Body />}
|
|
69
|
+
>
|
|
70
|
+
{({setOpened, isOpen}) => <button onClick={() => setOpened(!isOpen)}>open</button>}
|
|
71
|
+
</Confirmation>
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
expect(document.body.querySelectorAll('.popover-body')).toHaveLength(0)
|
|
75
|
+
wrapper.find('button').simulate('click')
|
|
76
|
+
expect(document.body.querySelectorAll('.popover-body')).toHaveLength(1)
|
|
77
|
+
}))
|
|
78
|
+
})
|
package/dist/confirmation.es.js
CHANGED
|
@@ -167,8 +167,8 @@ function styleInject(css, ref) {
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
var css = ".confirmation__confirmation__12-20-
|
|
171
|
-
var styles = {"confirmation":"confirmation__confirmation__12-20-
|
|
170
|
+
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.confirmation__confirmation__12-20-2-alpha-0 {\n min-width: 200px;\n max-width: 280px;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: start;\n -ms-flex-align: start;\n align-items: flex-start;\n}\n.confirmation__icon__confirmation__12-20-2-alpha-0 {\n -webkit-box-flex: 0;\n -ms-flex: 0 0 auto;\n flex: 0 0 auto;\n margin-right: var(--SpaceSM, 12px);\n border-radius: 50%;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n width: var(--ControlHeightDefault, 24px);\n height: var(--ControlHeightDefault, 24px);\n }\n.confirmation__inner__confirmation__12-20-2-alpha-0 {\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n }\n.confirmation__text__confirmation__12-20-2-alpha-0 {\n margin-bottom: var(--SpaceM, 16px);\n line-height: 1.23;\n }\n.confirmation__text--detailed__confirmation__12-20-2-alpha-0 {\n font-weight: var(--FontWeightSemibold, 600);\n line-height: 1.23;\n font-size: var(--FontSizeTitleSubsection, 16px);\n margin: var(--SpaceXS, 4px) 0 var(--SpaceS, 8px) 0;\n min-width: 200px;\n }\n.confirmation__description__confirmation__12-20-2-alpha-0 {\n margin-bottom: var(--SpaceM, 16px);\n line-height: 1.23;\n color: var(--FontColorGray, rgba(0, 0, 0, 0.7));\n }\n.confirmation__controls__confirmation__12-20-2-alpha-0 {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n margin-bottom: var(--SpaceXS, 4px);\n }\n.confirmation__controls__item__confirmation__12-20-2-alpha-0:not(:last-child) {\n margin-right: var(--SpaceS, 8px);\n }\n";
|
|
171
|
+
var styles = {"confirmation":"confirmation__confirmation__12-20-2-alpha-0","confirmation__icon":"confirmation__icon__confirmation__12-20-2-alpha-0","confirmation__inner":"confirmation__inner__confirmation__12-20-2-alpha-0","confirmation__text":"confirmation__text__confirmation__12-20-2-alpha-0","confirmation__text--detailed":"confirmation__text--detailed__confirmation__12-20-2-alpha-0","confirmation__description":"confirmation__description__confirmation__12-20-2-alpha-0","confirmation__controls":"confirmation__controls__confirmation__12-20-2-alpha-0","confirmation__controls__item":"confirmation__controls__item__confirmation__12-20-2-alpha-0"};
|
|
172
172
|
styleInject(css);
|
|
173
173
|
|
|
174
174
|
function uppercaseFirst(input) {
|
|
@@ -219,52 +219,52 @@ var ConfirmationBody = function ConfirmationBody(_ref) {
|
|
|
219
219
|
}), cancelLabel))))));
|
|
220
220
|
};
|
|
221
221
|
|
|
222
|
-
/**
|
|
223
|
-
* Confirmation can be used to display any kind of confirmation pop-up
|
|
224
|
-
* as popover with styled content and confirm and cancel buttons.
|
|
225
|
-
*
|
|
226
|
-
* In controlled mode, popover display can be adjusted with `isOpen` prop.
|
|
227
|
-
* In this mode, you are also responsible for closing the popover whenever
|
|
228
|
-
* any of the actions occur, if necessary:
|
|
229
|
-
* ```jsx
|
|
230
|
-
* <Confirmation
|
|
231
|
-
* text="Are you sure?"
|
|
232
|
-
* isOpen={this.state.isOpen}
|
|
233
|
-
* onCancel={() => this.setState({isOpen: false})}
|
|
234
|
-
* >
|
|
235
|
-
* <Button onClick={() => this.setState({isOpen: true})}>Delete</Button>
|
|
236
|
-
* </Confirmation>
|
|
237
|
-
* ```
|
|
238
|
-
*
|
|
239
|
-
* In uncontrolled mode, you can use render prop children to determine
|
|
240
|
-
* whether confirmation is open, and to open or close it. In this mode,
|
|
241
|
-
* popover is opened by setOpened(true) from render callback. It is closed
|
|
242
|
-
* automatically whenever `onConfirm` or `onCancel` are to be invoked, this can
|
|
243
|
-
* be prevented by setting `closeOnAnyAction` to `false`.
|
|
244
|
-
* Clicking outside the popover is equivalent to clicking cancel button, this can
|
|
245
|
-
* be prevented by setting `cancelOnOuterAction` to `false`.
|
|
246
|
-
*
|
|
247
|
-
* ```jsx
|
|
248
|
-
* <Confirmation text="Are you sure?" onConfirm={doSomethingUseful}>
|
|
249
|
-
* {({isOpen, setOpened}) => (
|
|
250
|
-
* <Button onClick={() => setOpened(!isOpen)}>Do something</Button>
|
|
251
|
-
* )}
|
|
252
|
-
* </Confirmation>
|
|
253
|
-
* ```
|
|
254
|
-
*
|
|
255
|
-
* `text` property is a user prompt and is the only required field for confirmation.
|
|
256
|
-
* You can optionally include `description`, in which case `text` becomes a header and
|
|
257
|
-
* `description` is displayed as dimmed text below.
|
|
258
|
-
*
|
|
259
|
-
* You can also provide an `icon` that will be displayed to the left in a circle.
|
|
260
|
-
* Its `color` prop, if not present, will be overriden (via `cloneElement`) to the
|
|
261
|
-
* color of the appropriate confirmation `kind`.
|
|
262
|
-
*
|
|
263
|
-
* `kind` adjusts confirm button color, icon color and icon backdrop color. Any palette
|
|
264
|
-
* name is supported (i.e. `primary`, `danger`, etc.).
|
|
265
|
-
*
|
|
266
|
-
* `confirmButtonProps` and `cancelButtonProps` can be used to fine-tune individual button
|
|
267
|
-
* display, if necessary.
|
|
222
|
+
/**
|
|
223
|
+
* Confirmation can be used to display any kind of confirmation pop-up
|
|
224
|
+
* as popover with styled content and confirm and cancel buttons.
|
|
225
|
+
*
|
|
226
|
+
* In controlled mode, popover display can be adjusted with `isOpen` prop.
|
|
227
|
+
* In this mode, you are also responsible for closing the popover whenever
|
|
228
|
+
* any of the actions occur, if necessary:
|
|
229
|
+
* ```jsx
|
|
230
|
+
* <Confirmation
|
|
231
|
+
* text="Are you sure?"
|
|
232
|
+
* isOpen={this.state.isOpen}
|
|
233
|
+
* onCancel={() => this.setState({isOpen: false})}
|
|
234
|
+
* >
|
|
235
|
+
* <Button onClick={() => this.setState({isOpen: true})}>Delete</Button>
|
|
236
|
+
* </Confirmation>
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* In uncontrolled mode, you can use render prop children to determine
|
|
240
|
+
* whether confirmation is open, and to open or close it. In this mode,
|
|
241
|
+
* popover is opened by setOpened(true) from render callback. It is closed
|
|
242
|
+
* automatically whenever `onConfirm` or `onCancel` are to be invoked, this can
|
|
243
|
+
* be prevented by setting `closeOnAnyAction` to `false`.
|
|
244
|
+
* Clicking outside the popover is equivalent to clicking cancel button, this can
|
|
245
|
+
* be prevented by setting `cancelOnOuterAction` to `false`.
|
|
246
|
+
*
|
|
247
|
+
* ```jsx
|
|
248
|
+
* <Confirmation text="Are you sure?" onConfirm={doSomethingUseful}>
|
|
249
|
+
* {({isOpen, setOpened}) => (
|
|
250
|
+
* <Button onClick={() => setOpened(!isOpen)}>Do something</Button>
|
|
251
|
+
* )}
|
|
252
|
+
* </Confirmation>
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* `text` property is a user prompt and is the only required field for confirmation.
|
|
256
|
+
* You can optionally include `description`, in which case `text` becomes a header and
|
|
257
|
+
* `description` is displayed as dimmed text below.
|
|
258
|
+
*
|
|
259
|
+
* You can also provide an `icon` that will be displayed to the left in a circle.
|
|
260
|
+
* Its `color` prop, if not present, will be overriden (via `cloneElement`) to the
|
|
261
|
+
* color of the appropriate confirmation `kind`.
|
|
262
|
+
*
|
|
263
|
+
* `kind` adjusts confirm button color, icon color and icon backdrop color. Any palette
|
|
264
|
+
* name is supported (i.e. `primary`, `danger`, etc.).
|
|
265
|
+
*
|
|
266
|
+
* `confirmButtonProps` and `cancelButtonProps` can be used to fine-tune individual button
|
|
267
|
+
* display, if necessary.
|
|
268
268
|
*/
|
|
269
269
|
var Confirmation = /*#__PURE__*/function (_React$Component) {
|
|
270
270
|
_inherits(Confirmation, _React$Component);
|
|
@@ -340,4 +340,8 @@ Confirmation.defaultProps = {
|
|
|
340
340
|
popoverPosition: 'bottomLeft'
|
|
341
341
|
};
|
|
342
342
|
|
|
343
|
+
/*********************************************************************
|
|
344
|
+
* © Copyright IBM Corp. 2024
|
|
345
|
+
*********************************************************************/
|
|
346
|
+
|
|
343
347
|
export { Confirmation };
|
package/dist/confirmation.js
CHANGED
|
@@ -172,8 +172,8 @@ function styleInject(css, ref) {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
var css = ".confirmation__confirmation__12-20-
|
|
176
|
-
var styles = {"confirmation":"confirmation__confirmation__12-20-
|
|
175
|
+
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.confirmation__confirmation__12-20-2-alpha-0 {\n min-width: 200px;\n max-width: 280px;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: start;\n -ms-flex-align: start;\n align-items: flex-start;\n}\n.confirmation__icon__confirmation__12-20-2-alpha-0 {\n -webkit-box-flex: 0;\n -ms-flex: 0 0 auto;\n flex: 0 0 auto;\n margin-right: var(--SpaceSM, 12px);\n border-radius: 50%;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n width: var(--ControlHeightDefault, 24px);\n height: var(--ControlHeightDefault, 24px);\n }\n.confirmation__inner__confirmation__12-20-2-alpha-0 {\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n }\n.confirmation__text__confirmation__12-20-2-alpha-0 {\n margin-bottom: var(--SpaceM, 16px);\n line-height: 1.23;\n }\n.confirmation__text--detailed__confirmation__12-20-2-alpha-0 {\n font-weight: var(--FontWeightSemibold, 600);\n line-height: 1.23;\n font-size: var(--FontSizeTitleSubsection, 16px);\n margin: var(--SpaceXS, 4px) 0 var(--SpaceS, 8px) 0;\n min-width: 200px;\n }\n.confirmation__description__confirmation__12-20-2-alpha-0 {\n margin-bottom: var(--SpaceM, 16px);\n line-height: 1.23;\n color: var(--FontColorGray, rgba(0, 0, 0, 0.7));\n }\n.confirmation__controls__confirmation__12-20-2-alpha-0 {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n margin-bottom: var(--SpaceXS, 4px);\n }\n.confirmation__controls__item__confirmation__12-20-2-alpha-0:not(:last-child) {\n margin-right: var(--SpaceS, 8px);\n }\n";
|
|
176
|
+
var styles = {"confirmation":"confirmation__confirmation__12-20-2-alpha-0","confirmation__icon":"confirmation__icon__confirmation__12-20-2-alpha-0","confirmation__inner":"confirmation__inner__confirmation__12-20-2-alpha-0","confirmation__text":"confirmation__text__confirmation__12-20-2-alpha-0","confirmation__text--detailed":"confirmation__text--detailed__confirmation__12-20-2-alpha-0","confirmation__description":"confirmation__description__confirmation__12-20-2-alpha-0","confirmation__controls":"confirmation__controls__confirmation__12-20-2-alpha-0","confirmation__controls__item":"confirmation__controls__item__confirmation__12-20-2-alpha-0"};
|
|
177
177
|
styleInject(css);
|
|
178
178
|
|
|
179
179
|
function uppercaseFirst(input) {
|
|
@@ -224,52 +224,52 @@ var ConfirmationBody = function ConfirmationBody(_ref) {
|
|
|
224
224
|
}), cancelLabel))))));
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
-
/**
|
|
228
|
-
* Confirmation can be used to display any kind of confirmation pop-up
|
|
229
|
-
* as popover with styled content and confirm and cancel buttons.
|
|
230
|
-
*
|
|
231
|
-
* In controlled mode, popover display can be adjusted with `isOpen` prop.
|
|
232
|
-
* In this mode, you are also responsible for closing the popover whenever
|
|
233
|
-
* any of the actions occur, if necessary:
|
|
234
|
-
* ```jsx
|
|
235
|
-
* <Confirmation
|
|
236
|
-
* text="Are you sure?"
|
|
237
|
-
* isOpen={this.state.isOpen}
|
|
238
|
-
* onCancel={() => this.setState({isOpen: false})}
|
|
239
|
-
* >
|
|
240
|
-
* <Button onClick={() => this.setState({isOpen: true})}>Delete</Button>
|
|
241
|
-
* </Confirmation>
|
|
242
|
-
* ```
|
|
243
|
-
*
|
|
244
|
-
* In uncontrolled mode, you can use render prop children to determine
|
|
245
|
-
* whether confirmation is open, and to open or close it. In this mode,
|
|
246
|
-
* popover is opened by setOpened(true) from render callback. It is closed
|
|
247
|
-
* automatically whenever `onConfirm` or `onCancel` are to be invoked, this can
|
|
248
|
-
* be prevented by setting `closeOnAnyAction` to `false`.
|
|
249
|
-
* Clicking outside the popover is equivalent to clicking cancel button, this can
|
|
250
|
-
* be prevented by setting `cancelOnOuterAction` to `false`.
|
|
251
|
-
*
|
|
252
|
-
* ```jsx
|
|
253
|
-
* <Confirmation text="Are you sure?" onConfirm={doSomethingUseful}>
|
|
254
|
-
* {({isOpen, setOpened}) => (
|
|
255
|
-
* <Button onClick={() => setOpened(!isOpen)}>Do something</Button>
|
|
256
|
-
* )}
|
|
257
|
-
* </Confirmation>
|
|
258
|
-
* ```
|
|
259
|
-
*
|
|
260
|
-
* `text` property is a user prompt and is the only required field for confirmation.
|
|
261
|
-
* You can optionally include `description`, in which case `text` becomes a header and
|
|
262
|
-
* `description` is displayed as dimmed text below.
|
|
263
|
-
*
|
|
264
|
-
* You can also provide an `icon` that will be displayed to the left in a circle.
|
|
265
|
-
* Its `color` prop, if not present, will be overriden (via `cloneElement`) to the
|
|
266
|
-
* color of the appropriate confirmation `kind`.
|
|
267
|
-
*
|
|
268
|
-
* `kind` adjusts confirm button color, icon color and icon backdrop color. Any palette
|
|
269
|
-
* name is supported (i.e. `primary`, `danger`, etc.).
|
|
270
|
-
*
|
|
271
|
-
* `confirmButtonProps` and `cancelButtonProps` can be used to fine-tune individual button
|
|
272
|
-
* display, if necessary.
|
|
227
|
+
/**
|
|
228
|
+
* Confirmation can be used to display any kind of confirmation pop-up
|
|
229
|
+
* as popover with styled content and confirm and cancel buttons.
|
|
230
|
+
*
|
|
231
|
+
* In controlled mode, popover display can be adjusted with `isOpen` prop.
|
|
232
|
+
* In this mode, you are also responsible for closing the popover whenever
|
|
233
|
+
* any of the actions occur, if necessary:
|
|
234
|
+
* ```jsx
|
|
235
|
+
* <Confirmation
|
|
236
|
+
* text="Are you sure?"
|
|
237
|
+
* isOpen={this.state.isOpen}
|
|
238
|
+
* onCancel={() => this.setState({isOpen: false})}
|
|
239
|
+
* >
|
|
240
|
+
* <Button onClick={() => this.setState({isOpen: true})}>Delete</Button>
|
|
241
|
+
* </Confirmation>
|
|
242
|
+
* ```
|
|
243
|
+
*
|
|
244
|
+
* In uncontrolled mode, you can use render prop children to determine
|
|
245
|
+
* whether confirmation is open, and to open or close it. In this mode,
|
|
246
|
+
* popover is opened by setOpened(true) from render callback. It is closed
|
|
247
|
+
* automatically whenever `onConfirm` or `onCancel` are to be invoked, this can
|
|
248
|
+
* be prevented by setting `closeOnAnyAction` to `false`.
|
|
249
|
+
* Clicking outside the popover is equivalent to clicking cancel button, this can
|
|
250
|
+
* be prevented by setting `cancelOnOuterAction` to `false`.
|
|
251
|
+
*
|
|
252
|
+
* ```jsx
|
|
253
|
+
* <Confirmation text="Are you sure?" onConfirm={doSomethingUseful}>
|
|
254
|
+
* {({isOpen, setOpened}) => (
|
|
255
|
+
* <Button onClick={() => setOpened(!isOpen)}>Do something</Button>
|
|
256
|
+
* )}
|
|
257
|
+
* </Confirmation>
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
260
|
+
* `text` property is a user prompt and is the only required field for confirmation.
|
|
261
|
+
* You can optionally include `description`, in which case `text` becomes a header and
|
|
262
|
+
* `description` is displayed as dimmed text below.
|
|
263
|
+
*
|
|
264
|
+
* You can also provide an `icon` that will be displayed to the left in a circle.
|
|
265
|
+
* Its `color` prop, if not present, will be overriden (via `cloneElement`) to the
|
|
266
|
+
* color of the appropriate confirmation `kind`.
|
|
267
|
+
*
|
|
268
|
+
* `kind` adjusts confirm button color, icon color and icon backdrop color. Any palette
|
|
269
|
+
* name is supported (i.e. `primary`, `danger`, etc.).
|
|
270
|
+
*
|
|
271
|
+
* `confirmButtonProps` and `cancelButtonProps` can be used to fine-tune individual button
|
|
272
|
+
* display, if necessary.
|
|
273
273
|
*/
|
|
274
274
|
var Confirmation = /*#__PURE__*/function (_React$Component) {
|
|
275
275
|
_inherits(Confirmation, _React$Component);
|
|
@@ -345,4 +345,8 @@ Confirmation.defaultProps = {
|
|
|
345
345
|
popoverPosition: 'bottomLeft'
|
|
346
346
|
};
|
|
347
347
|
|
|
348
|
+
/*********************************************************************
|
|
349
|
+
* © Copyright IBM Corp. 2024
|
|
350
|
+
*********************************************************************/
|
|
351
|
+
|
|
348
352
|
exports.Confirmation = Confirmation;
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@targetprocess/confirmation",
|
|
3
|
-
"version": "12.20.
|
|
3
|
+
"version": "12.20.2-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/confirmation.js",
|
|
6
6
|
"module": "dist/confirmation.es.js",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"prepack": "node -r ../../.ts-node.js ../../config/rollup.config.js ."
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@targetprocess/button": "^12.20.
|
|
14
|
-
"@targetprocess/css-variables": "^12.
|
|
15
|
-
"@targetprocess/popover": "^12.20.
|
|
13
|
+
"@targetprocess/button": "^12.20.2-alpha.0",
|
|
14
|
+
"@targetprocess/css-variables": "^12.20.2-alpha.0",
|
|
15
|
+
"@targetprocess/popover": "^12.20.2-alpha.0",
|
|
16
16
|
"classnames": "^2.2.5",
|
|
17
17
|
"prop-types": "^15.6.0",
|
|
18
18
|
"react": "^16.7.0"
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"sideEffects": false,
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "58801cfa426dcee4f34922ebc0e9cfa8fbd52735"
|
|
25
25
|
}
|
package/style/index.css
CHANGED
|
@@ -1,50 +1,53 @@
|
|
|
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
|
-
|
|
1
|
+
/*********************************************************************
|
|
2
|
+
* © Copyright IBM Corp. 2024
|
|
3
|
+
*********************************************************************/
|
|
4
|
+
.confirmation {
|
|
5
|
+
min-width: 200px;
|
|
6
|
+
max-width: 280px;
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: flex-start;
|
|
9
|
+
|
|
10
|
+
&__icon {
|
|
11
|
+
flex: 0 0 auto;
|
|
12
|
+
margin-right: $gSpaceSM;
|
|
13
|
+
border-radius: 50%;
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
width: $gControlHeightDefault;
|
|
18
|
+
height: $gControlHeightDefault;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&__inner {
|
|
22
|
+
flex: 1 1 auto;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&__text {
|
|
26
|
+
margin-bottom: $gSpaceM;
|
|
27
|
+
line-height: 1.23;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&__text--detailed {
|
|
31
|
+
font-weight: $gFontWeightSemibold;
|
|
32
|
+
line-height: 1.23;
|
|
33
|
+
font-size: $gFontSizeTitleSubsection;
|
|
34
|
+
margin: $gSpaceXS 0 $gSpaceS 0;
|
|
35
|
+
min-width: 200px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&__description {
|
|
39
|
+
margin-bottom: $gSpaceM;
|
|
40
|
+
line-height: 1.23;
|
|
41
|
+
color: $gFontColorGray;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&__controls {
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
margin-bottom: $gSpaceXS;
|
|
48
|
+
|
|
49
|
+
&__item:not(:last-child) {
|
|
50
|
+
margin-right: $gSpaceS;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|