tiny-react-dialog 0.0.5 → 0.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 +116 -66
- package/dist/TinyReactDialog.d.ts +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +3 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,69 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
### `tiny-react-dialog`
|
|
2
|
+
|
|
3
|
+
A simple, lightweight, and customizable React library for displaying modal dialog boxes.
|
|
4
|
+
|
|
5
|
+
-----
|
|
6
|
+
|
|
7
|
+
### Installation
|
|
8
|
+
|
|
9
|
+
Install the package using npm:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install tiny-react-dialog
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or with Yarn:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
yarn add tiny-react-dialog
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
-----
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
**Import**
|
|
26
|
+
|
|
27
|
+
The core component is `TinyReactDialog`. The default styles are optional; if you prefer to provide your own styling, you can omit the CSS import.
|
|
28
|
+
|
|
29
|
+
```jsx
|
|
30
|
+
import { TinyReactDialog } from 'tiny-react-dialog';
|
|
31
|
+
// Optional: import default styles
|
|
32
|
+
import 'tiny-react-dialog/index.css';
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Controlling the Component**
|
|
36
|
+
|
|
37
|
+
`TinyReactDialog` is a **controlled component**. You must manage its visibility from your parent component's state using the **`visible`** prop and a callback function for the **`onClose`** prop.
|
|
38
|
+
|
|
39
|
+
The `onClose` callback is triggered when the user clicks the close button or the overlay, allowing you to update your state and close the dialog.
|
|
40
|
+
|
|
41
|
+
**Styling and Customization**
|
|
42
|
+
|
|
43
|
+
The component comes with an optional default CSS file. If you choose not to import it, you can style the dialog yourself using the default CSS class names or by providing your own via the `classNames` prop.
|
|
44
|
+
|
|
45
|
+
The component's default structure is:
|
|
46
|
+
|
|
47
|
+
```html
|
|
48
|
+
<div class="tiny-react-dialog__overlay">
|
|
49
|
+
<div class="tiny-react-dialog__container">
|
|
50
|
+
<div class="tiny-react-dialog__content">
|
|
51
|
+
<!-- Content -->
|
|
52
|
+
</div>
|
|
53
|
+
<button class="tiny-react-dialog__close">
|
|
54
|
+
<!-- SVG closing icon -->
|
|
55
|
+
</button>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
40
58
|
```
|
|
41
59
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// Other configs...
|
|
55
|
-
// Enable lint rules for React
|
|
56
|
-
reactX.configs["recommended-typescript"],
|
|
57
|
-
// Enable lint rules for React DOM
|
|
58
|
-
reactDom.configs.recommended,
|
|
59
|
-
],
|
|
60
|
-
languageOptions: {
|
|
61
|
-
parserOptions: {
|
|
62
|
-
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
|
|
63
|
-
tsconfigRootDir: import.meta.dirname,
|
|
64
|
-
},
|
|
65
|
-
// other options...
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
]);
|
|
60
|
+
To add your own classes (for example, with **Tailwind CSS**), use the **`classNames`** prop:
|
|
61
|
+
|
|
62
|
+
```jsx
|
|
63
|
+
import { TinyReactDialog } from 'tiny-react-dialog';
|
|
64
|
+
|
|
65
|
+
<TinyReactDialog
|
|
66
|
+
classNames={{
|
|
67
|
+
overlay: "bg-black/50 backdrop-blur",
|
|
68
|
+
container: "bg-white rounded-lg shadow-lg",
|
|
69
|
+
content: "p-4",
|
|
70
|
+
close: "top-2 right-2 p-1 text-gray-400 hover:text-gray-600"
|
|
71
|
+
}} />
|
|
69
72
|
```
|
|
73
|
+
|
|
74
|
+
-----
|
|
75
|
+
|
|
76
|
+
### Example
|
|
77
|
+
|
|
78
|
+
Here's a complete example showing how to manage the dialog's state.
|
|
79
|
+
|
|
80
|
+
```jsx
|
|
81
|
+
import { useState } from "react";
|
|
82
|
+
import { TinyReactDialog } from "tiny-react-dialog";
|
|
83
|
+
import "tiny-react-dialog/index.css";
|
|
84
|
+
|
|
85
|
+
export default function Example() {
|
|
86
|
+
const [isDialogVisible, setIsDialogVisible] = useState(false);
|
|
87
|
+
|
|
88
|
+
const openDialog = () => {
|
|
89
|
+
setIsDialogVisible(true);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const closeDialog = () => {
|
|
93
|
+
setIsDialogVisible(false);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<>
|
|
98
|
+
<button onClick={openDialog}>Open Dialog</button>
|
|
99
|
+
|
|
100
|
+
<TinyReactDialog visible={isDialogVisible} onClose={closeDialog}>
|
|
101
|
+
Dialog Content
|
|
102
|
+
</TinyReactDialog>
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
-----
|
|
109
|
+
|
|
110
|
+
### Props
|
|
111
|
+
|
|
112
|
+
The component accepts the following properties:
|
|
113
|
+
|
|
114
|
+
| Prop | Type | Default Value | Description |
|
|
115
|
+
|:-------------|:----------------------------|:--------------|:--------------------------------------------------------------------------------|
|
|
116
|
+
| `visible` | `boolean` | `false` | Determines whether the dialog box is visible or hidden. |
|
|
117
|
+
| `onClose` | `() => void` | **Required** | A function to be called when the user requests to close the dialog. |
|
|
118
|
+
| `children` | `ReactNode` | `undefined` | The content to be rendered inside the dialog box. |
|
|
119
|
+
| `classNames` | `{ overlay?: string, ... }` | `{}` | An object for applying custom CSS class names to different parts of the dialog. |
|
package/dist/index.es.js
CHANGED
package/dist/index.umd.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var A;function q(){if(A)return v;A=1;var
|
|
9
|
+
*/var A;function q(){if(A)return v;A=1;var s=Symbol.for("react.transitional.element"),f=Symbol.for("react.fragment");function _(i,a,c){var p=null;if(c!==void 0&&(p=""+c),a.key!==void 0&&(p=""+a.key),"key"in a){c={};for(var T in a)T!=="key"&&(c[T]=a[T])}else c=a;return a=c.ref,{$$typeof:s,type:i,key:p,ref:a!==void 0?a:null,props:c}}return v.Fragment=f,v.jsx=_,v.jsxs=_,v}var b={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var P;function J(){return P||(P=1,process.env.NODE_ENV!=="production"&&(function(){function
|
|
17
|
+
*/var P;function J(){return P||(P=1,process.env.NODE_ENV!=="production"&&(function(){function s(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ae?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case x:return"Fragment";case Z:return"Profiler";case H:return"StrictMode";case re:return"Suspense";case te:return"SuspenseList";case oe:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case B:return"Portal";case K:return(e.displayName||"Context")+".Provider";case Q:return(e._context.displayName||"Context")+".Consumer";case ee:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ne:return r=e.displayName||null,r!==null?r:s(e.type)||"Memo";case F:r=e._payload,e=e._init;try{return s(e(r))}catch{}}return null}function f(e){return""+e}function _(e){try{f(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,n=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),f(e)}}function i(e){if(e===x)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===F)return"<...>";try{var r=s(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function a(){var e=j.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function p(e){if(I.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function T(e,r){function t(){L||(L=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function G(){var e=s(this.type);return M[e]||(M[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function X(e,r,t,n,d,l,O,w){return t=l.ref,e={$$typeof:D,type:e,key:r,props:l,_owner:d},(t!==void 0?t:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:G}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:O}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:w}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function C(e,r,t,n,d,l,O,w){var o=r.children;if(o!==void 0)if(n)if(se(o)){for(n=0;n<o.length;n++)Y(o[n]);Object.freeze&&Object.freeze(o)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Y(o);if(I.call(r,"key")){o=s(e);var E=Object.keys(r).filter(function(ie){return ie!=="key"});n=0<E.length?"{key: someKey, "+E.join(": ..., ")+": ...}":"{key: someKey}",U[o+n]||(E=0<E.length?"{"+E.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,n,o,E,o),U[o+n]=!0)}if(o=null,t!==void 0&&(_(t),o=""+t),p(r)&&(_(r.key),o=""+r.key),"key"in r){t={};for(var S in r)S!=="key"&&(t[S]=r[S])}else t=r;return o&&T(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),X(e,o,l,d,a(),t,O,w)}function Y(e){typeof e=="object"&&e!==null&&e.$$typeof===D&&e._store&&(e._store.validated=1)}var h=R,D=Symbol.for("react.transitional.element"),B=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),H=Symbol.for("react.strict_mode"),Z=Symbol.for("react.profiler"),Q=Symbol.for("react.consumer"),K=Symbol.for("react.context"),ee=Symbol.for("react.forward_ref"),re=Symbol.for("react.suspense"),te=Symbol.for("react.suspense_list"),ne=Symbol.for("react.memo"),F=Symbol.for("react.lazy"),oe=Symbol.for("react.activity"),ae=Symbol.for("react.client.reference"),j=h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=Object.prototype.hasOwnProperty,
|
|
22
|
+
<%s key={someKey} {...props} />`,n,o,E,o),U[o+n]=!0)}if(o=null,t!==void 0&&(_(t),o=""+t),p(r)&&(_(r.key),o=""+r.key),"key"in r){t={};for(var S in r)S!=="key"&&(t[S]=r[S])}else t=r;return o&&T(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),X(e,o,l,d,a(),t,O,w)}function Y(e){typeof e=="object"&&e!==null&&e.$$typeof===D&&e._store&&(e._store.validated=1)}var h=R,D=Symbol.for("react.transitional.element"),B=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),H=Symbol.for("react.strict_mode"),Z=Symbol.for("react.profiler"),Q=Symbol.for("react.consumer"),K=Symbol.for("react.context"),ee=Symbol.for("react.forward_ref"),re=Symbol.for("react.suspense"),te=Symbol.for("react.suspense_list"),ne=Symbol.for("react.memo"),F=Symbol.for("react.lazy"),oe=Symbol.for("react.activity"),ae=Symbol.for("react.client.reference"),j=h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=Object.prototype.hasOwnProperty,se=Array.isArray,y=console.createTask?console.createTask:function(){return null};h={react_stack_bottom_frame:function(e){return e()}};var L,M={},$=h.react_stack_bottom_frame.bind(h,c)(),W=y(i(c)),U={};b.Fragment=x,b.jsx=function(e,r,t,n,d){var l=1e4>j.recentlyCreatedOwnerStacks++;return C(e,r,t,!1,n,d,l?Error("react-stack-top-frame"):$,l?y(i(e)):W)},b.jsxs=function(e,r,t,n,d){var l=1e4>j.recentlyCreatedOwnerStacks++;return C(e,r,t,!0,n,d,l?Error("react-stack-top-frame"):$,l?y(i(e)):W)}})()),b}var N;function z(){return N||(N=1,process.env.NODE_ENV==="production"?k.exports=q():k.exports=J()),k.exports}var u=z();function g(s,f){return[s,f].filter(Boolean).join(" ")}function V({visible:s=!1,onClose:f,children:_="tiny-react-dialog: children is missing",classNames:i={}}){return u.jsx(u.Fragment,{children:s&&u.jsx("div",{className:g("tiny-react-dialog__overlay",i?.overlay),onClick:f,children:u.jsxs("div",{className:g("tiny-react-dialog__container",i?.container),onClick:a=>a.stopPropagation(),children:[u.jsx("div",{className:g("tiny-react-dialog__content",i?.content),children:_}),u.jsx("button",{className:g("tiny-react-dialog__close",i?.close),onClick:f,children:u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-x-icon lucide-x",children:[u.jsx("path",{d:"M18 6 6 18"}),u.jsx("path",{d:"m6 6 12 12"})]})})]})})})}m.TinyReactDialog=V,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-react-dialog",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.umd.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
20
21
|
"import": "./dist/index.es.js",
|
|
21
22
|
"require": "./dist/index.umd.js"
|
|
22
23
|
},
|