@pushwoosh/smart-components-kit 1.0.74 → 1.0.76
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/DocsButton/DocsButton.js +14 -13
- package/DocsButton/hooks.d.ts +2 -0
- package/DocsButton/hooks.js +24 -0
- package/DocsButton/index.d.ts +1 -0
- package/DocsButton/index.js +2 -1
- package/DocsButton/types.d.ts +1 -0
- package/package.json +1 -1
package/DocsButton/DocsButton.js
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
19
|
+
const url = useDocsButtonUrl(pathname);
|
|
20
|
+
if (!url) {
|
|
24
21
|
return null;
|
|
25
22
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
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:
|
|
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,24 @@
|
|
|
1
|
+
import { useSPAContext } from '@pushwoosh/spa-context';
|
|
2
|
+
const PUSHWOOSH_DOCS_BASE = 'https://docs.pushwoosh.com';
|
|
3
|
+
const WAVESEND_DOCS_BASE = 'https://docs.pushwoosh.com/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
|
+
}
|
package/DocsButton/index.d.ts
CHANGED
package/DocsButton/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { DocsButton } from './DocsButton';
|
|
1
|
+
export { DocsButton } from './DocsButton';
|
|
2
|
+
export { useIsAllowDocsButton, useDocsButtonUrl } from './hooks';
|
package/DocsButton/types.d.ts
CHANGED
package/package.json
CHANGED