@sonardigital/carbon-ui 1.1.18

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 (50) hide show
  1. package/README.md +93 -0
  2. package/package.json +59 -0
  3. package/src/App.css +34 -0
  4. package/src/components/atoms/alert/Alert.tsx +35 -0
  5. package/src/components/atoms/cursor/Cursor.tsx +10 -0
  6. package/src/components/atoms/index.ts +2 -0
  7. package/src/components/form/fields/FormInput.tsx +25 -0
  8. package/src/components/form/fields/FormPassword.tsx +48 -0
  9. package/src/components/form/fields/FormSelect.tsx +37 -0
  10. package/src/components/form/fields/FormTextArea.tsx +34 -0
  11. package/src/components/form/fields/index.ts +4 -0
  12. package/src/components/form/index.ts +1 -0
  13. package/src/components/form/layout/FormError.tsx +11 -0
  14. package/src/components/form/layout/FormLabel.tsx +19 -0
  15. package/src/components/form/layout/index.ts +2 -0
  16. package/src/components/index.ts +4 -0
  17. package/src/components/inputs/Select.tsx +52 -0
  18. package/src/components/inputs/index.ts +0 -0
  19. package/src/components/layout/Drawer_/components/DrawerContent.tsx +13 -0
  20. package/src/components/layout/Drawer_/components/DrawerProvider.tsx +23 -0
  21. package/src/components/layout/Drawer_/components/DrawerTrigger.tsx +28 -0
  22. package/src/components/layout/Drawer_/components/index.ts +3 -0
  23. package/src/components/layout/Drawer_/context/DrawerContext.ts +17 -0
  24. package/src/components/layout/Drawer_/context/index.ts +1 -0
  25. package/src/components/layout/Drawer_/hooks/index.ts +2 -0
  26. package/src/components/layout/Drawer_/hooks/useDrawer.ts +25 -0
  27. package/src/components/layout/Drawer_/hooks/useDrawerContext.ts +11 -0
  28. package/src/components/layout/Drawer_/index.ts +3 -0
  29. package/src/components/layout/Dropdown/components/DropdownPopover.tsx +35 -0
  30. package/src/components/layout/Dropdown/components/DropdownProvider.tsx +28 -0
  31. package/src/components/layout/Dropdown/components/DropdownTrigger.tsx +27 -0
  32. package/src/components/layout/Dropdown/components/index.ts +3 -0
  33. package/src/components/layout/Dropdown/context/DropdownContext.ts +21 -0
  34. package/src/components/layout/Dropdown/hooks/index.ts +1 -0
  35. package/src/components/layout/Dropdown/hooks/useDropdown.ts +22 -0
  36. package/src/components/layout/Dropdown/hooks/useDropdownContext.ts +11 -0
  37. package/src/components/layout/Dropdown/index.ts +2 -0
  38. package/src/components/layout/ScrollToTop/ScrollToTop.tsx +12 -0
  39. package/src/components/layout/index.ts +5 -0
  40. package/src/components/widgets/index.ts +0 -0
  41. package/src/index.css +8 -0
  42. package/src/index.ts +4 -0
  43. package/src/provider/CarbonProvider.tsx +13 -0
  44. package/src/provider/index.ts +1 -0
  45. package/src/theme/constants/components.ts +369 -0
  46. package/src/theme/constants/palette.ts +39 -0
  47. package/src/theme/constants/typography.ts +42 -0
  48. package/src/theme/index.ts +1 -0
  49. package/src/theme/theme.d.ts +0 -0
  50. package/src/theme/theme.ts +14 -0
