-
Notifications
You must be signed in to change notification settings - Fork 225
refactor(flip-card): composable Front/Back API with motion-safe code #511
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
09d4bc8
refactor(flip-card): composable Front/Back API with motion-safe trans…
sudhashrestha a273f76
refactor(flipping-cards): composable grid API on FlipCard
sudhashrestha e2c3ac8
refactor(split-reveal): composable API with modular subfiles
sudhashrestha babe859
fix(split-reveal): share hooks and stabilize bootstrap lifecycle
sudhashrestha f7cc523
fix(flip-card): add use client directive
sudhashrestha 3071adf
fix(flipping-cards): use theme accent and dark story colors
sudhashrestha c6969fe
docs: document bundled hooks and fix flipping-cards install
sudhashrestha f4ec407
chore(registry): assert bundled hooks in install validation
sudhashrestha cc81e3e
ci: replace deprecated react-doctor diff flag
sudhashrestha 998bb76
ci: run react-doctor via official action with pinned 0.5.5
sudhashrestha b042d00
fix: address PR review feedback on flip-card and split-reveal
sudhashrestha 7009ee9
ci: align react-doctor workflow with official GitHub Actions docs
sudhashrestha 32f5c13
ci: run react-doctor only on pull requests to main
sudhashrestha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,27 @@ | ||
| name: React Doctor | ||
|
|
||
| on: | ||
| # Scans the PR's changed files and posts a sticky summary comment listing only the new issues introduced relative to the merge base of the target branch. | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| push: | ||
| branches: | ||
| - main | ||
| branches: [main] | ||
| types: [opened, synchronize, reopened, ready_for_review] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| issues: write | ||
| statuses: write | ||
|
|
||
| # Cancels any in-flight scan for the same PR the moment a new commit arrives, so reviewers only ever see the latest run. | ||
| concurrency: | ||
| group: react-doctor-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| react-doctor: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 11.5.0 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "22" | ||
| cache: "pnpm" | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Run React Doctor | ||
| run: pnpm dlx react-doctor@latest . -y --diff main --blocking error | ||
| - uses: millionco/react-doctor@v2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,85 @@ | ||
| "use client"; | ||
|
|
||
| import { type ComponentProps, createContext, use, useMemo } from "react"; | ||
|
|
||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| interface FlipCardProps extends React.HTMLAttributes<HTMLDivElement> { | ||
| image: string; | ||
| title: string; | ||
| description: string; | ||
| subtitle?: string; | ||
| rotate?: "x" | "y"; | ||
| export type FlipCardRotate = "x" | "y"; | ||
|
|
||
| type FlipCardContextValue = { | ||
| rotate: FlipCardRotate; | ||
| }; | ||
|
|
||
| const FlipCardContext = createContext<FlipCardContextValue | null>(null); | ||
|
|
||
| const ROTATION_CLASS = { | ||
| x: { | ||
| hover: "group-hover/card:rotate-x-180", | ||
| back: "rotate-x-180", | ||
| }, | ||
| y: { | ||
| hover: "group-hover/card:rotate-y-180", | ||
| back: "rotate-y-180", | ||
| }, | ||
| } as const; | ||
|
|
||
| function useFlipCard() { | ||
| const context = use(FlipCardContext); | ||
| if (!context) { | ||
| throw new Error("FlipCard.Front and FlipCard.Back must be used within <FlipCard>."); | ||
| } | ||
| return context; | ||
| } | ||
|
|
||
| export default function FlipCard({ | ||
| image, | ||
| title, | ||
| description, | ||
| subtitle, | ||
| rotate = "y", | ||
| className, | ||
| ...props | ||
| }: FlipCardProps) { | ||
| const rotationClass = { | ||
| x: ["group-hover/card:rotate-x-180", "rotate-x-180"], | ||
| y: ["group-hover/card:rotate-y-180", "rotate-y-180"], | ||
| } as const; | ||
| type FlipCardRootProps = ComponentProps<"div"> & { | ||
| rotate?: FlipCardRotate; | ||
| }; | ||
|
|
||
| function FlipCardRoot({ rotate = "y", className, children, ...props }: FlipCardRootProps) { | ||
| const value = useMemo(() => ({ rotate }), [rotate]); | ||
|
|
||
| return ( | ||
| <div className={cn("group/card h-72 w-56 perspective-[1000px]", className)} {...props}> | ||
| <div | ||
| className={cn( | ||
| "relative h-full rounded-2xl transition-transform duration-500 transform-3d", | ||
| rotationClass[rotate][0], | ||
| )} | ||
| > | ||
| {/* Front */} | ||
| <div className="absolute inset-0 backface-hidden"> | ||
| <img | ||
| src={image} | ||
| alt={title} | ||
| className="h-full w-full rounded-2xl object-cover shadow-2xl shadow-black/40" | ||
| /> | ||
| <div className="absolute bottom-4 left-4 text-xl font-bold text-white">{title}</div> | ||
| </div> | ||
| {/* Back */} | ||
| <FlipCardContext.Provider value={value}> | ||
| <div className={cn("group/card h-72 w-56 perspective-[1000px]", className)} {...props}> | ||
| <div | ||
| className={cn( | ||
| "absolute inset-0 rounded-2xl bg-black/80 p-4 text-slate-200 backface-hidden", | ||
| rotationClass[rotate][1], | ||
| "relative h-full rounded-2xl transition-transform duration-500 ease-out transform-3d will-change-transform motion-reduce:transition-none", | ||
| ROTATION_CLASS[rotate].hover, | ||
| )} | ||
| > | ||
| <div className="flex min-h-full flex-col gap-2"> | ||
| <h1 className="text-base font-bold text-white">{subtitle}</h1> | ||
| <p className="mt-1 border-t border-t-gray-200 py-4 text-base font-medium leading-normal text-gray-100"> | ||
| {description} | ||
| </p> | ||
| </div> | ||
| {children} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </FlipCardContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| type FlipCardFaceProps = ComponentProps<"div">; | ||
|
|
||
| function FlipCardFront({ className, ...props }: FlipCardFaceProps) { | ||
| useFlipCard(); | ||
|
|
||
| return <div className={cn("absolute inset-0 backface-hidden", className)} {...props} />; | ||
| } | ||
|
|
||
| function FlipCardBack({ className, ...props }: FlipCardFaceProps) { | ||
| const { rotate } = useFlipCard(); | ||
|
|
||
| return ( | ||
| <div | ||
| className={cn("absolute inset-0 backface-hidden", ROTATION_CLASS[rotate].back, className)} | ||
| {...props} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| const FlipCard = Object.assign(FlipCardRoot, { | ||
| Front: FlipCardFront, | ||
| Back: FlipCardBack, | ||
| }) as typeof FlipCardRoot & { | ||
| Front: typeof FlipCardFront; | ||
| Back: typeof FlipCardBack; | ||
| }; | ||
|
|
||
| export default FlipCard; | ||
| export { FlipCard, FlipCardBack, FlipCardFront, FlipCardRoot }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.