[feature] Allow users to set default interaction policies per status visibility (#3108)

* [feature] Allow users to set default interaction policies

* use vars for default policies

* avoid some code repetition

* unfuck form binding

* avoid bonkers loop

* beep boop

* put policyValsToAPIPolicyVals in separate function

* don't bother with slices.Grow

* oops
This commit is contained in:
tobi
2024-07-17 16:46:52 +02:00
committed by GitHub
parent 401098191b
commit 0aadc2db2a
36 changed files with 3178 additions and 316 deletions

View File

@ -141,9 +141,28 @@ export interface SelectProps extends React.DetailedHTMLProps<
field: TextFormInputHook;
children?: ReactNode;
options: React.JSX.Element;
/**
* Optional callback function that is
* triggered along with the select's onChange.
*
* _selectValue is the current value of
* the select after onChange is triggered.
*
* @param _selectValue
* @returns
*/
onChangeCallback?: (_selectValue: string | undefined) => void;
}
export function Select({ label, field, children, options, ...props }: SelectProps) {
export function Select({
label,
field,
children,
options,
onChangeCallback,
...props
}: SelectProps) {
const { onChange, value, ref } = field;
return (
@ -152,7 +171,12 @@ export function Select({ label, field, children, options, ...props }: SelectProp
{label}
{children}
<select
onChange={onChange}
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
onChange(e);
if (onChangeCallback !== undefined) {
onChangeCallback(e.target.value);
}
}}
value={value}
ref={ref as RefObject<HTMLSelectElement>}
{...props}