@zuzjs/ui 0.5.0 → 0.5.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/dist/comps/drawer.js +6 -2
- package/dist/funs/index.d.ts +1 -1
- package/dist/funs/index.js +23 -1
- package/package.json +1 -1
package/dist/comps/drawer.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
3
3
|
import With from "./base";
|
|
4
4
|
import { DRAWER_SIDE, TRANSITION_CURVES, TRANSITIONS } from "../types/enums";
|
|
5
5
|
const Drawer = forwardRef((props, ref) => {
|
|
6
6
|
const { as, from, speed, children, prerender, ...rest } = props;
|
|
7
|
+
const [render, setRender] = useState(undefined == prerender ? true : prerender);
|
|
7
8
|
const [visible, setVisible] = useState(false);
|
|
8
9
|
const divRef = useRef(null);
|
|
9
10
|
const [content, setContent] = useState(children);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
setContent(children);
|
|
13
|
+
}, [children]);
|
|
10
14
|
const style = useMemo(() => {
|
|
11
15
|
switch (from) {
|
|
12
16
|
case DRAWER_SIDE.Left:
|
|
@@ -44,6 +48,6 @@ const Drawer = forwardRef((props, ref) => {
|
|
|
44
48
|
when: visible,
|
|
45
49
|
curve: TRANSITION_CURVES.EaseInOut,
|
|
46
50
|
duration: speed || .5,
|
|
47
|
-
}, ...rest, children: [from == DRAWER_SIDE.Top || from == DRAWER_SIDE.Bottom ? _jsx(With, { className: "drawer-handle" }) : null, visible
|
|
51
|
+
}, ...rest, children: [from == DRAWER_SIDE.Top || from == DRAWER_SIDE.Bottom ? _jsx(With, { className: "drawer-handle" }) : null, render ? content : visible ? content : null] })] });
|
|
48
52
|
});
|
|
49
53
|
export default Drawer;
|
package/dist/funs/index.d.ts
CHANGED
|
@@ -35,4 +35,4 @@ export declare const withTime: (fun: (...args: any[]) => any) => {
|
|
|
35
35
|
export declare const time: (stamp?: number, format?: string) => string;
|
|
36
36
|
export declare const arrayRand: (arr: any[]) => any;
|
|
37
37
|
export declare const formatNumber: ({ number, locale, style, decimal, currency }: FormatNumberParams) => string;
|
|
38
|
-
export declare const copyToClipboard: (text: string) => Promise<
|
|
38
|
+
export declare const copyToClipboard: (text: string) => Promise<unknown>;
|
package/dist/funs/index.js
CHANGED
|
@@ -190,4 +190,26 @@ export const formatNumber = ({ number, locale = 'en-US', style = `decimal`, deci
|
|
|
190
190
|
maximumFractionDigits: +number % 1 > 0 ? 2 : 0
|
|
191
191
|
}).format(+number);
|
|
192
192
|
};
|
|
193
|
-
export const copyToClipboard = (text) =>
|
|
193
|
+
export const copyToClipboard = (text) => {
|
|
194
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
195
|
+
return navigator.clipboard.writeText(text);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
const textarea = document.createElement("textarea");
|
|
200
|
+
textarea.value = text;
|
|
201
|
+
textarea.style.position = "fixed";
|
|
202
|
+
document.body.appendChild(textarea);
|
|
203
|
+
textarea.focus();
|
|
204
|
+
textarea.select();
|
|
205
|
+
try {
|
|
206
|
+
document.execCommand("copy");
|
|
207
|
+
resolve(`Copied to clipboard`);
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
reject(err);
|
|
211
|
+
}
|
|
212
|
+
document.body.removeChild(textarea);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
};
|