@@ -0,0 +1,35 @@
1
+ import { Popover, PopoverProps } from '@mui/material';
2
+ import React from 'react';
3
+ import { useDropdownContext } from '../hooks/useDropdownContext';
4
+
5
+ interface PopoverProviderProps extends Omit<PopoverProps, 'open'> {
6
+ children: React.ReactNode;
7
+ }
8
+
9
+ export function DropdownPopover({ children, ...props }: PopoverProviderProps): React.ReactElement {
10
+ const methods = useDropdownContext();
11
+
12
+ return (
13
+ <Popover
14
+ open={methods.isOpen}
15
+ anchorEl={methods.anchorEl}
16
+ onClose={methods.close}
17
+ sx={{ marginTop: 0.8, borderRadius: 0, width: '100%' }}
18
+ anchorPosition={{
19
+ top: 0,
20
+ left: 0,
21
+ }}
22
+ transformOrigin={{
23
+ vertical: 'top',
24
+ horizontal: 'right',
25
+ }}
26
+ anchorOrigin={{
27
+ vertical: 'bottom',
28
+ horizontal: 'right',
29
+ }}
30
+ {...props}
31
+ >
32
+ {children}
33
+ </Popover>
34
+ );
35
+ }
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { ClickAwayListener, Stack } from '@mui/material';
3
+ import { useDropdown } from '../hooks/useDropdown';
4
+ import DropdownContext from '../context/DropdownContext';
5
+
6
+ interface DropdownProviderProps {
7
+ methods?: ReturnType<typeof useDropdown>;
8
+ children: React.ReactNode;
9
+ onClose?: () => void;
10
+ }
11
+
12
+ export function DropdownProvider({
13
+ methods,
14
+ children,
15
+ onClose,
16
+ }: DropdownProviderProps): React.ReactElement<DropdownProviderProps> {
17
+ const defaultMethods = useDropdown({ onClose: onClose });
18
+
19
+ return (
20
+ <DropdownContext.Provider value={methods ?? defaultMethods}>
21
+ <ClickAwayListener onClickAway={methods ? methods.close : defaultMethods.close}>
22
+ <Stack flexDirection="column" position="relative" width="auto" height="auto">
23
+ {children}
24
+ </Stack>
25
+ </ClickAwayListener>
26
+ </DropdownContext.Provider>
27
+ );
28
+ }
@@ -0,0 +1,27 @@
1
+ import { ButtonBase } from '@mui/material';
2
+ import React from 'react';
3
+ import { useDropdownContext } from '../hooks/useDropdownContext';
4
+
5
+ interface DropdownTriggerProps {
6
+ children: React.ReactNode;
7
+ onClick?: () => void;
8
+ }
9
+
10
+ export function DropdownTrigger({ children, onClick }: DropdownTriggerProps): React.ReactElement {
11
+ const { open, setAnchorEl } = useDropdownContext();
12
+
13
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement>): void => {
14
+ if (event.detail === 0) {
15
+ return;
16
+ }
17
+ setAnchorEl(event.currentTarget);
18
+ open();
19
+ if (onClick) onClick();
20
+ };
21
+
22
+ return (
23
+ <ButtonBase sx={{ posiion: 'relative' }} disableRipple onClick={handleClick}>
24
+ {children}
25
+ </ButtonBase>
26
+ );
27
+ }
@@ -0,0 +1,3 @@
1
+ export * from './DropdownProvider';
2
+ export * from './DropdownTrigger';
3
+ export * from './DropdownPopover';
@@ -0,0 +1,21 @@
1
+ import { Context, createContext } from 'react';
2
+
3
+ export interface DropdownContextType {
4
+ isOpen: boolean;
5
+ toggle: () => void;
6
+ close: () => void;
7
+ open: () => void;
8
+ anchorEl: HTMLElement | null;
9
+ setAnchorEl: (el: HTMLElement | null) => void;
10
+ }
11
+
12
+ const DropdownContext: Context<DropdownContextType> = createContext<DropdownContextType>({
13
+ isOpen: false,
14
+ toggle: () => {},
15
+ close: () => {},
16
+ open: () => {},
17
+ anchorEl: null,
18
+ setAnchorEl: () => {},
19
+ });
20
+
21
+ export default DropdownContext;
@@ -0,0 +1 @@
1
+ export * from './useDropdown';
@@ -0,0 +1,22 @@
1
+ import { useState } from 'react';
2
+ import { DropdownContextType } from '../context/DropdownContext';
3
+
4
+ interface DropdownHookProps {
5
+ onClose?: () => void;
6
+ }
7
+
8
+ export const useDropdown = (props?: DropdownHookProps): DropdownContextType => {
9
+ const [isOpen, setIsOpen] = useState(false);
10
+ const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
11
+
12
+ const toggle = (): void => setIsOpen((prev) => !prev);
13
+ const open = (): void => {
14
+ setIsOpen(true);
15
+ };
16
+ const close = (): void => {
17
+ setIsOpen(false);
18
+ if (props?.onClose) props.onClose();
19
+ };
20
+
21
+ return { isOpen, toggle, open, close, anchorEl, setAnchorEl };
22
+ };
@@ -0,0 +1,11 @@
1
+ import { useContext } from 'react';
2
+ import DropdownContext, { DropdownContextType } from '../context/DropdownContext';
3
+
4
+ export const useDropdownContext = (): DropdownContextType => {
5
+ const context = useContext(DropdownContext);
6
+
7
+ if (!context) {
8
+ throw new Error('useDropdown must be used within a DropdownProvider');
9
+ }
10
+ return context;
11
+ };
@@ -0,0 +1,2 @@
1
+ export * from './components';
2
+ export * from './hooks';
@@ -0,0 +1,12 @@
1
+ import React, { useEffect } from 'react';
2
+ import { useLocation } from 'react-router';
3
+
4
+ export function ScrollToTop({ children }: { children?: React.ReactNode }): React.ReactElement {
5
+ const location = useLocation();
6
+
7
+ useEffect(() => {
8
+ window.scrollTo(0, 0);
9
+ }, [location.pathname]);
10
+
11
+ return <>{children}</>;
12
+ }
@@ -0,0 +1,5 @@
1
+ export * from '../../ui/header/Header';
2
+ export * from './app-layout/AppLayout';
3
+ export * from './Drawer_';
4
+ export * from './Dropdown';
5
+ export * from './ScrollToTop/ScrollToTop';
File without changes
package/src/index.css ADDED
@@ -0,0 +1,8 @@
1
+ html {
2
+ font-size: 9.7px;
3
+ }
4
+
5
+ body {
6
+ margin: 0;
7
+ padding: 0;
8
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './theme';
2
+ export * from './provider';
3
+ export * from './components';
4
+ export * from '@mui/material';
@@ -0,0 +1,13 @@
1
+ import { createTheme, ThemeProvider } from '@mui/material';
2
+
3
+ type Theme = ReturnType<typeof createTheme>;
4
+
5
+ export function CarbonProvider({
6
+ theme,
7
+ children,
8
+ }: {
9
+ theme: Theme;
10
+ children: React.ReactNode;
11
+ }): React.ReactElement {
12
+ return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
13
+ }
@@ -0,0 +1 @@
1
+ export * from './CarbonProvider';
@@ -0,0 +1,369 @@
1
+ /* eslint-disable max-lines */
2
+
3
+ import { Theme } from '@emotion/react';
4
+ import { Components, CssVarsTheme } from '@mui/material';
5
+
6
+ const defaultButtonStyle = {
7
+ paddingLeft: 20,
8
+ paddingRight: 20,
9
+ paddingTop: 10,
10
+ paddingBottom: 10,
11
+ fontWeight: 400,
12
+ fontSize: 16.5,
13
+ };
14
+
15
+ const borderRadius = 1;
16
+
17
+ export const components: Components<Omit<Theme, 'components' | 'palette'> & CssVarsTheme> = {
18
+ MuiMenuItem: {
19
+ defaultProps: {
20
+ sx: {
21
+ padding: 1.1,
22
+ paddingX: 1.5,
23
+ height: 48,
24
+ transition: '0.15s',
25
+ '&:hover': { backgroundColor: 'primary.light' },
26
+ fontWeight: 400,
27
+ },
28
+ },
29
+ },
30
+ MuiAutocomplete: {
31
+ defaultProps: {
32
+ slotProps: {
33
+ paper: {
34
+ sx: {
35
+ marginTop: 1,
36
+ boxShadow: 0,
37
+ backgroundColor: 'background.default',
38
+ padding: 0.5,
39
+ paddingX: 1.2,
40
+ border: 1,
41
+ borderColor: 'divider',
42
+ '& .MuiAutocomplete-listbox': {
43
+ '& .MuiAutocomplete-option': {
44
+ borderRadius,
45
+ display: 'flex',
46
+ flexDirection: 'column',
47
+ alignItems: 'flex-start',
48
+ padding: 1.2,
49
+ paddingTop: 1.5,
50
+ paddingBottom: 1.5,
51
+ fontSize: 16,
52
+ fontWeight: 450,
53
+ },
54
+ },
55
+ },
56
+ },
57
+ },
58
+ },
59
+ },
60
+
61
+ MuiTextField: {
62
+ defaultProps: {
63
+ size: 'medium',
64
+ fullWidth: true,
65
+ // eslint-disable-next-line
66
+ // @ts-ignore
67
+ color: 'info',
68
+ InputProps: {
69
+ sx: {
70
+ fontSize: '1.7rem',
71
+ fontWeight: 400,
72
+ height: 52,
73
+ },
74
+ },
75
+ InputLabelProps: {
76
+ sx: { fontSize: '1.7rem', fontWeight: 400, borderRadius: 0 },
77
+ shrink: true,
78
+ },
79
+ },
80
+ },
81
+ MuiContainer: {
82
+ defaultProps: {
83
+ maxWidth: 'lg',
84
+ sx: {
85
+ paddingY: 12,
86
+ },
87
+ style: {
88
+ height: '100%',
89
+ alignItems: 'center',
90
+ justifyContent: 'center',
91
+ },
92
+ },
93
+ },
94
+ MuiPaper: {
95
+ variants: [
96
+ {
97
+ props: {
98
+ variant: 'outlined',
99
+ },
100
+ style: {
101
+ borderWidth: 1,
102
+ borderStyle: 'solid',
103
+ borderColor: '#D4D6DE',
104
+ backgroundColor: 'transparent',
105
+ },
106
+ },
107
+ ],
108
+ },
109
+ MuiInputBase: {
110
+ defaultProps: {
111
+ sx: {
112
+ fontSize: 16.5,
113
+ fontWeight: 300,
114
+ },
115
+ },
116
+ },
117
+ MuiStack: {
118
+ defaultProps: {
119
+ style: {
120
+ borderColor: '#D4D6DE',
121
+ borderWidth: 1,
122
+ },
123
+ },
124
+ },
125
+ MuiChip: {
126
+ defaultProps: {
127
+ style: {
128
+ width: 'auto',
129
+ alignSelf: 'start',
130
+ height: 35,
131
+ },
132
+ },
133
+ },
134
+ MuiButton: {
135
+ variants: [
136
+ {
137
+ props: {
138
+ variant: 'contained',
139
+ color: 'primary',
140
+ },
141
+ style: ({ theme }) => ({
142
+ ...defaultButtonStyle,
143
+ backgroundColor: theme.palette.primary.light,
144
+ color: theme.palette.primary.main,
145
+ '&:hover': {
146
+ boxShadow: 0,
147
+ backgroundColor: theme.palette.primary.main,
148
+ color: 'white',
149
+ },
150
+ }),
151
+ },
152
+ {
153
+ props: {
154
+ variant: 'contained',
155
+ color: 'info',
156
+ },
157
+ style: ({ theme }) => ({
158
+ ...defaultButtonStyle,
159
+ paddingTop: 10,
160
+ backgroundColor: theme.palette.info.light,
161
+ color: theme.palette.info.main,
162
+ '&:hover': {
163
+ backgroundColor: theme.palette.info.main,
164
+ color: 'white',
165
+ },
166
+ }),
167
+ },
168
+ {
169
+ props: {
170
+ variant: 'text',
171
+ },
172
+ style: ({ theme }) => ({
173
+ ...defaultButtonStyle,
174
+ color: 'black',
175
+ backgroundColor: theme.palette.background.paper,
176
+ boxShadow: 'none',
177
+ '&:hover': {
178
+ backgroundColor: '#F1F1F1',
179
+ },
180
+ }),
181
+ },
182
+ {
183
+ props: {
184
+ // eslint-disable-next-line
185
+ // @ts-ignore
186
+ variant: 'hoverable',
187
+ },
188
+ style: ({ theme }) => ({
189
+ ...defaultButtonStyle,
190
+ backgroundColor: 'transparent',
191
+ '&:hover': {
192
+ backgroundColor: theme.palette.grey[100],
193
+ color: 'black',
194
+ },
195
+ }),
196
+ },
197
+ ],
198
+ defaultProps: {
199
+ disableRipple: true,
200
+ sx: {
201
+ boxShadow: 'none',
202
+ '&:hover': {
203
+ boxShadow: 'none',
204
+ },
205
+ },
206
+ },
207
+ },
208
+ MuiPopover: {
209
+ defaultProps: {
210
+ elevation: 0,
211
+ transitionDuration: 0,
212
+ slotProps: {
213
+ paper: {
214
+ sx: {
215
+ bgcolor: 'white',
216
+ minWidth: 175,
217
+ border: 1,
218
+ padding: 1,
219
+ borderColor: 'grey.400',
220
+ },
221
+ },
222
+ },
223
+ },
224
+ },
225
+ MuiIconButton: {
226
+ defaultProps: {
227
+ disableRipple: true,
228
+ sx: {
229
+ borderRadius,
230
+ ':hover': {
231
+ backgroundColor: 'grey.100',
232
+ },
233
+ },
234
+ },
235
+ },
236
+ MuiListItemIcon: {
237
+ defaultProps: {
238
+ sx: {
239
+ alignItems: 'center',
240
+ justifyContent: 'center',
241
+ paddingRight: 1,
242
+ color: 'inherit',
243
+ },
244
+ },
245
+ },
246
+ MuiAlert: {
247
+ defaultProps: {
248
+ variant: 'filled',
249
+ style: {
250
+ borderRadius,
251
+ opacity: 1,
252
+ boxShadow: 'none',
253
+ },
254
+ },
255
+ },
256
+ MuiDrawer: {
257
+ defaultProps: {
258
+ slotProps: {
259
+ paper: {
260
+ sx: {
261
+ bgcolor: 'background.default',
262
+ },
263
+ },
264
+ },
265
+ },
266
+ },
267
+ MuiListItem: {
268
+ defaultProps: {
269
+ style: {
270
+ paddingLeft: 12,
271
+ paddingRight: 12,
272
+ paddingTop: 0.5,
273
+ paddingBottom: 0.5,
274
+ cursor: 'pointer',
275
+ minHeight: 48,
276
+ width: '100%',
277
+ transition: '0.15s',
278
+ },
279
+ sx: {
280
+ width: '100%',
281
+ '&:hover': {
282
+ backgroundColor: 'background.paper',
283
+ },
284
+ },
285
+ },
286
+ },
287
+ MuiList: {
288
+ defaultProps: {
289
+ style: {
290
+ width: '100%',
291
+ minWidth: 230,
292
+ padding: 0,
293
+ margin: 0,
294
+ gap: 3,
295
+ },
296
+ },
297
+ },
298
+ MuiTooltip: {
299
+ defaultProps: {
300
+ style: {
301
+ fontSize: '1.8rem',
302
+ },
303
+ arrow: true,
304
+ slotProps: {
305
+ tooltip: {
306
+ sx: {
307
+ fontSize: '1.4rem',
308
+ fontWeight: 400,
309
+ bgcolor: 'grey.600',
310
+ color: 'white',
311
+ },
312
+ },
313
+ },
314
+ },
315
+ },
316
+ MuiCard: {
317
+ variants: [
318
+ {
319
+ props: {
320
+ variant: 'outlined',
321
+ },
322
+ style: {
323
+ padding: 30,
324
+ backgroundColor: 'transparent',
325
+ height: 280,
326
+ },
327
+ },
328
+ {
329
+ props: {
330
+ // TODO: fix this type
331
+ // eslint-disable-next-line
332
+ // @ts-ignore
333
+ variant: 'contained',
334
+ },
335
+ style: {
336
+ padding: 30,
337
+ boxShadow: 'none',
338
+ backgroundColor: 'background.paper',
339
+ },
340
+ },
341
+ {
342
+ props: {
343
+ // TODO: fix this type
344
+ // eslint-disable-next-line
345
+ // @ts-ignore
346
+ variant: 'numeric',
347
+ },
348
+ style: {
349
+ width: 50,
350
+ height: 50,
351
+ display: 'flex',
352
+ backgroundColor: '#1E1E1E',
353
+ padding: 0,
354
+ alignItems: 'center',
355
+ justifyContent: 'center',
356
+ },
357
+ },
358
+ ],
359
+ defaultProps: {
360
+ sx: {
361
+ transition: '0.2s',
362
+ boxShadow: 'none',
363
+ '&:hover': {
364
+ borderColor: 'primary.main',
365
+ },
366
+ },
367
+ },
368
+ },
369
+ };
@@ -0,0 +1,39 @@
1
+ export const palette = {
2
+ primary: {
3
+ main: '#791D46',
4
+ dark: '#51132f',
5
+ // light: '#FFEAEC',
6
+ light: '#FFEDF1',
7
+ },
8
+ secondary: {
9
+ main: '#4d1d81',
10
+ dark: '#000000',
11
+ light: '#f7f4fa',
12
+ // light: '#F1F0FF',
13
+ },
14
+ error: {
15
+ main: '#D80809',
16
+ dark: '#D80809',
17
+ light: '#fff2f1',
18
+ },
19
+ success: {
20
+ main: '#0D4D3C',
21
+ dark: '#D80809',
22
+ light: '#edfded',
23
+ },
24
+ info: {
25
+ main: '#222876',
26
+ dark: '#D80809',
27
+ // light: '#e4f5fd',
28
+ light: '#EEF4FC',
29
+ },
30
+ warning: {
31
+ main: '#A5500F',
32
+ dark: '#e67e22',
33
+ light: '#FFE5CA',
34
+ },
35
+ background: {
36
+ paper: '#FAFAFA',
37
+ },
38
+ diver: '#F7F7F7',
39
+ };
@@ -0,0 +1,42 @@
1
+ export const typography = {
2
+ fontFamily: `Inter`,
3
+ h1: {
4
+ fontSize: '4.0rem',
5
+ fontWeight: 500,
6
+ letterSpacing: -0.1,
7
+ },
8
+ h2: {
9
+ fontSize: '3.8rem',
10
+ fontWeight: 550,
11
+ },
12
+ h4: {
13
+ fontSize: '2rem',
14
+ fontWeight: 500,
15
+ },
16
+ h5: {
17
+ fontSize: '2.1rem',
18
+ fontWeight: 500,
19
+ },
20
+ body1: {
21
+ fontSize: '1.9rem',
22
+ lineHeight: 1.5,
23
+ fontWeight: 350,
24
+ },
25
+ body2: {
26
+ fontSize: '1.8rem',
27
+ fontWeight: 350,
28
+ lineHeight: 1.5,
29
+ },
30
+ caption: {
31
+ fontSize: '1.5rem',
32
+ fontWeight: 350,
33
+ textTransform: 'none',
34
+ letterSpacing: 0.1,
35
+ },
36
+ button: {
37
+ fontSize: '1.6rem',
38
+ fontWeight: 350,
39
+ textTransform: 'none',
40
+ letterSpacing: 0.1,
41
+ },
42
+ };
@@ -0,0 +1 @@
1
+ export * from './theme';
File without changes
@@ -0,0 +1,14 @@
1
+ import { createTheme } from '@mui/material';
2
+ import { typography } from './constants/typography';
3
+ import { components } from './constants/components';
4
+ import { palette } from './constants/palette';
5
+
6
+ export const theme = createTheme({
7
+ palette,
8
+ // TODO: fix this type
9
+ // eslint-disable-next-line
10
+ // @ts-ignore
11
+ typography,
12
+ components,
13
+ shape: { borderRadius: 4 },
14
+ });