From 4666190a00db1264535f57ee6843d318194cbf1a Mon Sep 17 00:00:00 2001 From: Samy Rahmani <99157490+samyosm@users.noreply.github.com> Date: Sun, 29 Jan 2023 10:05:02 -0500 Subject: [PATCH] Add stroke width to TailSpin circle (Issue #144) (#148) * Added strokeWidth property to TailSpin & changed tests appropriately * Fixed parsing issues --- src/loader/TailSpin.tsx | 114 ++++++++++++++++++---------------- test/loader/TailSpin.spec.tsx | 5 +- 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/src/loader/TailSpin.tsx b/src/loader/TailSpin.tsx index 6e4de962..1e7ffd9d 100644 --- a/src/loader/TailSpin.tsx +++ b/src/loader/TailSpin.tsx @@ -3,71 +3,79 @@ import { getDefaultStyle } from '../helpers' import { BaseProps, DEFAULT_COLOR, DEFAULT_WAI_ARIA_ATTRIBUTE } from '../type' interface TailSpinProps extends BaseProps { - radius?: string | number + radius?: string | number, + strokeWidth?: string | number } export const TailSpin: FunctionComponent = ({ height = 80, width = 80, + strokeWidth = 2, radius = 1, color = DEFAULT_COLOR, ariaLabel = 'tail-spin-loading', wrapperStyle, wrapperClass, visible = true, -}): ReactElement => ( -
- { + const strokeWidthNum = parseInt(String(strokeWidth)); + const viewBoxValue = strokeWidthNum + 36; + const halfStrokeWidth = strokeWidthNum / 2; + const processedRadius = halfStrokeWidth + parseInt(String(radius)) - 1; + return ( +
- - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - -
-) + +
+ ) +} export default TailSpin diff --git a/test/loader/TailSpin.spec.tsx b/test/loader/TailSpin.spec.tsx index e3b50650..f7bc9a9b 100644 --- a/test/loader/TailSpin.spec.tsx +++ b/test/loader/TailSpin.spec.tsx @@ -30,6 +30,7 @@ describe('TailSpin', () => { }) svg.querySelectorAll('path').forEach(path => { expect(path).toHaveAttribute('stroke', DEFAULT_COLOR) + expect(path).toHaveAttribute('stroke-width', "2") }) }) @@ -43,6 +44,7 @@ describe('TailSpin', () => { wrapperClass="test-class" wrapperStyle={{ opacity: '1' }} radius={10} + strokeWidth={3} /> ) const component = screen.getByTestId(wrapperTestId) @@ -64,10 +66,11 @@ describe('TailSpin', () => { }) svg.querySelectorAll('circle').forEach(circle => { - expect(circle).toHaveAttribute('r', '10') + expect(circle).toHaveAttribute('r', '10.5') // r-1 + stroke-width/2 }) svg.querySelectorAll('path').forEach(path => { expect(path).toHaveAttribute('stroke', 'red') + expect(path).toHaveAttribute('stroke-width','3') }) })