| 1 | import React from "react"; |
| 2 | import styled, { keyframes } from "styled-components"; |
| 3 | import { vscForeground } from ".."; |
| 4 | |
| 5 | const rotate = keyframes` |
| 6 | 0% { |
| 7 | stroke-dashoffset: 100; |
| 8 | } |
| 9 | 100% { |
| 10 | stroke-dashoffset: 12; |
| 11 | } |
| 12 | `; |
| 13 | |
| 14 | const LoaderSvg = styled.svg<{ |
| 15 | width?: string; |
| 16 | height?: string; |
| 17 | period?: number; |
| 18 | }>` |
| 19 | transform: rotate(-90deg); |
| 20 | width: ${(props) => props.width || "40px"}; |
| 21 | height: ${(props) => props.height || "40px"}; |
| 22 | opacity: 50%; |
| 23 | |
| 24 | circle { |
| 25 | fill: none; |
| 26 | stroke: ${vscForeground}; |
| 27 | stroke-width: 2; |
| 28 | stroke-dasharray: 100; |
| 29 | stroke-dashoffset: 0; |
| 30 | animation: ${rotate} ${(props) => props.period || 6}s ease-out infinite; |
| 31 | stroke-linecap: round; |
| 32 | } |
| 33 | `; |
| 34 | |
| 35 | const RingLoader = (props: { |
| 36 | size: number; |
| 37 | wFull?: boolean; |
| 38 | className?: string; |
| 39 | width?: string; |
| 40 | height?: string; |
| 41 | period?: number; |
| 42 | }) => { |
| 43 | const viewBox = `0 0 ${props.size} ${props.size}`; |
| 44 | const size = (props.size / 2).toString(); |
| 45 | const r = "14"; //(props.size / 2 - 2).toString(); |
| 46 | return ( |
| 47 | <div |
| 48 | className={ |
| 49 | "m-auto mt-2 text-center" + |
| 50 | (props.wFull === false ? "" : " w-full") + |
| 51 | " " + |
| 52 | props.className |
| 53 | } |
| 54 | > |
| 55 | <LoaderSvg |
| 56 | period={props.period} |
| 57 | width={props.width} |
| 58 | height={props.height} |
| 59 | viewBox={viewBox} |
| 60 | > |
| 61 | <circle cx={size} cy={size} r={r} /> |
| 62 | </LoaderSvg> |
| 63 | </div> |
| 64 | ); |
| 65 | }; |
| 66 | |
| 67 | export default RingLoader; |