@bigmath-ui-library/core 2.0.4

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 (229) hide show
  1. package/LICENSE +7 -0
  2. package/LICENSE.md +1 -0
  3. package/README.md +42 -0
  4. package/dist/cjs/index.css +11 -0
  5. package/dist/cjs/index.js +134365 -0
  6. package/dist/esm/index.css +11 -0
  7. package/dist/esm/index.js +134258 -0
  8. package/package.json +58 -0
  9. package/rollup.config.js +73 -0
  10. package/src/BMClassnameSetup.ts +3 -0
  11. package/src/assets/icons/Calendar.svg +6 -0
  12. package/src/assets/icons/Close.svg +40 -0
  13. package/src/assets/icons/Default-Loading-Circles.svg +31 -0
  14. package/src/assets/icons/alert.svg +6 -0
  15. package/src/assets/icons/aws.svg +19 -0
  16. package/src/assets/icons/caret-down.svg +3 -0
  17. package/src/assets/icons/check.svg +6 -0
  18. package/src/assets/icons/circle-check-solid.svg +7 -0
  19. package/src/assets/icons/circle-check.svg +6 -0
  20. package/src/assets/icons/circle-selected.svg +3 -0
  21. package/src/assets/icons/circle-unselected.svg +3 -0
  22. package/src/assets/icons/close-basic.svg +3 -0
  23. package/src/assets/icons/close_collapse.svg +3 -0
  24. package/src/assets/icons/copy.svg +3 -0
  25. package/src/assets/icons/drag.svg +3 -0
  26. package/src/assets/icons/expand-more.svg +3 -0
  27. package/src/assets/icons/failed-solid.svg +7 -0
  28. package/src/assets/icons/globe.svg +3 -0
  29. package/src/assets/icons/google-cloud.svg +6 -0
  30. package/src/assets/icons/in-active.svg +4 -0
  31. package/src/assets/icons/info-solid.svg +6 -0
  32. package/src/assets/icons/info.svg +6 -0
  33. package/src/assets/icons/k8s.svg +4 -0
  34. package/src/assets/icons/lock-locked.svg +5 -0
  35. package/src/assets/icons/microsoft-azure.svg +9 -0
  36. package/src/assets/icons/onprem.svg +3 -0
  37. package/src/assets/icons/pencil.svg +3 -0
  38. package/src/assets/icons/search.svg +6 -0
  39. package/src/assets/icons/shield.svg +4 -0
  40. package/src/assets/icons/star.svg +3 -0
  41. package/src/assets/icons/success-tick.svg +3 -0
  42. package/src/assets/icons/timer.svg +3 -0
  43. package/src/assets/icons/visibility-off.svg +6 -0
  44. package/src/assets/icons/visibility.svg +6 -0
  45. package/src/assets/icons/warning.svg +6 -0
  46. package/src/bma/components/BMButton/BMButton.tsx +34 -0
  47. package/src/bma/components/BMButton/index.ts +1 -0
  48. package/src/bma/components/BMInput/BMInput.tsx +13 -0
  49. package/src/bma/components/BMInput/BMInputField.tsx +7 -0
  50. package/src/bma/components/BMInput/BMSearch.tsx +6 -0
  51. package/src/bma/components/BMInput/index.ts +3 -0
  52. package/src/bma/index.ts +3 -0
  53. package/src/bma/package.json +4 -0
  54. package/src/bma/theme/BMAutocomplete.ts +12 -0
  55. package/src/bma/theme/BMInput.ts +46 -0
  56. package/src/bma/theme/theme.ts +15 -0
  57. package/src/bma/theme/themeUtils.ts +10 -0
  58. package/src/components/BMAccordion/BMAccordion.tsx +150 -0
  59. package/src/components/BMAccordion/index.ts +1 -0
  60. package/src/components/BMAddSection/BMAddSection.tsx +38 -0
  61. package/src/components/BMAddSection/index.ts +1 -0
  62. package/src/components/BMAlert/BMAlert.tsx +168 -0
  63. package/src/components/BMAlert/index.ts +1 -0
  64. package/src/components/BMAutoComplete/BMAutoComplete.tsx +86 -0
  65. package/src/components/BMAutoComplete/index.ts +1 -0
  66. package/src/components/BMAvatar/BMAvatar.tsx +45 -0
  67. package/src/components/BMAvatar/index.ts +1 -0
  68. package/src/components/BMButton/BMButton.tsx +46 -0
  69. package/src/components/BMButton/BMButtonGroup.tsx +46 -0
  70. package/src/components/BMButton/BMSplitButton.tsx +72 -0
  71. package/src/components/BMButton/index.ts +3 -0
  72. package/src/components/BMCheckbox/BMCheckbox.tsx +44 -0
  73. package/src/components/BMCheckbox/BMCheckboxField.tsx +41 -0
  74. package/src/components/BMCheckbox/index.ts +2 -0
  75. package/src/components/BMCloudSelect/BMCloudList.tsx +43 -0
  76. package/src/components/BMCloudSelect/BMCloudSelect.tsx +109 -0
  77. package/src/components/BMCloudSelect/BMCloudSelectField.tsx +46 -0
  78. package/src/components/BMCloudSelect/index.ts +3 -0
  79. package/src/components/BMCodeBlock/BMCodeBlock.tsx +233 -0
  80. package/src/components/BMCodeBlock/index.ts +1 -0
  81. package/src/components/BMDatePicker/BMDatePicker.tsx +187 -0
  82. package/src/components/BMDatePicker/index.ts +1 -0
  83. package/src/components/BMDropdown/BMDropdown.tsx +107 -0
  84. package/src/components/BMDropdown/index.ts +1 -0
  85. package/src/components/BMForm/BMFormControlLabel.tsx +23 -0
  86. package/src/components/BMForm/BMLabel.tsx +24 -0
  87. package/src/components/BMForm/index.ts +2 -0
  88. package/src/components/BMHelloBanner/BMHelloBanner.tsx +68 -0
  89. package/src/components/BMHelloBanner/index.ts +1 -0
  90. package/src/components/BMInput/BMInput.tsx +31 -0
  91. package/src/components/BMInput/BMInputEditableCode.tsx +120 -0
  92. package/src/components/BMInput/BMInputField.tsx +37 -0
  93. package/src/components/BMInput/BMSearch.tsx +17 -0
  94. package/src/components/BMInput/BMStripeInput.tsx +24 -0
  95. package/src/components/BMInput/index.ts +5 -0
  96. package/src/components/BMLoadingBox/BMLoadingBox.tsx +45 -0
  97. package/src/components/BMLoadingBox/index.ts +1 -0
  98. package/src/components/BMMaps/BMMapMarker.css +12 -0
  99. package/src/components/BMMaps/BMMapMarker.tsx +68 -0
  100. package/src/components/BMMaps/BMMaps.tsx +129 -0
  101. package/src/components/BMMaps/MapIcons.tsx +83 -0
  102. package/src/components/BMMaps/icons/GeoPartition.svg +19 -0
  103. package/src/components/BMMaps/icons/GeoPartitionHover.svg +20 -0
  104. package/src/components/BMMaps/icons/MasterPreferred.svg +19 -0
  105. package/src/components/BMMaps/icons/MasterPreferredHover.svg +20 -0
  106. package/src/components/BMMaps/icons/ReadReplica.svg +18 -0
  107. package/src/components/BMMaps/icons/ReadReplicaHover.svg +19 -0
  108. package/src/components/BMMaps/icons/RegionNotSelected.svg +18 -0
  109. package/src/components/BMMaps/icons/RegionNotSelectedHover.svg +19 -0
  110. package/src/components/BMMaps/icons/RegionPreferred.svg +18 -0
  111. package/src/components/BMMaps/icons/RegionPreferredHover.svg +19 -0
  112. package/src/components/BMMaps/icons/RegionSelected.svg +18 -0
  113. package/src/components/BMMaps/icons/RegionSelectedHover.svg +19 -0
  114. package/src/components/BMMaps/index.ts +5 -0
  115. package/src/components/BMMaps/legend/MapLegend.tsx +80 -0
  116. package/src/components/BMMaps/markerTypes.ts +8 -0
  117. package/src/components/BMModal/BMModal.tsx +313 -0
  118. package/src/components/BMModal/index.ts +1 -0
  119. package/src/components/BMMultiEntry/BMMultiEntry.tsx +328 -0
  120. package/src/components/BMMultiEntry/BMMultiEntryField.tsx +47 -0
  121. package/src/components/BMMultiEntry/index.ts +2 -0
  122. package/src/components/BMMultiLevelStepper/BMMultiLevelStepper.tsx +191 -0
  123. package/src/components/BMMultiLevelStepper/index.ts +1 -0
  124. package/src/components/BMPagination/BMPagination.tsx +64 -0
  125. package/src/components/BMPagination/index.ts +1 -0
  126. package/src/components/BMPassword/BMPassword.tsx +37 -0
  127. package/src/components/BMPassword/BMPasswordField.tsx +50 -0
  128. package/src/components/BMPassword/index.ts +2 -0
  129. package/src/components/BMProgress/BMProgress.tsx +43 -0
  130. package/src/components/BMProgress/index.ts +1 -0
  131. package/src/components/BMRadio/BMRadio.tsx +162 -0
  132. package/src/components/BMRadio/BMRadioGroupField.tsx +40 -0
  133. package/src/components/BMRadio/index.ts +2 -0
  134. package/src/components/BMSelect/BMSelect.tsx +70 -0
  135. package/src/components/BMSelect/BMSelectField.tsx +47 -0
  136. package/src/components/BMSelect/index.ts +2 -0
  137. package/src/components/BMSlider/BMSlider.tsx +16 -0
  138. package/src/components/BMSlider/index.ts +1 -0
  139. package/src/components/BMSmartStatus/BMSmartStatus.tsx +185 -0
  140. package/src/components/BMSmartStatus/index.tsx +1 -0
  141. package/src/components/BMStatus/BMStatus.tsx +98 -0
  142. package/src/components/BMStatus/index.ts +1 -0
  143. package/src/components/BMTable/BMTable.tsx +131 -0
  144. package/src/components/BMTable/index.ts +1 -0
  145. package/src/components/BMTabs/BMTabs.tsx +50 -0
  146. package/src/components/BMTabs/index.ts +1 -0
  147. package/src/components/BMTag/BMTag.tsx +47 -0
  148. package/src/components/BMTag/index.ts +1 -0
  149. package/src/components/BMTagv2/BMTagv2.tsx +250 -0
  150. package/src/components/BMTagv2/index.ts +1 -0
  151. package/src/components/BMToggle/BMMultiToggleButton.tsx +99 -0
  152. package/src/components/BMToggle/BMToggle.tsx +35 -0
  153. package/src/components/BMToggle/BMToggleField.tsx +28 -0
  154. package/src/components/BMToggle/index.ts +3 -0
  155. package/src/components/BMTooltip/BMTooltip.tsx +52 -0
  156. package/src/components/BMTooltip/index.ts +1 -0
  157. package/src/components/BMWarning/BMWarning.tsx +39 -0
  158. package/src/components/BMWarning/index.ts +1 -0
  159. package/src/components/GenericFailure/GenericFailure.tsx +28 -0
  160. package/src/components/GenericFailure/index.ts +1 -0
  161. package/src/components/NoAccess/NoAccess.tsx +40 -0
  162. package/src/components/NoAccess/NoAccessActionTooltip.tsx +53 -0
  163. package/src/components/NoAccess/NoPermissionModal.tsx +55 -0
  164. package/src/components/NoAccess/index.ts +3 -0
  165. package/src/components/index.ts +34 -0
  166. package/src/index.ts +9 -0
  167. package/src/theme/BMAutoComplete.ts +152 -0
  168. package/src/theme/BMAvatar.ts +5 -0
  169. package/src/theme/BMButton.ts +132 -0
  170. package/src/theme/BMButtonGroup.ts +49 -0
  171. package/src/theme/BMCheckbox.ts +16 -0
  172. package/src/theme/BMFormHelperText.ts +19 -0
  173. package/src/theme/BMInput.ts +120 -0
  174. package/src/theme/BMMaps.ts +9 -0
  175. package/src/theme/BMRadio.ts +10 -0
  176. package/src/theme/BMTabs.ts +79 -0
  177. package/src/theme/BMTag.ts +28 -0
  178. package/src/theme/BMToggle.ts +50 -0
  179. package/src/theme/BMTooltip.ts +34 -0
  180. package/src/theme/theme.ts +326 -0
  181. package/src/theme/variables.ts +152 -0
  182. package/src/types/custom.d.ts +9 -0
  183. package/src/types/svg.d.ts +5 -0
  184. package/stories/BMAButton.stories.tsx +67 -0
  185. package/stories/BMAccordion.stories.tsx +55 -0
  186. package/stories/BMAddSection.stories.tsx +40 -0
  187. package/stories/BMAlert.stories.tsx +33 -0
  188. package/stories/BMAutoComplete.stories.tsx +65 -0
  189. package/stories/BMAvatar.stories.tsx +76 -0
  190. package/stories/BMButton.stories.tsx +57 -0
  191. package/stories/BMButton2.stories.tsx +131 -0
  192. package/stories/BMCheckbox.stories.tsx +23 -0
  193. package/stories/BMCloudSelectField.stories.tsx +40 -0
  194. package/stories/BMCodeBlock.stories.tsx +57 -0
  195. package/stories/BMDatePicker.stories.tsx +88 -0
  196. package/stories/BMDropdown.stories.tsx +84 -0
  197. package/stories/BMGroupButton.stories.tsx +53 -0
  198. package/stories/BMHelloBanner.stories.tsx +33 -0
  199. package/stories/BMInput.stories.tsx +184 -0
  200. package/stories/BMInputEditableCode.stories.tsx +86 -0
  201. package/stories/BMInputField.stories.tsx +50 -0
  202. package/stories/BMLoadingBox.stories.tsx +45 -0
  203. package/stories/BMMaps.stories.tsx +29 -0
  204. package/stories/BMModal.stories.tsx +218 -0
  205. package/stories/BMMultiEntry.stories.tsx +93 -0
  206. package/stories/BMMultiLevelStepper.stories.tsx +87 -0
  207. package/stories/BMPagination.stories.tsx +41 -0
  208. package/stories/BMPassword.stories.tsx +133 -0
  209. package/stories/BMProgress.stories.tsx +60 -0
  210. package/stories/BMRadio.stories.tsx +71 -0
  211. package/stories/BMSelect.stories.tsx +160 -0
  212. package/stories/BMSlider.stories.tsx +74 -0
  213. package/stories/BMSmartStatus.stories.tsx +98 -0
  214. package/stories/BMSplitButton.stories.tsx +32 -0
  215. package/stories/BMStatus.stories.tsx +29 -0
  216. package/stories/BMTable.stories.tsx +350 -0
  217. package/stories/BMTabs.stories.tsx +25 -0
  218. package/stories/BMTag.stories.tsx +63 -0
  219. package/stories/BMTagv2.stories.tsx +288 -0
  220. package/stories/BMToggle.stories.tsx +123 -0
  221. package/stories/BMTooltip.stories.tsx +59 -0
  222. package/stories/BMTypography.stories.tsx +79 -0
  223. package/stories/BMWarning.stories.tsx +55 -0
  224. package/stories/GenericFailure.stories.tsx +47 -0
  225. package/stories/NoAccess.stories.tsx +19 -0
  226. package/stories/NoAccessActionTooltip.stories.tsx +50 -0
  227. package/stories/NoPermissionModal.stories.tsx +46 -0
  228. package/tsconfig.base.json +21 -0
  229. package/tsconfig.build.json +23 -0
