卡片 Svelte 元件

卡片與清單檢視一樣,是包含和整理資訊的另一種絕佳方式。卡片包含獨特的相關資料,例如,一張照片、文字和一個連結,全部都是關於單一主題。卡片通常是進入更複雜和詳細資訊的入口點。

卡片 Svelte 元件代表 卡片 元件。

卡片元件

包含下列元件

卡片屬性

屬性類型預設值說明
<Card> 屬性
標題字串卡片標頭內容
內容字串卡片內容
頁尾字串卡片頁尾內容
內距布林值true在卡片內容上增加額外的內部內距
外框布林值false讓卡片有外框 - 有邊框
outlineIos布林值false讓卡片外框採用 iOS 主題
outlineMd布林值false讓卡片外框採用 MD 主題
浮凸布林值false讓卡片浮凸 - 有陰影
標頭分隔線布林值false為卡片標頭加入分隔線 (邊框)
頁尾分隔線布林值false為卡片頁尾加入分隔線 (邊框)
可展開布林值false啟用可展開卡片
可展開動畫寬度布林值false啟用卡片內容寬度也可以動畫化和回應,但可能會影響效能
可展開已開啟布林值false布林值屬性,表示可展開卡片是否已開啟
動畫布林值true指定是否以動畫開啟可展開卡片
開啟時隱藏導覽列布林值可展開卡片開啟時將隱藏導覽列。預設值繼承相同的 應用程式卡片參數
開啟時隱藏工具列布林值可展開卡片開啟時將隱藏工具列。預設值繼承相同的 應用程式卡片參數
滑動關閉布林值允許用滑動關閉可展開卡片。預設值繼承相同的 應用程式卡片參數
背景布林值啟用可展開卡片背景圖層。預設值繼承相同的 應用程式卡片參數
背景元素字串允許指定自訂的可展開卡片背景元素。這應該是背景元素的 CSS 選擇器,例如,.card-backdrop.custom-backdrop
點選背景關閉布林值啟用時,可展開卡片將在其背景上點選時關閉。預設值繼承相同的 應用程式卡片參數
<CardContent> 屬性
內距布林值true增加額外的內部內距

卡片事件

事件說明
<Card> 事件
cardBeforeOpen可展開卡片開始其開啟動畫之前會觸發事件。當呼叫時,event.detail.prevent 包含會阻止卡片開啟的函式
cardOpen可展開卡片開始其開啟動畫時會觸發事件
cardOpened可展開卡片完成其開啟動畫後會觸發事件
cardClose可展開卡片開始其關閉動畫時會觸發事件
cardClosed可展開卡片完成其關閉動畫後會觸發事件

卡片插槽

<Card> 元件具有下列插槽

<Card>
  <span slot="header">Header</span>
  <span slot="content">Content</span>
  <span slot="footer">Footer</span>
</Card>

呈現為

<div class="card">
  <div class="card-header">
    <span>Header</span>
  </div>
  <div class="card-content">
    <span>Content</span>
  </div>
  <div class="card-footer">
    <span>Footer</span>
  </div>
</div>

範例

cards.svelte
<script>
  import {
    Navbar,
    Page,
    Block,
    BlockTitle,
    Card,
    CardHeader,
    CardContent,
    CardFooter,
    List,
    ListItem,
    Link,
  } from 'framework7-svelte';
</script>

