()
| 157 | } |
| 158 | |
| 159 | export function DynamicContentExample() { |
| 160 | const [tabs, setTabs] = createSignal([ |
| 161 | { id: "1", title: "Tab 1", content: "Tab body 1" }, |
| 162 | { id: "2", title: "Tab 2", content: "Tab body 2" }, |
| 163 | { id: "3", title: "Tab 3", content: "Tab body 3" }, |
| 164 | ]); |
| 165 | |
| 166 | const addTab = () => { |
| 167 | setTabs((prev) => [ |
| 168 | ...prev, |
| 169 | { |
| 170 | id: String(prev.length + 1), |
| 171 | title: `Tab ${prev.length + 1}`, |
| 172 | content: `Tab Body ${prev.length + 1}`, |
| 173 | }, |
| 174 | ]); |
| 175 | }; |
| 176 | |
| 177 | const removeTab = () => { |
| 178 | if (tabs().length > 1) { |
| 179 | setTabs((prev) => prev.slice(0, -1)); |
| 180 | } |
| 181 | }; |
| 182 | |
| 183 | return ( |
| 184 | <> |
| 185 | <div class="flex items-center space-x-2 mb-2"> |
| 186 | <button |
| 187 | type="button" |
| 188 | class="appearance-none outline-none h-10 px-4 rounded-md text-white bg-blue-600 dark:text-white/90 disabled:opacity-40 focus:ring focus:ring-blue-200 dark:focus:ring-blue-500/30" |
| 189 | onClick={addTab} |
| 190 | > |
| 191 | Add tab |
| 192 | </button> |
| 193 | <button |
| 194 | type="button" |
| 195 | class="appearance-none outline-none h-10 px-4 rounded-md text-white bg-blue-600 dark:text-white/90 disabled:opacity-40 focus:ring focus:ring-blue-200 dark:focus:ring-blue-500/30" |
| 196 | onClick={removeTab} |
| 197 | > |
| 198 | Remove tab |
| 199 | </button> |
| 200 | </div> |
| 201 | <Tabs> |
| 202 | <Tabs.List class={style.tabs__list}> |
| 203 | <For each={tabs()}> |
| 204 | {(tab) => ( |
| 205 | <Tabs.Trigger class={style.tabs__trigger} value={tab.id}> |
| 206 | {tab.title} |
| 207 | </Tabs.Trigger> |
| 208 | )} |
| 209 | </For> |
| 210 | <Tabs.Indicator class={style.tabs__indicator} /> |
| 211 | </Tabs.List> |
| 212 | <For each={tabs()}> |
| 213 | {(tab) => ( |
| 214 | <Tabs.Content class={style.tabs__content} value={tab.id}> |
| 215 | {tab.content} |
| 216 | </Tabs.Content> |
nothing calls this directly
no outgoing calls
no test coverage detected