mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 11:36:36 +00:00
feat(tile): add optional expand/collapse icon labels to ExpandableTile
This commit is contained in:
parent
b2560a21ac
commit
524b5080a6
6 changed files with 83 additions and 50 deletions
|
@ -1023,17 +1023,19 @@ None.
|
||||||
|
|
||||||
### Props
|
### Props
|
||||||
|
|
||||||
| Prop name | Kind | Reactive | Type | Default value | Description |
|
| Prop name | Kind | Reactive | Type | Default value | Description |
|
||||||
| :-------------------- | :--------------- | :------- | :-------------------------------------- | ------------------------------------------------ | ----------------------------------------------------- |
|
| :-------------------- | :--------------- | :------- | :----------------------------------------- | ------------------------------------------------ | ----------------------------------------------------- |
|
||||||
| ref | <code>let</code> | Yes | <code>null | HTMLDivElement</code> | <code>null</code> | Obtain a reference to the top-level element |
|
| ref | <code>let</code> | Yes | <code>null | HTMLButtonElement</code> | <code>null</code> | Obtain a reference to the top-level element |
|
||||||
| tilePadding | <code>let</code> | Yes | <code>number</code> | <code>0</code> | Specify the padding of the tile (number of pixels) |
|
| tilePadding | <code>let</code> | Yes | <code>number</code> | <code>0</code> | Specify the padding of the tile (number of pixels) |
|
||||||
| tileMaxHeight | <code>let</code> | Yes | <code>number</code> | <code>0</code> | Specify the max height of the tile (number of pixels) |
|
| tileMaxHeight | <code>let</code> | Yes | <code>number</code> | <code>0</code> | Specify the max height of the tile (number of pixels) |
|
||||||
| expanded | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to expand the tile |
|
| expanded | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to expand the tile |
|
||||||
| light | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the light variant |
|
| light | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the light variant |
|
||||||
| tileCollapsedIconText | <code>let</code> | No | <code>string</code> | <code>"Interact to expand Tile"</code> | Specify the icon text of the collapsed tile |
|
| tileCollapsedIconText | <code>let</code> | No | <code>string</code> | <code>"Interact to expand Tile"</code> | Specify the icon text of the collapsed tile |
|
||||||
| tileExpandedIconText | <code>let</code> | No | <code>string</code> | <code>"Interact to collapse Tile"</code> | Specify the icon text of the expanded tile |
|
| tileExpandedIconText | <code>let</code> | No | <code>string</code> | <code>"Interact to collapse Tile"</code> | Specify the icon text of the expanded tile |
|
||||||
| tabindex | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify the tabindex |
|
| tileExpandedLabel | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the icon label of the expanded tile |
|
||||||
| id | <code>let</code> | No | <code>string</code> | <code>"ccs-" + Math.random().toString(36)</code> | Set an id for the top-level div element |
|
| tileCollapsedLabel | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the icon label of the collapsed tile |
|
||||||
|
| tabindex | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify the tabindex |
|
||||||
|
| id | <code>let</code> | No | <code>string</code> | <code>"ccs-" + Math.random().toString(36)</code> | Set an id for the top-level div element |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
|
|
|
@ -8492,6 +8492,26 @@
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": false
|
"reactive": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "tileExpandedLabel",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Specify the icon label of the expanded tile",
|
||||||
|
"type": "string",
|
||||||
|
"value": "\"\"",
|
||||||
|
"isFunction": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "tileCollapsedLabel",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Specify the icon label of the collapsed tile",
|
||||||
|
"type": "string",
|
||||||
|
"value": "\"\"",
|
||||||
|
"isFunction": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "tabindex",
|
"name": "tabindex",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
|
@ -8516,7 +8536,7 @@
|
||||||
"name": "ref",
|
"name": "ref",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
"description": "Obtain a reference to the top-level element",
|
"description": "Obtain a reference to the top-level element",
|
||||||
"type": "null | HTMLDivElement",
|
"type": "null | HTMLButtonElement",
|
||||||
"value": "null",
|
"value": "null",
|
||||||
"isFunction": false,
|
"isFunction": false,
|
||||||
"constant": false,
|
"constant": false,
|
||||||
|
@ -8528,14 +8548,14 @@
|
||||||
{ "name": "below", "default": false, "slot_props": "{}" }
|
{ "name": "below", "default": false, "slot_props": "{}" }
|
||||||
],
|
],
|
||||||
"events": [
|
"events": [
|
||||||
{ "type": "forwarded", "name": "click", "element": "div" },
|
{ "type": "forwarded", "name": "click", "element": "button" },
|
||||||
{ "type": "forwarded", "name": "keypress", "element": "div" },
|
{ "type": "forwarded", "name": "keypress", "element": "button" },
|
||||||
{ "type": "forwarded", "name": "mouseover", "element": "div" },
|
{ "type": "forwarded", "name": "mouseover", "element": "button" },
|
||||||
{ "type": "forwarded", "name": "mouseenter", "element": "div" },
|
{ "type": "forwarded", "name": "mouseenter", "element": "button" },
|
||||||
{ "type": "forwarded", "name": "mouseleave", "element": "div" }
|
{ "type": "forwarded", "name": "mouseleave", "element": "button" }
|
||||||
],
|
],
|
||||||
"typedefs": [],
|
"typedefs": [],
|
||||||
"rest_props": { "type": "Element", "name": "div" }
|
"rest_props": { "type": "Element", "name": "button" }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"moduleName": "SelectableTile",
|
"moduleName": "SelectableTile",
|
||||||
|
|
|
@ -27,3 +27,10 @@ source: Tile/ExpandableTile.svelte
|
||||||
<div slot="above" style="height: 10rem">Above the fold content here</div>
|
<div slot="above" style="height: 10rem">Above the fold content here</div>
|
||||||
<div slot="below" style="height: 10rem">Below the fold content here</div>
|
<div slot="below" style="height: 10rem">Below the fold content here</div>
|
||||||
</ExpandableTile>
|
</ExpandableTile>
|
||||||
|
|
||||||
|
### With icon labels
|
||||||
|
|
||||||
|
<ExpandableTile tileExpandedLabel="View less" tileCollapsedLabel="View more">
|
||||||
|
<div slot="above" style="height: 10rem">Above the fold content here</div>
|
||||||
|
<div slot="below" style="height: 10rem">Below the fold content here</div>
|
||||||
|
</ExpandableTile>
|
|
@ -17,6 +17,12 @@
|
||||||
/** Specify the icon text of the expanded tile */
|
/** Specify the icon text of the expanded tile */
|
||||||
export let tileExpandedIconText = "Interact to collapse Tile";
|
export let tileExpandedIconText = "Interact to collapse Tile";
|
||||||
|
|
||||||
|
/** Specify the icon label of the expanded tile */
|
||||||
|
export let tileExpandedLabel = "";
|
||||||
|
|
||||||
|
/** Specify the icon label of the collapsed tile */
|
||||||
|
export let tileCollapsedLabel = "";
|
||||||
|
|
||||||
/** Specify the tabindex */
|
/** Specify the tabindex */
|
||||||
export let tabindex = "0";
|
export let tabindex = "0";
|
||||||
|
|
||||||
|
@ -27,7 +33,7 @@
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
import { afterUpdate } from "svelte";
|
import { afterUpdate } from "svelte";
|
||||||
import ChevronDown16 from "carbon-icons-svelte/lib/ChevronDown16";
|
import ChevronDown16 from "carbon-icons-svelte/lib/ChevronDown16/ChevronDown16.svelte";
|
||||||
|
|
||||||
let refContent = null;
|
let refContent = null;
|
||||||
let refAbove = null;
|
let refAbove = null;
|
||||||
|
@ -45,10 +51,13 @@
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<button
|
||||||
bind:this="{ref}"
|
bind:this="{ref}"
|
||||||
|
type="button"
|
||||||
id="{id}"
|
id="{id}"
|
||||||
|
aria-expanded="{expanded}"
|
||||||
tabindex="{tabindex}"
|
tabindex="{tabindex}"
|
||||||
|
title="{expanded ? tileExpandedIconText : tileCollapsedIconText}"
|
||||||
class:bx--tile="{true}"
|
class:bx--tile="{true}"
|
||||||
class:bx--tile--expandable="{true}"
|
class:bx--tile--expandable="{true}"
|
||||||
class:bx--tile--is-expanded="{expanded}"
|
class:bx--tile--is-expanded="{expanded}"
|
||||||
|
@ -60,45 +69,24 @@
|
||||||
expanded = !expanded;
|
expanded = !expanded;
|
||||||
}}"
|
}}"
|
||||||
on:keypress
|
on:keypress
|
||||||
on:keypress="{(e) => {
|
|
||||||
if (e.key === ' ' || e.key === 'Enter') {
|
|
||||||
e.preventDefault();
|
|
||||||
expanded = !expanded;
|
|
||||||
}
|
|
||||||
}}"
|
|
||||||
on:mouseover
|
on:mouseover
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
on:mouseleave
|
on:mouseleave
|
||||||
>
|
>
|
||||||
<div bind:this="{refContent}">
|
<div bind:this="{refContent}">
|
||||||
<div bind:this="{refAbove}" class:bx--tile-content="{true}">
|
<div bind:this="{refAbove}" class:bx--tile-content="{true}">
|
||||||
<span
|
<span class:bx--tile-content__above-the-fold="{true}">
|
||||||
class:bx--tile-content__above-the-fold="{true}"
|
|
||||||
on:click
|
|
||||||
on:mouseover
|
|
||||||
on:mouseenter
|
|
||||||
on:mouseleave
|
|
||||||
>
|
|
||||||
<slot name="above" />
|
<slot name="above" />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<div class:bx--tile__chevron="{true}">
|
||||||
aria-expanded="{expanded}"
|
<span>{expanded ? tileExpandedLabel : tileCollapsedLabel}</span>
|
||||||
aria-label="{expanded ? tileExpandedIconText : tileCollapsedIconText}"
|
|
||||||
class:bx--tile__chevron="{true}"
|
|
||||||
>
|
|
||||||
<ChevronDown16 />
|
<ChevronDown16 />
|
||||||
</button>
|
</div>
|
||||||
<div class:bx--tile-content="{true}">
|
<div class:bx--tile-content="{true}">
|
||||||
<span
|
<span class:bx--tile-content__below-the-fold="{true}">
|
||||||
on:click
|
|
||||||
on:mouseover
|
|
||||||
on:mouseenter
|
|
||||||
on:mouseleave
|
|
||||||
class:bx--tile-content__below-the-fold="{true}"
|
|
||||||
>
|
|
||||||
<slot name="below" />
|
<slot name="below" />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</button>
|
||||||
|
|
|
@ -12,7 +12,11 @@
|
||||||
<div slot="below" style="height: 10rem">Below the fold content here</div>
|
<div slot="below" style="height: 10rem">Below the fold content here</div>
|
||||||
</ExpandableTile>
|
</ExpandableTile>
|
||||||
|
|
||||||
<ExpandableTile light>
|
<ExpandableTile
|
||||||
|
light
|
||||||
|
tileExpandedLabel="View less"
|
||||||
|
tileCollapsedLabel="View more"
|
||||||
|
>
|
||||||
<div slot="above" style="height: 10rem">Above the fold content here</div>
|
<div slot="above" style="height: 10rem">Above the fold content here</div>
|
||||||
<div slot="below" style="height: 10rem">Below the fold content here</div>
|
<div slot="below" style="height: 10rem">Below the fold content here</div>
|
||||||
</ExpandableTile>
|
</ExpandableTile>
|
||||||
|
|
16
types/Tile/ExpandableTile.d.ts
vendored
16
types/Tile/ExpandableTile.d.ts
vendored
|
@ -1,6 +1,6 @@
|
||||||
/// <reference types="svelte" />
|
/// <reference types="svelte" />
|
||||||
|
|
||||||
export interface ExpandableTileProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["div"]> {
|
export interface ExpandableTileProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["button"]> {
|
||||||
/**
|
/**
|
||||||
* Set to `true` to expand the tile
|
* Set to `true` to expand the tile
|
||||||
* @default false
|
* @default false
|
||||||
|
@ -37,6 +37,18 @@ export interface ExpandableTileProps extends svelte.JSX.HTMLAttributes<HTMLEleme
|
||||||
*/
|
*/
|
||||||
tileExpandedIconText?: string;
|
tileExpandedIconText?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the icon label of the expanded tile
|
||||||
|
* @default ""
|
||||||
|
*/
|
||||||
|
tileExpandedLabel?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the icon label of the collapsed tile
|
||||||
|
* @default ""
|
||||||
|
*/
|
||||||
|
tileCollapsedLabel?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the tabindex
|
* Specify the tabindex
|
||||||
* @default "0"
|
* @default "0"
|
||||||
|
@ -53,7 +65,7 @@ export interface ExpandableTileProps extends svelte.JSX.HTMLAttributes<HTMLEleme
|
||||||
* Obtain a reference to the top-level element
|
* Obtain a reference to the top-level element
|
||||||
* @default null
|
* @default null
|
||||||
*/
|
*/
|
||||||
ref?: null | HTMLDivElement;
|
ref?: null | HTMLButtonElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ExpandableTile {
|
export default class ExpandableTile {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue