first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import {useController} from 'react-hook-form';
import React, {useMemo} from 'react';
import {mergeProps} from '@react-aria/utils';
import {
ChipField,
ChipValue,
} from '../../ui/forms/input-field/chip-field/chip-field';
import {FormChipFieldProps} from '../../ui/forms/input-field/chip-field/form-chip-field';
export function JsonChipField({children, ...props}: FormChipFieldProps<any>) {
const {
field: {onChange, onBlur, value = [], ref},
fieldState: {invalid, error},
} = useController({
name: props.name,
});
const arrayValue = useMemo(() => {
const mixedValue = value as string | string[];
return typeof mixedValue === 'string' ? JSON.parse(mixedValue) : mixedValue;
}, [value]);
const formProps: Partial<FormChipFieldProps<ChipValue>> = {
onChange: newValue => {
const jsonValue = JSON.stringify(newValue.map(chip => chip.name));
onChange(jsonValue);
},
onBlur,
value: arrayValue,
invalid,
errorMessage: error?.message,
};
return <ChipField ref={ref} {...mergeProps(formProps, props)} />;
}