Skip to content

Commit

Permalink
refactor: remove the usage of style-jsx (and so of "use client") in <…
Browse files Browse the repository at this point in the history
…Scroller/>

By moving animation into tailwind.config.js file
  • Loading branch information
LilaRest committed May 14, 2023
1 parent 8e98105 commit 2d209a5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/app/page.tsx → src/app/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Scroller from "@/components/ui/Scroller";
import { Scroller } from "@/components/ui";
import { type NextPage } from "next";

const Page: NextPage = () => (
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Page: NextPage = () => {
{buttonVariants.map((variant, index1) => (
<div key={index1} className="flex gap-4 p-2">
{buttonSizes.map((size, index2) => (
<Button variant={variant} size={size as any} key={index2}>
<Button variant={variant} size={size} key={index2}>
{variant} {size}
</Button>
))}
Expand Down
26 changes: 2 additions & 24 deletions src/components/ui/Scroller.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
"use client";
import clsx from "clsx";
import { FC } from "react";

export interface ScrollerProps {
className?: string;
}

const Scroller: FC<ScrollerProps> = ({ className }) => (
export const Scroller: FC<ScrollerProps> = ({ className }) => (
<div
className={clsx(
"border-4 rounded-lg border-fg/70 border-solid h-10 w-6 p-1",
className
)}
>
<style jsx>{`
@keyframes roll {
0% {
opacity: 0;
}
20% {
margin-top: 0;
opacity: 1;
}
80% {
margin-top: 16px;
opacity: 1;
}
100% {
opacity: 0;
}
}
.wheel {
animation: 2s infinite normal roll ease;
}
`}</style>
<div className="wheel bg-fg/70 w-2 h-2 rounded-full"></div>
<div className="animate-roll bg-fg/70 w-2 h-2 rounded-full"></div>
</div>
);
export default Scroller;
2 changes: 2 additions & 0 deletions src/components/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./Button";
export * from "./Scroller";
1 change: 0 additions & 1 deletion src/components/ui/index.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ export const theme = {
sm: "calc(var(--radius) - 4px)",
},
},
keyframes: {
// Used by <Scroller/> UI component
roll: {
"0%": { opacity: 0 },
"20%": { marginTop: "0", opacity: 1 },
"80%": { marginTop: "16px", opacity: 1 },
"100%": { opacity: 0 }
}
},
animation: {
// Used by <Scroller/> UI component
roll: "2s infinite normal roll ease"
}
};
export const plugins = [
plugin(({ addBase }) => addBase(vars)),
Expand Down

0 comments on commit 2d209a5

Please sign in to comment.