react-toolbox/components/ripple/Ripple.js

277 lines
11 KiB
JavaScript
Raw Normal View History

import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
2016-05-16 15:17:26 +03:00
import classnames from 'classnames';
import { themr } from 'react-css-themr';
Migrate styles to PostCSS (#666) * Add postcss-next postcss-include and reporter * Add stylelint * Add CSS colors * Add CSS custom media queries * Use dashes for CSS colors * Add base CSS variables * Remove AppBar SASS dependency from spec page * Migrate AppBar style to PostCSS * Migrate Avatar style to PostCSS * Migrate Ripple style to PostCSS * Remove unneeded media CSS import in Avatar * Add shadows to CSS variables * Migrate Button style to PostCSS * Update webpack test config and linting from npm * Migrate Input style to PostCSS * Add missing input config variables for Dropdown and Autocomplete * Migrate Chip style to PostCSS * Migrate Autocomplete style to PostCSS * Migrate Dropdown style to PostCSS * Migrate animations to PostCSS * Migrate Card style to PostCSS * Migrate Checkbox style to PostCSS * Migrate DataPicker style to PostCSS * Migrate Dialog style to PostCSS * Migrate Drawer style to PostCSS * Add postcss-mixins and postcss-each * Migrate Layout style to PostCSS * Fix bug in button theme * Bugfix in avatar css * Add some missing nesting notations * Migrate Link style to PostCSS * Migrate List style to PostCSS * Migrate Menu style to PostCSS * Migrate Navigation style to PostCSS * Migrate Overlay style to PostCSS * Migrate ProgressBar style to PostCSS * Migrate Radio style to PostCSS * Migrate Slider style to PostCSS * Migrate Snackbar style to PostCSS * Migrate Switch style to PostCSS * Migrate Table style to PostCSS * Migrate Tabs style to PostCSS * Migrate TimePicker to PostCSS * Migrate Tooltip styles to PostCSS * Update webpack config for testing and tests * Migrate commons to PostCSS * Remove sass from main project * Bye from docs to sass * Build with CSS * Remove unneded deps for sass in docs subproject * Fix tests * use 4p shadow in AppBar as spec indicates * Fixed typo in list/config.css * Fix tests * Fix linter errors * Latest build * Release 2.0.0-beta.0 * Remove sass lint * fixes old sass var in css config * Update linter * New Table implementation * Fix old sass var in list/config.css See da0c47041ecf2d8b118b06fba9f53cc4d7e1e79f. * Remove normalize.css from commons.css * Update dependencies * Latest build * Input ready to accept visible hint * Prepare slider and progress to be disabled * Render Snackbar using Portal * Refactor Dialog, Drawer and Overlay to be used in Layout * Add inner layer to AppBar * New layout * Use Layout in spec * Latest build * remove layout playground example * add smTablet and lgTablet to NavDrawer in Layout readme * add default prop className to Layout, NavDrawer and Sidebar * fix css linter errors in card and slider * Typings for Table component * Add missing Drawer identifier * Update lib build * Adds onQueryChange callback property to Autocomplete The onQueryChange callback is called when the value of the query changes in Autocomplete. It is called with the new query value. * Fix #966 * Fix #965 * Fixes #976 * Updated css-related dependencies Removed usages of `addDependencyTo` since it's deprecated and not needed anymore. See https://github.com/postcss/postcss-import#adddependencyto * Enabled HMR for styles by disabling extracting them to a CSS file * Remove lib from repo * Remove lib * Fixes #1021 * Build using Gulp * Export ThemeProvider from react-css-themr * Add CHANGELOG to release command * Release 2.0.0-beta.1 * Remove immutability helper * Update dependencies * Fix Tooltip trying to render after it's been unmounted * Fixes #1038 * Release 2.0.0-beta.2 * Add ramda, refactor utils and remove slide animation modules * Remove separate slide animations modules * Remove box-sizing reset and body rule * Remove commons.css * Release 2.0.0-beta.4 * Update dependencies * Fixes #1061 * More aggresive guard condition for multiple autocomplete * Fix typeof check in isBrowser function * Fixes an issue when specs are opened with browsers that do not support Object.entries(). * Import from ramda using the 'import XXX from "ramda/src/XXX"' pattern so that bundle sizes will be smaller for not including the whole ramda package. * Fix #1032 * Fix tests * Update yarn.lock * Fixes #1064
2017-01-05 04:42:18 +03:00
import dissoc from 'ramda/src/dissoc';
2016-05-28 16:37:10 +03:00
import { RIPPLE } from '../identifiers.js';
2016-04-12 22:41:28 +03:00
import events from '../utils/events';
2015-12-07 04:34:12 +03:00
import prefixer from '../utils/prefixer';
2015-12-07 04:34:12 +03:00
const defaults = {
centered: false,
className: '',
2016-08-06 15:24:40 +03:00
multiple: true,
2017-01-23 12:44:24 +03:00
passthrough: true,
2016-05-28 16:37:10 +03:00
spread: 2,
theme: {}
2015-12-07 04:34:12 +03:00
};
2016-05-28 16:37:10 +03:00
const rippleFactory = (options = {}) => {
2015-12-07 04:34:12 +03:00
const {
centered: defaultCentered,
className: defaultClassName,
2016-08-06 15:24:40 +03:00
multiple: defaultMultiple,
2017-01-23 12:44:24 +03:00
passthrough: defaultPassthrough,
2016-01-26 16:58:28 +03:00
spread: defaultSpread,
2016-05-28 16:37:10 +03:00
theme: defaultTheme,
2016-01-26 16:58:28 +03:00
...props
2015-12-07 04:34:12 +03:00
} = {...defaults, ...options};
2015-12-07 04:34:12 +03:00
return ComposedComponent => {
class RippledComponent extends Component {
2015-12-07 04:34:12 +03:00
static propTypes = {
children: PropTypes.any,
disabled: PropTypes.bool,
onRippleEnded: PropTypes.func,
ripple: PropTypes.bool,
rippleCentered: PropTypes.bool,
rippleClassName: PropTypes.string,
2016-08-06 15:24:40 +03:00
rippleMultiple: PropTypes.bool,
rippleSpread: PropTypes.number,
theme: PropTypes.shape({
ripple: PropTypes.string,
rippleActive: PropTypes.string,
rippleRestarting: PropTypes.string,
rippleWrapper: PropTypes.string
2016-05-16 15:17:26 +03:00
})
2015-12-07 04:34:12 +03:00
};
2015-12-07 04:34:12 +03:00
static defaultProps = {
disabled: false,
ripple: true,
rippleCentered: defaultCentered,
rippleClassName: defaultClassName,
2016-08-06 15:24:40 +03:00
rippleMultiple: defaultMultiple,
2015-12-07 04:34:12 +03:00
rippleSpread: defaultSpread
};
2015-12-07 04:34:12 +03:00
state = {
2016-08-06 15:24:40 +03:00
ripples: {}
2015-12-07 04:34:12 +03:00
};
componentDidUpdate (prevProps, prevState) {
2016-08-06 15:24:40 +03:00
// If a new ripple was just added, add a remove event listener to its animation
if (Object.keys(prevState.ripples).length < Object.keys(this.state.ripples).length) {
this.addRippleRemoveEventListener(this.getLastKey());
2016-04-12 22:41:28 +03:00
}
}
2016-08-06 21:40:24 +03:00
componentWillUnmount () {
// Remove document event listeners for ripple if they still exists
Object.keys(this.state.ripples).forEach(key => {
this.state.ripples[key].endRipple();
});
}
2016-08-06 15:24:40 +03:00
/**
* Add an event listener to the reference with given key so when the animation transition
* ends we can be sure that it finished and it can be safely removed from the state.
* This function is called whenever a new ripple is added to the component.
*
* @param {String} rippleKey Is the key of the ripple to add the event.
*/
addRippleRemoveEventListener (rippleKey) {
const self = this;
events.addEventListenerOnTransitionEnded(this.refs[rippleKey], function onOpacityEnd (e) {
if (e.propertyName === 'opacity') {
if (self.props.onRippleEnded) self.props.onRippleEnded(e);
events.removeEventListenerOnTransitionEnded(self.refs[rippleKey], onOpacityEnd);
Migrate styles to PostCSS (#666) * Add postcss-next postcss-include and reporter * Add stylelint * Add CSS colors * Add CSS custom media queries * Use dashes for CSS colors * Add base CSS variables * Remove AppBar SASS dependency from spec page * Migrate AppBar style to PostCSS * Migrate Avatar style to PostCSS * Migrate Ripple style to PostCSS * Remove unneeded media CSS import in Avatar * Add shadows to CSS variables * Migrate Button style to PostCSS * Update webpack test config and linting from npm * Migrate Input style to PostCSS * Add missing input config variables for Dropdown and Autocomplete * Migrate Chip style to PostCSS * Migrate Autocomplete style to PostCSS * Migrate Dropdown style to PostCSS * Migrate animations to PostCSS * Migrate Card style to PostCSS * Migrate Checkbox style to PostCSS * Migrate DataPicker style to PostCSS * Migrate Dialog style to PostCSS * Migrate Drawer style to PostCSS * Add postcss-mixins and postcss-each * Migrate Layout style to PostCSS * Fix bug in button theme * Bugfix in avatar css * Add some missing nesting notations * Migrate Link style to PostCSS * Migrate List style to PostCSS * Migrate Menu style to PostCSS * Migrate Navigation style to PostCSS * Migrate Overlay style to PostCSS * Migrate ProgressBar style to PostCSS * Migrate Radio style to PostCSS * Migrate Slider style to PostCSS * Migrate Snackbar style to PostCSS * Migrate Switch style to PostCSS * Migrate Table style to PostCSS * Migrate Tabs style to PostCSS * Migrate TimePicker to PostCSS * Migrate Tooltip styles to PostCSS * Update webpack config for testing and tests * Migrate commons to PostCSS * Remove sass from main project * Bye from docs to sass * Build with CSS * Remove unneded deps for sass in docs subproject * Fix tests * use 4p shadow in AppBar as spec indicates * Fixed typo in list/config.css * Fix tests * Fix linter errors * Latest build * Release 2.0.0-beta.0 * Remove sass lint * fixes old sass var in css config * Update linter * New Table implementation * Fix old sass var in list/config.css See da0c47041ecf2d8b118b06fba9f53cc4d7e1e79f. * Remove normalize.css from commons.css * Update dependencies * Latest build * Input ready to accept visible hint * Prepare slider and progress to be disabled * Render Snackbar using Portal * Refactor Dialog, Drawer and Overlay to be used in Layout * Add inner layer to AppBar * New layout * Use Layout in spec * Latest build * remove layout playground example * add smTablet and lgTablet to NavDrawer in Layout readme * add default prop className to Layout, NavDrawer and Sidebar * fix css linter errors in card and slider * Typings for Table component * Add missing Drawer identifier * Update lib build * Adds onQueryChange callback property to Autocomplete The onQueryChange callback is called when the value of the query changes in Autocomplete. It is called with the new query value. * Fix #966 * Fix #965 * Fixes #976 * Updated css-related dependencies Removed usages of `addDependencyTo` since it's deprecated and not needed anymore. See https://github.com/postcss/postcss-import#adddependencyto * Enabled HMR for styles by disabling extracting them to a CSS file * Remove lib from repo * Remove lib * Fixes #1021 * Build using Gulp * Export ThemeProvider from react-css-themr * Add CHANGELOG to release command * Release 2.0.0-beta.1 * Remove immutability helper * Update dependencies * Fix Tooltip trying to render after it's been unmounted * Fixes #1038 * Release 2.0.0-beta.2 * Add ramda, refactor utils and remove slide animation modules * Remove separate slide animations modules * Remove box-sizing reset and body rule * Remove commons.css * Release 2.0.0-beta.4 * Update dependencies * Fixes #1061 * More aggresive guard condition for multiple autocomplete * Fix typeof check in isBrowser function * Fixes an issue when specs are opened with browsers that do not support Object.entries(). * Import from ramda using the 'import XXX from "ramda/src/XXX"' pattern so that bundle sizes will be smaller for not including the whole ramda package. * Fix #1032 * Fix tests * Update yarn.lock * Fixes #1064
2017-01-05 04:42:18 +03:00
self.setState({ ripples: dissoc(rippleKey, self.state.ripples) });
2016-08-06 15:24:40 +03:00
}
});
2016-04-12 22:41:28 +03:00
}
2016-08-06 15:24:40 +03:00
/**
* Start a ripple animation on an specific point with touch or mouse events. First
* decides if the animation should trigger. If the ripple is multiple or there is no
* ripple present, it creates a new key. If it's a simple ripple and already exists,
* it just restarts the current ripple. The animation happens in two state changes
* to allow triggering via css.
*
* @param {Number} x Coordinate X on the screen where animation should start
* @param {Number} y Coordinate Y on the screen where animation should start
* @param {Boolean} isTouch Use events from touch or mouse.
*/
animateRipple (x, y, isTouch) {
if (this.rippleShouldTrigger(isTouch)) {
const { top, left, width } = this.getDescriptor(x, y);
const noRipplesActive = Object.keys(this.state.ripples).length === 0;
const key = this.props.rippleMultiple || noRipplesActive ? this.getNextKey() : this.getLastKey();
2016-08-06 21:40:24 +03:00
const endRipple = this.addRippleDeactivateEventListener(isTouch, key);
const initialState = { active: false, restarting: true, top, left, width, endRipple };
2016-08-06 15:24:40 +03:00
const runningState = { active: true, restarting: false };
Migrate styles to PostCSS (#666) * Add postcss-next postcss-include and reporter * Add stylelint * Add CSS colors * Add CSS custom media queries * Use dashes for CSS colors * Add base CSS variables * Remove AppBar SASS dependency from spec page * Migrate AppBar style to PostCSS * Migrate Avatar style to PostCSS * Migrate Ripple style to PostCSS * Remove unneeded media CSS import in Avatar * Add shadows to CSS variables * Migrate Button style to PostCSS * Update webpack test config and linting from npm * Migrate Input style to PostCSS * Add missing input config variables for Dropdown and Autocomplete * Migrate Chip style to PostCSS * Migrate Autocomplete style to PostCSS * Migrate Dropdown style to PostCSS * Migrate animations to PostCSS * Migrate Card style to PostCSS * Migrate Checkbox style to PostCSS * Migrate DataPicker style to PostCSS * Migrate Dialog style to PostCSS * Migrate Drawer style to PostCSS * Add postcss-mixins and postcss-each * Migrate Layout style to PostCSS * Fix bug in button theme * Bugfix in avatar css * Add some missing nesting notations * Migrate Link style to PostCSS * Migrate List style to PostCSS * Migrate Menu style to PostCSS * Migrate Navigation style to PostCSS * Migrate Overlay style to PostCSS * Migrate ProgressBar style to PostCSS * Migrate Radio style to PostCSS * Migrate Slider style to PostCSS * Migrate Snackbar style to PostCSS * Migrate Switch style to PostCSS * Migrate Table style to PostCSS * Migrate Tabs style to PostCSS * Migrate TimePicker to PostCSS * Migrate Tooltip styles to PostCSS * Update webpack config for testing and tests * Migrate commons to PostCSS * Remove sass from main project * Bye from docs to sass * Build with CSS * Remove unneded deps for sass in docs subproject * Fix tests * use 4p shadow in AppBar as spec indicates * Fixed typo in list/config.css * Fix tests * Fix linter errors * Latest build * Release 2.0.0-beta.0 * Remove sass lint * fixes old sass var in css config * Update linter * New Table implementation * Fix old sass var in list/config.css See da0c47041ecf2d8b118b06fba9f53cc4d7e1e79f. * Remove normalize.css from commons.css * Update dependencies * Latest build * Input ready to accept visible hint * Prepare slider and progress to be disabled * Render Snackbar using Portal * Refactor Dialog, Drawer and Overlay to be used in Layout * Add inner layer to AppBar * New layout * Use Layout in spec * Latest build * remove layout playground example * add smTablet and lgTablet to NavDrawer in Layout readme * add default prop className to Layout, NavDrawer and Sidebar * fix css linter errors in card and slider * Typings for Table component * Add missing Drawer identifier * Update lib build * Adds onQueryChange callback property to Autocomplete The onQueryChange callback is called when the value of the query changes in Autocomplete. It is called with the new query value. * Fix #966 * Fix #965 * Fixes #976 * Updated css-related dependencies Removed usages of `addDependencyTo` since it's deprecated and not needed anymore. See https://github.com/postcss/postcss-import#adddependencyto * Enabled HMR for styles by disabling extracting them to a CSS file * Remove lib from repo * Remove lib * Fixes #1021 * Build using Gulp * Export ThemeProvider from react-css-themr * Add CHANGELOG to release command * Release 2.0.0-beta.1 * Remove immutability helper * Update dependencies * Fix Tooltip trying to render after it's been unmounted * Fixes #1038 * Release 2.0.0-beta.2 * Add ramda, refactor utils and remove slide animation modules * Remove separate slide animations modules * Remove box-sizing reset and body rule * Remove commons.css * Release 2.0.0-beta.4 * Update dependencies * Fixes #1061 * More aggresive guard condition for multiple autocomplete * Fix typeof check in isBrowser function * Fixes an issue when specs are opened with browsers that do not support Object.entries(). * Import from ramda using the 'import XXX from "ramda/src/XXX"' pattern so that bundle sizes will be smaller for not including the whole ramda package. * Fix #1032 * Fix tests * Update yarn.lock * Fixes #1064
2017-01-05 04:42:18 +03:00
const ripples = {...this.state.ripples, [key]: initialState };
this.setState({ ripples }, () => {
if (this.refs[key]) this.refs[key].offsetWidth; //eslint-disable-line no-unused-expressions
Migrate styles to PostCSS (#666) * Add postcss-next postcss-include and reporter * Add stylelint * Add CSS colors * Add CSS custom media queries * Use dashes for CSS colors * Add base CSS variables * Remove AppBar SASS dependency from spec page * Migrate AppBar style to PostCSS * Migrate Avatar style to PostCSS * Migrate Ripple style to PostCSS * Remove unneeded media CSS import in Avatar * Add shadows to CSS variables * Migrate Button style to PostCSS * Update webpack test config and linting from npm * Migrate Input style to PostCSS * Add missing input config variables for Dropdown and Autocomplete * Migrate Chip style to PostCSS * Migrate Autocomplete style to PostCSS * Migrate Dropdown style to PostCSS * Migrate animations to PostCSS * Migrate Card style to PostCSS * Migrate Checkbox style to PostCSS * Migrate DataPicker style to PostCSS * Migrate Dialog style to PostCSS * Migrate Drawer style to PostCSS * Add postcss-mixins and postcss-each * Migrate Layout style to PostCSS * Fix bug in button theme * Bugfix in avatar css * Add some missing nesting notations * Migrate Link style to PostCSS * Migrate List style to PostCSS * Migrate Menu style to PostCSS * Migrate Navigation style to PostCSS * Migrate Overlay style to PostCSS * Migrate ProgressBar style to PostCSS * Migrate Radio style to PostCSS * Migrate Slider style to PostCSS * Migrate Snackbar style to PostCSS * Migrate Switch style to PostCSS * Migrate Table style to PostCSS * Migrate Tabs style to PostCSS * Migrate TimePicker to PostCSS * Migrate Tooltip styles to PostCSS * Update webpack config for testing and tests * Migrate commons to PostCSS * Remove sass from main project * Bye from docs to sass * Build with CSS * Remove unneded deps for sass in docs subproject * Fix tests * use 4p shadow in AppBar as spec indicates * Fixed typo in list/config.css * Fix tests * Fix linter errors * Latest build * Release 2.0.0-beta.0 * Remove sass lint * fixes old sass var in css config * Update linter * New Table implementation * Fix old sass var in list/config.css See da0c47041ecf2d8b118b06fba9f53cc4d7e1e79f. * Remove normalize.css from commons.css * Update dependencies * Latest build * Input ready to accept visible hint * Prepare slider and progress to be disabled * Render Snackbar using Portal * Refactor Dialog, Drawer and Overlay to be used in Layout * Add inner layer to AppBar * New layout * Use Layout in spec * Latest build * remove layout playground example * add smTablet and lgTablet to NavDrawer in Layout readme * add default prop className to Layout, NavDrawer and Sidebar * fix css linter errors in card and slider * Typings for Table component * Add missing Drawer identifier * Update lib build * Adds onQueryChange callback property to Autocomplete The onQueryChange callback is called when the value of the query changes in Autocomplete. It is called with the new query value. * Fix #966 * Fix #965 * Fixes #976 * Updated css-related dependencies Removed usages of `addDependencyTo` since it's deprecated and not needed anymore. See https://github.com/postcss/postcss-import#adddependencyto * Enabled HMR for styles by disabling extracting them to a CSS file * Remove lib from repo * Remove lib * Fixes #1021 * Build using Gulp * Export ThemeProvider from react-css-themr * Add CHANGELOG to release command * Release 2.0.0-beta.1 * Remove immutability helper * Update dependencies * Fix Tooltip trying to render after it's been unmounted * Fixes #1038 * Release 2.0.0-beta.2 * Add ramda, refactor utils and remove slide animation modules * Remove separate slide animations modules * Remove box-sizing reset and body rule * Remove commons.css * Release 2.0.0-beta.4 * Update dependencies * Fixes #1061 * More aggresive guard condition for multiple autocomplete * Fix typeof check in isBrowser function * Fixes an issue when specs are opened with browsers that do not support Object.entries(). * Import from ramda using the 'import XXX from "ramda/src/XXX"' pattern so that bundle sizes will be smaller for not including the whole ramda package. * Fix #1032 * Fix tests * Update yarn.lock * Fixes #1064
2017-01-05 04:42:18 +03:00
this.setState({ ripples: {
...this.state.ripples,
[key]: Object.assign({}, this.state.ripples[key], runningState)
} });
2015-12-07 04:34:12 +03:00
});
}
2016-08-06 15:24:40 +03:00
}
2015-11-29 14:40:09 +03:00
2016-08-06 15:24:40 +03:00
/**
* Determine if a ripple should start depending if its a touch event. For mobile both
* touchStart and mouseDown are launched so in case is touch we should always trigger
* but if its not we should check if a touch was already triggered to decide.
*
* @param {Boolean} isTouch True in case a touch event triggered the ripple false otherwise.
* @return {Boolean} True in case the ripple should trigger or false if it shouldn't.
*/
rippleShouldTrigger (isTouch) {
const shouldStart = isTouch ? true : !this.touchCache;
this.touchCache = isTouch;
return shouldStart;
2015-12-07 04:34:12 +03:00
}
2016-08-06 15:24:40 +03:00
/**
* Find out a descriptor object for the ripple element being created depending on
* the position where the it was triggered and the component's dimensions.
*
* @param {Number} x Coordinate x in the viewport where ripple was triggered
* @param {Number} y Coordinate y in the viewport where ripple was triggered
* @return {Object} Descriptor element including position and size of the element
*/
getDescriptor (x, y) {
const { left, top, height, width } = ReactDOM.findDOMNode(this).getBoundingClientRect();
const { rippleCentered: centered, rippleSpread: spread } = this.props;
2015-12-07 04:34:12 +03:00
return {
2016-08-06 15:24:40 +03:00
left: centered ? 0 : x - left - width / 2,
top: centered ? 0 : y - top - height / 2,
2015-12-07 04:34:12 +03:00
width: width * spread
};
}
2016-08-06 15:24:40 +03:00
/**
* Increments and internal counter and returns the next value as a string. It
* is used to assign key references to new ripple elements.
*
* @return {String} Key to be assigned to a ripple.
*/
getNextKey () {
this.currentCount = this.currentCount ? this.currentCount + 1 : 1;
2016-08-21 19:44:04 +03:00
return `ripple${this.currentCount}`;
2016-08-06 15:24:40 +03:00
}
/**
* Return the last generated key for a ripple element. When there is only one ripple
* and to get the reference when a ripple was just created.
*
* @return {String} The last generated ripple key.
*/
getLastKey () {
2016-08-21 19:44:04 +03:00
return `ripple${this.currentCount}`;
2016-08-06 15:24:40 +03:00
}
/**
2016-08-06 21:40:24 +03:00
* Add an event listener to the document needed to deactivate a ripple and make it dissappear.
* Deactivation can happen with a touchend or mouseup depending on the trigger type. The
* ending function is created from a factory function and returned.
2016-08-06 15:24:40 +03:00
*
* @param {Boolean} isTouch True in case the trigger was a touch event false otherwise.
* @param {String} rippleKey It's a key to identify the ripple that should be deactivated.
2016-08-06 21:40:24 +03:00
* @return {Function} Callback function that deactivates the ripple and removes the event listener
2016-08-06 15:24:40 +03:00
*/
addRippleDeactivateEventListener (isTouch, rippleKey) {
const eventType = isTouch ? 'touchend' : 'mouseup';
2016-08-06 21:40:24 +03:00
const endRipple = this.createRippleDeactivateCallback(eventType, rippleKey);
document.addEventListener(eventType, endRipple);
return endRipple;
}
/**
* Generates a function that can be called to deactivate a given ripple and remove its finishing
* event listener. If is generated because we need to store it to be called on unmount in case
* the ripple is still running.
*
* @param {String} eventType Is the event type that can be touchend or mouseup
* @param {String} rippleKey Is the key representing the ripple
* @return {Function} Callback function that deactivates the ripple and removes the listener
*/
createRippleDeactivateCallback (eventType, rippleKey) {
const self = this;
return function endRipple () {
2016-08-06 15:24:40 +03:00
document.removeEventListener(eventType, endRipple);
Migrate styles to PostCSS (#666) * Add postcss-next postcss-include and reporter * Add stylelint * Add CSS colors * Add CSS custom media queries * Use dashes for CSS colors * Add base CSS variables * Remove AppBar SASS dependency from spec page * Migrate AppBar style to PostCSS * Migrate Avatar style to PostCSS * Migrate Ripple style to PostCSS * Remove unneeded media CSS import in Avatar * Add shadows to CSS variables * Migrate Button style to PostCSS * Update webpack test config and linting from npm * Migrate Input style to PostCSS * Add missing input config variables for Dropdown and Autocomplete * Migrate Chip style to PostCSS * Migrate Autocomplete style to PostCSS * Migrate Dropdown style to PostCSS * Migrate animations to PostCSS * Migrate Card style to PostCSS * Migrate Checkbox style to PostCSS * Migrate DataPicker style to PostCSS * Migrate Dialog style to PostCSS * Migrate Drawer style to PostCSS * Add postcss-mixins and postcss-each * Migrate Layout style to PostCSS * Fix bug in button theme * Bugfix in avatar css * Add some missing nesting notations * Migrate Link style to PostCSS * Migrate List style to PostCSS * Migrate Menu style to PostCSS * Migrate Navigation style to PostCSS * Migrate Overlay style to PostCSS * Migrate ProgressBar style to PostCSS * Migrate Radio style to PostCSS * Migrate Slider style to PostCSS * Migrate Snackbar style to PostCSS * Migrate Switch style to PostCSS * Migrate Table style to PostCSS * Migrate Tabs style to PostCSS * Migrate TimePicker to PostCSS * Migrate Tooltip styles to PostCSS * Update webpack config for testing and tests * Migrate commons to PostCSS * Remove sass from main project * Bye from docs to sass * Build with CSS * Remove unneded deps for sass in docs subproject * Fix tests * use 4p shadow in AppBar as spec indicates * Fixed typo in list/config.css * Fix tests * Fix linter errors * Latest build * Release 2.0.0-beta.0 * Remove sass lint * fixes old sass var in css config * Update linter * New Table implementation * Fix old sass var in list/config.css See da0c47041ecf2d8b118b06fba9f53cc4d7e1e79f. * Remove normalize.css from commons.css * Update dependencies * Latest build * Input ready to accept visible hint * Prepare slider and progress to be disabled * Render Snackbar using Portal * Refactor Dialog, Drawer and Overlay to be used in Layout * Add inner layer to AppBar * New layout * Use Layout in spec * Latest build * remove layout playground example * add smTablet and lgTablet to NavDrawer in Layout readme * add default prop className to Layout, NavDrawer and Sidebar * fix css linter errors in card and slider * Typings for Table component * Add missing Drawer identifier * Update lib build * Adds onQueryChange callback property to Autocomplete The onQueryChange callback is called when the value of the query changes in Autocomplete. It is called with the new query value. * Fix #966 * Fix #965 * Fixes #976 * Updated css-related dependencies Removed usages of `addDependencyTo` since it's deprecated and not needed anymore. See https://github.com/postcss/postcss-import#adddependencyto * Enabled HMR for styles by disabling extracting them to a CSS file * Remove lib from repo * Remove lib * Fixes #1021 * Build using Gulp * Export ThemeProvider from react-css-themr * Add CHANGELOG to release command * Release 2.0.0-beta.1 * Remove immutability helper * Update dependencies * Fix Tooltip trying to render after it's been unmounted * Fixes #1038 * Release 2.0.0-beta.2 * Add ramda, refactor utils and remove slide animation modules * Remove separate slide animations modules * Remove box-sizing reset and body rule * Remove commons.css * Release 2.0.0-beta.4 * Update dependencies * Fixes #1061 * More aggresive guard condition for multiple autocomplete * Fix typeof check in isBrowser function * Fixes an issue when specs are opened with browsers that do not support Object.entries(). * Import from ramda using the 'import XXX from "ramda/src/XXX"' pattern so that bundle sizes will be smaller for not including the whole ramda package. * Fix #1032 * Fix tests * Update yarn.lock * Fixes #1064
2017-01-05 04:42:18 +03:00
self.setState({ ripples: {
...self.state.ripples,
[rippleKey]: Object.assign({}, self.state.ripples[rippleKey], { active: false })
} });
2016-08-06 21:40:24 +03:00
};
2016-08-06 15:24:40 +03:00
}
2015-12-07 04:34:12 +03:00
handleMouseDown = (event) => {
if (this.props.onMouseDown) this.props.onMouseDown(event);
2016-08-06 15:24:40 +03:00
if (!this.props.disabled) {
const { x, y } = events.getMousePosition(event);
this.animateRipple(x, y, false);
}
};
handleTouchStart = (event) => {
if (this.props.onTouchStart) this.props.onTouchStart(event);
if (!this.props.disabled) {
const { x, y } = events.getTouchPosition(event);
this.animateRipple(x, y, true);
}
2015-12-07 04:34:12 +03:00
};
2016-08-06 15:24:40 +03:00
renderRipple (key, className, { active, left, restarting, top, width }) {
const scale = restarting ? 0 : 1;
const transform = `translate3d(${-width / 2 + left}px, ${-width / 2 + top}px, 0) scale(${scale})`;
const _className = classnames(this.props.theme.ripple, {
[this.props.theme.rippleActive]: active,
[this.props.theme.rippleRestarting]: restarting
}, className);
return (
<span key={key} data-react-toolbox='ripple' className={this.props.theme.rippleWrapper} {...props}>
<span
role='ripple'
ref={key}
className={_className}
style={prefixer({ transform }, {width, height: width})}
/>
</span>
);
}
2015-12-07 04:34:12 +03:00
render () {
2017-01-23 12:44:24 +03:00
const {
children,
disabled,
ripple,
onRippleEnded, // eslint-disable-line
rippleCentered, // eslint-disable-line
rippleClassName, // eslint-disable-line
rippleMultiple, // eslint-disable-line
rippleSpread, // eslint-disable-line
theme,
...other
} = this.props;
2016-09-05 21:28:24 +03:00
const { ripples } = this.state;
2017-01-23 12:44:24 +03:00
const childRipples = Object.keys(ripples).map(key => this.renderRipple(key, rippleClassName, ripples[key]));
const childProps = { onMouseDown: this.handleMouseDown, onTouchStart: this.handleTouchStart, ...other };
const finalProps = defaultPassthrough ? { ...childProps, theme, disabled } : childProps;
2016-09-05 21:28:24 +03:00
2017-01-23 12:44:24 +03:00
return !ripple
? React.createElement(ComposedComponent, finalProps, children)
: React.createElement(ComposedComponent, finalProps, [children, childRipples]);
2015-12-07 04:34:12 +03:00
}
2016-05-16 15:17:26 +03:00
}
2016-05-28 16:37:10 +03:00
return themr(RIPPLE, defaultTheme)(RippledComponent);
2015-12-07 04:34:12 +03:00
};
};
2016-05-28 16:37:10 +03:00
export default rippleFactory;