@kws3/ui 1.6.5 → 1.6.6

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.
@@ -7,11 +7,14 @@
7
7
  @param {''|'small'|'medium'|'large'} [icon_size="small"] - Size of the trigger icon displayed when default slot has no content, Default: `"small"`
8
8
  @param {string} [trigger="click"] - Determines the events that cause the Popover to show. Multiple event names are separated by spaces.
9
9
 
10
- **Examples:** `click`, `mouseenter`, `mouseenter focus`, Default: `"click"`
10
+ **Examples:** `click`, `mouseenter`, `mouseenter focus`
11
+
12
+ If you would like to trigger the popover programatically only, you can use `manual`., Default: `"click"`
11
13
  @param {string} [placement="auto"] - Preferred placement of the Popover
12
14
 
13
15
  Available options: <a target="_blank" href="https://atomiks.github.io/tippyjs/v6/all-props/#placement">https://atomiks.github.io/tippyjs/v6/all-props/#placement</a>, Default: `"auto"`
14
16
  @param {boolean} [interactive=false] - Allows you to interact with the Popover content, when turned on, Default: `false`
17
+ @param {boolean} [hide_on_click=true] - Whether the popover should hide on clicking outside of it, Default: `true`
15
18
  @param {object} [external_target=null] - Specify a target node reference to use as the Popover content
16
19
 
17
20
  When set to `null`, it will use the content of the `popover` slot, Default: `null`
