@chayns-components/core 5.6.2 → 5.6.4

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.
Files changed (25) hide show
  1. package/AGENTS.md +8 -0
  2. package/lib/cjs/components/accordion/Accordion.js +28 -25
  3. package/lib/cjs/components/accordion/Accordion.js.map +1 -1
  4. package/lib/cjs/components/sharing-bar/SharingBar.js +2 -0
  5. package/lib/cjs/components/sharing-bar/SharingBar.js.map +1 -1
  6. package/lib/cjs/components/sharing-button/SharingButton.js +2 -0
  7. package/lib/cjs/components/sharing-button/SharingButton.js.map +1 -1
  8. package/lib/cjs/components/sharing-context-menu/SharingContextMenu.js +43 -10
  9. package/lib/cjs/components/sharing-context-menu/SharingContextMenu.js.map +1 -1
  10. package/lib/cjs/components/sharing-context-menu/SharingContextMenu.test.js +106 -2
  11. package/lib/cjs/components/sharing-context-menu/SharingContextMenu.test.js.map +1 -1
  12. package/lib/esm/components/accordion/Accordion.js +28 -25
  13. package/lib/esm/components/accordion/Accordion.js.map +1 -1
  14. package/lib/esm/components/sharing-bar/SharingBar.js +2 -0
  15. package/lib/esm/components/sharing-bar/SharingBar.js.map +1 -1
  16. package/lib/esm/components/sharing-button/SharingButton.js +2 -0
  17. package/lib/esm/components/sharing-button/SharingButton.js.map +1 -1
  18. package/lib/esm/components/sharing-context-menu/SharingContextMenu.js +44 -11
  19. package/lib/esm/components/sharing-context-menu/SharingContextMenu.js.map +1 -1
  20. package/lib/esm/components/sharing-context-menu/SharingContextMenu.test.js +108 -4
  21. package/lib/esm/components/sharing-context-menu/SharingContextMenu.test.js.map +1 -1
  22. package/lib/types/components/sharing-bar/SharingBar.d.ts +4 -0
  23. package/lib/types/components/sharing-button/SharingButton.d.ts +1 -1
  24. package/lib/types/components/sharing-context-menu/SharingContextMenu.d.ts +8 -0
  25. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import { getSite } from 'chayns-api';
2
+ import { getSite, invokeCall, isApp } from 'chayns-api';
3
3
  import React, { forwardRef, useCallback } from 'react';
4
4
  import { SHAREPROVIDER } from '../../constants/sharingBar';
5
5
  import { useIsTouch } from '../../utils/environment';
@@ -7,6 +7,7 @@ import { copyToClipboard, shareWithApp, shareWithUrl } from '../../utils/sharing
7
7
  import ContextMenu from '../context-menu/ContextMenu';
8
8
  const SharingContextMenu = /*#__PURE__*/forwardRef(({
9
9
  link,
10
+ text,
10
11
  children,
11
12
  shouldEnableKeyboardHighlighting,
12
13
  shouldShowCallingCodeAction = true,
@@ -14,6 +15,21 @@ const SharingContextMenu = /*#__PURE__*/forwardRef(({
14
15
  ...contextMenuProps
15
16
  }, ref) => {
16
17
  const isTouch = useIsTouch();
18
+ const shareInApp = useCallback((provider, shareText) => {
19
+ if (!provider) {
20
+ throw new Error('The requested sharing provider is not configured.');
21
+ }
22
+ void invokeCall({
23
+ action: 80,
24
+ value: {
25
+ text: shareText,
26
+ sharingApp: provider.providerId,
27
+ ...(provider.androidIdentifier ? {
28
+ sharingAndroidApp: provider.androidIdentifier
29
+ } : {})
30
+ }
31
+ });
32
+ }, []);
17
33
  const handleImageDownload = useCallback(() => {
18
34
  shareWithUrl(
19
35
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -23,31 +39,48 @@ const SharingContextMenu = /*#__PURE__*/forwardRef(({
23
39
  const handleShare = useCallback(key => {
24
40
  switch (key) {
25
41
  case 'whatsapp':
26
- shareWithUrl(
27
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
28
- // @ts-ignore
29
- SHAREPROVIDER[0].url.replace('{url}', encodeURIComponent(`${link}`.trim())));
30
- break;
42
+ {
43
+ const shareText = text ? `${text}\n\n${link}` : `${link}`.trim();
44
+ if (isApp()) {
45
+ shareInApp(SHAREPROVIDER[0], shareText);
46
+ break;
47
+ }
48
+ shareWithUrl(
49
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
50
+ // @ts-ignore
51
+ SHAREPROVIDER[0].url.replace('{url}', encodeURIComponent(shareText)));
52
+ break;
53
+ }
31
54
  case 'facebook':
55
+ if (isApp()) {
56
+ shareInApp(SHAREPROVIDER[3], `${link}`.trim());
57
+ break;
58
+ }
32
59
  shareWithUrl(
33
60
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
34
61
  // @ts-ignore
35
62
  SHAREPROVIDER[3].url.replace('{url}', encodeURIComponent(link)));
36
63
  break;
37
64
  case 'twitter':
65
+ if (isApp()) {
66
+ shareInApp(SHAREPROVIDER[4], text ? `${text}\n\n${link}` : `${link}`.trim());
67
+ break;
68
+ }
38
69
  shareWithUrl(
39
70
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
40
71
  // @ts-ignore
41
- SHAREPROVIDER[4].url.replace('{url}', encodeURIComponent(link)).replace('{linkText}', ''));
72
+ SHAREPROVIDER[4].url.replace('{url}', encodeURIComponent(link)).replace('{linkText}', encodeURIComponent(text ?? '')));
42
73
  break;
43
74
  case 'mail':
44
- if (isTouch) {
45
- shareWithApp(`${link}`.trim());
75
+ if (isApp()) {
76
+ shareInApp(SHAREPROVIDER[2], text ? `${text}\n\n${link}` : `${link}`.trim());
77
+ } else if (isTouch) {
78
+ shareWithApp(text ? `${text}\n\n${link}` : `${link}`.trim());
46
79
  } else {
47
80
  shareWithUrl(
48
81
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
49
82
  // @ts-ignore
50
- SHAREPROVIDER[2].url.replace('{url}', encodeURIComponent(`${link}`.trim())));
83
+ SHAREPROVIDER[2].url.replace('{url}', encodeURIComponent(text ? `${text}\n\n${link}` : `${link}`.trim())));
51
84
  }
52
85
  break;
53
86
  case 'copy':
@@ -56,7 +89,7 @@ const SharingContextMenu = /*#__PURE__*/forwardRef(({
56
89
  default:
57
90
  break;
58
91
  }
59
- }, [link, isTouch]);
92
+ }, [link, text, isTouch, shareInApp]);
60
93
  const contextMenuItems = [...(shouldShowCopyAction ? [{
61
94
  icons: ['fa fa-copy'],
62
95
  key: 'copy',
@@ -1 +1 @@
1
- {"version":3,"file":"SharingContextMenu.js","names":["getSite","React","forwardRef","useCallback","SHAREPROVIDER","useIsTouch","copyToClipboard","shareWithApp","shareWithUrl","ContextMenu","SharingContextMenu","link","children","shouldEnableKeyboardHighlighting","shouldShowCallingCodeAction","shouldShowCopyAction","contextMenuProps","ref","isTouch","handleImageDownload","url","replace","encodeURIComponent","color","handleShare","key","trim","contextMenuItems","icons","onClick","text","createElement","_extends","items","displayName"],"sources":["../../../../src/components/sharing-context-menu/SharingContextMenu.tsx"],"sourcesContent":["import { getSite } from 'chayns-api';\nimport React, { forwardRef, useCallback } from 'react';\nimport { SHAREPROVIDER } from '../../constants/sharingBar';\nimport { useIsTouch } from '../../utils/environment';\nimport { copyToClipboard, shareWithApp, shareWithUrl } from '../../utils/sharingBar';\nimport ContextMenu from '../context-menu/ContextMenu';\nimport { ContextMenuProps, ContextMenuRef } from '../context-menu/ContextMenu.types';\n\nexport type SharingContextMenuProps = {\n /**\n * The link that should be shared.\n */\n link: string;\n /**\n * Shows the action that copies the shared link to the clipboard.\n */\n shouldShowCopyAction?: boolean;\n /**\n * Shows the action that downloads a calling-code image.\n */\n shouldShowCallingCodeAction?: boolean;\n /**\n * Enables keyboard-only focus highlighting for the context menu trigger.\n */\n shouldEnableKeyboardHighlighting?: boolean;\n} & Omit<ContextMenuProps, 'items' | 'shouldEnableKeyboardHighlighting'>;\n\nconst SharingContextMenu = forwardRef<ContextMenuRef, SharingContextMenuProps>(\n (\n {\n link,\n children,\n shouldEnableKeyboardHighlighting,\n shouldShowCallingCodeAction = true,\n shouldShowCopyAction = true,\n ...contextMenuProps\n },\n ref,\n ) => {\n const isTouch = useIsTouch();\n\n const handleImageDownload = useCallback(() => {\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[5].url\n .replace('{url}', encodeURIComponent(link))\n .replace('{linkText}', 'Teilen')\n .replace('{color}', getSite().color.replace('#', '')),\n );\n }, [link]);\n\n const handleShare = useCallback(\n (key: string) => {\n switch (key) {\n case 'whatsapp':\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[0].url.replace(\n '{url}',\n encodeURIComponent(`${link}`.trim()),\n ),\n );\n break;\n case 'facebook':\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[3].url.replace('{url}', encodeURIComponent(link)),\n );\n break;\n case 'twitter':\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[4].url\n .replace('{url}', encodeURIComponent(link))\n .replace('{linkText}', ''),\n );\n break;\n case 'mail':\n if (isTouch) {\n shareWithApp(`${link}`.trim());\n } else {\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[2].url.replace(\n '{url}',\n encodeURIComponent(`${link}`.trim()),\n ),\n );\n }\n break;\n case 'copy':\n copyToClipboard(link);\n break;\n default:\n break;\n }\n },\n [link, isTouch],\n );\n\n const contextMenuItems = [\n ...(shouldShowCopyAction\n ? [\n {\n icons: ['fa fa-copy'],\n key: 'copy',\n onClick: () => handleShare('copy'),\n text: 'Zwischenablage',\n },\n ]\n : []),\n {\n icons: ['fa-solid fa-brands fa-whatsapp'],\n key: 'whatsapp',\n onClick: () => handleShare('whatsapp'),\n text: 'Whatsapp',\n },\n {\n icons: ['fa-solid fa-brands fa-facebook-f'],\n key: 'facebook',\n onClick: () => handleShare('facebook'),\n text: 'Facebook',\n },\n {\n icons: ['fa-solid fa-brands fa-x-twitter'],\n key: 'twitter',\n onClick: () => handleShare('twitter'),\n text: 'X',\n },\n {\n icons: ['fa fa-envelope'],\n key: 'mail',\n onClick: () => handleShare('mail'),\n text: 'Mail',\n },\n ...(shouldShowCallingCodeAction\n ? [\n {\n icons: ['fa fa-qrcode'],\n key: 'callingCode',\n onClick: handleImageDownload,\n text: 'Calling Code herunterladen',\n },\n ]\n : []),\n ];\n\n return (\n <ContextMenu\n items={contextMenuItems}\n ref={ref}\n shouldEnableKeyboardHighlighting={shouldEnableKeyboardHighlighting}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...contextMenuProps}\n >\n {children}\n </ContextMenu>\n );\n },\n);\n\nSharingContextMenu.displayName = 'SharingContextMenu';\n\nexport default SharingContextMenu;\n"],"mappings":";AAAA,SAASA,OAAO,QAAQ,YAAY;AACpC,OAAOC,KAAK,IAAIC,UAAU,EAAEC,WAAW,QAAQ,OAAO;AACtD,SAASC,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,UAAU,QAAQ,yBAAyB;AACpD,SAASC,eAAe,EAAEC,YAAY,EAAEC,YAAY,QAAQ,wBAAwB;AACpF,OAAOC,WAAW,MAAM,6BAA6B;AAsBrD,MAAMC,kBAAkB,gBAAGR,UAAU,CACjC,CACI;EACIS,IAAI;EACJC,QAAQ;EACRC,gCAAgC;EAChCC,2BAA2B,GAAG,IAAI;EAClCC,oBAAoB,GAAG,IAAI;EAC3B,GAAGC;AACP,CAAC,EACDC,GAAG,KACF;EACD,MAAMC,OAAO,GAAGb,UAAU,CAAC,CAAC;EAE5B,MAAMc,mBAAmB,GAAGhB,WAAW,CAAC,MAAM;IAC1CK,YAAY;IACR;IACA;IACAJ,aAAa,CAAC,CAAC,CAAC,CAACgB,GAAG,CACfC,OAAO,CAAC,OAAO,EAAEC,kBAAkB,CAACX,IAAI,CAAC,CAAC,CAC1CU,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAC/BA,OAAO,CAAC,SAAS,EAAErB,OAAO,CAAC,CAAC,CAACuB,KAAK,CAACF,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAC5D,C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","invokeCall","isApp","React","forwardRef","useCallback","SHAREPROVIDER","useIsTouch","copyToClipboard","shareWithApp","shareWithUrl","ContextMenu","SharingContextMenu","link","text","children","shouldEnableKeyboardHighlighting","shouldShowCallingCodeAction","shouldShowCopyAction","contextMenuProps","ref","isTouch","shareInApp","provider","shareText","Error","action","value","sharingApp","providerId","androidIdentifier","sharingAndroidApp","handleImageDownload","url","replace","encodeURIComponent","color","handleShare","key","trim","contextMenuItems","icons","onClick","createElement","_extends","items","displayName"],"sources":["../../../../src/components/sharing-context-menu/SharingContextMenu.tsx"],"sourcesContent":["import { getSite, invokeCall, isApp } from 'chayns-api';\nimport React, { forwardRef, useCallback } from 'react';\nimport { SHAREPROVIDER } from '../../constants/sharingBar';\nimport type { SharingBarProvider } from '../../types/sharingBar';\nimport { useIsTouch } from '../../utils/environment';\nimport { copyToClipboard, shareWithApp, shareWithUrl } from '../../utils/sharingBar';\nimport ContextMenu from '../context-menu/ContextMenu';\nimport { ContextMenuProps, ContextMenuRef } from '../context-menu/ContextMenu.types';\n\nexport type SharingContextMenuProps = {\n /**\n * The link that should be shared.\n */\n link: string;\n /**\n * Optional text that is shared together with the link via WhatsApp, mail, and X.\n */\n text?: string;\n /**\n * Shows the action that copies the shared link to the clipboard.\n */\n shouldShowCopyAction?: boolean;\n /**\n * Shows the action that downloads a calling-code image.\n */\n shouldShowCallingCodeAction?: boolean;\n /**\n * Enables keyboard-only focus highlighting for the context menu trigger.\n */\n shouldEnableKeyboardHighlighting?: boolean;\n} & Omit<ContextMenuProps, 'items' | 'shouldEnableKeyboardHighlighting'>;\n\nconst SharingContextMenu = forwardRef<ContextMenuRef, SharingContextMenuProps>(\n (\n {\n link,\n text,\n children,\n shouldEnableKeyboardHighlighting,\n shouldShowCallingCodeAction = true,\n shouldShowCopyAction = true,\n ...contextMenuProps\n },\n ref,\n ) => {\n const isTouch = useIsTouch();\n\n const shareInApp = useCallback(\n (provider: SharingBarProvider | undefined, shareText: string) => {\n if (!provider) {\n throw new Error('The requested sharing provider is not configured.');\n }\n\n void invokeCall({\n action: 80,\n value: {\n text: shareText,\n sharingApp: provider.providerId,\n ...(provider.androidIdentifier\n ? { sharingAndroidApp: provider.androidIdentifier }\n : {}),\n },\n });\n },\n [],\n );\n\n const handleImageDownload = useCallback(() => {\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[5].url\n .replace('{url}', encodeURIComponent(link))\n .replace('{linkText}', 'Teilen')\n .replace('{color}', getSite().color.replace('#', '')),\n );\n }, [link]);\n\n const handleShare = useCallback(\n (key: string) => {\n switch (key) {\n case 'whatsapp': {\n const shareText = text ? `${text}\\n\\n${link}` : `${link}`.trim();\n if (isApp()) {\n shareInApp(SHAREPROVIDER[0], shareText);\n break;\n }\n\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[0].url.replace('{url}', encodeURIComponent(shareText)),\n );\n break;\n }\n case 'facebook':\n if (isApp()) {\n shareInApp(SHAREPROVIDER[3], `${link}`.trim());\n break;\n }\n\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[3].url.replace('{url}', encodeURIComponent(link)),\n );\n break;\n case 'twitter':\n if (isApp()) {\n shareInApp(\n SHAREPROVIDER[4],\n text ? `${text}\\n\\n${link}` : `${link}`.trim(),\n );\n break;\n }\n\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[4].url\n .replace('{url}', encodeURIComponent(link))\n .replace('{linkText}', encodeURIComponent(text ?? '')),\n );\n break;\n case 'mail':\n if (isApp()) {\n shareInApp(\n SHAREPROVIDER[2],\n text ? `${text}\\n\\n${link}` : `${link}`.trim(),\n );\n } else if (isTouch) {\n shareWithApp(text ? `${text}\\n\\n${link}` : `${link}`.trim());\n } else {\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[2].url.replace(\n '{url}',\n encodeURIComponent(\n text ? `${text}\\n\\n${link}` : `${link}`.trim(),\n ),\n ),\n );\n }\n break;\n case 'copy':\n copyToClipboard(link);\n break;\n default:\n break;\n }\n },\n [link, text, isTouch, shareInApp],\n );\n\n const contextMenuItems = [\n ...(shouldShowCopyAction\n ? [\n {\n icons: ['fa fa-copy'],\n key: 'copy',\n onClick: () => handleShare('copy'),\n text: 'Zwischenablage',\n },\n ]\n : []),\n {\n icons: ['fa-solid fa-brands fa-whatsapp'],\n key: 'whatsapp',\n onClick: () => handleShare('whatsapp'),\n text: 'Whatsapp',\n },\n {\n icons: ['fa-solid fa-brands fa-facebook-f'],\n key: 'facebook',\n onClick: () => handleShare('facebook'),\n text: 'Facebook',\n },\n {\n icons: ['fa-solid fa-brands fa-x-twitter'],\n key: 'twitter',\n onClick: () => handleShare('twitter'),\n text: 'X',\n },\n {\n icons: ['fa fa-envelope'],\n key: 'mail',\n onClick: () => handleShare('mail'),\n text: 'Mail',\n },\n ...(shouldShowCallingCodeAction\n ? [\n {\n icons: ['fa fa-qrcode'],\n key: 'callingCode',\n onClick: handleImageDownload,\n text: 'Calling Code herunterladen',\n },\n ]\n : []),\n ];\n\n return (\n <ContextMenu\n items={contextMenuItems}\n ref={ref}\n shouldEnableKeyboardHighlighting={shouldEnableKeyboardHighlighting}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...contextMenuProps}\n >\n {children}\n </ContextMenu>\n );\n },\n);\n\nSharingContextMenu.displayName = 'SharingContextMenu';\n\nexport default SharingContextMenu;\n"],"mappings":";AAAA,SAASA,OAAO,EAAEC,UAAU,EAAEC,KAAK,QAAQ,YAAY;AACvD,OAAOC,KAAK,IAAIC,UAAU,EAAEC,WAAW,QAAQ,OAAO;AACtD,SAASC,aAAa,QAAQ,4BAA4B;AAE1D,SAASC,UAAU,QAAQ,yBAAyB;AACpD,SAASC,eAAe,EAAEC,YAAY,EAA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E;EACV,CAAC,EACD;IACI2B,KAAK,EAAE,CAAC,iCAAiC,CAAC;IAC1CH,GAAG,EAAE,SAAS;IACdI,OAAO,EAAEA,CAAA,KAAML,WAAW,CAAC,SAAS,CAAC;IACrCvB,IAAI,EAAE;EACV,CAAC,EACD;IACI2B,KAAK,EAAE,CAAC,gBAAgB,CAAC;IACzBH,GAAG,EAAE,MAAM;IACXI,OAAO,EAAEA,CAAA,KAAML,WAAW,CAAC,MAAM,CAAC;IAClCvB,IAAI,EAAE;EACV,CAAC,EACD,IAAIG,2BAA2B,GACzB,CACI;IACIwB,KAAK,EAAE,CAAC,cAAc,CAAC;IACvBH,GAAG,EAAE,aAAa;IAClBI,OAAO,EAAEV,mBAAmB;IAC5BlB,IAAI,EAAE;EACV,CAAC,CACJ,GACD,EAAE,CAAC,CACZ;EAED,oBACIX,KAAA,CAAAwC,aAAA,CAAChC,WAAW,EAAAiC,QAAA;IACRC,KAAK,EAAEL,gBAAiB;IACxBpB,GAAG,EAAEA,GAAI;IACTJ,gCAAgC,EAAEA;IAClC;EAAA,GACIG,gBAAgB,GAEnBJ,QACQ,CAAC;AAEtB,CACJ,CAAC;AAEDH,kBAAkB,CAACkC,WAAW,GAAG,oBAAoB;AAErD,eAAelC,kBAAkB","ignoreList":[]}
@@ -1,11 +1,29 @@
1
- import { render } from '@testing-library/react';
1
+ import { fireEvent, render } from '@testing-library/react';
2
2
  import React from 'react';
3
- import { describe, expect, it, vi } from 'vitest';
3
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
4
4
  import SharingContextMenu from './SharingContextMenu';
5
+ const {
6
+ invokeCall,
7
+ isApp,
8
+ shareWithApp,
9
+ shareWithUrl
10
+ } = vi.hoisted(() => ({
11
+ invokeCall: vi.fn(),
12
+ isApp: vi.fn(() => false),
13
+ shareWithApp: vi.fn(),
14
+ shareWithUrl: vi.fn()
15
+ }));
5
16
  vi.mock('chayns-api', () => ({
6
17
  getSite: () => ({
7
18
  color: '#000000'
8
- })
19
+ }),
20
+ invokeCall,
21
+ isApp
22
+ }));
23
+ vi.mock('../../utils/sharingBar', () => ({
24
+ copyToClipboard: vi.fn(),
25
+ shareWithApp,
26
+ shareWithUrl
9
27
  }));
10
28
  vi.mock('../../utils/environment', () => ({
11
29
  useIsTouch: () => false
@@ -16,9 +34,95 @@ vi.mock('../context-menu/ContextMenu', () => ({
16
34
  items
17
35
  }) => /*#__PURE__*/React.createElement("div", {
18
36
  "data-item-keys": items.map(item => item.key).join(',')
19
- }, children)
37
+ }, items.map(item => /*#__PURE__*/React.createElement("button", {
38
+ key: item.key,
39
+ type: "button",
40
+ onClick: item.onClick
41
+ }, item.key)), children)
20
42
  }));
21
43
  describe('SharingContextMenu', () => {
44
+ beforeEach(() => {
45
+ vi.clearAllMocks();
46
+ isApp.mockReturnValue(false);
47
+ });
48
+ it('uses the native share call in the app', () => {
49
+ isApp.mockReturnValue(true);
50
+ const {
51
+ getByRole
52
+ } = render(/*#__PURE__*/React.createElement(SharingContextMenu, {
53
+ link: "https://example.com",
54
+ text: "Check this out"
55
+ }, /*#__PURE__*/React.createElement("button", {
56
+ type: "button"
57
+ }, "Share")));
58
+ fireEvent.click(getByRole('button', {
59
+ name: 'whatsapp'
60
+ }));
61
+ fireEvent.click(getByRole('button', {
62
+ name: 'facebook'
63
+ }));
64
+ fireEvent.click(getByRole('button', {
65
+ name: 'twitter'
66
+ }));
67
+ fireEvent.click(getByRole('button', {
68
+ name: 'mail'
69
+ }));
70
+ expect(invokeCall).toHaveBeenNthCalledWith(1, {
71
+ action: 80,
72
+ value: {
73
+ text: 'Check this out\n\nhttps://example.com',
74
+ sharingApp: 1,
75
+ sharingAndroidApp: 'com.whatsapp'
76
+ }
77
+ });
78
+ expect(invokeCall).toHaveBeenNthCalledWith(2, {
79
+ action: 80,
80
+ value: {
81
+ text: 'https://example.com',
82
+ sharingApp: 2,
83
+ sharingAndroidApp: 'com.facebook.katana'
84
+ }
85
+ });
86
+ expect(invokeCall).toHaveBeenNthCalledWith(3, {
87
+ action: 80,
88
+ value: {
89
+ text: 'Check this out\n\nhttps://example.com',
90
+ sharingApp: 5
91
+ }
92
+ });
93
+ expect(invokeCall).toHaveBeenNthCalledWith(4, {
94
+ action: 80,
95
+ value: {
96
+ text: 'Check this out\n\nhttps://example.com',
97
+ sharingApp: 0
98
+ }
99
+ });
100
+ expect(shareWithApp).not.toHaveBeenCalled();
101
+ expect(shareWithUrl).not.toHaveBeenCalled();
102
+ });
103
+ it('shares the optional text via WhatsApp, mail, and X only', () => {
104
+ const {
105
+ getByRole
106
+ } = render(/*#__PURE__*/React.createElement(SharingContextMenu, {
107
+ link: "https://example.com",
108
+ text: "Check this out"
109
+ }, /*#__PURE__*/React.createElement("button", {
110
+ type: "button"
111
+ }, "Share")));
112
+ fireEvent.click(getByRole('button', {
113
+ name: 'whatsapp'
114
+ }));
115
+ fireEvent.click(getByRole('button', {
116
+ name: 'mail'
117
+ }));
118
+ fireEvent.click(getByRole('button', {
119
+ name: 'twitter'
120
+ }));
121
+ expect(shareWithUrl).toHaveBeenNthCalledWith(1, 'https://api.whatsapp.com/send?text=Check%20this%20out%0A%0Ahttps%3A%2F%2Fexample.com');
122
+ expect(shareWithUrl).toHaveBeenNthCalledWith(2, 'mailto:?body=Check%20this%20out%0A%0Ahttps%3A%2F%2Fexample.com');
123
+ expect(shareWithUrl).toHaveBeenNthCalledWith(3, 'http://twitter.com/intent/tweet?text=Check%20this%20out&url=https%3A%2F%2Fexample.com&hashtags=chayns');
124
+ expect(shareWithApp).not.toHaveBeenCalled();
125
+ });
22
126
  it('keeps copy and calling-code actions enabled by default', () => {
23
127
  const {
24
128
  container
@@ -1 +1 @@
1
- {"version":3,"file":"SharingContextMenu.test.js","names":["render","React","describe","expect","it","vi","SharingContextMenu","mock","getSite","color","useIsTouch","default","children","items","createElement","map","item","key","join","container","link","type","firstChild","getAttribute","toBe","shouldShowCallingCodeAction","shouldShowCopyAction"],"sources":["../../../../src/components/sharing-context-menu/SharingContextMenu.test.tsx"],"sourcesContent":["import { render } from '@testing-library/react';\nimport React, { ReactNode } from 'react';\nimport { describe, expect, it, vi } from 'vitest';\nimport SharingContextMenu from './SharingContextMenu';\n\nvi.mock('chayns-api', () => ({\n getSite: () => ({ color: '#000000' }),\n}));\n\nvi.mock('../../utils/environment', () => ({\n useIsTouch: () => false,\n}));\n\nvi.mock('../context-menu/ContextMenu', () => ({\n default: ({ children, items }: { children: ReactNode; items: Array<{ key: string }> }) => (\n <div data-item-keys={items.map((item) => item.key).join(',')}>{children}</div>\n ),\n}));\n\ndescribe('SharingContextMenu', () => {\n it('keeps copy and calling-code actions enabled by default', () => {\n const { container } = render(\n <SharingContextMenu link=\"https://example.com\">\n <button type=\"button\">Share</button>\n </SharingContextMenu>,\n );\n\n expect((container.firstChild as HTMLElement).getAttribute('data-item-keys')).toBe(\n 'copy,whatsapp,facebook,twitter,mail,callingCode',\n );\n });\n\n it('can hide copy and calling-code actions for dedicated content actions', () => {\n const { container } = render(\n <SharingContextMenu\n link=\"https://example.com\"\n shouldShowCallingCodeAction={false}\n shouldShowCopyAction={false}\n >\n <button type=\"button\">Share</button>\n </SharingContextMenu>,\n );\n\n expect((container.firstChild as HTMLElement).getAttribute('data-item-keys')).toBe(\n 'whatsapp,facebook,twitter,mail',\n );\n });\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,wBAAwB;AAC/C,OAAOC,KAAK,MAAqB,OAAO;AACxC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AACjD,OAAOC,kBAAkB,MAAM,sBAAsB;AAErDD,EAAE,CAACE,IAAI,CAAC,YAAY,EAAE,OAAO;EACzBC,OAAO,EAAEA,CAAA,MAAO;IAAEC,KAAK,EAAE;EAAU,CAAC;AACxC,CAAC,CAAC,CAAC;AAEHJ,EAAE,CAACE,IAAI,CAAC,yBAAyB,EAAE,OAAO;EACtCG,UAAU,EAAEA,CAAA,KAAM;AACtB,CAAC,CAAC,CAAC;AAEHL,EAAE,CAACE,IAAI,CAAC,6BAA6B,EAAE,OAAO;EAC1CI,OAAO,EAAEA,CAAC;IAAEC,QAAQ;IAAEC;EAA8D,CAAC,kBACjFZ,KAAA,CAAAa,aAAA;IAAK,kBAAgBD,KAAK,CAACE,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAACC,GAAG,CAAC,CAACC,IAAI,CAAC,GAAG;EAAE,GAAEN,QAAc;AAErF,CAAC,CAAC,CAAC;AAEHV,QAAQ,CAAC,oBAAoB,EAAE,MAAM;EACjCE,EAAE,CAAC,wDAAwD,EAAE,MAAM;IAC/D,MAAM;MAAEe;IAAU,CAAC,GAAGnB,MAAM,cACxBC,KAAA,CAAAa,aAAA,CAACR,kBAAkB;MAACc,IAAI,EAAC;IAAqB,gBAC1CnB,KAAA,CAAAa,aAAA;MAAQO,IAAI,EAAC;IAAQ,GAAC,OAAa,CACnB,CACxB,CAAC;IAEDlB,MAAM,CAAEgB,SAAS,CAACG,UAAU,CAAiBC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAACC,IAAI,CAC7E,iDACJ,CAAC;EACL,CAAC,CAAC;EAEFpB,EAAE,CAAC,sEAAsE,EAAE,MAAM;IAC7E,MAAM;MAAEe;IAAU,CAAC,GAAGnB,MAAM,cACxBC,KAAA,CAAAa,aAAA,CAACR,kBAAkB;MACfc,IAAI,EAAC,qBAAqB;MAC1BK,2BAA2B,EAAE,KAAM;MACnCC,oBAAoB,EAAE;IAAM,gBAE5BzB,KAAA,CAAAa,aAAA;MAAQO,IAAI,EAAC;IAAQ,GAAC,OAAa,CACnB,CACxB,CAAC;IAEDlB,MAAM,CAAEgB,SAAS,CAACG,UAAU,CAAiBC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAACC,IAAI,CAC7E,gCACJ,CAAC;EACL,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"SharingContextMenu.test.js","names":["fireEvent","render","React","beforeEach","describe","expect","it","vi","SharingContextMenu","invokeCall","isApp","shareWithApp","shareWithUrl","hoisted","fn","mock","getSite","color","copyToClipboard","useIsTouch","default","children","items","createElement","map","item","key","join","type","onClick","clearAllMocks","mockReturnValue","getByRole","link","text","click","name","toHaveBeenNthCalledWith","action","value","sharingApp","sharingAndroidApp","not","toHaveBeenCalled","container","firstChild","getAttribute","toBe","shouldShowCallingCodeAction","shouldShowCopyAction"],"sources":["../../../../src/components/sharing-context-menu/SharingContextMenu.test.tsx"],"sourcesContent":["import { fireEvent, render } from '@testing-library/react';\nimport React, { ReactNode } from 'react';\nimport { beforeEach, describe, expect, it, vi } from 'vitest';\nimport SharingContextMenu from './SharingContextMenu';\n\nconst { invokeCall, isApp, shareWithApp, shareWithUrl } = vi.hoisted(() => ({\n invokeCall: vi.fn(),\n isApp: vi.fn(() => false),\n shareWithApp: vi.fn(),\n shareWithUrl: vi.fn(),\n}));\n\nvi.mock('chayns-api', () => ({\n getSite: () => ({ color: '#000000' }),\n invokeCall,\n isApp,\n}));\n\nvi.mock('../../utils/sharingBar', () => ({\n copyToClipboard: vi.fn(),\n shareWithApp,\n shareWithUrl,\n}));\n\nvi.mock('../../utils/environment', () => ({\n useIsTouch: () => false,\n}));\n\nvi.mock('../context-menu/ContextMenu', () => ({\n default: ({\n children,\n items,\n }: {\n children: ReactNode;\n items: Array<{ key: string; onClick: VoidFunction }>;\n }) => (\n <div data-item-keys={items.map((item) => item.key).join(',')}>\n {items.map((item) => (\n <button key={item.key} type=\"button\" onClick={item.onClick}>\n {item.key}\n </button>\n ))}\n {children}\n </div>\n ),\n}));\n\ndescribe('SharingContextMenu', () => {\n beforeEach(() => {\n vi.clearAllMocks();\n isApp.mockReturnValue(false);\n });\n\n it('uses the native share call in the app', () => {\n isApp.mockReturnValue(true);\n\n const { getByRole } = render(\n <SharingContextMenu link=\"https://example.com\" text=\"Check this out\">\n <button type=\"button\">Share</button>\n </SharingContextMenu>,\n );\n\n fireEvent.click(getByRole('button', { name: 'whatsapp' }));\n fireEvent.click(getByRole('button', { name: 'facebook' }));\n fireEvent.click(getByRole('button', { name: 'twitter' }));\n fireEvent.click(getByRole('button', { name: 'mail' }));\n\n expect(invokeCall).toHaveBeenNthCalledWith(1, {\n action: 80,\n value: {\n text: 'Check this out\\n\\nhttps://example.com',\n sharingApp: 1,\n sharingAndroidApp: 'com.whatsapp',\n },\n });\n expect(invokeCall).toHaveBeenNthCalledWith(2, {\n action: 80,\n value: {\n text: 'https://example.com',\n sharingApp: 2,\n sharingAndroidApp: 'com.facebook.katana',\n },\n });\n expect(invokeCall).toHaveBeenNthCalledWith(3, {\n action: 80,\n value: {\n text: 'Check this out\\n\\nhttps://example.com',\n sharingApp: 5,\n },\n });\n expect(invokeCall).toHaveBeenNthCalledWith(4, {\n action: 80,\n value: {\n text: 'Check this out\\n\\nhttps://example.com',\n sharingApp: 0,\n },\n });\n expect(shareWithApp).not.toHaveBeenCalled();\n expect(shareWithUrl).not.toHaveBeenCalled();\n });\n\n it('shares the optional text via WhatsApp, mail, and X only', () => {\n const { getByRole } = render(\n <SharingContextMenu link=\"https://example.com\" text=\"Check this out\">\n <button type=\"button\">Share</button>\n </SharingContextMenu>,\n );\n\n fireEvent.click(getByRole('button', { name: 'whatsapp' }));\n fireEvent.click(getByRole('button', { name: 'mail' }));\n fireEvent.click(getByRole('button', { name: 'twitter' }));\n\n expect(shareWithUrl).toHaveBeenNthCalledWith(\n 1,\n 'https://api.whatsapp.com/send?text=Check%20this%20out%0A%0Ahttps%3A%2F%2Fexample.com',\n );\n expect(shareWithUrl).toHaveBeenNthCalledWith(\n 2,\n 'mailto:?body=Check%20this%20out%0A%0Ahttps%3A%2F%2Fexample.com',\n );\n expect(shareWithUrl).toHaveBeenNthCalledWith(\n 3,\n 'http://twitter.com/intent/tweet?text=Check%20this%20out&url=https%3A%2F%2Fexample.com&hashtags=chayns',\n );\n expect(shareWithApp).not.toHaveBeenCalled();\n });\n\n it('keeps copy and calling-code actions enabled by default', () => {\n const { container } = render(\n <SharingContextMenu link=\"https://example.com\">\n <button type=\"button\">Share</button>\n </SharingContextMenu>,\n );\n\n expect((container.firstChild as HTMLElement).getAttribute('data-item-keys')).toBe(\n 'copy,whatsapp,facebook,twitter,mail,callingCode',\n );\n });\n\n it('can hide copy and calling-code actions for dedicated content actions', () => {\n const { container } = render(\n <SharingContextMenu\n link=\"https://example.com\"\n shouldShowCallingCodeAction={false}\n shouldShowCopyAction={false}\n >\n <button type=\"button\">Share</button>\n </SharingContextMenu>,\n );\n\n expect((container.firstChild as HTMLElement).getAttribute('data-item-keys')).toBe(\n 'whatsapp,facebook,twitter,mail',\n );\n });\n});\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,MAAM,QAAQ,wBAAwB;AAC1D,OAAOC,KAAK,MAAqB,OAAO;AACxC,SAASC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AAC7D,OAAOC,kBAAkB,MAAM,sBAAsB;AAErD,MAAM;EAAEC,UAAU;EAAEC,KAAK;EAAEC,YAAY;EAAEC;AAAa,CAAC,GAAGL,EAAE,CAACM,OAAO,CAAC,OAAO;EACxEJ,UAAU,EAAEF,EAAE,CAACO,EAAE,CAAC,CAAC;EACnBJ,KAAK,EAAEH,EAAE,CAACO,EAAE,CAAC,MAAM,KAAK,CAAC;EACzBH,YAAY,EAAEJ,EAAE,CAACO,EAAE,CAAC,CAAC;EACrBF,YAAY,EAAEL,EAAE,CAACO,EAAE,CAAC;AACxB,CAAC,CAAC,CAAC;AAEHP,EAAE,CAACQ,IAAI,CAAC,YAAY,EAAE,OAAO;EACzBC,OAAO,EAAEA,CAAA,MAAO;IAAEC,KAAK,EAAE;EAAU,CAAC,CAAC;EACrCR,UAAU;EACVC;AACJ,CAAC,CAAC,CAAC;AAEHH,EAAE,CAACQ,IAAI,CAAC,wBAAwB,EAAE,OAAO;EACrCG,eAAe,EAAEX,EAAE,CAACO,EAAE,CAAC,CAAC;EACxBH,YAAY;EACZC;AACJ,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IAAI,CAC7E,iDACJ,CAAC;EACL,CAAC,CAAC;EAEFzC,EAAE,CAAC,sEAAsE,EAAE,MAAM;IAC7E,MAAM;MAAEsC;IAAU,CAAC,GAAG3C,MAAM,cACxBC,KAAA,CAAAqB,aAAA,CAACf,kBAAkB;MACfyB,IAAI,EAAC,qBAAqB;MAC1Be,2BAA2B,EAAE,KAAM;MACnCC,oBAAoB,EAAE;IAAM,gBAE5B/C,KAAA,CAAAqB,aAAA;MAAQK,IAAI,EAAC;IAAQ,GAAC,OAAa,CACnB,CACxB,CAAC;IAEDvB,MAAM,CAAEuC,SAAS,CAACC,UAAU,CAAiBC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAACC,IAAI,CAC7E,gCACJ,CAAC;EACL,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -13,6 +13,10 @@ export type SharingBarProps = {
13
13
  * The link that should be shared.
14
14
  */
15
15
  link: string;
16
+ /**
17
+ * Optional text that is shared together with the link via WhatsApp, mail, and X.
18
+ */
19
+ text?: string;
16
20
  /**
17
21
  * The alignment of the sharing options.
18
22
  */
@@ -1,6 +1,6 @@
1
1
  import { FunctionComponent, PropsWithChildren } from 'react';
2
2
  import { SharingContextMenuProps } from '../sharing-context-menu/SharingContextMenu';
3
3
  import { ButtonProps } from '../button/Button.types';
4
- export type SharingButtonProps = PropsWithChildren<Pick<SharingContextMenuProps, 'link' | 'alignment' | 'container'> & Pick<ButtonProps, 'isDisabled' | 'shouldEnableKeyboardHighlighting'>>;
4
+ export type SharingButtonProps = PropsWithChildren<Pick<SharingContextMenuProps, 'link' | 'text' | 'alignment' | 'container'> & Pick<ButtonProps, 'isDisabled' | 'shouldEnableKeyboardHighlighting'>>;
5
5
  declare const SharingButton: FunctionComponent<SharingButtonProps>;
6
6
  export default SharingButton;
@@ -5,6 +5,10 @@ export type SharingContextMenuProps = {
5
5
  * The link that should be shared.
6
6
  */
7
7
  link: string;
8
+ /**
9
+ * Optional text that is shared together with the link via WhatsApp, mail, and X.
10
+ */
11
+ text?: string;
8
12
  /**
9
13
  * Shows the action that copies the shared link to the clipboard.
10
14
  */
@@ -23,6 +27,10 @@ declare const SharingContextMenu: React.ForwardRefExoticComponent<{
23
27
  * The link that should be shared.
24
28
  */
25
29
  link: string;
30
+ /**
31
+ * Optional text that is shared together with the link via WhatsApp, mail, and X.
32
+ */
33
+ text?: string;
26
34
  /**
27
35
  * Shows the action that copies the shared link to the clipboard.
28
36
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/core",
3
- "version": "5.6.2",
3
+ "version": "5.6.4",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -93,5 +93,5 @@
93
93
  "publishConfig": {
94
94
  "access": "public"
95
95
  },
96
- "gitHead": "bea270433dc400efc779922b843a42d64c026171"
96
+ "gitHead": "14fd754461f54c94eb03455cabd6c114fc6993f2"
97
97
  }