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

Commit 7b24d01

Browse files
Kerricklynnmercier
authored andcommitted
feat(ripple): export util from @material/ripple (#751)
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 86160de commit 7b24d01

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

packages/mdc-ripple/README.md

+25-2
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

@@ -125,13 +126,13 @@ First import the ripple JS
125126
##### ES2015
126127

127128
```javascript
128-
import {MDCRipple, MDCRippleFoundation} from '@material/ripple';
129+
import {MDCRipple, MDCRippleFoundation, util} from '@material/ripple';
129130
```
130131

131132
##### CommonJS
132133

133134
```javascript
134-
const {MDCRipple, MDCRippleFoundation} = require('@material/ripple');
135+
const {MDCRipple, MDCRippleFoundation, util} = require('@material/ripple');
135136
```
136137

137138
##### AMD
@@ -140,6 +141,7 @@ const {MDCRipple, MDCRippleFoundation} = require('@material/ripple');
140141
require('path/to/@material/ripple', function(mdcRipple) {
141142
const MDCRipple = mdcRipple.MDCRipple;
142143
const MDCRippleFoundation = mdcRipple.MDCRippleFoundation;
144+
const util = mdcRipple.util;
143145
});
144146
```
145147

@@ -148,6 +150,7 @@ require('path/to/@material/ripple', function(mdcRipple) {
148150
```javascript
149151
const MDCRipple = mdc.ripple.MDCRipple;
150152
const MDCRippleFoundation = mdc.ripple.MDCRippleFoundation;
153+
const util = mdc.ripple.util;
151154
```
152155

153156
Then, simply initialize the ripple with the correct DOM element.
@@ -408,3 +411,23 @@ background: color(var(--mdc-theme-primary) a(6%));
408411
But as far as we know, no browsers yet support it. We have added a `@supports` clause into our code
409412
to make sure that it can be used as soon as browsers adopt it, but for now this means that _changes
410413
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.
414+
415+
### The util API
416+
417+
External frameworks and libraries can use the following utility methods when integrating a component.
418+
419+
#### util.supportsCssVariables(windowObj) => Boolean
420+
421+
Determine whether the current browser supports CSS variables (custom properties).
422+
423+
#### util.applyPassive(globalObj = window, forceRefresh = false) => object
424+
425+
Determine whether the current browser supports passive event listeners, and if so, use them.
426+
427+
#### getMatchesProperty(HTMLElementPrototype) => Function
428+
429+
Choose the correct matches property to use on the current browser.
430+
431+
#### getNormalizedEventCoords(ev, pageOffset, clientRect) => object
432+
433+
Determines X/Y coordinates of an event normalized for touch events and ripples.

packages/mdc-ripple/index.js

+6-5
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)