mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
chore: lift components folder
This commit is contained in:
parent
76df51674d
commit
2200b29b92
301 changed files with 57 additions and 76 deletions
5
src/TooltipDefinition/TooltipDefinition.Story.svelte
Normal file
5
src/TooltipDefinition/TooltipDefinition.Story.svelte
Normal file
|
@ -0,0 +1,5 @@
|
|||
<script>
|
||||
import TooltipDefinition from "./TooltipDefinition.svelte";
|
||||
</script>
|
||||
|
||||
<TooltipDefinition {...$$props}>Definition Tooltip</TooltipDefinition>
|
31
src/TooltipDefinition/TooltipDefinition.stories.js
Normal file
31
src/TooltipDefinition/TooltipDefinition.stories.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { withKnobs, select, text } from "@storybook/addon-knobs";
|
||||
import Component from "./TooltipDefinition.Story.svelte";
|
||||
|
||||
export default { title: "TooltipDefinition", decorators: [withKnobs] };
|
||||
|
||||
const directions = {
|
||||
"Top (top)": "top",
|
||||
"Bottom (bottom)": "bottom",
|
||||
};
|
||||
|
||||
const alignments = {
|
||||
"Start (start)": "start",
|
||||
"Center (center)": "center",
|
||||
"End (end)": "end",
|
||||
};
|
||||
|
||||
export const Default = () => ({
|
||||
Component,
|
||||
props: {
|
||||
direction: select("Tooltip direction (direction)", directions, "bottom"),
|
||||
align: select(
|
||||
"Tooltip alignment to trigger button (align)",
|
||||
alignments,
|
||||
"start"
|
||||
),
|
||||
tooltipText: text(
|
||||
"Tooltip content (tooltipText)",
|
||||
"Brief description of the dotted, underlined words above."
|
||||
),
|
||||
},
|
||||
});
|
51
src/TooltipDefinition/TooltipDefinition.svelte
Normal file
51
src/TooltipDefinition/TooltipDefinition.svelte
Normal file
|
@ -0,0 +1,51 @@
|
|||
<script>
|
||||
export let tooltipText = "";
|
||||
export let align = "center"; // "start" | "center" | "end"
|
||||
export let direction = "bottom"; // "top" | "bottom"
|
||||
export let id = "ccs-" + Math.random().toString(36);
|
||||
export let ref = null;
|
||||
|
||||
$: hidden = false;
|
||||
$: visible = false;
|
||||
</script>
|
||||
|
||||
<svelte:body
|
||||
on:keydown={e => {
|
||||
if (e.key === 'Escape') {
|
||||
hidden = true;
|
||||
}
|
||||
}} />
|
||||
|
||||
<div
|
||||
class:bx--tooltip--definition={true}
|
||||
class:bx--tooltip--a11y={true}
|
||||
{...$$restProps}
|
||||
on:mouseenter={() => {
|
||||
hidden = false;
|
||||
visible = true;
|
||||
}}
|
||||
on:mouseleave={() => {
|
||||
visible = false;
|
||||
}}>
|
||||
<button
|
||||
bind:this={ref}
|
||||
aria-describedby={id}
|
||||
class:bx--tooltip--a11y={true}
|
||||
class:bx--tooltip__trigger={true}
|
||||
class:bx--tooltip__trigger--definition={true}
|
||||
class:bx--tooltip--hidden={hidden}
|
||||
class:bx--tooltip--visible={visible}
|
||||
class="{direction && `bx--tooltip--${direction}`}
|
||||
{align && `bx--tooltip--align-${align}`}"
|
||||
on:click
|
||||
on:mouseover
|
||||
on:mouseenter
|
||||
on:mouseleave
|
||||
on:focus
|
||||
on:focus={() => {
|
||||
hidden = false;
|
||||
}}>
|
||||
<slot />
|
||||
</button>
|
||||
<div role="tooltip" {id} class:bx--assistive-text={true}>{tooltipText}</div>
|
||||
</div>
|
1
src/TooltipDefinition/index.js
Normal file
1
src/TooltipDefinition/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default as TooltipDefinition } from "./TooltipDefinition.svelte";
|
Loading…
Add table
Add a link
Reference in a new issue