diff --git a/README.md b/README.md index 0196d45a8..7eb6fae14 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ import ReactDOM from 'react-dom'; * [`FileDrop`](#filedrop) * [`Mailto`](#mailto) * [`Modal`](#modal) +* [`RippleButton`](#ripplebutton) * [`StarRating`](#starrating) * [`Tabs`](#tabs) * [`Ticker`](#ticker) @@ -1629,6 +1630,129 @@ ReactDOM.render(, document.getElementById('root'));
[⬆ Back to top](#contents) +### RippleButton + +### RippleButton + +Renders a button that animates a ripple effect when clicked. + +- Define some appropriate CSS styles and an animation for the ripple effect. +- Use the `React.useState()` hook to create appropriate variables and setters for the pointer's coordinates and for the animation state of the button. +- Use the `React.useEffect()` hook to change the state every time the `coords` state variable changes, starting the animation. +- Use `setTimeout()` in the previous hook to clear the animation after it's done playing. +- Use the `React.useEffect()` hook a second time to reset `coords` whenever the `isRippling` state variable is `false.` +- Handle the `onClick` event by updating the `coords` state variable and calling the passed callback. +- Finally, render a ` + ); +} +``` + +
+Examples + +```jsx +ReactDOM.render( + console.log(e)}>Click me, + document.getElementById('root') +); +``` +
+ +
[⬆ Back to top](#contents) + ### StarRating Renders a star rating component. diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index 1d4e01b52..555d19b80 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -268,6 +268,23 @@ "hash": "b9d1d5a6b61d2ab8e73943da1dcf86bfa872821c9584715a2cee303a052334ea" } }, + { + "id": "RippleButton", + "type": "snippetListing", + "title": "RippleButton", + "attributes": { + "text": "### RippleButton\n\nRenders a button that animates a ripple effect when clicked.\n\n- Define some appropriate CSS styles and an animation for the ripple effect.\n- Use the `React.useState()` hook to create appropriate variables and setters for the pointer's coordinates and for the animation state of the button.\n- Use the `React.useEffect()` hook to change the state every time the `coords` state variable changes, starting the animation.\n- Use `setTimeout()` in the previous hook to clear the animation after it's done playing.\n- Use the `React.useEffect()` hook a second time to reset `coords` whenever the `isRippling` state variable is `false.`\n- Handle the `onClick` event by updating the `coords` state variable and calling the passed callback.\n- Finally, render a `\n );\n}", + "example": "ReactDOM.render(\n console.log(e)}>Click me,\n document.getElementById('root')\n);" + }, + "tags": [ + "visual", + "state", + "effect", + "intermediate" + ] + }, + "meta": { + "hash": "95d8e2f6113d2d38c90c3f6d0f765cc48cbc85a14cc77613b0c9b09156684116" + } + }, { "id": "Select", "title": "Select",