@@ -20,6 +23,16 @@ When set to `null`, it will use the content of the `popover` slot, Default: `nul
20
23
  It can be any CSS value associated with `max-width` property, including `"none"`, Default: `"none"`
21
24
  @param {string} [style=""] - Inline CSS for Popover trigger, Default: `""`
22
25
  @param {string} [class=""] - CSS classes for Popover trigger, Default: `""`
26
+ @param {function} [open()] - Open function
27
+ @param {function} [close()] - Close function
28
+ @param {function} [enable()] - Enable function
29
+ @param {function} [disable()] - Disable function
30
+ @param {function} [setProps(props)] - SetProps function
31
+
32
+ ### Events
33
+ - `open` - Triggered when popoper is shown
34
+ - `close` - Triggered when popoper is hidden
35
+ - `trigger` - Triggered when popover is triggered either programatically or by user interaction
23
36
 
24
37
  ### Slots
25
38
  - `<slot name="default" />` - Content of the Popover Trigger, by default it displays an Icon
@@ -28,11 +41,16 @@ It can be any CSS value associated with `max-width` property, including `"none"`
28
41
  -->
29
42
  <span
30
43
  use:popover={{ content: targetNode }}
44
+ bind:this={popoverParent}
45
+ on:shown={popoverShown}
46
+ on:hidden={popoverHidden}
47
+ on:triggered={popoverTriggered}
31
48
  data-tippy-trigger={trigger}
32
49
  data-tippy-placement={placement}
33
50
  data-tippy-offset="[0, 10]"
34
51
  data-tippy-interactive={interactive ? "true" : "false"}
35
52
  data-tippy-maxWidth={max_width}
53
+ data-tippy-hideOnClick={hide_on_click ? "true" : "false"}
36
54
  style={_style}
37
55
  class={klass}>
38
56
  <!--Content of the Popover Trigger, by default it displays an Icon--><slot
@@ -51,8 +69,12 @@ It can be any CSS value associated with `max-width` property, including `"none"`
51
69
  </style>
52
70
 
53
71
  <script>
72
+ import { createEventDispatcher } from "svelte";
54
73
  import { popover } from "./Tooltip";
55
74
  import { Icon } from "@kws3/ui";
75
+
76
+ const fire = createEventDispatcher();
77
+
56
78
  /**
57
79
  * Icon used when default slot has no content
58
80
  */
@@ -71,6 +93,8 @@ It can be any CSS value associated with `max-width` property, including `"none"`
71
93
  * Determines the events that cause the Popover to show. Multiple event names are separated by spaces.
72
94
  *
73
95
  * **Examples:** `click`, `mouseenter`, `mouseenter focus`
96
+ *
97
+ * If you would like to trigger the popover programatically only, you can use `manual`.
74
98
  */
75
99
  export let trigger = "click";
76
100
  /**
@@ -83,6 +107,10 @@ It can be any CSS value associated with `max-width` property, including `"none"`
83
107
  * Allows you to interact with the Popover content, when turned on
84
108
  */
85
109
  export let interactive = false;
110
+ /**
111
+ * Whether the popover should hide on clicking outside of it
112
+ */
113
+ export let hide_on_click = true;
86
114
  /**
87
115
  * Specify a target node reference to use as the Popover content
88
116
  *
@@ -106,7 +134,52 @@ It can be any CSS value associated with `max-width` property, including `"none"`
106
134
  let klass = "";
107
135
  export { klass as class };
108
136
 
109
- let popoverNode;
137
+ let popoverNode, popoverParent;
138
+
139
+ const getInstance = () => {
140
+ return popoverParent._tippy;
141
+ };
142
+
143
+ export function open() {
144
+ getInstance().show();
145
+ }
146
+
147
+ export function close() {
148
+ getInstance().hide();
149
+ }
150
+
151
+ export function enable() {
152
+ getInstance().enable();
153
+ }
154
+
155
+ export function disable() {
156
+ getInstance().disable();
157
+ }
158
+
159
+ export function setProps(props) {
160
+ getInstance().setProps(props);
161
+ }
162
+
163
+ const popoverShown = ({ detail }) => {
164
+ /**
165
+ * Triggered when popoper is shown
166
+ */
167
+ fire("open", detail);
168
+ };
169
+
170
+ const popoverHidden = ({ detail }) => {
171
+ /**
172
+ * Triggered when popoper is hidden
173
+ */
174
+ fire("close", detail);
175
+ };
176
+
177
+ const popoverTriggered = ({ detail }) => {
178
+ /**
179
+ * Triggered when popover is triggered either programatically or by user interaction
180
+ */
181
+ fire("trigger", detail);
182
+ };
110
183
 
111
184
  $: _style = `cursor:pointer;${style}`;
112
185
  $: targetNode = external_target ? external_target : popoverNode;
@@ -29,7 +29,17 @@ function createTippyAction(defaultOpts) {
29
29
  let instance;
30
30
 
31
31
  function makeOptions() {
32
- return Object.assign({}, defaultOpts, opts);
32
+ return Object.assign({}, defaultOpts, opts, {
33
+ onShow(instance) {
34
+ dispatch("shown", { instance });
35
+ },
36
+ onHide(instance) {
37
+ dispatch("hidden", { instance });
38
+ },
39
+ onTrigger(instance) {
40
+ dispatch("triggered", { instance });
41
+ },
42
+ });
33
43
  }
34
44
 
35
45
  function remakeInstance() {
@@ -51,6 +61,11 @@ function createTippyAction(defaultOpts) {
51
61
 
52
62
  makeInstance();
53
63
 
64
+ function dispatch(type, detail) {
65
+ const e = new CustomEvent(type, { bubbles: false, detail });
66
+ node.dispatchEvent(e);
67
+ }
68
+
54
69
  return {
55
70
  update(_opts) {
56
71
  opts = _opts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kws3/ui",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
4
4
  "description": "UI components for use with Svelte v3 applications.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,5 +29,5 @@
29
29
  "text-mask-core": "^5.1.2",
30
30
  "tippy.js": "^6.3.1"
31
31
  },
32
- "gitHead": "7bd56973e65c032a94e8285e321de06d0a89d051"
32
+ "gitHead": "0f6862d3aefc099de5ccc7df5eaca60c47bbcdab"
33
33
  }