@thecb/components 5.6.7 → 5.6.9

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": "@thecb/components",
3
- "version": "5.6.7",
3
+ "version": "5.6.9",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -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={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";
@@ -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;
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import styled from "styled-components";
3
+ import { ALTO_GREY } from "../../../constants/colors";
4
+
5
+ export const DashboardIframe = styled.iframe`
6
+ border: none;
7
+ box-shadow: 0 0 5px 0 ${ALTO_GREY};
8
+ display: none;
9
+ `;
@@ -0,0 +1,3 @@
1
+ import PeriscopeDashboardIframe from "./PeriscopeDashboardIframe";
2
+
3
+ export default PeriscopeDashboardIframe;
@@ -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
+ `;
package/src/.DS_Store DELETED
Binary file
Binary file
Binary file
Binary file