fix(clickable-tile): support disabled state for ClickableTile

This commit is contained in:
Eric Y Liu 2021-04-30 16:34:59 -07:00
commit ce5348fdc0
5 changed files with 38 additions and 16 deletions

View file

@ -479,6 +479,7 @@ None.
| :-------- | :--------------- | :------- | :------------------- | ------------------ | ----------------------------------------- | | :-------- | :--------------- | :------- | :------------------- | ------------------ | ----------------------------------------- |
| clicked | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to click the tile | | clicked | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to click 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 |
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the tile |
| href | <code>let</code> | No | <code>string</code> | -- | Set the `href` | | href | <code>let</code> | No | <code>string</code> | -- | Set the `href` |
### Slots ### Slots

View file

@ -767,6 +767,16 @@
"constant": false, "constant": false,
"reactive": false "reactive": false
}, },
{
"name": "disabled",
"kind": "let",
"description": "Set to `true` to disable the tile",
"type": "boolean",
"value": "false",
"isFunction": false,
"constant": false,
"reactive": false
},
{ {
"name": "href", "name": "href",
"kind": "let", "kind": "let",
@ -779,14 +789,14 @@
], ],
"slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }], "slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }],
"events": [ "events": [
{ "type": "forwarded", "name": "click", "element": "a" }, { "type": "forwarded", "name": "click", "element": "Link" },
{ "type": "forwarded", "name": "keydown", "element": "a" }, { "type": "forwarded", "name": "keydown", "element": "Link" },
{ "type": "forwarded", "name": "mouseover", "element": "a" }, { "type": "forwarded", "name": "mouseover", "element": "Link" },
{ "type": "forwarded", "name": "mouseenter", "element": "a" }, { "type": "forwarded", "name": "mouseenter", "element": "Link" },
{ "type": "forwarded", "name": "mouseleave", "element": "a" } { "type": "forwarded", "name": "mouseleave", "element": "Link" }
], ],
"typedefs": [], "typedefs": [],
"rest_props": { "type": "Element", "name": "a" } "rest_props": { "type": "InlineComponent", "name": "Link" }
}, },
{ {
"moduleName": "CodeSnippet", "moduleName": "CodeSnippet",

View file

@ -14,3 +14,7 @@ source: Tile/ClickableTile.svelte
### Light variant ### Light variant
<ClickableTile light href="https://www.carbondesignsystem.com/">Carbon Design System</ClickableTile> <ClickableTile light href="https://www.carbondesignsystem.com/">Carbon Design System</ClickableTile>
### Disabled state
<ClickableTile disabled href="https://www.carbondesignsystem.com/">Carbon Design System</ClickableTile>

View file

@ -5,21 +5,23 @@
/** Set to `true` to enable the light variant */ /** Set to `true` to enable the light variant */
export let light = false; export let light = false;
/** Set to `true` to disable the tile */
export let disabled = false;
/** /**
* Set the `href` * Set the `href`
* @type {string} * @type {string}
*/ */
export let href = undefined; export let href = undefined;
import Link from "../Link/Link.svelte";
</script> </script>
<!-- svelte-ignore a11y-missing-attribute --> <Link
<a
class:bx--tile="{true}"
class:bx--tile--clickable="{true}"
class:bx--tile--is-clicked="{clicked}"
class:bx--tile--light="{light}"
rel="{$$restProps.target === '_blank' ? 'noopener noreferrer' : undefined}"
{...$$restProps} {...$$restProps}
disabled="{disabled}"
class="bx--tile bx--tile--clickable {clicked &&
'bx--tile--is-clicked'} {light && 'bx--tile--light'} {$$restProps.class}"
href="{href}" href="{href}"
on:click on:click
on:click="{() => { on:click="{() => {
@ -36,4 +38,4 @@
on:mouseleave on:mouseleave
> >
<slot /> <slot />
</a> </Link>

View file

@ -1,8 +1,7 @@
/// <reference types="svelte" /> /// <reference types="svelte" />
import { SvelteComponentTyped } from "svelte"; import { SvelteComponentTyped } from "svelte";
export interface ClickableTileProps export interface ClickableTileProps {
extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["a"]> {
/** /**
* Set to `true` to click the tile * Set to `true` to click the tile
* @default false * @default false
@ -15,6 +14,12 @@ export interface ClickableTileProps
*/ */
light?: boolean; light?: boolean;
/**
* Set to `true` to disable the tile
* @default false
*/
disabled?: boolean;
/** /**
* Set the `href` * Set the `href`
*/ */