diff --git a/.changeset/ppp_ooo_iiii.md b/.changeset/ppp_ooo_iiii.md new file mode 100644 index 00000000..b894115f --- /dev/null +++ b/.changeset/ppp_ooo_iiii.md @@ -0,0 +1,6 @@ +--- +'@ldn-viz/ui': minor +--- + +CHANGED: add modal support to tooltips. +CHANGED: update sidebar hint to use a tooltip for its modal option. diff --git a/packages/ui/src/lib/sidebar/elements/sidebarHint/SidebarHint.stories.svelte b/packages/ui/src/lib/sidebar/elements/sidebarHint/SidebarHint.stories.svelte index 347e533f..a4d59f6c 100644 --- a/packages/ui/src/lib/sidebar/elements/sidebarHint/SidebarHint.stories.svelte +++ b/packages/ui/src/lib/sidebar/elements/sidebarHint/SidebarHint.stories.svelte @@ -9,6 +9,22 @@ hintType: { options: ['tooltip', 'popover', 'modal'], control: { type: 'radio' } + }, + hintLabel: { + type: 'string', + control: { type: 'text' } + }, + modalTitle: { + type: 'string', + control: { type: 'text' } + }, + modalDescription: { + type: 'string', + control: { type: 'text' } + }, + modalWidth: { + options: ['xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl', '5xl', '6xl', '7xl', 'full'], + control: { type: 'select' } } } }; @@ -40,6 +56,44 @@ + + + + + + +
+

Heading

+

+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt + ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco + laboris nisi ut aliquip ex ea commodo consequat. +

+

+ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla + pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt + mollit anim id est laborum.' +

+

+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt + ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco + laboris nisi ut aliquip ex ea commodo consequat. +

+

+ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla + pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt + mollit anim id est laborum.' +

+
+
+
+ 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea diff --git a/packages/ui/src/lib/sidebar/elements/sidebarHint/SidebarHint.svelte b/packages/ui/src/lib/sidebar/elements/sidebarHint/SidebarHint.svelte index d5641796..8a3047b1 100644 --- a/packages/ui/src/lib/sidebar/elements/sidebarHint/SidebarHint.svelte +++ b/packages/ui/src/lib/sidebar/elements/sidebarHint/SidebarHint.svelte @@ -5,7 +5,6 @@ */ import Tooltip from '../../../tooltip/Tooltip.svelte'; - import SidebarHintModal from './SidebarHintModal.svelte'; /** * Form in which the help text should be displayed. @@ -57,8 +56,10 @@ {:else if hintType === 'modal'} - + - - + + + + {/if} diff --git a/packages/ui/src/lib/tooltip/Tooltip.stories.svelte b/packages/ui/src/lib/tooltip/Tooltip.stories.svelte index edf7b9bf..0fd6c1d9 100644 --- a/packages/ui/src/lib/tooltip/Tooltip.stories.svelte +++ b/packages/ui/src/lib/tooltip/Tooltip.stories.svelte @@ -45,3 +45,10 @@ But I still work the same + + + + Click me! +

This is the modal content in an extra large modal.

+
+
diff --git a/packages/ui/src/lib/tooltip/Tooltip.svelte b/packages/ui/src/lib/tooltip/Tooltip.svelte index b952db30..9512e5a5 100644 --- a/packages/ui/src/lib/tooltip/Tooltip.svelte +++ b/packages/ui/src/lib/tooltip/Tooltip.svelte @@ -16,23 +16,63 @@ import Button from '../button/Button.svelte'; import { floatingRef } from '../tooltip/tooltip.js'; + import Modal from '../modal/Modal.svelte'; /** - * text that appears in the tooltip target, next to the icon + * Text that appears in the tooltip target, next to the icon. */ export let hintLabel = 'what is this?'; /** - * text size for the tooltip target + * Text size for the tooltip target. */ export let hintSize: 'sm' | 'md' | 'lg' | undefined = undefined; + /** + * Description that appears below the title of the modal (the + * `aria-describedby` for the modal points to the element containing this + * text). The presence of this property enables modal toggling on tooltip + * click. + */ + export let modalDescription = ''; + + /** + * Title that appears at the top of the modal. + * + * This property is only applicable if a `modalDescription` or a named slot + * called `modal` is provided. + */ + export let modalTitle = ''; + + /** + * Width of the modal. + * + * This property is only applicable if a `modalDescription` or a named slot + * called `modal` is provided. + */ + export let modalWidth: + | 'sm' + | 'md' + | 'lg' + | 'xs' + | 'xl' + | '2xl' + | '3xl' + | '4xl' + | '5xl' + | '6xl' + | '7xl' + | 'full' + | undefined = undefined; + let showTooltip = false; let element: HTMLSpanElement; const arrowRef: Writable = writable(); let dynamicOptions = {}; + + // TODO: Needs refactoring into something more readable. $: if (showTooltip) { dynamicOptions = { middleware: [offset(10), flip(), shift(), arrow({ element: arrowRef })], @@ -53,9 +93,21 @@ } }; } + + let isModalOpen: Writable | undefined; + const openModal = () => { + if ($$slots.modal) { + isModalOpen?.set(true); + } + }; - +{#if modalDescription || $$slots.modal} + + {#if $$slots.modal} + + {/if} + +{/if} + {#if showTooltip}
- +