|
| 1 | +--- |
| 2 | +description: Use when creating interactive examples for Vibe's Storybook Playground (vibe.monday.com/playground) - including bug reproductions, component demonstrations, feasibility testing, or consumer examples. Triggered by keywords like "playground", "reproduce bug", "interactive example", "user reported an issue" or "demonstrate". |
| 3 | +alwaysApply: false |
| 4 | +--- |
| 5 | + |
| 6 | +# Playground Reproduce |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +Vibe supports a Playground in its Storybook, accessible at `vibe.monday.com/playground`. |
| 11 | + |
| 12 | +Your goal is to output a working playground code *directly in the chat* (do not write it to a file). |
| 13 | + |
| 14 | +Behind the scenes, this playground uses: |
| 15 | + |
| 16 | +- **CodeMirror** for the editor interface (via `storybook-addon-playground` addon) |
| 17 | +- **React Live** for rendering the code in real-time |
| 18 | + |
| 19 | +## When to Use the Playground |
| 20 | + |
| 21 | +The Playground is for **one-time usage scenarios**: |
| 22 | + |
| 23 | +- Creating bug reproductions for issue reports |
| 24 | +- Testing component combinations and integrations |
| 25 | +- Validating if a feature is feasible with current or updated code |
| 26 | +- Demonstrating to consumers how to achieve specific behaviors |
| 27 | +- Helping consumers understand usage patterns |
| 28 | + |
| 29 | +**Important**: Playground examples are NOT for documentation or long-term storage. They are ephemeral demonstrations. |
| 30 | + |
| 31 | +## React Live Constraints |
| 32 | + |
| 33 | +React Live has strict requirements for the code format: |
| 34 | + |
| 35 | +### ✅ MUST: Single Anonymous Component |
| 36 | + |
| 37 | +The code MUST be wrapped in a single anonymous arrow function component: |
| 38 | + |
| 39 | +```javascript |
| 40 | +() => { |
| 41 | + const [timesClicked, setTimesClicked] = useState(0); |
| 42 | + |
| 43 | + function onButtonClick() { |
| 44 | + setTimesClicked(prev => prev + 1); |
| 45 | + } |
| 46 | + |
| 47 | + return ( |
| 48 | + <Flex direction="column" gap="medium"> |
| 49 | + <Button onClick={onButtonClick}> |
| 50 | + Clicked {timesClicked} time{timesClicked === 1 ? "" : "s"} |
| 51 | + </Button> |
| 52 | + </Flex> |
| 53 | + ); |
| 54 | +}; |
| 55 | +``` |
| 56 | + |
| 57 | +### ❌ CANNOT: Multiple Root Components |
| 58 | + |
| 59 | +React Live cannot render multiple components at the root level. This will NOT work: |
| 60 | + |
| 61 | +```javascript |
| 62 | +// ❌ Bad - Multiple root components |
| 63 | +const ComponentA = () => <div>A</div>; |
| 64 | +const ComponentB = () => <div>B</div>; |
| 65 | +``` |
| 66 | + |
| 67 | +### ✅ WORKAROUND: Define Components Inside |
| 68 | + |
| 69 | +For multi-component bugs (e.g., re-render issues), define child components INSIDE the root anonymous component: |
| 70 | + |
| 71 | +```javascript |
| 72 | +() => { |
| 73 | + const ChildComponent = ({ value }) => { |
| 74 | + console.log("ChildComponent rendered"); |
| 75 | + return <div>{value}</div>; |
| 76 | + }; |
| 77 | + |
| 78 | + const AnotherComponent = () => { |
| 79 | + return <Text>Another component</Text>; |
| 80 | + }; |
| 81 | + |
| 82 | + return ( |
| 83 | + <Flex direction="column" gap="small"> |
| 84 | + <ChildComponent value="test" /> |
| 85 | + <AnotherComponent /> |
| 86 | + </Flex> |
| 87 | + ); |
| 88 | +}; |
| 89 | +``` |
| 90 | + |
| 91 | +## Available Components |
| 92 | + |
| 93 | +### Default Components (Vibe 3.0 / Next) |
| 94 | + |
| 95 | +All Vibe components are available by their standard names and default to the "next" versions: |
| 96 | + |
| 97 | +```javascript |
| 98 | +<Button /> |
| 99 | +<Dropdown /> |
| 100 | +<Modal /> |
| 101 | +<TextField /> |
| 102 | +``` |
| 103 | + |
| 104 | +### Icons |
| 105 | + |
| 106 | +Access all Vibe icons via the `VibeIcons` prefix: |
| 107 | + |
| 108 | +```javascript |
| 109 | +<VibeIcons.RemoveRound /> |
| 110 | +<VibeIcons.Check /> |
| 111 | +<VibeIcons.Close /> |
| 112 | +``` |
| 113 | + |
| 114 | +### Legacy Components (Vibe 2.0) |
| 115 | + |
| 116 | +To use older versions of components, use the `VibeLegacy` prefix: |
| 117 | + |
| 118 | +```javascript |
| 119 | +<VibeLegacy.Modal /> |
| 120 | +<VibeLegacy.Dropdown /> |
| 121 | +``` |
| 122 | + |
| 123 | +### React Hooks |
| 124 | + |
| 125 | +All standard React hooks are available (`useState`, `useEffect`, `useCallback`, etc.). |
| 126 | + |
| 127 | +## Editor Tabs |
| 128 | + |
| 129 | +The Playground has two tabs: |
| 130 | + |
| 131 | +### JSX Tab |
| 132 | + |
| 133 | +Write your component code here using the anonymous component format. |
| 134 | + |
| 135 | +### CSS Tab |
| 136 | + |
| 137 | +Write CSS styles here. Reference these styles in the JSX tab using `className`: |
| 138 | + |
| 139 | +```javascript |
| 140 | +// JSX tab |
| 141 | +() => { |
| 142 | + return <div className="my-custom-class">Styled content</div>; |
| 143 | +} |
| 144 | + |
| 145 | +// CSS tab |
| 146 | +.my-custom-class { |
| 147 | + background: red; |
| 148 | + padding: 16px; |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +**Note**: CSS Modules are NOT supported. Use plain class names as strings. |
| 153 | + |
| 154 | +## Best Practices |
| 155 | + |
| 156 | +### Keep It Simple |
| 157 | + |
| 158 | +Focus ONLY on reproducing the specific issue. Don't add unrelated complexity. |
| 159 | + |
| 160 | +```javascript |
| 161 | +// ❌ Bad - Bug about Menu text, but adding unnecessary icons |
| 162 | +() => { |
| 163 | + return ( |
| 164 | + <Menu> |
| 165 | + <MenuItem icon={<VibeIcons.Check />}>Item with icon</MenuItem> |
| 166 | + <MenuItem icon={<VibeIcons.Star />}>Another with icon</MenuItem> |
| 167 | + </Menu> |
| 168 | + ); |
| 169 | +}; |
| 170 | + |
| 171 | +// ✅ Good - Focus on the Menu text issue |
| 172 | +() => { |
| 173 | + return ( |
| 174 | + <Menu> |
| 175 | + <MenuItem>Simple menu item text</MenuItem> |
| 176 | + <MenuItem>Another menu item</MenuItem> |
| 177 | + </Menu> |
| 178 | + ); |
| 179 | +}; |
| 180 | +``` |
| 181 | + |
| 182 | +### Ask Questions |
| 183 | + |
| 184 | +Before generating playground code, ask human: |
| 185 | + |
| 186 | +- What is the specific behavior they're trying to reproduce? |
| 187 | +- Which components are involved? |
| 188 | +- What should the expected vs. actual behavior be? |
| 189 | +- Are there any specific props or states that trigger the issue? |
| 190 | +- More related questions you think are worth asking. |
| 191 | +- Do not bug human with too many questions if you think you already understood most of the issue and what human wants. |
| 192 | + |
| 193 | +### Use JavaScript, Not TypeScript |
| 194 | + |
| 195 | +TypeScript types are valid code but add no value in the Playground. Keep code simple by using Javascript only. |
| 196 | + |
| 197 | +### Minimal Reproduction |
| 198 | + |
| 199 | +Strip away everything not essential to demonstrating the issue: |
| 200 | + |
| 201 | +```javascript |
| 202 | +// ❌ Too complex for a simple button bug |
| 203 | +() => { |
| 204 | + const [state, setState] = useState({ count: 0, enabled: true, label: "Click" }); |
| 205 | + const handleClick = useCallback(() => { |
| 206 | + setState(prev => ({ ...prev, count: prev.count + 1 })); |
| 207 | + }, []); |
| 208 | + |
| 209 | + return ( |
| 210 | + <Flex direction="column" gap="large" padding="large"> |
| 211 | + <Heading>Button Test</Heading> |
| 212 | + <Button onClick={handleClick}> |
| 213 | + {state.label} {state.count} |
| 214 | + </Button> |
| 215 | + </Flex> |
| 216 | + ); |
| 217 | +}; |
| 218 | + |
| 219 | +// ✅ Minimal reproduction |
| 220 | +() => { |
| 221 | + return <Button>Test button label</Button>; |
| 222 | +}; |
| 223 | +``` |
| 224 | + |
| 225 | +## Accessing the Playground |
| 226 | + |
| 227 | +Users can access the playground directly at: **vibe.monday.com/playground** |
| 228 | + |
| 229 | +Or navigate through Storybook UI to the "Playground" story. |
| 230 | + |
| 231 | +Press `D` on the keyboard to toggle the editor visibility in Storybook. |
0 commit comments