ForkFree

Prompts / Coding

Port a Code Snippet Into Your Project

You get a snippet rewritten to match your own framework, styling and theme, plus an honest list of what was changed and what still needs checking. It works because the AI must inspect your setup first and then report its limits, rather than pasting code in blindly.

Worked in our testIt followed every step and the requested output order. It stated the setup and assumptions first, then gave a scoped Tailwind named-export component with the insertion point and kept keyboard access and reduced motion. It mapped each colour, and its Changed and Not verified lists were honest, including the added focus ring and the label change.

The prompt

Act as a careful senior front-end developer who adapts third-party snippets to fit an existing codebase.

Task: Port the snippet below into my project without breaking its conventions.

Snippet:
{component_code}

Project setup: {project_setup}
Where it goes: {insertion_point}
Theme variables available: {theme_variables}

Steps:
1. Before writing anything, state what the project setup tells you about framework, styling method and theming, and note any gaps you are assuming.
2. Rewrite the snippet as a component in that framework, scoping its styles so they cannot leak elsewhere.
3. Replace every hard-coded colour with the closest theme variable, listing each mapping.
4. Place it at the insertion point, keeping keyboard access and reduced-motion behaviour intact.
5. Say honestly what you changed and what you could not verify.

Output: The finished component code in one block, then a short "Colour mapping" table, then two bullet lists headed "Changed" and "Not verified".

Change the parts in curly braces. Use it when you find a nice component or code sample online and want it to fit your existing app rather than bring its own style.

What happened when we ran it

We sent

Act as a careful senior front-end developer who adapts third-party snippets to fit an existing codebase.

Task: Port the snippet below into my project without breaking its conventions.

