# solvekit.core


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

**SVG Icon Support**: The `icon` parameter supports the
`'ii:{prefix}:{name}'` format, which automatically fetches SVG icons
from the [Iconify API](https://api.iconify.design). For example,
`'ii:lucide:copy-plus'` will request
https://api.iconify.design/lucide/copy-plus.svg?height=16&width=16, with
a default size of 16×16.

------------------------------------------------------------------------

<a
href="https://github.com/TheSecondStep/solvekit/blob/main/solvekit/core.py#L77"
target="_blank" style="float:right; font-size:smaller">source</a>

### add_btn

``` python

def add_btn(
    id:str, # Unique DOM id for the button element
    icon:str, # HTML/SVG icon string, or `'ii:prefix:name'` for Iconify lookup
    onclick:str, # Code to execute on click (Python or JS depending on `lang`)
    tooltip:str=None, # Optional tooltip text shown on hover
    lang:Literal='py', # Whether `onclick` is Python or JavaScript
):

```

*Add a custom button to the solveit toolbar inside the shared button
group.*

## Examples

**Dice Button**

Adds a toolbar button that rolls a random die. Click the button — it
prints the result in a self-deleting code cell.

``` python
add_btn('dice', 'ii:lucide:dice-5', 'import random; dice_num = random.randint(1,6); print(f"🎲 You rolled a {dice_num}!"); time.sleep(dice_num)', 'Roll a dice!', lang='py')
```

**Fastcore Docs Format Button**

Adds a toolbar button that reformats selected code cells into
`fastcore docs format`. Select one or more code messages, then click the
button — it creates a prompt asking SolveitAI to add docstrings and
per-parameter comments to each function.

``` python
fc_format = """
() => {
    const ids = selectedMsgIds();
    _post('upsert_msg', {
        id_: '',
        msg_type: 'prompt',
        content: `Please create a new version of functions in msgs ${ids} which adds a docstring and also adds a comment after each parameter. This is known as fastcore docs format. So each parameter will need to be on a separate line. Try to make the overall structure look the same as the previous function with these characteristics.`,
        is_input: '1',
        cmd: 'upsert-shift-run'
    });
}""".strip()
```

``` python
add_btn('fc_format', 'ii:lucide:file-code', fc_format, 'Fastcore docs format', lang='js')
```
