Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(button): use gradient loading spinner for loading state #60

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-drinks-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@groupos/ui-components': patch
---

Button: use gradient loading spinner for loading state
55 changes: 23 additions & 32 deletions packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,48 +75,39 @@ const spinnerVariants = cva('animate-spin', {
})

export const Spinner = ({ variant = 'primary', size = 'md' }: VariantProps<typeof spinnerVariants>) => (
// this is custom made from this sample CodePen: https://codepen.io/mtvv/pen/JjdoPRr
// and this tutorial: https://www.benmvp.com/blog/how-to-create-circle-svg-gradient-loading-spinner/
// it works by making two semi-circle arcs and applying 0->50 gradient on one and 50-100 gradient
// on the other to make it look like one continuous 0->100 gradient
<svg
className={cn(
'animate-spin',
spinnerVariants({
variant,
size,
}),
)}
width="24"
height="24"
viewBox="0 0 24 24"
color="#687385"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M12 4.75V6.25" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
<path
d="M17.1266 6.87347L16.0659 7.93413"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path d="M19.25 12L17.75 12" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
<path
d="M17.1266 17.1265L16.0659 16.0659"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path d="M12 17.75V19.25" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
<path
d="M7.9342 16.0659L6.87354 17.1265"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path d="M6.25 12L4.75 12" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
<path
d="M7.9342 7.93413L6.87354 6.87347"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<defs>
<linearGradient id="spinner-firstHalf">
<stop offset="0%" stopOpacity="1" stopColor="currentColor" />
<stop offset="100%" stopOpacity="0.4" stopColor="currentColor" />
</linearGradient>
<linearGradient id="spinner-secondHalf">
<stop offset="0%" stopOpacity="0" stopColor="currentColor" />
<stop offset="100%" stopOpacity="0.5" stopColor="currentColor" />
</linearGradient>
</defs>

<g fill="currentColor" transform="translate(4,4)">
<path fill="url(#spinner-firstHalf)" d="M 0 8 A 8 8 0 0 0 16 8 L 13 8 A 5 5 0 0 1 3 8 L 0 8 Z" />
<path fill="url(#spinner-secondHalf)" d="M 16 8 A 8 8 0 0 0 0 8 L 3 8 A 5 5 0 0 1 13 8 L 16 8 Z" />
</g>
</svg>
)