-
Notifications
You must be signed in to change notification settings - Fork 2
update-mui-design-system #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
anicioalexandre
merged 3 commits into
BA-903-mui-design-system
from
BA-914-update-mui-design-system
Aug 11, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,54 @@ | ||
| import { ButtonWithLoading } from '@baseapp-frontend/design-system-mui' | ||
| import { | ||
| ButtonWithLoading, | ||
| PasswordField, | ||
| ImageUploader, | ||
| } from '@baseapp-frontend/design-system-mui' | ||
| import { Divider, useTheme } from '@mui/material' | ||
| import { useState } from 'react' | ||
|
|
||
| export default function Docs() { | ||
| const [images, setImages] = useState([]) | ||
| const theme = useTheme() | ||
| return ( | ||
| <div> | ||
| <h1>Docs</h1> | ||
| <ButtonWithLoading>button</ButtonWithLoading> | ||
| <h1>Components demo</h1> | ||
| <Divider style={{ margin: theme.spacing(2, 0) }} /> | ||
|
|
||
| <h2>{`<ButtonWithLoading>`}</h2> | ||
| <div style={{ width: theme.spacing(48), display: 'flex', flexDirection: 'column' }}> | ||
| <ButtonWithLoading variant="contained" style={{ margin: theme.spacing(2, 0) }}> | ||
| button | ||
| </ButtonWithLoading> | ||
|
|
||
| <ButtonWithLoading variant="contained" loading> | ||
| button | ||
| </ButtonWithLoading> | ||
| </div> | ||
|
|
||
| <Divider style={{ margin: theme.spacing(2, 0) }} /> | ||
|
|
||
| <div style={{ width: theme.spacing(48) }}> | ||
| <h2>{`<PasswordField />`}</h2> | ||
| <PasswordField /> | ||
|
|
||
| <PasswordField helperText="Type your password." /> | ||
|
|
||
| <PasswordField error helperText="Incorrect entry." /> | ||
| </div> | ||
|
|
||
| <Divider style={{ margin: theme.spacing(2, 0) }} /> | ||
|
|
||
| <h2>{`<ImageUploader />`}</h2> | ||
| <div style={{ width: theme.spacing(48) }}> | ||
| <ImageUploader | ||
| images={images} | ||
| setImages={setImages} | ||
| name="imageUploeader" | ||
| ImageProps={{ style: { outline: '1px solid blue' } }} | ||
| buttonLabel="Upload your image here" | ||
| buttonRemoveLabel="Remove" | ||
| /> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 16 additions & 2 deletions
18
packages/design-system-mui/components/ButtonWithLoading/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,19 @@ | ||
| import { Button } from './styled' | ||
| import { Button } from '@mui/material' | ||
| import { CircularProgress } from './styled' | ||
|
|
||
| const ButtonWithLoading = ({ children }) => <Button>{children} With Loading</Button> | ||
| function ButtonWithLoading({ | ||
| loading = false, | ||
| children, | ||
| loadingChildren = <CircularProgress size="20px" />, | ||
| loadingColor = 'primary', | ||
| ...props | ||
| }) { | ||
| return ( | ||
| <Button disabled={loading} {...props}> | ||
| {children} | ||
| {loading && loadingChildren} | ||
| </Button> | ||
| ) | ||
| } | ||
|
|
||
| export default ButtonWithLoading |
13 changes: 9 additions & 4 deletions
13
packages/design-system-mui/components/ButtonWithLoading/styled.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| import { styled } from '@mui/material/styles' | ||
| import { Button as MUIButton } from '@mui/material' | ||
| import { CircularProgress as MuiCircularProgress, CircularProgressProps } from '@mui/material' | ||
| import { FC } from 'react' | ||
|
|
||
| export const Button = styled(MUIButton)(({ theme }) => ({ | ||
| background: theme.palette.primary.main, | ||
| })) | ||
| export const CircularProgress = styled(MuiCircularProgress)(({ theme }) => ({ | ||
| position: 'absolute', | ||
| top: '50%', | ||
| left: '50%', | ||
| marginTop: '-10px', | ||
| marginLeft: '-10px', | ||
| })) as unknown as FC<CircularProgressProps> | ||
83 changes: 83 additions & 0 deletions
83
packages/design-system-mui/components/ImageUploader/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { FormControl, FormHelperText } from '@mui/material' | ||
| import UploadFileOutlinedIcon from '@mui/icons-material/UploadFileOutlined' | ||
| import type { IImageUploadInput } from './types' | ||
| import { ImageGroup, Image, UploaderButton, LabelGroup, ImageLabel, DeleteButton } from './styled' | ||
|
|
||
| function ImageUploader({ | ||
| images, | ||
| setImages, | ||
| buttonLabel, | ||
| buttonRemoveLabel, | ||
| name, | ||
| error, | ||
| helperText, | ||
| ImageProps, | ||
| ImageLabelProps, | ||
| DeleteButtonProps, | ||
| UploaderButtonProps, | ||
| ...props | ||
| }: IImageUploadInput) { | ||
| const deleteImage = (index: number) => { | ||
| const newImages = [...images] | ||
| newImages.splice(index, 1) | ||
| setImages(newImages) | ||
| } | ||
|
|
||
| function onChange(e: any): void { | ||
| //eslint-disable-line @typescript-eslint/no-explicit-any | ||
| for (let i = 0; i < e.target?.files?.length; i++) { | ||
| const file = e.target?.files[i] | ||
| const fileReader = new FileReader() | ||
| fileReader.onload = () => { | ||
| setImages([{ file: file, imagePreviewUrl: fileReader.result }]) | ||
| } | ||
| fileReader.readAsDataURL(file) | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <FormControl error={error} fullWidth> | ||
| <UploaderButton | ||
| component="label" | ||
| htmlFor={'imageInput' + name} | ||
| variant="outlined" | ||
| color="primary" | ||
| sx={{ display: images.length ? 'none' : 'auto' }} | ||
| {...UploaderButtonProps} | ||
| > | ||
| <UploadFileOutlinedIcon sx={{ marginRight: 1 }} /> | ||
| {buttonLabel || 'Upload Photo'} | ||
| </UploaderButton> | ||
| <input | ||
| name={name} | ||
| id={'imageInput' + name} | ||
| type="file" | ||
| accept="image/*" | ||
| onChange={onChange} | ||
| style={{ display: 'none' }} | ||
| {...props} | ||
| /> | ||
| {error && <FormHelperText>{helperText}</FormHelperText>} | ||
| {images.map((img, index) => ( | ||
| <ImageGroup key={index}> | ||
| <Image src={img.imagePreviewUrl as string} alt="preview" {...ImageProps} /> | ||
| <LabelGroup> | ||
| <ImageLabel variant="caption" {...ImageLabelProps}> | ||
| {img.file.name} | ||
| </ImageLabel> | ||
| <DeleteButton | ||
| onClick={() => deleteImage(index)} | ||
| variant="text" | ||
| color="primary" | ||
| {...DeleteButtonProps} | ||
| > | ||
| {buttonRemoveLabel || 'Remove Photo'} | ||
| </DeleteButton> | ||
| </LabelGroup> | ||
| </ImageGroup> | ||
| ))} | ||
| </FormControl> | ||
| ) | ||
| } | ||
|
|
||
| export default ImageUploader |
53 changes: 53 additions & 0 deletions
53
packages/design-system-mui/components/ImageUploader/styled.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { styled } from '@mui/material/styles' | ||
| import { Button as MuiButton, Typography } from '@mui/material' | ||
| import { FC } from 'react' | ||
| import { fontSize } from '../../styles/utils' | ||
|
|
||
| const UploaderButton = styled(MuiButton)(({ theme }) => ({ | ||
| width: '100%', | ||
| marginTop: theme.spacing(2), | ||
| border: `1px dashed ${theme.palette.grey[500]}`, | ||
| borderRadius: '8px', | ||
| height: '46px', | ||
| color: theme.palette.grey[500], | ||
| textTransform: 'capitalize', | ||
| })) as unknown as typeof MuiButton | ||
|
|
||
| const ImageGroup = styled('div')(({ theme }) => ({ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| marginTop: theme.spacing(2), | ||
| })) as unknown as FC | ||
|
|
||
| const Image = styled('img')(({ theme }) => ({ | ||
| width: '87px', | ||
| height: '87px', | ||
| objectFit: 'cover', | ||
| borderRadius: theme.spacing(1), | ||
| })) as unknown as FC<JSX.IntrinsicElements['img']> | ||
|
|
||
| const LabelGroup = styled('div')(({ theme }) => ({ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'flex-start', | ||
| justifyContent: 'flex-start', | ||
| marginLeft: theme.spacing(1), | ||
| })) as unknown as FC | ||
|
|
||
| const ImageLabel = styled(Typography)(({ theme }) => ({ | ||
| color: theme.palette.grey[500], | ||
| fontSize: fontSize(16), | ||
| padding: theme.spacing(1), | ||
| })) as unknown as typeof Typography | ||
|
|
||
| const DeleteButton = styled(MuiButton)(({ theme }) => ({ | ||
| color: theme.palette.warning[500], | ||
| textDecoration: 'underline', | ||
| textTransform: 'capitalize', | ||
| fontSize: fontSize(14), | ||
| '&:hover': { | ||
| color: theme.palette.warning[200], | ||
| }, | ||
| })) as unknown as typeof MuiButton | ||
|
|
||
| export { UploaderButton, ImageGroup, Image, LabelGroup, ImageLabel, DeleteButton } |
24 changes: 24 additions & 0 deletions
24
packages/design-system-mui/components/ImageUploader/types.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| export interface IInputBaseComponentProps | ||
| extends React.HTMLAttributes<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement> { | ||
| // Accommodate arbitrary additional props coming from the `IInputProps` prop | ||
| [arbitrary: string]: any | ||
| } | ||
|
|
||
| export interface IInputProps extends IInputBaseComponentProps { | ||
| component?: React.ElementType<IInputBaseComponentProps> | React.FC<any> | ||
| templateComponent?: React.FC<any> | ||
| name: string | ||
| label?: string | ||
| helperText?: string | ||
| } | ||
|
|
||
| interface IImageUploadInput extends IInputProps { | ||
| ImageProps?: IImageProps | ||
| ImageLabelProps?: IImageLabelProps | ||
| DeleteButtonProps?: IImageDeleteButtonProps | ||
| } | ||
|
|
||
| interface ImageFile { | ||
| file: File | ||
| imagePreviewUrl: string | ArrayBuffer | null | ||
| } |
55 changes: 55 additions & 0 deletions
55
packages/design-system-mui/components/PasswordField/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { useState, ReactElement } from 'react' | ||
| import IconButton from '@mui/material/IconButton' | ||
| import InputAdornment from '@mui/material/InputAdornment' | ||
| import Visibility from '@mui/icons-material/Visibility' | ||
| import VisibilityOff from '@mui/icons-material/VisibilityOff' | ||
| import { TextField } from './styled' | ||
| import { useTheme } from '@mui/material' | ||
| import { IPasswordFieldProps } from './types' | ||
|
|
||
| function PasswordField({ | ||
| name = 'password', | ||
| visibilityIconColor, | ||
| InputLabelProps, | ||
| InputProps, | ||
| ...props | ||
| }: IPasswordFieldProps): ReactElement { | ||
| const [viewPassword, setViewPassword] = useState(false) | ||
| const theme = useTheme() | ||
| return ( | ||
| <TextField | ||
| label="Password" | ||
| placeholder="Password" | ||
| type={viewPassword ? 'text' : 'password'} | ||
| name={name} | ||
| InputLabelProps={{ ...InputLabelProps }} | ||
| InputProps={{ | ||
| endAdornment: ( | ||
| <InputAdornment position="end"> | ||
| <IconButton | ||
| aria-label="toggle password visibility" | ||
| onClick={() => setViewPassword((state: any) => !state)} | ||
| edge="end" | ||
| > | ||
| {viewPassword ? ( | ||
| <VisibilityOff | ||
| htmlColor={visibilityIconColor || theme.palette.grey[500]} | ||
| sx={{ marginRight: '4px' }} | ||
| /> | ||
| ) : ( | ||
| <Visibility | ||
| htmlColor={visibilityIconColor || theme.palette.grey[500]} | ||
| sx={{ marginRight: '4px' }} | ||
| /> | ||
| )} | ||
| </IconButton> | ||
| </InputAdornment> | ||
| ), | ||
| ...InputProps, | ||
| }} | ||
| {...props} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| export default PasswordField |
10 changes: 10 additions & 0 deletions
10
packages/design-system-mui/components/PasswordField/styled.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { styled, makeStyles } from '@mui/material/styles' | ||
| import { TextField as MuiITextField, TextFieldProps } from '@mui/material' | ||
| import { FC } from 'react' | ||
|
|
||
| const TextField = styled(MuiITextField)(({ theme }) => ({ | ||
| width: '100%', | ||
| marginBottom: theme.spacing(2), | ||
| })) as unknown as FC<TextFieldProps> | ||
|
|
||
| export { TextField } |
12 changes: 12 additions & 0 deletions
12
packages/design-system-mui/components/PasswordField/types.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { TextFieldProps } from '@mui/material' | ||
|
|
||
| export interface IPasswordFieldProps extends ITextFieldProps { | ||
| component?: React.ElementType<ITextFieldProps> | React.FC | ||
| name?: string | ||
| label?: string | ||
| helperText?: string | ||
| InputLabelProps?: TextFieldProps['InputLabelProps'] | ||
| InputProps?: TextFieldProps['InputProps'] | ||
| visibilityIconColor?: string | ||
| error?: boolean | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| "dependencies": { | ||
| "@emotion/react": "^11.10.0", | ||
| "@emotion/styled": "^11.10.0", | ||
| "@mui/icons-material": "^5.8.4", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's not add this until we need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am using that |
||
| "@mui/material": "^5.10.0", | ||
| "react": "^18.2.0", | ||
| "react-dom": "^18.2.0" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export function fontSize(fontSizeInPx: number, defaultFontSize = 16): string { | ||
| /* | ||
| - This should be used when you have a font-size value in px as reference | ||
| (i.e figma) to convert it to rem values instead; | ||
| - Should used just for 'font-size' property | ||
| - This can be useful when changing globaly the 'font-size' for accessibilty reasons; | ||
| - <body> should use this same default font-size value, 16px is usualy the default; | ||
| - avoid changing the defaultFontSize value. | ||
| */ | ||
| return `${fontSizeInPx / defaultFontSize}rem` | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't be better if we show the loading state besides the children text? Not sure how the design looks like but seems better than overlapping the content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can always have your own loadingChildren to overwrite