@dosgato/dialog 1.4.2 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,7 @@
19
19
 
20
20
  <style>
21
21
  button.reset {
22
- padding: 0.5em 1em;
22
+ padding: 0.5em 15px;
23
23
  border: 0;
24
24
  border-radius: 0.25em;
25
25
  background-color: var(--dg-button-bg, #501214);
@@ -30,7 +30,8 @@
30
30
  line-height: 1;
31
31
  }
32
32
  button.reset.compact {
33
- padding: 0.1em;
33
+ padding: 0.2em 5px 0.1em 5px;
34
+ font-size: 0.9em;
34
35
  }
35
36
  button.reset[disabled] {
36
37
  opacity: 0.6;
package/dist/Icon.svelte CHANGED
@@ -5,8 +5,10 @@
5
5
  -->
6
6
  <script lang="ts">
7
7
  import type { IconifyIcon } from '@iconify/svelte'
8
+ import type { GlueAlignOpts } from '@txstate-mws/svelte-components'
8
9
  import { randomid } from 'txstate-utils'
9
10
  import Tooltip from './Tooltip.svelte'
11
+
10
12
  export let icon: IconifyIcon | undefined
11
13
  /** Label used in a `<ScreenReaderOnly>`. */
12
14
  export let hiddenLabel: string | undefined = undefined
@@ -14,6 +16,7 @@
14
16
  export let width: string | number | undefined = undefined
15
17
  export let height: string | number | undefined = undefined
16
18
  export let tooltip: string | undefined = undefined
19
+ export let tooltipAlign: GlueAlignOpts = 'automiddle'
17
20
  let className: string | undefined = undefined
18
21
  export { className as class }
19
22
 
@@ -48,7 +51,7 @@
48
51
  </script>
49
52
 
50
53
  {#if icon}
51
- <Tooltip tip={tooltip} top>
54
+ <Tooltip tip={tooltip} align={tooltipAlign}>
52
55
  <svg role="img" class={className} viewBox="{icon.left ?? 0} {icon.top ?? 0} {icon.width ?? 256} {icon.height ?? 256}" class:vFlip={icon.vFlip} class:hFlip={icon.hFlip} class:inline {width} {height} aria-hidden={!hiddenLabel} aria-label={hiddenLabel} xmlns="http://www.w3.org/2000/svg">
53
56
  {@html svgBody(icon)}
54
57
  </svg>
@@ -1,5 +1,6 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { IconifyIcon } from '@iconify/svelte';
3
+ import type { GlueAlignOpts } from '@txstate-mws/svelte-components';
3
4
  declare const __propDef: {
4
5
  props: {
5
6
  icon: IconifyIcon | undefined;
@@ -8,6 +9,7 @@ declare const __propDef: {
8
9
  width?: string | number | undefined;
9
10
  height?: string | number | undefined;
10
11
  tooltip?: string | undefined;
12
+ tooltipAlign?: GlueAlignOpts;
11
13
  class?: string | undefined;
12
14
  };
13
15
  events: {
@@ -1,16 +1,60 @@
1
1
  <script lang="ts">
2
+ import { tick } from 'svelte'
3
+ import { glue, ScreenReaderOnly, type GlueAlignOpts } from '@txstate-mws/svelte-components'
4
+ import { randomid } from 'txstate-utils'
5
+
2
6
  export let tip: string | undefined = undefined
3
7
  export let top: boolean = false
4
8
  export let right: boolean = false
5
9
  export let bottom: boolean = false
6
10
  export let left: boolean = false
11
+ export let align: GlueAlignOpts | undefined = undefined
7
12
  export let active: boolean = false
13
+
14
+ const tooltipId = randomid()
15
+ const anchorName = `--tip-${tooltipId}`
16
+ let triggerEl: HTMLSpanElement
17
+ let slotwrapper: HTMLSpanElement
18
+
19
+ let hasFocusableChild = false
20
+ $: resolvedAlign = align ?? (top ? 'top' : right ? 'right' : bottom ? 'bottom' : left ? 'left' : 'auto') as GlueAlignOpts
21
+
22
+ async function reactToTip (..._: any[]) {
23
+ await tick()
24
+ if (!triggerEl) return
25
+ const focusable = triggerEl.querySelector('a[href], button, input, select, textarea, [tabindex]')
26
+ if (focusable) {
27
+ hasFocusableChild = true
28
+ focusable.setAttribute('aria-describedby', tooltipId)
29
+ } else {
30
+ hasFocusableChild = false
31
+ }
32
+ }
33
+ $: reactToTip(tip).catch(console.error)
8
34
  </script>
9
35
 
36
+ {#if tip}
37
+ <div class="tooltip-wrapper">
38
+ <span bind:this={slotwrapper} class="tooltip-slot" style:anchor-name={anchorName} bind:this={triggerEl}>
39
+ <slot />
40
+ {#if !hasFocusableChild}<ScreenReaderOnly>tooltip: {tip}</ScreenReaderOnly>{/if}
41
+ </span>
42
+ <div
43
+ id={tooltipId}
44
+ role="tooltip"
45
+ class="tooltip"
46
+ class:active
47
+ use:glue={{ target: slotwrapper, align: resolvedAlign, gap: 5 }}>
48
+ <div class="default-tip tip">{tip}</div>
49
+ </div>
50
+ </div>
51
+ {:else}
52
+ <slot />
53
+ {/if}
54
+
10
55
  <style>
11
56
  .tooltip {
12
57
  opacity: 0;
13
- position: absolute;
14
58
  z-index: 1;
15
59
  visibility: hidden;
16
60
  transition: opacity 150ms, visibility 150ms;
@@ -20,15 +64,12 @@
20
64
  border-radius: 6px;
21
65
  color: inherit;
22
66
  }
23
- .tooltip.top {
24
- transform: translate(-40%, -100%);
25
- margin-top: -20px;
26
- }
27
67
  .tooltip.active {
28
68
  opacity: 1;
29
69
  visibility: initial;
30
70
  }
31
- .tooltip-slot:hover + .tooltip {
71
+ .tooltip-slot:hover + .tooltip,
72
+ .tooltip-slot:focus-within + .tooltip {
32
73
  opacity: 1;
33
74
  visibility: initial;
34
75
  }
@@ -37,22 +78,3 @@
37
78
  background-color: #fff;
38
79
  }
39
80
  </style>
40
-
41
- {#if tip}
42
- <div class="tooltip-wrapper">
43
- <span class="tooltip-slot">
44
- <slot />
45
- </span>
46
- <div
47
- class="tooltip"
48
- class:active
49
- class:left
50
- class:right
51
- class:bottom
52
- class:top>
53
- <div class="default-tip tip">{tip}</div>
54
- </div>
55
- </div>
56
- {:else}
57
- <slot />
58
- {/if}
@@ -1,4 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import { type GlueAlignOpts } from '@txstate-mws/svelte-components';
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  tip?: string | undefined;
@@ -6,6 +7,7 @@ declare const __propDef: {
6
7
  right?: boolean;
7
8
  bottom?: boolean;
8
9
  left?: boolean;
10
+ align?: GlueAlignOpts | undefined;
9
11
  active?: boolean;
10
12
  };
11
13
  events: {
package/dist/index.d.ts CHANGED
@@ -32,6 +32,7 @@ export { default as Radio } from './Radio.svelte';
32
32
  export { default as Switcher } from './Switcher.svelte';
33
33
  export { default as Tab } from './Tab.svelte';
34
34
  export { default as Tabs } from './Tabs.svelte';
35
+ export { default as Tooltip } from './Tooltip.svelte';
35
36
  export * from './chooser/index.js';
36
37
  export * from './fileIcons.js';
37
38
  export * from './errorIcons.js';
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ export { default as Radio } from './Radio.svelte';
32
32
  export { default as Switcher } from './Switcher.svelte';
33
33
  export { default as Tab } from './Tab.svelte';
34
34
  export { default as Tabs } from './Tabs.svelte';
35
+ export { default as Tooltip } from './Tooltip.svelte';
35
36
  export * from './chooser/index.js';
36
37
  export * from './fileIcons.js';
37
38
  export * from './errorIcons.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dosgato/dialog",
3
3
  "description": "A component library for building forms that edit a JSON document.",
4
- "version": "1.4.2",
4
+ "version": "1.4.4",
5
5
  "scripts": {
6
6
  "prepublishOnly": "svelte-package",
7
7
  "dev": "vite dev --force",