kitzo 2.0.34 → 2.1.1

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 CHANGED
@@ -15,6 +15,7 @@
15
15
  ##### [React js](#react)
16
16
 
17
17
  - React Toast notifications
18
+ - Tooltip wrapper component
18
19
 
19
20
  #### Install
20
21
 
@@ -25,23 +26,17 @@ npm i kitzo
25
26
  or
26
27
 
27
28
  ```javascript
28
- <script src="https://cdn.jsdelivr.net/npm/kitzo@2.0.34/dist/kitzo.umd.min.js"></script>
29
+ <script src="https://cdn.jsdelivr.net/npm/kitzo@2.1.1/dist/kitzo.umd.min.js"></script>
29
30
  ```
30
31
 
31
- > Attach this script tag in the html head tag and you are good to go.
32
+ > Vanilla: Attach this script tag in the html head tag and you are good to go.
32
33
 
33
34
  ---
34
35
 
35
- #### Quick usage overview: Vanilla js
36
+ #### API links
36
37
 
37
- | [API](#vanilla-apis) |
38
- | ----------------------------------- |
39
- | [`kitzo.copy()`](#copy-api) |
40
- | [`kitzo.tooltip()`](#tooltip-api) |
41
- | [`kitzo.ripple()`](#ripple-api) |
42
- | [`kitzo.debounce()`](#debounce-api) |
43
- | [`kitzo.clippath()`](#clippath-api) |
44
- | [`kitzo.getType()`](#typecheck-api) |
38
+ - **Vanilla**: [copy](#copy-api), [Tooltip](#tooltip-api), [Ripple](#ripple-api), [Debounce](#debounce-api), [Clippath](#clippath-api), [Get type](#typecheck-api)
39
+ - **React**: [Toast](#react-toast-api-usage), [Tooltip](#react-tooltip-api)
45
40
 
46
41
  #### Vanilla APIs
47
42
 
@@ -149,7 +144,7 @@ npm i kitzo
149
144
  #### React APIs
150
145
 
151
146
  ```jsx
152
- import { ToastContainer, toast, ... } from 'kitzo/react';
147
+ import { ToastContainer, toast, Tooltip, ... } from 'kitzo/react';
153
148
  ```
154
149
 
155
150
  ##### Toast API:
@@ -185,7 +180,7 @@ toast.custom((dismiss) => (
185
180
  toast.custom("string");
186
181
  ```
187
182
 
188
- ##### Toast API Usage
183
+ ##### React Toast API Usage
189
184
 
190
185
  ```jsx
191
186
  import { ToastContainer, toast } from 'kitzo/react';
@@ -240,4 +235,26 @@ function App() {
240
235
  }
241
236
  ```
242
237
 
243
- > Each toast can have its own position. default position is `top-center`.
238
+ > Each toast can have its own position. default position is `top-center`.
239
+
240
+ ##### React Tooltip API:
241
+
242
+ ```jsx
243
+ import { Tooltip } from 'kitzo/react';
244
+
245
+ function App() {
246
+ return (
247
+ <div>
248
+ <h1>Tooltip api</h1>
249
+
250
+ <div>
251
+ <Tooltip content="Tooltip" position="top" offset="10">
252
+ <button>Hover me</button>
253
+ </Tooltip>
254
+ </div>
255
+ </div>
256
+ );
257
+ }
258
+ ```
259
+
260
+ > what short description about this api need to written here bro?
package/dist/react.d.ts CHANGED
@@ -1,15 +1,17 @@
1
- import React from 'react';
1
+ import { ReactNode, CSSProperties } from 'react';
2
2
 
3
+ // Toast API types declaration
3
4
  export interface ToastOptions {
4
5
  position?: 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
5
6
  duration?: number;
6
- style?: React.CSSProperties;
7
+ style?: CSSProperties;
7
8
  showIcon?: boolean;
8
9
  }
9
10
 
10
- export type CustomContent = string | React.ReactNode | ((dismiss: () => void) => React.ReactNode);
11
+ export type CustomContent = string | ReactNode | ((dismiss: () => void) => ReactNode);
11
12
 
12
13
  export interface ToastAPI {
14
+ (text?: string, options?: ToastOptions): void;
13
15
  success(text?: string, options?: ToastOptions): void;
14
16
  error(text?: string, options?: ToastOptions): void;
15
17
  promise<T>(
@@ -26,4 +28,13 @@ export interface ToastAPI {
26
28
 
27
29
  export declare const toast: ToastAPI;
28
30
 
29
- export declare function ToastContainer(props: { position?: 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'; gap?: number }): void;
31
+ export declare function ToastContainer(props: { position?: 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'; gap?: number }): JSX.Element;
32
+
33
+ // Tooltip API types declaration
34
+ export interface TooltipProps {
35
+ content: string | ReactNode;
36
+ position?: 'top' | 'right' | 'bottom' | 'left';
37
+ offset?: number;
38
+ }
39
+
40
+ export declare function Tooltip(props: TooltipProps): JSX.Element;
package/dist/react.esm.js CHANGED
@@ -185,23 +185,23 @@ function toastStyles() {
185
185
  `;
186
186
  }
187
187
  const listeners = new Set();
188
- let isStyleAdded = false;
188
+ let isStyleAdded$1 = false;
189
189
  function addToast(toast) {
190
190
  listeners.forEach(callback => {
191
191
  callback(toast);
192
192
  });
193
193
  }
194
194
  function subscribe(callback) {
195
- if (!isStyleAdded) {
195
+ if (!isStyleAdded$1) {
196
196
  const styleTag = document.createElement('style');
197
197
  styleTag.textContent = toastStyles();
198
198
  document.head.appendChild(styleTag);
199
- isStyleAdded = true;
199
+ isStyleAdded$1 = true;
200
200
  }
201
201
  listeners.add(callback);
202
202
  return () => listeners.delete(callback);
203
203
  }
204
- function success(text = 'Toast success', options = {}) {
204
+ function toast(text = 'Toast message', options = {}) {
205
205
  const id = Date.now();
206
206
  options = Object.assign({
207
207
  duration: 2000,
@@ -215,7 +215,21 @@ function success(text = 'Toast success', options = {}) {
215
215
  options
216
216
  });
217
217
  }
218
- function error(text = 'Toast denied', options = {}) {
218
+ toast.success = (text = 'Toast success', options = {}) => {
219
+ const id = Date.now();
220
+ options = Object.assign({
221
+ duration: 2000,
222
+ id,
223
+ style: {},
224
+ showIcon: true
225
+ }, options);
226
+ addToast({
227
+ type: 'success',
228
+ text,
229
+ options
230
+ });
231
+ };
232
+ toast.error = (text = 'Toast denied', options = {}) => {
219
233
  const id = Date.now();
220
234
  options = Object.assign({
221
235
  duration: 2000,
@@ -228,8 +242,8 @@ function error(text = 'Toast denied', options = {}) {
228
242
  text,
229
243
  options
230
244
  });
231
- }
232
- function promise(callback, msgs = {}, options = {}) {
245
+ };
246
+ toast.promise = (callback, msgs = {}, options = {}) => {
233
247
  const id = Date.now();
234
248
  options = Object.assign({
235
249
  duration: 2000,
@@ -269,8 +283,8 @@ function promise(callback, msgs = {}, options = {}) {
269
283
  });
270
284
  return Promise.reject(normalizedError);
271
285
  });
272
- }
273
- function custom(render, options = {}) {
286
+ };
287
+ toast.custom = (render, options = {}) => {
274
288
  const id = Date.now();
275
289
  options = Object.assign({
276
290
  duration: 3000,
@@ -283,7 +297,7 @@ function custom(render, options = {}) {
283
297
  options
284
298
  });
285
299
  return id;
286
- }
300
+ };
287
301
  function dismiss(id, exitDelay) {
288
302
  addToast({
289
303
  type: 'dismiss',
@@ -541,11 +555,138 @@ function ToastContainer(props) {
541
555
  }));
542
556
  }
543
557
 
544
- const toast = {
545
- success,
546
- error,
547
- promise,
548
- custom
549
- };
558
+ const tooltipStyles = `
559
+ .kitzo-react-tooltip-content-default-style {
560
+ font-family: sans-serif;
561
+ font-size: 0.875rem;
562
+ background-color: hsl(0, 0%, 15%);
563
+ color: hsl(0, 0%, 95%);
564
+ padding-block: 8px;
565
+ padding-inline: 10px;
566
+ border-radius: 0.325rem;
567
+
568
+ @media (prefers-color-scheme: dark) {
569
+ background-color: hsl(0, 0%, 95%);
570
+ color: hsl(0, 0%, 15%);
571
+ }
572
+ }
573
+
574
+ .kitzo-react-tooltip-wrapper {
575
+ transition-duration: 120ms, 50ms;
576
+ transition-property: scale opacity;
577
+ }
578
+
579
+ .kitzo-react-tooltip-wrapper.top {
580
+ --tooltip-offset: calc(var(--offset) * 1px);
581
+
582
+ bottom: calc(var(--tooltip-offset) + 100%);
583
+ left: 50%;
584
+ translate: -50% 0;
585
+ scale: 0.7;
586
+ opacity: 0;
587
+ transform-origin: bottom;
588
+ }
589
+
590
+ .kitzo-react-tooltip-wrapper.right {
591
+ --tooltip-offset: calc(var(--offset) * 1px);
592
+
593
+ left: calc(var(--tooltip-offset) + 100%);
594
+ top: 50%;
595
+ translate: 0 -50%;
596
+ scale: 0.7;
597
+ opacity: 0;
598
+ transform-origin: left;
599
+ }
600
+
601
+ .kitzo-react-tooltip-wrapper.bottom {
602
+ --tooltip-offset: calc(var(--offset) * 1px);
603
+
604
+ top: calc(var(--tooltip-offset) + 100%);
605
+ left: 50%;
606
+ translate: -50% 0;
607
+ scale: 0.7;
608
+ opacity: 0;
609
+ transform-origin: top;
610
+ }
611
+
612
+ .kitzo-react-tooltip-wrapper.left {
613
+ --tooltip-offset: calc(var(--offset) * 1px);
614
+
615
+ right: calc(var(--tooltip-offset) + 100%);
616
+ top: 50%;
617
+ translate: 0 -50%;
618
+ scale: 0.7;
619
+ opacity: 0;
620
+ transform-origin: right;
621
+ }
622
+
623
+ .kitzo-react-tooltip-root:hover {
624
+ .kitzo-react-tooltip-wrapper.top {
625
+ scale: 1;
626
+ opacity: 1;
627
+ }
628
+ .kitzo-react-tooltip-wrapper.right {
629
+ scale: 1;
630
+ opacity: 1;
631
+ }
632
+ .kitzo-react-tooltip-wrapper.bottom {
633
+ scale: 1;
634
+ opacity: 1;
635
+ }
636
+ .kitzo-react-tooltip-wrapper.left {
637
+ scale: 1;
638
+ opacity: 1;
639
+ }
640
+ }
641
+ `;
642
+ (() => {
643
+ if (!document.getElementById('kitzo-react-tooltip-styles')) {
644
+ const styleTag = document.createElement('style');
645
+ styleTag.id = 'kitzo-react-tooltip-styles';
646
+ styleTag.textContent = tooltipStyles;
647
+ document.head.appendChild(styleTag);
648
+ isStyleAdded = true;
649
+ }
650
+ })();
651
+ function getPositionBasedClassName(position) {
652
+ let defaultClass = 'kitzo-react-tooltip-wrapper';
653
+ const allowedPositions = ['top', 'right', 'bottom', 'left'];
654
+ if (allowedPositions.includes(position)) {
655
+ return defaultClass + ' ' + position;
656
+ } else {
657
+ return defaultClass + ' ' + 'top';
658
+ }
659
+ }
660
+ function Tooltip({
661
+ content = 'Tooltip',
662
+ position = '',
663
+ offset = 8,
664
+ children
665
+ }) {
666
+ // sanitize props
667
+ if (typeof position !== 'string') {
668
+ console.warn(`[kitzo/react]: Tooltip position ignored due to invalid data type.`);
669
+ position = 'top';
670
+ }
671
+ if (isNaN(Number(offset))) offset = 8;
672
+ return /*#__PURE__*/React.createElement("div", {
673
+ style: {
674
+ position: 'relative',
675
+ width: 'fit-content',
676
+ '--offset': Math.max(0, offset)
677
+ },
678
+ className: "kitzo-react-tooltip-root"
679
+ }, children, /*#__PURE__*/React.createElement("div", {
680
+ style: {
681
+ position: 'absolute',
682
+ textWrap: 'nowrap',
683
+ pointerEvents: 'none'
684
+ },
685
+ tabIndex: -1,
686
+ className: getPositionBasedClassName(position.trim().toLowerCase())
687
+ }, typeof content === 'string' || typeof content === 'number' ? /*#__PURE__*/React.createElement("div", {
688
+ className: "kitzo-react-tooltip-content-default-style"
689
+ }, content) : /*#__PURE__*/React.createElement(React.Fragment, null, content)));
690
+ }
550
691
 
551
- export { ToastContainer, toast };
692
+ export { ToastContainer, Tooltip, toast };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.0.34",
3
+ "version": "2.1.1",
4
4
  "description": "A lightweight JavaScript UI micro-library.",
5
5
  "type": "module",
6
6
  "main": "./dist/kitzo.umd.js",