@adobe-commerce/elsie 1.3.0-beta5 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe-commerce/elsie",
3
- "version": "1.3.0-beta5",
3
+ "version": "1.3.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "description": "Domain Package SDK",
6
6
  "engines": {
@@ -27,10 +27,10 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@adobe-commerce/event-bus": "~1.0.0",
30
- "@adobe-commerce/fetch-graphql": "1.1.0-beta1",
31
- "@adobe-commerce/recaptcha": "1.0.1-beta2",
30
+ "@adobe-commerce/fetch-graphql": "~1.1.0",
31
+ "@adobe-commerce/recaptcha": "~1.0.1",
32
32
  "@adobe-commerce/storefront-design": "~1.0.0",
33
- "@dropins/build-tools": "1.0.1-beta1",
33
+ "@dropins/build-tools": "~1.0.1",
34
34
  "preact": "~10.22.1",
35
35
  "vite-plugin-banner": "^0.8.0"
36
36
  },
@@ -12,6 +12,7 @@ import { Modal as component, ModalProps } from './Modal';
12
12
  import { useState } from 'preact/hooks';
13
13
  import { Button } from '../Button';
14
14
  import { expect, userEvent, within, waitFor } from '@storybook/test';
15
+ import { useText } from '@adobe-commerce/elsie/i18n';
15
16
 
16
17
  const meta: Meta<ModalProps> = {
17
18
  title: 'Components/Modal',
@@ -269,4 +270,65 @@ export const OverflowingTitle: Story = {
269
270
  },
270
271
  };
271
272
 
273
+ const LocalizedContent = () => {
274
+ const translations = useText({
275
+ label: 'Dropin.ExampleComponentName.item.label',
276
+ });
277
+
278
+ console.log(translations.label);
279
+ return <div>{translations.label}</div>;
280
+ };
281
+
282
+ /**
283
+ * ```ts
284
+ * import { Modal } from '@/elsie/components/Modal';
285
+ * import { useText } from '@adobe-commerce/elsie/i18n';
286
+ *
287
+ * const label = useText(`Dropin.ExampleComponentName.item.label`).label;
288
+ *
289
+ * <Modal size="medium" title={<h3>Localized Modal</h3>}>
290
+ * <div>{label}</div>
291
+ * </Modal>
292
+ * ```
293
+ */
294
+
295
+ export const LocalizedModal: Story = {
296
+ args: {
297
+ size: 'medium',
298
+ children: <LocalizedContent />,
299
+ title: <h3>Localized Modal</h3>,
300
+ },
301
+ play: async ({ canvasElement }) => {
302
+ const canvas = within(canvasElement);
303
+ await userEvent.click(canvas.getByRole('button'));
304
+
305
+ const portalRoot = await waitFor(() => {
306
+ const root = document.querySelector('[data-portal-root]') as HTMLDivElement;
307
+ expect(root).toBeTruthy();
308
+ return root;
309
+ });
310
+
311
+ await expect(portalRoot).toBeVisible();
312
+
313
+ const modal = document.querySelector(
314
+ '.dropin-modal__body'
315
+ ) as HTMLDivElement;
316
+
317
+ await expect(modal).toBeVisible();
318
+
319
+ expect(portalRoot.querySelector('h3')?.innerText).toBe('Localized Modal');
320
+ expect((portalRoot.querySelector('.dropin-modal__body') as HTMLElement)?.innerText).toContain('string');
321
+
322
+ const closeButton = document.querySelector(
323
+ '.dropin-modal__header-close-button'
324
+ ) as HTMLButtonElement;
325
+
326
+ await userEvent.click(closeButton);
327
+
328
+ await expect(modal).not.toBeVisible();
329
+
330
+ await expect(canvas.getByText('Open Modal')).toBeVisible();
331
+ },
332
+ };
333
+
272
334
  export default meta;
@@ -7,8 +7,8 @@
7
7
  * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
- import { ComponentChildren, render } from 'preact';
11
- import { FunctionComponent, useEffect, useRef } from 'preact/compat';
10
+ import { ComponentChildren } from 'preact';
11
+ import { FunctionComponent, useLayoutEffect, useRef } from 'preact/compat';
12
12
 
13
13
  interface PortalProps {
14
14
  children: ComponentChildren;
@@ -16,28 +16,34 @@ interface PortalProps {
16
16
 
17
17
  export const Portal: FunctionComponent<PortalProps> = ({ children }) => {
18
18
  const portalRoot = useRef<HTMLDivElement | null>(null);
19
+ const contentRef = useRef<HTMLDivElement | null>(null);
19
20
 
20
- useEffect(() => {
21
+ useLayoutEffect(() => {
21
22
  // Create portal root if it doesn't exist
22
23
  if (!portalRoot.current) {
23
24
  portalRoot.current = document.createElement('div');
24
25
  portalRoot.current.setAttribute('data-portal-root', '');
25
- portalRoot.current.classList.add('dropin-design');
26
26
  document.body.appendChild(portalRoot.current);
27
27
  }
28
28
 
29
- // Render children into portal root
30
- render(children, portalRoot.current);
29
+ // Move content to portal root
30
+ if (contentRef.current && portalRoot.current) {
31
+ portalRoot.current.appendChild(contentRef.current);
32
+ }
31
33
 
32
34
  // Cleanup
33
35
  return () => {
34
36
  if (portalRoot.current) {
35
- render(null, portalRoot.current);
36
37
  portalRoot.current.remove();
37
38
  portalRoot.current = null;
38
39
  }
39
40
  };
40
- }, [children]);
41
+ }, []);
41
42
 
42
- return null;
43
+ // Return a div that contains the children
44
+ return (
45
+ <div ref={contentRef} className="dropin-design">
46
+ {children}
47
+ </div>
48
+ );
43
49
  };