kitzo 2.1.4 → 2.1.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.
- package/README.md +3 -3
- package/dist/react.esm.js +13 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ npm i kitzo
|
|
|
26
26
|
or
|
|
27
27
|
|
|
28
28
|
```javascript
|
|
29
|
-
<script src="https://cdn.jsdelivr.net/npm/kitzo@2.1.
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/kitzo@2.1.6/dist/kitzo.umd.min.js"></script>
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
> Vanilla: Attach this script tag in the html head tag and you are good to go.
|
|
@@ -248,7 +248,7 @@ function App() {
|
|
|
248
248
|
<h1>Tooltip api</h1>
|
|
249
249
|
|
|
250
250
|
<div>
|
|
251
|
-
<Tooltip content="Tooltip" position="top" offset="10">
|
|
251
|
+
<Tooltip content="Tooltip" position="top" offset="10" hideOnTouch={true}>
|
|
252
252
|
<button>Hover me</button>
|
|
253
253
|
</Tooltip>
|
|
254
254
|
</div>
|
|
@@ -257,4 +257,4 @@ function App() {
|
|
|
257
257
|
}
|
|
258
258
|
```
|
|
259
259
|
|
|
260
|
-
>
|
|
260
|
+
> You can provide your own custom jsx element as `content`. e.g. `content={<div>Custom tooltip</div>}`
|
package/dist/react.esm.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { useRef, useLayoutEffect, useState, useEffect } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
return `.toast-content,
|
|
3
|
+
const toastStyles = `.toast-content,
|
|
5
4
|
.toast-content-bottom {
|
|
6
5
|
font-size: 0.925rem;
|
|
7
6
|
}
|
|
@@ -183,7 +182,6 @@ function toastStyles() {
|
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
184
|
`;
|
|
186
|
-
}
|
|
187
185
|
const listeners = new Set();
|
|
188
186
|
function addToast(toast) {
|
|
189
187
|
listeners.forEach(callback => {
|
|
@@ -194,13 +192,13 @@ function subscribe(callback) {
|
|
|
194
192
|
if (!document.getElementById('kitzo-react-toast-styles')) {
|
|
195
193
|
const styleTag = document.createElement('style');
|
|
196
194
|
styleTag.id = 'kitzo-react-toast-styles';
|
|
197
|
-
styleTag.textContent = toastStyles
|
|
195
|
+
styleTag.textContent = toastStyles;
|
|
198
196
|
document.head.appendChild(styleTag);
|
|
199
197
|
}
|
|
200
198
|
listeners.add(callback);
|
|
201
199
|
return () => listeners.delete(callback);
|
|
202
200
|
}
|
|
203
|
-
function
|
|
201
|
+
function toast(text = 'Toast message', options = {}) {
|
|
204
202
|
const id = Date.now();
|
|
205
203
|
options = Object.assign({
|
|
206
204
|
duration: 2000,
|
|
@@ -214,7 +212,7 @@ function baseToast(text = 'Toast message', options = {}) {
|
|
|
214
212
|
options
|
|
215
213
|
});
|
|
216
214
|
}
|
|
217
|
-
|
|
215
|
+
toast.success = (text = 'Toast success', options = {}) => {
|
|
218
216
|
const id = Date.now();
|
|
219
217
|
options = Object.assign({
|
|
220
218
|
duration: 2000,
|
|
@@ -228,7 +226,7 @@ baseToast.success = (text = 'Toast success', options = {}) => {
|
|
|
228
226
|
options
|
|
229
227
|
});
|
|
230
228
|
};
|
|
231
|
-
|
|
229
|
+
toast.error = (text = 'Toast denied', options = {}) => {
|
|
232
230
|
const id = Date.now();
|
|
233
231
|
options = Object.assign({
|
|
234
232
|
duration: 2000,
|
|
@@ -242,7 +240,7 @@ baseToast.error = (text = 'Toast denied', options = {}) => {
|
|
|
242
240
|
options
|
|
243
241
|
});
|
|
244
242
|
};
|
|
245
|
-
|
|
243
|
+
toast.promise = (callback, msgs = {}, options = {}) => {
|
|
246
244
|
const id = Date.now();
|
|
247
245
|
options = Object.assign({
|
|
248
246
|
duration: 2000,
|
|
@@ -283,7 +281,7 @@ baseToast.promise = (callback, msgs = {}, options = {}) => {
|
|
|
283
281
|
return Promise.reject(normalizedError);
|
|
284
282
|
});
|
|
285
283
|
};
|
|
286
|
-
|
|
284
|
+
toast.custom = (render, options = {}) => {
|
|
287
285
|
const id = Date.now();
|
|
288
286
|
options = Object.assign({
|
|
289
287
|
duration: 3000,
|
|
@@ -304,7 +302,6 @@ function dismiss(id, exitDelay) {
|
|
|
304
302
|
exitDelay
|
|
305
303
|
});
|
|
306
304
|
}
|
|
307
|
-
const toast = baseToast;
|
|
308
305
|
|
|
309
306
|
function SuccessSvg() {
|
|
310
307
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -561,7 +558,7 @@ const tooltipStyles = `
|
|
|
561
558
|
font-size: 0.875rem;
|
|
562
559
|
background-color: hsl(0, 0%, 15%);
|
|
563
560
|
color: hsl(0, 0%, 95%);
|
|
564
|
-
padding-block:
|
|
561
|
+
padding-block: 6px;
|
|
565
562
|
padding-inline: 10px;
|
|
566
563
|
border-radius: 0.325rem;
|
|
567
564
|
|
|
@@ -660,8 +657,13 @@ function Tooltip({
|
|
|
660
657
|
content = 'Tooltip',
|
|
661
658
|
position = '',
|
|
662
659
|
offset = 8,
|
|
660
|
+
hideOnTouch = true,
|
|
663
661
|
children
|
|
664
662
|
}) {
|
|
663
|
+
if (typeof hideOnTouch !== 'boolean') hideOnTouch = true;
|
|
664
|
+
const isTouch = window.matchMedia('(pointer: coarse)').matches;
|
|
665
|
+
if (isTouch && hideOnTouch) return children;
|
|
666
|
+
|
|
665
667
|
// sanitize props
|
|
666
668
|
if (typeof position !== 'string') {
|
|
667
669
|
console.warn(`[kitzo/react]: Tooltip position ignored due to invalid data type.`);
|