Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 85eb0fb

Browse files
committed
feat(ripple): export util from @material/ripple
Resolves #253: The docs recommend using certain functions from util when implementing an adapter for the ripple foundation. Export util from index.js so this is possible.
1 parent 7c6da3a commit 85eb0fb

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

packages/mdc-ripple/README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ path: /catalog/ripples/
3333
- [Specifying known element dimensions](#specifying-known-element-dimensions)
3434
- [Caveat: Safari](#caveat-safari)
3535
- [Caveat: Theme Custom Variables](#caveat-theme-custom-variables)
36+
- [The util API](#the-util-api)
3637

3738
MDC Ripple provides the Javascript and CSS required to provide components (or any element at all) with a material "ink ripple" interaction effect. It is designed to be efficient, uninvasive, and usable without adding any extra DOM to your elements.
3839

@@ -126,13 +127,13 @@ First import the ripple JS
126127
##### ES2015
127128

128129
```javascript
129-
import {MDCRipple, MDCRippleFoundation} from '@material/ripple';
130+
import {MDCRipple, MDCRippleFoundation, util} from '@material/ripple';
130131
```
131132

132133
##### CommonJS
133134

134135
```javascript
135-
const {MDCRipple, MDCRippleFoundation} = require('@material/ripple');
136+
const {MDCRipple, MDCRippleFoundation, util} = require('@material/ripple');
136137
```
137138

138139
##### AMD
@@ -141,6 +142,7 @@ const {MDCRipple, MDCRippleFoundation} = require('@material/ripple');
141142
require('path/to/@material/ripple', function(mdcRipple) {
142143
const MDCRipple = mdcRipple.MDCRipple;
143144
const MDCRippleFoundation = mdcRipple.MDCRippleFoundation;
145+
const util = mdcRipple.util;
144146
});
145147
```
146148

@@ -149,6 +151,7 @@ require('path/to/@material/ripple', function(mdcRipple) {
149151
```javascript
150152
const MDCRipple = mdc.ripple.MDCRipple;
151153
const MDCRippleFoundation = mdc.ripple.MDCRippleFoundation;
154+
const util = mdc.ripple.util;
152155
```
153156

154157
Then, simply initialize the ripple with the correct DOM element.
@@ -409,3 +412,23 @@ background: color(var(--mdc-theme-primary) a(6%));
409412
But as far as we know, no browsers yet support it. We have added a `@supports` clause into our code
410413
to make sure that it can be used as soon as browsers adopt it, but for now this means that _changes
411414
to your theme via a custom variable will not propagate to ripples._ We don't see this being a gigantic issue as we envision most users configuring one theme via sass. For places where you do need this, special treatment will have to be given.
415+
416+
### The util API
417+
418+
External frameworks and libraries can use the following utility methods when integrating a component.
419+
420+
#### util.supportsCssVariables(windowObj) => Boolean
421+
422+
Determine whether the current browser supports CSS variables (custom properties).
423+
424+
#### util.applyPassive(globalObj = window, forceRefresh = false) => object
425+
426+
Determine whether the current browser supports passive event listeners, and if so, use them.
427+
428+
#### getMatchesProperty(HTMLElementPrototype) => Function
429+
430+
Choose the correct matches property to use on the current browser.
431+
432+
#### getNormalizedEventCoords(ev, pageOffset, clientRect) => object
433+
434+
Determines X/Y coordinates of an event normalized for touch events and ripples.

packages/mdc-ripple/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
import {MDCComponent} from '@material/base';
1818
import MDCRippleFoundation from './foundation';
19-
import {applyPassive, supportsCssVariables, getMatchesProperty} from './util';
19+
import * as util from './util';
2020

2121
export {MDCRippleFoundation};
22+
export {util};
2223

2324
export class MDCRipple extends MDCComponent {
2425
static attachTo(root, {isUnbounded = undefined} = {}) {
@@ -31,19 +32,19 @@ export class MDCRipple extends MDCComponent {
3132
}
3233

3334
static createAdapter(instance) {
34-
const MATCHES = getMatchesProperty(HTMLElement.prototype);
35+
const MATCHES = util.getMatchesProperty(HTMLElement.prototype);
3536

3637
return {
37-
browserSupportsCssVars: () => supportsCssVariables(window),
38+
browserSupportsCssVars: () => util.supportsCssVariables(window),
3839
isUnbounded: () => instance.unbounded,
3940
isSurfaceActive: () => instance.root_[MATCHES](':active'),
4041
isSurfaceDisabled: () => instance.disabled,
4142
addClass: (className) => instance.root_.classList.add(className),
4243
removeClass: (className) => instance.root_.classList.remove(className),
4344
registerInteractionHandler: (evtType, handler) =>
44-
instance.root_.addEventListener(evtType, handler, applyPassive()),
45+
instance.root_.addEventListener(evtType, handler, util.applyPassive()),
4546
deregisterInteractionHandler: (evtType, handler) =>
46-
instance.root_.removeEventListener(evtType, handler, applyPassive()),
47+
instance.root_.removeEventListener(evtType, handler, util.applyPassive()),
4748
registerResizeHandler: (handler) => window.addEventListener('resize', handler),
4849
deregisterResizeHandler: (handler) => window.removeEventListener('resize', handler),
4950
updateCssVariable: (varName, value) => instance.root_.style.setProperty(varName, value),

0 commit comments

Comments
 (0)