-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(grid-component): improve end of drag events of the grid elements,…
… animate over other elements refactor(grid-component): added useful comments on 'addGridItemAnimatingClass'
- Loading branch information
1 parent
bb8598b
commit 251c1bb
Showing
3 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
projects/angular-grid-layout/src/lib/utils/transition-duration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Transition duration utilities. | ||
* This file is taken from Angular Material repository. | ||
*/ | ||
|
||
/* eslint-disable @katoid/prefix-exported-code */ | ||
|
||
/** Parses a CSS time value to milliseconds. */ | ||
function parseCssTimeUnitsToMs(value: string): number { | ||
// Some browsers will return it in seconds, whereas others will return milliseconds. | ||
const multiplier = value.toLowerCase().indexOf('ms') > -1 ? 1 : 1000; | ||
return parseFloat(value) * multiplier; | ||
} | ||
|
||
/** Gets the transform transition duration, including the delay, of an element in milliseconds. */ | ||
export function getTransformTransitionDurationInMs(element: HTMLElement): number { | ||
const computedStyle = getComputedStyle(element); | ||
const transitionedProperties = parseCssPropertyValue(computedStyle, 'transition-property'); | ||
const property = transitionedProperties.find(prop => prop === 'transform' || prop === 'all'); | ||
|
||
// If there's no transition for `all` or `transform`, we shouldn't do anything. | ||
if (!property) { | ||
return 0; | ||
} | ||
|
||
// Get the index of the property that we're interested in and match | ||
// it up to the same index in `transition-delay` and `transition-duration`. | ||
const propertyIndex = transitionedProperties.indexOf(property); | ||
const rawDurations = parseCssPropertyValue(computedStyle, 'transition-duration'); | ||
const rawDelays = parseCssPropertyValue(computedStyle, 'transition-delay'); | ||
|
||
return parseCssTimeUnitsToMs(rawDurations[propertyIndex]) + | ||
parseCssTimeUnitsToMs(rawDelays[propertyIndex]); | ||
} | ||
|
||
/** Parses out multiple values from a computed style into an array. */ | ||
function parseCssPropertyValue(computedStyle: CSSStyleDeclaration, name: string): string[] { | ||
const value = computedStyle.getPropertyValue(name); | ||
return value.split(',').map(part => part.trim()); | ||
} |