@thecb/components 5.6.6 → 5.6.10
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/dist/index.cjs.js +212 -60
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +212 -61
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/atoms/dropdown/Dropdown.js +8 -4
- package/src/components/atoms/form-select/FormSelect.js +3 -1
- package/src/components/atoms/layouts/Box.js +8 -2
- package/src/components/molecules/index.js +1 -0
- package/src/components/molecules/periscope-dashboard-iframe/PeriscopeDashBoardIframe.stories.js +22 -0
- package/src/components/molecules/periscope-dashboard-iframe/PeriscopeDashboardIframe.js +124 -0
- package/src/components/molecules/periscope-dashboard-iframe/PeriscopeDashboardIframe.styled.js +9 -0
- package/src/components/molecules/periscope-dashboard-iframe/index.js +3 -0
- package/src/util/general.js +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thecb/components",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.10",
|
|
4
4
|
"description": "Common lib for CityBase react components",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -85,6 +85,6 @@
|
|
|
85
85
|
"ramda": "^0.27.0",
|
|
86
86
|
"react-aria-modal": "^4.0.0",
|
|
87
87
|
"react-pose": "^4.0.10",
|
|
88
|
-
"redux-freeform": "^5.
|
|
88
|
+
"redux-freeform": "^5.4.0"
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -92,7 +92,8 @@ const Dropdown = ({
|
|
|
92
92
|
themeValues,
|
|
93
93
|
maxHeight,
|
|
94
94
|
widthFitOptions = false,
|
|
95
|
-
disabled
|
|
95
|
+
disabled,
|
|
96
|
+
hasTitles = false
|
|
96
97
|
}) => {
|
|
97
98
|
const [inputValue, setInputValue] = useState("");
|
|
98
99
|
const [optionsState, setOptionsState] = useState([]);
|
|
@@ -113,6 +114,9 @@ const Dropdown = ({
|
|
|
113
114
|
const optionRefs = useRef([...Array(options.length)].map(() => createRef()));
|
|
114
115
|
const dropdownRef = useRef(null);
|
|
115
116
|
|
|
117
|
+
const getSelection = () =>
|
|
118
|
+
value ? options.find(option => option.value === value)?.text : placeholder;
|
|
119
|
+
|
|
116
120
|
const onKeyDown = e => {
|
|
117
121
|
const { key, keyCode } = e;
|
|
118
122
|
const focus = document.activeElement;
|
|
@@ -210,6 +214,7 @@ const Dropdown = ({
|
|
|
210
214
|
background-color: #f7f7f7;
|
|
211
215
|
pointer-events: none;`
|
|
212
216
|
}
|
|
217
|
+
title={hasTitles ? getSelection() : null}
|
|
213
218
|
>
|
|
214
219
|
<Box
|
|
215
220
|
as="button"
|
|
@@ -253,9 +258,7 @@ const Dropdown = ({
|
|
|
253
258
|
pointer-events: none;`
|
|
254
259
|
}
|
|
255
260
|
>
|
|
256
|
-
{
|
|
257
|
-
? options.find(option => option.value === value)?.text
|
|
258
|
-
: placeholder}
|
|
261
|
+
{getSelection()}
|
|
259
262
|
</Text>
|
|
260
263
|
)}
|
|
261
264
|
<IconWrapper open={isOpen}>
|
|
@@ -287,6 +290,7 @@ const Dropdown = ({
|
|
|
287
290
|
disabled={disabledValues.includes(choice.value)}
|
|
288
291
|
data-qa={choice.text}
|
|
289
292
|
themeValues={themeValues}
|
|
293
|
+
title={hasTitles ? choice.text : null}
|
|
290
294
|
>
|
|
291
295
|
<Text
|
|
292
296
|
variant="p"
|
|
@@ -18,7 +18,8 @@ const FormSelect = ({
|
|
|
18
18
|
dropdownMaxHeight,
|
|
19
19
|
disabledValues,
|
|
20
20
|
disabled,
|
|
21
|
-
themeValues
|
|
21
|
+
themeValues,
|
|
22
|
+
hasTitles = false
|
|
22
23
|
}) => {
|
|
23
24
|
const [open, setOpen] = useState(false);
|
|
24
25
|
const dropdownRef = useRef(null);
|
|
@@ -59,6 +60,7 @@ const FormSelect = ({
|
|
|
59
60
|
<Dropdown
|
|
60
61
|
aria-labelledby={labelTextWhenNoError.replace(/\s+/g, "-")}
|
|
61
62
|
maxHeight={dropdownMaxHeight}
|
|
63
|
+
hasTitles={hasTitles}
|
|
62
64
|
placeholder={options[0] ? options[0].text : ""}
|
|
63
65
|
options={options}
|
|
64
66
|
value={field.rawValue}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React, { Fragment } from "react";
|
|
2
2
|
import { BoxWrapper } from "./Box.styled";
|
|
3
|
-
import { safeChildren } from "../../../util/general";
|
|
3
|
+
import { safeChildren, screenReaderOnlyStyle } from "../../../util/general";
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
Box component to create generic boxes
|
|
7
7
|
Supply padding, border, background, and color values
|
|
8
|
+
|
|
9
|
+
srOnly prop enables special screen-reader style that is used to position content
|
|
10
|
+
completely off screen (only for users of screen readers)
|
|
8
11
|
*/
|
|
9
12
|
|
|
10
13
|
const Box = ({
|
|
@@ -37,6 +40,7 @@ const Box = ({
|
|
|
37
40
|
theme,
|
|
38
41
|
hiddenStyles,
|
|
39
42
|
extraStyles,
|
|
43
|
+
srOnly = false,
|
|
40
44
|
dataQa,
|
|
41
45
|
children,
|
|
42
46
|
...rest
|
|
@@ -63,7 +67,9 @@ const Box = ({
|
|
|
63
67
|
onClick={onClick}
|
|
64
68
|
hiddenStyles={hiddenStyles}
|
|
65
69
|
onKeyDown={onKeyDown}
|
|
66
|
-
extraStyles={
|
|
70
|
+
extraStyles={
|
|
71
|
+
srOnly ? `${screenReaderOnlyStyle}${extraStyles}` : extraStyles
|
|
72
|
+
}
|
|
67
73
|
theme={theme}
|
|
68
74
|
textAlign={textAlign}
|
|
69
75
|
data-qa={dataQa}
|
|
@@ -33,3 +33,4 @@ export { default as TermsAndConditionsModal } from "./terms-and-conditions-modal
|
|
|
33
33
|
export { default as Timeout } from "./timeout";
|
|
34
34
|
export { default as WelcomeModule } from "./welcome-module";
|
|
35
35
|
export { default as WorkflowTile } from "./workflow-tile";
|
|
36
|
+
export { default as PeriscopeDashboardIframe } from "./periscope-dashboard-iframe";
|
package/src/components/molecules/periscope-dashboard-iframe/PeriscopeDashBoardIframe.stories.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import PeriscopeDashboardIframe from "./PeriscopeDashboardIframe";
|
|
3
|
+
import page from "../../../../.storybook/page";
|
|
4
|
+
import { boolean } from "@storybook/addon-knobs";
|
|
5
|
+
|
|
6
|
+
export const periscopeDashboardIframe = () => (
|
|
7
|
+
<PeriscopeDashboardIframe
|
|
8
|
+
url={"www.example.com"}
|
|
9
|
+
requestDashboardUrl={() => {}}
|
|
10
|
+
periscopeDataPending={boolean("dataPending", true)}
|
|
11
|
+
periscopeDataSuccess={boolean("dataSuccess", false)}
|
|
12
|
+
periscopeDataFailure={boolean("dataFailure", false)}
|
|
13
|
+
periscopeDataRequestSuccess={boolean("requestSuccess", false)}
|
|
14
|
+
periscopeDataRequestFailure={boolean("requestFailure", false)}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const story = page({
|
|
19
|
+
title: "Components|Molecules/PeriscopeDashboardIframe",
|
|
20
|
+
Component: PeriscopeDashboardIframe
|
|
21
|
+
});
|
|
22
|
+
export default story;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React, { useLayoutEffect, useState, useEffect, Fragment } from "react";
|
|
2
|
+
import {
|
|
3
|
+
BoxWithShadow,
|
|
4
|
+
Center,
|
|
5
|
+
Box,
|
|
6
|
+
PeriscopeFailedIcon,
|
|
7
|
+
Heading,
|
|
8
|
+
Paragraph,
|
|
9
|
+
Cover,
|
|
10
|
+
Spinner
|
|
11
|
+
} from "../../atoms";
|
|
12
|
+
import { DashboardIframe } from "./PeriscopeDashboardIframe.styled";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Component: PeriscopeDashboardIframe
|
|
16
|
+
*
|
|
17
|
+
* Used for rendering Citybase's periscope reporting dashboards in iframes.
|
|
18
|
+
* Receives action props to trigger a request on mount for the iframe's url.
|
|
19
|
+
* Receives a string prop if/when we receive the url result.
|
|
20
|
+
* And receives action props to emit errors from failed iframe loading.
|
|
21
|
+
*
|
|
22
|
+
* The logic and api client methods to handle requests/response,
|
|
23
|
+
* store the url, etc. should be provided from the app consuming this library.
|
|
24
|
+
*
|
|
25
|
+
* If the url request is pending, render a spinner.
|
|
26
|
+
* If the url request failed, render a UI error state.
|
|
27
|
+
**/
|
|
28
|
+
|
|
29
|
+
const DASHBOARD_SIZE_MESSAGE_TYPE = "dashboard_resize";
|
|
30
|
+
const PERISCOPE_ORIGIN = "https://app.periscopedata.com";
|
|
31
|
+
const isValidMessage = message =>
|
|
32
|
+
message.isTrusted &&
|
|
33
|
+
message.origin === PERISCOPE_ORIGIN &&
|
|
34
|
+
message.data &&
|
|
35
|
+
message.data.event_type === DASHBOARD_SIZE_MESSAGE_TYPE;
|
|
36
|
+
|
|
37
|
+
const PeriscopeDashboardIframe = ({
|
|
38
|
+
url,
|
|
39
|
+
requestDashboardUrl,
|
|
40
|
+
periscopeDataPending,
|
|
41
|
+
periscopeDataSuccess,
|
|
42
|
+
periscopeDataFailure,
|
|
43
|
+
periscopeDataRequestSuccess,
|
|
44
|
+
periscopeDataRequestFailure
|
|
45
|
+
}) => {
|
|
46
|
+
const [height, setHeight] = useState(0);
|
|
47
|
+
let time = { timer: null };
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
time.timer = setTimeout(() => {
|
|
51
|
+
periscopeDataRequestFailure();
|
|
52
|
+
}, 10000);
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
const Dashboard = height => url => (
|
|
56
|
+
<DashboardIframe
|
|
57
|
+
src={url}
|
|
58
|
+
width="100%"
|
|
59
|
+
height={height}
|
|
60
|
+
data-qa="DashboardIframe"
|
|
61
|
+
onLoad={() => {
|
|
62
|
+
let iframe = document.querySelector("iframe");
|
|
63
|
+
iframe.style.display = "initial";
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const validatePeriscope = message => {
|
|
69
|
+
if (isValidMessage(message)) {
|
|
70
|
+
setHeight(message.data.dashboard_height + 100);
|
|
71
|
+
clearTimeout(time.timer);
|
|
72
|
+
periscopeDataRequestSuccess();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
useLayoutEffect(() => {
|
|
77
|
+
window.addEventListener("message", validatePeriscope);
|
|
78
|
+
requestDashboardUrl();
|
|
79
|
+
return () => window.removeEventListener("message", validatePeriscope);
|
|
80
|
+
}, [requestDashboardUrl]);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<Fragment>
|
|
84
|
+
<BoxWithShadow
|
|
85
|
+
padding="0"
|
|
86
|
+
minWidth="100%"
|
|
87
|
+
minHeight="592px"
|
|
88
|
+
variant="baseStandard"
|
|
89
|
+
background="#fff"
|
|
90
|
+
borderRadius="4px"
|
|
91
|
+
extraStyles={`display: flex; justify-content: center; align-items: center; flex-direction: column;`}
|
|
92
|
+
>
|
|
93
|
+
{periscopeDataPending && !periscopeDataSuccess && (
|
|
94
|
+
<Cover minHeight="100%" singleChild>
|
|
95
|
+
<Center intrinsic>
|
|
96
|
+
<Spinner size="100" />
|
|
97
|
+
</Center>
|
|
98
|
+
</Cover>
|
|
99
|
+
)}
|
|
100
|
+
{periscopeDataFailure && !periscopeDataSuccess && (
|
|
101
|
+
<Box padding="64px">
|
|
102
|
+
<Center intrinsic>
|
|
103
|
+
<Box padding="0 0 2rem">
|
|
104
|
+
<PeriscopeFailedIcon />
|
|
105
|
+
</Box>
|
|
106
|
+
<Heading variant="h3" weight="700">
|
|
107
|
+
Something Went Wrong
|
|
108
|
+
</Heading>
|
|
109
|
+
<Paragraph variant="p" extraStyles={`text-align: center;`}>
|
|
110
|
+
There was an issue trying to load the dashboard.
|
|
111
|
+
</Paragraph>
|
|
112
|
+
<Paragraph variant="p" extraStyles={`text-align: center;`}>
|
|
113
|
+
Your organization may not have a dashboard configured.
|
|
114
|
+
</Paragraph>
|
|
115
|
+
</Center>
|
|
116
|
+
</Box>
|
|
117
|
+
)}
|
|
118
|
+
{!periscopeDataFailure && url && Dashboard(height)(url)}
|
|
119
|
+
</BoxWithShadow>
|
|
120
|
+
</Fragment>
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export default PeriscopeDashboardIframe;
|
package/src/util/general.js
CHANGED
|
@@ -79,3 +79,20 @@ export const checkDeniedCards = name => {
|
|
|
79
79
|
return "";
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
+
|
|
83
|
+
/*
|
|
84
|
+
An optional style for layout atoms that positions the atom completely off screen
|
|
85
|
+
This will *not* be visible or accessible to sighted users
|
|
86
|
+
Use to contain text content or a11y interactive content (skip links when not visible)
|
|
87
|
+
that is only for users of assistive technologies (screen readers)
|
|
88
|
+
|
|
89
|
+
Currently implemented on the Box atom via the srOnly prop
|
|
90
|
+
*/
|
|
91
|
+
export const screenReaderOnlyStyle = `
|
|
92
|
+
position: absolute;
|
|
93
|
+
left: -10000px;
|
|
94
|
+
top: auto;
|
|
95
|
+
width: 1px;
|
|
96
|
+
height: 1px;
|
|
97
|
+
overflow: hidden;
|
|
98
|
+
`;
|