Accordion
アコーディオン要素を作成できるコンポーネントです。
details/summary
を採用。grid
の1fr
を使った transition で “height:100% 問題” を解決。
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
<Accordion.Root p='20'> <Accordion.Header> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon/> </Accordion.Header> <Accordion.Body mbs='20'> <Dummy length='l' /> </Accordion.Body></Accordion.Root>
Props
プロパティ | 説明 |
---|---|
<Accordions> variant | .d--accordions--{variant} バリエーションクラスを出力します |
<Accordion.Root> variant | .d--accordion--{variant} バリエーションクラスを出力します |
<Accordions> ,<Accordion.Root> duration | --acc-duration が出力され、トランジションの時間を変更できます。 |
<Accordions> allowMultiple | data-acc-multiple が出力され、複数のアコーディオンを同時に開くことを禁止します。 |
<Accordion.Icon> icon | 内部で呼び出される<Icon> に渡す icon を指定できます。ただし、<Accordion.Icon> に子要素が配置されている場合は無視されます。 |
<Accordion.Icon> isTrigger | data-role="trigger" button タグでの出力となり[data-role="trigger"] が付与されます。 |
Import
import { Accordions, Accordion } from '@lism-ui/core';
HTML で使用する場合、jsファイルが必要です。
<script src='...'></script>
Usage
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
<Accordion.Root p='20'> <Accordion.Header> <Accordion.Label tag='h3' f='inherit'>Accordion.Label</Accordion.Label> <Accordion.Icon/> </Accordion.Header> <Accordion.Body mbs='20'> <Dummy length='l' /> </Accordion.Body></Accordion.Root>
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
<Accordion.Root p='20'> <Accordion.Header> <Accordion.Icon/> <Accordion.Label>Accordion.Label</Accordion.Label> </Accordion.Header> <Accordion.Body mbs='20'> <Dummy length='l' /> </Accordion.Body></Accordion.Root>
アイコンを変更する
<Accordion.Label>
に指定するicon
は、内部で<Icon>
に渡されます。
デフォルトは'caret-down'
になっています。
'caret-down-fill'
を指定するAccordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
<Accordion.Root p='20'> <Accordion.Header> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon icon='caret-down-fill'/> </Accordion.Header> <Accordion.Body mbs='20'> <Dummy length='l' /> </Accordion.Body></Accordion.Root>
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
import { CaretDoubleDown } from "@phosphor-icons/react";
<Accordion.Root p='20'> <Accordion.Header> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon icon={CaretDoubleDown}/> </Accordion.Header> <Accordion.Body mbs='20'> <Dummy length='l' /> </Accordion.Body></Accordion.Root>
開閉時にアイコンを変更する (Opt-in)
追加で少しCSSを加える必要がありますが、開閉時にアイコンを切り替える例も紹介します。
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
<Accordion.Root p='20'> <Accordion.Header> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon> <Icon icon={{as:Plus, weight:'bold'}} /> <Icon icon={{as:Minus, weight:'bold'}} /> </Accordion.Icon> </Accordion.Header> <Accordion.Body mbs='20'> <Dummy length='l' /> </Accordion.Body></Accordion.Root>
<Accordions>
アコーディオン専用のラッパーコンポーネントです。
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
<Accordions hasDivider bd> <Accordion.Root p='20'> <Accordion.Header> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon/> </Accordion.Header> <Accordion.Body mbs='20'> <Dummy length='l' /> </Accordion.Body> </Accordion.Root> <Accordion.Root p='20'> <Accordion.Header> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon/> </Accordion.Header> <Accordion.Body mbs='20'> <Dummy length='l' /> </Accordion.Body> </Accordion.Root> <Accordion.Root p='20'> <Accordion.Header> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon/> </Accordion.Header> <Accordion.Body mbs='20'> <Dummy length='l' /> </Accordion.Body> </Accordion.Root>
allowMultiple
allowMultiple
にfalse
を指定すると [data-acc-multiple="disallow"]
が出力され、複数のアコーディオンを同時に開くことを禁止します。
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
<Accordions hasDivider bdc='base' allowMultiple={false}> <Accordion.Root> <Accordion.Header p='30' bgc='text' c='base'> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon/> </Accordion.Header> <Accordion.Body p='30'> <Dummy length='l' /> </Accordion.Body> </Accordion.Root> <Accordion.Root> <Accordion.Header p='30' bgc='text' c='base'> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon/> </Accordion.Header> <Accordion.Body p='30'> <Dummy length='l' /> </Accordion.Body> </Accordion.Root> ...</Accordions>
開閉トランジションの時間を変更する
--acc-duration
でトランジションの秒数を管理します。
<Accordions>
,<Accordion>
にduration
を指定すると、(--acc-duration
)を出力できます。
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
Accordion.Label
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi provident libero, eum nulla sunt, porro sed dicta. Impedit ullam eveniet obcaecati minima.
<Accordions duration='0.4s' g='30'> <Accordion.Root bgc='base-2' bxsh='1' bdrs='3'> <Accordion.Header p='30'> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon/> </Accordion.Header> <Accordion.Body p='30' bd='t' bdc='divider'> <Dummy length='l' /> </Accordion.Body> </Accordion.Root> <Accordion.Root bgc='base-2' bxsh='1' bdrs='3'> <Accordion.Header p='30'> <Accordion.Label>Accordion.Label</Accordion.Label> <Accordion.Icon/> </Accordion.Header> <Accordion.Body p='30' bd='t' bdc='divider'> <Dummy length='l' /> </Accordion.Body> </Accordion.Root> ...</Accordions>
CSSで:root
の--acc-duration
を上書きすると、デフォルトの開閉速度を変更できます。
アコーディオントリガーをアイコンのみにする
<Accordion.Icon>
に isTrigger
を指定すると、button
タグでの出力となり[data-role="trigger"]
が付与されます。
この時、アコーディオンを開閉するためのclick
イベントは summary
(アコーディオンヘッダー)全体ではなくアイコン部分に対して登録されます。
これにより、アコーディオンヘッダー内にリンクを置いてもクリックできるようになります。
Labelテキスト(ヘルプリンク)
Lorem ipsum dolor sit, amet consectetur adipisicing elit, sed do eiusmod tempor. Non facere laudantium ex eos doloribus aut dolore nisi.
<Accordion.Root p='20'> <Accordion.Header trigger='icon'> <Accordion.Label>Labelテキスト(<a href="#acc-innerlink">ヘルプリンク</a>)</Accordion.Label> <Accordion.Icon isTrigger bd bdrs='1' bgc='inherit'/> </Accordion.Header> <Accordion.Body mbs='20'>...</Accordion.Body></Accordion.Root>
ただし、Tabキーでのカーソル操作時は、summary
タグ全体の選択を回避できません。