Snippet:
<button class="cta">Subscribe</button>
<style>.cta{background:#3b6cf6;color:#fff;padding:12px 24px;border-radius:8px;border:0;transition:transform .2s}.cta:hover{transform:translateY(-2px)}@media (prefers-reduced-motion:reduce){.cta{transition:none}}</style>
This is a call-to-action button with a small lift on hover. It uses plain HTML and CSS with no scripts.

Project setup: Next.js 14 with the App Router, TypeScript, Tailwind CSS 3, and dark mode switched by a 'dark' class on the html element. Components live in src/components and use named exports.
Where it goes: Replace the existing 'Join the newsletter' button in src/components/NewsletterForm.tsx, just below the email input.
Theme variables available: --brand-primary, --brand-primary-contrast, --surface, --text-default, all defined in globals.css with separate light and dark values.

Steps:
1. Before writing anything, state what the project setup tells you about framework, styling method and theming, and note any gaps you are assuming.
2. Rewrite the snippet as a component in that framework, scoping its styles so they cannot leak elsewhere.
3. Replace every hard-coded colour with the closest theme variable, listing each mapping.
4. Place it at the insertion point, keeping keyboard access and reduced-motion behaviour intact.
5. Say honestly what you changed and what you could not verify.

Output: The finished component code in one block, then a short "Colour mapping" table, then two bullet lists headed "Changed" and "Not verified".

The model replied

**Step 1: What the setup tells me** - **Framework:** Next.js 14 App Router with TypeScript. Components are named exports in `src/components`. The snippet has no JS, so it needs no `"use client"` of its own. - **Styling:** Tailwind 3. Utility classes are already scoped per element, so I'm dropping the `<style>` block and the global `.cta` class, which would leak. - **Theming:** Dark mode comes from a `dark` class on `<html>`. The theme variables change per mode, so using them means I need no `dark:` variants. - **Assumptions (gaps):** - I haven't opened `NewsletterForm.tsx`, `globals.css` or `tailwind.config`, so I don't know the existing button's props, handlers or `type`. - I assume the variables hold complete colour values (e.g. `#3b6cf6`), not bare RGB channels. - I assume the Tailwind config doesn't already map them to named colours, so I use arbitrary values. ```tsx // src/components/SubscribeButton.tsx import type { ButtonHTMLAttributes } from "react"; type SubscribeButtonProps = ButtonHTMLAttributes<HTMLButtonElement>; export function SubscribeButton({ children = "Subscribe", className = "", type = "submit", ...rest }: SubscribeButtonProps) { return ( <button type={type} className={[ "border-0 rounded-lg px-6 py-3", "bg-[var(--brand-primary)] text-[color:var(--brand-primary-contrast)]", "transition-transform duration-200 hover:-translate-y-0.5", "motion-reduce:transition-none", "focus-visible:outline-none focus-visible:ring-2", "focus-visible:ring-[color:var(--brand-primary)]", "focus-visible:ring-offset-2 focus-visible:ring-offset-[color:var(--surface)]", className, ] .filter(Boolean) .join(" ")} {...rest} > {children} </button> ); } // src/components/NewsletterForm.tsx (edit only the relevant parts) // import { SubscribeButton } from "./SubscribeButton"; // // <input ... /> {/* existing email input, unchanged */} // <SubscribeButton /> {/* replaces the old "Join the newsletter" <button> */} // // If the old button had onClick, disabled, or aria-* props, move them onto // <SubscribeButton ... />. They pass straight through to the <button>. ``` **Colour mapping** | Original | Used for | Theme variable | |---|---|---| | `#3b6cf6` | Background | `--brand-primary` | | `#fff` | Text | `--brand-primary-contrast` | | *(none, new)* | Focus-ring offset gap | `--surface` | `--text-default` isn't used, because the button text sits on the brand colour and takes the contrast variable. **Changed** - Replaced the `<style>` block and `.cta` class with Tailwind utilities on the element, so nothing is global. - Converted values: `padding: 12px 24px` → `py-3 px-6`, `border-radius: 8px` → `rounded-lg`, `translateY(-2px)` → `hover:-translate-y-0.5`, `.2s` → `duration-200`, `border:0` → `border-0`. - Kept the reduced-motion behaviour with `motion-reduce:transition-none`. As in the original, the lift still happens but without animation. - Used a real `<button>` that defaults to `type="submit"`, so it's focusable and works with Enter and Space. - Added a `focus-visible` ring, which the snippet lacked. The snippet has no outline override, but the ring is more visible on both themes, and its offset uses `--surface`. - Wrote `text-[color:…]` and `ring-[color:…]` explicitly, because Tailwind can't tell whether `text-[var(--x)]` means a colour or a font size. - Made it a named export that accepts standard button props and an optional `className`. - Changed the label from "Join the newsletter" to "Subscribe", following the snippet. Pass `children` if you want the old wording. **Not verified** - I haven't run the app, built it, or opened the project files, so the edit to `NewsletterForm.tsx` is described rather than applied. - I haven't confirmed the variables hold full colour values. If they hold channels like `59 108 246`, the classes need `rgb(var(--x))` instead. - I haven't checked contrast ratios for `--brand-primary-contrast` on `--brand-primary` in light and dark modes. - I haven't checked the existing button's disabled, loading or submit-handler behaviour, so it may need to be carried over. - I haven't tested in a browser, including the hover lift, the focus ring, or the reduced-motion setting.

Run on Claude Sonnet 5.5, 07 Nov 2026. Automatic check: 5 out of 5.

Mentioned for

Claude Code, Cursor, Codex

Where it came from

Found on GitHub, shared by Seokwoooo: Seokwoooo/lucian-uxui-prompt.

This is our own version of the idea, written and tested by us. The original may differ.

More coding prompts

Coding Worked in our test
Generate Strict JSON Spec From Description

You get a clean, machine-readable JSON object that matches your rules on the first try. It works because the model reads the rules first, then checks its own answer against each one before replying.

Found on GitHub, shared by DominikScholz
Coding Partly worked
Match Ownership Wording to Change Size

You get a tightly scoped code change, plus a separate list of things the AI spotted but left alone. It works because you state how far the AI may go, so a sense of "ownership" does not trigger unrequested refactoring.

Found on Web, shared by explainx.ai
Coding Worked in our test
Turn Vague Bug Reports Into Concrete Objectives

You get a bug fix broken into a reproduction, a minimal change and a regression test, each checked against clear objectives. Concrete objectives stop the model drifting into large rewrites or guessing at what "fixed" means.

Found on Web, shared by David Ch (@chhddavid)