5180 fichiers 38.5 Mo 0 téléchargements 288 vues mis à jour il y a 6 heures ui
nitro-v36-with-renderer-v36 / src / components / inventory / views / InventoryFilterSelect.tsx
InventoryFilterSelect.tsx 1.7 Ko Télécharger le fichier
import { Children, FC, isValidElement, ReactNode } from 'react';
import { ListSelect } from '../../../common/ListSelect';
import { NativeTextTree } from '../../../common/native-text/NativeTextTree';

interface InventoryFilterSelectProps {
    value?: string | number;
    disabled?: boolean;
    'aria-label': string;
    onChange?: (value: string) => void;
    children: ReactNode;
}

export const InventoryFilterSelect: FC<InventoryFilterSelectProps> = ({ value, disabled, onChange, children, 'aria-label': label }) => {
    const options = Children.toArray(children)
        .filter(isValidElement<{ value?: string | number; children: ReactNode }>)
        .map((child) => ({
            value: String(child.props.value ?? ''),
            label: String(child.props.children ?? '').slice(0, 200)
        }));
    const selected = options.find((option) => option.value === String(value ?? '')) ?? options[0];

    return (
        <NativeTextTree>
            <span className="octane-inventory-filter-choice">
                <ListSelect
                    aria-label={label}
                    disabled={disabled || !options.length}
                    itemClassName="octane-inventory-filter-option"
                    options={options}
                    popupClassName="octane-inventory-filter-menu"
                    scaleWithTrigger
                    // The list opens over the trigger, like the AIR client's drop menu.
                    sideOffset={({ anchor }) => -anchor.height}
                    triggerClassName="octane-inventory-filter-select"
                    value={selected?.value ?? ''}
                    onValueChange={(next) => onChange?.(next)}
                />
            </span>
        </NativeTextTree>
    );
};
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser