
Research
/Security News
Mini Shai-Hulud Campaign Hits Red Hat Cloud Services npm Packages
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.
@caldwell619/mui-form-generator
Advanced tools
An API for crafting MUI powered forms.
You'll need to fully setup MUI, following this guide.
This is based on MUI v5, using only v4 will not work with this.
yarn add @caldwell619/mui-form-generator
The following will render a single text input with a label of "One".
name property must match one of your object keys. This is the same behavior as react-hook-form.config. The specifics are determined by the type property. For example, select requires you to pass options.**You must add a provider that wraps your form FOR EACH FORM YOU USE. **
This is not shown in this example, but is shown in this one, with just the single form.
import { FC, useContext } from 'react'
import { MuiForm, Config, MuiFormContext } from '@caldwell619/mui-form-generator'
import { Button } from '@mui/material'
import { UseFormReturn } from 'react-hook-form'
import { diff } from 'deep-object-diff'
export const defaultValues: SomeObject = {
one: 'Rex',
two: 'Cody',
three: 'Wolffe'
}
const inputs: Config<SomeObject>[] = [
{
type: 'text',
config: {
control: {
name: 'one',
label: 'One'
}
}
}
]
export const Form: FC = () => {
const { handleSubmit } = useContext<UseFormReturn<SomeObject>>(MuiFormContext)
const onSubmit = (data: SomeObject) => {
console.log('Current state of form', data)
}
return (
<form>
<MuiForm inputs={inputs} />
<Button variant='outlined' onClick={handleSubmit(onSubmit)}>
Submit
</Button>
</form>
)
}
export interface SomeObject {
one: string
two: string
three: string
}
The result is just a single input and your button under it. Clicking submit will console log an object showing your defaults:
{
one: 'Rex',
two: 'Cody',
three: 'Wolffe'
}
There is a working example with a select input and a text field that can be found here
Currently, there are only 2 supported inputs, but this list will grow with time.
If an input you want is not supported, you can "easily" pass your own custom input into the render. For an example, see the Date override.
This is an example of using a Date picker, which is not supported natively by this tool, because they are so specific.
There are many different kinds, as well as requiring @mui/lab as a peer dependency.
import { CustomOverrideRenderArgs } from '@caldwell619/mui-form-generator'
export const FormInputDate: FC<CustomOverrideRenderArgs<SomeObject>> = ({
field: { value, onChange },
fieldState: { error }
}) => {
return (
<LocalizationProvider dateAdapter={AdapterDateFns}>
<DateTimePicker
value={value}
onChange={onChange}
renderInput={params => <TextField fullWidth {...params} error={!!error} />}
/>
</LocalizationProvider>
)
}
{
type: 'custom',
config: {
control: {
name: 'startDate',
children: props => <FormInputDate {...props} />
}
}
}
You may pass rules to each form component that act as validation. You can read more about the validation rules on react hook form under the "Register Options".
These rules are optional, and will be applied to the unit they are applied to. If none are given, it is assumed the input can be empty upon submission.
There is also validation in the example, here.
rules: {
required: { value: true, message: 'This is required' },
pattern: { value: /^[0-9]*$/, message: 'Must be a number' }
},
When the error state is met, the message you provide will be shown as the helper text.
If there is not an error, and you do not provide helperText, it will be set to an empty string to prevent layout shift should an error occur. This means inputs might be sapced further apart because they essentially have an empty helperText to maintain the layout.
The bundle size is a bit deceptive, as the published version is unminified JS. I haven't found the best way to go about this, but it seems as if the best way is to just provide the source, and let you bundle it.
However you React will also tree shake and minify this library. I'm seeing an average of 3-5kb depending on which inputs are used. This will be less if you are already using these inputs elsewhere in the bundle.
Sometime wrapping the consumer is tedious, you don't really need it at the next level, but it has to go somewhere.
import { UseFormReturn } from 'react-hook-form'
import { MuiFormContext, MuiForm } from '@caldwell619/mui-form-generator'
const Form = () => {
const { handleSubmit } = useContext<UseFormReturn<SomeObject>>(MuiFormContext)
return (
<MuiForm inputs={inputs} gridSpacing={1} />
)
}
const WrappedForm: FC = () => {
return (
<MuiFormProvider>
<Form>
</MuiFormProvider>
)
}
In the above, WrappedForm is uneccesary.
Using withMuiForm, you can access the form config from the same component. It's similar to using MuiFormContext.Consumer, but a bit more conveinient.
import { UseFormReturn } from 'react-hook-form'
import { withMuiForm, MuiFormContext, MuiForm } from '@caldwell619/mui-form-generator'
export const Home = withMuiForm({ defaultValues }, () => {
const { handleSubmit } = useContext<UseFormReturn<SomeObject>>(MuiFormContext)
return <MuiForm inputs={inputs} gridSpacing={1} />
})
FAQs
An API for crafting MUI powered forms.
We found that @caldwell619/mui-form-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.

Security News
The Rust project is moving toward formal rules on LLM use in contributions after months of internal debate over maintainer burden, code quality, and contributor experience.