Cards
Card component with icon, title, description and footer, plus a product card with description, brand, reviews, discount, color and size options, out of stock state, horizontal layout, favorite toggle and add to cart button.
How to use it
Run npx @blossomui/react add card, or copy src/components/UI/Card/Card.tsx into your React project and import it.
import { Card, ProductCard } from './components/ui/Card'Props
CardProps
| Prop | Type | Description |
|---|---|---|
| color | string | Accent color of this component: any CSS color. Without it the component uses `--blossom-accent`, which is pink by default. |
| title (required) | string | |
| description | ReactNode | |
| icon | ReactNode | Icon shown inside a tinted square. |
| footer | ReactNode | Extra content, for example buttons or links. |
| className | string |
ProductCardLabels
| Prop | Type | Description |
|---|---|---|
| addToCart (required) | string | |
| added (required) | string | |
| unavailable (required) | string | |
| chooseSize (required) | string | Text of the button while a size is required and none is chosen. |
| outOfStock (required) | string | |
| addToFavorites (required) | string | |
| removeFromFavorites (required) | string | |
| expandPhoto (required) | (name: string) => string | |
| stars (required) | (rating: number) => string | |
| color (required) | string | |
| size (required) | string | |
| close (required) | string | Texts of the photo viewer. |
| previousPhoto (required) | string | |
| nextPhoto (required) | string | |
| showPhoto (required) | (photo: number) => string | |
| viewer (required) | (name: string, photo: number, total: number) => string |
ProductColor
| Prop | Type | Description |
|---|---|---|
| value (required) | string | Any CSS color. |
| label | string | Name of the color, used by screen readers and passed to `onAddToCart`. |
ProductSize
| Prop | Type | Description |
|---|---|---|
| value (required) | string | What `onAddToCart` receives, for example "250 g". |
| label | string | Text of the button. Without it the value is used. |
| price | number | Price of this size. Without it the price of the product is used. |
| originalPrice | number | Price before the discount of this size. |
| inStock | boolean | Set it to false for a size that is not available. |
ProductSelection
| Prop | Type | Description |
|---|---|---|
| color | string | |
| size | string | |
| price | number | Price of the product with the chosen size. |
ProductCardProps
| Prop | Type | Description |
|---|---|---|
| labels | Partial<ProductCardLabels> | Texts of the component. Pass only the ones you want to change, for example to translate it. |
| formatPrice | (price: number) => string | Formats the prices, for example with `Intl.NumberFormat` to show another currency. Without it `currency` and two decimals are used. |
| color | string | Accent color of this component: any CSS color. Without it the component uses `--blossom-accent`, which is pink by default. |
| badgeColor | string | Color of the badge: any CSS color. Without it the badge uses the accent. |
| preselectSize | boolean | Start with the first size that is in stock chosen, so the price and `onAddToCart` already have a size. |
| requireSize | boolean | The add to cart button stays disabled until the user chooses a size. |
| buttonColor | string | Color of the add to cart button: `accent` for the brand color or any CSS color. Without it the button is black, or white in dark mode. |
| image (required) | string | |
| name (required) | string | |
| price (required) | number | |
| description | string | Short text under the name. It is cut after two lines. |
| brand | string | Small text above the name, for example the brand or the category. |
| rating | number | From 0 to 5. |
| reviews | number | Number of reviews, shown next to the stars. |
| badge | string | |
| originalPrice | number | Price before the discount. It is crossed out and the percentage is calculated. |
| expandable | boolean | Opens the photo in full size when it is pressed. |
| images | string[] | More photos of the product. They are shown after the main image when it is expanded, with arrows and thumbnails. |
| currency | string | Symbol shown before the prices. |
| colors | (string | ProductColor)[] | Available colors, a CSS color or an object with a `value` and a `label`. The user can choose one. |
| sizes | (string | ProductSize)[] | Available sizes or weights, a string or an object with its own `price`. The user can choose one and the price changes. |
| inStock | boolean | Out of stock products cannot be added to the cart. |
| layout | 'vertical' | 'horizontal' | `horizontal` puts the image at the left, useful for lists. |
| onAddToCart | (name: string, selection: ProductSelection) => void | Called with the product name and the chosen color and size when the user presses "Add to cart". |
| onFavoriteChange | (favorite: boolean) => void | Called when the user marks or unmarks the product as favorite. |
| className | string |