gradio/js/json/JSON.stories.svelte
Hannah 87e3537342
Add height param to gr.JSON (#9023)
* add height param and styles

* use lines instead of height

* replace height with lines

* add param and add description to gr.code

* add title attr

* remove styling

* format

* fix test

* add changeset

* revert to height

* remove lines logic

* add changeset

* code param tweak

* remove redundant code

* tweak test

* revert onDestroy removal

* fix test

* tweak

* docstring

* height fix

---------

Co-authored-by: pngwn <hello@pngwn.io>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2024-08-13 09:49:34 +00:00

61 lines
1.1 KiB
Svelte

<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import JSON from "./Index.svelte";
import { userEvent, within } from "@storybook/test";
const SAMPLE_JSON = {
items: {
item: [
{
id: "0001",
type: null,
is_good: false,
ppu: 0.55,
batters: {
batter: [{ id: "1001", type: "Regular" }]
},
topping: [{ id: "5002", type: "Glazed" }]
}
]
}
};
export const meta = {
title: "Components/JSON",
component: JSON
};
</script>
<Template let:args>
<JSON value={SAMPLE_JSON} {...args} />
</Template>
<Story name="Default JSON" args={{}} />
<Story
name="JSON Interactions"
args={{
value: SAMPLE_JSON,
interactive: true
}}
play={async ({ canvasElement }) => {
const canvas = within(canvasElement);
const toggles = within(canvasElement).getAllByRole("button");
await userEvent.click(toggles[1]);
await userEvent.click(toggles[1]);
await userEvent.click(toggles[2]);
await userEvent.click(canvas.getAllByText("Object(2)")[0]);
}}
/>
<Story
name="JSON viewed as list with height"
args={{
value: SAMPLE_JSON,
show_indices: true,
height: 200
}}
/>