@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.
- package/README.md +93 -0
- package/package.json +59 -0
- package/src/App.css +34 -0
- package/src/components/atoms/alert/Alert.tsx +35 -0
- package/src/components/atoms/cursor/Cursor.tsx +10 -0
- package/src/components/atoms/index.ts +2 -0
- package/src/components/form/fields/FormInput.tsx +25 -0
- package/src/components/form/fields/FormPassword.tsx +48 -0
- package/src/components/form/fields/FormSelect.tsx +37 -0
- package/src/components/form/fields/FormTextArea.tsx +34 -0
- package/src/components/form/fields/index.ts +4 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/form/layout/FormError.tsx +11 -0
- package/src/components/form/layout/FormLabel.tsx +19 -0
- package/src/components/form/layout/index.ts +2 -0
- package/src/components/index.ts +4 -0
- package/src/components/inputs/Select.tsx +52 -0
- package/src/components/inputs/index.ts +0 -0
- package/src/components/layout/Drawer_/components/DrawerContent.tsx +13 -0
- package/src/components/layout/Drawer_/components/DrawerProvider.tsx +23 -0
- package/src/components/layout/Drawer_/components/DrawerTrigger.tsx +28 -0
- package/src/components/layout/Drawer_/components/index.ts +3 -0
- package/src/components/layout/Drawer_/context/DrawerContext.ts +17 -0
- package/src/components/layout/Drawer_/context/index.ts +1 -0
- package/src/components/layout/Drawer_/hooks/index.ts +2 -0
- package/src/components/layout/Drawer_/hooks/useDrawer.ts +25 -0
- package/src/components/layout/Drawer_/hooks/useDrawerContext.ts +11 -0
- package/src/components/layout/Drawer_/index.ts +3 -0
- package/src/components/layout/Dropdown/components/DropdownPopover.tsx +35 -0
- package/src/components/layout/Dropdown/components/DropdownProvider.tsx +28 -0
- package/src/components/layout/Dropdown/components/DropdownTrigger.tsx +27 -0
- package/src/components/layout/Dropdown/components/index.ts +3 -0
- package/src/components/layout/Dropdown/context/DropdownContext.ts +21 -0
- package/src/components/layout/Dropdown/hooks/index.ts +1 -0
- package/src/components/layout/Dropdown/hooks/useDropdown.ts +22 -0
- package/src/components/layout/Dropdown/hooks/useDropdownContext.ts +11 -0
- package/src/components/layout/Dropdown/index.ts +2 -0
- package/src/components/layout/ScrollToTop/ScrollToTop.tsx +12 -0
- package/src/components/layout/index.ts +5 -0
- package/src/components/widgets/index.ts +0 -0
- package/src/index.css +8 -0
- package/src/index.ts +4 -0
- package/src/provider/CarbonProvider.tsx +13 -0
- package/src/provider/index.ts +1 -0
- package/src/theme/constants/components.ts +369 -0
- package/src/theme/constants/palette.ts +39 -0
- package/src/theme/constants/typography.ts +42 -0
- package/src/theme/index.ts +1 -0
- package/src/theme/theme.d.ts +0 -0
- package/src/theme/theme.ts +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Carbon-ui
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
8
|
+
|
|
9
|
+
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
10
|
+
|
|
11
|
+
## Add your files
|
|
12
|
+
|
|
13
|
+
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
14
|
+
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
cd existing_repo
|
|
18
|
+
git remote add origin https://gitlab.com/packages8185248/carbon-ui.git
|
|
19
|
+
git branch -M main
|
|
20
|
+
git push -uf origin main
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Integrate with your tools
|
|
24
|
+
|
|
25
|
+
- [ ] [Set up project integrations](https://gitlab.com/packages8185248/carbon-ui/-/settings/integrations)
|
|
26
|
+
|
|
27
|
+
## Collaborate with your team
|
|
28
|
+
|
|
29
|
+
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
30
|
+
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
31
|
+
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
32
|
+
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
33
|
+
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
|
34
|
+
|
|
35
|
+
## Test and Deploy
|
|
36
|
+
|
|
37
|
+
Use the built-in continuous integration in GitLab.
|
|
38
|
+
|
|
39
|
+
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
|
|
40
|
+
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
41
|
+
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
42
|
+
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
43
|
+
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
44
|
+
|
|
45
|
+
***
|
|
46
|
+
|
|
47
|
+
# Editing this README
|
|
48
|
+
|
|
49
|
+
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
50
|
+
|
|
51
|
+
## Suggestions for a good README
|
|
52
|
+
|
|
53
|
+
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
54
|
+
|
|
55
|
+
## Name
|
|
56
|
+
Choose a self-explaining name for your project.
|
|
57
|
+
|
|
58
|
+
## Description
|
|
59
|
+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
60
|
+
|
|
61
|
+
## Badges
|
|
62
|
+
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
63
|
+
|
|
64
|
+
## Visuals
|
|
65
|
+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
72
|
+
|
|
73
|
+
## Support
|
|
74
|
+
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
75
|
+
|
|
76
|
+
## Roadmap
|
|
77
|
+
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
State if you are open to contributions and what your requirements are for accepting them.
|
|
81
|
+
|
|
82
|
+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
83
|
+
|
|
84
|
+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
85
|
+
|
|
86
|
+
## Authors and acknowledgment
|
|
87
|
+
Show your appreciation to those who have contributed to the project.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
For open source projects, say how it is licensed.
|
|
91
|
+
|
|
92
|
+
## Project status
|
|
93
|
+
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sonardigital/carbon-ui",
|
|
3
|
+
"version": "1.1.18",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"src/**/*"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"format": "prettier --write './src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
|
|
13
|
+
"prepare": "husky",
|
|
14
|
+
"precommit": "npm run lint && npm run format"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "sonar",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@tsconfig/recommended": "^1.0.6",
|
|
21
|
+
"@types/js-cookie": "^3.0.6",
|
|
22
|
+
"@types/react": "^18.3.21",
|
|
23
|
+
"globals": "^15.6.0"
|
|
24
|
+
},
|
|
25
|
+
"lint-staged": {
|
|
26
|
+
"*.{js,jsx,ts,tsx}": [
|
|
27
|
+
"prettier --write",
|
|
28
|
+
"eslint --fix",
|
|
29
|
+
"git add"
|
|
30
|
+
],
|
|
31
|
+
"*.{html,css,less,ejs,json,md}": [
|
|
32
|
+
"prettier --write",
|
|
33
|
+
"git add"
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@emotion/react": "^11.14.0",
|
|
38
|
+
"@emotion/styled": "^11.14.1",
|
|
39
|
+
"@mui/material": "^7.3.2",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
41
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
42
|
+
"eslint": "^8.57.0",
|
|
43
|
+
"eslint-config-prettier": "^9.1.0",
|
|
44
|
+
"eslint-plugin-import": "^2.31.0",
|
|
45
|
+
"eslint-plugin-prettier": "^5.4.0",
|
|
46
|
+
"eslint-plugin-react": "^7.34.3",
|
|
47
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
48
|
+
"eslint-plugin-react-refresh": "^0.4.7",
|
|
49
|
+
"eslint-plugin-storybook": "^0.8.0",
|
|
50
|
+
"husky": "^9.1.7",
|
|
51
|
+
"lint-staged": "^16.0.0",
|
|
52
|
+
"prettier": "^3.5.3",
|
|
53
|
+
"react": "^19.1.0",
|
|
54
|
+
"react-icons": "^5.5.0",
|
|
55
|
+
"react-router": "^7.6.0",
|
|
56
|
+
"react-router-dom": "^7.6.0",
|
|
57
|
+
"typescript": "^5.4.5"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/App.css
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap');
|
|
2
|
+
|
|
3
|
+
a {
|
|
4
|
+
text-decoration: none;
|
|
5
|
+
color: inherit;
|
|
6
|
+
transition: 0.2s;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
a:hover {
|
|
10
|
+
text-decoration: underline;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
textarea {
|
|
14
|
+
font-family: 'Inter', sans-serif;
|
|
15
|
+
font-size: 1.6rem;
|
|
16
|
+
line-height: 2.4rem;
|
|
17
|
+
padding: 1.6rem;
|
|
18
|
+
width: auto;
|
|
19
|
+
resize: none;
|
|
20
|
+
border: 1px solid #c4c4c4;
|
|
21
|
+
border-radius: 0px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
textarea:hover {
|
|
25
|
+
border-color: #000;
|
|
26
|
+
opacity: 0.8;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
textarea:active,
|
|
30
|
+
textarea:focus {
|
|
31
|
+
border-color: transparent;
|
|
32
|
+
outline: 2px solid #000;
|
|
33
|
+
opacity: 0.8;
|
|
34
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Alert as MuiAlert, Typography, useTheme } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
interface BannerAlertAlertProps {
|
|
5
|
+
severity: 'success' | 'info' | 'warning' | 'error';
|
|
6
|
+
actions?: React.ReactNode;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function BannerAlert({ severity, actions, children }: BannerAlertAlertProps): React.ReactElement {
|
|
11
|
+
const theme = useTheme();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<MuiAlert
|
|
15
|
+
severity={severity}
|
|
16
|
+
action={actions}
|
|
17
|
+
variant="filled"
|
|
18
|
+
icon={false}
|
|
19
|
+
sx={{
|
|
20
|
+
alignItems: 'center',
|
|
21
|
+
minWidth: 350,
|
|
22
|
+
boxShadow: 3,
|
|
23
|
+
bgcolor: theme.palette?.[severity].light,
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
{typeof children === 'string' ? (
|
|
27
|
+
<Typography variant="body2" fontWeight={400} color={severity}>
|
|
28
|
+
{children}
|
|
29
|
+
</Typography>
|
|
30
|
+
) : (
|
|
31
|
+
children
|
|
32
|
+
)}
|
|
33
|
+
</MuiAlert>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Stack, StackProps } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
export function Cursor({ children, sx, ...props }: StackProps): React.ReactElement {
|
|
5
|
+
return (
|
|
6
|
+
<Stack sx={{ cursor: 'pointer', ...sx }} {...props}>
|
|
7
|
+
{children}
|
|
8
|
+
</Stack>
|
|
9
|
+
);
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Stack, TextField, TextFieldProps } from '@mui/material';
|
|
2
|
+
import { Controller } from 'react-hook-form';
|
|
3
|
+
import { FormLabel } from '../layout';
|
|
4
|
+
import { FormError } from '../layout/FormError';
|
|
5
|
+
|
|
6
|
+
interface FormInputProps extends TextFieldProps<'standard'> {
|
|
7
|
+
name: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function FormInput({ name, label, ...props }: FormInputProps): React.ReactElement {
|
|
12
|
+
return (
|
|
13
|
+
<Controller
|
|
14
|
+
name={name}
|
|
15
|
+
render={({ field, fieldState }) => (
|
|
16
|
+
<FormLabel label={label}>
|
|
17
|
+
<Stack gap={0.8}>
|
|
18
|
+
<TextField {...field} {...props} />
|
|
19
|
+
{fieldState.error && <FormError label={fieldState.error?.message ?? ''} />}
|
|
20
|
+
</Stack>
|
|
21
|
+
</FormLabel>
|
|
22
|
+
)}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { OutlinedInput, Stack } from '@mui/material';
|
|
2
|
+
import { Controller } from 'react-hook-form';
|
|
3
|
+
import { FormLabel } from '../layout';
|
|
4
|
+
import { FormError } from '../layout/FormError';
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import RemoveRedEyeIcon from '@mui/icons-material/RemoveRedEye';
|
|
7
|
+
import { Cursor } from 'src/components/atoms';
|
|
8
|
+
|
|
9
|
+
export function FormPassword({ name, label }: { name: string; label: string }): React.ReactElement {
|
|
10
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
11
|
+
return (
|
|
12
|
+
<Controller
|
|
13
|
+
name={name}
|
|
14
|
+
render={({ field, fieldState }) => (
|
|
15
|
+
<FormLabel label={label}>
|
|
16
|
+
<Stack gap={0.8}>
|
|
17
|
+
<OutlinedInput
|
|
18
|
+
sx={{ borderRadius: 1.5, width: '100%', height: 52 }}
|
|
19
|
+
type={isVisible ? 'text' : 'password'}
|
|
20
|
+
color="secondary"
|
|
21
|
+
{...field}
|
|
22
|
+
inputProps={{
|
|
23
|
+
sx: {
|
|
24
|
+
width: '100%',
|
|
25
|
+
fontSize: '1.7rem',
|
|
26
|
+
borderRadius: 3,
|
|
27
|
+
},
|
|
28
|
+
}}
|
|
29
|
+
endAdornment={
|
|
30
|
+
<Cursor>
|
|
31
|
+
<RemoveRedEyeIcon
|
|
32
|
+
sx={{
|
|
33
|
+
width: 24,
|
|
34
|
+
height: 24,
|
|
35
|
+
opacity: isVisible ? 1 : 0.5,
|
|
36
|
+
}}
|
|
37
|
+
onClick={() => setIsVisible(!isVisible)}
|
|
38
|
+
/>
|
|
39
|
+
</Cursor>
|
|
40
|
+
}
|
|
41
|
+
/>
|
|
42
|
+
{fieldState.error && <FormError label={fieldState.error?.message ?? ''} />}
|
|
43
|
+
</Stack>
|
|
44
|
+
</FormLabel>
|
|
45
|
+
)}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AutocompleteProps, Stack } from '@mui/material';
|
|
2
|
+
import { Controller } from 'react-hook-form';
|
|
3
|
+
import { FormLabel } from '../layout';
|
|
4
|
+
import { FormError } from '../layout/FormError';
|
|
5
|
+
import { SelectAutocomplete } from 'src/components/inputs/Select';
|
|
6
|
+
|
|
7
|
+
interface SelectAutocompleteProps
|
|
8
|
+
extends Omit<
|
|
9
|
+
AutocompleteProps<{ label: string; value: string | number }, false, false, false>,
|
|
10
|
+
'renderInput' | 'options' | 'value' | 'onChange'
|
|
11
|
+
> {
|
|
12
|
+
name: string;
|
|
13
|
+
label: string;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
options: { label: string; value: string | number }[];
|
|
16
|
+
helperText?: string;
|
|
17
|
+
fetchOptions?: () => Promise<{ label: string; value: string | number }[]>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function FormSelect({ name, label, options, ...rest }: SelectAutocompleteProps): React.ReactElement {
|
|
21
|
+
return (
|
|
22
|
+
<Controller
|
|
23
|
+
name={name}
|
|
24
|
+
render={({ field, fieldState }) => {
|
|
25
|
+
const { value, onChange } = field;
|
|
26
|
+
return (
|
|
27
|
+
<FormLabel label={label}>
|
|
28
|
+
<Stack gap={0.8}>
|
|
29
|
+
<SelectAutocomplete {...field} {...rest} options={options} value={value} onChange={onChange} />
|
|
30
|
+
{fieldState.error && <FormError label={fieldState.error?.message ?? ''} />}
|
|
31
|
+
</Stack>
|
|
32
|
+
</FormLabel>
|
|
33
|
+
);
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Stack, TextareaAutosize, TextareaAutosizeProps, useTheme } from '@mui/material';
|
|
2
|
+
import { Controller } from 'react-hook-form';
|
|
3
|
+
import { FormLabel } from '../layout';
|
|
4
|
+
import { FormError } from '../layout/FormError';
|
|
5
|
+
|
|
6
|
+
interface FormTextareaProps extends TextareaAutosizeProps {
|
|
7
|
+
name: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function FormTextarea({ name, label, ...props }: FormTextareaProps): React.ReactElement {
|
|
12
|
+
const theme = useTheme();
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Controller
|
|
16
|
+
name={name}
|
|
17
|
+
render={({ field, fieldState }) => (
|
|
18
|
+
<FormLabel label={label}>
|
|
19
|
+
<Stack gap={0.8}>
|
|
20
|
+
<TextareaAutosize
|
|
21
|
+
minRows={5}
|
|
22
|
+
{...field}
|
|
23
|
+
{...props}
|
|
24
|
+
style={{
|
|
25
|
+
borderRadius: theme.shape.borderRadius,
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
{fieldState.error && <FormError label={fieldState.error?.message ?? ''} />}
|
|
29
|
+
</Stack>
|
|
30
|
+
</FormLabel>
|
|
31
|
+
)}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fields';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Alert, Typography } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
export function FormError({ label }: { label: string }): React.ReactElement {
|
|
4
|
+
return (
|
|
5
|
+
<Alert severity="error" icon={false} sx={{ bgcolor: 'error.light' }}>
|
|
6
|
+
<Typography variant="body2" color="error" sx={{ opacity: 1, color: 'error.main' }}>
|
|
7
|
+
{label}
|
|
8
|
+
</Typography>
|
|
9
|
+
</Alert>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Stack, Typography } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
export function FormLabel({
|
|
5
|
+
label,
|
|
6
|
+
children,
|
|
7
|
+
}: {
|
|
8
|
+
label: string;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}): React.ReactElement {
|
|
11
|
+
return (
|
|
12
|
+
<Stack width="100%" gap={0.5}>
|
|
13
|
+
<Typography variant="body1" fontWeight={500}>
|
|
14
|
+
{label}
|
|
15
|
+
</Typography>
|
|
16
|
+
{children}
|
|
17
|
+
</Stack>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Autocomplete, AutocompleteProps, IconButton, TextField, useTheme } from '@mui/material';
|
|
3
|
+
import { RiCloseFill } from 'react-icons/ri';
|
|
4
|
+
|
|
5
|
+
interface SelectAutocompleteProps
|
|
6
|
+
extends Omit<
|
|
7
|
+
AutocompleteProps<{ label: string; value: string | number }, false, false, false>,
|
|
8
|
+
'renderInput' | 'onChange' | 'value'
|
|
9
|
+
> {
|
|
10
|
+
value: string | number | null;
|
|
11
|
+
onChange: (value: string | number | null) => void;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
options: { label: string; value: string | number }[];
|
|
14
|
+
helperText?: string;
|
|
15
|
+
fetchOptions?: () => Promise<{ label: string; value: string | number }[]>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function SelectAutocomplete(props: SelectAutocompleteProps): React.ReactElement {
|
|
19
|
+
const { options = [], value, onChange, placeholder, ...rest } = props;
|
|
20
|
+
|
|
21
|
+
const theme = useTheme();
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Autocomplete
|
|
25
|
+
value={options?.find((option) => option.value === value) || null}
|
|
26
|
+
noOptionsText="No options"
|
|
27
|
+
onChange={(_, value) => value?.value && onChange(value.value)}
|
|
28
|
+
getOptionLabel={(option) => option.label || ''}
|
|
29
|
+
clearIcon={
|
|
30
|
+
<IconButton size="small" onClick={() => onChange(null)}>
|
|
31
|
+
<RiCloseFill size={18} />
|
|
32
|
+
</IconButton>
|
|
33
|
+
}
|
|
34
|
+
popupIcon={null}
|
|
35
|
+
renderInput={(params) => (
|
|
36
|
+
<TextField
|
|
37
|
+
inputProps={params.inputProps}
|
|
38
|
+
InputLabelProps={params.InputLabelProps}
|
|
39
|
+
placeholder={placeholder}
|
|
40
|
+
InputProps={{
|
|
41
|
+
...params.InputProps,
|
|
42
|
+
sx: {
|
|
43
|
+
...theme.components?.MuiTextField?.defaultProps?.InputProps?.sx,
|
|
44
|
+
},
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
)}
|
|
48
|
+
{...rest}
|
|
49
|
+
options={options || []}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DrawerProps, Drawer as MuiDrawer } from '@mui/material';
|
|
3
|
+
import { useDrawerContext } from '../hooks/useDrawerContext';
|
|
4
|
+
|
|
5
|
+
export default function DrawerContent({ children, ...props }: DrawerProps): React.ReactElement {
|
|
6
|
+
const { isOpen, closeDrawer } = useDrawerContext();
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<MuiDrawer open={isOpen} onClose={closeDrawer} {...props}>
|
|
10
|
+
{children}
|
|
11
|
+
</MuiDrawer>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Stack } from '@mui/material';
|
|
3
|
+
import { useDrawer } from '../hooks/useDrawer';
|
|
4
|
+
import DrawerContext, { DrawerContextType } from '../context/DrawerContext';
|
|
5
|
+
|
|
6
|
+
interface DrawerProviderProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
methods?: DrawerContextType;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function DrawerProvider({
|
|
12
|
+
methods,
|
|
13
|
+
children,
|
|
14
|
+
}: DrawerProviderProps): React.ReactElement<DrawerProviderProps> {
|
|
15
|
+
const defaultMethods = useDrawer();
|
|
16
|
+
return (
|
|
17
|
+
<DrawerContext.Provider value={methods ?? defaultMethods}>
|
|
18
|
+
<Stack flexDirection="column" position="relative" width="auto" height="auto">
|
|
19
|
+
{children}
|
|
20
|
+
</Stack>
|
|
21
|
+
</DrawerContext.Provider>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ButtonBase } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useDrawerContext } from '../hooks/useDrawerContext';
|
|
4
|
+
|
|
5
|
+
interface DialogTriggerProps {
|
|
6
|
+
children?: React.ReactElement;
|
|
7
|
+
openIcon?: React.ReactNode;
|
|
8
|
+
closeIcon?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function DrawerTrigger({
|
|
12
|
+
children,
|
|
13
|
+
openIcon,
|
|
14
|
+
closeIcon,
|
|
15
|
+
}: DialogTriggerProps): React.ReactElement {
|
|
16
|
+
const { isOpen, toggleDrawer } = useDrawerContext();
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ButtonBase
|
|
20
|
+
sx={{ posiion: 'relative', alignSelf: 'center' }}
|
|
21
|
+
disableRipple
|
|
22
|
+
onClick={() => toggleDrawer()}
|
|
23
|
+
>
|
|
24
|
+
{children}
|
|
25
|
+
{!isOpen ? openIcon : closeIcon}
|
|
26
|
+
</ButtonBase>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, createContext } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface DrawerContextType {
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
openDrawer: () => void;
|
|
6
|
+
closeDrawer: () => void;
|
|
7
|
+
toggleDrawer: () => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const DrawerContext: Context<DrawerContextType> = createContext<DrawerContextType>({
|
|
11
|
+
isOpen: false,
|
|
12
|
+
openDrawer: () => {},
|
|
13
|
+
closeDrawer: () => {},
|
|
14
|
+
toggleDrawer: () => {},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default DrawerContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DrawerContext';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { DrawerContextType } from '../context/DrawerContext';
|
|
3
|
+
|
|
4
|
+
export const useDrawer = (): DrawerContextType => {
|
|
5
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
6
|
+
|
|
7
|
+
const openDrawer = (): void => {
|
|
8
|
+
setIsOpen(true);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const closeDrawer = (): void => {
|
|
12
|
+
setIsOpen(false);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const toggleDrawer = (): void => {
|
|
16
|
+
setIsOpen((prevState) => !prevState);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
isOpen,
|
|
21
|
+
openDrawer,
|
|
22
|
+
closeDrawer,
|
|
23
|
+
toggleDrawer,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import DrawerContext, { DrawerContextType } from '../context/DrawerContext';
|
|
3
|
+
|
|
4
|
+
export const useDrawerContext = (): DrawerContextType => {
|
|
5
|
+
const context = useContext(DrawerContext);
|
|
6
|
+
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error('useDrawer must be used within a DrawerProvider');
|
|
9
|
+
}
|
|
10
|
+
return context;
|
|
11
|
+
};
|