sbwb-ds 3.36.0 → 3.36.2
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/README.md +16 -0
- package/dist/index.d.ts +3 -0
- package/dist/sbwb-ds.js +14573 -14331
- package/dist/sbwb-ds.umd.cjs +680 -588
- package/dist/src/presentation/components/molecules/PopConfirm/index.d.ts +6 -1
- package/package.json +1 -1
- package/src/presentation/components/molecules/PopConfirm/PopConfirm.stories.tsx +3 -3
- package/src/presentation/components/molecules/PopConfirm/index.tsx +76 -18
- package/src/presentation/components/molecules/PopConfirm/styles.ts +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { ButtonProps } from '../../atoms/Button';
|
|
2
3
|
export interface PopConfirmProps {
|
|
3
4
|
id?: string;
|
|
4
5
|
children?: React.ReactNode;
|
|
@@ -13,6 +14,10 @@ export interface PopConfirmProps {
|
|
|
13
14
|
wrapperStyles?: React.CSSProperties;
|
|
14
15
|
onClickConfirm?: () => void;
|
|
15
16
|
onClickCancel?: () => void;
|
|
17
|
+
cancelLabel?: React.ReactNode;
|
|
18
|
+
confirmLabel?: React.ReactNode;
|
|
19
|
+
cancelButtonProps?: ButtonProps;
|
|
20
|
+
confirmButtonProps?: ButtonProps;
|
|
16
21
|
}
|
|
17
|
-
declare const PopConfirm: ({ id, children, type, title, text, position, isActive, popConfirmMargin, wrapperWidth, wrapperHeight, wrapperStyles, onClickConfirm, onClickCancel, }: PopConfirmProps) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
declare const PopConfirm: ({ id, children, type, title, text, position, isActive, popConfirmMargin, wrapperWidth, wrapperHeight, wrapperStyles, onClickConfirm, onClickCancel, cancelLabel, confirmLabel, cancelButtonProps, confirmButtonProps, }: PopConfirmProps) => import("react/jsx-runtime").JSX.Element;
|
|
18
23
|
export default PopConfirm;
|
package/package.json
CHANGED
|
@@ -64,9 +64,9 @@ Default.args = {
|
|
|
64
64
|
width: '240px',
|
|
65
65
|
height: 'fit-content',
|
|
66
66
|
type: 'danger',
|
|
67
|
-
title:
|
|
68
|
-
text: '
|
|
67
|
+
title: 'Deletar projeto?',
|
|
68
|
+
text: 'Você tem certeza que deseja deletar este projeto?',
|
|
69
69
|
onClickConfirm: () => {
|
|
70
|
-
alert('
|
|
70
|
+
alert('Confirmado!');
|
|
71
71
|
},
|
|
72
72
|
};
|
|
@@ -2,10 +2,10 @@ import * as C from './styles';
|
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import Icon from '../../atoms/Icon';
|
|
4
4
|
import { sg } from '../../../styles';
|
|
5
|
-
import Button from '../../atoms/Button';
|
|
5
|
+
import Button, { ButtonProps } from '../../atoms/Button';
|
|
6
6
|
import { pxToRem } from '../../../../main/helpers/functions/measurementConverters';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { useCallback, useLayoutEffect, useRef } from 'react';
|
|
9
9
|
|
|
10
10
|
export interface PopConfirmProps {
|
|
11
11
|
id?: string;
|
|
@@ -21,6 +21,10 @@ export interface PopConfirmProps {
|
|
|
21
21
|
wrapperStyles?: React.CSSProperties;
|
|
22
22
|
onClickConfirm?: () => void;
|
|
23
23
|
onClickCancel?: () => void;
|
|
24
|
+
cancelLabel?: React.ReactNode;
|
|
25
|
+
confirmLabel?: React.ReactNode;
|
|
26
|
+
cancelButtonProps?: ButtonProps;
|
|
27
|
+
confirmButtonProps?: ButtonProps;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
const PopConfirm = ({
|
|
@@ -29,7 +33,7 @@ const PopConfirm = ({
|
|
|
29
33
|
type,
|
|
30
34
|
title,
|
|
31
35
|
text,
|
|
32
|
-
position,
|
|
36
|
+
position = 'bottom',
|
|
33
37
|
isActive = true,
|
|
34
38
|
popConfirmMargin = '8px',
|
|
35
39
|
wrapperWidth,
|
|
@@ -37,14 +41,20 @@ const PopConfirm = ({
|
|
|
37
41
|
wrapperStyles,
|
|
38
42
|
onClickConfirm,
|
|
39
43
|
onClickCancel,
|
|
44
|
+
cancelLabel,
|
|
45
|
+
confirmLabel,
|
|
46
|
+
cancelButtonProps,
|
|
47
|
+
confirmButtonProps,
|
|
40
48
|
}: PopConfirmProps) => {
|
|
41
49
|
const targetRef = useRef<HTMLDivElement>(null);
|
|
42
50
|
const popconfirmRef = useRef<HTMLDivElement>(null);
|
|
43
|
-
|
|
51
|
+
|
|
52
|
+
const updatePopConfirmPosition = useCallback(() => {
|
|
44
53
|
if (targetRef.current && popconfirmRef.current) {
|
|
45
54
|
const targetRect = targetRef.current.getBoundingClientRect();
|
|
46
55
|
const popconfirmRect = popconfirmRef.current.getBoundingClientRect();
|
|
47
|
-
const
|
|
56
|
+
const parsedMargin = Number.parseFloat(popConfirmMargin);
|
|
57
|
+
const margin = Number.isFinite(parsedMargin) ? parsedMargin : 0;
|
|
48
58
|
let newStyle: React.CSSProperties = {};
|
|
49
59
|
|
|
50
60
|
switch (position) {
|
|
@@ -83,17 +93,37 @@ const PopConfirm = ({
|
|
|
83
93
|
|
|
84
94
|
Object.assign(popconfirmRef.current.style, newStyle);
|
|
85
95
|
}
|
|
86
|
-
};
|
|
87
|
-
|
|
96
|
+
}, [popConfirmMargin, position]);
|
|
97
|
+
|
|
98
|
+
useLayoutEffect(() => {
|
|
88
99
|
if (isActive) {
|
|
89
100
|
updatePopConfirmPosition();
|
|
90
101
|
window.addEventListener('resize', updatePopConfirmPosition);
|
|
102
|
+
document.addEventListener('scroll', updatePopConfirmPosition, true);
|
|
103
|
+
|
|
104
|
+
const resizeObserver =
|
|
105
|
+
typeof ResizeObserver !== 'undefined'
|
|
106
|
+
? new ResizeObserver(updatePopConfirmPosition)
|
|
107
|
+
: undefined;
|
|
108
|
+
|
|
109
|
+
if (resizeObserver) {
|
|
110
|
+
if (targetRef.current) resizeObserver.observe(targetRef.current);
|
|
111
|
+
if (popconfirmRef.current)
|
|
112
|
+
resizeObserver.observe(popconfirmRef.current);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return () => {
|
|
116
|
+
window.removeEventListener('resize', updatePopConfirmPosition);
|
|
117
|
+
document.removeEventListener('scroll', updatePopConfirmPosition, true);
|
|
118
|
+
resizeObserver?.disconnect();
|
|
119
|
+
};
|
|
91
120
|
}
|
|
92
121
|
|
|
93
122
|
return () => {
|
|
94
123
|
window.removeEventListener('resize', updatePopConfirmPosition);
|
|
124
|
+
document.removeEventListener('scroll', updatePopConfirmPosition, true);
|
|
95
125
|
};
|
|
96
|
-
}, [isActive,
|
|
126
|
+
}, [isActive, updatePopConfirmPosition]);
|
|
97
127
|
|
|
98
128
|
if (!isActive) {
|
|
99
129
|
return <>{children}</>;
|
|
@@ -123,6 +153,17 @@ const PopConfirm = ({
|
|
|
123
153
|
return sg.colors.feedbackColors.colorFeedbackWarning;
|
|
124
154
|
}
|
|
125
155
|
};
|
|
156
|
+
|
|
157
|
+
const handleCancelClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
158
|
+
cancelButtonProps?.onClick?.(event);
|
|
159
|
+
onClickCancel?.();
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const handleConfirmClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
163
|
+
confirmButtonProps?.onClick?.(event);
|
|
164
|
+
onClickConfirm?.();
|
|
165
|
+
};
|
|
166
|
+
|
|
126
167
|
const popConfirmContent = (
|
|
127
168
|
<C.PopconfirmContainer ref={popconfirmRef} position={position}>
|
|
128
169
|
<C.Header>
|
|
@@ -130,26 +171,43 @@ const PopConfirm = ({
|
|
|
130
171
|
<C.Spacing width={sg.spacings.spacingStack.spacingStackXs} />
|
|
131
172
|
<C.Title>{title}</C.Title>
|
|
132
173
|
</C.Header>
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
174
|
+
{text && (
|
|
175
|
+
<>
|
|
176
|
+
<C.Spacing height={sg.spacings.spacingStack.spacingStackXs} />
|
|
177
|
+
<C.Content>{text}</C.Content>
|
|
178
|
+
<C.Spacing height={sg.spacings.spacingInline.spacingInlineAnt} />
|
|
179
|
+
</>
|
|
180
|
+
)}
|
|
136
181
|
<C.Footer>
|
|
137
182
|
<Button
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
183
|
+
{...cancelButtonProps}
|
|
184
|
+
variant={cancelButtonProps?.variant ?? 'secondary'}
|
|
185
|
+
size={cancelButtonProps?.size ?? 'Small'}
|
|
186
|
+
width={cancelButtonProps?.width ?? pxToRem('102px')}
|
|
187
|
+
onClick={handleCancelClick}
|
|
142
188
|
>
|
|
143
|
-
|
|
189
|
+
{cancelLabel ??
|
|
190
|
+
cancelButtonProps?.children ??
|
|
191
|
+
cancelButtonProps?.name ??
|
|
192
|
+
'Cancelar'}
|
|
144
193
|
</Button>
|
|
145
|
-
<Button
|
|
146
|
-
|
|
194
|
+
<Button
|
|
195
|
+
{...confirmButtonProps}
|
|
196
|
+
size={confirmButtonProps?.size ?? 'Small'}
|
|
197
|
+
width={confirmButtonProps?.width ?? pxToRem('102px')}
|
|
198
|
+
onClick={handleConfirmClick}
|
|
199
|
+
>
|
|
200
|
+
{confirmLabel ??
|
|
201
|
+
confirmButtonProps?.children ??
|
|
202
|
+
confirmButtonProps?.name ??
|
|
203
|
+
'Confirmar'}
|
|
147
204
|
</Button>
|
|
148
205
|
</C.Footer>
|
|
149
206
|
</C.PopconfirmContainer>
|
|
150
207
|
);
|
|
151
208
|
return (
|
|
152
209
|
<C.PopConfirmWrapper
|
|
210
|
+
id={id}
|
|
153
211
|
ref={targetRef}
|
|
154
212
|
wrapperWidth={wrapperWidth}
|
|
155
213
|
wrapperHeight={wrapperHeight}
|
|
@@ -33,7 +33,7 @@ export const PopconfirmContainer = styled.div<PopConfirmContainerProps>`
|
|
|
33
33
|
border-color: ${sg.colors.neutralColors.colorNeutralClean};
|
|
34
34
|
border-style: solid;
|
|
35
35
|
min-width: 240px;
|
|
36
|
-
z-index:
|
|
36
|
+
z-index: ${sg.zIndexes.popover};
|
|
37
37
|
&::before {
|
|
38
38
|
content: '';
|
|
39
39
|
position: absolute;
|