GroupItems
Drag items from a common pool into labeled groups
GroupItems presents a mixed pool of items and empty labeled zones. Users drag items from the common area into the correct groups. It uses @dnd-kit/react for drag and drop.
Import
import { GroupItems } from '@bside-tech/tbx-ui/components';Example
<GroupItems
entries={{
animals: ['Cat', 'Dog'],
plants: ['Oak', 'Rose', 'Tulip'],
}}
/>Props
Prop
Type
Style
Tailwind v4 is available for customisations. Pass classes via the classNames prop, or override CSS variables for fine-grained control.
CSS Classes
| Key | Element |
|---|---|
root | Root wrapper |
commonArea | Common pool of items |
groupsRow | Row of group zones |
groupZone | Drop zone for a group |
groupLabel | Zone heading |
groupContent | Zone content area |
item | Draggable item |
checkButton | Check button |
resetButton | Reset button |
result | Results text |
CSS Variables
Scoped under .tbx-groupitems:
| Variable | Purpose |
|---|---|
--groupitems-zone-bg | Zone background |
--groupitems-zone-border | Zone border |
--groupitems-zone-drop | Zone background when drag-over |
--groupitems-item-bg | Item background (default) |
--groupitems-item-border | Item border |
--groupitems-item-in-target-bg | Item background when in a target zone (before validation). Uses color-mix with --exercise-accent-color. |
--groupitems-item-in-target-border | Item border when in a target zone (before validation). Uses --exercise-accent-color. |
--groupitems-item-dragging | Item background when dragging |
--groupitems-action-bg, --groupitems-action-border | Check/Reset button background and border |
--groupitems-result-neutral, --groupitems-result-correct, --groupitems-result-wrong | Results text colors (neutral, correct, wrong) |
--groupitems-correct-bg, --groupitems-correct-border | Correct item highlight |
--groupitems-wrong-bg, --groupitems-wrong-border | Wrong item highlight |
These feed into --exercise-action-bg, --exercise-action-border and --exercise-result-* used by ExerciseLayout.
Item labels use --exercise-layout-content-font-size.
Labels
Override labels via the labels prop. Fixed keys: items (common pool area, default "Items"), check, reset (buttons), results (e.g. "correct" in "3 / 5 correct"). Use group ids (keys from entries) to override zone headings—since groups are defined dynamically, any entry key can be used as a label key.
<GroupItems
entries={{ animals: ['Cat', 'Dog'], plants: ['Oak'] }}
labels={{
items: 'Drag here',
animals: 'Mammals',
plants: 'Flora',
check: 'Verify',
reset: 'Reset',
results: 'correct',
}}
/>Hook
Use useGroupItemsExercise for custom group interfaces. Pass items and groups derived from your entries:
import { useGroupItemsExercise } from '@bside-tech/tbx-ui/hooks';
const entries = { animals: ['Cat', 'Dog'], plants: ['Oak'] };
const items = Object.entries(entries).flatMap(([group, labels]) =>
labels.map((label) => ({ label, group }))
);
const groups = Object.keys(entries).map(id => ({ id, label: id }));
const { itemsByGroup, moveItem, solution, isCorrect, check, reset } = useGroupItemsExercise({
items,
groups,
checkOn: 'manual',
});| Return | Description |
|---|---|
itemsByGroup | Record of zone id → item ids in that zone |
moveItem | Move item from one group to another |
setItemsByGroup | Set full state (e.g. for shuffle/reset) |
solution | Correct group id for each item id |
isCorrect | Validation result |
check | Validate placements |
reset | Reset to initial state (all items in common) |