# Ripple

Source: https://material.spynejs.com/features/ripple
Part of: Material shell gallery, Google's Material Design 3 for SpyneJS. Index: https://material.spynejs.com/llms.txt

Material's ripple: a press on a button, a card or a navigation link spreads from the point that was pressed. Every app on the template has it, on everything of the template's that can be pressed. A model does not ask for it.

## In an app model

Nothing. Everything of the template’s that can be pressed ripples: a generated app gets it with the template.

## What ripples

These, and nothing else:

| Selector | What it is |
| --- | --- |
| `.btn` | a button |
| `a.page-card` | a card that is a link |
| `.site-nav a.nav` | a link in the app bar |
| `#menu-drawer a.nav` | a link in the drawer |
| `.theme-toggle` | the button for the colour scheme |
| `#menu_toggle` | the menu button |

- So a call to action written with the class `btn` ripples, and a card written as `a.page-card` does. Nothing more is needed.
- The styles draw the ripple. One view, `MaterialRippleNullView`, hears every press from the window channel and writes the pressed point on the pressed element as two custom properties, `--ripple-x` and `--ripple-y`, in pixels from its top-left corner. Pressed from the keyboard, a ripple starts in the middle.
- An element of your own does not ripple by being pressable. It would need to be in the trait’s list and to have the ripple’s styles; the two are kept in step by hand. Use `btn` or `a.page-card` instead where you can.
- With reduced motion asked for there is no ripple: the pressed layer shows flat, at once.

## Where it is in the template

| File | What it holds | By name |
| --- | --- | --- |
| `src/app/components/material/material-ripple-null-view.js` | the one view that writes the pressed point | `MaterialRippleNullView` |
| `src/app/traits/material/material-ripple-traits.js` | the list of what ripples; the point of a press | `materialRipple$OnPointerDown`, `materialRipple$OnKeyPress` |
| `src/scss/03-components/material/_ripple.scss` | the ripple for cards, navigation links and icon buttons |  |
| `src/scss/00-spynejs-design-system/elements/_buttons.scss` | the button’s own ripple |  |

The template is public: https://github.com/spynejs/application-shell-material. An app made from it has these same files.

What it rests on in `@spynejs/grammar`: `op:null-appended-behavior-view`, `op:window-event-via-channel`, `op:dynamic-children-ingress`.

## As the page shows it

The page’s own words, in its own order, read from the page as it is drawn in the light colour scheme. They were written for someone looking at the page: “above”, “below” and “marked” mean the drawn page. A thing the page draws is named here in its place (`Button:`, `Field:`, `Switch:`), and a box that reports what the reader does is as it starts, empty. What depends on the reader’s own window is left out.

A press on a button, a card or a navigation link spreads from the point that was pressed. Press and hold one of these, near an end, to see where it starts.

Buttons: Filled, Tonal, Outlined, Text

The links in the sidebar, the button for the colour scheme and every card ripple too. Pressed from the keyboard, a ripple starts in the middle.

### The last press

```
Nothing pressed yet.
```

### How it knows the point

The styles draw the ripple, but they cannot know where a press landed. One view with no presence of its own hears every press from the window channel and writes the point on the pressed element, as two custom properties: --ripple-x and --ripple-y. It is the one view in the template that writes on elements it did not make.

Nothing to ask for in a model. Everything that can be pressed ripples; a generated app gets it with the template.
