|
| 1 | +--- |
| 2 | +title: Card Code |
| 3 | +component: card |
| 4 | +description: A card is a contained surface that groups related information and actions about a single subject, making content easy to scan and interact with. |
| 5 | +--- |
| 6 | + |
| 7 | +import { Card, Button } from "@sistent/sistent"; |
| 8 | + |
| 9 | +The Card component wraps MUI's Card and works with Sistent's theming out of the box. Here are the most common usage patterns. |
| 10 | + |
| 11 | +<a id="Basic Card"> |
| 12 | + <h2>Basic Card</h2> |
| 13 | +</a> |
| 14 | + |
| 15 | +A basic card with some content inside. By default it uses the elevated style with a subtle shadow. |
| 16 | + |
| 17 | +<div className="showcase"> |
| 18 | + <div className="items"> |
| 19 | + <ThemeWrapper> |
| 20 | + <div style={{ display: 'flex', justifyContent: 'center', padding: '16px' }}> |
| 21 | + <Card style={{ width: 300, padding: '16px' }}> |
| 22 | + Simple card content |
| 23 | + </Card> |
| 24 | + </div> |
| 25 | + </ThemeWrapper> |
| 26 | + </div> |
| 27 | + <CodeBlock name="basic-card" collapsible code={`<SistentThemeProvider initialMode={isDark ? "dark" : "light"}> |
| 28 | + <Card style={{ width: 300, padding: "16px" }}> |
| 29 | + Simple card content |
| 30 | + </Card> |
| 31 | +</SistentThemeProvider>`} /> |
| 32 | +</div> |
| 33 | + |
| 34 | +<a id="Outlined Card"> |
| 35 | + <h2>Outlined Card</h2> |
| 36 | +</a> |
| 37 | + |
| 38 | +Use `variant="outlined"` to get a card with a border instead of a shadow. Useful when the background is already elevated or when you want a lighter visual style. |
| 39 | + |
| 40 | +<div className="showcase"> |
| 41 | + <div className="items"> |
| 42 | + <ThemeWrapper> |
| 43 | + <div style={{ display: 'flex', justifyContent: 'center', padding: '16px' }}> |
| 44 | + <Card variant="outlined" style={{ width: 300, padding: '16px' }}> |
| 45 | + Outlined card content |
| 46 | + </Card> |
| 47 | + </div> |
| 48 | + </ThemeWrapper> |
| 49 | + </div> |
| 50 | + <CodeBlock name="outlined-card" collapsible code={`<SistentThemeProvider initialMode={isDark ? "dark" : "light"}> |
| 51 | + <Card variant="outlined" style={{ width: 300, padding: "16px" }}> |
| 52 | + Outlined card content |
| 53 | + </Card> |
| 54 | +</SistentThemeProvider>`} /> |
| 55 | +</div> |
| 56 | + |
| 57 | +<a id="Elevation"> |
| 58 | + <h2>Elevation</h2> |
| 59 | +</a> |
| 60 | + |
| 61 | +The `elevation` prop controls shadow depth. Values go from 0 (flat) to 24 (maximum depth). Most cards in practice sit between 1 and 8. |
| 62 | + |
| 63 | +<div className="showcase"> |
| 64 | + <div className="items"> |
| 65 | + <ThemeWrapper> |
| 66 | + <div style={{ display: 'flex', flexDirection: 'column', gap: '12px', padding: '16px' }}> |
| 67 | + <Card elevation={1} style={{ padding: '16px' }}>Elevation 1</Card> |
| 68 | + <Card elevation={4} style={{ padding: '16px' }}>Elevation 4</Card> |
| 69 | + <Card elevation={8} style={{ padding: '16px' }}>Elevation 8</Card> |
| 70 | + </div> |
| 71 | + </ThemeWrapper> |
| 72 | + </div> |
| 73 | + <CodeBlock name="card-elevation" collapsible code={`<SistentThemeProvider initialMode={isDark ? "dark" : "light"}> |
| 74 | + <Card elevation={1} style={{ padding: "16px" }}>Elevation 1</Card> |
| 75 | + <Card elevation={4} style={{ padding: "16px" }}>Elevation 4</Card> |
| 76 | + <Card elevation={8} style={{ padding: "16px" }}>Elevation 8</Card> |
| 77 | +</SistentThemeProvider>`} /> |
| 78 | +</div> |
| 79 | + |
| 80 | +<a id="Square Corners"> |
| 81 | + <h2>Square Corners</h2> |
| 82 | +</a> |
| 83 | + |
| 84 | +Cards have rounded corners by default. Set `square` to `true` to remove the rounding for a more geometric look. |
| 85 | + |
| 86 | +<div className="showcase"> |
| 87 | + <div className="items"> |
| 88 | + <ThemeWrapper> |
| 89 | + <div style={{ display: 'flex', gap: '16px', justifyContent: 'center', padding: '16px' }}> |
| 90 | + <Card style={{ width: 200, padding: '16px' }}>Rounded</Card> |
| 91 | + <Card square style={{ width: 200, padding: '16px' }}>Square</Card> |
| 92 | + </div> |
| 93 | + </ThemeWrapper> |
| 94 | + </div> |
| 95 | + <CodeBlock name="card-corners" collapsible code={`<SistentThemeProvider initialMode={isDark ? "dark" : "light"}> |
| 96 | + <Card style={{ width: 200, padding: "16px" }}>Rounded</Card> |
| 97 | + <Card square style={{ width: 200, padding: "16px" }}>Square</Card> |
| 98 | +</SistentThemeProvider>`} /> |
| 99 | +</div> |
| 100 | + |
| 101 | +<a id="Clickable Card"> |
| 102 | + <h2>Clickable Card</h2> |
| 103 | +</a> |
| 104 | + |
| 105 | +To make the entire card interactive, add an `onClick` handler and update the cursor style. This pattern is common in grid layouts where each card is a navigation target. |
| 106 | + |
| 107 | +<div className="showcase"> |
| 108 | + <div className="items"> |
| 109 | + <ThemeWrapper> |
| 110 | + <div style={{ display: 'flex', justifyContent: 'center', padding: '16px' }}> |
| 111 | + <Card |
| 112 | + style={{ width: 300, padding: '16px', cursor: 'pointer' }} |
| 113 | + onClick={() => alert('Card clicked')} |
| 114 | + > |
| 115 | + Click anywhere on this card |
| 116 | + </Card> |
| 117 | + </div> |
| 118 | + </ThemeWrapper> |
| 119 | + </div> |
| 120 | + <CodeBlock name="clickable-card" collapsible code={`<SistentThemeProvider initialMode={isDark ? "dark" : "light"}> |
| 121 | + <Card |
| 122 | + style={{ width: 300, padding: "16px", cursor: "pointer" }} |
| 123 | + onClick={() => console.log("Card clicked")} |
| 124 | + > |
| 125 | + Click anywhere on this card |
| 126 | + </Card> |
| 127 | +</SistentThemeProvider>`} /> |
| 128 | +</div> |
| 129 | + |
| 130 | +<a id="Card with Header and Actions"> |
| 131 | + <h2>Card with Header and Actions</h2> |
| 132 | +</a> |
| 133 | + |
| 134 | +A common real-world pattern — a card with a title, a short description, and action buttons at the bottom. |
| 135 | + |
| 136 | +<div className="showcase"> |
| 137 | + <div className="items"> |
| 138 | + <ThemeWrapper> |
| 139 | + <div style={{ display: 'flex', justifyContent: 'center', padding: '16px' }}> |
| 140 | + <Card style={{ width: 300 }}> |
| 141 | + <div style={{ padding: '16px' }}> |
| 142 | + <h3 style={{ margin: '0 0 8px' }}>Card Title</h3> |
| 143 | + <p style={{ margin: 0, color: 'gray' }}>A short description about what this card represents and why it matters.</p> |
| 144 | + </div> |
| 145 | + <div style={{ padding: '8px 16px 16px', display: 'flex', gap: '8px' }}> |
| 146 | + <Button variant="contained" size="small">Action</Button> |
| 147 | + <Button variant="outlined" size="small">Cancel</Button> |
| 148 | + </div> |
| 149 | + </Card> |
| 150 | + </div> |
| 151 | + </ThemeWrapper> |
| 152 | + </div> |
| 153 | + <CodeBlock name="card-with-actions" collapsible code={`<SistentThemeProvider initialMode={isDark ? "dark" : "light"}> |
| 154 | + <Card style={{ width: 300 }}> |
| 155 | + <div style={{ padding: "16px" }}> |
| 156 | + <h3 style={{ margin: "0 0 8px" }}>Card Title</h3> |
| 157 | + <p style={{ margin: 0, color: "gray" }}> |
| 158 | + A short description about what this card represents. |
| 159 | + </p> |
| 160 | + </div> |
| 161 | + <div style={{ padding: "8px 16px 16px", display: "flex", gap: "8px" }}> |
| 162 | + <Button variant="contained" size="small">Action</Button> |
| 163 | + <Button variant="outlined" size="small">Cancel</Button> |
| 164 | + </div> |
| 165 | + </Card> |
| 166 | +</SistentThemeProvider>`} /> |
| 167 | +</div> |
0 commit comments