ehscan-react-components 0.1.4 → 0.1.5

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.
@@ -1 +1,2 @@
1
- export declare const myComp: () => boolean;
1
+ import './style/button.css';
2
+ export declare const myComp: () => import("react/jsx-runtime").JSX.Element;
@@ -1,3 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import ExtButton from './ExtButton';
3
+ import './style/button.css';
1
4
  export const myComp = () => {
2
- return true;
5
+ return _jsx(ExtButton, {});
3
6
  };
@@ -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,3 @@
1
+ import { MouseEvent } from 'react';
2
+ declare const useRipple: () => (event: MouseEvent<HTMLElement>, buttonRef: React.RefObject<HTMLElement>) => void;
3
+ export default useRipple;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ehscan-react-components",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "components",
5
5
  "main": "dist/Components.js",
6
6
  "types": "dist/Components.d.ts",