├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── config.yml
│ ├── feature.yml
│ └── bug.yml
├── SECURITY.md
├── PULL_REQUEST_TEMPLATE.md
├── workflows
│ ├── markdown-normalize.yml
│ ├── update-changelog.yml
│ └── dependabot-auto-merge.yml
├── dependabot.yml
└── CONTRIBUTING.md
├── bin
├── build.sh
└── setup.sh
├── docs
├── usage
│ ├── _index.md
│ ├── configuration.md
│ ├── x-ripple-focus.md
│ ├── global-customization.md
│ └── x-ripple.md
├── _index.md
├── changelog.md
├── requirements.md
├── questions-and-issues.md
├── introduction.md
└── installation.md
├── .npmignore
├── .gitignore
├── .editorconfig
├── src
├── js
│ ├── utils
│ │ ├── keydown.js
│ │ ├── will-have-mouse-up-event.js
│ │ ├── attributes.js
│ │ ├── to-styles.js
│ │ ├── index.js
│ │ ├── config.js
│ │ ├── modifiers.js
│ │ └── ripple.js
│ ├── ripple.js
│ └── directives
│ │ ├── focus.js
│ │ └── click.js
└── css
│ └── styles.css
├── rollup.config.js
├── dist
├── alpine-ripple.css
├── alpine-ripple.js
└── alpine-ripple.js.map
├── package.json
├── LICENSE.md
├── CHANGELOG.md
└── README.md
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: rawilk
2 |
--------------------------------------------------------------------------------
/bin/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | npm run build
4 |
--------------------------------------------------------------------------------
/bin/setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | npm install
4 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: true
2 |
--------------------------------------------------------------------------------
/docs/usage/_index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Usage
3 | sort: 1
4 | ---
5 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .editorconfig
2 | .github/
3 | .idea
4 | bin/
5 | docs/
6 | rollup.config.js
7 |
--------------------------------------------------------------------------------
/.github/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | If you discover any security related issues, please email randall@randallwilk.dev instead of using the issue tracker.
4 |
--------------------------------------------------------------------------------
/docs/_index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: v1
3 | slogan: Ripple effect (materialize) for Alpine.js.
4 | githubUrl: https://github.com/rawilk/alpine-ripple
5 | branch: main
6 | ---
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | node_modules/
3 | *.log
4 |
5 | # OS generated files
6 | .DS_Store
7 | .DS_Store?
8 | ._*
9 | .Spotlight-V100
10 | .Trashes
11 | ehthumbs.db
12 | Thumbs.db
13 |
--------------------------------------------------------------------------------
/docs/changelog.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Changelog
3 | sort: 5
4 | ---
5 |
6 | All notable changes for laravel-form-components are documented [on GitHub](https://github.com/rawilk/alpine-ripple/blob/main/CHANGELOG.md).
7 |
--------------------------------------------------------------------------------
/docs/requirements.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Requirements
3 | sort: 2
4 | ---
5 |
6 | ## General Requirements
7 |
8 | - Alpine.js `v3.x`
9 | - Tailwind CSS (only required if you want to use custom color classes on the directive)
10 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_size = 4
6 | indent_style = space
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
--------------------------------------------------------------------------------
/src/js/utils/keydown.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Check if the keydown event is the enter key or the space bar.
3 | *
4 | * @param {KeyboardEvent} event
5 | * @returns {boolean}
6 | */
7 | export const isEnterOrSpace = event => event.key === 'Enter' || event.key === ' ';
8 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | 1️⃣ Is this something that is wanted/needed? Did you create an issue / discussion about it first?
2 |
3 | 2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.
4 |
5 | 3️⃣ Does it include tests, if possible? (Not a deal-breaker, just a nice-to-have)
6 |
7 | 4️⃣ Please include a thorough description of the improvement and reasons why it's useful.
8 |
9 | 5️⃣ Thanks for contributing! 🙌
10 |
--------------------------------------------------------------------------------
/src/js/utils/will-have-mouse-up-event.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Some events, such as a right click or ctrl + left click won't trigger a mouseup event,
3 | * so we need to prevent the ripple from being added in those cases.
4 | *
5 | * @param {MouseEvent} event
6 | * @returns {boolean}
7 | */
8 | export default event => {
9 | if (event.ctrlKey) {
10 | return false;
11 | }
12 |
13 | return event.button === 0 || event.button === 1;
14 | };
15 |
--------------------------------------------------------------------------------
/src/js/utils/attributes.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Get an attribute from an element that starts with a string.
3 | *
4 | * @param {HTMLElement} el
5 | * @param {string} startsWith
6 | * @returns {object|null}
7 | */
8 | export const getAttributeThatStartsWith = (el, startsWith) => {
9 | for (const attr of el.attributes) {
10 | if (attr.name.startsWith(startsWith)) {
11 | return attr;
12 | }
13 | }
14 |
15 | return null;
16 | };
17 |
--------------------------------------------------------------------------------
/src/js/utils/to-styles.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Convert an object of style properties to a string of CSS.
3 | *
4 | * @param {object} styles
5 | * @returns {string}
6 | */
7 | export default styles => Object.entries(styles).map(([key, value]) => `${formatStyleKey(key)}: ${value}`).join(';');
8 |
9 | /**
10 | * convert a style key to a css property.
11 | *
12 | * @param {string} key
13 | * @returns {string}
14 | */
15 | const formatStyleKey = key => key.replace(/([A-Z])/g, '-$1').toLowerCase();
16 |
--------------------------------------------------------------------------------
/docs/questions-and-issues.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Questions & Issues
3 | sort: 4
4 | ---
5 |
6 | Find yourself stuck using this package? Found a bug? Do you have general questions or suggestions for improving this package?
7 | Feel free to [create an issue on GitHub](https://github.com/rawilk/alpine-ripple/issues), and I'll try to address it as soon as possible.
8 |
9 | > {note} If you've found a bug regarding security please email [randall@randallwilk.dev](mailto:randall@randallwilk.dev) instead of using the issue tracker.
10 |
--------------------------------------------------------------------------------
/.github/workflows/markdown-normalize.yml:
--------------------------------------------------------------------------------
1 | name: Normalize Markdown
2 |
3 | on:
4 | push:
5 | paths:
6 | - "*.md"
7 |
8 | jobs:
9 | normalize:
10 | timeout-minutes: 1
11 | runs-on: ubuntu-latest
12 | steps:
13 | - name: Git checkout
14 | uses: actions/checkout@v4
15 |
16 | - name: Prettify markdown
17 | uses: creyD/prettier_action@v4.6
18 | with:
19 | prettier_options: --write **/*.md
20 |
--------------------------------------------------------------------------------
/src/js/utils/index.js:
--------------------------------------------------------------------------------
1 | export { getAttributeThatStartsWith } from './attributes';
2 | export { addConfigClassToElement, configClassToSelector, removeConfigClassFromElement } from './config';
3 | export { isEnterOrSpace } from './keydown';
4 | export { getCustomColorFromModifiers } from './modifiers';
5 | export { getCustomRadiusFromModifiers } from './modifiers';
6 | export { startRipple } from './ripple';
7 | export { default as toStyles } from './to-styles';
8 | export { default as willHaveAMouseUpEvent } from './will-have-mouse-up-event';
9 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # Please see the documentation for all configuration options:
2 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3 |
4 | version: 2
5 | updates:
6 |
7 | - package-ecosystem: "github-actions"
8 | directory: "/"
9 | schedule:
10 | interval: "weekly"
11 | labels:
12 | - "dependencies"
13 |
14 | - package-ecosystem: "npm"
15 | directory: "/"
16 | schedule:
17 | interval: "weekly"
18 | commit-message:
19 | prefix: "NPM"
20 | labels:
21 | - "dependencies"
22 | - "npm"
23 |
--------------------------------------------------------------------------------
/docs/introduction.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Introduction
3 | sort: 1
4 | ---
5 |
6 | ## Introduction
7 |
8 | `alpine-ripple` is a simple Alpine.js plugin that adds a ripple effect to any element with an alpine directive `x-ripple`. The most common use case
9 | is adding a ripple effect to a button when it is clicked on.
10 |
11 | ```html
12 |
13 | ```
14 |
15 | ## Alternatives
16 |
17 | Currently, there doesn't seem to be many alternatives, however more can be added here if they are found.
18 |
19 | - [alHasandev/tailwind-button](https://github.com/alHasandev/tailwind-button)
20 |
21 | ## Disclaimer
22 |
23 | This package is not affiliated with, maintained, authorized, endorsed or sponsored by Alpine.js or Tailwind CSS or any of its affiliates.
24 |
--------------------------------------------------------------------------------
/src/js/utils/config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Convert a space separated class string to a valid css selector.
3 | *
4 | * @param {string} configClass
5 | * @returns {string}
6 | */
7 | export const configClassToSelector = configClass => `.${configClass.replace(' ', '.')}`;
8 |
9 | /**
10 | * Add a space separated class string to an element.
11 | *
12 | * @param {HTMLElement} el
13 | * @param {string} configClass
14 | */
15 | export const addConfigClassToElement = (el, configClass) => configClass.split(' ').forEach(c => el.classList.add(c));
16 |
17 | /**
18 | * Remove a space separated class string from an element.
19 | *
20 | * @param {HTMLElement} el
21 | * @param {string} configClass
22 | */
23 | export const removeConfigClassFromElement = (el, configClass) => configClass.split(' ').forEach(c => el.classList.remove(c));
24 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature.yml:
--------------------------------------------------------------------------------
1 | name: Feature Request
2 | description: Propose a new feature for laravel-settings
3 | title: "[Feature Request]: "
4 | labels: [feature request]
5 | body:
6 | - type: markdown
7 | attributes:
8 | value: |
9 | Thanks for proposing a new feature for alpine-ripple!
10 | - type: textarea
11 | id: feature-description
12 | attributes:
13 | label: Feature Description
14 | description: How should this feature look like?
15 | validations:
16 | required: true
17 | - type: textarea
18 | id: valuable
19 | attributes:
20 | label: Is this feature valuable for other users as well and why?
21 | description: We want to build software that provides a great experience for all of us.
22 |
--------------------------------------------------------------------------------
/.github/workflows/update-changelog.yml:
--------------------------------------------------------------------------------
1 | name: "Update Changelog"
2 |
3 | on:
4 | release:
5 | types: [released]
6 |
7 | jobs:
8 | update:
9 | runs-on: ubuntu-latest
10 |
11 | steps:
12 | - name: Checkout code
13 | uses: actions/checkout@v4
14 | with:
15 | ref: main
16 |
17 | - name: Update Changelog
18 | uses: stefanzweifel/changelog-updater-action@v1
19 | with:
20 | latest-version: ${{ github.event.release.name }}
21 | release-notes: ${{ github.event.release.body }}
22 |
23 | - name: Commit updated CHANGELOG
24 | uses: stefanzweifel/git-auto-commit-action@v5
25 | with:
26 | branch: main
27 | commit_message: Update CHANGELOG
28 | file_pattern: CHANGELOG.md
29 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import babel from 'rollup-plugin-babel';
2 | import filesize from 'rollup-plugin-filesize';
3 | import { nodeResolve } from '@rollup/plugin-node-resolve';
4 | import css from 'rollup-plugin-import-css';
5 |
6 | export default {
7 | input: 'builds/cdn.js',
8 | output: [
9 | {
10 | name: 'AlpineRipple',
11 | file: 'dist/alpine-ripple.js',
12 | format: 'umd',
13 | sourcemap: true,
14 | compact: true,
15 | minifyInternalExports: true,
16 | }
17 | ],
18 | plugins: [
19 | nodeResolve(),
20 | filesize(),
21 | css({
22 | minify: true,
23 | }),
24 | babel({
25 | babelrc: false,
26 | exclude: 'node_modules/**',
27 | presets: [
28 | [
29 | '@babel/preset-env',
30 | {
31 | targets: {
32 | node: 'current',
33 | },
34 | },
35 | ],
36 | ],
37 | }),
38 | ],
39 | };
40 |
--------------------------------------------------------------------------------
/docs/installation.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Installation
3 | sort: 3
4 | ---
5 |
6 | ## Installation
7 |
8 | The package can be installed through npm or by using a CDN.
9 |
10 | ### NPM
11 |
12 | ```bash
13 | npm i -S @wilkr/alpine-ripple
14 | ```
15 |
16 | Add the `x-ripple` and `x-ripple-focus` directives to your project by importing the package.
17 |
18 | ```js
19 | import Alpine from "alpinejs";
20 | import Ripple from "@wilkr/alpine-ripple";
21 |
22 | Alpine.plugin(Ripple);
23 |
24 | window.Alpine = Alpine;
25 | window.Alpine.start();
26 | ```
27 |
28 | Import the package styles into your CSS.
29 |
30 | ```css
31 | @import "@wilkr/alpine-ripple/dist/alpine-ripple.css";
32 | ```
33 |
34 | ### CDN
35 |
36 | If CDNs are more your thing, you can include the following `
47 | ```
48 |
--------------------------------------------------------------------------------
/dist/alpine-ripple.css:
--------------------------------------------------------------------------------
1 | :root{--ripple-color:#fff;--ripple-radius:9999px;--ripple-duration:600ms;--ripple-timing-function:linear;--ripple-focus-duration:2500ms;--ripple-focus-timing-function:ease-in-out;--ripple-focus-delay:200ms;}.ripple{position:absolute;top:0;left:0;bottom:0;right:0;overflow:hidden;pointer-events:none;border-radius:inherit;}.ripple span{position:absolute;border-radius:var(--ripple-radius);opacity:0.5;background:var(--ripple-color);transform:scale(0);animation:ripple var(--ripple-duration) var(--ripple-timing-function);}.ripple-focus{overflow:hidden;pointer-events:none;position:absolute;z-index:0;border-radius:inherit;inset:0;}.ripple-focus-child{position:absolute;opacity:0.3;border-radius:50%;background:var(--ripple-focus-color,var(--ripple-color));transform:scale(1);animation:ripple-pulsate var(--ripple-focus-duration) var(--ripple-focus-timing-function) infinite var(--ripple-focus-delay);}.ripple-focus-child > span{position:absolute;top:0;left:0;display:block;width:100%;height:100%;border-radius:50%;}@keyframes ripple{to{transform:scale(4);opacity:0;}}@keyframes ripple-pulsate{0%{transform:scale(1);}50%{transform:scale(.92);}100%{transform:scale(1);}}
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@wilkr/alpine-ripple",
3 | "version": "1.1.2",
4 | "description": "Ripple effect (materialize) for Alpine.js.",
5 | "main": "src/js/ripple.js",
6 | "scripts": {
7 | "build": "rollup -c",
8 | "watch": "rollup -c -w"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "git+https://github.com/rawilk/alpine-ripple.git"
13 | },
14 | "author": "Randall Wilk ",
15 | "license": "MIT",
16 | "bugs": {
17 | "url": "https://github.com/rawilk/alpine-ripple/issues"
18 | },
19 | "homepage": "https://github.com/rawilk/alpine-ripple#readme",
20 | "keywords": [
21 | "Alpine.js",
22 | "Alpine",
23 | "ripple",
24 | "materialize"
25 | ],
26 | "devDependencies": {
27 | "@babel/core": "^7.20.5",
28 | "@babel/preset-env": "^7.20.2",
29 | "@rollup/plugin-node-resolve": "^16.0.1",
30 | "rollup": "^4.36.0",
31 | "rollup-plugin-babel": "^4.4.0",
32 | "rollup-plugin-filesize": "^10.0.0",
33 | "rollup-plugin-import-css": "^3.1.0"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) Randall Wilk
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
13 | all 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
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/docs/usage/configuration.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Configuration
3 | sort: 4
4 | ---
5 |
6 | ## Introduction
7 |
8 | If you are using the [npm installation](/docs/alpine-ripple/{version}/installation#user-content-npm) method for this package, you can use the `Ripple.configure()` method to set configuration options for the package.
9 | In the example below, we will show the configuration options you may set, separated out by directive.
10 |
11 | ```js
12 | import Ripple from "@wilkr/alpine-ripple";
13 |
14 | Alpine.plugin(
15 | Ripple.configure({
16 | /**
17 | * x-ripple
18 | */
19 |
20 | // Specify your own class(es) for the ripple element.
21 | class: "ripple",
22 |
23 | // Specify how long the ripple element should remain on the page
24 | // after the animation has finished.
25 | removeTimeout: 1000,
26 |
27 | /**
28 | * x-ripple-focus
29 | */
30 |
31 | // Specify your own class(es) for the ripple focus element.
32 | focusClass: "ripple-focus",
33 |
34 | // Specify your own class(es) for the root element when it is focused.
35 | // The directive will use this class to determine when the element is focused.
36 | focusedClass: "ripple-focus-active",
37 | })
38 | );
39 | ```
40 |
--------------------------------------------------------------------------------
/.github/workflows/dependabot-auto-merge.yml:
--------------------------------------------------------------------------------
1 | name: dependabot-auto-merge
2 | on: pull_request_target
3 |
4 | permissions:
5 | pull-requests: write
6 | contents: write
7 |
8 | jobs:
9 | dependabot:
10 | runs-on: ubuntu-latest
11 | if: ${{ github.actor == 'dependabot[bot]' }}
12 | steps:
13 |
14 | - name: Dependabot metadata
15 | id: metadata
16 | uses: dependabot/fetch-metadata@v2.4.0
17 | with:
18 | github-token: "${{ secrets.GITHUB_TOKEN }}"
19 |
20 | - name: Auto-merge Dependabot PRs for semver-minor updates
21 | if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-minor' }}
22 | run: gh pr merge --auto --merge "$PR_URL"
23 | env:
24 | PR_URL: ${{ github.event.pull_request.html_url }}
25 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26 |
27 | - name: Auto-merge Dependabot PRs for semver-patch updates
28 | if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-patch' }}
29 | run: gh pr merge --auto --merge "$PR_URL"
30 | env:
31 | PR_URL: ${{ github.event.pull_request.html_url }}
32 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33 |
--------------------------------------------------------------------------------
/src/js/ripple.js:
--------------------------------------------------------------------------------
1 | import rippleClick from './directives/click';
2 | import rippleFocus from './directives/focus';
3 |
4 | /**
5 | * Configuration options for the ripple directives.
6 | *
7 | * @type {{rippleClass: string, removeTimeout: number, focusClass: string, focusedClass: string}}
8 | */
9 | const rippleConfig = {
10 | rippleClass: 'ripple',
11 | removeTimeout: 1000,
12 | focusClass: 'ripple-focus',
13 | focusedClass: 'ripple-focus-active',
14 | };
15 |
16 | function Ripple(Alpine) {
17 | rippleClick(Alpine, rippleConfig);
18 | rippleFocus(Alpine, rippleConfig);
19 | }
20 |
21 | Ripple.configure = config => {
22 | if (config.hasOwnProperty('class') && typeof config.class === 'string') {
23 | rippleConfig.rippleClass = config.class;
24 | }
25 |
26 | if (config.hasOwnProperty('removeTimeout') && typeof config.removeTimeout === 'number') {
27 | rippleConfig.removeTimeout = config.removeTimeout;
28 | }
29 |
30 | if (config.hasOwnProperty('focusClass') && typeof config.focusClass === 'string') {
31 | rippleConfig.focusClass = config.focusClass;
32 | }
33 |
34 | if (config.hasOwnProperty('focusedClass') && typeof config.focusedClass === 'string') {
35 | rippleConfig.focusedClass = config.focusedClass;
36 | }
37 |
38 | return Ripple;
39 | };
40 |
41 | export default Ripple;
42 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug.yml:
--------------------------------------------------------------------------------
1 | name: Bug
2 | description: File a bug report
3 | labels: [bug]
4 | body:
5 | - type: markdown
6 | attributes:
7 | value: |
8 | Before opening a bug report, please search for the behavior in the existing issues.
9 |
10 | ---
11 |
12 | Thank you for taking the time to file a bug report. To address this bug as fast as possible, we need some information.
13 | - type: input
14 | id: package
15 | attributes:
16 | label: alpine-ripple
17 | description: Which version of the package are you using?
18 | placeholder: v1.0.0
19 | validations:
20 | required: true
21 | - type: textarea
22 | id: bug-description
23 | attributes:
24 | label: Bug description
25 | description: What happened?
26 | validations:
27 | required: true
28 | - type: textarea
29 | id: steps
30 | attributes:
31 | label: Steps to reproduce
32 | description: What steps do we need to take to reproduce this error?
33 | - type: textarea
34 | id: logs
35 | attributes:
36 | label: Relevant log output
37 | description: If applicable, provide relevant log (error) output. No need for backticks here.
38 | render: shell
39 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to `alpine-ripple` will be documented in this file.
4 |
5 | ## v1.1.2 - 2023-04-03
6 |
7 | ### What's Changed
8 |
9 | - Use `passive` option for `touchstart` and `touchmove` event listeners
10 |
11 | **Full Changelog**: https://github.com/rawilk/alpine-ripple/compare/v1.1.1...v1.1.2
12 |
13 | ## v1.1.1 - 2023-01-31
14 |
15 | ### What's Changed
16 |
17 | - Bump dependabot/fetch-metadata from 1.3.5 to 1.3.6 by @dependabot in https://github.com/rawilk/alpine-ripple/pull/3
18 | - Make ripple click effect inherit border radius from its parent element
19 |
20 | **Full Changelog**: https://github.com/rawilk/alpine-ripple/compare/v1.1.0...v1.1.1
21 |
22 | ## v1.1.0 - 2023-01-26
23 |
24 | ### What's Changed
25 |
26 | - NPM: Bump @babel/core from 7.20.5 to 7.20.7 by @dependabot in https://github.com/rawilk/alpine-ripple/pull/1
27 | - Add `overflow:hidden` to base ripple element
28 | - Add new `x-ripple-focus` directive for keyboard focus pulsating ripple effect
29 | - Add new `focusedClass` config option for the ripple focus directive
30 | - Add more event listeners to the `x-ripple` directive, such as `keydown` and `touchstart` for better handling of the ripple effect
31 |
32 | ### New Contributors
33 |
34 | - @dependabot made their first contribution in https://github.com/rawilk/alpine-ripple/pull/1
35 |
36 | **Full Changelog**: https://github.com/rawilk/alpine-ripple/compare/v1.0.0...v1.1.0
37 |
38 | ## v1.0.0 - 2022-12-16
39 |
40 | initial release
41 |
--------------------------------------------------------------------------------
/src/js/utils/modifiers.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Return a user defined custom color for the ripple effect.
3 | *
4 | * @param {Array} modifiers
5 | * @returns {string}
6 | */
7 | export const getCustomColorFromModifiers = modifiers => {
8 | if (! modifiers.includes('color')) {
9 | return '';
10 | }
11 |
12 | const nextModifier = modifiers[modifiers.indexOf('color') + 1] || 'invalid-color';
13 | if (nextModifier.indexOf('#') === 0 || nextModifier.indexOf('rgb') === 0) {
14 | return nextModifier;
15 | }
16 |
17 | return nextModifier.indexOf('bg') === 0
18 | ? nextModifier
19 | : `bg-${nextModifier}`;
20 | };
21 |
22 | /**
23 | * Return a user defined custom radius for the ripple effect.
24 | *
25 | * @param {Array} modifiers
26 | * @returns {string}
27 | */
28 | export const getCustomRadiusFromModifiers = modifiers => {
29 | if (! modifiers.includes('radius')) {
30 | return '';
31 | }
32 |
33 | let nextModifier = modifiers[modifiers.indexOf('radius') + 1] || 'invalid-radius';
34 |
35 | // _ allows us to use decimals, such as 0.5.
36 | nextModifier = nextModifier.replace('_', '.');
37 |
38 | // Separate the numeric value from the unit in nextModifier.
39 | // Possible values for nextModifier: 50, 50.5, 50.5px, 50px, 50%, 50rem, 50em
40 | const numericValue = nextModifier.match(/^[0-9]+(\.[0-9]+)?/)[0];
41 | let unit = nextModifier.replace(numericValue, '');
42 | if (! unit) {
43 | unit = '%';
44 | }
45 |
46 | return `${numericValue}${unit}`;
47 | }
48 |
--------------------------------------------------------------------------------
/src/js/utils/ripple.js:
--------------------------------------------------------------------------------
1 | export const startRipple = (event, el, options = {}) => {
2 | const {
3 | center = options.pulsate,
4 | } = options;
5 |
6 | const rect = el.getBoundingClientRect();
7 |
8 | // Determine the size of the ripple.
9 | let rippleX,
10 | rippleY,
11 | rippleSize;
12 |
13 | if (
14 | center ||
15 | event === undefined ||
16 | (event.clientX === 0 && event.clientY === 0) ||
17 | (! event.clientX && ! event.touches)
18 | ) {
19 | // This is mostly used for the keyboard focus ripple.
20 | rippleX = Math.round(rect.width / 2);
21 | rippleY = Math.round(rect.height / 2);
22 | } else {
23 | const { clientX, clientY } = event.touches && event.touches.length > 0 ? event.touches[0] : event;
24 |
25 | rippleX = Math.round(clientX - rect.left);
26 | rippleY = Math.round(clientY - rect.top);
27 | }
28 |
29 | if (center) {
30 | rippleSize = Math.sqrt((2 * rect.width ** 2 + rect.height ** 2) / 3);
31 |
32 | // For some reason the animation is broken on Mobile Chrome if the size is even.
33 | if (rippleSize % 2 === 0) {
34 | rippleSize++;
35 | }
36 | } else {
37 | const sizeX = Math.max(Math.abs((el ? el.clientWidth : 0) - rippleX), rippleX) * 2 + 2,
38 | sizeY = Math.max(Math.abs((el ? el.clientHeight : 0) - rippleY), rippleY) * 2 + 2;
39 |
40 | rippleSize = Math.sqrt(sizeX ** 2 + sizeY ** 2);
41 | }
42 |
43 | return {
44 | width: `${rippleSize}px`,
45 | height: `${rippleSize}px`,
46 | top: `${-(rippleSize / 2) + rippleY}px`,
47 | left: `${-(rippleSize / 2) + rippleX}px`,
48 | };
49 | };
50 |
--------------------------------------------------------------------------------
/src/css/styles.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --ripple-color: #fff;
3 | --ripple-radius: 9999px;
4 | --ripple-duration: 600ms;
5 | --ripple-timing-function: linear;
6 | --ripple-focus-duration: 2500ms;
7 | --ripple-focus-timing-function: ease-in-out;
8 | --ripple-focus-delay: 200ms;
9 | }
10 |
11 | .ripple {
12 | position: absolute;
13 | top: 0;
14 | left: 0;
15 | bottom: 0;
16 | right: 0;
17 | overflow: hidden;
18 | pointer-events: none;
19 | border-radius: inherit;
20 | }
21 |
22 | .ripple span {
23 | position: absolute;
24 | border-radius: var(--ripple-radius);
25 | opacity: 0.5;
26 | background: var(--ripple-color);
27 | transform: scale(0);
28 | animation: ripple var(--ripple-duration) var(--ripple-timing-function);
29 | }
30 |
31 | .ripple-focus {
32 | overflow: hidden;
33 | pointer-events: none;
34 | position: absolute;
35 | z-index: 0;
36 | border-radius: inherit;
37 | inset: 0;
38 | }
39 |
40 | .ripple-focus-child {
41 | position: absolute;
42 | opacity: 0.3;
43 | border-radius: 50%;
44 | background: var(--ripple-focus-color, var(--ripple-color));
45 | transform: scale(1);
46 | animation: ripple-pulsate var(--ripple-focus-duration) var(--ripple-focus-timing-function) infinite var(--ripple-focus-delay);
47 | }
48 |
49 | .ripple-focus-child > span {
50 | position: absolute;
51 | top: 0;
52 | left: 0;
53 | display: block;
54 | width: 100%;
55 | height: 100%;
56 | border-radius: 50%;
57 | }
58 |
59 | @keyframes ripple {
60 | to {
61 | transform: scale(4);
62 | opacity: 0;
63 | }
64 | }
65 |
66 | @keyframes ripple-pulsate {
67 | 0% {
68 | transform: scale(1);
69 | }
70 | 50% {
71 | transform: scale(.92);
72 | }
73 | 100% {
74 | transform: scale(1);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/docs/usage/x-ripple-focus.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: X-Ripple-Focus
3 | sort: 2
4 | ---
5 |
6 | ## Introduction
7 |
8 | The `x-ripple-focus` directive can be attached to an element to provide a pulsating ripple effect when the element is focused. This directive is compatible
9 | with the `x-ripple` directive, and can be used in conjunction with it.
10 |
11 | ```html
12 |
13 | ```
14 |
15 | When this button is focused, it will show a pulsating ripple effect.
16 |
17 | > {note} For the `x-ripple-focus` directive to work, you must have the `x-data` directive applied to the element as well, or the element
18 | > must be inside the scope of an `x-data` directive.
19 |
20 | ## Options
21 |
22 | Certain aspects of the ripple focus effect can be customized for this package. Some options can be set [globally via CSS](/docs/alpine-ripple/{version}/usage d/global-customization), or on a per-element basis.
23 |
24 | ### Color
25 |
26 | By default, the ripple focus color is white, which should work in most cases. However, if you want to change the color, you can do so with a `color` modifier.
27 |
28 | ```html
29 |
30 | ```
31 |
32 | This will result in a black ripple focus effect when the button is focused. If you're using Tailwind, you may define a color class and use that instead.
33 |
34 | ```html
35 |
36 | ```
37 |
38 | This will result in the ripple focus element getting the `!bg-green-500` class added to it. `!` is added to the class to specify that it is important,
39 | so it overrides any other styles. to prevent Tailwind from puring your color classes, you should be sure to add them to your `safelist` in your
40 | `tailwind.config.js` file if you're not using them anywhere else.
41 |
42 | > {note} If you're using the `x-ripple-focus` directive in conjunction with the `x-ripple` directive, the color of the ripple focus effect will default to
43 | > the color of the ripple effect unless you specify a color for the ripple focus effect.
44 |
45 | ### Other Options
46 |
47 | The rest of the options for the ripple focus effect are only able to be changed globally via CSS. See the [X-Ripple-Focus](/docs/alpine-ripple/{version}/usage/global-customization#user-content-x-ripple-focus) section
48 | for more information.
49 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions are **welcome** and will be fully **credited**.
4 |
5 | Please read and understand the contribution guide before creating an issue or pull request.
6 |
7 | ## Etiquette
8 |
9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11 | extremely unfair for them to suffer abuse or anger for their hard work.
12 |
13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14 | world that developers are civilized and selfless people.
15 |
16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17 | quality to benefit the project. Many developers have different skill-sets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18 |
19 | ## Viability
20 |
21 | When requesting or submitting new features, first consider whether it might be useful to others. Open
22 | source projects are used by many developers, who may have entirely different needs to your own. Think about
23 | whether or not your feature is likely to be used by other users of the project.
24 |
25 | ## Procedure
26 |
27 | Before filing an issue:
28 |
29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30 | - Check to make sure your feature suggestion isn't already present within the project.
31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32 | - Check the pull requests tab to ensure that the feature isn't already in progress.
33 |
34 | Before submitting a pull request:
35 |
36 | - Check the codebase to ensure that your feature doesn't already exist.
37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38 |
39 | ## Requirements
40 |
41 | If the project maintainer has any additional requirements, you will find them listed here.
42 |
43 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
44 |
45 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
46 |
47 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
48 |
49 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
50 |
51 | **Happy coding**!
52 |
--------------------------------------------------------------------------------
/docs/usage/global-customization.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Global Customization
3 | sort: 3
4 | ---
5 |
6 | ## Introduction
7 |
8 | If you find yourself using the same options on multiple elements, you may find it better to modify those options globally via CSS. This way, you don't have to repeat yourself on every element.
9 | Below is an explanation of how to modify each of the options for the directives globally.
10 |
11 | > {tip} Be sure your CSS if located after the CSS for this package for any changes to take effect.
12 |
13 | ## X-Ripple
14 |
15 | Below are the options for the `x-ripple` directive that can be modified globally.
16 |
17 | ### Color
18 |
19 | If you want to change the color globally, you can do so by setting the `--ripple-color` CSS variable. The best place to do this in your app CSS file in a `:root` selector.
20 | You may define the color with any valid hex or rgb value.
21 |
22 | ```css
23 | :root {
24 | --ripple-color: #000;
25 | }
26 | ```
27 |
28 | ### Radius
29 |
30 | By default, the ripple radius is 9999px, but you may make it more or less to suit your needs. To change it globally, you can set the `--ripple-radius` CSS variable in your app CSS file.
31 |
32 | ```css
33 | :root {
34 | --ripple-radius: 5%;
35 | }
36 | ```
37 |
38 | Now the ripple radius will be 5% instead.
39 |
40 | ### Duration
41 |
42 | By default, the ripple duration is 600ms, but you may make it more or less to suit your needs. To change it globally, you can set the `--ripple-duration` CSS variable in your app CSS file.
43 |
44 | ```css
45 | :root {
46 | --ripple-duration: 1000ms;
47 | }
48 | ```
49 |
50 | ### Timing Function
51 |
52 | By default, the ripple timing function is `linear`, but you may change it to suit your needs by setting the `--ripple-timing-function` CSS variable in your app CSS file.
53 |
54 | ```css
55 | :root {
56 | --ripple-timing-function: ease-in-out;
57 | }
58 | ```
59 |
60 | ## X-Ripple-Focus
61 |
62 | Below are the options for the `x-ripple-focus` directive that can be modified globally.
63 |
64 | ### Focus Color
65 |
66 | If you want to change the color of the `x-ripple-focus` globally, you can do so by setting the `--ripple-focus-color` CSS variable in your app CSS file.
67 | You may define the color with any valid hex or rgb value.
68 |
69 | ```css
70 | :root {
71 | --ripple-focus-color: #000;
72 | }
73 | ```
74 |
75 | > {note} If you're using the `x-ripple` directives, you only need to set the `--ripple-color` CSS variable unless you want to use a different color for the `x-ripple-focus` directive.
76 |
77 | ### Animation
78 |
79 | The `x-ripple-focus` directive uses a CSS animation to create a pulsating effect on the ripple focus element that gets appended inside your element when it is focused. There
80 | are a few customizations you may make to the animation via CSS variables. Here are the defaults that are used for the animation.
81 |
82 | ```css
83 | :root {
84 | --ripple-focus-duration: 2500ms;
85 | --ripple-focus-timing-function: ease-in-out;
86 | --ripple-focus-delay: 200ms;
87 | }
88 | ```
89 |
--------------------------------------------------------------------------------
/docs/usage/x-ripple.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: X-Ripple
3 | sort: 1
4 | ---
5 |
6 | ## Introduction
7 |
8 | The `x-ripple` directive is the main directive this package offers. It adds a ripple effect to any element with the directive applied to it.
9 | In most cases, this will be a button, but you are free to use it on any element.
10 |
11 | ```html
12 |
13 | ```
14 |
15 | This will result in a ripple effect when the button is clicked on. By default, the ripple effect will be white, but this can be
16 | changed globally or on a per-element basis.
17 |
18 | > {note} For the `x-ripple` directive to work, you must have the `x-data` directive applied to the element as well, or the element
19 | > must be inside the scope of an `x-data` directive.
20 |
21 | ## Options
22 |
23 | Certain aspects of the ripple effect can be customized for this package. Some options can be set [globally via CSS](/docs/alpine-ripple/{version}/usage/global-customization), or on a per-element basis.
24 |
25 | ### Color
26 |
27 | By default, the ripple color is white, which should work in most cases. However, if you want to change the color, you can do so with a `color` modifier.
28 |
29 | ```html
30 |
31 | ```
32 |
33 | This will result in a black ripple effect when the button is clicked on. If you're using Tailwind, you may define a color class and use that instead.
34 |
35 | ```html
36 |
37 | ```
38 |
39 | This will result in the ripple element getting the `!bg-green-500` class added to it. `!` is added to the class to specify that it is important,
40 | so it overrides any other styles. to prevent Tailwind from puring your color classes, you should be sure to add them to your `safelist` in your
41 | `tailwind.config.js` file if you're not using them anywhere else.
42 |
43 | ### Radius
44 |
45 | By default, the ripple radius is set to `9999px`, but you may make it more or less to suit your needs. You can modify the radius with the `radius` modifier.
46 |
47 | ```html
48 |
49 | ```
50 |
51 | This button will now have a radius of 5rem. Any valid CSS unit can be used. If one is omitted, we will assume a unit of `%`. If you want to use a decimal value,
52 | you may define it with an underscore, like this:
53 |
54 | ```html
55 |
56 | ```
57 |
58 | This will give the ripple a radius of 5.5%.
59 |
60 | ### Duration
61 |
62 | By default, the ripple duration is 600ms, but you may make it more or less to suit your needs, however the only way to do this is by setting it globally via CSS.
63 | See the [Duration](/docs/alpine-ripple/{version}/usage/global-customization#user-content-duration) section for more information.
64 |
65 | ## Advanced Usage
66 |
67 | It is possible to chain multiple modifiers onto the `x-ripple` directive. Here is an example of changing the color to red, and the radius to 25%.
68 |
69 | ```html
70 |
71 | ```
72 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | > ✨ Help support the maintenance of this package by [sponsoring me](https://github.com/sponsors/rawilk).
2 |
3 | # alpine-ripple
4 |
5 | 
6 | 
7 | 
8 |
9 | 
10 |
11 | `alpine-ripple` is a simple Alpine.js plugin that adds a ripple effect to any element with an alpine directive `x-ripple`.
12 |
13 | ## Requirements
14 |
15 | - Alpine.js v3.x
16 | - Tailwind CSS (only required if you want to use custom color classes on the directive)
17 |
18 | ## Installation
19 |
20 | ### CDN
21 |
22 | Include the following `
33 | ```
34 |
35 | ### NPM
36 |
37 | ```bash
38 | npm i -S @wilkr/alpine-ripple
39 | ```
40 |
41 | Add the `x-ripple` directive to your project by importing the package.
42 |
43 | ```js
44 | import Alpine from "alpinejs";
45 | import Ripple from "@wilkr/alpine-ripple";
46 |
47 | Alpine.plugin(Ripple);
48 |
49 | window.Alpine = Alpine;
50 | window.Alpine.start();
51 | ```
52 |
53 | Import the package styles into your css.
54 |
55 | ```css
56 | @import "@wilkr/alpine-ripple/dist/alpine-ripple.css";
57 | ```
58 |
59 | ## Usage
60 |
61 | Add the `x-ripple` directive to any element, which in most cases will be a `