11import React , { useCallback , FunctionComponent } from 'react'
22import styled , { keyframes } from 'styled-components'
3- import { DEFAULT_COLOR , DEFAULT_WAI_ARIA_ATTRIBUTE } from '../type'
3+ import { BaseProps , DEFAULT_COLOR , DEFAULT_WAI_ARIA_ATTRIBUTE } from '../type'
44import { SVG_NAMESPACE } from '../shared/constants'
5+ import { SvgWrapper } from '../shared/svg-wrapper'
56
6- type Props = {
7- width ?: string
8- visible ?: boolean
9- strokeWidth ?: string
7+ interface Props extends BaseProps {
8+ strokeWidth ?: string | number
9+ animationDuration ?: string | number
1010 strokeColor ?: string
11- animationDuration ?: string
12- ariaLabel ?: string
1311}
1412
1513const POINTS = [ 0 , 30 , 60 , 90 , 120 , 150 , 180 , 210 , 240 , 270 , 300 , 330 ]
1917 transform: rotate(360deg);
2018 }
2119`
22- const Svg = styled . svg `
23- animation: ${ spin } 0.75s steps(12, end) infinite;
24- animation-duration: 0.75s ;
20+
21+ const Svg = styled . svg < { $animationDuration : string | number } > `
22+ animation: ${ spin } ${ props => ( String ( props . $animationDuration ) . endsWith ( 's' ) ? String ( props . $animationDuration ) : ` ${ props . $animationDuration } s` ) } steps(12, end) infinite ;
2523`
2624
27- const Polyline = styled . polyline `
28- stroke-width: ${ props => props . width } px;
25+ const Polyline = styled . polyline < { $strokeWidth : string | number } > `
26+ stroke-width: ${ props => ` ${ props . $strokeWidth } px` } ;
2927 stroke-linecap: round;
3028
3129 &:nth-child(12n + 0) {
@@ -74,12 +72,16 @@ const Polyline = styled.polyline`
7472`
7573
7674export const RotatingLines : FunctionComponent < Props > = ( {
77- strokeColor = DEFAULT_COLOR ,
78- strokeWidth = '5' ,
79- animationDuration = '0.75' ,
80- width = '96' ,
75+ height = 96 ,
76+ width = 96 ,
77+ color = DEFAULT_COLOR ,
78+ strokeWidth = 5 ,
79+ animationDuration = 0.75 ,
80+ strokeColor,
8181 visible = true ,
8282 ariaLabel = 'rotating-lines-loading' ,
83+ wrapperStyle,
84+ wrapperClass,
8385} ) : React . ReactElement | null => {
8486 const lines = useCallback (
8587 ( ) =>
@@ -88,24 +90,38 @@ export const RotatingLines: FunctionComponent<Props> = ({
8890 < Polyline
8991 key = { point }
9092 points = "24,12 24,4"
91- width = { strokeWidth }
93+ $strokeWidth = { strokeWidth }
9294 transform = { `rotate(${ point } , 24, 24)` }
9395 />
9496 ) ) ,
9597 [ strokeWidth ]
9698 )
97- return ! visible ? null : (
98- < Svg
99- xmlns = { SVG_NAMESPACE }
100- viewBox = "0 0 48 48"
101- width = { width }
102- stroke = { strokeColor }
103- speed = { animationDuration }
104- data-testid = "rotating-lines-svg"
99+
100+ if ( ! visible ) return null
101+
102+ return (
103+ < SvgWrapper
104+ style = { wrapperStyle }
105+ $visible = { visible }
106+ className = { wrapperClass }
105107 aria-label = { ariaLabel }
108+ data-testid = "rotating-lines-loading"
106109 { ...DEFAULT_WAI_ARIA_ATTRIBUTE }
107110 >
108- { lines ( ) }
109- </ Svg >
111+ < Svg
112+ xmlns = { SVG_NAMESPACE }
113+ viewBox = "0 0 48 48"
114+ width = { width }
115+ height = { height }
116+ stroke = { strokeColor ?? color }
117+ $animationDuration = { animationDuration }
118+ speed = { String ( animationDuration ) }
119+ aria-label = { ariaLabel }
120+ data-testid = "rotating-lines-svg"
121+ { ...DEFAULT_WAI_ARIA_ATTRIBUTE }
122+ >
123+ { lines ( ) }
124+ </ Svg >
125+ </ SvgWrapper >
110126 )
111127}
0 commit comments