mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
feat(accordion): add disabled prop
This commit is contained in:
parent
cb80c7d15b
commit
ebf882cff4
5 changed files with 81 additions and 2 deletions
|
@ -199,6 +199,7 @@ import { Accordion } from "carbon-components-svelte";
|
||||||
| :-------- | :-------------------------------- | :------------ |
|
| :-------- | :-------------------------------- | :------------ |
|
||||||
| align | <code>"start" | "end"</code> | "end" |
|
| align | <code>"start" | "end"</code> | "end" |
|
||||||
| size | <code>"sm" | "xl"</code> | -- |
|
| size | <code>"sm" | "xl"</code> | -- |
|
||||||
|
| disabled | <code>boolean</code> | false |
|
||||||
| skeleton | <code>boolean</code> | false |
|
| skeleton | <code>boolean</code> | false |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
@ -232,6 +233,7 @@ import { AccordionItem } from "carbon-components-svelte";
|
||||||
| :-------------- | :------------------- | :---------------- |
|
| :-------------- | :------------------- | :---------------- |
|
||||||
| title | <code>string</code> | "title" |
|
| title | <code>string</code> | "title" |
|
||||||
| open | <code>boolean</code> | false |
|
| open | <code>boolean</code> | false |
|
||||||
|
| disabled | <code>boolean</code> | false |
|
||||||
| iconDescription | <code>string</code> | "Expand/Collapse" |
|
| iconDescription | <code>string</code> | "Expand/Collapse" |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
|
@ -91,6 +91,34 @@
|
||||||
</AccordionItem>
|
</AccordionItem>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
|
### Disabled
|
||||||
|
|
||||||
|
<Accordion disabled>
|
||||||
|
<AccordionItem title="Title 1">
|
||||||
|
Content 1
|
||||||
|
</AccordionItem>
|
||||||
|
<AccordionItem title="Title 2">
|
||||||
|
Content 2
|
||||||
|
</AccordionItem>
|
||||||
|
<AccordionItem title="Title 3">
|
||||||
|
Content 3
|
||||||
|
</AccordionItem>
|
||||||
|
</Accordion>
|
||||||
|
|
||||||
|
### Disabled (item)
|
||||||
|
|
||||||
|
<Accordion>
|
||||||
|
<AccordionItem disabled title="Title 1">
|
||||||
|
Content 1
|
||||||
|
</AccordionItem>
|
||||||
|
<AccordionItem title="Title 2">
|
||||||
|
Content 2
|
||||||
|
</AccordionItem>
|
||||||
|
<AccordionItem title="Title 3">
|
||||||
|
Content 3
|
||||||
|
</AccordionItem>
|
||||||
|
</Accordion>
|
||||||
|
|
||||||
### Skeleton
|
### Skeleton
|
||||||
|
|
||||||
<Accordion skeleton />
|
<Accordion skeleton />
|
||||||
|
|
|
@ -11,13 +11,27 @@
|
||||||
*/
|
*/
|
||||||
export let size = undefined;
|
export let size = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to disable the accordion
|
||||||
|
* @type {boolean} [disabled=false]
|
||||||
|
*/
|
||||||
|
export let disabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to `true` to display the skeleton state
|
* Set to `true` to display the skeleton state
|
||||||
* @type {boolean} [skeleton=false]
|
* @type {boolean} [skeleton=false]
|
||||||
*/
|
*/
|
||||||
export let skeleton = false;
|
export let skeleton = false;
|
||||||
|
|
||||||
|
import { setContext } from "svelte";
|
||||||
|
import { writable } from "svelte/store";
|
||||||
import AccordionSkeleton from "./Accordion.Skeleton.svelte";
|
import AccordionSkeleton from "./Accordion.Skeleton.svelte";
|
||||||
|
|
||||||
|
const disableItems = writable(disabled);
|
||||||
|
|
||||||
|
$: disableItems.set(disabled);
|
||||||
|
|
||||||
|
setContext("Accordion", { disableItems });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if skeleton}
|
{#if skeleton}
|
||||||
|
|
|
@ -12,22 +12,44 @@
|
||||||
*/
|
*/
|
||||||
export let open = false;
|
export let open = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to disable the accordion item
|
||||||
|
* @type {boolean} [disabled=false]
|
||||||
|
*/
|
||||||
|
export let disabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the ARIA label for the accordion item chevron icon
|
* Specify the ARIA label for the accordion item chevron icon
|
||||||
* @type {string} [iconDescription="Expand/Collapse"]
|
* @type {string} [iconDescription="Expand/Collapse"]
|
||||||
*/
|
*/
|
||||||
export let iconDescription = "Expand/Collapse";
|
export let iconDescription = "Expand/Collapse";
|
||||||
|
|
||||||
|
import { onMount, getContext } from "svelte";
|
||||||
import ChevronRight16 from "carbon-icons-svelte/lib/ChevronRight16";
|
import ChevronRight16 from "carbon-icons-svelte/lib/ChevronRight16";
|
||||||
|
|
||||||
$: animation = undefined;
|
let initialDisabled = disabled;
|
||||||
|
|
||||||
|
const ctx = getContext("Accordion");
|
||||||
|
const unsubscribe = ctx.disableItems.subscribe((value) => {
|
||||||
|
if (!value && initialDisabled) return;
|
||||||
|
disabled = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
let animation = undefined;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
return () => {
|
||||||
|
unsubscribe();
|
||||||
|
};
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<li
|
<li
|
||||||
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--${animation}"
|
class:bx--accordion__item--disabled="{disabled}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
|
class="bx--accordion__item--${animation} {$$restProps.class}"
|
||||||
on:animationend
|
on:animationend
|
||||||
on:animationend="{() => {
|
on:animationend="{() => {
|
||||||
animation = undefined;
|
animation = undefined;
|
||||||
|
@ -38,6 +60,7 @@
|
||||||
class:bx--accordion__heading="{true}"
|
class:bx--accordion__heading="{true}"
|
||||||
title="{iconDescription}"
|
title="{iconDescription}"
|
||||||
aria-expanded="{open}"
|
aria-expanded="{open}"
|
||||||
|
disabled="{disabled}"
|
||||||
on:click
|
on:click
|
||||||
on:click="{() => {
|
on:click="{() => {
|
||||||
open = !open;
|
open = !open;
|
||||||
|
|
12
types/index.d.ts
vendored
12
types/index.d.ts
vendored
|
@ -23,6 +23,12 @@ export class Accordion extends CarbonSvelteComponent {
|
||||||
*/
|
*/
|
||||||
size?: "sm" | "xl";
|
size?: "sm" | "xl";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to disable the accordion
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
disabled?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to `true` to display the skeleton state
|
* Set to `true` to display the skeleton state
|
||||||
* @default false
|
* @default false
|
||||||
|
@ -48,6 +54,12 @@ export class AccordionItem extends CarbonSvelteComponent {
|
||||||
*/
|
*/
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to disable the accordion item
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
disabled?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the ARIA label for the accordion item chevron icon
|
* Specify the ARIA label for the accordion item chevron icon
|
||||||
* @default "Expand/Collapse"
|
* @default "Expand/Collapse"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue