Files
pezkuwi-apps/packages/react-params/src/Param/Tuple.tsx
T
Satoshi Qazi Muhammed 45d479d2ec Move to @pezkuwi/dev 0.86.4 (eslint 10 toolchain)
- dev ^0.86.4 at the root and in packages/apps; directives renamed by
  pezkuwi-dev-migrate-eslint10.
- eslint --fix with the 0.86.4 config; one fix broke syntax
  (typescript-eslint prefer-optional-chain turned
  `(isStarted && onStart) && onStart()` into `(isStarted && onStart?.();`
  in TxButton) and is corrected by hand.
- The remaining findings fixed rather than disabled: optional chains
  (each suggestion reviewed), `cause` on rethrown errors, `if` instead of
  `a && promise` in effects, parallel instead of sequential awaits in
  Promise.all, Error rejections, no `delete` on arrays (the storage query
  cache is a Map; an upload's file list no longer keeps a hole), no
  `[object Object]` stringification (TFunction's second argument is text
  or options), dead code removed (referenda's never-shown expand button,
  react-query's unused CoreDescriptor).
2026-10-10 02:06:12 +04:00

59 lines
1.6 KiB
TypeScript

// Copyright 2017-2026 @pezkuwi/react-params authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Props, RawParam } from '../types.js';
import React, { useCallback, useState } from 'react';
import { Tuple } from '@pezkuwi/types';
import Params from '../index.js';
import Base from './Base.js';
import useParamDefs from './useParamDefs.js';
function getInitialValues ({ value }: RawParam): RawParam[] {
return value instanceof Tuple
? value.map((value: unknown) => ({ isValid: true, value }))
: value as RawParam[];
}
function TupleDisplay (props: Props): React.ReactElement<Props> {
const { className = '', defaultValue, isDisabled, label, onChange, overrides, registry, type, withLabel } = props;
const params = useParamDefs(registry, type);
const [values] = useState<RawParam[]>(() => getInitialValues(defaultValue));
const _onChangeParams = useCallback(
(values: RawParam[]): void => {
if (isDisabled) {
return;
}
onChange?.({
isValid: values.reduce<boolean>((result, { isValid }) => result && isValid, true),
value: values.map(({ value }) => value)
});
},
[isDisabled, onChange]
);
return (
<div className='ui--Params-Tuple'>
<Base
className={className}
label={label}
withLabel={withLabel}
/>
<Params
isDisabled={isDisabled}
onChange={_onChangeParams}
overrides={overrides}
params={params}
registry={registry}
values={values}
/>
</div>
);
}
export default React.memo(TupleDisplay);