@onsvisual/svelte-components 1.1.40 → 1.1.41

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.
@@ -13,47 +13,22 @@
13
13
  * Set a maximum width for the tooltip (beyond this width text will wrap)
14
14
  * @type {number|null}
15
15
  */
16
- export let maxWidth = null;
16
+ export let width = null;
17
17
 
18
18
  let isHovered = false;
19
- let currentPos = {};
20
19
 
21
- function mouseOver(event) {
22
- const bboxEl = event.target.getBoundingClientRect();
23
- const bboxPt = event?.target?.offsetParent?.getBoundingClientRect?.() || { top: 0, left: 0 };
24
- const x = window.pageXOffset;
25
- const y = window.pageYOffset;
26
- const bbox = {
27
- top: bboxEl.top - bboxPt.top - y,
28
- bottom: bboxEl.bottom - bboxPt.top - y,
29
- left: bboxEl.left - bboxPt.left - x,
30
- right: bboxEl.right - bboxPt.left - x
31
- };
32
- currentPos = {
33
- top:
34
- (position === "bottom"
35
- ? bbox.bottom
36
- : position === "top"
37
- ? bbox.top
38
- : (bbox.top + bbox.bottom) / 2) + window.pageYOffset,
39
- left:
40
- (position === "right"
41
- ? bbox.right
42
- : position === "left"
43
- ? bbox.left
44
- : (bbox.left + bbox.right) / 2) + window.pageXOffset
45
- };
20
+ function mouseOver() {
46
21
  isHovered = true;
22
+ console.log("hovered");
47
23
  }
48
24
  function mouseLeave() {
49
25
  isHovered = false;
50
- }
51
- function renderDim(dim) {
52
- return dim ? `${dim}px` : null;
26
+ console.log("unhovered");
53
27
  }
54
28
  </script>
55
29
 
56
30
  <div
31
+ role="tooltip"
57
32
  class="tooltip-wrapper"
58
33
  on:mouseenter={mouseOver}
59
34
  on:mouseleave={mouseLeave}
@@ -61,23 +36,21 @@
61
36
  on:focusout={mouseLeave}
62
37
  >
63
38
  <slot />
39
+ {#if isHovered}
40
+ <div
41
+ class="tooltip tooltip-{position}"
42
+ style:width={width != null ? `${width}px` : null}
43
+ style:white-space={width == null ? "nowrap" : "wrap"}
44
+ >
45
+ {text}
46
+ </div>
47
+ {/if}
64
48
  </div>
65
- {#if isHovered}
66
- <div
67
- class="tooltip tooltip-{position}"
68
- style:left={renderDim(currentPos.left)}
69
- style:right={renderDim(currentPos.right)}
70
- style:top={renderDim(currentPos.top)}
71
- style:bottom={renderDim(currentPos.bottom)}
72
- style:max-width={renderDim(maxWidth)}
73
- >
74
- {text}
75
- </div>
76
- {/if}
77
49
 
78
50
  <style>
79
51
  .tooltip-wrapper {
80
52
  display: inline-block;
53
+ position: relative;
81
54
  }
82
55
  .tooltip {
83
56
  position: absolute;
@@ -89,21 +62,32 @@
89
62
  padding: 4px 6px;
90
63
  border-radius: 4px;
91
64
  box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.25);
65
+ word-break: keep-all;
92
66
  }
93
67
  .tooltip-top {
94
- transform: translate(-50%, -100%) translateY(-8px);
68
+ bottom: calc(100% + 8px);
69
+ left: 50%;
70
+ transform: translateX(-50%);
95
71
  }
96
72
  .tooltip-bottom {
97
- transform: translate(-50%, 8px);
73
+ top: calc(100% + 8px);
74
+ left: 50%;
75
+ transform: translateX(-50%);
98
76
  }
99
77
  .tooltip-left {
100
- transform: translate(-100%, -50%) translateX(-8px);
78
+ top: 50%;
79
+ right: calc(100% + 8px);
80
+ transform: translateY(-50%);
101
81
  }
102
82
  .tooltip-right {
103
- transform: translate(8px, -50%);
83
+ top: 50%;
84
+ left: calc(100% + 8px);
85
+ transform: translateY(-50%);
104
86
  }
105
87
  .tooltip-middle {
106
- transform: translate(-50%, 8px);
88
+ top: calc(50% + 8px);
89
+ left: 50%;
90
+ transform: translateX(-50%);
107
91
  }
108
92
  .tooltip::before {
109
93
  content: " ";
@@ -2,9 +2,9 @@
2
2
  /** @typedef {typeof __propDef.events} TooltipEvents */
3
3
  /** @typedef {typeof __propDef.slots} TooltipSlots */
4
4
  export default class Tooltip extends SvelteComponentTyped<{
5
+ width?: number | null | undefined;
5
6
  text?: string | undefined;
6
7
  position?: "top" | "bottom" | "left" | "right" | "middle" | undefined;
7
- maxWidth?: number | null | undefined;
8
8
  }, {
9
9
  [evt: string]: CustomEvent<any>;
10
10
  }, {
@@ -17,9 +17,9 @@ export type TooltipSlots = typeof __propDef.slots;
17
17
  import { SvelteComponentTyped } from "svelte";
18
18
  declare const __propDef: {
19
19
  props: {
20
+ width?: number | null | undefined;
20
21
  text?: string | undefined;
21
22
  position?: "top" | "bottom" | "left" | "right" | "middle" | undefined;
22
- maxWidth?: number | null | undefined;
23
23
  };
24
24
  events: {
25
25
  [evt: string]: CustomEvent<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "1.1.40",
3
+ "version": "1.1.41",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "npm run build:package && npm run build:docs",