mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
chore(tabs): document prop types
This commit is contained in:
parent
aadc8d9bf1
commit
c06aa92978
3 changed files with 61 additions and 19 deletions
|
@ -1,8 +1,27 @@
|
||||||
<script>
|
<script>
|
||||||
export let disabled = false;
|
/**
|
||||||
export let href = "#";
|
* Specify the tab label
|
||||||
|
* Alternatively, use the default slot (e.g. <Tab><span>Label</span></Tab>)
|
||||||
|
* @type {string} [label=""]
|
||||||
|
*/
|
||||||
export let label = "";
|
export let label = "";
|
||||||
export let role = "presentation";
|
|
||||||
|
/**
|
||||||
|
* Specify the href attribute
|
||||||
|
* @type {string} [href="#"]
|
||||||
|
*/
|
||||||
|
export let href = "#";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to disable the tab
|
||||||
|
* @type {boolean} [disabled=false]
|
||||||
|
*/
|
||||||
|
export let disabled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the tabindex
|
||||||
|
* @type {string} [tabindex="0"]
|
||||||
|
*/
|
||||||
export let tabindex = "0";
|
export let tabindex = "0";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +29,11 @@
|
||||||
* @type {string} [id]
|
* @type {string} [id]
|
||||||
*/
|
*/
|
||||||
export let id = "ccs-" + Math.random().toString(36);
|
export let id = "ccs-" + Math.random().toString(36);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain a reference to the anchor HTML element
|
||||||
|
* @type {null | HTMLAnchorElement} [ref=null]
|
||||||
|
*/
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
import { getContext } from "svelte";
|
import { getContext } from "svelte";
|
||||||
|
@ -26,7 +50,7 @@
|
||||||
|
|
||||||
<li
|
<li
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
{role}
|
role="presentation"
|
||||||
{id}
|
{id}
|
||||||
class:bx--tabs__nav-item={true}
|
class:bx--tabs__nav-item={true}
|
||||||
class:bx--tabs__nav-item--disabled={disabled}
|
class:bx--tabs__nav-item--disabled={disabled}
|
||||||
|
@ -59,6 +83,6 @@
|
||||||
aria-disabled={disabled}
|
aria-disabled={disabled}
|
||||||
{href}
|
{href}
|
||||||
class:bx--tabs__nav-link={true}>
|
class:bx--tabs__nav-link={true}>
|
||||||
{label}
|
<slot>{label}</slot>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -18,9 +18,7 @@
|
||||||
aria-hidden={!selected}
|
aria-hidden={!selected}
|
||||||
hidden={!selected}
|
hidden={!selected}
|
||||||
{id}
|
{id}
|
||||||
{...$$restProps}
|
|
||||||
class:bx--tab-content={true}
|
class:bx--tab-content={true}
|
||||||
class={$$restProps.class}
|
{...$$restProps}>
|
||||||
style={$$restProps.style}>
|
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,25 +1,42 @@
|
||||||
<script>
|
<script>
|
||||||
export let iconDescription = "Show menu options";
|
/**
|
||||||
export let role = "navigation";
|
* Specify the selected tab index
|
||||||
|
* @type {number} [selected=0]
|
||||||
|
*/
|
||||||
export let selected = 0;
|
export let selected = 0;
|
||||||
export let triggerHref = "#";
|
|
||||||
|
/**
|
||||||
|
* Specify the type of tabs
|
||||||
|
* @type {"default" | "container"} [type="default"]
|
||||||
|
*/
|
||||||
export let type = "default";
|
export let type = "default";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the ARIA label for the chevron icon
|
||||||
|
* @type {string} [iconDescription="Expand/Collapse"]
|
||||||
|
*/
|
||||||
|
export let iconDescription = "Show menu options";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the tab trigger href attribute
|
||||||
|
* @type {string} [triggerHref="#"]
|
||||||
|
*/
|
||||||
|
export let triggerHref = "#";
|
||||||
|
|
||||||
import { createEventDispatcher, afterUpdate, setContext } from "svelte";
|
import { createEventDispatcher, afterUpdate, setContext } from "svelte";
|
||||||
import { writable, derived } from "svelte/store";
|
import { writable, derived } from "svelte/store";
|
||||||
import ChevronDownGlyph from "carbon-icons-svelte/lib/ChevronDownGlyph";
|
import ChevronDownGlyph from "carbon-icons-svelte/lib/ChevronDownGlyph";
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
let dropdownHidden = true;
|
const tabs = writable([]);
|
||||||
let tabs = writable([]);
|
const tabsById = derived(tabs, (_) =>
|
||||||
let tabsById = derived(tabs, (_) =>
|
|
||||||
_.reduce((a, c) => ({ ...a, [c.id]: c }), {})
|
_.reduce((a, c) => ({ ...a, [c.id]: c }), {})
|
||||||
);
|
);
|
||||||
let currentIndex = selected;
|
|
||||||
let selectedTab = writable(undefined);
|
const selectedTab = writable(undefined);
|
||||||
let content = writable([]);
|
const content = writable([]);
|
||||||
let selectedContent = writable(undefined);
|
const selectedContent = writable(undefined);
|
||||||
|
|
||||||
setContext("Tabs", {
|
setContext("Tabs", {
|
||||||
selectedTab,
|
selectedTab,
|
||||||
|
@ -64,6 +81,9 @@
|
||||||
selected = currentIndex;
|
selected = currentIndex;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let dropdownHidden = true;
|
||||||
|
let currentIndex = selected;
|
||||||
|
|
||||||
$: currentIndex = selected;
|
$: currentIndex = selected;
|
||||||
$: currentTab = $tabs[currentIndex] || undefined;
|
$: currentTab = $tabs[currentIndex] || undefined;
|
||||||
$: currentContent = $content[currentIndex] || undefined;
|
$: currentContent = $content[currentIndex] || undefined;
|
||||||
|
@ -84,7 +104,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
{role}
|
role="navigation"
|
||||||
class:bx--tabs={true}
|
class:bx--tabs={true}
|
||||||
class:bx--tabs--container={type === 'container'}
|
class:bx--tabs--container={type === 'container'}
|
||||||
{...$$restProps}>
|
{...$$restProps}>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue