kitzo 2.0.33 → 2.1.0

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.33/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,8 +180,7 @@ toast.custom((dismiss) => (
185
180
  toast.custom("string");
186
181
  ```
187
182
 
188
- ##### Toast API Usage
189
-
183
+ ##### React Toast API Usage
190
184
 
191
185
  ```jsx
192
186
  import { ToastContainer, toast } from 'kitzo/react';
@@ -240,4 +234,27 @@ function App() {
240
234
  );
241
235
  }
242
236
  ```
243
- > Each toast can have its own position, but if you specify a position on `<ToastContainer />`, that position will apply to all toasts.
237
+
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,26 +185,25 @@ 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
- position: 'top-center',
208
207
  duration: 2000,
209
208
  id,
210
209
  style: {},
@@ -216,10 +215,23 @@ function success(text = 'Toast success', options = {}) {
216
215
  options
217
216
  });
218
217
  }
219
- 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 = {}) => {
220
233
  const id = Date.now();
221
234
  options = Object.assign({
222
- position: 'top-center',
223
235
  duration: 2000,
224
236
  id,
225
237
  style: {},
@@ -230,11 +242,10 @@ function error(text = 'Toast denied', options = {}) {
230
242
  text,
231
243
  options
232
244
  });
233
- }
234
- function promise(callback, msgs = {}, options = {}) {
245
+ };
246
+ toast.promise = (callback, msgs = {}, options = {}) => {
235
247
  const id = Date.now();
236
248
  options = Object.assign({
237
- position: 'top-center',
238
249
  duration: 2000,
239
250
  id,
240
251
  style: {},
@@ -272,11 +283,10 @@ function promise(callback, msgs = {}, options = {}) {
272
283
  });
273
284
  return Promise.reject(normalizedError);
274
285
  });
275
- }
276
- function custom(render, options = {}) {
286
+ };
287
+ toast.custom = (render, options = {}) => {
277
288
  const id = Date.now();
278
289
  options = Object.assign({
279
- position: 'top-center',
280
290
  duration: 3000,
281
291
  id,
282
292
  exitDelay: 50
@@ -287,7 +297,7 @@ function custom(render, options = {}) {
287
297
  options
288
298
  });
289
299
  return id;
290
- }
300
+ };
291
301
  function dismiss(id, exitDelay) {
292
302
  addToast({
293
303
  type: 'dismiss',
@@ -428,6 +438,7 @@ function getToastPosition(position) {
428
438
 
429
439
  function ToastContainer(props) {
430
440
  props = Object.assign({
441
+ position: 'top-center',
431
442
  gap: 8
432
443
  }, props);
433
444
  const {
@@ -519,25 +530,8 @@ function ToastContainer(props) {
519
530
  fontFamily: 'inherit',
520
531
  boxSizing: 'border-box'
521
532
  }
522
- }, position ? /*#__PURE__*/React.createElement("div", {
523
- style: {
524
- position: 'absolute',
525
- inset: 0,
526
- display: 'grid',
527
- padding: '1rem'
528
- }
529
- }, /*#__PURE__*/React.createElement("div", {
530
- style: {
531
- position: 'relative'
532
- }
533
- }, toasts.map(toast => /*#__PURE__*/React.createElement(Toast, {
534
- key: toast.options.id,
535
- toast: toast,
536
- setToasts: setToasts,
537
- position: position,
538
- gap: typeof gap === 'string' ? isNaN(+gap) ? 8 : +gap : gap
539
- })))) : /*#__PURE__*/React.createElement(React.Fragment, null, positions.map(pos => {
540
- const group = toasts.filter(t => t.options.position === pos);
533
+ }, positions.map(pos => {
534
+ const group = toasts.filter(t => (t.options.position || position || 'top-center') === pos);
541
535
  if (!group.length) return null;
542
536
  return /*#__PURE__*/React.createElement("div", {
543
537
  key: pos,
@@ -558,14 +552,141 @@ function ToastContainer(props) {
558
552
  position: pos,
559
553
  gap: typeof gap === 'string' ? isNaN(+gap) ? 8 : +gap : gap
560
554
  }))));
561
- })));
555
+ }));
562
556
  }
563
557
 
564
- const toast = {
565
- success,
566
- error,
567
- promise,
568
- custom
569
- };
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
+ }
570
691
 
571
- 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.33",
3
+ "version": "2.1.0",
4
4
  "description": "A lightweight JavaScript UI micro-library.",
5
5
  "type": "module",
6
6
  "main": "./dist/kitzo.umd.js",