Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve styling of parameter tables in the docs #8618

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
5 changes: 5 additions & 0 deletions .changeset/ninety-ravens-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"website": patch
---

feat:Improve styling of parameter tables in the docs
52 changes: 8 additions & 44 deletions js/_website/src/lib/components/EventListeners.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<script lang="ts">
export let fns: any[];
import { style_formatted_text } from "$lib/text";
import ParamTable from "$lib/components/ParamTable.svelte";
</script>

<div id="event-listeners-description">
<h4 class="mt-8 text-xl text-orange-500 font-light group">Description</h4>
<p class="mb-2 text-lg text-gray-600">
Event listeners allow you to capture and respond to user interactions with
the UI components you've defined in a Gradio Blocks app. When a user
interacts with an element, such as changing a slider value or uploading an
image, a function is called.
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a
function is called.
</p>
</div>

Expand All @@ -25,7 +26,7 @@
component supports the following event listeners. Each event listener takes the
same parameters, which are listed in the
<a href="#event-listeners-arguments" class="text-orange-500 font-light"
>Event Arguments</a
>Event Parameters</a
> table below.
</p>

Expand Down Expand Up @@ -62,46 +63,9 @@
class="text-xl text-orange-500 font-light group"
id="event-listener-arguments"
>
Event Arguments
Event Parameters
</h4>