@@ -0,0 +1,3 @@
1
+ export * from "./BMButton";
2
+ export * from "./BMSplitButton";
3
+ export * from './BMButtonGroup';
@@ -0,0 +1,44 @@
1
+ import { type InputProps, Typography, styled } from "@mui/material";
2
+ import Checkbox, { type CheckboxProps } from "@mui/material/Checkbox";
3
+ import { BMFormControlLabel } from "../BMForm/BMFormControlLabel";
4
+
5
+ export interface BMCheckboxProps extends CheckboxProps {
6
+ dataTestId: string;
7
+ label: React.ReactNode;
8
+ labelClassName?: string;
9
+ inputProps?: InputProps["inputProps"];
10
+ }
11
+
12
+ const CheckBoxIcon = styled("span")(({ theme }) => ({
13
+ width: 16,
14
+ height: 16,
15
+ margin: "3.14px",
16
+ borderRadius: "1px",
17
+ boxShadow: `inset 0 0 0 2px ${theme.palette.grey[400]}, inset 0 -1px 0 ${theme.palette.grey[400]}`,
18
+ "input:hover ~ &": {
19
+ background: theme.palette.grey[100],
20
+ },
21
+ "input:disabled ~ &": {
22
+ boxShadow: `inset 0 0 0 2px ${theme.palette.grey[200]}, inset 0 -1px 0 ${theme.palette.grey[200]}`,
23
+ background: theme.palette.grey[100],
24
+ },
25
+ }));
26
+
27
+ export const BMCheckbox: React.FC<BMCheckboxProps> = ({
28
+ label,
29
+ labelClassName,
30
+ dataTestId,
31
+ ...checkboxProps
32
+ }) => {
33
+ return (
34
+ <BMFormControlLabel
35
+ control={<Checkbox {...checkboxProps} data-testid={dataTestId} icon={<CheckBoxIcon />} />}
36
+ label={
37
+ <Typography component="span" variant="body2">
38
+ {label}
39
+ </Typography>
40
+ }
41
+ className={labelClassName}
42
+ />
43
+ );
44
+ };
@@ -0,0 +1,41 @@
1
+ import type { ReactElement } from "react";
2
+ import {
3
+ type FieldValues,
4
+ type UseControllerProps,
5
+ useController,
6
+ } from "react-hook-form";
7
+ import { BMCheckbox, type BMCheckboxProps } from "./BMCheckbox";
8
+
9
+ type BMCheckboxFieldProps<T extends FieldValues> = UseControllerProps<T> &
10
+ BMCheckboxProps;
11
+
12
+ export const BMCheckboxField = <T extends FieldValues>(
13
+ props: BMCheckboxFieldProps<T>,
14
+ ): ReactElement => {
15
+ const {
16
+ name,
17
+ rules,
18
+ defaultValue,
19
+ control,
20
+ shouldUnregister,
21
+ ...bmCheckboxProps
22
+ } = props;
23
+ const { field } = useController({
24
+ name,
25
+ rules,
26
+ defaultValue,
27
+ control,
28
+ shouldUnregister,
29
+ });
30
+
31
+ return (
32
+ <BMCheckbox
33
+ name={field.name}
34
+ inputRef={field.ref}
35
+ checked={!!field.value}
36
+ onBlur={field.onBlur}
37
+ onChange={field.onChange}
38
+ {...bmCheckboxProps}
39
+ />
40
+ );
41
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./BMCheckbox";
2
+ export * from "./BMCheckboxField";
@@ -0,0 +1,43 @@
1
+ import { BMCloudSelectorOption } from "./BMCloudSelect";
2
+ import AWS from '../../assets/icons/aws.svg';
3
+ import GCP from '../../assets/icons/google-cloud.svg';
4
+ import Azure from '../../assets/icons/microsoft-azure.svg';
5
+ import Kubernetes from '../../assets/icons/k8s.svg';
6
+ import OnPrem from '../../assets/icons/onprem.svg';
7
+
8
+ export const AWS_CLOUD_OPTION: BMCloudSelectorOption<string> = {
9
+ label: "AWS",
10
+ icon: <AWS />,
11
+ value: "aws",
12
+ description: "Amazon Web Services",
13
+ visible: true,
14
+ }
15
+
16
+ export const GCP_CLOUD_OPTION: BMCloudSelectorOption<string> = {
17
+ label: "GCP",
18
+ icon: <GCP />,
19
+ value: "gcp",
20
+ description: "Google Cloud Platform",
21
+ visible: true,
22
+ }
23
+ export const AZURE_CLOUD_OPTION: BMCloudSelectorOption<string> = {
24
+ label: "Azure",
25
+ icon: <Azure />,
26
+ value: "azure",
27
+ description: "Microsoft Azure",
28
+ visible: true,
29
+ }
30
+ export const K8S_CLOUD_OPTION: BMCloudSelectorOption<string> = {
31
+ label: "Kubernetes",
32
+ icon: <Kubernetes />,
33
+ value: "k8s",
34
+ description: "Kubernetes",
35
+ visible: true,
36
+ }
37
+ export const ON_PREM_CLOUD_OPTION: BMCloudSelectorOption<string> = {
38
+ label: "On Prem",
39
+ icon: <OnPrem />,
40
+ value: "onprem",
41
+ description: "On Premise",
42
+ visible: true,
43
+ }
@@ -0,0 +1,109 @@
1
+ import { ReactElement, ReactNode } from "react";
2
+ import { Box, styled, Typography } from "@mui/material";
3
+ import { themeVariables } from "../../theme/variables";
4
+ import CheckIcon from "../../assets/icons/circle-selected.svg";
5
+ import CircleIcon from "../../assets/icons/circle-unselected.svg";
6
+
7
+ export interface BMCloudSelectorOption<T> {
8
+ label: string;
9
+ icon: ReactNode;
10
+ description?: string;
11
+ value: T;
12
+ visible: boolean;
13
+ dataTestId?: string;
14
+ }
15
+
16
+ export interface BMCloudSelectorProps<T> {
17
+ label?: ReactNode;
18
+ overrideOptionWidth?: number;
19
+ options: BMCloudSelectorOption<T>[];
20
+ value: T;
21
+ onChange: (value: T) => void;
22
+ }
23
+
24
+
25
+ const Card = styled("div", {
26
+ shouldForwardProp: (prop) => prop !== 'selected' && prop !== 'visible'
27
+ })<{
28
+ selected?: boolean;
29
+ visible?: boolean;
30
+ }>((props) => {
31
+ const { theme, selected, visible } = props;
32
+ return {
33
+ cursor: 'pointer',
34
+ userSelect: 'none',
35
+ width: '200px',
36
+ height: 56,
37
+ display: visible === false ? 'none' : 'flex',
38
+ alignItems: 'center',
39
+ justifyContent: 'space-between',
40
+ flexShrink: 0,
41
+ padding: theme.spacing(0, 1.5),
42
+ border: `1px solid ${theme.palette.grey[200]}`,
43
+ borderRadius: theme.shape.borderRadius,
44
+ marginRight: theme.spacing(1.5),
45
+ '&:last-child': {
46
+ marginRight: 0
47
+ },
48
+ '&:hover': {
49
+ borderColor: theme.palette.primary[300],
50
+ boxShadow: themeVariables.shadowLight
51
+ },
52
+ ...(selected && {
53
+ backgroundColor: theme.palette.primary[100],
54
+ borderColor: theme.palette.primary[300],
55
+ boxShadow: `inset 0 0 0 1px ${theme.palette.primary[300]}`,
56
+ '&:hover': {
57
+ boxShadow: `inset 0 0 0 1px ${theme.palette.primary[300]}, ${themeVariables.shadowLight}`
58
+ }
59
+ })
60
+ };
61
+ });
62
+
63
+ const IconLogo = styled("i")(({ theme }) => ({
64
+ width: '32px',
65
+ height: '32px',
66
+ marginRight: theme.spacing(1)
67
+ }));
68
+
69
+ const CircleCheckIcon = styled(CheckIcon)(({ theme }: { theme: any }) => ({
70
+ color: theme.palette.primary[600],
71
+ height: '24px',
72
+ width: '24px'
73
+ }));
74
+
75
+ const Circle = styled(CircleIcon)(({ theme }) => ({
76
+ color: theme.palette.grey[600]
77
+ }));
78
+
79
+ export const BMCloudSelect = <T,>({
80
+ overrideOptionWidth,
81
+ options,
82
+ value,
83
+ onChange
84
+ }: BMCloudSelectorProps<T>): ReactElement => {
85
+ return (
86
+ <Box display="flex" alignItems="center" flexWrap={"wrap"} rowGap={1} >
87
+ {options.map((item) => (
88
+ <Card
89
+ key={String(item.value)}
90
+ data-testid={item.dataTestId ?? item.value}
91
+ onClick={() => onChange(item.value)}
92
+ selected={value === item.value}
93
+ visible={item.visible}
94
+ style={{ width: overrideOptionWidth }}
95
+ >
96
+ <Box display="flex" alignItems="center">
97
+ <IconLogo>{item.icon}</IconLogo>
98
+ <Typography variant="body1">{item.label}</Typography>
99
+ </Box>
100
+ {value === item.value ? (
101
+ <CircleCheckIcon />
102
+ ) : (
103
+ <Circle />
104
+ )}
105
+ </Card>
106
+ ))}
107
+ </Box>
108
+ );
109
+ };
@@ -0,0 +1,46 @@
1
+ import { ReactElement } from "react";
2
+ import { FormHelperText } from "@mui/material";
3
+ import { Control, Controller, FieldValues, UseControllerProps } from "react-hook-form";
4
+ import { BMCloudSelect, BMCloudSelectorProps } from "./BMCloudSelect";
5
+ import { BMFormControlLabel } from "../BMForm/BMFormControlLabel";
6
+ import { BMLabel } from "../BMForm";
7
+
8
+ export type BMCloudSelectFieldProps<T extends FieldValues> = UseControllerProps<T> &
9
+ BMCloudSelectorProps<T>;
10
+
11
+ export const BMCloudSelectField = <T extends FieldValues>({ name, label, control, options }: BMCloudSelectFieldProps<T>): ReactElement => {
12
+
13
+ return (
14
+
15
+ <Controller
16
+ name={name}
17
+ control={control as unknown as Control<FieldValues>}
18
+ render={({ field, fieldState }) => (
19
+ <BMFormControlLabel
20
+ labelPlacement="top"
21
+ control={
22
+ <div>
23
+ <BMCloudSelect
24
+ options={options}
25
+ value={field.value}
26
+ onChange={field.onChange}
27
+ />
28
+ {
29
+ fieldState.error && fieldState.error.message && (
30
+ <FormHelperText error>{fieldState.error.message}</FormHelperText>
31
+ )
32
+ }
33
+ </div>
34
+ }
35
+ label={<BMLabel error={!!fieldState.error} sx={{ alignSelf: 'flex-start', marginBottom: '8px' }}>
36
+ {label}
37
+ </BMLabel>}
38
+ sx={{
39
+ flexDirection: 'column-reverse',
40
+ alignItems: 'flex-start',
41
+ }}
42
+ />
43
+ )}
44
+ />
45
+ );
46
+ };
@@ -0,0 +1,3 @@
1
+ export * from './BMCloudSelect';
2
+ export * from './BMCloudSelectField';
3
+ export * from './BMCloudList';
@@ -0,0 +1,233 @@
1
+ import React, { FC, useEffect, useLayoutEffect, useRef, useState } from "react";
2
+ import clsx from "clsx";
3
+ import hljs from "highlight.js";
4
+ import {
5
+ Box,
6
+ Collapse,
7
+ IconButton,
8
+ Typography,
9
+ Button,
10
+ useTheme,
11
+ styled,
12
+ } from "@mui/material";
13
+
14
+ import "highlight.js/styles/github.css";
15
+
16
+ import CopyIcon from "../../assets/icons/copy.svg";
17
+ import CaretDownIcon from "../../assets/icons/caret-down.svg";
18
+
19
+ export interface CodeBlockProps {
20
+ showCopyButton?: boolean;
21
+ multiBlock?: boolean;
22
+ codeClassName?: string;
23
+ preClassName?: string;
24
+ lang?: string;
25
+ containerClassName?: string;
26
+ text: string | string[] | React.ReactElement | React.ReactElement[];
27
+ dataTestId?: string;
28
+ enabledExpandCollapse?: boolean;
29
+ collapseHeight?: number;
30
+ copyLabel?: string;
31
+ showAllLabel?: string;
32
+ collapseLabel?: string;
33
+ onCopySuccess?: () => void;
34
+ }
35
+
36
+ const COLLAPSE_HEIGHT = 120;
37
+
38
+ const StyledBox = styled(Box)(({ theme }) => ({
39
+ background: theme.palette.info[400],
40
+ borderRadius: theme.shape.borderRadius,
41
+ color: theme.palette.grey[800],
42
+ border: `1px solid ${theme.palette.grey[300]}`,
43
+ overflowX: "hidden",
44
+ position: "relative",
45
+ marginBottom: theme.spacing(1),
46
+ }));
47
+
48
+ const CodeWrapper = styled("pre")(({ theme }) => ({
49
+ display: "block",
50
+ position: "relative",
51
+ fontFamily: "Menlo-Regular, Courier, monospace",
52
+ fontSize: 13,
53
+ lineHeight: "17px",
54
+ borderRadius: theme.spacing(0.5),
55
+ margin: 0,
56
+ paddingRight: theme.spacing(8),
57
+ }));
58
+
59
+ const InnerCode = styled("code")(({ theme }) => ({
60
+ fontFamily: "Menlo, Courier, monospace",
61
+ whiteSpace: "pre-wrap",
62
+ lineHeight: 2.7,
63
+ backgroundColor: "unset",
64
+ margin: 0,
65
+ }));
66
+
67
+ const InlineCopyButton = styled(Button)(({ theme }) => ({
68
+ position: "absolute",
69
+ right: theme.spacing(0.75),
70
+ top: theme.spacing(0.5),
71
+ fontSize: 11.5,
72
+ textTransform: "uppercase",
73
+ display: "none",
74
+ backgroundColor: theme.palette.info[200],
75
+ }));
76
+
77
+ const CopyIconButton = styled(IconButton)(({ theme }) => ({
78
+ position: "absolute",
79
+ right: 0,
80
+ top: 0,
81
+ color: theme.palette.primary[600],
82
+ padding: theme.spacing(1),
83
+ }));
84
+
85
+ const HoverableLine = styled("pre")(({ theme }) => ({
86
+ padding: theme.spacing(0.5, 0.75),
87
+ "&:hover": {
88
+ backgroundColor: theme.palette.primary[200],
89
+ },
90
+ "&:hover .bm-copy-btn": {
91
+ display: "block",
92
+ },
93
+ }));
94
+
95
+ export const BMCodeBlock: FC<CodeBlockProps> = ({
96
+ showCopyButton,
97
+ multiBlock,
98
+ text,
99
+ codeClassName,
100
+ preClassName,
101
+ lang,
102
+ containerClassName,
103
+ dataTestId,
104
+ enabledExpandCollapse = false,
105
+ collapseHeight = COLLAPSE_HEIGHT,
106
+ copyLabel = "Copy",
107
+ showAllLabel = "Show All",
108
+ collapseLabel = "Collapse",
109
+ onCopySuccess,
110
+ }) => {
111
+ const theme = useTheme();
112
+ const preRef = useRef<HTMLPreElement>(null);
113
+ const expandableBox = useRef<HTMLDivElement>(null);
114
+ const [expanded, setExpanded] = useState(!enabledExpandCollapse);
115
+ const [showToggle, setShowToggle] = useState(false);
116
+ const syntaxLanguage = lang ?? "language-plaintext";
117
+
118
+ useEffect(() => {
119
+ hljs.highlightAll();
120
+ }, [text]);
121
+
122
+ const didMountRef = useRef(false);
123
+ useEffect(() => {
124
+ if (didMountRef.current) {
125
+ if (expanded && expandableBox?.current) {
126
+ expandableBox?.current?.scrollTo({ top: 0 });
127
+ }
128
+ } else {
129
+ didMountRef.current = true;
130
+ }
131
+ }, [expanded]);
132
+
133
+ useLayoutEffect(() => {
134
+ if (expandableBox?.current) {
135
+ setShowToggle(
136
+ enabledExpandCollapse &&
137
+ Math.round(expandableBox?.current?.clientHeight ?? 0) > collapseHeight
138
+ );
139
+ }
140
+ }, [collapseHeight, enabledExpandCollapse]);
141
+
142
+ const copy = async (value: string) => {
143
+ try {
144
+ await navigator.clipboard.writeText(value);
145
+ onCopySuccess?.();
146
+ } catch (err) {
147
+ console.error("Failed to copy:", err);
148
+ }
149
+ };
150
+
151
+ const copyBlock = () => {
152
+ const text = preRef.current?.innerText?.replace(
153
+ /\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/g,
154
+ "$'"
155
+ );
156
+ if (text) copy(text);
157
+ };
158
+
159
+ const copyLineBlock = async (ev: React.MouseEvent) => {
160
+ const line = (
161
+ ev.currentTarget.previousSibling as HTMLElement
162
+ )?.innerText?.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/g, "$'");
163
+ if (line) await copy(line);
164
+ };
165
+
166
+ return (
167
+ <StyledBox className={clsx(containerClassName)} data-testid={dataTestId}>
168
+ <Collapse
169
+ in={expanded}
170
+ collapsedSize={showToggle ? collapseHeight : undefined}
171
+ >
172
+ <div ref={expandableBox}>
173
+ {multiBlock && Array.isArray(text) ? (
174
+ text.map((val, index) => (
175
+ <HoverableLine
176
+ key={`code-line-${index}`}
177
+ className={preClassName}
178
+ >
179
+ <InnerCode className={clsx(codeClassName, syntaxLanguage)}>
180
+ {val}
181
+ </InnerCode>
182
+ {showCopyButton && (
183
+ <InlineCopyButton
184
+ size="small"
185
+ className="bm-copy-btn"
186
+ onClick={copyLineBlock}
187
+ >
188
+ {copyLabel}
189
+ </InlineCopyButton>
190
+ )}
191
+ </HoverableLine>
192
+ ))
193
+ ) : (
194
+ <CodeWrapper className={preClassName}>
195
+ <InnerCode
196
+ className={clsx(codeClassName, syntaxLanguage)}
197
+ ref={preRef}
198
+ >
199
+ {text}
200
+ </InnerCode>
201
+ {showCopyButton && (
202
+ <CopyIconButton onClick={copyBlock}>
203
+ <CopyIcon fontSize="small" />
204
+ </CopyIconButton>
205
+ )}
206
+ </CodeWrapper>
207
+ )}
208
+ </div>
209
+ </Collapse>
210
+
211
+ {showToggle && (
212
+ <Box mt={1} display="flex" justifyContent="flex-end">
213
+ <Box
214
+ component="a"
215
+ sx={{ cursor: "pointer", display: "flex", alignItems: "center" }}
216
+ onClick={() => setExpanded(!expanded)}
217
+ >
218
+ <Typography variant="body2" color="primary">
219
+ <strong>{expanded ? collapseLabel : showAllLabel}</strong>
220
+ </Typography>
221
+ <CaretDownIcon
222
+ style={{
223
+ marginLeft: theme.spacing(0.5),
224
+ transition: "transform 0.3s",
225
+ transform: expanded ? "rotate(180deg)" : "rotate(0deg)",
226
+ }}
227
+ />
228
+ </Box>
229
+ </Box>
230
+ )}
231
+ </StyledBox>
232
+ );
233
+ };
@@ -0,0 +1 @@
1
+ export * from './BMCodeBlock';