@capillarytech/cap-ui-utils 1.4.6-alpha5.0 → 1.4.6-alpha6.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": "@capillarytech/cap-ui-utils",
3
- "version": "1.4.6-alpha5.0",
3
+ "version": "1.4.6-alpha6.0",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "author": "Rajshekar",
10
10
  "dependencies": {
11
- "@capillarytech/cap-ui-library": "4.0.1",
11
+ "@capillarytech/cap-ui-library": "4.1.15",
12
12
  "prop-types": "^15.8.1",
13
13
  "react": "^16.13.0",
14
14
  "react-ga": "^2.7.0",
@@ -3,6 +3,8 @@ import { ResizableBox } from "react-resizable";
3
3
  import PropTypes from "prop-types";
4
4
  import CapColumn from "@capillarytech/cap-ui-library/CapColumn";
5
5
  import CapIcon from "@capillarytech/cap-ui-library/CapIcon";
6
+ import CapLink from "@capillarytech/cap-ui-library/CapLink";
7
+ import CapHeading from "@capillarytech/cap-ui-library/CapHeading";
6
8
  import CapRow from "@capillarytech/cap-ui-library/CapRow";
7
9
  import Draggable from "react-draggable";
8
10
  import "react-resizable/css/styles.css";
@@ -10,114 +12,125 @@ import "react-resizable/css/styles.css";
10
12
  const ResizablePIP = ({
11
13
  children,
12
14
  width = 400,
13
- height = 260,
15
+ height = 310,
14
16
  showMaximised = false,
15
17
  handleShowMaximised,
16
- minConstraints = [400, 260],
17
- maxConstraints = [1404, 900],
18
+ minConstraints = [400, 310],
19
+ maxConstraints = [1104, 722],
18
20
  closePIPContainer = () => {},
19
- handleOpenInNew = () => {},
20
- PIPPosition = '',
21
+ footerContent = {},
21
22
  }) => {
22
23
  const [pipWidth, setPipWidth] = useState(width);
23
24
  const [pipHeight, setPipHeight] = useState(height);
25
+ const [isHovering, setIsHovering] = useState(false);
26
+ const handleMouseEnter = () => setIsHovering(true);
27
+ const handleMouseLeave = () => setIsHovering(false);
24
28
  const handleMaximiseView = () => {
25
29
  if (!showMaximised) {
26
- setPipWidth(1404);
27
- setPipHeight(730);
30
+ setPipWidth(1104);
31
+ setPipHeight(722);
28
32
  } else {
29
33
  setPipWidth(width);
30
34
  setPipHeight(height);
31
35
  }
32
36
  handleShowMaximised(!showMaximised);
33
37
  };
34
- const positionStyle = {
35
- position: 'relative',
36
- }
37
- switch (PIPPosition) {
38
- case 'topLeft':
39
- positionStyle.left = 8;
40
- positionStyle.top = 8;
41
- break;
42
- case 'topRight':
43
- positionStyle.right = '-70vw';
44
- positionStyle.top = 8;
45
- break;
46
- case 'bottomLeft':
47
- positionStyle.left = 8;
48
- positionStyle.bottom = '-33vw';
49
- break;
50
- case 'bottomRight':
51
- positionStyle.right = '-70vw';
52
- positionStyle.bottom = '-33vw';
53
- break;
54
-
55
- default:
56
- break;
57
- }
38
+
39
+ const handleOpenDoc = () => window.open(footerContent.supportDoc, "_blank");
40
+ console.log("NIKHIL hover: ", isHovering);
41
+ const draggableStyle = {
42
+ position: "relative",
43
+ left: 24,
44
+ // bottom: "-88vh",
45
+ margin: 2,
46
+ border: '1px solid black',
47
+ };
58
48
  return (
59
- <div
60
- style={positionStyle}
49
+ <Draggable
50
+ style={draggableStyle}
61
51
  >
62
- <Draggable>
63
- <div
64
- style={{
65
- backgroundColor: "#242d36",
66
- zIndex: "100000",
67
- position: "fixed",
68
- fontSize: "14px",
69
- fontWeight: "200",
70
- lineHeight: "1.5",
71
- color: "rgb(248, 248, 249)",
72
- boxSizing: "content-box",
73
- boxShadow:
74
- "1px 3px 3px 0 rgb(0 0 0 / 20%), 1px 3px 15px 2px rgb(0 0 0 / 20%)",
75
- borderRadius: "0.28571429rem",
52
+ <div
53
+ style={{
54
+ zIndex: "100000",
55
+ position: "fixed",
56
+ fontSize: "14px",
57
+ fontWeight: "200",
58
+ lineHeight: "1.5",
59
+ boxSizing: "content-box",
60
+ boxShadow:
61
+ "1px 3px 3px 0 rgb(0 0 0 / 20%), 1px 3px 15px 2px rgb(0 0 0 / 20%)",
62
+ borderRadius: 4,
63
+ backgroundColor: "#fff",
64
+ }}
65
+ >
66
+ <ResizableBox
67
+ onMouseDown={(e) => {
68
+ e.stopPropagation();
76
69
  }}
70
+ width={pipWidth}
71
+ height={pipHeight}
72
+ minConstraints={minConstraints}
73
+ maxConstraints={maxConstraints}
77
74
  >
78
- <CapRow>
79
- <CapRow>
80
- <CapColumn span={showMaximised ? 2 : 5} offset={showMaximised ? 22 : 19}>
81
- <CapIcon
82
- onClick={handleMaximiseView}
83
- style={{ marginTop: 8 }}
84
- type="help"
85
- />
86
- <CapIcon
87
- onClick={handleOpenInNew}
88
- style={{ marginTop: 8, marginLeft: 4 }}
89
- type="open-in-new"
90
- />
91
- <CapIcon
92
- onClick={closePIPContainer}
93
- style={{ marginTop: 8, marginLeft: 4 }}
94
- type="close"
95
- />
96
- </CapColumn>
97
- </CapRow>
98
- <CapRow>
99
- <ResizableBox
100
- onMouseDown={(e) => {
101
- e.stopPropagation();
102
- }}
103
- style={{
104
- background: "#202429",
105
- margin: "8px",
106
- borderRadius: "4px",
107
- overflow: "auto",
108
- }}
109
- width={pipWidth}
110
- height={pipHeight}
111
- minConstraints={minConstraints}
112
- maxConstraints={maxConstraints}
113
- >
114
- {children}
115
- </ResizableBox>
116
- </CapRow>
75
+ <div
76
+ style={{
77
+ height: "calc(100% - 56px)",
78
+ opacity: isHovering ? 0.3 : 1,
79
+ color: "#000",
80
+ backgroundColor: "rgba(0, 0, 0, 0.3)",
81
+ transition: "opacity 0.2s ease-in-out",
82
+ }}
83
+ onMouseEnter={handleMouseEnter}
84
+ onMouseLeave={handleMouseLeave}
85
+ >
86
+ {children}
87
+ {isHovering && (
88
+ <>
89
+ <div
90
+ style={{
91
+ float: "right",
92
+ position: "fixed",
93
+ top: 224,
94
+ right: 16,
95
+ }}
96
+ >
97
+ <CapIcon
98
+ onClick={handleMaximiseView}
99
+ size="m"
100
+ type="open-in-new"
101
+ style={{opacity: '1 !important'}}
102
+ />
103
+ </div>
104
+ </>
105
+ )}
106
+ </div>
107
+ <CapRow style={{ height: 56 }}>
108
+ <CapColumn span={17}>
109
+ <CapHeading style={{ margin: 18 }} type="h3">
110
+ {footerContent.videoTitle}
111
+ </CapHeading>
112
+ </CapColumn>
113
+ <CapLink
114
+ style={{
115
+ float: "right",
116
+ margin: "18px 18px 18px 0",
117
+ }}
118
+ onClick={handleOpenDoc}
119
+ title={
120
+ <CapHeading type="h5">
121
+ View docs
122
+ <CapIcon
123
+ onClick={handleOpenDoc}
124
+ size="s"
125
+ type="open-in-new"
126
+ />
127
+ </CapHeading>
128
+ }
129
+ />
117
130
  </CapRow>
118
- </div>
119
- </Draggable>
120
- </div>
131
+ </ResizableBox>
132
+ </div>
133
+ </Draggable>
121
134
  );
122
135
  };
123
136
 
@@ -128,22 +141,8 @@ ResizablePIP.propTypes = {
128
141
  minConstraints: PropTypes.array,
129
142
  maxConstraints: PropTypes.array,
130
143
  closePIPContainer: PropTypes.func,
131
- handleOpenInNew: PropTypes.func,
132
144
  handleShowMaximised: PropTypes.func,
133
145
  showMaximised: PropTypes.bool,
134
- PIPPosition: PropTypes.string,
146
+ footerContent: PropTypes.object,
135
147
  };
136
148
  export default ResizablePIP;
137
-
138
- /** put this is draggable div
139
- * .pipWindow:hover {
140
- cursor: grab;
141
- }
142
- .pipWindow:active {
143
- cursor: grabbing;
144
- outline: -webkit-focus-ring-color auto 1px;
145
- outline-color: -webkit-focus-ring-color;
146
- outline-style: auto;
147
- outline-width: 1px;
148
- }
149
- */
@@ -1,6 +1,6 @@
1
- import React, { useState } from 'react';
2
- import ResizablePIP from './ResizablePIP';
1
+ import React, { useState } from "react";
3
2
  import PropTypes from "prop-types";
3
+ import ResizablePIP from "./ResizablePIP";
4
4
 
5
5
  /** Sample targetElementsData
6
6
  target_elements: {
@@ -45,14 +45,14 @@ import PropTypes from "prop-types";
45
45
  },
46
46
  */
47
47
  const WithDemoVideosAndLinks = (props) => {
48
- const { children, targetElements, locale = 'en'} = props;
48
+ const { children, targetElements, locale = "en" } = props;
49
49
  const [showPIP, setShowPIP] = useState(false);
50
- const [PIPContentLink, setPIPContentLink] = useState('');
51
- const [PIPPosition, setPIPPosition] = useState('');
50
+ const [PIPContentLink, setPIPContentLink] = useState("");
51
+ const [PIPFooterContent, setPIPFooterContent] = useState({});
52
52
  const [showMaximised, setShowMaximised] = useState(false);
53
53
  const cssSelectors = [];
54
54
  if (Object.keys(targetElements || {})?.length) {
55
- Object.keys(targetElements).map(targetElement => {
55
+ Object.keys(targetElements).map((targetElement) => {
56
56
  cssSelectors.push({
57
57
  cssSelector: targetElement,
58
58
  locale,
@@ -61,32 +61,35 @@ const WithDemoVideosAndLinks = (props) => {
61
61
  });
62
62
  }
63
63
 
64
- cssSelectors.forEach(selector => {
64
+ cssSelectors.forEach((selector) => {
65
65
  const {
66
66
  support_link: { target_url: linkTargetUrl = {} } = {},
67
- support_video: { target_url: videoTargetUrl = {}, PIPPosition : videoPIPPosition = 'topLeft' } = {},
67
+ support_video: { target_url: videoTargetUrl = {} } = {},
68
68
  locale,
69
69
  cssSelector,
70
70
  } = selector || {};
71
71
  let matchedNodes = document.querySelectorAll(selector.cssSelector);
72
72
  const handleOnClickVideoLink = () => {
73
73
  setPIPContentLink(videoTargetUrl?.[locale]?.href);
74
- setPIPPosition(videoPIPPosition);
74
+ setPIPFooterContent({
75
+ videoTitle: videoTargetUrl?.[locale]?.videoTitle,
76
+ supportDoc: videoTargetUrl?.[locale]?.supportDoc,
77
+ });
75
78
  setShowPIP(true);
76
79
  };
77
80
  const handleOpenSupportLink = () =>
78
- window.open(linkTargetUrl?.[locale]?.href, '_blank');
81
+ window.open(linkTargetUrl?.[locale]?.href, "_blank");
79
82
 
80
83
  if (selector?.support_video?.target_url?.default?.href) {
81
- matchedNodes.forEach(node => {
84
+ matchedNodes.forEach((node) => {
82
85
  if (!document.getElementById(`demo-video-${cssSelector}`)) {
83
- let videoAnchor = document.createElement('a');
86
+ let videoAnchor = document.createElement("a");
84
87
  videoAnchor.textContent = videoTargetUrl?.[locale].label;
85
88
  videoAnchor.id = `demo-video-${cssSelector}`;
86
- videoAnchor.style.marginLeft = '2px';
89
+ videoAnchor.style.marginLeft = "2px";
87
90
  videoAnchor.onclick = handleOnClickVideoLink;
88
91
 
89
- const videoIconElement = document.createElement('i');
92
+ const videoIconElement = document.createElement("i");
90
93
  videoIconElement.innerHTML = `<svg width="1em" height="1em" viewBox="0 0 24 24" fill="currentColor">
91
94
  <path
92
95
  d="M14.756 11.032a1.194 1.194 0 0 1 0 1.921l-2.937 2.17a1.194 1.194 0 0 1-1.904-.96v-4.34a1.194 1.194 0 0 1 1.904-.96l2.937 2.17zM12 19a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm0 2a9 9 0 1 1 0-18 9 9 0 0 1 0 18z"
@@ -94,26 +97,26 @@ const WithDemoVideosAndLinks = (props) => {
94
97
  ></path>
95
98
  </svg>`;
96
99
  videoIconElement.onclick = handleOnClickVideoLink;
97
- videoIconElement.style.marginLeft = '2px';
98
- videoIconElement.style.cursor = 'pointer';
99
- videoIconElement.style.color = '#2466eb';
100
- videoIconElement.style.fontSize = '18px';
100
+ videoIconElement.style.marginLeft = "2px";
101
+ videoIconElement.style.cursor = "pointer";
102
+ videoIconElement.style.color = "#2466eb";
103
+ videoIconElement.style.fontSize = "18px";
101
104
  node.appendChild(videoIconElement);
102
105
  node.appendChild(videoAnchor);
103
106
  }
104
107
  });
105
108
  } else if (selector?.support_link?.target_url?.default?.href) {
106
- matchedNodes.forEach(node => {
109
+ matchedNodes.forEach((node) => {
107
110
  if (!document.getElementById(`support-link-${cssSelector}`)) {
108
- let linkAnchor = document.createElement('a');
111
+ let linkAnchor = document.createElement("a");
109
112
  linkAnchor.href = linkTargetUrl?.[locale]?.href;
110
113
  linkAnchor.textContent = linkTargetUrl?.[locale].label;
111
- linkAnchor.target = '_blank';
114
+ linkAnchor.target = "_blank";
112
115
  linkAnchor.id = `support-link-${cssSelector}`;
113
- linkAnchor.style.marginLeft = '2px';
116
+ linkAnchor.style.marginLeft = "2px";
114
117
  linkAnchor.onclick = handleOpenSupportLink;
115
118
 
116
- const helpIconElement = document.createElement('i');
119
+ const helpIconElement = document.createElement("i");
117
120
  helpIconElement.innerHTML = `<svg width="1em" height="1em" viewBox="0 0 24 24" fill="currentColor">
118
121
  <path
119
122
  id="help_svg__a"
@@ -121,10 +124,10 @@ const WithDemoVideosAndLinks = (props) => {
121
124
  ></path>
122
125
  </svg>`;
123
126
  helpIconElement.onclick = handleOpenSupportLink;
124
- helpIconElement.style.marginLeft = '2px';
125
- helpIconElement.style.cursor = 'pointer';
126
- helpIconElement.style.fontSize = '16px';
127
- helpIconElement.style.color = '#2466eb';
127
+ helpIconElement.style.marginLeft = "2px";
128
+ helpIconElement.style.cursor = "pointer";
129
+ helpIconElement.style.fontSize = "16px";
130
+ helpIconElement.style.color = "#2466eb";
128
131
 
129
132
  node.appendChild(helpIconElement);
130
133
  node.appendChild(linkAnchor);
@@ -134,16 +137,12 @@ const WithDemoVideosAndLinks = (props) => {
134
137
  });
135
138
 
136
139
  const handleOpenInNew = () => {
137
- window.open(PIPContentLink, '_blank');
140
+ window.open(PIPContentLink, "_blank");
138
141
  };
139
- const handleShowMaximised = value => {
142
+ const handleShowMaximised = (value) => {
140
143
  setShowMaximised(value);
141
144
  };
142
- const handleClosePIPContainer = () => {
143
- setShowPIP(false);
144
- setPIPPosition('');
145
- }
146
-
145
+ const handleClosePIPContainer = () => setShowPIP(false);
147
146
  return (
148
147
  <div>
149
148
  {showPIP && (
@@ -152,15 +151,16 @@ const WithDemoVideosAndLinks = (props) => {
152
151
  handleOpenInNew={handleOpenInNew}
153
152
  handleShowMaximised={handleShowMaximised}
154
153
  showMaximised={showMaximised}
155
- PIPPosition={PIPPosition}
154
+ footerContent={PIPFooterContent}
156
155
  >
157
156
  <iframe
158
157
  width="100%"
159
158
  height="100%"
160
- src={PIPContentLink}
159
+ src={`${PIPContentLink}?controls=0`}
161
160
  title="YouTube video player"
162
161
  frameBorder="0"
163
162
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
163
+ style={{ borderRadius: 4 }}
164
164
  />
165
165
  </ResizablePIP>
166
166
  )}