|
| 1 | +--- |
| 2 | +description: Rules and checklist for adding and using langflow component icons. |
| 3 | +globs: |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | +# Component Icon Rules |
| 7 | + |
| 8 | +## Purpose |
| 9 | +To ensure consistent, clear, and functional icon usage for components, covering both backend (Python) and frontend (React/TypeScript) steps. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## 1. Backend (Python) — Setting the Icon Name |
| 14 | + |
| 15 | +- **Where:** In your component class (e.g., in `src/backend/base/langflow/components/vectorstores/astradb.py`) |
| 16 | +- **How:** |
| 17 | + Set the `icon` attribute to a string matching the icon you want to use. |
| 18 | + ```python |
| 19 | + icon = "AstraDB" |
| 20 | + ``` |
| 21 | +- **Tip:** |
| 22 | + The string must match the frontend icon mapping exactly (case-sensitive). |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## 2. Frontend (React/TypeScript) — Adding the Icon |
| 27 | + |
| 28 | +### a. Create the Icon Component |
| 29 | + |
| 30 | +- **Where:** |
| 31 | + In a new directory for your icon, e.g., `src/frontend/src/icons/AstraDB/`. |
| 32 | +- **How:** |
| 33 | + - Add your SVG as a React component, e.g., `AstraSVG` in `AstraDB.jsx`. |
| 34 | + ```jsx |
| 35 | + const AstraSVG = (props) => ( |
| 36 | + <svg {...props}> |
| 37 | + <path |
| 38 | + // ... |
| 39 | + /> |
| 40 | + </svg> |
| 41 | + ); |
| 42 | + ``` |
| 43 | + - Create an `index.tsx` that exports your icon using `forwardRef`: |
| 44 | + ```tsx |
| 45 | + import { useDarkStore } from "@/stores/darkStore"; |
| 46 | + import React, { forwardRef } from "react"; |
| 47 | + import AstraSVG from "./AstraDB"; |
| 48 | + |
| 49 | + export const AstraDBIcon = forwardRef< |
| 50 | + SVGSVGElement, |
| 51 | + React.PropsWithChildren<{}> |
| 52 | + >((props, ref) => { |
| 53 | + const isdark = useDarkStore((state) => state.dark).toString(); |
| 54 | + return <AstraSVG ref={ref} isdark={isdark} {...props} />; |
| 55 | + }); |
| 56 | + ``` |
| 57 | + |
| 58 | +#### Supporting Light and Dark Mode Icons |
| 59 | + |
| 60 | +- **How:** |
| 61 | + - In your SVG component (e.g., `AstraDB.jsx`), use the `isdark` prop to switch colors: |
| 62 | + ```jsx |
| 63 | + const AstraSVG = (props) => ( |
| 64 | + <svg {...props}> |
| 65 | + <path |
| 66 | + fill={stringToBool(props.isdark) ? "#ffffff" : "#0A0A0A"} |
| 67 | + // ... |
| 68 | + /> |
| 69 | + </svg> |
| 70 | + ); |
| 71 | + ``` |
| 72 | + - The `isdark` prop is passed from the icon wrapper (see above) and should be used to toggle between light and dark color schemes. |
| 73 | + - You can use a utility like `stringToBool` to ensure the prop is interpreted correctly. |
| 74 | + |
| 75 | +### b. Add to Lazy Icon Imports |
| 76 | + |
| 77 | +- **Where:** |
| 78 | + In `src/frontend/src/icons/lazyIconImports.ts` |
| 79 | +- **How:** |
| 80 | + Add an entry to the `lazyIconsMapping` object: |
| 81 | + ```ts |
| 82 | + AstraDB: () => |
| 83 | + import("@/icons/AstraDB").then((mod) => ({ default: mod.AstraDBIcon })), |
| 84 | + ``` |
| 85 | +- **Tip:** |
| 86 | + The key (`AstraDB`) must match the string used in the backend. |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## 3. Best Practices |
| 91 | + |
| 92 | +- **Naming:** |
| 93 | + Use clear, recognizable names (e.g., `"AstraDB"`, `"Postgres"`, `"OpenAI"`). |
| 94 | +- **Consistency:** |
| 95 | + Always use the same icon name for the same service across backend and frontend. |
| 96 | +- **Missing Icon:** |
| 97 | + If no icon exists, use a [lucide icon](https://lucide.dev/icons) |
| 98 | +- **Light/Dark Mode:** |
| 99 | + Always support both light and dark mode for custom icons by using the `isdark` prop in your SVG. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## 4. Checklist for Adding a New Icon |
| 104 | + |
| 105 | +- [ ] Decide on a clear, descriptive icon name (e.g., `AstraDB`). |
| 106 | +- [ ] In your Python component, set `icon = "YourIconName"`. |
| 107 | +- [ ] Create a new icon directory in `src/frontend/src/icons/YourIconName/`. |
| 108 | +- [ ] Add your SVG as a React component (e.g., `YourIconNameIcon.jsx`). |
| 109 | +- [ ] Create an `index.tsx` that exports your icon using `forwardRef` and passes the `isdark` prop. |
| 110 | +- [ ] Add your icon to `lazyIconsMapping` in `src/frontend/src/icons/lazyIconImports.ts` with the exact same name. |
| 111 | +- [ ] Verify the icon appears correctly in the UI in both light and dark mode. |
| 112 | +- [ ] If no suitable icon exists, use a generic icon and request a new one if needed. |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +**Example for AstraDB:** |
| 117 | +- Backend: |
| 118 | + ```python |
| 119 | + icon = "AstraDB" |
| 120 | + ``` |
| 121 | +- Frontend: |
| 122 | + - `src/icons/AstraDB/AstraDB.jsx` (SVG as React component, uses `isdark` prop) |
| 123 | + - `src/icons/AstraDB/index.tsx` (exports `AstraDBIcon` and passes `isdark`) |
| 124 | + - Add to `lazyIconImports.ts`: |
| 125 | + ```ts |
| 126 | + AstraDB: () => |
| 127 | + import("@/icons/AstraDB").then((mod) => ({ default: mod.AstraDBIcon })), |
| 128 | + ``` |
| 129 | + |
| 130 | +--- |
0 commit comments