shoelace/docs/components/card.md

303 wiersze
6.0 KiB
Markdown
Czysty Zwykły widok Historia

2020-07-22 20:02:49 +00:00
# Card
[component-header:sl-card]
```html preview
<sl-card class="card-overview">
2022-03-02 15:10:41 +00:00
<img
slot="image"
src="https://images.unsplash.com/photo-1559209172-0ff8f6d49ff7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=80"
2020-07-22 20:02:49 +00:00
alt="A kitten sits patiently between a terracotta pot and decorative grasses."
2022-03-02 15:10:41 +00:00
/>
2020-07-22 20:02:49 +00:00
2022-03-02 15:10:41 +00:00
<strong>Mittens</strong><br />
This kitten is as cute as he is playful. Bring him home today!<br />
2020-07-22 20:02:49 +00:00
<small>6 weeks old</small>
<div slot="footer">
2021-12-13 22:38:40 +00:00
<sl-button variant="primary" pill>More Info</sl-button>
2020-07-22 20:02:49 +00:00
<sl-rating></sl-rating>
</div>
</sl-card>
<style>
.card-overview {
max-width: 300px;
}
.card-overview small {
color: var(--sl-color-neutral-500);
2020-07-22 20:02:49 +00:00
}
2022-03-02 15:10:41 +00:00
.card-overview [slot='footer'] {
display: flex;
justify-content: space-between;
2020-07-22 20:02:49 +00:00
align-items: center;
}
</style>
```
2021-11-04 22:12:47 +00:00
```jsx react
2022-03-02 15:10:41 +00:00
import { SlButton, SlCard, SlRating } from '@shoelace-style/shoelace/dist/react';
2021-11-04 22:12:47 +00:00
const css = `
.card-overview {
max-width: 300px;
}
.card-overview small {
color: var(--sl-color-neutral-500);
2021-11-04 22:12:47 +00:00
}
.card-overview [slot="footer"] {
display: flex;
justify-content: space-between;
align-items: center;
}
`;
const App = () => (
<>
2021-11-05 14:06:06 +00:00
<SlCard className="card-overview">
2022-03-02 15:10:41 +00:00
<img
slot="image"
src="https://images.unsplash.com/photo-1559209172-0ff8f6d49ff7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=80"
2021-11-04 22:12:47 +00:00
alt="A kitten sits patiently between a terracotta pot and decorative grasses."
/>
2022-03-02 15:10:41 +00:00
<strong>Mittens</strong>
<br />
This kitten is as cute as he is playful. Bring him home today!
<br />
2021-11-04 22:12:47 +00:00
<small>6 weeks old</small>
<div slot="footer">
2022-03-02 15:10:41 +00:00
<SlButton variant="primary" pill>
More Info
</SlButton>
2021-11-04 22:12:47 +00:00
<SlRating></SlRating>
</div>
</SlCard>
<style>{css}</style>
</>
);
```
2020-07-22 20:02:49 +00:00
## Examples
## Basic Card
Basic cards aren't very exciting, but they can display any content you want them to.
```html preview
<sl-card class="card-basic">
This is just a basic card. No image, no header, and no footer. Just your content.
</sl-card>
<style>
.card-basic {
max-width: 300px;
}
</style>
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlCard } from '@shoelace-style/shoelace/dist/react';
const css = `
.card-basic {
max-width: 300px;
}
`;
const App = () => (
<>
2021-11-05 14:06:06 +00:00
<SlCard className="card-basic">
2021-11-04 22:12:47 +00:00
This is just a basic card. No image, no header, and no footer. Just your content.
</SlCard>
<style>{css}</style>
</>
);
```
2020-07-22 20:02:49 +00:00
## Card with Header
2020-07-24 20:57:54 +00:00
Headers can be used to display titles and more.
2020-07-22 20:02:49 +00:00
```html preview
<sl-card class="card-header">
<div slot="header">
Header Title
<sl-icon-button name="gear" label="Settings"></sl-icon-button>
2020-07-22 20:02:49 +00:00
</div>
This card has a header. You can put all sorts of things in it!
</sl-card>
<style>
2021-11-04 22:12:47 +00:00
.card-header {
max-width: 300px;
}
2022-03-02 15:10:41 +00:00
.card-header [slot='header'] {
display: flex;
align-items: center;
2021-11-04 22:12:47 +00:00
justify-content: space-between;
}
.card-header h3 {
margin: 0;
}
.card-header sl-icon-button {
font-size: var(--sl-font-size-medium);
}
2020-07-22 20:02:49 +00:00
</style>
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlCard, SlIconButton } from '@shoelace-style/shoelace/dist/react';
const css = `
.card-header {
max-width: 300px;
}
.card-header [slot="header"] {
display: flex;
align-items: center;
justify-content: space-between;
}
.card-header h3 {
margin: 0;
}
.card-header sl-icon-button {
font-size: var(--sl-font-size-medium);
}
`;
const App = () => (
<>
2021-11-05 14:06:06 +00:00
<SlCard className="card-header">
2021-11-04 22:12:47 +00:00
<div slot="header">
Header Title
<SlIconButton name="gear"></SlIconButton>
</div>
This card has a header. You can put all sorts of things in it!
</SlCard>
<style>{css}</style>
</>
);
```
2020-07-22 20:02:49 +00:00
## Card with Footer
Footers can be used to display actions, summaries, or other relevant content.
```html preview
<sl-card class="card-footer">
This card has a footer. You can put all sorts of things in it!
<div slot="footer">
<sl-rating></sl-rating>
<sl-button variant="primary">Preview</sl-button>
2020-07-22 20:02:49 +00:00
</div>
</sl-card>
<style>
.card-footer {
max-width: 300px;
}
2022-03-02 15:10:41 +00:00
.card-footer [slot='footer'] {
display: flex;
justify-content: space-between;
2020-07-22 20:02:49 +00:00
align-items: center;
}
</style>
```
2021-11-04 22:12:47 +00:00
```jsx react
2022-03-02 15:10:41 +00:00
import { SlButton, SlCard, SlRating } from '@shoelace-style/shoelace/dist/react';
2021-11-04 22:12:47 +00:00
const css = `
.card-footer {
max-width: 300px;
}
.card-footer [slot="footer"] {
display: flex;
justify-content: space-between;
align-items: center;
}
`;
const App = () => (
<>
2021-11-05 14:06:06 +00:00
<SlCard className="card-footer">
2021-11-04 22:12:47 +00:00
This card has a footer. You can put all sorts of things in it!
<div slot="footer">
<SlRating></SlRating>
2022-03-02 15:10:41 +00:00
<SlButton slot="footer" variant="primary">
Preview
</SlButton>
2021-11-04 22:12:47 +00:00
</div>
</SlCard>
<style>{css}</style>
</>
);
```
2020-07-22 20:02:49 +00:00
## Images
Cards accept an `image` slot. The image is displayed atop the card and stretches to fit.
```html preview
<sl-card class="card-image">
2022-03-02 15:10:41 +00:00
<img
slot="image"
src="https://images.unsplash.com/photo-1547191783-94d5f8f6d8b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=80"
2020-07-22 20:02:49 +00:00
alt="A kitten walks towards camera on top of pallet."
2022-03-02 15:10:41 +00:00
/>
2020-07-22 20:02:49 +00:00
This is a kitten, but not just any kitten. This kitten likes walking along pallets.
</sl-card>
<style>
.card-image {
max-width: 300px;
}
</style>
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlCard } from '@shoelace-style/shoelace/dist/react';
const css = `
.card-image {
max-width: 300px;
}
`;
const App = () => (
<>
2021-11-05 14:06:06 +00:00
<SlCard className="card-image">
2022-03-02 15:10:41 +00:00
<img
slot="image"
src="https://images.unsplash.com/photo-1547191783-94d5f8f6d8b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=80"
2021-11-04 22:12:47 +00:00
alt="A kitten walks towards camera on top of pallet."
/>
This is a kitten, but not just any kitten. This kitten likes walking along pallets.
</SlCard>
<style>{css}</style>
</>
);
```
2020-07-22 20:02:49 +00:00
[component-metadata:sl-card]