@sebgroup/green-react 3.0.0 → 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 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,
@@ -2077,17 +2088,19 @@ const CoreDatepicker = createComponent({
2077
2088
  },
2078
2089
  react: React
2079
2090
  });
2080
- const Datepicker = ({
2081
- label: _label = 'Date',
2082
- onChange,
2083
- minDate,
2084
- maxDate,
2085
- value,
2086
- showWeeks,
2087
- testId,
2088
- selectedDate,
2089
- currentDate
2090
- }) => {
2091
+ const Datepicker = _a => {
2092
+ var {
2093
+ label = 'Date',
2094
+ onChange,
2095
+ minDate,
2096
+ maxDate,
2097
+ value,
2098
+ showWeeks,
2099
+ testId,
2100
+ selectedDate,
2101
+ currentDate
2102
+ } = _a,
2103
+ props = __rest(_a, ["label", "onChange", "minDate", "maxDate", "value", "showWeeks", "testId", "selectedDate", "currentDate"]);
2091
2104
  if (currentDate && !value) value = currentDate;
2092
2105
  if (selectedDate && !value) value = selectedDate;
2093
2106
  const min = minDate ? minDate : new Date(new Date().getFullYear() - 10, 0, 1);
@@ -2101,15 +2114,15 @@ const Datepicker = ({
2101
2114
  return jsx("div", Object.assign({
2102
2115
  className: "form-group"
2103
2116
  }, {
2104
- children: jsx(CoreDatepicker, {
2117
+ children: jsx(CoreDatepicker, Object.assign({
2105
2118
  "data-testid": testId,
2106
- label: _label,
2119
+ label: label,
2107
2120
  min: min,
2108
2121
  max: max,
2109
2122
  showWeekNumbers: showWeeks,
2110
2123
  onchange: onChangeHandler,
2111
2124
  value: value
2112
- })
2125
+ }, props))
2113
2126
  }));
2114
2127
  };
2115
2128
 
@@ -4997,12 +5010,26 @@ const Tabs = ({
4997
5010
  };
4998
5011
 
4999
5012
  const ModalHeader = ({
5013
+ type,
5014
+ setStatus,
5015
+ setShouldRender,
5000
5016
  header: _header = '',
5001
5017
  id,
5002
5018
  onClose
5003
5019
  }) => {
5004
5020
  const handleClose = event => {
5005
- if (onClose) onClose(event);
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
+ }
5006
5033
  };
5007
5034
  return jsxs("div", Object.assign({
5008
5035
  className: "header"
@@ -5039,7 +5066,8 @@ const ModalFooter = ({
5039
5066
  dismiss,
5040
5067
  onClose,
5041
5068
  onConfirm,
5042
- onDismiss
5069
+ onDismiss,
5070
+ preventBackdropClose: _preventBackdropClose = false
5043
5071
  }) => {
5044
5072
  const handleConfirm = event => {
5045
5073
  if (onConfirm) onConfirm(event);
@@ -5065,6 +5093,13 @@ const ModalFooter = ({
5065
5093
  }))]
5066
5094
  }));
5067
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';
5068
5103
  const Modal = _a => {
5069
5104
  var {
5070
5105
  type = 'default',
@@ -5074,6 +5109,27 @@ const Modal = _a => {
5074
5109
  } = _a,
5075
5110
  props = __rest(_a, ["type", "id", "isOpen", "size"]);
5076
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]);
5077
5133
  if (!isOpen) return null;
5078
5134
  const bodyId = `${uuid}_body`;
5079
5135
  const headerId = `${uuid}_header`;
@@ -5088,14 +5144,18 @@ const Modal = _a => {
5088
5144
  switch (type) {
5089
5145
  case 'slideout':
5090
5146
  {
5091
- let className = undefined;
5092
- if (size === 'lg') className = 'gds-slide-out--960';
5093
- if (size === 'md') className = 'gds-slide-out--768';
5147
+ const className = classNames(status, {
5148
+ 'gds-slide-out--960': size === 'lg',
5149
+ 'gds-slide-out--768': size === 'md'
5150
+ });
5094
5151
  modalContent = jsxs("aside", Object.assign({
5095
5152
  className: className
5096
5153
  }, dialogProps, {
5097
5154
  children: [jsx(ModalHeader, Object.assign({
5098
- id: headerId
5155
+ id: headerId,
5156
+ setStatus: setStatus,
5157
+ setShouldRender: setShouldRender,
5158
+ type: type
5099
5159
  }, props)), jsx(ModalBody, Object.assign({
5100
5160
  id: bodyId
5101
5161
  }, props)), jsx(ModalFooter, Object.assign({}, props))]
@@ -5115,24 +5175,44 @@ const Modal = _a => {
5115
5175
  }
5116
5176
  default:
5117
5177
  {
5118
- modalContent = jsxs("section", Object.assign({}, dialogProps, {
5119
- children: [jsx(ModalHeader, Object.assign({
5120
- id: headerId
5121
- }, props)), jsx(ModalBody, Object.assign({
5122
- id: bodyId
5123
- }, props)), jsx(ModalFooter, Object.assign({}, props))]
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
+ }))
5124
5188
  }));
5125
5189
  break;
5126
5190
  }
5127
5191
  }
5128
- const handleBackdropClick = () => {
5129
- if (props.onClose) props.onClose(null);
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
+ }
5130
5210
  };
5131
5211
  return jsxs(Fragment, {
5132
5212
  children: [modalContent, jsx("div", {
5133
5213
  "data-testid": "modal-backdrop",
5134
- className: "backdrop",
5135
- onClick: handleBackdropClick,
5214
+ className: backdropClassnames,
5215
+ onClick: e => handleBackdropClick(e),
5136
5216
  "aria-hidden": "true"
5137
5217
  })]
5138
5218
  });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@sebgroup/green-react",
3
- "version": "3.0.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
- "@sebgroup/green-core": "^1.4.0",
10
- "@sebgroup/chlorophyll": "^3.0.0",
9
+ "@sebgroup/green-core": "^1.4.1",
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"
@@ -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;
@@ -15,4 +15,4 @@ export interface DatepickerOptions {
15
15
  /** @deprecated Use `value` instead */
16
16
  currentDate?: Date;
17
17
  }
18
- export declare const Datepicker: ({ label, onChange, minDate, maxDate, value, showWeeks, testId, selectedDate, currentDate, }: DatepickerOptions) => import("react/jsx-runtime").JSX.Element;
18
+ export declare const Datepicker: ({ label, onChange, minDate, maxDate, value, showWeeks, testId, selectedDate, currentDate, ...props }: DatepickerOptions) => import("react/jsx-runtime").JSX.Element;
@@ -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;