@pushwoosh/smart-components-kit 1.0.74 → 1.0.75

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.
@@ -1,31 +1,32 @@
1
1
  import React from 'react';
2
2
  import { Button, DrawerDocs, useDocs } from '@pushwoosh/dumb-components';
3
3
  import { DocsIcon } from '@pushwoosh/kit-icons';
4
- import { useSPAContext } from '@pushwoosh/spa-context';
5
- const PUSHWOOSH_DOCS_BASE = 'https://docs.pushwoosh.com';
6
- const WAVESEND_DOCS_BASE = 'https://docs.wavesend.ru';
4
+ import { useDocsButtonUrl } from './hooks';
7
5
  export function DocsButton(props) {
8
6
  const {
9
7
  pathname,
10
8
  children,
11
9
  color = 'secondary',
12
10
  view = 'ghost',
13
- size
11
+ size,
12
+ openInNewWindow = false
14
13
  } = props;
15
- const {
16
- environment
17
- } = useSPAContext();
18
14
  const {
19
15
  docsOpen,
20
16
  openDocsDrawer,
21
17
  closeDocsDrawer
22
18
  } = useDocs();
23
- if (environment.isOMO) {
19
+ const url = useDocsButtonUrl(pathname);
20
+ if (!url) {
24
21
  return null;
25
22
  }
26
- const base = environment.isWavesend ? WAVESEND_DOCS_BASE : PUSHWOOSH_DOCS_BASE;
27
- const normalizedPath = pathname.startsWith('/') ? pathname : `/${pathname}`;
28
- const url = `${base}${normalizedPath}`;
23
+ const handleClick = () => {
24
+ if (openInNewWindow) {
25
+ window.open(url, '_blank', 'noopener,noreferrer');
26
+ return;
27
+ }
28
+ openDocsDrawer();
29
+ };
29
30
  return React.createElement(React.Fragment, null, React.createElement(Button, {
30
31
  "aria-label": "Documentation",
31
32
  color: color,
@@ -35,8 +36,8 @@ export function DocsButton(props) {
35
36
  size: "medium",
36
37
  view: "lined"
37
38
  }),
38
- onClick: openDocsDrawer
39
- }, children), React.createElement(DrawerDocs, {
39
+ onClick: handleClick
40
+ }, children), !openInNewWindow && React.createElement(DrawerDocs, {
40
41
  url: url,
41
42
  isOpen: docsOpen,
42
43
  onClose: closeDocsDrawer
@@ -0,0 +1,2 @@
1
+ export declare function useIsAllowDocsButton(): boolean;
2
+ export declare function useDocsButtonUrl(pathname: string): string;
@@ -0,0 +1,24 @@
1
+ import { useSPAContext } from '@pushwoosh/spa-context';
2
+ const PUSHWOOSH_DOCS_BASE = 'https://docs.pushwoosh.com';
3
+ const WAVESEND_DOCS_BASE = 'https://docs.wavesend.ru';
4
+ export function useIsAllowDocsButton() {
5
+ const {
6
+ environment
7
+ } = useSPAContext();
8
+ return !environment.isOMO;
9
+ }
10
+ export function useDocsButtonUrl(pathname) {
11
+ const {
12
+ environment
13
+ } = useSPAContext();
14
+ const isAllowDocsButton = useIsAllowDocsButton();
15
+ if (!isAllowDocsButton) {
16
+ return '';
17
+ }
18
+ const base = environment.isWavesend ? WAVESEND_DOCS_BASE : PUSHWOOSH_DOCS_BASE;
19
+ if (!pathname) {
20
+ return base;
21
+ }
22
+ const normalizedPath = pathname.startsWith('/') ? pathname : `/${pathname}`;
23
+ return `${base}${normalizedPath}`;
24
+ }
@@ -1,2 +1,3 @@
1
1
  export { DocsButton } from './DocsButton';
2
+ export { useIsAllowDocsButton, useDocsButtonUrl } from './hooks';
2
3
  export type { DocsButtonProps } from './types';
@@ -1 +1,2 @@
1
- export { DocsButton } from './DocsButton';
1
+ export { DocsButton } from './DocsButton';
2
+ export { useIsAllowDocsButton, useDocsButtonUrl } from './hooks';
@@ -5,4 +5,5 @@ export interface DocsButtonProps {
5
5
  color?: 'primary' | 'secondary' | 'danger';
6
6
  size?: 'field' | 'compact';
7
7
  view?: 'shape' | 'ghost';
8
+ openInNewWindow?: boolean;
8
9
  }
package/package.json CHANGED
@@ -48,5 +48,5 @@
48
48
  "react": "^16.14.0 || ^18.0.0",
49
49
  "react-dom": "^16.14.0 || ^18.0.0"
50
50
  },
51
- "version": "1.0.74"
51
+ "version": "1.0.75"
52
52
  }