@campxdev/react-blueprint 1.1.6 → 1.1.7

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 (49) hide show
  1. package/.prettierrc +8 -0
  2. package/package.json +4 -1
  3. package/src/App.tsx +17 -38
  4. package/src/components/Assets/Icons/IconComponents/AcademicIcon.tsx +41 -0
  5. package/src/components/Assets/Icons/IconComponents/AccordionArrow.tsx +23 -0
  6. package/src/components/Assets/Icons/IconComponents/NoteIcon.tsx +41 -0
  7. package/src/components/Assets/Icons/Icons.tsx +65 -58
  8. package/src/components/Charts/BarChart/BarChart.tsx +33 -9
  9. package/src/components/Charts/LineChart/LineChart.tsx +10 -4
  10. package/src/components/Charts/PieChart/PieChart.tsx +3 -2
  11. package/src/components/Charts/TreeMap/TreeMap.tsx +1 -0
  12. package/src/components/Charts/export.ts +4 -0
  13. package/src/components/Charts/types/types.ts +12 -2
  14. package/src/components/DataDisplay/Accordion/Accordion.tsx +42 -46
  15. package/src/components/DataDisplay/AccordionGroup/AccordionGroup.tsx +30 -0
  16. package/src/components/DataDisplay/Avatar/Avatar.tsx +18 -29
  17. package/src/components/DataDisplay/Card/Card.tsx +29 -8
  18. package/src/components/DataDisplay/DataTable/DataTable.tsx +14 -6
  19. package/src/components/DataDisplay/export.ts +6 -5
  20. package/src/components/DataDisplay/styles.tsx +2 -3
  21. package/src/components/Feedback/Snackbar/Snackbar.tsx +6 -5
  22. package/src/components/Input/DatePicker/DatePicker.tsx +58 -0
  23. package/src/components/Input/FormActions/FormActions.tsx +49 -0
  24. package/src/components/Input/FormControlWrapper/FormControlWrapper.tsx +70 -0
  25. package/src/components/Input/IconButtons/IconButtons.tsx +4 -4
  26. package/src/components/Input/LabelWrapper/LabelWrapper.tsx +1 -1
  27. package/src/components/Input/SingleSelect/SingleSelect.tsx +43 -54
  28. package/src/components/Input/{Chips/Chips.tsx → Tags/Tags.tsx} +14 -14
  29. package/src/components/Input/TimePicker/TimePicker.tsx +39 -0
  30. package/src/components/Input/export.ts +13 -8
  31. package/src/components/Layout/PageContent/PageContent.tsx +16 -0
  32. package/src/components/Layout/PageHeader/PageHeader.tsx +46 -0
  33. package/src/components/Navigation/DropDownMenu/DropDownButton.tsx +5 -5
  34. package/src/components/Navigation/Sidebar/Components.tsx +97 -0
  35. package/src/components/Navigation/Sidebar/MenuItem.tsx +76 -104
  36. package/src/components/Navigation/Sidebar/Sidebar.tsx +150 -55
  37. package/src/components/Navigation/Sidebar/SubMenuItem.tsx +34 -0
  38. package/src/components/Navigation/Sidebar/interfaces.ts +35 -12
  39. package/src/components/Navigation/Sidebar/styles.tsx +2 -2
  40. package/src/components/Navigation/exports.ts +2 -0
  41. package/src/components/export.ts +1 -1
  42. package/src/stories/DataDisplay/AccordionGroup.stories.tsx +131 -0
  43. package/src/stories/Input/DatePicker.stories.tsx +138 -0
  44. package/src/stories/Input/{Chips.stories.tsx → Tags.stories.tsx} +17 -17
  45. package/src/stories/Input/TimePicker.stories.tsx +123 -0
  46. package/src/themes/commonTheme.ts +171 -155
  47. package/src/components/DataDisplay/Accordion/utils/StandardImageList.tsx +0 -70
  48. package/src/components/Navigation/Sidebar/DropdownItem.tsx +0 -34
  49. package/src/stories/DataDisplay/Accordion.stories.tsx +0 -62
