mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:35:20 +00:00
feat(client): add constant props api for variable input (#5116)
This commit is contained in:
parent
c167435583
commit
580286db96
@ -118,10 +118,19 @@ const ConstantTypes = {
|
||||
},
|
||||
};
|
||||
|
||||
function getTypedConstantOption(type: string, types: true | string[], fieldNames) {
|
||||
type UseTypeConstantType = true | (string | [string, Record<string, any>])[];
|
||||
|
||||
function getTypedConstantOption(type: string, types: UseTypeConstantType, fieldNames) {
|
||||
const allTypes = Object.values(ConstantTypes).filter((item) => item.value !== 'null');
|
||||
const children = (
|
||||
types ? allTypes.filter((item) => (Array.isArray(types) && types.includes(item.value)) || types === true) : allTypes
|
||||
types
|
||||
? allTypes.filter(
|
||||
(item) =>
|
||||
(Array.isArray(types) &&
|
||||
types.filter((t) => (Array.isArray(t) ? t[0] === item.value : t === item.value)).length) ||
|
||||
types === true,
|
||||
)
|
||||
: allTypes
|
||||
).map((item) =>
|
||||
Object.keys(item).reduce(
|
||||
(result, key) =>
|
||||
@ -150,7 +159,7 @@ export type VariableInputProps = {
|
||||
onChange: (value: string, optionPath?: any[]) => void;
|
||||
children?: any;
|
||||
button?: React.ReactElement;
|
||||
useTypedConstant?: true | string[];
|
||||
useTypedConstant?: UseTypeConstantType;
|
||||
changeOnSelect?: CascaderProps['changeOnSelect'];
|
||||
fieldNames?: CascaderProps['fieldNames'];
|
||||
disabled?: boolean;
|
||||
@ -214,6 +223,9 @@ export function Input(props: VariableInputProps) {
|
||||
}, [type, useTypedConstant]);
|
||||
|
||||
const ConstantComponent = constantOption && !children ? constantOption.component : NullComponent;
|
||||
const constantComponentProps = Array.isArray(useTypedConstant)
|
||||
? (useTypedConstant.find((item) => Array.isArray(item) && item[0] === type)?.[1] as Record<string, any>) ?? {}
|
||||
: {};
|
||||
let cValue;
|
||||
if (value == null) {
|
||||
if (children && isFieldValue) {
|
||||
@ -403,7 +415,13 @@ export function Input(props: VariableInputProps) {
|
||||
{children && isFieldValue ? (
|
||||
children
|
||||
) : ConstantComponent ? (
|
||||
<ConstantComponent role="button" aria-label="variable-constant" value={value} onChange={onChange} />
|
||||
<ConstantComponent
|
||||
role="button"
|
||||
aria-label="variable-constant"
|
||||
{...constantComponentProps}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
|
Loading…
Reference in New Issue
Block a user