refactor(accordion): use the class name directive, resolve svelte icon paths

This commit is contained in:
Eric Liu 2020-12-05 15:05:40 -08:00
commit c401149b5a
6 changed files with 26 additions and 23 deletions

View file

@ -192,12 +192,12 @@
### Props ### Props
| Prop name | Kind | Reactive | Type | Default value | Description | | Prop name | Kind | Reactive | Type | Default value | Description |
| :-------------- | :--------------- | :------- | :------------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- | | :-------------- | :--------------- | :------- | :------------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| disabled | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to disable the accordion item | | disabled | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to disable the accordion item |
| open | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to open the first accordion item | | open | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to open the first accordion item |
| title | <code>let</code> | No | <code>string</code> | <code>"title"</code> | Specify the title of the accordion item heading<br />Alternatively, use the named slot "title" (e.g., &lt;div slot="title"&gt;...&lt;/div&gt;) | | title | <code>let</code> | No | <code>string</code> | <code>"title"</code> | Specify the title of the accordion item heading<br />Alternatively, use the "title" slot (e.g., &lt;div slot="title"&gt;...&lt;/div&gt;) |
| iconDescription | <code>let</code> | No | <code>string</code> | <code>"Expand/Collapse"</code> | Specify the ARIA label for the accordion item chevron icon | | iconDescription | <code>let</code> | No | <code>string</code> | <code>"Expand/Collapse"</code> | Specify the ARIA label for the accordion item chevron icon |
### Slots ### Slots

View file

@ -191,7 +191,7 @@
{ {
"name": "title", "name": "title",
"kind": "let", "kind": "let",
"description": "Specify the title of the accordion item heading\nAlternatively, use the named slot \"title\" (e.g., <div slot=\"title\">...</div>)", "description": "Specify the title of the accordion item heading\nAlternatively, use the \"title\" slot (e.g., <div slot=\"title\">...</div>)",
"type": "string", "type": "string",
"value": "\"title\"", "value": "\"title\"",
"isFunction": false, "isFunction": false,

View file

@ -43,10 +43,11 @@
{:else} {:else}
<ul <ul
class:bx--accordion="{true}" class:bx--accordion="{true}"
class:bx--accordion--start="{align === 'start'}"
class:bx--accordion--end="{align === 'end'}"
class:bx--accordion--sm="{size === 'sm'}"
class:bx--accordion--xl="{size === 'xl'}"
{...$$restProps} {...$$restProps}
class="bx--accordion--{align}
{size && `bx--accordion--${size}`}
{$$restProps.class}"
on:click on:click
on:mouseover on:mouseover
on:mouseenter on:mouseenter

View file

@ -1,7 +1,7 @@
<script> <script>
/** /**
* Specify the title of the accordion item heading * Specify the title of the accordion item heading
* Alternatively, use the named slot "title" (e.g., <div slot="title">...</div>) * Alternatively, use the "title" slot (e.g., <div slot="title">...</div>)
*/ */
export let title = "title"; export let title = "title";
@ -15,7 +15,7 @@
export let iconDescription = "Expand/Collapse"; export let iconDescription = "Expand/Collapse";
import { onMount, getContext } from "svelte"; import { onMount, getContext } from "svelte";
import ChevronRight16 from "carbon-icons-svelte/lib/ChevronRight16"; import ChevronRight16 from "carbon-icons-svelte/lib/ChevronRight16/ChevronRight16.svelte";
let initialDisabled = disabled; let initialDisabled = disabled;
@ -38,8 +38,9 @@
class:bx--accordion__item="{true}" class:bx--accordion__item="{true}"
class:bx--accordion__item--active="{open}" class:bx--accordion__item--active="{open}"
class:bx--accordion__item--disabled="{disabled}" class:bx--accordion__item--disabled="{disabled}"
class:bx--accordion__item--expanding="{animation === 'expanding'}"
class:bx--accordion__item--collapsing="{animation === 'collapsing'}"
{...$$restProps} {...$$restProps}
class="bx--accordion__item--{animation} {$$restProps.class}"
on:animationend on:animationend
on:animationend="{() => { on:animationend="{() => {
animation = undefined; animation = undefined;
@ -70,11 +71,11 @@
class="bx--accordion__arrow" class="bx--accordion__arrow"
aria-label="{iconDescription}" aria-label="{iconDescription}"
/> />
<div class="bx--accordion__title"> <div class:bx--accordion__title="{true}">
<slot name="title">{title}</slot> <slot name="title">{title}</slot>
</div> </div>
</button> </button>
<div class="bx--accordion__content"> <div class:bx--accordion__content="{true}">
<slot /> <slot />
</div> </div>
</li> </li>

View file

@ -17,17 +17,18 @@
/** Set to `false` to close the first accordion item */ /** Set to `false` to close the first accordion item */
export let open = true; export let open = true;
import ChevronRight16 from "carbon-icons-svelte/lib/ChevronRight16"; import ChevronRight16 from "carbon-icons-svelte/lib/ChevronRight16/ChevronRight16.svelte";
import { SkeletonText } from "../SkeletonText"; import SkeletonText from "../SkeletonText/SkeletonText.svelte";
</script> </script>
<ul <ul
class:bx--accordion="{true}"
class:bx--skeleton="{true}" class:bx--skeleton="{true}"
class:bx--accordion="{true}"
class:bx--accordion--start="{align === 'start'}"
class:bx--accordion--end="{align === 'end'}"
class:bx--accordion--sm="{size === 'sm'}"
class:bx--accordion--xl="{size === 'xl'}"
{...$$restProps} {...$$restProps}
class="bx--accordion--{align}
{size && `bx--accordion--${size}`}
{$$restProps.class}"
on:click on:click
on:mouseover on:mouseover
on:mouseenter on:mouseenter
@ -49,7 +50,7 @@
</div> </div>
</li> </li>
{/if} {/if}
{#each Array.from({ length: open ? count - 1 : count }, (_, i) => i) as item, i (item)} {#each Array.from({ length: open ? count - 1 : count }, (_, i) => i) as item (item)}
<li class="bx--accordion__item"> <li class="bx--accordion__item">
<span class="bx--accordion__heading"> <span class="bx--accordion__heading">
<ChevronRight16 class="bx--accordion__arrow" /> <ChevronRight16 class="bx--accordion__arrow" />

View file

@ -3,7 +3,7 @@
export interface AccordionItemProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["li"]> { export interface AccordionItemProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["li"]> {
/** /**
* Specify the title of the accordion item heading * Specify the title of the accordion item heading
* Alternatively, use the named slot "title" (e.g., <div slot="title">...</div>) * Alternatively, use the "title" slot (e.g., <div slot="title">...</div>)
* @default "title" * @default "title"
*/ */
title?: string; title?: string;