-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,639 additions
and
397 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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,51 @@ | ||
import * as React from 'react' | ||
import { | ||
FormControl, | ||
FormControlProps, | ||
FormHelperText, | ||
FormHelperTextProps, | ||
InputLabel, | ||
InputLabelProps, | ||
MenuItem, | ||
Select, | ||
TextField | ||
} from '@mui/material' | ||
import { Input } from '@nextui-org/react' | ||
|
||
/** | ||
* @description MUI表单项参数 | ||
*/ | ||
export type FormItemProps = FormControlProps & { | ||
helperText?: React.ReactNode | ||
label?: React.ReactNode | ||
error?: boolean | ||
inputLabelProps?: InputLabelProps | ||
formHelperText?: FormHelperTextProps | ||
} | ||
|
||
/** | ||
* MUI FormControl,FormLabel,FormHelperText 轻封装 | ||
* @param props | ||
* @returns | ||
*/ | ||
export const FormItem = ({ | ||
children, | ||
helperText, | ||
label, | ||
error, | ||
inputLabelProps = {}, | ||
formHelperText = {}, | ||
...props | ||
}: FormItemProps) => { | ||
return ( | ||
<FormControl {...props}> | ||
<InputLabel error={error} {...inputLabelProps}> | ||
{label} | ||
</InputLabel> | ||
{children} | ||
<FormHelperText {...formHelperText} error={error}> | ||
{helperText} | ||
</FormHelperText> | ||
</FormControl> | ||
) | ||
} |
This file contains 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,133 @@ | ||
import { AttrBase } from '@/AttrBase' | ||
import { RenderAttrProps } from '@/useAttr' | ||
import { AutocompleteProps, TextFieldProps } from '@mui/material' | ||
import { FormItem, FormItemProps } from './FormItem' | ||
|
||
/** | ||
* MUI.5的快速绑定支持 静态工具类, 无需new,直接使用 | ||
*/ | ||
export class MUI_5 extends AttrBase { | ||
private constructor() { | ||
super() | ||
} | ||
|
||
static M_AutoComplete = < | ||
Value, | ||
Multiple extends boolean | undefined, | ||
DisableClearable extends boolean | undefined, | ||
FreeSolo extends boolean | undefined, | ||
ChipComponent extends React.FunctionComponent<any> | ||
>( | ||
props: RenderAttrProps<Value> | ||
) => { | ||
return { | ||
value: props.value, | ||
onChange: (_e: any, v: Value) => { | ||
props.setValue(v) | ||
} | ||
} as unknown as AutocompleteProps<Value, Multiple, DisableClearable, FreeSolo, ChipComponent> | ||
} | ||
|
||
/** | ||
* 绑定错误信息 | ||
* @param props | ||
* @returns | ||
*/ | ||
static M_Error = (props: RenderAttrProps<any>) => { | ||
return { | ||
helperText: props.msg, | ||
error: props.isError | ||
} | ||
} | ||
|
||
/** | ||
* 绑定TextField | ||
* @param props | ||
* @returns | ||
*/ | ||
static M_TextField = (props: RenderAttrProps<string>) => { | ||
return { | ||
...this.M_Error(props), | ||
value: props.value, | ||
onChange: (e: any) => { | ||
props.setValue(e.target.value) | ||
} | ||
} as TextFieldProps | ||
} | ||
|
||
/** | ||
* 绑定 Switch | ||
* @param props | ||
* @returns | ||
*/ | ||
static M_Switch = (props: RenderAttrProps<boolean>) => { | ||
return { | ||
...this.D_Checkbox(props) | ||
} | ||
} | ||
|
||
/** | ||
* 绑定 Checkbox | ||
* @param props | ||
* @returns | ||
*/ | ||
static M_Checkbox = (props: RenderAttrProps<boolean>) => { | ||
return { | ||
...this.D_Checkbox(props) | ||
} | ||
} | ||
|
||
/** | ||
* Slider | ||
* @param props | ||
* @returns | ||
*/ | ||
static M_Slider = (props: RenderAttrProps<number>) => { | ||
return { | ||
value: props.value, | ||
onChange: (_e: unknown, v: number) => { | ||
props.setValue(v) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* RadioGroup | ||
* @param props | ||
* @returns | ||
*/ | ||
static M_RadioGroup = (props: RenderAttrProps<string>) => { | ||
return { | ||
...this.D_Input(props) | ||
} | ||
} | ||
|
||
/** | ||
* Rating | ||
* @param props | ||
* @returns | ||
*/ | ||
static M_Rating = (props: RenderAttrProps<number>) => { | ||
return { | ||
value: props.value, | ||
onChange: (_e: any, v: number) => { | ||
props.setValue(v) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Select | ||
* @param props | ||
* @returns | ||
*/ | ||
static M_Select = <T = any>(props: RenderAttrProps<T>) => { | ||
return { | ||
...this.D_Input(props) | ||
} | ||
} | ||
|
||
static FormItem = FormItem | ||
} | ||
|
||
export type { FormItemProps } |
This file contains 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
Oops, something went wrong.