Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(loaders): fix Dot loader for IE11 #936

Merged
merged 3 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/loaders/.size-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
}
},
"index.cjs.js": {
"bundled": 26822,
"minified": 19885,
"gzipped": 5153
"bundled": 26190,
"minified": 19459,
"gzipped": 5017
},
"index.esm.js": {
"bundled": 25021,
"minified": 18294,
"gzipped": 4999,
"bundled": 24398,
"minified": 17875,
"gzipped": 4873,
"treeshaked": {
"rollup": {
"code": 14395,
"import_statements": 366
"code": 14041,
"import_statements": 403
},
"webpack": {
"code": 16324
"code": 15958
}
}
}
Expand Down
25 changes: 18 additions & 7 deletions packages/loaders/src/elements/Dots.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import React from 'react';
import { render, act } from 'garden-test-utils';
import mockDate from 'mockdate';
import Dots from './Dots';
import { useCSSSVGAnimation } from '../utils/useCSSSVGAnimation';

jest.useFakeTimers();
jest.mock('../utils/useCSSSVGAnimation', () => ({
useCSSSVGAnimation: jest.fn(() => false)
}));

const DEFAULT_DATE = new Date(2019, 1, 5, 1, 1, 1);

Expand Down Expand Up @@ -51,7 +47,6 @@ describe('Dots', () => {

describe('Animation', () => {
it('relies on svg transition attribute if css svg animation is not supported', () => {
(useCSSSVGAnimation as jest.Mock).mockReturnValue(true);
const { container } = render(<Dots data-test-id="dots" />);

act(() => {
Expand Down Expand Up @@ -100,8 +95,6 @@ describe('Dots', () => {
/>
</g>
`);

(useCSSSVGAnimation as jest.Mock).mockReset();
});

it('updates animation after request animation frame', () => {
Expand Down Expand Up @@ -135,18 +128,21 @@ describe('Dots', () => {
cx="9"
cy="36"
r="9"
transform=""
/>
<circle
class="c1"
cx="40"
cy="36"
r="9"
transform=""
/>
<circle
class="c2"
cx="71"
cy="36"
r="9"
transform=""
/>
</g>
`);
Expand All @@ -166,18 +162,21 @@ describe('Dots', () => {
cx="9"
cy="36"
r="9"
transform=""
/>
<circle
class="sc-bdVaJa sc-htpNat yBsjz"
cx="40"
cy="36"
r="9"
transform=""
/>
<circle
class="sc-bdVaJa sc-bxivhb eQgpbI"
cx="71"
cy="36"
r="9"
transform=""
/>
</g>
`);
Expand Down Expand Up @@ -214,18 +213,21 @@ describe('Dots', () => {
cx="9"
cy="36"
r="9"
transform=""
/>
<circle
class="c1"
cx="40"
cy="36"
r="9"
transform=""
/>
<circle
class="c2"
cx="71"
cy="36"
r="9"
transform=""
/>
</g>
`);
Expand All @@ -245,18 +247,21 @@ describe('Dots', () => {
cx="9"
cy="36"
r="9"
transform=""
/>
<circle
class="sc-bdVaJa sc-htpNat kPGrdX"
cx="40"
cy="36"
r="9"
transform=""
/>
<circle
class="sc-bdVaJa sc-bxivhb hGBsiB"
cx="71"
cy="36"
r="9"
transform=""
/>
</g>
`);
Expand Down Expand Up @@ -293,18 +298,21 @@ describe('Dots', () => {
cx="9"
cy="36"
r="9"
transform=""
/>
<circle
class="c1"
cx="40"
cy="36"
r="9"
transform=""
/>
<circle
class="c2"
cx="71"
cy="36"
r="9"
transform=""
/>
</g>
`);
Expand All @@ -324,18 +332,21 @@ describe('Dots', () => {
cx="9"
cy="36"
r="9"
transform=""
/>
<circle
class="sc-bdVaJa sc-htpNat gYiuXr"
cx="40"
cy="36"
r="9"
transform=""
/>
<circle
class="sc-bdVaJa sc-bxivhb iRhcNm"
cx="71"
cy="36"
r="9"
transform=""
/>
</g>
`);
Expand Down
20 changes: 15 additions & 5 deletions packages/loaders/src/elements/Dots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

import React, { useEffect, useRef } from 'react';
import React, { useEffect, useRef, useContext } from 'react';
import PropTypes from 'prop-types';
import { ThemeContext } from 'styled-components';
import { useSchedule } from '@zendeskgarden/container-schedule';
import { useDocument } from '@zendeskgarden/react-theming';
import {
StyledDotsCircleOne,
StyledDotsCircleTwo,
StyledDotsCircleThree,
StyledSVG,
StyledLoadingPlaceholder
} from '../styled';
import { useCSSSVGAnimation } from '../utils/useCSSSVGAnimation';

const COMPONENT_ID = 'loaders.dots';

Expand All @@ -39,14 +40,23 @@ export interface IDotsProps extends React.HTMLAttributes<SVGSVGElement> {
}

const Dots: React.FC<IDotsProps> = ({ size, color, duration, delayMS, ...other }) => {
const noAnimatedSVGSupport = useCSSSVGAnimation();
const { delayComplete } = useSchedule({ duration, delayMS, loop: noAnimatedSVGSupport });
const theme = useContext(ThemeContext);
const environment = useDocument(theme);
const canTransformSVG = useRef<boolean | null>(null);
austingreendev marked this conversation as resolved.
Show resolved Hide resolved

if (environment && canTransformSVG.current === null) {
const svg = environment.createElementNS('http://www.w3.org/2000/svg', 'svg');

canTransformSVG.current = 'transform' in svg;
}
austingreendev marked this conversation as resolved.
Show resolved Hide resolved

const { delayComplete } = useSchedule({ duration, delayMS, loop: true });
const dotOne = useRef<SVGCircleElement>(null);
const dotTwo = useRef<SVGCircleElement>(null);
const dotThree = useRef<SVGCircleElement>(null);

useEffect(() => {
if (noAnimatedSVGSupport && delayComplete) {
if (!canTransformSVG.current && delayComplete) {
const transforms = [
window.getComputedStyle(dotOne.current!).getPropertyValue('transform'),
window.getComputedStyle(dotTwo.current!).getPropertyValue('transform'),
Expand Down
28 changes: 0 additions & 28 deletions packages/loaders/src/utils/useCSSSVGAnimation.spec.tsx

This file was deleted.

39 changes: 0 additions & 39 deletions packages/loaders/src/utils/useCSSSVGAnimation.ts

This file was deleted.