@capillarytech/cap-ui-utils 1.4.6-alpha4.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-alpha4.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,93 +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
- setShowMaximised,
16
- minConstraints = [400, 260],
17
- maxConstraints = [1404, 900],
17
+ handleShowMaximised,
18
+ minConstraints = [400, 310],
19
+ maxConstraints = [1104, 722],
18
20
  closePIPContainer = () => {},
19
- handleOpenInNew = () => {},
20
- PIPPosition = 'topLeft',
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
- setPipWidth(1404);
26
- setPipHeight(730);
27
- setShowMaximised(!showMaximised);
29
+ if (!showMaximised) {
30
+ setPipWidth(1104);
31
+ setPipHeight(722);
32
+ } else {
33
+ setPipWidth(width);
34
+ setPipHeight(height);
35
+ }
36
+ handleShowMaximised(!showMaximised);
37
+ };
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',
28
47
  };
29
48
  return (
30
- <div
31
- style={{
32
- position: "absolute",
33
- left: 8,
34
- top: -56,
35
- }}
49
+ <Draggable
50
+ style={draggableStyle}
36
51
  >
37
- <Draggable>
38
- <div
39
- style={{
40
- backgroundColor: "#242d36",
41
- zIndex: "100000",
42
- position: "fixed",
43
- fontSize: "14px",
44
- fontWeight: "200",
45
- lineHeight: "1.5",
46
- color: "rgb(248, 248, 249)",
47
- boxSizing: "content-box",
48
- boxShadow:
49
- "1px 3px 3px 0 rgb(0 0 0 / 20%), 1px 3px 15px 2px rgb(0 0 0 / 20%)",
50
- 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();
51
69
  }}
70
+ width={pipWidth}
71
+ height={pipHeight}
72
+ minConstraints={minConstraints}
73
+ maxConstraints={maxConstraints}
52
74
  >
53
- <CapRow>
54
- <CapRow>
55
- <CapColumn span={1} offset={18}>
56
- <CapIcon
57
- onClick={handleMaximiseView}
58
- style={{ marginTop: "8px" }}
59
- type="help"
60
- />
61
- </CapColumn>
62
- <CapColumn span={1} offset={1}>
63
- <CapIcon
64
- onClick={handleOpenInNew}
65
- style={{ marginTop: "8px" }}
66
- type="open-in-new"
67
- />
68
- </CapColumn>
69
- <CapColumn span={1} offset={1}>
70
- <CapIcon
71
- onClick={closePIPContainer}
72
- style={{ marginTop: "8px" }}
73
- type="close"
74
- />
75
- </CapColumn>
76
- </CapRow>
77
- <CapRow>
78
- <ResizableBox
79
- onMouseDown={(e) => {
80
- e.stopPropagation();
81
- }}
82
- style={{
83
- background: "#202429",
84
- margin: "8px",
85
- borderRadius: "4px",
86
- overflow: "auto",
87
- }}
88
- width={pipWidth}
89
- height={pipHeight}
90
- minConstraints={minConstraints}
91
- maxConstraints={maxConstraints}
92
- >
93
- {children}
94
- </ResizableBox>
95
- </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
+ />
96
130
  </CapRow>
97
- </div>
98
- </Draggable>
99
- </div>
131
+ </ResizableBox>
132
+ </div>
133
+ </Draggable>
100
134
  );
101
135
  };
102
136
 
@@ -107,22 +141,8 @@ ResizablePIP.propTypes = {
107
141
  minConstraints: PropTypes.array,
108
142
  maxConstraints: PropTypes.array,
109
143
  closePIPContainer: PropTypes.func,
110
- handleOpenInNew: PropTypes.func,
111
- setShowMaximised: PropTypes.func,
144
+ handleShowMaximised: PropTypes.func,
112
145
  showMaximised: PropTypes.bool,
113
- PIPPosition: PropTypes.string,
146
+ footerContent: PropTypes.object,
114
147
  };
115
148
  export default ResizablePIP;
116
-
117
- /** put this is draggable div
118
- * .pipWindow:hover {
119
- cursor: grab;
120
- }
121
- .pipWindow:active {
122
- cursor: grabbing;
123
- outline: -webkit-focus-ring-color auto 1px;
124
- outline-color: -webkit-focus-ring-color;
125
- outline-style: auto;
126
- outline-width: 1px;
127
- }
128
- */
@@ -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('topLeft');
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
+ setPIPFooterContent({
75
+ videoTitle: videoTargetUrl?.[locale]?.videoTitle,
76
+ supportDoc: videoTargetUrl?.[locale]?.supportDoc,
77
+ });
74
78
  setShowPIP(true);
75
- setPIPPosition(videoPIPPosition);
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,13 +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 = () => {
140
- setShowMaximised(!showMaximised);
142
+ const handleShowMaximised = (value) => {
143
+ setShowMaximised(value);
141
144
  };
142
145
  const handleClosePIPContainer = () => setShowPIP(false);
143
-
144
146
  return (
145
147
  <div>
146
148
  {showPIP && (
@@ -149,15 +151,16 @@ const WithDemoVideosAndLinks = (props) => {
149
151
  handleOpenInNew={handleOpenInNew}
150
152
  handleShowMaximised={handleShowMaximised}
151
153
  showMaximised={showMaximised}
152
- PIPPosition={PIPPosition}
154
+ footerContent={PIPFooterContent}
153
155
  >
154
156
  <iframe
155
157
  width="100%"
156
158
  height="100%"
157
- src={PIPContentLink}
159
+ src={`${PIPContentLink}?controls=0`}
158
160
  title="YouTube video player"
159
161
  frameBorder="0"
160
162
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
163
+ style={{ borderRadius: 4 }}
161
164
  />
162
165
  </ResizablePIP>
163
166
  )}