Skip to content

Commit e02113a

Browse files
authored
Cleanup Ripple button example (#6709)
* Cleanup Ripple button example
1 parent a9c39a6 commit e02113a

File tree

3 files changed

+19
-25
lines changed

3 files changed

+19
-25
lines changed

packages/react-aria-components/docs/Button.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import packageData from 'react-aria-components/package.json';
1818
import Anatomy from '@react-aria/datepicker/docs/daterangepicker-anatomy.svg';
1919
import ChevronRight from '@spectrum-icons/workflow/ChevronRight';
2020
import {Divider} from '@react-spectrum/divider';
21+
import {ExampleList} from '@react-spectrum/docs/src/ExampleList';
2122
import {ExampleCard} from '@react-spectrum/docs/src/ExampleCard';
2223
import {Keyboard} from '@react-spectrum/text';
2324
import {StarterKits} from '@react-spectrum/docs/src/StarterKits';
@@ -103,6 +104,10 @@ buttons using the <Keyboard>Space</Keyboard> or <Keyboard>Enter</Keyboard> keys.
103104
If a visual label is not provided (e.g. an icon only button), then an `aria-label` or
104105
`aria-labelledby` prop must be passed to identify the button to assistive technology.
105106

107+
## Examples
108+
109+
<ExampleList tag="button" />
110+
106111
## Starter kits
107112

108113
To help kick-start your project, we offer starter kits that include example implementations of all React Aria components with various styling solutions. All components are fully styled, including support for dark mode, high contrast mode, and all UI states. Each starter comes with a pre-configured [Storybook](https://storybook.js.org/) that you can experiment with, or use as a starting point for your own component library.

packages/react-aria-components/docs/examples/ripple-button.mdx

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import {ExampleCard} from '@react-spectrum/docs/src/ExampleCard';
2020
keywords: [example, button, aria, accessibility, react, component]
2121
type: component
2222
image: ripple-button.png
23-
description: A ripple animated button styled with Tailwind CSS.
23+
description: A button with an animated ripple effect styled with Tailwind CSS.
2424
---
2525

2626
# Ripple Button
2727

28-
An animated Ripple [Button](../Button.html) styled with [Tailwind CSS](https://tailwindcss.com/).
28+
A [Button](../Button.html) with an animated ripple effect styled with [Tailwind CSS](https://tailwindcss.com/).
2929

3030
## Example
3131

@@ -39,17 +39,17 @@ import {useEffect, useRef, useState} from 'react';
3939
import Airplane from '@spectrum-icons/workflow/Airplane';
4040

4141
function RippleButton(props) {
42-
const [coords, setCoords] = useState({x: -1, y: -1});
43-
const [isRippling, setIsRippling] = useState(false);
42+
const [coords, setCoords] = useState(null);
4443

4544
let timeout = useRef<ReturnType<typeof setTimeout> | null>(null);
4645
let onPress = (e) => {
4746
setCoords({x: e.x, y: e.y});
4847
if (e.x !== -1 && e.y !== -1) {
49-
setIsRippling(true);
50-
timeout.current = setTimeout(() => setIsRippling(false), 600);
48+
clearTimeout(timeout.current);
49+
timeout.current = setTimeout(() => setCoords(null), 600);
5150
}
5251
};
52+
5353
useEffect(() => {
5454
return () => {
5555
clearTimeout(timeout.current);
@@ -61,20 +61,19 @@ function RippleButton(props) {
6161
<Button
6262
onPress={onPress}
6363
className={`
64-
relative overflow-hidden min-h-16
65-
inline-flex items-center justify-center rounded-md bg-black bg-opacity-50 bg-clip-padding border border-white/20 px-3.5 py-2 font-medium text-white
64+
relative overflow-hidden
65+
inline-flex items-center justify-center rounded-md bg-black bg-opacity-50 bg-clip-padding border border-white/20 px-6 py-4 text-white text-lg
6666
hover:bg-opacity-60 pressed:bg-opacity-70 transition-colors cursor-default outline-none focus-visible:ring-2 focus-visible:ring-white/75`}>
67-
{isRippling ? (
67+
{coords && (
6868
<div
69-
className="ripple"
69+
key={`${coords.x},${coords.y}`}
70+
className="absolute h-8 w-8 rounded-full opacity-100 bg-white/60"
7071
style={{
72+
animation: 'ripple 600ms linear',
7173
left: coords.x - 15,
7274
top: coords.y - 15
73-
}} />
74-
) : (
75-
''
76-
)}
77-
<span className="flex items-center gap-2">{props.children}</span>
75+
}} />)}
76+
<span className="flex items-center gap-4">{props.children}</span>
7877
</Button>
7978
</div>
8079
)
@@ -83,16 +82,6 @@ function RippleButton(props) {
8382
<RippleButton><Airplane size="S" /> Book flight</RippleButton>
8483
```
8584
```css
86-
div.ripple {
87-
position: absolute;
88-
height: 30px;
89-
width: 30px;
90-
border-radius: 50%;
91-
transform: scale(0);
92-
opacity: 1;
93-
animation: ripple 600ms linear;
94-
background-color: rgba(255, 255, 255, .6);
95-
}
9685
@keyframes ripple {
9786
from {
9887
transform: scale(0);
-15.3 KB
Loading

0 commit comments

Comments
 (0)