-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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(components): add spinner component #1583
base: main
Are you sure you want to change the base?
Conversation
@olekbaran is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
@olekbaran What do you think about using an svg icon from import { Loader2 } from "lucide-react"
<Loader2 className="animate-spin" /> |
@shadcn I think my loader is a better match for the components' style and more in line with your original idea. The whole library is designed with the Vercel style, so I made a loader that replicates it. But, the final decision is all yours. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate you trying to keep the spinner in a similar style and not just adding an animate-spin
to an icon (which is what i always do 😅). I think there are some things that could be improved though like removing the style prop or making the spinnerBars more composable or functional 🤷♂️
Though I think for more sophisticated animations like this, I would rather opt to use something like framer-motion rather then tailwind, but i'm sure a similar effect can be created regardless 👍
const spinnerBars: SpinnerBar[] = [ | ||
{ animationDelay: -1.2, rotate: 0.0001 }, | ||
{ animationDelay: -1.1, rotate: 30 }, | ||
{ animationDelay: -1, rotate: 60 }, | ||
{ animationDelay: -0.9, rotate: 90 }, | ||
{ animationDelay: -0.8, rotate: 120 }, | ||
{ animationDelay: -0.7, rotate: 150 }, | ||
{ animationDelay: -0.6, rotate: 180 }, | ||
{ animationDelay: -0.5, rotate: 210 }, | ||
{ animationDelay: -0.4, rotate: 240 }, | ||
{ animationDelay: -0.3, rotate: 270 }, | ||
{ animationDelay: -0.2, rotate: 300 }, | ||
{ animationDelay: -0.1, rotate: 330 }, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const spinnerBars: SpinnerBar[] = [ | |
{ animationDelay: -1.2, rotate: 0.0001 }, | |
{ animationDelay: -1.1, rotate: 30 }, | |
{ animationDelay: -1, rotate: 60 }, | |
{ animationDelay: -0.9, rotate: 90 }, | |
{ animationDelay: -0.8, rotate: 120 }, | |
{ animationDelay: -0.7, rotate: 150 }, | |
{ animationDelay: -0.6, rotate: 180 }, | |
{ animationDelay: -0.5, rotate: 210 }, | |
{ animationDelay: -0.4, rotate: 240 }, | |
{ animationDelay: -0.3, rotate: 270 }, | |
{ animationDelay: -0.2, rotate: 300 }, | |
{ animationDelay: -0.1, rotate: 330 }, | |
] | |
const spinnerBars: SpinnerBar[] = Array.from({ length: 12 }, (_, index) => ({ | |
animationDelay: -1.2 + 0.1 * index, | |
rotate: 30 * index | |
})); |
Little cleaner implementations of the spinnerBars
? Could also move it outside the context of the Component to save some performance 👍
spinner: { | ||
from: { opacity: '1' }, | ||
to: { opacity: '0.15' }, | ||
}, | ||
}, | ||
animation: { | ||
"accordion-down": "accordion-down 0.2s ease-out", | ||
"accordion-up": "accordion-up 0.2s ease-out", | ||
spinner: 'spinner 1.2s linear infinite', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this animation could be renames to something like fade-out
since its only using opacity and doesnt describe any spinning animation. Will also make it more composable with other components 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking for a sec, something like this could work: spinner: 'rotate 1.2s infinite steps(12)',
and then you can just stagger the opacity and rotate the icon 🤷♂️
style={{ | ||
animationDelay: `${bar.animationDelay}s`, | ||
transform: `rotate(${bar.rotate}deg) translate(146%)`, | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm less of a fan of mixing style
and className
though I understand tailwinds limitations with dynamic values. Technically you could just return the classNames in your spinnerBars
explicitly (ignoring my suggestion) and then tailwind would pick it up on compile 🤔😆
const spinnerBars: SpinnerBar[] = [
{ animationDelay: "delay-[1.2s]", rotate: "rotate-[0deg]" },
{ animationDelay: "delay-[1.1s]", rotate: "rotate-[30deg]" },
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't do that, because delay
class in tailwind stands for transition-delay
CSS property, however I need animation-delay
. To style this component only with className
prop, I would need to add animation-delay as a custom tailwind class, but it will be so complicated to implement dynamic values for this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could use Arbitray Properties: like [animation-delay: 1.2sec]
🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but still think its better to rotate the icon using steps(12)
rather then creating 12 individual animating divs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, I'll give it a try
Spinner
This PR adds a Vercel style spinner component