From 0b15259b33ef2c261ffd1a2b39f2c29af40b31ad Mon Sep 17 00:00:00 2001 From: Andrew Holloway Date: Fri, 10 Mar 2023 13:56:36 -0600 Subject: [PATCH] feat(LoadingIndicator): extract and use SVG animation directly - we only have one particular loading indicator we want to use at this time - apply styles and parameters to match previous implementation's output --- package.json | 1 - .../LoadingIndicator.module.css | 6 ++ .../LoadingIndicator/LoadingIndicator.tsx | 76 ++++++++++++++----- .../LoadingIndicator.test.ts.snap | 8 +- yarn.lock | 26 +------ 5 files changed, 65 insertions(+), 52 deletions(-) diff --git a/package.json b/package.json index 9c1679988..4db9b2fff 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,6 @@ "react-beautiful-dnd": "^13.1.1", "react-children-by-type": "^1.1.0", "react-focus-lock": "^2.9.4", - "react-loader-spinner": "^5.3.4", "react-popper": "^2.3.0", "react-portal": "^4.2.2" }, diff --git a/src/components/LoadingIndicator/LoadingIndicator.module.css b/src/components/LoadingIndicator/LoadingIndicator.module.css index 193eda4c0..e53820ccf 100644 --- a/src/components/LoadingIndicator/LoadingIndicator.module.css +++ b/src/components/LoadingIndicator/LoadingIndicator.module.css @@ -7,6 +7,12 @@ */ .loading-indicator { background-color: transparent; + padding: 3px; /* ported from react-loader-spinner */ + display: flex; +} + +.loading-indicator--invisible { + display: none; } /* override for `color` */ diff --git a/src/components/LoadingIndicator/LoadingIndicator.tsx b/src/components/LoadingIndicator/LoadingIndicator.tsx index b00eb6d82..8aeba4074 100644 --- a/src/components/LoadingIndicator/LoadingIndicator.tsx +++ b/src/components/LoadingIndicator/LoadingIndicator.tsx @@ -1,7 +1,6 @@ import clsx from 'clsx'; import React from 'react'; -import { Oval } from 'react-loader-spinner'; import styles from './LoadingIndicator.module.css'; export type Props = { @@ -18,17 +17,11 @@ export type Props = { /** * Aria label of the oval. Default is "loading". Will be overridden if ariaLabel is passed in props - * (Shadowed from OvalProps) - * - * See: https://mhnpd.github.io/react-loader-spinner/docs/components/oval */ ariaLabel?: string; /** * Whether the oval is visible. Default is true. - * (Shadowed from OvalProps) - * - * See: https://mhnpd.github.io/react-loader-spinner/docs/components/oval */ visible?: boolean; }; @@ -47,6 +40,13 @@ const loaderStrokeSize = { lg: 4, }; +// The viewport changes based on adjustments to handle the stroke width +const loaderViewportSize = { + sm: '-20 -20 42 42', + md: '-20.5 -20.5 43 43', + lg: '-21 -21 44 44', +}; + /** * BETA: This component is still a work in progress and is subject to change. * @@ -54,7 +54,7 @@ const loaderStrokeSize = { * * Loading indicators inform users about the wait time, reason, and status of ongoing processes when the layout is unknown * - * For screen readers, add an `aria-label` to describe what is loading. + * For screen readers, add a custom `aria-label` to describe what is loading. * */ export const LoadingIndicator = ({ @@ -64,22 +64,58 @@ export const LoadingIndicator = ({ visible = true, ...other }: Props) => { - const componentClassName = clsx(styles['loading-indicator'], className); + const componentClassName = clsx( + styles['loading-indicator'], + !visible && styles['loading-indicator--invisible'], + className, + ); // setting the colors to be transparent since we override in CSS // (and have a lint rule prevent token variable use in components) return ( - + > + + + + + + + + + + + ); }; diff --git a/src/components/LoadingIndicator/__snapshots__/LoadingIndicator.test.ts.snap b/src/components/LoadingIndicator/__snapshots__/LoadingIndicator.test.ts.snap index 02f6f3e9b..031bae074 100644 --- a/src/components/LoadingIndicator/__snapshots__/LoadingIndicator.test.ts.snap +++ b/src/components/LoadingIndicator/__snapshots__/LoadingIndicator.test.ts.snap @@ -7,7 +7,6 @@ exports[` Default story renders snapshot 1`] = ` class="loading-indicator" data-testid="oval-loading" role="status" - style="display: flex; padding: 3px;" > Invisible story renders snapshot 1`] = `