alpinejs-ripple 0.0.0-stage → 1.0.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 +174 -2
- package/dist/ripple.css +1 -0
- package/dist/ripple.esm.js +1 -0
- package/dist/ripple.min.js +1 -0
- package/package.json +22 -3
package/README.md
CHANGED
|
@@ -1,3 +1,175 @@
|
|
|
1
|
-
#
|
|
1
|
+
# alpinejs-ripple
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
A simple yet powerful alpinejs directive to add ripple effects to any element using the `::before` or `::after` css selectors. No new elements are added to the DOM making this very stable. Simply use the directive `x-ripple` on any HTML element.
|
|
8
|
+
|
|
9
|
+
The package is minimal and simple. We are using the following css classes so make sure you are not overwriting them by accident:
|
|
10
|
+
|
|
11
|
+
- `.ripple`
|
|
12
|
+
- `.ripple-before`
|
|
13
|
+
- `.ripple-after`
|
|
14
|
+
- `.ripple--active`
|
|
15
|
+
|
|
16
|
+
This package has been developed for [bellisUI](https://bellis-ui.com/docs/ripple) but it can be used standalone as it is just an alpinejs plugin.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
### With a CDN
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<script defer src="https://unpkg.com/alpinejs-ripple@latest/dist/ripple.min.js"></script>
|
|
24
|
+
<link rel="stylesheet" href="https://unpkg.com/alpinejs-ripple@latest/dist/ripple.css">
|
|
25
|
+
|
|
26
|
+
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### With a Package Manager
|
|
30
|
+
|
|
31
|
+
Choose whatever package manager you use.
|
|
32
|
+
|
|
33
|
+
```shell
|
|
34
|
+
npm install alpinejs-ripple
|
|
35
|
+
|
|
36
|
+
yarn add alpinejs-ripple
|
|
37
|
+
|
|
38
|
+
pnpm add alpinejs-ripple
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then load the Alpine plugin in your main javascript file.
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import Alpine from 'alpinejs'
|
|
45
|
+
import Ripple from 'alpinejs-ripple'
|
|
46
|
+
|
|
47
|
+
Alpine.plugin(Ripple)
|
|
48
|
+
|
|
49
|
+
Alpine.start()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
You can find a full example in the [index.html](./index.html) file.
|
|
55
|
+
|
|
56
|
+
<p align="center">
|
|
57
|
+
<img alt="A default example of the ripple effect on a button click." src="./media/preview.gif" height="128" title="Default example">
|
|
58
|
+
</p>
|
|
59
|
+
|
|
60
|
+
### Default usage
|
|
61
|
+
|
|
62
|
+
We are using sensible defaults that look good out of the box.
|
|
63
|
+
|
|
64
|
+
```html
|
|
65
|
+
<button x-ripple></button>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Custom duration
|
|
69
|
+
|
|
70
|
+
You can customize the duration in seconds or milliseconds.
|
|
71
|
+
|
|
72
|
+
```html
|
|
73
|
+
<button x-ripple.duration.2s>2 Seconds</button>
|
|
74
|
+
<button x-ripple.duration.1_5s>1.5 Seconds</button>
|
|
75
|
+
<button x-ripple.duration.250ms>250 Milliseconds</button>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Custom radius
|
|
79
|
+
|
|
80
|
+
You can customize the border radius in px, rem or %.
|
|
81
|
+
|
|
82
|
+
```html
|
|
83
|
+
<button x-ripple.radius.0px>0 Pixel</button>
|
|
84
|
+
<button x-ripple.radius.3rem>3 Rem</button>
|
|
85
|
+
<button x-ripple.radius.25%>25 Percent</button>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Custom color
|
|
89
|
+
|
|
90
|
+
You can customize the color with builtin colors, hex or variables.
|
|
91
|
+
|
|
92
|
+
```html
|
|
93
|
+
<button x-ripple.color.red>Builtin color</button>
|
|
94
|
+
<button x-ripple.color.#f00>Short hex</button>
|
|
95
|
+
<button x-ripple.color.#ff0000>Long hex</button>
|
|
96
|
+
<button x-ripple.color.--some-color>Variable</button>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Custom opacity
|
|
100
|
+
|
|
101
|
+
You can customize the opacity.
|
|
102
|
+
|
|
103
|
+
```html
|
|
104
|
+
<button x-ripple.opacity.0>Invisible</button>
|
|
105
|
+
<button x-ripple.opacity.0_5>50% Visible</button>
|
|
106
|
+
<button x-ripple.opacity.1>100% Visible</button>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Custom animation timing
|
|
110
|
+
|
|
111
|
+
You can customize the animation timing function.
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<button x-ripple.timing.ease>ease</button>
|
|
115
|
+
<button x-ripple.timing.ease-in>ease-in</button>
|
|
116
|
+
<button x-ripple.timing.ease-out>ease-out</button>
|
|
117
|
+
<button x-ripple.timing.ease-in-out>ease-in-out</button>
|
|
118
|
+
<button x-ripple.timing.linear>linear</button>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Using ::before instead of ::after
|
|
122
|
+
|
|
123
|
+
By default the ripple is placed in the ::after pseudo-element. If that is already used by your element you can switch to ::before instead.
|
|
124
|
+
|
|
125
|
+
```html
|
|
126
|
+
<button x-ripple.before>ease</button>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
### Customizing via css variables
|
|
131
|
+
|
|
132
|
+
All modifiers can also be set via css by setting the respective variable. This allows you to set global defaults or regional ones.
|
|
133
|
+
|
|
134
|
+
Global default:
|
|
135
|
+
```css
|
|
136
|
+
* {
|
|
137
|
+
--ripple-duration: 2s;
|
|
138
|
+
--ripple-radius: 100px;
|
|
139
|
+
--ripple-color: red;
|
|
140
|
+
--ripple-timing: linear;
|
|
141
|
+
--ripple-opacity: 1;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Regional default:
|
|
146
|
+
```html
|
|
147
|
+
<div style="
|
|
148
|
+
--ripple-duration: 2s; --ripple-radius: 100px; --ripple-color: red;
|
|
149
|
+
--ripple-timing: linear; --ripple-opacity: 1;">
|
|
150
|
+
...
|
|
151
|
+
<button x-ripple>Some buton</button>
|
|
152
|
+
...
|
|
153
|
+
</div>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Local:
|
|
157
|
+
```html
|
|
158
|
+
<button x-ripple style="
|
|
159
|
+
--ripple-duration: 2s; --ripple-radius: 100px; --ripple-color: red;
|
|
160
|
+
--ripple-timing: linear; --ripple-opacity: 1;">
|
|
161
|
+
Some buton
|
|
162
|
+
</button>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
1. Clone the repository.
|
|
168
|
+
2. Run `npm install`.
|
|
169
|
+
3. Make whatever changes you want.
|
|
170
|
+
4. Run `npm run build` to build your changed files.
|
|
171
|
+
5. Either use the build files directly or use something like [vercel/serve](https://www.npmjs.com/package/serve) to locally test your changes.
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT
|
package/dist/ripple.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ripple{position:relative;overflow:hidden;-webkit-tap-highlight-color:transparent}.ripple-before:before,.ripple-after:after{content:"";position:absolute;left:var(--ripple-x, 50%);top:var(--ripple-y, 50%);width:var(--ripple-d, 200px);height:var(--ripple-d, 200px);border-radius:var(--ripple-radius, 50%);background:var(--ripple-color, currentColor);opacity:0;transform:translate(-50%,-50%) scale(0);pointer-events:none;transition:none}.ripple-before.ripple--active:before,.ripple-after.ripple--active:after{animation:ripple var(--ripple-duration, .6s) var(--ripple-timing, cubic-bezier(.4, 0, .2, 1)) forwards}@keyframes ripple{0%{transform:translate(-50%,-50%) scale(0);opacity:var(--ripple-opacity, .35)}to{transform:translate(-50%,-50%) scale(1);opacity:0}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function d(u){u.directive("ripple",(t,{modifiers:f},{cleanup:v})=>{function y(e){let p=new Set(["duration","radius","color","timing","opacity"]),r={},c=!1;for(let o=0;o<e.length;o++){if(e[o]==="before"){c=!0;continue}p.has(e[o])&&o+1<e.length&&(r[e[o]]=e[o+1],o++)}return{options:r,useBefore:c}}t.classList.add("ripple");let{options:i,useBefore:L}=y(f);if(t.classList.add(L?"ripple-before":"ripple-after"),i.duration&&t.style.setProperty("--ripple-duration",i.duration.replace(/_/g,".")),i.radius&&t.style.setProperty("--ripple-radius",i.radius.replace(/_/g,".")),i.color){let e=i.color.startsWith("--")?`var(${i.color})`:i.color;t.style.setProperty("--ripple-color",e)}i.timing&&t.style.setProperty("--ripple-timing",i.timing),i.opacity&&t.style.setProperty("--ripple-opacity",i.opacity.replace(/_/g,"."));let n,s,a;function l(e,p){let r=t.getBoundingClientRect();t.style.setProperty("--ripple-x",`${e===null?r.width/2:e-r.left}px`),t.style.setProperty("--ripple-y",`${p===null?r.height/2:p-r.top}px`),t.style.setProperty("--ripple-d",`${Math.hypot(r.width,r.height)*2}px`),t.classList.remove("ripple--active"),t.offsetWidth,t.classList.add("ripple--active")}n=e=>{e.button===0&&l(e.clientX,e.clientY)},s=e=>{e.detail===0&&l(null,null)},a=()=>{t.classList.remove("ripple--active")},t.addEventListener("pointerdown",n),t.addEventListener("click",s),t.addEventListener("animationend",a),v(()=>{t.removeEventListener("pointerdown",n),t.removeEventListener("click",s),t.removeEventListener("animationend",a),t.classList.remove("ripple--active"),t.classList.remove("ripple"),t.classList.remove("ripple-before"),t.classList.remove("ripple-after")})})}var m=d;export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{function d(u){u.directive("ripple",(t,{modifiers:v},{cleanup:f})=>{function y(e){let n=new Set(["duration","radius","color","timing","opacity"]),r={},c=!1;for(let o=0;o<e.length;o++){if(e[o]==="before"){c=!0;continue}n.has(e[o])&&o+1<e.length&&(r[e[o]]=e[o+1],o++)}return{options:r,useBefore:c}}t.classList.add("ripple");let{options:i,useBefore:L}=y(v);if(t.classList.add(L?"ripple-before":"ripple-after"),i.duration&&t.style.setProperty("--ripple-duration",i.duration.replace(/_/g,".")),i.radius&&t.style.setProperty("--ripple-radius",i.radius.replace(/_/g,".")),i.color){let e=i.color.startsWith("--")?`var(${i.color})`:i.color;t.style.setProperty("--ripple-color",e)}i.timing&&t.style.setProperty("--ripple-timing",i.timing),i.opacity&&t.style.setProperty("--ripple-opacity",i.opacity.replace(/_/g,"."));let p,s,a;function l(e,n){let r=t.getBoundingClientRect();t.style.setProperty("--ripple-x",`${e===null?r.width/2:e-r.left}px`),t.style.setProperty("--ripple-y",`${n===null?r.height/2:n-r.top}px`),t.style.setProperty("--ripple-d",`${Math.hypot(r.width,r.height)*2}px`),t.classList.remove("ripple--active"),t.offsetWidth,t.classList.add("ripple--active")}p=e=>{e.button===0&&l(e.clientX,e.clientY)},s=e=>{e.detail===0&&l(null,null)},a=()=>{t.classList.remove("ripple--active")},t.addEventListener("pointerdown",p),t.addEventListener("click",s),t.addEventListener("animationend",a),f(()=>{t.removeEventListener("pointerdown",p),t.removeEventListener("click",s),t.removeEventListener("animationend",a),t.classList.remove("ripple--active"),t.classList.remove("ripple"),t.classList.remove("ripple-before"),t.classList.remove("ripple-after")})})}document.addEventListener("alpine:init",()=>window.Alpine.plugin(d));})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alpinejs-ripple",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "DESCRIPTION",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Alpine",
|
|
7
|
+
"Alpine JS",
|
|
8
|
+
"Alpine JS Plugin",
|
|
9
|
+
"Alpine JS Plugins",
|
|
10
|
+
"Ripple",
|
|
11
|
+
"Ripple Effect",
|
|
12
|
+
"CSS"
|
|
13
|
+
],
|
|
14
|
+
"module": "dist/ripple.esm.js",
|
|
15
|
+
"unpkg": "dist/ripple.min.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "node scripts/build.js"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"esbuild": "^0.25.0"
|
|
24
|
+
}
|
|
6
25
|
}
|