beem-component 1.2.7 → 1.3.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.
@@ -1,17 +1,23 @@
1
- import React from "react";
1
+ import React, { useState } from "react";
2
2
  import Proptypes from "prop-types";
3
- import { Error, Info, Warning } from "@material-ui/icons";
3
+ import { Clear, Error, Info, Warning } from "@material-ui/icons";
4
4
  import styled from "styled-components";
5
5
  import {
6
6
  BmGrey400,
7
7
  BmPrimaryBlue,
8
8
  BmSecondaryRed,
9
9
  BmPrimaryGold,
10
+ BmSecondaryGrey,
10
11
  } from "../colors";
11
12
  import { BmIcons } from "../iconStyles";
12
13
 
13
14
  export const NoteBarWrapper = styled.div`
14
- display: flex;
15
+ display: ${({ closeButton, isOpen }) => {
16
+ if (!closeButton) {
17
+ return "flex";
18
+ }
19
+ return isOpen ? "flex" : "none";
20
+ }};
15
21
  flex-direction: row;
16
22
  align-items: center;
17
23
  padding: 0.5rem 1rem;
@@ -22,9 +28,17 @@ export const NoteBarWrapper = styled.div`
22
28
  }
23
29
  `;
24
30
 
25
- export const BmNoteBar = ({ type, children, color, size, ...rest }) => {
31
+ export const BmNoteBar = ({
32
+ type,
33
+ children,
34
+ color,
35
+ size,
36
+ closeButton,
37
+ ...rest
38
+ }) => {
39
+ const [isOpen, setIsOpen] = useState(true);
26
40
  return (
27
- <NoteBarWrapper {...rest}>
41
+ <NoteBarWrapper closeButton={closeButton} isOpen={isOpen} {...rest}>
28
42
  {type === "info" && (
29
43
  <BmIcons
30
44
  icon={<Info />}
@@ -47,6 +61,15 @@ export const BmNoteBar = ({ type, children, color, size, ...rest }) => {
47
61
  />
48
62
  )}
49
63
  {children}
64
+ {closeButton && (
65
+ <BmIcons
66
+ icon={<Clear />}
67
+ color={color ? color : `${BmSecondaryGrey}`}
68
+ size={size ? size : "small"}
69
+ style={{ marginLeft: "auto" }}
70
+ onClick={() => setIsOpen(false)}
71
+ />
72
+ )}
50
73
  </NoteBarWrapper>
51
74
  );
52
75
  };
@@ -56,4 +79,5 @@ BmNoteBar.propTypes = {
56
79
  color: Proptypes.string,
57
80
  size: Proptypes.string,
58
81
  type: Proptypes.string,
82
+ closeButton: Proptypes.bool,
59
83
  };
@@ -26,6 +26,9 @@ export default {
26
26
  description: "Color of the icon ",
27
27
  defaultValue: { summary: undefined },
28
28
  },
29
+ closeButton: {
30
+ description: "If present will allow to close the notebar, default size of the icon is small",
31
+ },
29
32
  },
30
33
  };
31
34
 
@@ -38,3 +41,12 @@ NoteBar.args = {
38
41
  children: <p>NoteBar</p>,
39
42
  color: undefined,
40
43
  };
44
+
45
+ export const NoteBarWithCloseButton = MainNoteBar.bind({});
46
+ NoteBarWithCloseButton.args = {
47
+ type: "warning",
48
+ size: "large",
49
+ children: <p>NoteBar</p>,
50
+ color: undefined,
51
+ closeButton: true,
52
+ };
@@ -0,0 +1,145 @@
1
+ import React, { useEffect, useState, useRef } from "react";
2
+ import PropTypes from "prop-types";
3
+ import styled from "styled-components";
4
+ import {
5
+ BmGrey100,
6
+ BmPrimaryBlue,
7
+ BmSecondaryDarkGreen,
8
+ BmPrimaryGold,
9
+ BmSecondaryRed,
10
+ } from "../colors";
11
+
12
+ const small = 1.429;
13
+ const medium = 1.714;
14
+ const large = 2.286;
15
+
16
+ let center;
17
+ let radius;
18
+ let circumference;
19
+ let strokeWidth = 5;
20
+ let initialSize;
21
+
22
+ const measurement = (size) => {
23
+ let initialSize = size || large * 14;
24
+ if (size === "small") {
25
+ initialSize = small * 14;
26
+ }
27
+ if (size === "medium") {
28
+ initialSize = medium * 14;
29
+ }
30
+ if (size === "large") {
31
+ initialSize = large * 14;
32
+ }
33
+ center = initialSize / 2;
34
+ radius = initialSize / 2 - strokeWidth / 2;
35
+ circumference = 2 * Math.PI * radius;
36
+ return { center, radius, circumference, initialSize };
37
+ };
38
+ const ProgressRingWrapper = styled.svg`
39
+ display: flex;
40
+ width: ${({ size }) => {
41
+ if (size === "small") return "1.429rem";
42
+ if (size === "medium") return "1.714rem";
43
+ if (size === "large") return "2.286rem";
44
+ if (!size) return "2.286rem";
45
+ return `${size}px`;
46
+ }};
47
+ height: ${({ size }) => {
48
+ if (size === "small") return "1.429rem";
49
+ if (size === "medium") return "1.714rem";
50
+ if (size === "large") return "2.286rem";
51
+ if (!size) return "2.286rem";
52
+ return `${size}px`;
53
+ }};
54
+ `;
55
+
56
+ const ProgressRingCircle1 = styled.circle`
57
+ fill: none;
58
+ `;
59
+
60
+ const ProgressRingCircle2 = styled.circle`
61
+ fill: none;
62
+ stroke: ${({ variant, progress }) => {
63
+ if (progress) {
64
+ if (variant === "primary") return `${BmPrimaryBlue}`;
65
+ if (variant === "success") return `${BmSecondaryDarkGreen}`;
66
+ if (variant === "warning") return `${BmPrimaryGold}`;
67
+ if (variant === "danger") return `${BmSecondaryRed}`;
68
+ if (!variant) return `${BmPrimaryBlue}`;
69
+ }
70
+ if (!progress) return `${BmGrey100}`;
71
+ }};
72
+ `;
73
+
74
+ const Text = styled.text`
75
+ font-size: ${() => {
76
+ if (initialSize >= 50 && initialSize < 100) {
77
+ return "1rem";
78
+ }
79
+ if (initialSize >= 100) {
80
+ return "2rem";
81
+ }
82
+ return "0.5rem";
83
+ }};
84
+ text-anchor: middle;
85
+ fill: black;
86
+ `;
87
+
88
+ const BmProgressRing = (props) => {
89
+ const [offset, setOffset] = useState(0);
90
+ const circleRef = useRef(null);
91
+ const { size, progress, variant, children } = props;
92
+
93
+ console.log({ children });
94
+ const initialMeasure = measurement(size);
95
+
96
+ circumference = initialMeasure.circumference;
97
+ radius = initialMeasure.radius;
98
+ center = initialMeasure.center;
99
+ initialSize = initialMeasure.initialSize;
100
+
101
+ useEffect(() => {
102
+ const progressOffset = ((100 - progress) / 100) * circumference;
103
+ setOffset(progressOffset);
104
+
105
+ circleRef.current.style = "transition: stroke-dashoffset 850ms ease-in-out";
106
+ }, [setOffset, progress, offset]);
107
+
108
+ return (
109
+ <>
110
+ <ProgressRingWrapper size={size}>
111
+ <ProgressRingCircle1
112
+ stroke={`${BmGrey100}`}
113
+ cx={center}
114
+ cy={center}
115
+ r={radius}
116
+ strokeWidth={strokeWidth}
117
+ />
118
+
119
+ <Text x={`${center}`} y={`${center}`} size={size}>
120
+ {progress}
121
+ </Text>
122
+ <ProgressRingCircle2
123
+ progress={progress}
124
+ ref={circleRef}
125
+ variant={variant}
126
+ cx={center}
127
+ cy={center}
128
+ r={radius}
129
+ strokeWidth={strokeWidth}
130
+ strokeDasharray={circumference}
131
+ strokeDashoffset={offset}
132
+ data-testid="progress-bar-bar"
133
+ />
134
+ </ProgressRingWrapper>
135
+ </>
136
+ );
137
+ };
138
+
139
+ BmProgressRing.propTypes = {
140
+ size: PropTypes.number.isRequired,
141
+ progress: PropTypes.number.isRequired,
142
+ variant: PropTypes.string,
143
+ };
144
+
145
+ export default BmProgressRing;
@@ -0,0 +1,41 @@
1
+ /* eslint-disable import/no-anonymous-default-export */
2
+ import React from "react";
3
+ import BmProgressRing from "./progressRing";
4
+
5
+ export default {
6
+ component: BmProgressRing,
7
+ title: "components/ProgressRing",
8
+ argTypes: {
9
+ size: {
10
+ options: ["small", "medium", "large"],
11
+ control: { type: "select" },
12
+ description: "Size of the Progress Ring (Can also be predefined e.g. 50)",
13
+ defaultValue: { summary: "large" },
14
+ },
15
+ progress: {
16
+ description: "Progress Indicator",
17
+ },
18
+ variant: {
19
+ options: ["primary", "success", "warning", "danger"],
20
+ control: { type: "select" },
21
+ description: "Color of the Progress Ring",
22
+ defaultValue: { summary: "xsmall" },
23
+ },
24
+ },
25
+ };
26
+
27
+ const MainProgressRing = (args) => <BmProgressRing {...args} />;
28
+
29
+ export const BasicProgressRing = MainProgressRing.bind({});
30
+ BasicProgressRing.args = {
31
+ progress: 30,
32
+ variant: "success",
33
+ size: "xlarge"
34
+ };
35
+
36
+ export const CustomProgressRing = MainProgressRing.bind({});
37
+ CustomProgressRing.args = {
38
+ progress: 50,
39
+ variant: "primary",
40
+ size: "40"
41
+ };
@@ -9,15 +9,12 @@ const BmTabWrapper = styled.div`
9
9
  flex-direction: row;