<table class="table-fixed w-full leading-loose">
<thead class="text-left">
<tr>
<th class="px-3 pb-3 font-semibold text-gray-700 w-2/5">Parameter</th>
<th class="px-3 pb-3 font-semibold text-gray-700">Description</th>
</tr>
</thead>
<tbody
class=" rounded-lg bg-gray-50 border border-gray-100 overflow-hidden text-left align-top divide-y"
>
{#each fns[0].parameters as param}
{#if param["name"] != "self"}
<tr class="group hover:bg-gray-200/60 odd:bg-gray-100/80">
<td class="p-3 w-2/5 break-words">
<code class="block">
{param["name"]}
</code>
<p class="text-gray-500 italic">
{param["annotation"].replace("Sequence[", "list[")}
</p>

{#if "default" in param}
<p class="text-gray-500 font-semibold">
default: {param["default"]}
</p>
{:else if !("kwargs" in param)}
<p class="text-orange-600 font-semibold italic">required</p>
{/if}
</td>
<td class="p-3 text-gray-700 break-words">
<p>{@html style_formatted_text(param["doc"]) || ""}</p>
</td>
</tr>
{/if}
{/each}
</tbody>
</table>
<ParamTable parameters={fns[0].parameters}></ParamTable>
</div>

<style>
Expand Down
4 changes: 2 additions & 2 deletions js/_website/src/lib/components/FunctionsSection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

{#if event_listeners}
{#if fns && fns.length > 0}
<div class="flex flex-col gap-8 pl-12">
<div class="flex flex-col pl-12">
<EventListeners {fns} />
<div class="ml-12" />
</div>
{/if}
{:else}
<div class="flex flex-col gap-8 pl-12">
<div class="flex flex-col pl-12">
{#each fns as fn}
<FunctionDoc {fn} />
{/each}
Expand Down
85 changes: 50 additions & 35 deletions js/_website/src/lib/components/ParamTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,55 @@
</script>

{#if (parameters.length > 0 && parameters[0].name != "self") || parameters.length > 1}
<table class="table-fixed w-full leading-loose">
<thead class="text-left">
<tr>
<th class="px-3 pb-3 w-2/5 text-gray-700 font-semibold">Parameter</th>
<th class="px-3 pb-3 text-gray-700 font-semibold">Description</th>
</tr>
</thead>
<tbody
class=" rounded-lg bg-gray-50 border border-gray-100 overflow-hidden text-left align-top divide-y"
>
{#each parameters as param}
{#if param["name"] != "self"}
<tr class="group hover:bg-gray-200/60 odd:bg-gray-100/80">
<td class="p-3 w-2/5 break-words">
<code class="block">
{param["name"]}
</code>
<p class="text-gray-500 italic">
{param["annotation"].replace("Sequence[", "list[")}
</p>
<div style="background-color: rgb(252 253 253);">
{#each parameters as param}
{#if param["name"] != "self"}
<hr class="hr" />
<div style="padding-left:5px">
<p>
<span class="code" style="font-weight:bold">{param["name"]}</span>
<span class="code highlight" style="margin-left: 10px;"
>{param["annotation"].replace("Sequence[", "list[")}</span
>
<span style="margin-left: 10px;">
{#if "default" in param}
<p class="text-gray-500 font-semibold">
default: {param["default"]}
</p>
{:else if !("kwargs" in param)}
<p class="text-orange-600 font-semibold italic">required</p>
{/if}
</td>
<td class="p-3 text-gray-700 break-words">
<p>{@html style_formatted_text(param["doc"]) || ""}</p>
</td>
</tr>
{/if}
{/each}
</tbody>
</table>
<em><strong>Default: </strong></em>{param["default"]}
{:else if !("kwargs" in param)}<em><strong>Required</strong></em
>{/if}
</span>
</p>
<p class="desc">
{@html style_formatted_text(param["doc"]) || ""}
</p>
</div>
{/if}
{/each}
</div>
{/if}

<style>
.hr {
border: 0;
height: 2px;
background: var(--color-accent-soft);
margin-bottom: 12px;
margin-top: 12px;
}

.code {
font-family: var(--font-mono);
display: inline;
}

.highlight {
background: var(--color-accent-soft);
color: var(--color-accent);
padding: var(--size-1);
}

.desc {
color: #444;
font-size: var(--text-lg);
margin-top: var(--size-1);
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ demo.launch()
```
{/if}

<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ demo = gr.ChatInterface(fn=echo, examples=["hello", "hola", "merhaba"], title="E
demo.launch()
```

<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ gradio.TabbedInterface(interface_list, ···)
### Description
## {@html style_formatted_text(obj.description)}

<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ demo.launch()
```
{/if}

<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ with gr.Blocks() as demo:
```
{/if}

<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ with gr.Accordion("See Details"):
```
{/if}

<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ with gr.Blocks() as demo:
```
{/if}

<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ with gr.Group():
```
{/if}

<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
4 changes: 2 additions & 2 deletions js/_website/src/lib/templates/gradio/02_blocks-layout/row.svx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ demo.launch()
```
{/if}

<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
4 changes: 2 additions & 2 deletions js/_website/src/lib/templates/gradio/02_blocks-layout/tab.svx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ with gr.Blocks() as demo:
```
{/if}

<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def predict(···) -> tuple[np.ndarray | PIL.Image.Image | str, list[tuple[np.n
```


<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
8 changes: 4 additions & 4 deletions js/_website/src/lib/templates/gradio/03_components/audio.svx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def predict(···) -> str | Path | bytes | tuple[int, np.ndarray] | None
```


<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down Expand Up @@ -99,8 +99,8 @@ gradio.WaveformOptions(···)
#### Description
## {@html style_formatted_text(waveform_obj.description)}

<!--- Initialization -->
#### Initialization
<!--- Parameters -->
#### Parameters
<ParamTable parameters={waveform_obj.parameters} />

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def predict(···) -> pd.DataFrame | None
```


<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
4 changes: 2 additions & 2 deletions js/_website/src/lib/templates/gradio/03_components/button.svx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def predict(···) -> str | None
```


<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def predict(···) -> list[list[str | tuple[str] | tuple[str, str] | None] | tu
```


<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def predict(···) -> bool | None
```


<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def predict(···) -> list[str | int | float] | str | int | float | None
```


<!--- Initialization -->
### Initialization
<!--- Parameters -->
### Parameters
<ParamTable parameters={obj.parameters} />


Expand Down
Loading