|
| 1 | +import { Meta, Story, Controls } from '@storybook/addon-docs/blocks'; |
| 2 | +import * as ItemCardStories from './ItemCard.stories'; |
| 3 | + |
| 4 | +<Meta of={ItemCardStories} /> |
| 5 | + |
| 6 | +# ItemCard |
| 7 | + |
| 8 | +A convenience wrapper around `Item type="card"` that provides a more natural card API by mapping `title` to the card heading and `children` to the card body. |
| 9 | + |
| 10 | +## When to Use |
| 11 | + |
| 12 | +- When displaying notification-style messages (success, error, warning, info) |
| 13 | +- For status banners or alert cards |
| 14 | +- When you need a card with a heading and body content |
| 15 | + |
| 16 | +## Component |
| 17 | + |
| 18 | +<Story of={ItemCardStories.Default} /> |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +### Properties |
| 23 | + |
| 24 | +<Controls of={ItemCardStories.Default} /> |
| 25 | + |
| 26 | +### Base Properties |
| 27 | + |
| 28 | +Supports [Base properties](https://github.com/tenphi/tasty/blob/main/docs/tasty.md) |
| 29 | + |
| 30 | +### Styling Properties |
| 31 | + |
| 32 | +#### styles |
| 33 | + |
| 34 | +Inherits all styling from `Item`. See [Item documentation](/docs/content-item--docs) for sub-elements and modifiers. |
| 35 | + |
| 36 | +## Variants |
| 37 | + |
| 38 | +### Sizes |
| 39 | + |
| 40 | +<Story of={ItemCardStories.Sizes} /> |
| 41 | + |
| 42 | +- `medium` — Default size suitable for most use cases |
| 43 | +- `large` — Larger size for prominent notifications |
| 44 | +- `xlarge` — Extra large size for emphasized alerts |
| 45 | + |
| 46 | +### Themes |
| 47 | + |
| 48 | +Use the `theme` prop to apply a semantic color scheme: |
| 49 | + |
| 50 | +- `default` — Standard card appearance |
| 51 | +- `success` — Green theme for positive outcomes |
| 52 | +- `danger` — Red theme for errors or destructive states |
| 53 | +- `warning` — Amber theme for caution |
| 54 | +- `note` — Violet theme for informational context |
| 55 | + |
| 56 | +## Examples |
| 57 | + |
| 58 | +### Basic Usage |
| 59 | + |
| 60 | +```jsx |
| 61 | +<ItemCard title="Info" icon={<IconInfoCircle />}> |
| 62 | + This is the card body content. |
| 63 | +</ItemCard> |
| 64 | +``` |
| 65 | + |
| 66 | +### Themed Cards |
| 67 | + |
| 68 | +```jsx |
| 69 | +<ItemCard title="Success" icon={<IconCheck />} theme="success"> |
| 70 | + Operation completed successfully. |
| 71 | +</ItemCard> |
| 72 | + |
| 73 | +<ItemCard title="Error" icon={<IconAlertTriangle />} theme="danger"> |
| 74 | + Something went wrong. |
| 75 | +</ItemCard> |
| 76 | +``` |
| 77 | + |
| 78 | +### With Actions |
| 79 | + |
| 80 | +Use `ItemCard.Action` to add inline action buttons such as dismiss or close. |
| 81 | + |
| 82 | +```jsx |
| 83 | +<ItemCard |
| 84 | + title="Deployment Complete" |
| 85 | + icon={<IconCheck />} |
| 86 | + theme="success" |
| 87 | + actions={<ItemCard.Action icon={<IconX />} aria-label="Dismiss" />} |
| 88 | +> |
| 89 | + Your changes are now live in production. |
| 90 | +</ItemCard> |
| 91 | +``` |
| 92 | + |
| 93 | +### Custom Heading Level |
| 94 | + |
| 95 | +The `level` prop controls the semantic HTML heading tag (h1-h6) for the title. Default is `level={3}` (h3). |
| 96 | + |
| 97 | +```jsx |
| 98 | +<ItemCard title="Important Section" icon={<IconInfoCircle />} level={2}> |
| 99 | + This card's title renders as an h2 element. |
| 100 | +</ItemCard> |
| 101 | +``` |
| 102 | +
|
| 103 | +## Accessibility |
| 104 | +
|
| 105 | +### Keyboard Navigation |
| 106 | +
|
| 107 | +- `Tab` - Moves focus to the component when focusable |
| 108 | +- `Space/Enter` - Activates the component when used as a button |
| 109 | +
|
| 110 | +### Screen Reader Support |
| 111 | +
|
| 112 | +- Title renders as a semantic heading (h1-h6) via the `level` prop for proper document structure |
| 113 | +- Inherits all accessibility features from `Item` |
| 114 | +
|
| 115 | +### ARIA Properties |
| 116 | +
|
| 117 | +- `aria-label` - Provides accessible label when no visible label exists |
| 118 | +
|
| 119 | +## Best Practices |
| 120 | +
|
| 121 | +1. **Do**: Use meaningful titles and body content |
| 122 | + ```jsx |
| 123 | + <ItemCard title="Deployment Complete" icon={<IconCheck />} theme="success"> |
| 124 | + Your changes are now live in production. |
| 125 | + </ItemCard> |
| 126 | + ``` |
| 127 | +
|
| 128 | +2. **Don't**: Use without a title |
| 129 | + ```jsx |
| 130 | + {/* Prefer using Item type="card" directly if you only need a description */} |
| 131 | + <ItemCard>Body only without a title</ItemCard> |
| 132 | + ``` |
| 133 | + |
| 134 | +## Related Components |
| 135 | + |
| 136 | +- [Item](/docs/content-item--docs) - The underlying component with full control over `type`, `children`, and `description` |
0 commit comments