@@ -1,18 +1,13 @@
1
- import {
2
- Box,
3
- Autocomplete as MuiAutocomplete,
4
- Paper,
5
- PaperProps,
6
- } from "@mui/material";
7
- import axios from "axios";
8
- import _ from "lodash";
9
- import { useEffect, useReducer } from "react";
10
- import { campxAxios } from "../../../utils/campxAxios";
11
- import { Typography } from "../../DataDisplay/Typography/Typography";
12
- import { Spinner } from "../../Feedback/Spinner/Spinner";
13
- import { TextField } from "../TextField/TextField";
14
- import { FetchingOptionsLoader } from "../components/FetchingOptionsLoader";
15
- import { OptionContainer } from "../styles";
1
+ import { axios as campxAxios } from '@campxdev/campx-web-utils';
2
+ import { BaseSelectProps, Box, Autocomplete as MuiAutocomplete, Paper, PaperProps } from '@mui/material';
3
+ import axios from 'axios';
4
+ import _ from 'lodash';
5
+ import { useEffect, useReducer } from 'react';
6
+ import { Typography } from '../../DataDisplay/Typography/Typography';
7
+ import { Spinner } from '../../Feedback/Spinner/Spinner';
8
+ import { TextField } from '../TextField/TextField';
9
+ import { FetchingOptionsLoader } from '../components/FetchingOptionsLoader';
10
+ import { OptionContainer } from '../styles';
16
11
 
