Food card
A food category: a round cutout with a soft plate shadow and a centred label, plain or on an outline, filled or elevated surface.
npx @swipeui/cli add food-cardWhen to use it
- A horizontal row of food categories at the top of a delivery or restaurant screen, such as Burgers, Pizzas and Rolls.
- A category picker where one dish type is selected at a time, the choice shown in the primary colour.
- A grid of dishes on a menu, with a price or count as the subtitle.
- Any small round cutout with a label, such as drinks, desserts or ingredients.
When not to use it
- A featured product with a large tilted cutout. Product spotlight card is designed for that.
- Restaurant listings with photos, price and rating. Listing card fits better.
- Photos with a background; the plate shadow only reads on clear cutouts.
- Text-only filters. Chip or Segmented control is lighter.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add food-card- Adds
components/swipeui/card/food-card.tsx,components/swipeui/card/food-card-palette.tsand 7 shared helpers. - Installs class-variance-authority, expo-image, react-native-reanimated, react-native-svg, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { useState } from 'react';
import { ScrollView } from 'react-native';
import { FoodCard } from '@/components/swipeui/card/food-card';
const categories = [
{ id: 'burgers', label: 'Burgers', image: require('./assets/burger.webp') },
{ id: 'pizzas', label: 'Pizzas', image: require('./assets/pizza.webp') },
{ id: 'rolls', label: 'Rolls', image: require('./assets/rolls.webp') },
];
const [selected, setSelected] = useState('burgers');
<ScrollView horizontal contentContainerClassName="gap-4 px-4">
{categories.map((category) => (
<FoodCard
key={category.id}
image={category.image}
label={category.label}
selected={selected === category.id}
onSelectedChange={() => setSelected(category.id)}
/>
))}
</ScrollView>;Examples
import { View } from 'react-native';
import { FoodCard } from '@/components/swipeui/card/food-card';
// Menu tiles on a surface, with a price as the subtitle.
<View className="flex-row gap-3">
{dishes.map((dish) => (
<FoodCard
key={dish.id}
image={{ uri: dish.cutoutUrl }}
label={dish.name}
subtitle={dish.price}
variant="elevated"
onPress={() => openDish(dish.id)}
className="flex-1"
/>
))}
</View>;import { FoodCard } from '@/components/swipeui/card/food-card';
// A dense row: small size, no plate shadow.
<FoodCard image={latte} label="Latte" size="small" shadow={false} onPress={addLatte} />;Glass appearance
Select Glass in the Preset picker. Outline, Filled and Elevated use Glass on the card; Plain keeps its bare plate.
API reference
FoodCardProps
| Prop | Type | Default | Description |
|---|---|---|---|
image | | — | The dish: a bundled image, |
label | | — | The category or dish name, centred under the image. |
subtitle? | | — | A second line, such as "120 places" or a price. |
variant? | | |
|
surfaceBackground? | | | Optional material inside the outline, filled or elevated surface. |
size? | | |
|
shadow? | | | The soft ellipse under the plate. |
palette? | | | The shadow's colour and depth. |
selected? | | — | Whether the card is selected, as in a category picker. Pair with |
defaultSelected? | | | Whether it starts selected when uncontrolled. |
onSelectedChange? | | — | Called with the new selected state when the card is pressed. |
selectable? | | | Pressing toggles the selected state. |
selectionRing? | | | Outline the selected card with a token-tinted ring (around the plate when plain, around the surface otherwise). Without it the selected label turns the primary colour. |
onPress? | | — | Runs on press, after any selection change. |
disabled? | | | Prevents pressing and dims the card. |
haptics? | | | A light haptic tap when pressed. |
motion? | | | Motion for the press and the selection ring. |
accessibilityLabel? | | | What a screen reader announces. |
accessibilityHint? | | — | Says what pressing does, such as "Shows burger places". |
className? | | — | Classes merged over the card. |
style? | | — | Native style escape hatch for the card. |
testID? | | — | Root identifier; parts add |
Composition and behavior
- The image is a cutout fitted into a plate box that's wider than tall, like a plate seen at an angle, with a soft elliptical shadow just under it. The label and optional subtitle are centred below.
- variant="plain" (the default) has no surface, as in a row of categories. outline, filled and elevated add a
rounded-cardsurface for menu grids. - With selected and onSelectedChange the card is a selectable chip: pressing toggles it and the selected label turns the primary colour. selectionRing adds a token-tinted outline that fades in, around the plate when plain and around the surface otherwise. Control it from one piece of state for a single choice.
- The card is read as one element ("Burgers, 120 places") and reports its selected state.
- The shadow's colour lives in
food-card-palette.ts; the surface and text use theme tokens, so presets and dark mode apply.
Food card settings
| Prop | Does | Default |
|---|---|---|
| surfaceBackground | Optional decorative material behind non-plain cards | None |
| variant | plain, outline, filled or elevated | plain |
| size | small or medium | medium |
| shadow | The soft plate shadow | true |
| palette | The shadow's colour and depth | FOOD_CARD_PALETTE |
| selected / defaultSelected | Whether it's selected | uncontrolled, false |
| onSelectedChange | Called with the new selected state | none |
| selectable | Pressing toggles selection | true with any selection prop |
| selectionRing | Outlines the selected card with a token-tinted ring | false |
| onPress | Runs on press, after any selection change | none |
| haptics | A light tap when pressed | true |
Behavior and gestures
- With onPress or any selection prop the card is one button that presses in slightly with a light haptic.
- selected with onSelectedChange (or defaultSelected) makes it a selectable chip: pressing toggles it and the selected label turns the primary colour. selectionRing adds a token-tinted outline that fades in on the select role (around the plate when plain, around the surface otherwise). selectable={false} keeps it a plain button.
- variant is plain (no surface, as in a category row), outline, filled or elevated; size is small or medium.
- shadow={false} removes the soft plate shadow; palette changes its colour and depth.
- Without onPress or selection it's a static element. disabled dims the card and ignores presses; haptics={false} turns off the tap.
Accessibility
- The card is read as one element: the label and subtitle, such as "Burgers, 120 places".
- Selectable cards report their selected state, so a row works as a category picker for screen readers.
- The image and shadow are decorative; pass accessibilityLabel if the label alone isn't enough.
- Cards are at least 44pt; labels truncate to one line, so keep them short.
- Under Reduce Motion the selection ring (when on) appears at once and the card doesn't scale.
Motion
- Uses the
pressandselectmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Pressing scales the card on the press role.
- With selectionRing, the ring fades in and out on the select role; under Reduce Motion it changes at once.
Performance
- One image and one small vector shadow; safe in long horizontal lists. Size cutouts close to 2–3× the image box.
Notes for AI
- Use cutouts with a clear background (PNG or WebP with alpha); the plate shadow is drawn under the image.
- For a category picker, control selected from one piece of state so only one card is selected. Leave selectionRing off for the clean look; turn it on when the choice must stand out more.
- Keep labels to one or two short words such as Burgers or Rolls; put counts or prices in subtitle.
- Use variant="plain" for a category row and a surface variant for menu grids.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.