Backpack accordion component.
Check the main Readme for a complete installation guide.
The withSingleItemAccordionState
higher-order component is used to limit one section to be expanded at any time.
import { BpkAccordion, BpkAccordionItem, withSingleItemAccordionState } from '@skyscanner/backpack-web/bpk-component-accordion';
const SingleItemAccordion = withSingleItemAccordionState(BpkAccordion);
export default () => (
<SingleItemAccordion>
<BpkAccordionItem id="stops" title="Stops">
My stops content.
</BpkAccordionItem>
<BpkAccordionItem id="departure-times" title="Departure times" initiallyExpanded>
My departure times content.
</BpkAccordionItem>
<BpkAccordionItem id="journey-duration" title="Journey duration">
My journey duration content.
</BpkAccordionItem>
</SingleItemAccordion>
)
The withAccordionItemState
higher-order component is used to allow multiple items to be expanded simultaneously.
import { BpkAccordion, BpkAccordionItem, withAccordionItemState } from '@skyscanner/backpack-web/bpk-component-accordion';
const StatefulAccordionItem = withAccordionItemState(BpkAccordionItem);
export default () => (
<BpkAccordion>
<StatefulAccordionItem id="stops" title="Stops">
My stops content.
</StatefulAccordionItem>
<StatefulAccordionItem id="departure-times" title="Departure times" initiallyExpanded>
My departure times content.
</StatefulAccordionItem>
<StatefulAccordionItem id="journey-duration" title="Journey duration" initiallyExpanded>
My journey duration content.
</StatefulAccordionItem>
</BpkAccordion>
)
BpkAccordionItem
supports the use of displaying icons alongside the title. To do this you will need to align your icon to the text using withAlignment
and pass through the matching sizes for the icon you wish to use. For more information see Alignment
import { BpkAccordion, BpkAccordionItem } from '@skyscanner/backpack-web/bpk-component-accordion';
import { withAlignment } from '@skyscanner/backpack-web/bpk-component-icon';
import StopsIcon from '@skyscanner/backpack-web/bpk-component-icon/sm/stops';
import { lineHeightBase, iconSizeSm, colorPanjin } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
const AlignedStopsIcon = withAlignment(StopsIcon, lineHeightBase, iconSizeSm);
<BpkAccordion>
<BpkAccordionItem id="stops" title="Stops" icon={<AlignedStopsIcon fill={colorPanjin}/>}>
My stops content.
</BpkAccordionItem>
</BpkAccordion>
Check out the full list of props on Skyscanner's design system documentation website.