@balena/ui-shared-components 0.0.2-build-init-190503048d5b6e69c93a384baff80050fd3ea9bd-1

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.
Files changed (47) hide show
  1. package/README.md +16 -0
  2. package/dist/components/AnimatedText/index.js +55 -0
  3. package/dist/components/ButtonWithTracking/index.js +36 -0
  4. package/dist/components/Code/index.js +34 -0
  5. package/dist/components/CollapsedList/index.js +32 -0
  6. package/dist/components/CustomHelmet/index.js +10 -0
  7. package/dist/components/DropDownButton/index.js +64 -0
  8. package/dist/components/LimitedRowImages/index.js +28 -0
  9. package/dist/components/LinkWithTracking/index.js +43 -0
  10. package/dist/components/Map/index.js +125 -0
  11. package/dist/components/Markdown/index.js +86 -0
  12. package/dist/components/Truncate/index.js +24 -0
  13. package/dist/contexts/AnalyticsContext.js +85 -0
  14. package/dist/index.js +15 -0
  15. package/dist/theme.js +190 -0
  16. package/dist/utils/analytics.js +11 -0
  17. package/dist_esm5/components/AnimatedText/index.d.ts +8 -0
  18. package/dist_esm5/components/AnimatedText/index.js +45 -0
  19. package/dist_esm5/components/ButtonWithTracking/index.d.ts +9 -0
  20. package/dist_esm5/components/ButtonWithTracking/index.js +15 -0
  21. package/dist_esm5/components/Code/index.d.ts +3 -0
  22. package/dist_esm5/components/Code/index.js +13 -0
  23. package/dist_esm5/components/CollapsedList/index.d.ts +10 -0
  24. package/dist_esm5/components/CollapsedList/index.js +22 -0
  25. package/dist_esm5/components/CustomHelmet/index.d.ts +10 -0
  26. package/dist_esm5/components/CustomHelmet/index.js +10 -0
  27. package/dist_esm5/components/DropDownButton/index.d.ts +11 -0
  28. package/dist_esm5/components/DropDownButton/index.js +43 -0
  29. package/dist_esm5/components/LimitedRowImages/index.d.ts +9 -0
  30. package/dist_esm5/components/LimitedRowImages/index.js +18 -0
  31. package/dist_esm5/components/LinkWithTracking/index.d.ts +9 -0
  32. package/dist_esm5/components/LinkWithTracking/index.js +22 -0
  33. package/dist_esm5/components/Map/index.d.ts +31 -0
  34. package/dist_esm5/components/Map/index.js +115 -0
  35. package/dist_esm5/components/Markdown/index.d.ts +3 -0
  36. package/dist_esm5/components/Markdown/index.js +65 -0
  37. package/dist_esm5/components/Truncate/index.d.ts +7 -0
  38. package/dist_esm5/components/Truncate/index.js +14 -0
  39. package/dist_esm5/contexts/AnalyticsContext.d.ts +31 -0
  40. package/dist_esm5/contexts/AnalyticsContext.js +75 -0
  41. package/dist_esm5/index.d.ts +16 -0
  42. package/dist_esm5/index.js +17 -0
  43. package/dist_esm5/theme.d.ts +2 -0
  44. package/dist_esm5/theme.js +190 -0
  45. package/dist_esm5/utils/analytics.d.ts +2 -0
  46. package/dist_esm5/utils/analytics.js +11 -0
  47. package/package.json +82 -0
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Getting Started with Create React App
2
+
3
+ This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4
+
5
+ ## Available Scripts
6
+
7
+ In the project directory, you can run:
8
+
9
+ ### `npm start`
10
+
11
+ Runs the app in the development mode.\
12
+ Open [http://localhost:6060/](http://localhost:6060/) to view it in the browser.
13
+
14
+ ### `npm run build`
15
+
16
+ Builds the app for production to the `build` folder.
@@ -0,0 +1,55 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { Collapse, Fade, Grow, Slide, Typography, Zoom } from '@mui/material';
14
+ import { useEffect, useRef, useState } from 'react';
15
+ export var AnimatedText = function (_a) {
16
+ var words = _a.words, animationType = _a.animationType, _b = _a.animationTimeout, animationTimeout = _b === void 0 ? 4000 : _b;
17
+ var _c = useState(0), wordIndex = _c[0], setWordIndex = _c[1];
18
+ var _d = useState(true), showSlide = _d[0], setSetShowSlide = _d[1];
19
+ var indexInterval = useRef();
20
+ var slideInterval = useRef();
21
+ useEffect(function () {
22
+ var setupTimeouts = function () {
23
+ indexInterval.current = setTimeout(function () {
24
+ setSetShowSlide(false);
25
+ slideInterval.current = setTimeout(function () {
26
+ if (wordIndex + 1 === words.length) {
27
+ setWordIndex(0);
28
+ }
29
+ else {
30
+ setWordIndex(wordIndex + 1);
31
+ }
32
+ setSetShowSlide(true);
33
+ }, animationTimeout - (animationTimeout - 1200));
34
+ }, animationTimeout);
35
+ };
36
+ setupTimeouts();
37
+ return function () {
38
+ clearInterval(indexInterval.current);
39
+ clearInterval(slideInterval.current);
40
+ };
41
+ }, [animationTimeout, wordIndex, words.length]);
42
+ if (animationType === 'grow') {
43
+ return (_jsx(Grow, __assign({ in: showSlide, timeout: { enter: 800, exit: 1200 } }, { children: _jsx(Typography, __assign({ variant: "inherit", component: "div", color: "hubYellow.main" }, { children: words[wordIndex] })) })));
44
+ }
45
+ if (animationType === 'zoom') {
46
+ return (_jsx(Zoom, __assign({ in: showSlide, timeout: { enter: 800, exit: 1200 } }, { children: _jsx(Typography, __assign({ variant: "inherit", component: "div", color: "hubYellow.main" }, { children: words[wordIndex] })) })));
47
+ }
48
+ if (animationType === 'slide') {
49
+ return (_jsx(Slide, __assign({ direction: "down", in: showSlide, timeout: { enter: 800, exit: 1200 } }, { children: _jsx(Typography, __assign({ variant: "inherit", component: "div", color: "hubYellow.main" }, { children: words[wordIndex] })) })));
50
+ }
51
+ if (animationType === 'fade') {
52
+ return (_jsx(Fade, __assign({ in: showSlide, timeout: { enter: 800, exit: 1200 } }, { children: _jsx(Typography, __assign({ variant: "inherit", component: "div", color: "hubYellow.main" }, { children: words[wordIndex] })) })));
53
+ }
54
+ return (_jsx(Collapse, __assign({ orientation: "horizontal", in: showSlide, timeout: { enter: 800, exit: 1200 } }, { children: _jsx(Typography, __assign({ variant: "inherit", component: "div", color: "hubYellow.main", sx: { overflow: 'hidden', whiteSpace: 'nowrap' } }, { children: words[wordIndex] })) })));
55
+ };
@@ -0,0 +1,36 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { jsx as _jsx } from "react/jsx-runtime";
24
+ import { Button } from "@mui/material";
25
+ import { useAnalyticsContext } from "../../contexts/AnalyticsContext";
26
+ export var ButtonWithTracking = function (_a) {
27
+ var eventName = _a.eventName, eventProperties = _a.eventProperties, children = _a.children, onClick = _a.onClick, rest = __rest(_a, ["eventName", "eventProperties", "children", "onClick"]);
28
+ var state = useAnalyticsContext().state;
29
+ var handleClick = function (event) {
30
+ if (state.webTracker) {
31
+ state.webTracker.track(eventName, eventProperties);
32
+ }
33
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
34
+ };
35
+ return (_jsx(Button, __assign({}, rest, { onClick: handleClick, disableElevation: true }, { children: children })));
36
+ };
@@ -0,0 +1,34 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { jsx as _jsx } from "react/jsx-runtime";
24
+ import { Box } from "@mui/material";
25
+ import { theme } from "../../theme";
26
+ export var Code = function (_a) {
27
+ var children = _a.children, props = __rest(_a, ["children"]);
28
+ return (_jsx(Box, __assign({ sx: {
29
+ background: theme.palette.hubGrey.xlight,
30
+ borderRadius: 1,
31
+ }, p: 1, component: "span" }, props, { children: _jsx("code", __assign({ style: {
32
+ color: theme.palette.hubGrey.dark || "#000",
33
+ } }, { children: children })) })));
34
+ };
@@ -0,0 +1,32 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { Avatar, Box, Button, Collapse, Typography } from "@mui/material";
14
+ import { useMemo, useState } from "react";
15
+ import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
16
+ import ArrowDropUpIcon from "@mui/icons-material/ArrowDropUp";
17
+ export var CollapsedList = function (_a) {
18
+ var list = _a.list, _b = _a.collapseItems, collapseItems = _b === void 0 ? 3 : _b;
19
+ var _c = useState(false), showMore = _c[0], setShowMore = _c[1];
20
+ var listItems = useMemo(function () { return (_jsx(Box, __assign({ display: "flex", flexDirection: "column" }, { children: list === null || list === void 0 ? void 0 : list.map(function (item, index) {
21
+ var _a;
22
+ return (_jsxs(Typography, __assign({ variant: "body2", display: "flex", alignItems: "center", my: 1 }, { children: [item.logo && (_jsx(Avatar, { variant: "square", component: "span", alt: item.name, src: (_a = item.logo) !== null && _a !== void 0 ? _a : "", sx: {
23
+ width: "24px",
24
+ height: "24px",
25
+ marginRight: 2,
26
+ } })), item.name] }), index));
27
+ }) }))); }, [list]);
28
+ if (!list) {
29
+ return null;
30
+ }
31
+ return (_jsxs(Box, __assign({ display: "flex", flexDirection: "column", justifyContent: "center" }, { children: [_jsx(Collapse, __assign({ in: showMore, collapsedSize: collapseItems * 33 }, { children: listItems })), list.length > collapseItems && (_jsxs(Button, __assign({ onClick: function () { return setShowMore(!showMore); } }, { children: [showMore ? "Less" : "More", showMore ? _jsx(ArrowDropUpIcon, {}) : _jsx(ArrowDropDownIcon, {})] })))] })));
32
+ };
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Helmet } from "react-helmet";
3
+ export var CustomHelmet = function (_a) {
4
+ var title = _a.title, description = _a.description, properties = _a.properties;
5
+ return (_jsxs(Helmet, { children: [title && _jsx("title", { children: title }), description && _jsx("meta", { name: "description", content: description }), properties &&
6
+ Object.entries(properties).map(function (_a) {
7
+ var propertyKey = _a[0], propertyValue = _a[1];
8
+ return (_jsx("meta", { property: propertyKey, content: propertyValue }));
9
+ })] }));
10
+ };
@@ -0,0 +1,64 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
+ import * as React from "react";
25
+ import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
26
+ import ClickAwayListener from "@mui/material/ClickAwayListener";
27
+ import { Button, ButtonGroup, Tooltip, Grow, Paper, Popper, MenuItem, MenuList, } from "@mui/material";
28
+ import { ButtonWithTracking, } from "../ButtonWithTracking";
29
+ export var DropDownButton = function (_a) {
30
+ var items = _a.items, _b = _a.selectedItemIndex, selectedItemIndex = _b === void 0 ? 0 : _b, onClick = _a.onClick, buttonGroupProps = __rest(_a, ["items", "selectedItemIndex", "onClick"]);
31
+ var _c = React.useState(false), open = _c[0], setOpen = _c[1];
32
+ var anchorRef = React.useRef(null);
33
+ var _d = React.useState(selectedItemIndex), selectedIndex = _d[0], setSelectedIndex = _d[1];
34
+ var handleClick = function (event) {
35
+ var _a, _b;
36
+ return ((_b = (_a = items[selectedIndex]).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event)) ||
37
+ (onClick === null || onClick === void 0 ? void 0 : onClick(event, items[selectedIndex]));
38
+ };
39
+ var handleMenuItemClick = function (index) {
40
+ setSelectedIndex(index);
41
+ setOpen(false);
42
+ };
43
+ var handleToggle = function () {
44
+ setOpen(function (prevOpen) { return !prevOpen; });
45
+ };
46
+ var handleClose = function (event) {
47
+ if (anchorRef.current &&
48
+ anchorRef.current.contains(event.target)) {
49
+ return;
50
+ }
51
+ setOpen(false);
52
+ };
53
+ return (_jsxs(React.Fragment, { children: [_jsxs(ButtonGroup, __assign({ variant: "contained", ref: anchorRef, "aria-label": "split button", disableElevation: true }, buttonGroupProps, { children: [_jsx(Tooltip, __assign({ title: items[selectedIndex].tooltip }, { children: _jsx(ButtonWithTracking, __assign({ onClick: handleClick, eventName: items[selectedIndex].eventName, eventProperties: items[selectedIndex].eventProperties }, { children: items[selectedIndex].children })) })), _jsx(Button, __assign({ size: "small", "aria-controls": open ? "split-button-menu" : undefined, "aria-expanded": open ? "true" : undefined, "aria-label": "actions", "aria-haspopup": "menu", onClick: handleToggle }, { children: _jsx(ArrowDropDownIcon, {}) }))] })), _jsx(Popper, __assign({ sx: {
54
+ zIndex: 1,
55
+ }, open: open, anchorEl: anchorRef.current, role: undefined, transition: true, disablePortal: true }, { children: function (_a) {
56
+ var TransitionProps = _a.TransitionProps, placement = _a.placement;
57
+ return (_jsx(Grow, __assign({}, TransitionProps, { style: {
58
+ transformOrigin: placement === "bottom" ? "center top" : "center bottom",
59
+ } }, { children: _jsx(Paper, { children: _jsx(ClickAwayListener, __assign({ onClickAway: handleClose }, { children: _jsx(MenuList, __assign({ id: "split-button-menu", autoFocusItem: true }, { children: items.map(function (option, index) {
60
+ var _a, _b;
61
+ return (_jsx(Tooltip, __assign({ title: option.tooltip }, { children: _jsx(MenuItem, __assign({ disabled: option.disabled, selected: index === selectedIndex, onClick: function () { return handleMenuItemClick(index); } }, { children: option.children }), (_b = (_a = option.id) !== null && _a !== void 0 ? _a : option.key) !== null && _b !== void 0 ? _b : index) })));
62
+ }) })) })) }) })));
63
+ } }))] }));
64
+ };
@@ -0,0 +1,28 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { Avatar, Box, Typography } from "@mui/material";
14
+ export var LimitedRowImages = function (_a) {
15
+ var items = _a.items, numberBeforeTruncate = _a.numberBeforeTruncate;
16
+ if (!(items === null || items === void 0 ? void 0 : items.length)) {
17
+ return _jsx(_Fragment, { children: "No supported devices" });
18
+ }
19
+ var slicedItems = items.slice(0, numberBeforeTruncate !== null && numberBeforeTruncate !== void 0 ? numberBeforeTruncate : 3);
20
+ return (_jsxs(Box, __assign({ display: "flex", flexDirection: "row", alignItems: "center" }, { children: [slicedItems.map(function (item, index) {
21
+ var _a;
22
+ return (_jsx(Avatar, { variant: "square", alt: item.name, src: (_a = item.logo) !== null && _a !== void 0 ? _a : "", sx: {
23
+ width: 24,
24
+ height: 24,
25
+ marginRight: 1,
26
+ } }, index));
27
+ }), " ", items.length > slicedItems.length && (_jsxs(Typography, __assign({ height: "fit-content", variant: "smallText" }, { children: ["+ ", items.length - slicedItems.length, " more"] })))] })));
28
+ };
@@ -0,0 +1,43 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { jsx as _jsx } from "react/jsx-runtime";
24
+ import { Link } from "react-router-dom";
25
+ import { useAnalyticsContext } from "../../contexts/AnalyticsContext";
26
+ export var LinkWithTracking = function (_a) {
27
+ var eventName = _a.eventName, eventProperties = _a.eventProperties, children = _a.children, onClick = _a.onClick, rest = __rest(_a, ["eventName", "eventProperties", "children", "onClick"]);
28
+ var state = useAnalyticsContext().state;
29
+ var handleClick = function (event) {
30
+ if (!state.webTracker) {
31
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
32
+ return;
33
+ }
34
+ if (eventName) {
35
+ state.webTracker.track(eventName, eventProperties);
36
+ }
37
+ else {
38
+ state.webTracker.trackNavigationClick("".concat(rest.to), eventProperties);
39
+ }
40
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
41
+ };
42
+ return (_jsx(Link, __assign({}, rest, { onClick: handleClick, "data-underline": "false" }, { children: children })));
43
+ };
@@ -0,0 +1,125 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import * as React from 'react';
14
+ import { GoogleMap, LoadScript, Marker } from '@react-google-maps/api';
15
+ import { Box } from '@mui/material';
16
+ // Coordinates of Seattle, avoid having the map centered in the middle of the sea
17
+ var DEFAULT_LATLNG = {
18
+ lat: 47.6062,
19
+ lng: -122.3321,
20
+ };
21
+ var DEFAULT_ZOOM_LEVEL = 3;
22
+ var DETAIL_ZOOM_LEVEL = 12;
23
+ var defaultMapOptions = {
24
+ controlSize: 32,
25
+ scrollwheel: false,
26
+ disableDefaultUI: true,
27
+ zoomControl: true,
28
+ mapTypeControl: false,
29
+ mapTypeControlOptions: {
30
+ mapTypeIds: ['roadmap', 'hybrid'],
31
+ },
32
+ styles: [
33
+ {
34
+ elementType: 'all',
35
+ featureType: 'all',
36
+ stylers: [{ saturation: -50 }],
37
+ },
38
+ {
39
+ elementType: 'all',
40
+ featureType: 'administrative.country',
41
+ stylers: [{ gamma: 2 }],
42
+ },
43
+ {
44
+ elementType: 'all',
45
+ featureType: 'administrative.locality',
46
+ stylers: [{ gamma: 1.5 }],
47
+ },
48
+ ],
49
+ };
50
+ // Return map bounds based on list of markers
51
+ var getMapBounds = function (markers) {
52
+ var bounds = new google.maps.LatLngBounds();
53
+ markers.forEach(function (marker) {
54
+ bounds.extend(new google.maps.LatLng(isNaN(marker.lat) ? 0 : marker.lat, isNaN(marker.lng) ? 0 : marker.lng));
55
+ });
56
+ return bounds;
57
+ };
58
+ // Fit map to its bounds after the api is loaded
59
+ var onGoogleMapsApiLoad = function (map, markers) {
60
+ if (!markers.length) {
61
+ map.setCenter(DEFAULT_LATLNG);
62
+ map.setZoom(DEFAULT_ZOOM_LEVEL);
63
+ }
64
+ else {
65
+ var bounds = getMapBounds(markers);
66
+ map.fitBounds(bounds);
67
+ }
68
+ // These options depend on the global "google" object, so we set it once the API has loaded.
69
+ map.setOptions({
70
+ zoomControlOptions: {
71
+ position: google.maps.ControlPosition.TOP_RIGHT,
72
+ },
73
+ });
74
+ // If we run `setZoom` right after `fitBounds` the map won't refresh. With this we first wait for the map to be idle (from fitBounds), and then set the zoom level.
75
+ var listener = google.maps.event.addListenerOnce(map, 'idle', function () {
76
+ // Don't allow to zoom closer than the defailt detail zoom level on initial load.
77
+ var currentZoom = map.getZoom();
78
+ if (currentZoom != null && currentZoom > DETAIL_ZOOM_LEVEL) {
79
+ map.setZoom(DETAIL_ZOOM_LEVEL);
80
+ }
81
+ google.maps.event.removeListener(listener);
82
+ });
83
+ };
84
+ var getFieldFromMap = function (entry, fieldName, dataMap) {
85
+ if (!dataMap[fieldName]) {
86
+ return undefined;
87
+ }
88
+ if (typeof dataMap[fieldName] === 'string') {
89
+ return entry[dataMap[fieldName]];
90
+ }
91
+ if (typeof dataMap[fieldName] === 'function') {
92
+ return dataMap[fieldName](entry);
93
+ }
94
+ };
95
+ var BaseMap = function (_a) {
96
+ var className = _a.className, _b = _a.data, data = _b === void 0 ? [] : _b, dataMap = _a.dataMap, getIcon = _a.getIcon, onItemClick = _a.onItemClick, apiKey = _a.apiKey, mapClick = _a.mapClick;
97
+ var markers = React.useMemo(function () {
98
+ return data
99
+ .map(function (entry) {
100
+ var marker = {
101
+ lng: getFieldFromMap(entry, 'lng', dataMap),
102
+ lat: getFieldFromMap(entry, 'lat', dataMap),
103
+ id: getFieldFromMap(entry, 'id', dataMap),
104
+ title: getFieldFromMap(entry, 'title', dataMap),
105
+ icon: getIcon ? getIcon(entry) : undefined,
106
+ click: onItemClick ? function () { return onItemClick(entry); } : undefined,
107
+ };
108
+ if (!marker.lng || !marker.lat || !marker.id) {
109
+ return null;
110
+ }
111
+ return marker;
112
+ })
113
+ .filter(function (x) { return !!x; });
114
+ }, [data, dataMap, getIcon, onItemClick]);
115
+ return (_jsx(Box, __assign({ height: "100%", className: className }, { children: apiKey && (_jsx(LoadScript, __assign({ googleMapsApiKey: apiKey, version: "3", language: "en" }, { children: _jsx(GoogleMap, __assign({ mapContainerStyle: {
116
+ height: '100%',
117
+ minHeight: '300px',
118
+ opacity: 1,
119
+ }, options: defaultMapOptions, onLoad: function (map) { return onGoogleMapsApiLoad(map, markers); }, onClick: mapClick }, { children: markers.map(function (marker) { return (_jsx(Marker, { position: {
120
+ lat: isNaN(marker.lat) ? 0 : marker.lat,
121
+ lng: isNaN(marker.lng) ? 0 : marker.lng,
122
+ }, clickable: markers.length > 1, onClick: marker.click, title: marker.title, icon: marker.icon }, marker.id)); }) })) }))) })));
123
+ };
124
+ /** [View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Map/Map.stories.tsx) */
125
+ export var Map = BaseMap;
@@ -0,0 +1,86 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { jsx as _jsx } from "react/jsx-runtime";
24
+ import { ReactMarkdown, } from "react-markdown/lib/react-markdown";
25
+ import remarkGfm from "remark-gfm";
26
+ import rehypeRaw from "rehype-raw";
27
+ import { theme } from "../../theme";
28
+ export var Markdown = function (props) {
29
+ return (_jsx(ReactMarkdown, __assign({ remarkPlugins: [remarkGfm], rehypePlugins: [rehypeRaw], components: {
30
+ img: function (_a) {
31
+ var alt = _a.alt, props = __rest(_a, ["alt"]);
32
+ return _jsx("img", __assign({ style: { maxWidth: "100%" }, alt: alt }, props));
33
+ },
34
+ pre: function (props) {
35
+ return _jsx("pre", __assign({ style: { maxWidth: "100%" } }, props));
36
+ },
37
+ a: function (_a) {
38
+ var children = _a.children, props = __rest(_a, ["children"]);
39
+ return (_jsx("a", __assign({ target: "_blank", rel: "noreferrer", style: {
40
+ textDecoration: "none",
41
+ color: theme.palette.hubBlue.main,
42
+ } }, props, { children: children })));
43
+ },
44
+ code: function (props) {
45
+ return (_jsx("code", __assign({ style: {
46
+ display: "block",
47
+ maxWidth: "100%",
48
+ whiteSpace: "break-spaces",
49
+ fontFamily: "monospace",
50
+ backgroundColor: "#f4f4f4",
51
+ } }, props)));
52
+ },
53
+ table: function (_a) {
54
+ var children = _a.children, props = __rest(_a, ["children"]);
55
+ return (_jsx("table", __assign({ style: {
56
+ borderSpacing: 0,
57
+ borderCollapse: "collapse",
58
+ display: "block",
59
+ width: "100%",
60
+ overflow: "auto",
61
+ } }, props, { children: children })));
62
+ },
63
+ th: function (_a) {
64
+ var children = _a.children, props = __rest(_a, ["children"]);
65
+ return (_jsx("th", __assign({ style: {
66
+ padding: "6px 13px",
67
+ border: "1px solid #ccc",
68
+ } }, props, { children: children })));
69
+ },
70
+ td: function (_a) {
71
+ var children = _a.children, props = __rest(_a, ["children"]);
72
+ return (_jsx("td", __assign({ style: {
73
+ padding: "6px 13px",
74
+ border: "1px solid #ccc",
75
+ } }, props, { children: children })));
76
+ },
77
+ tr: function (_a) {
78
+ var children = _a.children, props = __rest(_a, ["children"]);
79
+ var isNthChild2n = props.node.position.start.line % 2 === 0;
80
+ return (_jsx("tr", __assign({ style: {
81
+ backgroundColor: isNthChild2n ? "#fff" : "#f4f4f4",
82
+ borderTop: "1px solid #eee",
83
+ } }, props, { children: children })));
84
+ },
85
+ } }, props)));
86
+ };
@@ -0,0 +1,24 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { Tooltip, Typography } from '@mui/material';
14
+ export var Truncate = function (_a) {
15
+ var children = _a.children, lineCamp = _a.lineCamp, tooltip = _a.tooltip;
16
+ return (_jsx(Tooltip, __assign({ title: tooltip && typeof children === 'string' ? children : undefined }, { children: _jsx(Typography, __assign({ component: "span", sx: {
17
+ lineHeight: '2rem',
18
+ display: '-webkit-box',
19
+ overflow: 'hidden !important',
20
+ textOverflow: 'ellipsis',
21
+ WebkitLineClamp: lineCamp,
22
+ WebkitBoxOrient: 'vertical',
23
+ } }, { children: children })) })));
24
+ };
@@ -0,0 +1,85 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { AnalyticsUrlParams, createMarketingClient, createWebTracker, } from "analytics-client";
14
+ import { createContext, useContext, useReducer } from "react";
15
+ export var StoreActions;
16
+ (function (StoreActions) {
17
+ StoreActions["setAnalyticsData"] = "set_device_types";
18
+ })(StoreActions || (StoreActions = {}));
19
+ var AnalyticsStateContext = createContext(undefined);
20
+ var urlParamsHandler = new AnalyticsUrlParams();
21
+ var trackBalenaNavigation = function (url) {
22
+ var baseUrl = new URL(url);
23
+ var deviceIdQuery = initialContext.urlParamsHandler.getQueryString(baseUrl);
24
+ if (!baseUrl.search) {
25
+ baseUrl.search = deviceIdQuery;
26
+ }
27
+ else {
28
+ baseUrl.search = baseUrl.search + "&".concat(deviceIdQuery);
29
+ }
30
+ return baseUrl.toString();
31
+ };
32
+ var initialContext = {
33
+ webTracker: null,
34
+ urlParamsHandler: urlParamsHandler,
35
+ trackBalenaNavigation: trackBalenaNavigation,
36
+ };
37
+ var contextReducer = function (state, _a) {
38
+ var _b;
39
+ var type = _a.type, payload = _a.payload;
40
+ switch (type) {
41
+ case StoreActions.setAnalyticsData: {
42
+ var newQuery = (_b = initialContext.urlParamsHandler.consumeUrlParameters(window.location.search)) !== null && _b !== void 0 ? _b : null;
43
+ if (newQuery != null) {
44
+ var newUrl = window.location.pathname + (!!newQuery ? "?".concat(newQuery) : "");
45
+ window.history.replaceState(null, "", newUrl);
46
+ }
47
+ var analyticsClient = payload &&
48
+ "endpoint" in payload &&
49
+ "projectName" in payload &&
50
+ "componentName" in payload &&
51
+ "componentVersion" in payload
52
+ ? createMarketingClient({
53
+ endpoint: payload.endpoint,
54
+ projectName: payload.projectName,
55
+ componentName: payload.componentName,
56
+ deviceId: initialContext.urlParamsHandler.getPassedDeviceId(),
57
+ componentVersion: payload.componentVersion,
58
+ })
59
+ : null;
60
+ var webTracker = analyticsClient && payload && "trackerName" in payload
61
+ ? createWebTracker(analyticsClient, payload.trackerName)
62
+ : null;
63
+ if (analyticsClient) {
64
+ initialContext.urlParamsHandler.setClient(analyticsClient);
65
+ }
66
+ return __assign(__assign({}, state), { webTracker: webTracker, urlParamsHandler: initialContext.urlParamsHandler, trackBalenaNavigation: trackBalenaNavigation });
67
+ }
68
+ default: {
69
+ throw new Error("Unhandled action type: ".concat(type));
70
+ }
71
+ }
72
+ };
73
+ export var AnalyticsContextProvider = function (_a) {
74
+ var children = _a.children;
75
+ var _b = useReducer(contextReducer, initialContext), state = _b[0], dispatch = _b[1];
76
+ var value = { state: state, dispatch: dispatch };
77
+ return (_jsx(AnalyticsStateContext.Provider, __assign({ value: value }, { children: children })));
78
+ };
79
+ export var useAnalyticsContext = function () {
80
+ var context = useContext(AnalyticsStateContext);
81
+ if (context === undefined) {
82
+ throw new Error("useAnalyticsContext must be used within a ContextProvider");
83
+ }
84
+ return context;
85
+ };