@yamada-ui/ripple 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Hirotomo Yamada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # @yamada-ui/ripple
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ $ pnpm add @yamada-ui/ripple
7
+ ```
8
+
9
+ or
10
+
11
+ ```sh
12
+ $ yarn add @yamada-ui/ripple
13
+ ```
14
+
15
+ or
16
+
17
+ ```sh
18
+ $ npm install @yamada-ui/ripple
19
+ ```
20
+
21
+ ## Contribution
22
+
23
+ Wouldn't you like to contribute? That's amazing! We have prepared a [contribution guide](./CONTRIBUTING.md) to assist you.
24
+
25
+ ## License
26
+
27
+ This package is licensed under the terms of the
28
+ [MIT license](https://github.com/hirotomoyamada/yamada-ui/blob/main/LICENSE).
@@ -0,0 +1,54 @@
1
+ // src/ripple.tsx
2
+ import { AnimatePresence, Motion } from "@yamada-ui/motion";
3
+ import { cx, handlerAll } from "@yamada-ui/utils";
4
+ import { Fragment, jsx } from "react/jsx-runtime";
5
+ var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
6
+ var Ripple = ({
7
+ className,
8
+ ripples,
9
+ onAnimationComplete,
10
+ onClear,
11
+ color = "currentColor",
12
+ style,
13
+ isDisabled,
14
+ ...rest
15
+ }) => {
16
+ if (isDisabled)
17
+ return null;
18
+ return /* @__PURE__ */ jsx(Fragment, { children: ripples.map(({ key, x, y, size }) => {
19
+ const duration = clamp(0.01 * size, 0.2, size > 100 ? 0.75 : 0.5);
20
+ return /* @__PURE__ */ jsx(AnimatePresence, { mode: "popLayout", children: /* @__PURE__ */ jsx(
21
+ Motion,
22
+ {
23
+ as: "span",
24
+ className: cx("ui-ripple", className),
25
+ initial: { transform: "scale(0)", opacity: 0.35 },
26
+ animate: { transform: "scale(2)", opacity: 0 },
27
+ exit: { opacity: 0 },
28
+ transition: { duration },
29
+ style: {
30
+ position: "absolute",
31
+ backgroundColor: color,
32
+ borderRadius: "100%",
33
+ transformOrigin: "center",
34
+ pointerEvents: "none",
35
+ zIndex: 10,
36
+ left: x,
37
+ top: y,
38
+ width: `${size}px`,
39
+ height: `${size}px`,
40
+ ...style
41
+ },
42
+ ...rest,
43
+ onAnimationComplete: handlerAll(
44
+ onAnimationComplete,
45
+ () => onClear(key)
46
+ )
47
+ }
48
+ ) }, key);
49
+ }) });
50
+ };
51
+
52
+ export {
53
+ Ripple
54
+ };
@@ -0,0 +1,28 @@
1
+ // src/use-ripple.ts
2
+ import { createId, handlerAll } from "@yamada-ui/utils";
3
+ import { useCallback, useState } from "react";
4
+ var useRipple = (props) => {
5
+ const [ripples, setRipples] = useState([]);
6
+ const onClick = useCallback((ev) => {
7
+ const trigger = ev.currentTarget;
8
+ const size = Math.max(trigger.clientWidth, trigger.clientHeight);
9
+ const rect = trigger.getBoundingClientRect();
10
+ setRipples((prev) => [
11
+ ...prev,
12
+ {
13
+ key: createId(prev.length.toString()),
14
+ size,
15
+ x: ev.clientX - rect.x - size / 2,
16
+ y: ev.clientY - rect.y - size / 2
17
+ }
18
+ ]);
19
+ }, []);
20
+ const onClear = useCallback((key) => {
21
+ setRipples((prev) => prev.filter((item) => item.key !== key));
22
+ }, []);
23
+ return { ripples, onClick: handlerAll(onClick, props.onClick), onClear };
24
+ };
25
+
26
+ export {
27
+ useRipple
28
+ };
@@ -0,0 +1,4 @@
1
+ export { Ripple, RippleProps } from './ripple.mjs';
2
+ export { RippleOptions, UseRippleProps, UseRippleReturn, useRipple } from './use-ripple.mjs';
3
+ import '@yamada-ui/motion';
4
+ import 'react';
@@ -0,0 +1,4 @@
1
+ export { Ripple, RippleProps } from './ripple.js';
2
+ export { RippleOptions, UseRippleProps, UseRippleReturn, useRipple } from './use-ripple.js';
3
+ import '@yamada-ui/motion';
4
+ import 'react';
package/dist/index.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Ripple: () => Ripple,
24
+ useRipple: () => useRipple
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/ripple.tsx
29
+ var import_motion = require("@yamada-ui/motion");
30
+ var import_utils = require("@yamada-ui/utils");
31
+ var import_jsx_runtime = require("react/jsx-runtime");
32
+ var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
33
+ var Ripple = ({
34
+ className,
35
+ ripples,
36
+ onAnimationComplete,
37
+ onClear,
38
+ color = "currentColor",
39
+ style,
40
+ isDisabled,
41
+ ...rest
42
+ }) => {
43
+ if (isDisabled)
44
+ return null;
45
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: ripples.map(({ key, x, y, size }) => {
46
+ const duration = clamp(0.01 * size, 0.2, size > 100 ? 0.75 : 0.5);
47
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_motion.AnimatePresence, { mode: "popLayout", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
48
+ import_motion.Motion,
49
+ {
50
+ as: "span",
51
+ className: (0, import_utils.cx)("ui-ripple", className),
52
+ initial: { transform: "scale(0)", opacity: 0.35 },
53
+ animate: { transform: "scale(2)", opacity: 0 },
54
+ exit: { opacity: 0 },
55
+ transition: { duration },
56
+ style: {
57
+ position: "absolute",
58
+ backgroundColor: color,
59
+ borderRadius: "100%",
60
+ transformOrigin: "center",
61
+ pointerEvents: "none",
62
+ zIndex: 10,
63
+ left: x,
64
+ top: y,
65
+ width: `${size}px`,
66
+ height: `${size}px`,
67
+ ...style
68
+ },
69
+ ...rest,
70
+ onAnimationComplete: (0, import_utils.handlerAll)(
71
+ onAnimationComplete,
72
+ () => onClear(key)
73
+ )
74
+ }
75
+ ) }, key);
76
+ }) });
77
+ };
78
+
79
+ // src/use-ripple.ts
80
+ var import_utils2 = require("@yamada-ui/utils");
81
+ var import_react = require("react");
82
+ var useRipple = (props) => {
83
+ const [ripples, setRipples] = (0, import_react.useState)([]);
84
+ const onClick = (0, import_react.useCallback)((ev) => {
85
+ const trigger = ev.currentTarget;
86
+ const size = Math.max(trigger.clientWidth, trigger.clientHeight);
87
+ const rect = trigger.getBoundingClientRect();
88
+ setRipples((prev) => [
89
+ ...prev,
90
+ {
91
+ key: (0, import_utils2.createId)(prev.length.toString()),
92
+ size,
93
+ x: ev.clientX - rect.x - size / 2,
94
+ y: ev.clientY - rect.y - size / 2
95
+ }
96
+ ]);
97
+ }, []);
98
+ const onClear = (0, import_react.useCallback)((key) => {
99
+ setRipples((prev) => prev.filter((item) => item.key !== key));
100
+ }, []);
101
+ return { ripples, onClick: (0, import_utils2.handlerAll)(onClick, props.onClick), onClear };
102
+ };
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ Ripple,
106
+ useRipple
107
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ Ripple
3
+ } from "./chunk-AY3JROH4.mjs";
4
+ import {
5
+ useRipple
6
+ } from "./chunk-V3W3PQD3.mjs";
7
+ export {
8
+ Ripple,
9
+ useRipple
10
+ };
@@ -0,0 +1,17 @@
1
+ import { MotionProps } from '@yamada-ui/motion';
2
+ import { Key, FC } from 'react';
3
+ import { RippleOptions } from './use-ripple.mjs';
4
+
5
+ type RippleProps = MotionProps<"span"> & {
6
+ /**
7
+ * If `true`, disable ripple effects when pressing a element.
8
+ *
9
+ * @default false
10
+ */
11
+ isDisabled?: boolean;
12
+ ripples: RippleOptions[];
13
+ onClear: (key: Key) => void;
14
+ };
15
+ declare const Ripple: FC<RippleProps>;
16
+
17
+ export { Ripple, type RippleProps };
@@ -0,0 +1,17 @@
1
+ import { MotionProps } from '@yamada-ui/motion';
2
+ import { Key, FC } from 'react';
3
+ import { RippleOptions } from './use-ripple.js';
4
+
5
+ type RippleProps = MotionProps<"span"> & {
6
+ /**
7
+ * If `true`, disable ripple effects when pressing a element.
8
+ *
9
+ * @default false
10
+ */
11
+ isDisabled?: boolean;
12
+ ripples: RippleOptions[];
13
+ onClear: (key: Key) => void;
14
+ };
15
+ declare const Ripple: FC<RippleProps>;
16
+
17
+ export { Ripple, type RippleProps };
package/dist/ripple.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/ripple.tsx
21
+ var ripple_exports = {};
22
+ __export(ripple_exports, {
23
+ Ripple: () => Ripple
24
+ });
25
+ module.exports = __toCommonJS(ripple_exports);
26
+ var import_motion = require("@yamada-ui/motion");
27
+ var import_utils = require("@yamada-ui/utils");
28
+ var import_jsx_runtime = require("react/jsx-runtime");
29
+ var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
30
+ var Ripple = ({
31
+ className,
32
+ ripples,
33
+ onAnimationComplete,
34
+ onClear,
35
+ color = "currentColor",
36
+ style,
37
+ isDisabled,
38
+ ...rest
39
+ }) => {
40
+ if (isDisabled)
41
+ return null;
42
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: ripples.map(({ key, x, y, size }) => {
43
+ const duration = clamp(0.01 * size, 0.2, size > 100 ? 0.75 : 0.5);
44
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_motion.AnimatePresence, { mode: "popLayout", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
45
+ import_motion.Motion,
46
+ {
47
+ as: "span",
48
+ className: (0, import_utils.cx)("ui-ripple", className),
49
+ initial: { transform: "scale(0)", opacity: 0.35 },
50
+ animate: { transform: "scale(2)", opacity: 0 },
51
+ exit: { opacity: 0 },
52
+ transition: { duration },
53
+ style: {
54
+ position: "absolute",
55
+ backgroundColor: color,
56
+ borderRadius: "100%",
57
+ transformOrigin: "center",
58
+ pointerEvents: "none",
59
+ zIndex: 10,
60
+ left: x,
61
+ top: y,
62
+ width: `${size}px`,
63
+ height: `${size}px`,
64
+ ...style
65
+ },
66
+ ...rest,
67
+ onAnimationComplete: (0, import_utils.handlerAll)(
68
+ onAnimationComplete,
69
+ () => onClear(key)
70
+ )
71
+ }
72
+ ) }, key);
73
+ }) });
74
+ };
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ Ripple
78
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ Ripple
3
+ } from "./chunk-AY3JROH4.mjs";
4
+ export {
5
+ Ripple
6
+ };
@@ -0,0 +1,19 @@
1
+ import React, { MouseEventHandler, Key } from 'react';
2
+
3
+ type RippleOptions = {
4
+ key: React.Key;
5
+ x: number;
6
+ y: number;
7
+ size: number;
8
+ };
9
+ type UseRippleProps<T extends any = HTMLElement> = {
10
+ onClick?: MouseEventHandler<T>;
11
+ };
12
+ declare const useRipple: <T extends unknown = HTMLElement>(props: UseRippleProps<T>) => {
13
+ ripples: RippleOptions[];
14
+ onClick: (event: React.MouseEvent<T, MouseEvent>) => void;
15
+ onClear: (key: Key) => void;
16
+ };
17
+ type UseRippleReturn = ReturnType<typeof useRipple>;
18
+
19
+ export { type RippleOptions, type UseRippleProps, type UseRippleReturn, useRipple };
@@ -0,0 +1,19 @@
1
+ import React, { MouseEventHandler, Key } from 'react';
2
+
3
+ type RippleOptions = {
4
+ key: React.Key;
5
+ x: number;
6
+ y: number;
7
+ size: number;
8
+ };
9
+ type UseRippleProps<T extends any = HTMLElement> = {
10
+ onClick?: MouseEventHandler<T>;
11
+ };
12
+ declare const useRipple: <T extends unknown = HTMLElement>(props: UseRippleProps<T>) => {
13
+ ripples: RippleOptions[];
14
+ onClick: (event: React.MouseEvent<T, MouseEvent>) => void;
15
+ onClear: (key: Key) => void;
16
+ };
17
+ type UseRippleReturn = ReturnType<typeof useRipple>;
18
+
19
+ export { type RippleOptions, type UseRippleProps, type UseRippleReturn, useRipple };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/use-ripple.ts
21
+ var use_ripple_exports = {};
22
+ __export(use_ripple_exports, {
23
+ useRipple: () => useRipple
24
+ });
25
+ module.exports = __toCommonJS(use_ripple_exports);
26
+ var import_utils = require("@yamada-ui/utils");
27
+ var import_react = require("react");
28
+ var useRipple = (props) => {
29
+ const [ripples, setRipples] = (0, import_react.useState)([]);
30
+ const onClick = (0, import_react.useCallback)((ev) => {
31
+ const trigger = ev.currentTarget;
32
+ const size = Math.max(trigger.clientWidth, trigger.clientHeight);
33
+ const rect = trigger.getBoundingClientRect();
34
+ setRipples((prev) => [
35
+ ...prev,
36
+ {
37
+ key: (0, import_utils.createId)(prev.length.toString()),
38
+ size,
39
+ x: ev.clientX - rect.x - size / 2,
40
+ y: ev.clientY - rect.y - size / 2
41
+ }
42
+ ]);
43
+ }, []);
44
+ const onClear = (0, import_react.useCallback)((key) => {
45
+ setRipples((prev) => prev.filter((item) => item.key !== key));
46
+ }, []);
47
+ return { ripples, onClick: (0, import_utils.handlerAll)(onClick, props.onClick), onClear };
48
+ };
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ useRipple
52
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ useRipple
3
+ } from "./chunk-V3W3PQD3.mjs";
4
+ export {
5
+ useRipple
6
+ };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@yamada-ui/ripple",
3
+ "version": "0.1.0",
4
+ "description": "Yamada UI ripple component",
5
+ "keywords": [],
6
+ "author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
7
+ "license": "MIT",
8
+ "main": "dist/index.js",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "sideEffects": false,
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/hirotomoyamada/yamada-ui",
19
+ "directory": "packages/components/ripple"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/hirotomoyamada/yamada-ui/issues"
23
+ },
24
+ "dependencies": {
25
+ "@yamada-ui/core": "0.13.0",
26
+ "@yamada-ui/motion": "0.4.19",
27
+ "@yamada-ui/utils": "0.3.3"
28
+ },
29
+ "devDependencies": {
30
+ "react": "^18.0.0",
31
+ "clean-package": "2.2.0"
32
+ },
33
+ "peerDependencies": {
34
+ "react": ">=18"
35
+ },
36
+ "clean-package": "../../../clean-package.config.json",
37
+ "tsup": {
38
+ "clean": true,
39
+ "target": "es2019",
40
+ "format": [
41
+ "cjs",
42
+ "esm"
43
+ ]
44
+ },
45
+ "module": "dist/index.mjs",
46
+ "types": "dist/index.d.ts",
47
+ "exports": {
48
+ ".": {
49
+ "types": "./dist/index.d.ts",
50
+ "import": "./dist/index.mjs",
51
+ "require": "./dist/index.js"
52
+ },
53
+ "./package.json": "./package.json"
54
+ },
55
+ "scripts": {
56
+ "dev": "pnpm build:fast -- --watch",
57
+ "build": "tsup src --dts",
58
+ "build:fast": "tsup src",
59
+ "clean": "rimraf dist .turbo",
60
+ "typecheck": "tsc --noEmit"
61
+ }
62
+ }