@duetds/react 9.10.0 → 9.12.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.
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { OverlayEventDetail } from './interfaces';
3
+ import { StencilReactForwardedRef } from './utils';
4
+ interface OverlayElement extends HTMLElement {
5
+ present: () => Promise<void>;
6
+ dismiss: (data?: any, role?: string | undefined) => Promise<boolean>;
7
+ }
8
+ export interface ReactOverlayProps {
9
+ children?: React.ReactNode;
10
+ isOpen: boolean;
11
+ onDidDismiss?: (event: CustomEvent<OverlayEventDetail>) => void;
12
+ onDidPresent?: (event: CustomEvent<OverlayEventDetail>) => void;
13
+ onWillDismiss?: (event: CustomEvent<OverlayEventDetail>) => void;
14
+ onWillPresent?: (event: CustomEvent<OverlayEventDetail>) => void;
15
+ }
16
+ export declare const createOverlayComponent: <OverlayComponent extends object, OverlayType extends OverlayElement>(tagName: string, controller: {
17
+ create: (options: any) => Promise<OverlayType>;
18
+ }, customElement?: any) => React.ForwardRefExoticComponent<React.PropsWithoutRef<OverlayComponent & ReactOverlayProps & {
19
+ forwardedRef?: StencilReactForwardedRef<OverlayType>;
20
+ }> & React.RefAttributes<OverlayType>>;
21
+ export {};
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
51
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
52
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
53
+ return new (P || (P = Promise))(function (resolve, reject) {
54
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
55
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
56
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
57
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
58
+ });
59
+ };
60
+ var __generator = (this && this.__generator) || function (thisArg, body) {
61
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
62
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
63
+ function verb(n) { return function (v) { return step([n, v]); }; }
64
+ function step(op) {
65
+ if (f) throw new TypeError("Generator is already executing.");
66
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
67
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
68
+ if (y = 0, t) op = [op[0] & 2, t.value];
69
+ switch (op[0]) {
70
+ case 0: case 1: t = op; break;
71
+ case 4: _.label++; return { value: op[1], done: false };
72
+ case 5: _.label++; y = op[1]; op = [0]; continue;
73
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
74
+ default:
75
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
76
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
77
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
78
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
79
+ if (t[2]) _.ops.pop();
80
+ _.trys.pop(); continue;
81
+ }
82
+ op = body.call(thisArg, _);
83
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
84
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
+ }
86
+ };
87
+ var __rest = (this && this.__rest) || function (s, e) {
88
+ var t = {};
89
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
90
+ t[p] = s[p];
91
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
92
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
93
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
94
+ t[p[i]] = s[p[i]];
95
+ }
96
+ return t;
97
+ };
98
+ var __importDefault = (this && this.__importDefault) || function (mod) {
99
+ return (mod && mod.__esModule) ? mod : { "default": mod };
100
+ };
101
+ Object.defineProperty(exports, "__esModule", { value: true });
102
+ exports.createOverlayComponent = void 0;
103
+ var react_1 = __importStar(require("react"));
104
+ var react_dom_1 = __importDefault(require("react-dom"));
105
+ var utils_1 = require("./utils");
106
+ var createOverlayComponent = function (tagName, controller, customElement) {
107
+ (0, utils_1.defineCustomElement)(tagName, customElement);
108
+ var displayName = (0, utils_1.dashToPascalCase)(tagName);
109
+ var didDismissEventName = "on".concat(displayName, "DidDismiss");
110
+ var didPresentEventName = "on".concat(displayName, "DidPresent");
111
+ var willDismissEventName = "on".concat(displayName, "WillDismiss");
112
+ var willPresentEventName = "on".concat(displayName, "WillPresent");
113
+ var isDismissing = false;
114
+ var Overlay = /** @class */ (function (_super) {
115
+ __extends(Overlay, _super);
116
+ function Overlay(props) {
117
+ var _this = _super.call(this, props) || this;
118
+ if (typeof document !== 'undefined') {
119
+ _this.el = document.createElement('div');
120
+ }
121
+ _this.handleDismiss = _this.handleDismiss.bind(_this);
122
+ return _this;
123
+ }
124
+ Object.defineProperty(Overlay, "displayName", {
125
+ get: function () {
126
+ return displayName;
127
+ },
128
+ enumerable: false,
129
+ configurable: true
130
+ });
131
+ Overlay.prototype.componentDidMount = function () {
132
+ if (this.props.isOpen) {
133
+ this.present();
134
+ }
135
+ };
136
+ Overlay.prototype.componentWillUnmount = function () {
137
+ if (this.overlay) {
138
+ this.overlay.dismiss();
139
+ }
140
+ };
141
+ Overlay.prototype.handleDismiss = function (event) {
142
+ if (this.props.onDidDismiss) {
143
+ this.props.onDidDismiss(event);
144
+ }
145
+ (0, utils_1.setRef)(this.props.forwardedRef, null);
146
+ };
147
+ Overlay.prototype.shouldComponentUpdate = function (nextProps) {
148
+ // Check if the overlay component is about to dismiss
149
+ if (this.overlay && nextProps.isOpen !== this.props.isOpen && nextProps.isOpen === false) {
150
+ isDismissing = true;
151
+ }
152
+ return true;
153
+ };
154
+ Overlay.prototype.componentDidUpdate = function (prevProps) {
155
+ return __awaiter(this, void 0, void 0, function () {
156
+ return __generator(this, function (_a) {
157
+ switch (_a.label) {
158
+ case 0:
159
+ if (this.overlay) {
160
+ (0, utils_1.attachProps)(this.overlay, this.props, prevProps);
161
+ }
162
+ if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
163
+ this.present(prevProps);
164
+ }
165
+ if (!(this.overlay && prevProps.isOpen !== this.props.isOpen && this.props.isOpen === false)) return [3 /*break*/, 2];
166
+ return [4 /*yield*/, this.overlay.dismiss()];
167
+ case 1:
168
+ _a.sent();
169
+ isDismissing = false;
170
+ /**
171
+ * Now that the overlay is dismissed
172
+ * we need to render again so that any
173
+ * inner components will be unmounted
174
+ */
175
+ this.forceUpdate();
176
+ _a.label = 2;
177
+ case 2: return [2 /*return*/];
178
+ }
179
+ });
180
+ });
181
+ };
182
+ Overlay.prototype.present = function (prevProps) {
183
+ return __awaiter(this, void 0, void 0, function () {
184
+ var _a, children, isOpen, onDidDismiss, onDidPresent, onWillDismiss, onWillPresent, cProps, elementProps, _b;
185
+ var _c;
186
+ var _this = this;
187
+ return __generator(this, function (_d) {
188
+ switch (_d.label) {
189
+ case 0:
190
+ _a = this.props, children = _a.children, isOpen = _a.isOpen, onDidDismiss = _a.onDidDismiss, onDidPresent = _a.onDidPresent, onWillDismiss = _a.onWillDismiss, onWillPresent = _a.onWillPresent, cProps = __rest(_a, ["children", "isOpen", "onDidDismiss", "onDidPresent", "onWillDismiss", "onWillPresent"]);
191
+ elementProps = __assign(__assign({}, cProps), (_c = { ref: this.props.forwardedRef }, _c[didDismissEventName] = this.handleDismiss, _c[didPresentEventName] = function (e) {
192
+ return _this.props.onDidPresent && _this.props.onDidPresent(e);
193
+ }, _c[willDismissEventName] = function (e) {
194
+ return _this.props.onWillDismiss && _this.props.onWillDismiss(e);
195
+ }, _c[willPresentEventName] = function (e) {
196
+ return _this.props.onWillPresent && _this.props.onWillPresent(e);
197
+ }, _c));
198
+ _b = this;
199
+ return [4 /*yield*/, controller.create(__assign(__assign({}, elementProps), { component: this.el, componentProps: {} }))];
200
+ case 1:
201
+ _b.overlay = _d.sent();
202
+ (0, utils_1.setRef)(this.props.forwardedRef, this.overlay);
203
+ (0, utils_1.attachProps)(this.overlay, elementProps, prevProps);
204
+ return [4 /*yield*/, this.overlay.present()];
205
+ case 2:
206
+ _d.sent();
207
+ return [2 /*return*/];
208
+ }
209
+ });
210
+ });
211
+ };
212
+ Overlay.prototype.render = function () {
213
+ /**
214
+ * Continue to render the component even when
215
+ * overlay is dismissing otherwise component
216
+ * will be hidden before animation is done.
217
+ */
218
+ return react_dom_1.default.createPortal(this.props.isOpen || isDismissing ? this.props.children : null, this.el);
219
+ };
220
+ return Overlay;
221
+ }(react_1.Component));
222
+ return react_1.default.forwardRef(function (props, ref) {
223
+ return react_1.default.createElement(Overlay, __assign({}, props, { forwardedRef: ref }));
224
+ });
225
+ };
226
+ exports.createOverlayComponent = createOverlayComponent;
227
+ //# sourceMappingURL=createOverlayComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createOverlayComponent.js","sourceRoot":"","sources":["../../src/react-component-lib/createOverlayComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA0D;AAC1D,wDAAiC;AAGjC,iCAMiB;AAgBV,IAAM,sBAAsB,GAAG,UAIpC,OAAe,EACf,UAA8D,EAC9D,aAAmB;IAEnB,IAAA,2BAAmB,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAE5C,IAAM,WAAW,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;IAC9C,IA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C;AACL,CAAC,CAAC;AAvIW,QAAA,sBAAsB,0BAuIjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duetds/react",
3
- "version": "9.10.0",
3
+ "version": "9.12.0",
4
4
  "description": "This package includes React specific wrapper for Duet Design System Web Components.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "author": "LocalTapiola Services Ltd <duetdesignsystem@lahitapiola.fi>",
@@ -22,7 +22,7 @@
22
22
  "tsc": "tsc -p ./tsconfig.es2015.json && tsc -p ./tsconfig.commonjs.json"
23
23
  },
24
24
  "dependencies": {
25
- "@duetds/components": "9.10.0"
25
+ "@duetds/components": "9.12.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@testing-library/react": "16.0.1",
@@ -44,5 +44,5 @@
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "daef74b33510c172624d94fd298ffa3adf0092e1"
47
+ "gitHead": "efb1655b4344b0a8ae9e792e7cd4b9087676577f"
48
48
  }