Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/docs/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export default function Docs() {

<div style={{ width: theme.spacing(48) }}>
<h2>{`<PasswordField />`}</h2>
<PasswordField />
<PasswordField name="password" />

<PasswordField helperText="Type your password." />
<PasswordField name="password" helperText="Type your password." />

<PasswordField error helperText="Incorrect entry." />
<PasswordField name="password" error helperText="Incorrect entry." />
</div>

<Divider style={{ margin: theme.spacing(2, 0) }} />
Expand Down
7 changes: 7 additions & 0 deletions packages/design-system-mui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @baseapp-frontend/design-system-mui

## 1.1.0

### Minor Changes

- Added TextField
- Added support to Formik (These will be changed in the future, just added to the sake of keep current baseapp-nextjs-mui-template working)

## 1.0.1

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ function ButtonWithLoading({
loading = false,
children,
loadingChildren = <CircularProgress size="20px" />,
formik,
...props
}: IButtonWitthLoadingProps) {
const _isLoading = formik ? formik.isSubmitting : loading
return (
<Button disabled={loading} {...props}>
{children}
{loading && loadingChildren}
{_isLoading && loadingChildren}
</Button>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface IButtonWitthLoadingProps extends ButtonProps {
children?: React.FC<any> | React.Element | string
loading?: boolean
loadingChildren?: React.FC<any> | React.Element
formik?: any // eslint-disable-line @typescript-eslint/no-explicit-any
}
12 changes: 7 additions & 5 deletions packages/design-system-mui/components/ImageUploader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { ReactChild, ReactFragment, ReactPortal, Key } from 'react'
function ImageUploader({
images,
setImages,
buttonLabel,
buttonRemoveLabel,
buttonLabel = 'Upload Image',
buttonRemoveLabel = 'Remove Image',
name,
error,
helperText,
Expand All @@ -18,6 +18,8 @@ function ImageUploader({
UploaderButtonProps,
...props
}: IImageUploadInput) {
// @TODO: Add support for multiple images
// @TODO Add formik or other form context to support form validation
const deleteImage = (index: number) => {
const newImages = [...images]
newImages.splice(index, 1)
Expand Down Expand Up @@ -47,7 +49,7 @@ function ImageUploader({
{...UploaderButtonProps}
>
<UploadFileOutlinedIcon sx={{ marginRight: 1 }} />
{buttonLabel || 'Upload Photo'}
{buttonLabel}
</UploaderButton>
<input
name={name}
Expand All @@ -59,7 +61,7 @@ function ImageUploader({
{...props}
/>
{error && <FormHelperText>{helperText}</FormHelperText>}
{images.map((img: ImageFile, index: number) => (
{images?.map((img: ImageFile, index: number) => (
<ImageGroup key={index}>
<Image src={img.imagePreviewUrl as string} alt="preview" {...ImageProps} />
<LabelGroup>
Expand All @@ -72,7 +74,7 @@ function ImageUploader({
color="primary"
{...DeleteButtonProps}
>
{buttonRemoveLabel || 'Remove Photo'}
{buttonRemoveLabel}
</DeleteButton>
</LabelGroup>
</ImageGroup>
Expand Down
27 changes: 10 additions & 17 deletions packages/design-system-mui/components/ImageUploader/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
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 {
export interface IImageUploadInput extends IInputProps {
ImageProps?: IImageProps
ImageLabelProps?: IImageLabelProps
DeleteButtonProps?: IImageDeleteButtonProps
image?: ImageFile[]
images: ImageFile[]
setImages: Dispatch<SetStateAction<never[]>>
buttonLabel?: string
buttonRemoveLabel?: string
name?: string
UploaderButtonProps?: IImageUploaderButtonProps
error?: boolean
helperText?: string
}

interface ImageFile {
export interface ImageFile {
file: File
imagePreviewUrl: string | ArrayBuffer | null
}
10 changes: 6 additions & 4 deletions packages/design-system-mui/components/PasswordField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ 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 { StyledPasswordTextField } from './styled'
import { useTheme } from '@mui/material'
import { IPasswordFieldProps } from './types'
import { ITextField } from '../TextField/types'

function PasswordField({
name = 'password',
visibilityIconColor,
InputLabelProps,
InputProps,
formik,
...props
}: IPasswordFieldProps): ReactElement {
}: ITextField): ReactElement {
const [viewPassword, setViewPassword] = useState(false)
const theme = useTheme()
return (
<TextField
<StyledPasswordTextField
label="Password"
placeholder="Password"
type={viewPassword ? 'text' : 'password'}
name={name}
formik={formik}
InputLabelProps={{ ...InputLabelProps }}
InputProps={{
endAdornment: (
Expand Down
11 changes: 5 additions & 6 deletions packages/design-system-mui/components/PasswordField/styled.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { styled, makeStyles } from '@mui/material/styles'
import { TextField as MuiITextField, TextFieldProps } from '@mui/material'
import { FC } from 'react'
import { styled } from '@mui/material/styles'
import TextField from '../TextField'

const TextField = styled(MuiITextField)(({ theme }) => ({
const StyledPasswordTextField = styled(TextField)(({ theme }) => ({
width: '100%',
marginBottom: theme.spacing(2),
})) as unknown as FC<TextFieldProps>
}))

export { TextField }
export { StyledPasswordTextField }
12 changes: 0 additions & 12 deletions packages/design-system-mui/components/PasswordField/types.d.ts

This file was deleted.

18 changes: 18 additions & 0 deletions packages/design-system-mui/components/TextField/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import MuiTextField from '@mui/material/TextField'
import { ITextField } from './types'

function TextField({ name, formik, helperText, value, handleChange, ...props }: ITextField) {
const showError = (formik?.errors?.[name] && formik?.touched?.[name]) as boolean
return (
<MuiTextField
name={name}
onChange={formik?.handleChange || handleChange}
value={formik?.values?.[name] || value}
error={showError}
helperText={showError ? formik.errors?.[name] : helperText}
{...props}
/>
)
}

export default TextField
22 changes: 22 additions & 0 deletions packages/design-system-mui/components/TextField/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { TextFieldProps } from '@mui/material'

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>
formik?: any // eslint-disable-line @typescript-eslint/no-explicit-any
templateComponent?: React.FC<any>
name: string
label?: string
helperText?: string
value?: string
handleChange?: (
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>,
) => void
}

export type ITextField = TextFieldProps & IInputProps
12 changes: 11 additions & 1 deletion packages/design-system-mui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ export * from './styles/utils'

export { default as theme } from './styles/theme'

export * from './components/ButtonWithLoading'
export { default as ButtonWithLoading } from './components/ButtonWithLoading'
export type { IButtonWitthLoadingProps } from './components/ButtonWithLoading/types'

export { default as PasswordField } from './components/PasswordField'

export { default as ImageUploader } from './components/ImageUploader'
export type { IImageUploadInput, ImageFile } from './components/ImageUploader/types'

export { default as TextField } from './components/TextField'
export type {
ITextField,
IInputBaseComponentProps,
IInputProps,
} from './components/TextField/types'
2 changes: 1 addition & 1 deletion packages/design-system-mui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@baseapp-frontend/design-system-mui",
"description": "Design System components and configurations.",
"version": "1.0.1",
"version": "1.1.0",
"main": "./dist/index.ts",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down