10
10
  justify-content: center;
11
11
  align-items: center;
12
- padding: 0.714rem 1.714rem;
12
+ padding: 1rem;
13
13
  background: ${BmPrimaryWhite};
14
- box-shadow: ${({ state }) => {
15
- if (state === "active") {
14
+ box-shadow: ${({ state, disabled }) => {
15
+ if (state === "active" && !disabled) {
16
16
  return `inset 0px -3px 0px ${BmPrimaryBlue}`;
17
17
  }
18
- if (state === "inactive") {
19
- return `inset 0px -3px 0px ${BmGrey400}`;
20
- }
21
18
  return "none";
22
19
  }};
23
20
  > *:not(:last-child) {
@@ -35,6 +32,15 @@ const BmTabWrapper = styled.div`
35
32
  color: ${color};
36
33
  }
37
34
  `}
35
+
36
+ &:hover {
37
+ box-shadow: ${({ disabled }) => {
38
+ if (!disabled) {
39
+ return `inset 0px -3px 0px ${BmGrey400}`;
40
+ }
41
+ return "none";
42
+ }};
43
+ }
38
44
  `;
39
45
 
40
46
  export const BmTab = ({
@@ -58,7 +64,7 @@ export const BmTab = ({
58
64
  {leadingIcon && (
59
65
  <BmIcons
60
66
  icon={leadingIcon}
61
- size={size || 'large'}
67
+ size={size || "large"}
62
68
  color={disabled ? `${BmGrey400}` : color}
63
69
  />
64
70
  )}
@@ -66,7 +72,7 @@ export const BmTab = ({
66
72
  {trailingIcon && (
67
73
  <BmIcons
68
74
  icon={trailingIcon}
69
- size={size || 'large'}
75
+ size={size || "large"}
70
76
  color={disabled ? `${BmGrey400}` : color}
71
77
  />
72
78
  )}
@@ -81,4 +87,5 @@ BmTab.propTypes = {
81
87
  state: PropTypes.string,
82
88
  color: PropTypes.string,
83
89
  size: PropTypes.string,
84
- };
90
+ disabled: PropTypes.bool,
91
+ };
@@ -12,7 +12,7 @@ export default {
12
12
  description: "Color of the Icons and Text",
13
13
  },
14
14
  state: {
15
- options: ["active", "inactive"],
15
+ options: ["active"],
16
16
  control: { type: "select" },
17
17
  description: "State of the Tabs (optional)",
18
18
  },
@@ -22,16 +22,28 @@ export default {
22
22
  description: "Size of the icons",
23
23
  defaultValue: { summary: "large" },
24
24
  },
25
+ disabled: {
26
+ description:
27
+ "Disabled tab",
28
+ },
25
29
  },
26
30
  };
27
31
 
28
32
  const MainTab = (args) => <BmTab {...args} />;
29
33
 
30
- export const Tabs = MainTab.bind({});
31
- Tabs.args = {
34
+ export const BasicTab = MainTab.bind({});
35
+ BasicTab.args = {
32
36
  children: <h3>Tabs</h3>,
33
37
  leadingIcon: <Favorite />,
34
38
  trailingIcon: <KeyboardArrowDown />,
35
39
  disabled: false,
36
40
  state: 'active',
37
41
  };
42
+
43
+ export const DisabledTab = MainTab.bind({});
44
+ DisabledTab.args = {
45
+ children: <h3>Disabled Tabs</h3>,
46
+ leadingIcon: <Favorite />,
47
+ trailingIcon: <KeyboardArrowDown />,
48
+ disabled: true,
49
+ };
@@ -18,6 +18,9 @@ import * as BmColors from "./colors";
18
18
  import { BmLoader } from "./Loader/loader";
19
19
  import { BmCheckbox } from "./checkbox";
20
20
  import { BmTag } from "../components/Tags/tags";
21
+ import BmBanner from "../components/BannerCard/bannerCards";
22
+ import BmProgressRing from "./ProgressRing/progressRing";
23
+
21
24
  import {
22
25
  BmTagIcon,
23
26
  BmAvatarIcon,
@@ -72,6 +75,8 @@ export {
72
75
  BmListBox,
73
76
  BmListHeader,
74
77
  BmRowLabel,
78
+ BmBanner,
79
+ BmProgressRing,
75
80
  // Fix height and if there is dropdown option inside the modal body
76
81
  BmModal,
77
82
  BmNoteBar,