// 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 { const { className = '', defaultValue, isDisabled, label, onChange, overrides, registry, type, withLabel } = props; const params = useParamDefs(registry, type); const [values] = useState(() => getInitialValues(defaultValue)); const _onChangeParams = useCallback( (values: RawParam[]): void => { if (isDisabled) { return; } onChange && onChange({ isValid: values.reduce((result, { isValid }) => result && isValid, true), value: values.map(({ value }) => value) }); }, [isDisabled, onChange] ); return (
); } export default React.memo(TupleDisplay);