@sebgroup/green-react 3.0.1 → 3.0.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/index.esm.js +94 -16
- package/package.json +2 -2
- package/src/lib/badge/badge.d.ts +11 -0
- package/src/lib/modal/modal.d.ts +2 -1
package/index.esm.js
CHANGED
|
@@ -2013,6 +2013,17 @@ function AlertRibbon({
|
|
|
2013
2013
|
}));
|
|
2014
2014
|
}
|
|
2015
2015
|
|
|
2016
|
+
/**
|
|
2017
|
+
* Renders a badge component.
|
|
2018
|
+
*
|
|
2019
|
+
* @param {React.ReactNode} props.children - The content of the badge.
|
|
2020
|
+
* @param {string} props.badgeType - The type of the badge.
|
|
2021
|
+
* @param {boolean} props.isCloseable - Indicates if the badge is closeable.
|
|
2022
|
+
* @param {string} props.closeText - The text for the close button.
|
|
2023
|
+
* @param {string} props.customColor - The custom color for the badge.
|
|
2024
|
+
* @param {string} props.customBackgroundColor - The custom background color for the badge.
|
|
2025
|
+
* @returns {React.ReactNode} The rendered badge component.
|
|
2026
|
+
*/
|
|
2016
2027
|
function Badge(_a) {
|
|
2017
2028
|
var {
|
|
2018
2029
|
children,
|
|
@@ -4999,12 +5010,26 @@ const Tabs = ({
|
|
|
4999
5010
|
};
|
|
5000
5011
|
|
|
5001
5012
|
const ModalHeader = ({
|
|
5013
|
+
type,
|
|
5014
|
+
setStatus,
|
|
5015
|
+
setShouldRender,
|
|
5002
5016
|
header: _header = '',
|
|
5003
5017
|
id,
|
|
5004
5018
|
onClose
|
|
5005
5019
|
}) => {
|
|
5006
5020
|
const handleClose = event => {
|
|
5007
|
-
if (
|
|
5021
|
+
if (type === 'slideout') {
|
|
5022
|
+
setStatus && setStatus(IS_EXITING);
|
|
5023
|
+
setTimeout(() => {
|
|
5024
|
+
if (onClose) onClose(event);
|
|
5025
|
+
setStatus && setStatus(UNMOUNTED);
|
|
5026
|
+
setShouldRender && setShouldRender(false);
|
|
5027
|
+
}, DELAY);
|
|
5028
|
+
} else {
|
|
5029
|
+
if (onClose) onClose(event);
|
|
5030
|
+
setStatus && setStatus(UNMOUNTED);
|
|
5031
|
+
setShouldRender && setShouldRender(false);
|
|
5032
|
+
}
|
|
5008
5033
|
};
|
|
5009
5034
|
return jsxs("div", Object.assign({
|
|
5010
5035
|
className: "header"
|
|
@@ -5041,7 +5066,8 @@ const ModalFooter = ({
|
|
|
5041
5066
|
dismiss,
|
|
5042
5067
|
onClose,
|
|
5043
5068
|
onConfirm,
|
|
5044
|
-
onDismiss
|
|
5069
|
+
onDismiss,
|
|
5070
|
+
preventBackdropClose: _preventBackdropClose = false
|
|
5045
5071
|
}) => {
|
|
5046
5072
|
const handleConfirm = event => {
|
|
5047
5073
|
if (onConfirm) onConfirm(event);
|
|
@@ -5067,6 +5093,13 @@ const ModalFooter = ({
|
|
|
5067
5093
|
}))]
|
|
5068
5094
|
}));
|
|
5069
5095
|
};
|
|
5096
|
+
/* This delay is the same as the one used in the aside modal mixin: /libs/chlorophyll/scss/components/modal/_mixins.scss */
|
|
5097
|
+
const DELAY = 500;
|
|
5098
|
+
const UNMOUNTED = 'unmounted';
|
|
5099
|
+
const IS_MOUNTING = 'is-mounting';
|
|
5100
|
+
const IS_ENTERING = 'is-entering';
|
|
5101
|
+
const ENTERED = 'entered';
|
|
5102
|
+
const IS_EXITING = 'is-exiting';
|
|
5070
5103
|
const Modal = _a => {
|
|
5071
5104
|
var {
|
|
5072
5105
|
type = 'default',
|
|
@@ -5076,6 +5109,27 @@ const Modal = _a => {
|
|
|
5076
5109
|
} = _a,
|
|
5077
5110
|
props = __rest(_a, ["type", "id", "isOpen", "size"]);
|
|
5078
5111
|
const [uuid, _] = useState(id);
|
|
5112
|
+
const [status, setStatus] = useState(UNMOUNTED);
|
|
5113
|
+
const [shouldRender, setShouldRender] = useState(false);
|
|
5114
|
+
useEffect(() => {
|
|
5115
|
+
if (isOpen && !shouldRender && status === UNMOUNTED) {
|
|
5116
|
+
setShouldRender(true);
|
|
5117
|
+
setStatus(IS_MOUNTING);
|
|
5118
|
+
}
|
|
5119
|
+
if (isOpen && shouldRender && status === IS_MOUNTING) {
|
|
5120
|
+
setStatus(IS_ENTERING);
|
|
5121
|
+
setTimeout(() => {
|
|
5122
|
+
setStatus(ENTERED);
|
|
5123
|
+
}, DELAY);
|
|
5124
|
+
}
|
|
5125
|
+
if (!isOpen && status === ENTERED) {
|
|
5126
|
+
setStatus(IS_EXITING);
|
|
5127
|
+
setTimeout(() => {
|
|
5128
|
+
setStatus(UNMOUNTED);
|
|
5129
|
+
setShouldRender(false);
|
|
5130
|
+
}, DELAY);
|
|
5131
|
+
}
|
|
5132
|
+
}, [isOpen, shouldRender, status]);
|
|
5079
5133
|
if (!isOpen) return null;
|
|
5080
5134
|
const bodyId = `${uuid}_body`;
|
|
5081
5135
|
const headerId = `${uuid}_header`;
|
|
@@ -5090,14 +5144,18 @@ const Modal = _a => {
|
|
|
5090
5144
|
switch (type) {
|
|
5091
5145
|
case 'slideout':
|
|
5092
5146
|
{
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5147
|
+
const className = classNames(status, {
|
|
5148
|
+
'gds-slide-out--960': size === 'lg',
|
|
5149
|
+
'gds-slide-out--768': size === 'md'
|
|
5150
|
+
});
|
|
5096
5151
|
modalContent = jsxs("aside", Object.assign({
|
|
5097
5152
|
className: className
|
|
5098
5153
|
}, dialogProps, {
|
|
5099
5154
|
children: [jsx(ModalHeader, Object.assign({
|
|
5100
|
-
id: headerId
|
|
5155
|
+
id: headerId,
|
|
5156
|
+
setStatus: setStatus,
|
|
5157
|
+
setShouldRender: setShouldRender,
|
|
5158
|
+
type: type
|
|
5101
5159
|
}, props)), jsx(ModalBody, Object.assign({
|
|
5102
5160
|
id: bodyId
|
|
5103
5161
|
}, props)), jsx(ModalFooter, Object.assign({}, props))]
|
|
@@ -5117,24 +5175,44 @@ const Modal = _a => {
|
|
|
5117
5175
|
}
|
|
5118
5176
|
default:
|
|
5119
5177
|
{
|
|
5120
|
-
modalContent =
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5178
|
+
modalContent = jsx("div", Object.assign({
|
|
5179
|
+
className: "gds-dialog-wrapper"
|
|
5180
|
+
}, {
|
|
5181
|
+
children: jsxs("section", Object.assign({}, dialogProps, {
|
|
5182
|
+
children: [jsx(ModalHeader, Object.assign({
|
|
5183
|
+
id: headerId
|
|
5184
|
+
}, props)), jsx(ModalBody, Object.assign({
|
|
5185
|
+
id: bodyId
|
|
5186
|
+
}, props)), jsx(ModalFooter, Object.assign({}, props))]
|
|
5187
|
+
}))
|
|
5126
5188
|
}));
|
|
5127
5189
|
break;
|
|
5128
5190
|
}
|
|
5129
5191
|
}
|
|
5130
|
-
const
|
|
5131
|
-
|
|
5192
|
+
const backdropClassnames = classNames('backdrop', {
|
|
5193
|
+
'backdrop--transparent': type === 'slideout'
|
|
5194
|
+
}, status);
|
|
5195
|
+
const handleBackdropClick = event => {
|
|
5196
|
+
if (props.onClose && !props.preventBackdropClose) {
|
|
5197
|
+
if (type === 'slideout') {
|
|
5198
|
+
setStatus && setStatus(IS_EXITING);
|
|
5199
|
+
setTimeout(() => {
|
|
5200
|
+
if (props.onClose) props.onClose(event);
|
|
5201
|
+
setStatus && setStatus(UNMOUNTED);
|
|
5202
|
+
setShouldRender && setShouldRender(false);
|
|
5203
|
+
}, DELAY);
|
|
5204
|
+
} else {
|
|
5205
|
+
if (props.onClose) props.onClose(event);
|
|
5206
|
+
setStatus && setStatus(UNMOUNTED);
|
|
5207
|
+
setShouldRender && setShouldRender(false);
|
|
5208
|
+
}
|
|
5209
|
+
}
|
|
5132
5210
|
};
|
|
5133
5211
|
return jsxs(Fragment, {
|
|
5134
5212
|
children: [modalContent, jsx("div", {
|
|
5135
5213
|
"data-testid": "modal-backdrop",
|
|
5136
|
-
className:
|
|
5137
|
-
onClick: handleBackdropClick,
|
|
5214
|
+
className: backdropClassnames,
|
|
5215
|
+
onClick: e => handleBackdropClick(e),
|
|
5138
5216
|
"aria-hidden": "true"
|
|
5139
5217
|
})]
|
|
5140
5218
|
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebgroup/green-react",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"react": "^17 || ^18",
|
|
6
6
|
"react-dom": "^17 || ^18"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@sebgroup/green-core": "^1.4.1",
|
|
10
|
-
"@sebgroup/chlorophyll": "^3.0.
|
|
10
|
+
"@sebgroup/chlorophyll": "^3.0.2",
|
|
11
11
|
"@sebgroup/extract": "^3.0.0",
|
|
12
12
|
"@lit/react": "^1.0.2",
|
|
13
13
|
"classnames": "^2.3.2"
|
package/src/lib/badge/badge.d.ts
CHANGED
|
@@ -8,5 +8,16 @@ export interface BadgeProps extends HTMLProps<HTMLSpanElement> {
|
|
|
8
8
|
customColor?: string;
|
|
9
9
|
customBackgroundColor?: string;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Renders a badge component.
|
|
13
|
+
*
|
|
14
|
+
* @param {React.ReactNode} props.children - The content of the badge.
|
|
15
|
+
* @param {string} props.badgeType - The type of the badge.
|
|
16
|
+
* @param {boolean} props.isCloseable - Indicates if the badge is closeable.
|
|
17
|
+
* @param {string} props.closeText - The text for the close button.
|
|
18
|
+
* @param {string} props.customColor - The custom color for the badge.
|
|
19
|
+
* @param {string} props.customBackgroundColor - The custom background color for the badge.
|
|
20
|
+
* @returns {React.ReactNode} The rendered badge component.
|
|
21
|
+
*/
|
|
11
22
|
export declare function Badge({ children, badgeType, isCloseable, closeText, customColor, customBackgroundColor, ...props }: BadgeProps): import("react/jsx-runtime").JSX.Element | null;
|
|
12
23
|
export default Badge;
|
package/src/lib/modal/modal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ModalType, Size } from '@sebgroup/extract';
|
|
2
2
|
import { MouseEvent, ReactNode } from 'react';
|
|
3
|
-
declare type ModalEventListener = (event: MouseEvent<HTMLButtonElement> | null) => unknown;
|
|
3
|
+
declare type ModalEventListener = (event: MouseEvent<HTMLButtonElement | HTMLDivElement> | null) => unknown;
|
|
4
4
|
export interface ModalProps {
|
|
5
5
|
type?: ModalType;
|
|
6
6
|
header?: string;
|
|
@@ -13,6 +13,7 @@ export interface ModalProps {
|
|
|
13
13
|
onClose?: ModalEventListener;
|
|
14
14
|
onConfirm?: ModalEventListener;
|
|
15
15
|
onDismiss?: ModalEventListener;
|
|
16
|
+
preventBackdropClose?: boolean;
|
|
16
17
|
}
|
|
17
18
|
export declare const Modal: ({ type, id, isOpen, size, ...props }: ModalProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
18
19
|
export default Modal;
|