import { useState, useRef } from 'react'; import { RtFrame } from '@dpa/react-frame-intro'; import { RtItem, RtList, RtListItem, RtListVirtual } from '@dpa/react-item'; import { RtText } from '@dpa/react-text'; import { RtChips } from '@dpa/react-chips'; import { RtToggle } from '@dpa/react-toggle'; import { RtCheckbox } from '@dpa/react-checkbox'; import { RtRadio } from '@dpa/react-radio'; const ITEMS: RtListItem[] = Array.from({ length: 50, }).map((_, index) => { if ((index + 1) % 5 === 0) { return { id: `item-${index + 1}`, slot: (
console.log('text slot click')} />
), use: 'neutral', label: '', }; } return { id: `${index + 1}`, label: `Item ${index + 1}`, subLabel: `Item ${index + 1}`, use: 'neutral', }; }); const values = ['car', 'phone', 'clothes', 'food', 'other']; export const ListPage = () => { const [val, setVal] = useState(['phone']); const [radioValue, setRadioValue] = useState('phone'); const [isReadOnly, setIsReadOnly] = useState(false); const [items, setItems] = useState([ { id: '1', use: 'neutral', label: '🍎 Apple', subLabel: '🍎 Apple' }, { id: '2', use: 'neutral', label: '🍌 Banana', subLabel: '🍌 Banana' }, { id: '3', use: 'neutral', label: '🍇 Grape', subLabel: '🍇 Grape' }, ]); const virtualContainerRef = useRef(null); return (
Rt List DnD
Edit mode setIsReadOnly(!isReadOnly)} name="Mode" />
item.id} onReorder={setItems} renderItem={(item) => { return ( console.log('action click', item.id)} actionVariant="clear" actionState="dragging" readOnly={isReadOnly} onClear={() => { setItems((items) => items.filter((fruit) => fruit.id !== item.id) ); }} /> ); }} />
Rt List virtual
item.id} renderItem={(item: RtListItem) => { if ('slot' in item) { return item.slot; } return ( console.log('action click', item.id)} actionVariant="clear" actionState="dragging" /> ); }} containerRef={virtualContainerRef} />
RtList Checkbox ({ id: i, label: i } as RtListItem))} renderItem={(item) => { return ( console.log('action click', item.id)} leadingSlot={ setVal((oldV) => { if (oldV.includes(item.id)) return oldV.filter((i) => i !== item.id); return [...oldV, item.id]; }) } /> } /> ); }} /> RtList Toggle ({ id: i, label: i } as RtListItem))} renderItem={(item) => { return ( console.log('action click', item.id)} leadingSlot={ setVal((oldV) => { if (oldV.includes(item.id)) return oldV.filter((i) => i !== item.id); return [...oldV, item.id]; }) } /> } /> ); }} /> RtList Radio ({ id: i, label: i } as RtListItem))} renderItem={(item) => { return ( console.log('action click', item.id)} leadingSlot={ setRadioValue(item.id)} /> } /> ); }} />
); };