ehscan-react-components 0.1.4 → 0.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/dist/Button.d.ts +13 -0
- package/dist/Button.js +19 -0
- package/dist/Components.d.ts +2 -1
- package/dist/Components.js +5 -2
- package/dist/ExtButton.d.ts +13 -0
- package/dist/ExtButton.js +19 -0
- package/dist/tools/useRipple.d.ts +3 -0
- package/dist/tools/useRipple.js +21 -0
- package/package.json +1 -1
package/dist/Button.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
index?: string | number;
|
|
4
|
+
text?: string;
|
|
5
|
+
selected?: boolean;
|
|
6
|
+
addClass?: string;
|
|
7
|
+
notimeout?: boolean;
|
|
8
|
+
size?: 'sm' | 'md' | 'lg';
|
|
9
|
+
click?: (args?: any) => void;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
declare const Button: React.FC<Props>;
|
|
13
|
+
export default Button;
|
package/dist/Button.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useCallback } from "react";
|
|
3
|
+
import useRipple from "./tools/useRipple";
|
|
4
|
+
const Button = ({ index, text, selected, addClass, notimeout, size = 'md', click, children }) => {
|
|
5
|
+
const buttonRef = useRef(null);
|
|
6
|
+
const handleRipple = useRipple();
|
|
7
|
+
const handleButtonClick = useCallback((event) => {
|
|
8
|
+
handleRipple(event, buttonRef);
|
|
9
|
+
if (notimeout) {
|
|
10
|
+
click === null || click === void 0 ? void 0 : click(event);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
setTimeout(() => {
|
|
14
|
+
click === null || click === void 0 ? void 0 : click(event);
|
|
15
|
+
}, 200);
|
|
16
|
+
}, [notimeout, click, handleRipple]);
|
|
17
|
+
return (_jsx(_Fragment, { children: _jsxs("button", { type: "button", ref: buttonRef, onClick: handleButtonClick, className: `ext-btn ext-btn--primary ext-btn--${size} _ripple ${addClass !== null && addClass !== void 0 ? addClass : ''}`, "aria-pressed": selected, children: [children, text && _jsx("div", { className: "ext-btn-label", children: text })] }, index) }));
|
|
18
|
+
};
|
|
19
|
+
export default Button;
|
package/dist/Components.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import './style/button.css';
|
|
2
|
+
export declare const ExtButton: () => import("react/jsx-runtime").JSX.Element;
|
package/dist/Components.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
index?: string | number;
|
|
4
|
+
text?: string;
|
|
5
|
+
selected?: boolean;
|
|
6
|
+
addClass?: string;
|
|
7
|
+
notimeout?: boolean;
|
|
8
|
+
size?: 'sm' | 'md' | 'lg';
|
|
9
|
+
click?: (args?: any) => void;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
declare const ExtButton: React.FC<Props>;
|
|
13
|
+
export default ExtButton;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useCallback } from "react";
|
|
3
|
+
import useRipple from "./tools/useRipple";
|
|
4
|
+
const ExtButton = ({ index, text, selected, addClass, notimeout, size = 'md', click, children }) => {
|
|
5
|
+
const buttonRef = useRef(null);
|
|
6
|
+
const handleRipple = useRipple();
|
|
7
|
+
const handleButtonClick = useCallback((event) => {
|
|
8
|
+
handleRipple(event, buttonRef);
|
|
9
|
+
if (notimeout) {
|
|
10
|
+
click === null || click === void 0 ? void 0 : click(event);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
setTimeout(() => {
|
|
14
|
+
click === null || click === void 0 ? void 0 : click(event);
|
|
15
|
+
}, 200);
|
|
16
|
+
}, [notimeout, click, handleRipple]);
|
|
17
|
+
return (_jsx(_Fragment, { children: _jsxs("button", { type: "button", ref: buttonRef, onClick: handleButtonClick, className: `ext-btn ext-btn--primary ext-btn--${size} _ripple ${addClass !== null && addClass !== void 0 ? addClass : ''}`, "aria-pressed": selected, children: [children, text && _jsx("div", { className: "ext-btn-label", children: text })] }, index) }));
|
|
18
|
+
};
|
|
19
|
+
export default ExtButton;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
const useRipple = () => {
|
|
3
|
+
const handleRipple = useCallback((event, buttonRef) => {
|
|
4
|
+
const button = buttonRef.current;
|
|
5
|
+
if (!button)
|
|
6
|
+
return;
|
|
7
|
+
const rect = button.getBoundingClientRect();
|
|
8
|
+
const size = Math.max(rect.width, rect.height);
|
|
9
|
+
const x = event.clientX - rect.left - size / 2;
|
|
10
|
+
const y = event.clientY - rect.top - size / 2;
|
|
11
|
+
const ripple = document.createElement('span');
|
|
12
|
+
ripple.style.width = ripple.style.height = `${size}px`;
|
|
13
|
+
ripple.style.left = `${x}px`;
|
|
14
|
+
ripple.style.top = `${y}px`;
|
|
15
|
+
ripple.className = 'ripple';
|
|
16
|
+
button.appendChild(ripple);
|
|
17
|
+
setTimeout(() => ripple.remove(), 600);
|
|
18
|
+
}, []);
|
|
19
|
+
return handleRipple;
|
|
20
|
+
};
|
|
21
|
+
export default useRipple;
|