17
12
  function sleep(duration: number): Promise<void> {
18
13
  return new Promise<void>((resolve) => {
@@ -28,9 +23,13 @@ export type SingleSelectProps = {
28
23
  useCampxAxios: boolean;
29
24
  required?: boolean;
30
25
  label?: string;
26
+ name?: string;
31
27
  value?: any;
32
28
  getValue?: (option: any) => any;
33
- };
29
+ onChange: (value: any) => void;
30
+ error?: any;
31
+ helperText?: string;
32
+ } & BaseSelectProps;
34
33
 
35
34
  const CustomPaper = (props: PaperProps) => (
36
35
  <Paper {...props}>
@@ -40,24 +39,18 @@ const CustomPaper = (props: PaperProps) => (
40
39
  );
41
40
 
42
41
  enum SingleSelectActionsTypes {
43
- OPEN = "open",
44
- CLOSE = "close",
45
- LOAD_INTERNAL_OPTIONS_START = "load_internal_options_start",
46
- LOAD_INTERNAL_OPTIONS_END = "load_internal_options_end",
47
- LOAD_INITIAL_INTERNAL_OPTIONS_START = "load_initial_internal_options_start",
48
- LOAD_INITIAL_INTERNAL_OPTIONS_END = "load_initial_internal_options_end",
49
- SET_NETWORK_ERROR = "set_network_error",
50
- SET_INTERNAL_OPTIONS = "set_internal_options",
51
- APPEND_INTERNAL_OPTIONS = "append_internal_options",
52
- CHANGE_HAS_MORE_FLAG = "change_has_more_flag",
42
+ OPEN = 'open',
43
+ CLOSE = 'close',
44
+ LOAD_INTERNAL_OPTIONS_START = 'load_internal_options_start',
45
+ LOAD_INTERNAL_OPTIONS_END = 'load_internal_options_end',
46
+ LOAD_INITIAL_INTERNAL_OPTIONS_START = 'load_initial_internal_options_start',
47
+ LOAD_INITIAL_INTERNAL_OPTIONS_END = 'load_initial_internal_options_end',
48
+ SET_NETWORK_ERROR = 'set_network_error',
49
+ SET_INTERNAL_OPTIONS = 'set_internal_options',
50
+ APPEND_INTERNAL_OPTIONS = 'append_internal_options',
51
+ CHANGE_HAS_MORE_FLAG = 'change_has_more_flag',
53
52
  }
54
- const singleSelectReducer = (
55
- state: any,
56
- {
57
- actionType,
58
- stateChanges,
59
- }: { actionType: SingleSelectActionsTypes; stateChanges?: any }
60
- ) => {
53
+ const singleSelectReducer = (state: any, { actionType, stateChanges }: { actionType: SingleSelectActionsTypes; stateChanges?: any }) => {
61
54
  switch (actionType) {
62
55
  case SingleSelectActionsTypes.OPEN: {
63
56
  return { ...state, open: true };
@@ -118,8 +111,13 @@ export const SingleSelect = ({
118
111
  useCampxAxios = true,
119
112
  required = false,
120
113
  label,
114
+ name,
121
115
  getValue,
122
116
  value,
117
+ onChange,
118
+ error,
119
+ helperText,
120
+ ...restProps
123
121
  }: SingleSelectProps) => {
124
122
  const generateOptionsMap = (options: any[]) => {
125
123
  return _.keyBy(options ?? [], getValue ? getValue : (o) => o.value);
@@ -135,15 +133,7 @@ export const SingleSelect = ({
135
133
  offset: 0,
136
134
  hasMore: true,
137
135
  });
138
- const {
139
- open,
140
- loadingInternalOptions,
141
- loadingInitialInternalOptions,
142
- internalOptions,
143
- limit,
144
- offset,
145
- hasMore,
146
- } = state;
136
+ const { open, loadingInternalOptions, loadingInitialInternalOptions, internalOptions, limit, offset, hasMore } = state;
147
137
 
148
138
  const internalAxios = useCampxAxios ? campxAxios : axios;
149
139
 
@@ -188,17 +178,12 @@ export const SingleSelect = ({
188
178
 
189
179
  const handleScroll = async (event: any) => {
190
180
  const listboxNode = event.currentTarget;
191
- if (
192
- listboxNode.scrollTop + listboxNode.clientHeight >=
193
- listboxNode.scrollHeight - 1 &&
194
- hasMore &&
195
- optionsApiEndPoint
196
- ) {
181
+ if (listboxNode.scrollTop + listboxNode.clientHeight >= listboxNode.scrollHeight - 1 && hasMore && optionsApiEndPoint) {
197
182
  dispatch({
198
183
  actionType: SingleSelectActionsTypes.LOAD_INTERNAL_OPTIONS_START,
199
184
  });
200
185
  const newOptions = await internalAxios
201
- .get(optionsApiEndPoint ?? "", {
186
+ .get(optionsApiEndPoint ?? '', {
202
187
  params: {
203
188
  limit: limit,
204
189
  offset: offset + 10,
@@ -226,7 +211,7 @@ export const SingleSelect = ({
226
211
  actionType: SingleSelectActionsTypes.LOAD_INITIAL_INTERNAL_OPTIONS_START,
227
212
  });
228
213
  try {
229
- const res = await internalAxios.get(optionsApiEndPoint ?? "", {
214
+ const res = await internalAxios.get(optionsApiEndPoint ?? '', {
230
215
  params: { limit, offset, selectedValue: value },
231
216
  });
232
217
  dispatch({
@@ -249,32 +234,36 @@ export const SingleSelect = ({
249
234
  if (value && optionsApiEndPoint) {
250
235
  fetchInitialOptions().finally(() => {
251
236
  dispatch({
252
- actionType:
253
- SingleSelectActionsTypes.LOAD_INITIAL_INTERNAL_OPTIONS_END,
237
+ actionType: SingleSelectActionsTypes.LOAD_INITIAL_INTERNAL_OPTIONS_END,
254
238
  });
255
239
  });
256
240
  }
257
241
  }, []);
258
242
 
259
243
  if (loadingInitialInternalOptions) {
260
- console.log("Rendered Loading");
261
244
  return (
262
245
  <TextField
263
246
  label={label}
247
+ name={name}
264
248
  required={required}
265
249
  InputProps={{
266
250
  endAdornment: <Spinner />,
267
251
  }}
252
+ error={error}
253
+ helperText={helperText}
268
254
  />
269
255
  );
270
256
  }
271
257
  return (
272
258
  <MuiAutocomplete
259
+ onChange={(e, value) => {
260
+ onChange(getValue ? getValue(value) : value?.value);
261
+ }}
273
262
  open={open}
274
263
  autoFocus={true}
275
264
  value={state.internalOptionsMap[value]}
276
265
  renderInput={(params) => (
277
- <TextField {...params} label={label} required={required} />
266
+ <TextField {...params} label={label} required={required} name={name} error={error} helperText={helperText} />
278
267
  )}
279
268
  PaperComponent={CustomPaper}
280
269
  renderOption={(props, option: any) => {
@@ -1,24 +1,24 @@
1
- import { Chip, styled } from "@mui/material";
2
- import { Typography } from "../../DataDisplay/Typography/Typography";
3
- import { Icons } from "../../export";
1
+ import { Chip, styled } from '@mui/material';
2
+ import { Typography } from '../../DataDisplay/Typography/Typography';
3
+ import { Icons } from '../../export';
4
4
 
5
- const ChipList = styled("ul")(({ theme }) => ({
6
- display: "flex",
7
- justifyContent: "center",
8
- flexWrap: "wrap",
9
- listStyle: "none",
5
+ const TagList = styled('ul')(({ theme }) => ({
6
+ display: 'flex',
7
+ justifyContent: 'center',
8
+ flexWrap: 'wrap',
9
+ listStyle: 'none',
10
10
  }));
11
11
 
12
- export type ChipsProps = {
13
- chips: { label: string; value: any }[];
12
+ export type TagsProps = {
13
+ tags: { label: string; value: any }[];
14
14
  onClick?: (clickedChip: any) => void;
15
15
  onDelete?: (deletedChip: any) => void;
16
16
  };
17
17
 
18
- export const Chips = ({ chips, onClick, onDelete }: ChipsProps) => {
18
+ export const Tags = ({ tags, onClick, onDelete }: TagsProps) => {
19
19
  return (
20
- <ChipList>
21
- {chips.map(({ label, value }) => (
20
+ <TagList>
21
+ {tags.map(({ label, value }) => (
22
22
  <Chip
23
23
  label={<Typography variant="body2">{label}</Typography>}
24
24
  onClick={
@@ -38,6 +38,6 @@ export const Chips = ({ chips, onClick, onDelete }: ChipsProps) => {
38
38
  deleteIcon={<Icons.CrossIcon />}
39
39
  />
40
40
  ))}
41
- </ChipList>
41
+ </TagList>
42
42
  );
43
43
  };
@@ -0,0 +1,39 @@
1
+ import { PickerValidDate } from '@mui/x-date-pickers';
2
+ import { TimePicker as MuiTimePicker, TimePickerProps as MuiTimePickerProps } from '@mui/x-date-pickers/TimePicker';
3
+ import { LabelWrapper } from '../LabelWrapper/LabelWrapper';
4
+
5
+ type TimePickerProps<TDate extends PickerValidDate, TEnableAccessibleFieldDOMStructure extends boolean = false> = {
6
+ format?: 'hh:mm a' | 'HH:mm' | 'HH:mm:ss a' | 'HH:mm:ss';
7
+ views?: ('hours' | 'minutes' | 'seconds')[];
8
+ helperText?: string;
9
+ placeholder?: string;
10
+ required?: boolean;
11
+ containerProps?: any;
12
+ } & MuiTimePickerProps<TDate, TEnableAccessibleFieldDOMStructure>;
13
+
14
+ export const TimePicker = <TDate extends PickerValidDate, TEnableAccessibleFieldDOMStructure extends boolean = false>({
15
+ label,
16
+ name,
17
+ value,
18
+ format = 'hh:mm a',
19
+ views = ['hours', 'minutes'],
20
+ helperText,
21
+ placeholder = '',
22
+ required = false,
23
+ containerProps,
24
+ ...rest
25
+ }: TimePickerProps<TDate, TEnableAccessibleFieldDOMStructure>) => {
26
+ return (
27
+ <LabelWrapper label={label} required={required} name={name} containerProps={containerProps}>
28
+ <MuiTimePicker
29
+ defaultValue={value}
30
+ format={format}
31
+ views={views}
32
+ slotProps={{
33
+ textField: { placeholder, helperText },
34
+ }}
35
+ {...rest}
36
+ />
37
+ </LabelWrapper>
38
+ );
39
+ };
@@ -1,8 +1,13 @@
1
- export * from "./Button/Button";
2
- export * from "./MultiCheckBox/MultiCheckBox";
3
- export * from "./PasswordField/PasswordField";
4
- export * from "./SearchBar/SearchBar";
5
- export * from "./SingleCheckBox/SIngleCheckBox";
6
- export * from "./SingleSelect/SingleSelect";
7
- export * from "./Switch/Switch";
8
- export * from "./TextField/TextField";
1
+ export * from './Button/Button';
2
+ export * from './DatePicker/DatePicker';
3
+ export * from './FormActions/FormActions';
4
+ export * from './FormControlWrapper/FormControlWrapper';
5
+ export * from './IconButtons/IconButtons';
6
+ export * from './MultiCheckBox/MultiCheckBox';
7
+ export * from './PasswordField/PasswordField';
8
+ export * from './SearchBar/SearchBar';
9
+ export * from './SingleCheckBox/SIngleCheckBox';
10
+ export * from './SingleSelect/SingleSelect';
11
+ export * from './Switch/Switch';
12
+ export * from './TextField/TextField';
13
+ export * from './TimePicker/TimePicker';
@@ -0,0 +1,16 @@
1
+ import { Box, BoxProps, styled } from '@mui/material';
2
+
3
+ const StyledPageContent = styled(Box)(({ theme }) => ({
4
+ padding: '1rem',
5
+ flex: 1,
6
+ display: 'flex',
7
+ flexDirection: 'column',
8
+ borderRadius: '10px',
9
+ overflowY: 'auto',
10
+ backgroundColor: theme.palette.surface.paperBackground,
11
+ height: '100%',
12
+ }));
13
+
14
+ export function PageContent(props: BoxProps) {
15
+ return <StyledPageContent {...props}>{props.children}</StyledPageContent>;
16
+ }
@@ -0,0 +1,46 @@
1
+ import { Box, styled, Typography } from '@mui/material';
2
+ import { ReactNode } from 'react';
3
+ import { Breadcrumbs } from '../../Navigation/Breadcrumbs/Breadcrumbs';
4
+
5
+ interface BreadCrumbsLink {
6
+ name: string | ReactNode;
7
+ to: string;
8
+ }
9
+ interface PageHeaderProps {
10
+ title?: string | ReactNode;
11
+ actions?: ReactNode;
12
+ links?: BreadCrumbsLink[];
13
+ }
14
+
15
+ const StyledBox = styled(Box)(({ theme }) => ({
16
+ minHeight: '40px',
17
+ display: 'flex',
18
+ alignItems: 'center',
19
+ justifyContent: 'space-between',
20
+ margin: '0',
21
+ flexWrap: 'wrap',
22
+ '& .actions': {
23
+ display: 'flex',
24
+ gap: '1rem',
25
+ alignItems: 'center',
26
+ marginLeft: 'auto',
27
+ '& .MuiButton-root': {
28
+ height: '40px',
29
+ },
30
+ },
31
+ }));
32
+
33
+ export default function PageHeader({ title, actions, links }: PageHeaderProps) {
34
+ return (
35
+ <StyledBox>
36
+ <>
37
+ {links && links.length > 0 ? (
38
+ <Breadcrumbs links={links} />
39
+ ) : (
40
+ <>{typeof title === 'string' ? <Typography variant="subtitle2">{title}</Typography> : title}</>
41
+ )}
42
+ </>
43
+ <Box className="actions">{actions}</Box>
44
+ </StyledBox>
45
+ );
46
+ }
@@ -1,8 +1,8 @@
1
- import { KeyboardArrowDown } from "@mui/icons-material";
2
- import { Button, ButtonProps } from "../../Input/Button/Button";
1
+ import { KeyboardArrowDown } from '@mui/icons-material'
2
+ import { Button, ButtonProps } from '../../Input/Button/Button'
3
3
 
4
4
  export const DropDownButton = (props: ButtonProps) => {
5
5
  return (
6
- <Button {...props} variant="outlined" endIcon={<KeyboardArrowDown />} />
7
- );
8
- };
6
+ <Button variant="outlined" endIcon={<KeyboardArrowDown />} {...props} />
7
+ )
8
+ }
@@ -0,0 +1,97 @@
1
+ import { Box, Stack } from "@mui/material";
2
+ import { useMemo } from "react";
3
+ import { Icons, Tooltip, Typography } from "../../export";
4
+ import {
5
+ DefaultButtonProps,
6
+ InternalMenuButtonProps,
7
+ SubMenuButtonProps,
8
+ TooltipIconProps,
9
+ } from "./interfaces";
10
+ import { createSidebarStyles } from "./styles";
11
+
12
+ export const TooltipIcon = ({ name, icon }: TooltipIconProps) => {
13
+ return (
14
+ <Tooltip title={<Typography variant="label2">{name}</Typography>}>
15
+ {icon}
16
+ </Tooltip>
17
+ );
18
+ };
19
+
20
+ export const DefaultButton = ({
21
+ name,
22
+ icon,
23
+ collapsed,
24
+ }: DefaultButtonProps) => {
25
+ const { StyledListItemButton, StyledListItemIcon } = useMemo(
26
+ () => createSidebarStyles(collapsed),
27
+ [collapsed]
28
+ );
29
+
30
+ return (
31
+ <StyledListItemButton collapsed={collapsed}>
32
+ <StyledListItemIcon collapsed={collapsed}>{icon}</StyledListItemIcon>
33
+ <Typography variant="button1">{name}</Typography>
34
+ </StyledListItemButton>
35
+ );
36
+ };
37
+
38
+ export const InternalMenuButton = ({
39
+ name,
40
+ icon,
41
+ collapsed,
42
+ }: InternalMenuButtonProps) => {
43
+ const { StyledListItemButton, StyledListItemIcon, HoverIcon } = useMemo(
44
+ () => createSidebarStyles(collapsed),
45
+ [collapsed]
46
+ );
47
+
48
+ return (
49
+ <StyledListItemButton collapsed={collapsed}>
50
+ <Stack
51
+ width={"100%"}
52
+ direction="row"
53
+ alignItems={"center"}
54
+ justifyContent={"space-between"}
55
+ >
56
+ <Stack direction="row" alignItems={"center"}>
57
+ <StyledListItemIcon collapsed={collapsed}>{icon}</StyledListItemIcon>
58
+ <Typography variant="button1">{name}</Typography>
59
+ </Stack>
60
+ <HoverIcon display={"flex"} className="hoverIcon">
61
+ <Icons.RedoIcon size={18} />
62
+ </HoverIcon>
63
+ </Stack>
64
+ </StyledListItemButton>
65
+ );
66
+ };
67
+
68
+ export const SubMenuButton = ({
69
+ name,
70
+ icon,
71
+ expanded,
72
+ collapsed,
73
+ }: SubMenuButtonProps) => {
74
+ const { StyledListItemButton, StyledListItemIcon } = useMemo(
75
+ () => createSidebarStyles(collapsed),
76
+ [collapsed]
77
+ );
78
+
79
+ return (
80
+ <StyledListItemButton collapsed={collapsed}>
81
+ <Stack
82
+ width={"100%"}
83
+ direction="row"
84
+ alignItems={"center"}
85
+ justifyContent={"space-between"}
86
+ >
87
+ <Stack direction="row" alignItems={"center"}>
88
+ <StyledListItemIcon collapsed={collapsed}>{icon}</StyledListItemIcon>
89
+ <Typography variant="button1">{name}</Typography>
90
+ </Stack>
91
+ <Box display={"flex"}>
92
+ {expanded ? <Icons.CollapseIcon /> : <Icons.ExpandIcon />}
93
+ </Box>
94
+ </Stack>
95
+ </StyledListItemButton>
96
+ );
97
+ };