<!-- svelte-ignore a11y-missing-attribute -->
<Page>
  <Navbar title="Cards" />

  <Block>
    <p>
      Cards are a great way to contain and organize your information, especially when combined with
      List Views. Cards can contain unique related data, like for example photos, text or links
      about a particular subject. Cards are typically an entry point to more complex and detailed
      information.
    </p>
  </Block>
  <BlockTitle>Simple Cards</BlockTitle>
  <Card
    content="This is a simple card with plain text, but cards can also contain their own header, footer, list view, image, or any other element."
  />
  <Card
    title="Card header"
    content="Card with header and footer. Card headers are used to display card titles and footers for additional information or just for custom actions."
    footer="Card footer"
  />
  <Card
    content="Another card. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse feugiat sem est, non tincidunt ligula volutpat sit amet. Mauris aliquet magna justo. "
  />

  <BlockTitle>Outline Cards</BlockTitle>
  <Card
    outline
    content="This is a simple card with plain text, but cards can also contain their own header, footer, list view, image, or any other element."
  />
  <Card
    outline
    title="Card header"
    content="Card with header and footer. Card headers are used to display card titles and footers for additional information or just for custom actions."
    footer="Card footer"
  />
  <Card
    outline
    content="Another card. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse feugiat sem est, non tincidunt ligula volutpat sit amet. Mauris aliquet magna justo. "
  />

  <BlockTitle>Outline With Dividers</BlockTitle>
  <Card
    outline
    headerDivider
    footerDivider
    title="Card header"
    content="Card with header and footer. Card headers are used to display card titles and footers for additional information or just for custom actions."
    footer="Card footer"
  />

  <BlockTitle>Raised Cards</BlockTitle>
  <Card
    raised
    content="This is a simple card with plain text, but cards can also contain their own header, footer, list view, image, or any other element."
  />
  <Card
    raised
    title="Card header"
    content="Card with header and footer. Card headers are used to display card titles and footers for additional information or just for custom actions."
    footer="Card footer"
  />
  <Card
    raised
    content="Another card. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse feugiat sem est, non tincidunt ligula volutpat sit amet. Mauris aliquet magna justo. "
  />

  <BlockTitle>Styled Cards</BlockTitle>
  <Card outlineMd class="demo-card-header-pic">
    <CardHeader
      valign="bottom"
      style="background-image: url(https://cdn.framework7.io/placeholder/nature-1000x600-3.jpg)"
      >Journey To Mountains</CardHeader
    >
    <CardContent>
      <p class="date">Posted on January 21, 2015</p>
      <p>
        Quisque eget vestibulum nulla. Quisque quis dui quis ex ultricies efficitur vitae non felis.
        Phasellus quis nibh hendrerit...
      </p>
    </CardContent>
    <CardFooter>
      <Link>Like</Link>
      <Link>Read more</Link>
    </CardFooter>
  </Card>
  <Card class="demo-card-header-pic">
    <CardHeader
      valign="bottom"
      style="background-image: url(https://cdn.framework7.io/placeholder/people-1000x600-6.jpg)"
      >Journey To Mountains</CardHeader
    >
    <CardContent>
      <p class="date">Posted on January 21, 2015</p>
      <p>
        Quisque eget vestibulum nulla. Quisque quis dui quis ex ultricies efficitur vitae non felis.
        Phasellus quis nibh hendrerit...
      </p>
    </CardContent>
    <CardFooter>
      <Link>Like</Link>
      <Link>Read more</Link>
    </CardFooter>
  </Card>

  <BlockTitle>Cards With List View</BlockTitle>
  <Card>
    <CardContent padding={false}>
      <List>
        <ListItem link="#">Link 1</ListItem>
        <ListItem link="#">Link 2</ListItem>
        <ListItem link="#">Link 3</ListItem>
        <ListItem link="#">Link 4</ListItem>
        <ListItem link="#">Link 5</ListItem>
      </List>
    </CardContent>
  </Card>
  <Card title="New Releases:">
    <CardContent padding={false}>
      <List mediaList>
        <ListItem title="Yellow Submarine" subtitle="Beatles">
          <img
            slot="media"
            src="https://cdn.framework7.io/placeholder/fashion-88x88-4.jpg"
            width="44"
          />
        </ListItem>
        <ListItem title="Don't Stop Me Now" subtitle="Queen">
          <img
            slot="media"
            src="https://cdn.framework7.io/placeholder/fashion-88x88-5.jpg"
            width="44"
          />
        </ListItem>
        <ListItem title="Billie Jean" subtitle="Michael Jackson">
          <img
            slot="media"
            src="https://cdn.framework7.io/placeholder/fashion-88x88-6.jpg"
            width="44"
          />
        </ListItem>
      </List>
    </CardContent>
    <CardFooter>
      <span>January 20, 2015</span>
      <span>5 comments</span>
    </CardFooter>
  </Card>
</Page>