Skip to content

Commit 716501e

Browse files
committed
Fix scaling
1 parent ee0fdfa commit 716501e

File tree

3 files changed

+30
-50
lines changed

3 files changed

+30
-50
lines changed

packages/components/src/Spinner.tsx

+8-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const Spinner: ForwardRef<SVGSVGElement, SpinnerProps> =
2323
size = 48,
2424
strokeWidth = 4,
2525
max = 1,
26-
title = 'Loading',
26+
title = 'Loading',
2727
duration = 750,
2828
...props
2929
},
@@ -37,7 +37,7 @@ export const Spinner: ForwardRef<SVGSVGElement, SpinnerProps> =
3737
const svgProps = {
3838
strokeWidth,
3939

40-
viewBox: `0 0 ${size} ${size}`,
40+
viewBox: '0 0 32 32',
4141
width: size,
4242
height: size,
4343

@@ -46,13 +46,11 @@ export const Spinner: ForwardRef<SVGSVGElement, SpinnerProps> =
4646
role: 'img',
4747
}
4848

49-
const radius = size / 2 - strokeWidth
50-
const center = radius + strokeWidth
5149
const circleProps = {
5250
strokeWidth,
53-
r: radius,
54-
cx: radius + strokeWidth,
55-
cy: radius + strokeWidth,
51+
r: 16 - strokeWidth,
52+
cx: 16,
53+
cy: 16,
5654
fill: 'none',
5755
}
5856

@@ -66,13 +64,13 @@ export const Spinner: ForwardRef<SVGSVGElement, SpinnerProps> =
6664
>
6765
<title>{title}</title>
6866
<circle {...circleProps} opacity={1 / 8} />
69-
<circle {...circleProps} strokeDasharray="20 180">
67+
<circle {...circleProps} strokeDasharray="20 110">
7068
<animateTransform
7169
attributeName="transform"
7270
attributeType="XML"
7371
type="rotate"
74-
from={`0 ${center} ${center}`}
75-
to={`360 ${center} ${center}`}
72+
from="0 16 16"
73+
to="360 16 16"
7674
dur={`${duration}ms`}
7775
repeatCount="indefinite"
7876
/>

packages/components/test/__snapshots__/index.tsx.snap

+17-36
Original file line numberDiff line numberDiff line change
@@ -1329,22 +1329,6 @@ exports[`Slider renders 1`] = `
13291329
`;
13301330

13311331
exports[`Spinner renders 1`] = `
1332-
@keyframes animation-0 {
1333-
from {
1334-
-webkit-transform: rotate(0deg);
1335-
-moz-transform: rotate(0deg);
1336-
-ms-transform: rotate(0deg);
1337-
transform: rotate(0deg);
1338-
}
1339-
1340-
to {
1341-
-webkit-transform: rotate(360deg);
1342-
-moz-transform: rotate(360deg);
1343-
-ms-transform: rotate(360deg);
1344-
transform: rotate(360deg);
1345-
}
1346-
}
1347-
13481332
.emotion-0 {
13491333
box-sizing: border-box;
13501334
margin: 0;
@@ -1353,21 +1337,6 @@ exports[`Spinner renders 1`] = `
13531337
overflow: visible;
13541338
}
13551339
1356-
.emotion-1 {
1357-
box-sizing: border-box;
1358-
margin: 0;
1359-
min-width: 0;
1360-
transform-origin: 50% 50%;
1361-
-webkit-animation-name: animation-0;
1362-
animation-name: animation-0;
1363-
-webkit-animation-timing-function: linear;
1364-
animation-timing-function: linear;
1365-
-webkit-animation-duration: 500ms;
1366-
animation-duration: 500ms;
1367-
-webkit-animation-iteration-count: infinite;
1368-
animation-iteration-count: infinite;
1369-
}
1370-
13711340
<svg
13721341
className="emotion-0"
13731342
fill="none"
@@ -1379,22 +1348,34 @@ exports[`Spinner renders 1`] = `
13791348
width={48}
13801349
>
13811350
<title>
1382-
Loading...
1351+
Loading
13831352
</title>
13841353
<circle
13851354
cx={16}
13861355
cy={16}
1356+
fill="none"
13871357
opacity={0.125}
13881358
r={12}
1359+
strokeWidth={4}
13891360
/>
13901361
<circle
1391-
className="emotion-1"
13921362
cx={16}
13931363
cy={16}
1364+
fill="none"
13941365
r={12}
1395-
strokeDasharray={75.39822368615503}
1396-
strokeDashoffset={56.548667764616276}
1397-
/>
1366+
strokeDasharray="20 110"
1367+
strokeWidth={4}
1368+
>
1369+
<animateTransform
1370+
attributeName="transform"
1371+
attributeType="XML"
1372+
dur="750ms"
1373+
from="0 16 16"
1374+
repeatCount="indefinite"
1375+
to="360 16 16"
1376+
type="rotate"
1377+
/>
1378+
</circle>
13981379
</svg>
13991380
`;
14001381

packages/docs/src/pages/components/spinner.mdx

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ import { Spinner } from 'theme-ui'
1919
| Name | Type | Description |
2020
| ------------- | ------ | ------------------------------------------------ |
2121
| `title` | String | (default `'loading'`) Text for SVG `<title>` tag |
22-
| `size` | Number | (default `48`) chart diameter |
22+
| `size` | Number | (default `48`) indicator diameter |
2323
| `strokeWidth` | Number | (default `4`) stroke width |
24+
| `duration` | Number | (default `750`) duration of animation in ms |
2425

25-
A `title` attribute should be provided to the component for accessibility purposes.
26-
The element uses `role='img'` by default.
27-
Pass any overrides or additional attributes for the SVG element as props.
26+
A `title` attribute should be provided to the component for accessibility
27+
purposes. The element uses `role='img'` by default. Pass any overrides or
28+
additional attributes for the SVG element as props.
2829

2930
## Variants
3031

0 commit comments

Comments
 (0)