feat: extract graph-interface into seperate package
This commit is contained in:
21
packages/ui/src/lib/Details.svelte
Normal file
21
packages/ui/src/lib/Details.svelte
Normal file
@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
export let title = "Details";
|
||||
</script>
|
||||
|
||||
<details>
|
||||
<summary>{title}</summary>
|
||||
|
||||
<slot />
|
||||
</details>
|
||||
|
||||
<style>
|
||||
details {
|
||||
padding: 1em;
|
||||
color: white;
|
||||
background-color: #202020;
|
||||
outline: solid 0.1px white;
|
||||
border-radius: 2px;
|
||||
font-weight: 300;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
</style>
|
21
packages/ui/src/lib/Input.svelte
Normal file
21
packages/ui/src/lib/Input.svelte
Normal file
@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
import Checkbox from "$lib/elements/Checkbox.svelte";
|
||||
import Float from "$lib/elements/Float.svelte";
|
||||
import Integer from "$lib/elements/Integer.svelte";
|
||||
import Select from "$lib/elements/Select.svelte";
|
||||
|
||||
import type { NodeInput } from "@nodes/types";
|
||||
|
||||
export let input: NodeInput;
|
||||
export let value: any;
|
||||
</script>
|
||||
|
||||
{#if input.type === "float"}
|
||||
<Float bind:value />
|
||||
{:else if input.type === "integer"}
|
||||
<Integer bind:value />
|
||||
{:else if input.type === "boolean"}
|
||||
<Checkbox bind:value />
|
||||
{:else if input.type === "select"}
|
||||
<Select bind:value labels={input.labels} />
|
||||
{/if}
|
17
packages/ui/src/lib/elements/Checkbox.story.svelte
Normal file
17
packages/ui/src/lib/elements/Checkbox.story.svelte
Normal file
@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Hst } from "@histoire/plugin-svelte";
|
||||
export let Hst: Hst;
|
||||
import Checkbox from "./Checkbox.svelte";
|
||||
</script>
|
||||
|
||||
<Hst.Story>
|
||||
<div>
|
||||
<Checkbox checked={false} />
|
||||
</div>
|
||||
</Hst.Story>
|
||||
|
||||
<style>
|
||||
div {
|
||||
padding: 1em;
|
||||
}
|
||||
</style>
|
58
packages/ui/src/lib/elements/Checkbox.svelte
Normal file
58
packages/ui/src/lib/elements/Checkbox.svelte
Normal file
@ -0,0 +1,58 @@
|
||||
<script lang="ts">
|
||||
export let value: boolean;
|
||||
</script>
|
||||
|
||||
<input type="checkbox" bind:checked={value} />
|
||||
|
||||
<style>
|
||||
input[type="checkbox"] {
|
||||
/* Add if not using autoprefixer */
|
||||
-webkit-appearance: none;
|
||||
/* Remove most all native input styles */
|
||||
appearance: none;
|
||||
/* For iOS < 15 */
|
||||
background-color: var(--form-background);
|
||||
/* Not removed via appearance */
|
||||
margin: 0;
|
||||
|
||||
font: inherit;
|
||||
color: currentColor;
|
||||
width: 1.15em;
|
||||
height: 1.15em;
|
||||
border: 0.15em solid currentColor;
|
||||
border-radius: 0.15em;
|
||||
transform: translateY(-0.075em);
|
||||
|
||||
display: grid;
|
||||
place-content: center;
|
||||
}
|
||||
|
||||
input[type="checkbox"]::before {
|
||||
content: "";
|
||||
width: 0.65em;
|
||||
height: 0.65em;
|
||||
clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
|
||||
transform: scale(0);
|
||||
transform-origin: bottom left;
|
||||
transition: 120ms transform ease-in-out;
|
||||
box-shadow: inset 1em 1em var(--form-control-color);
|
||||
/* Windows High Contrast Mode */
|
||||
background-color: CanvasText;
|
||||
}
|
||||
|
||||
input[type="checkbox"]:checked::before {
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
input[type="checkbox"]:focus {
|
||||
outline: max(2px, 0.15em) solid currentColor;
|
||||
outline-offset: max(2px, 0.15em);
|
||||
}
|
||||
|
||||
input[type="checkbox"]:disabled {
|
||||
--form-control-color: var(--form-control-disabled);
|
||||
|
||||
color: var(--form-control-disabled);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
17
packages/ui/src/lib/elements/Float.story.svelte
Normal file
17
packages/ui/src/lib/elements/Float.story.svelte
Normal file
@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Hst } from "@histoire/plugin-svelte";
|
||||
export let Hst: Hst;
|
||||
import Float from "./Float.svelte";
|
||||
</script>
|
||||
|
||||
<Hst.Story>
|
||||
<div>
|
||||
<Float value={0} min={0} max={6.9} />
|
||||
</div>
|
||||
</Hst.Story>
|
||||
|
||||
<style>
|
||||
div {
|
||||
padding: 1em;
|
||||
}
|
||||
</style>
|
19
packages/ui/src/lib/elements/Float.svelte
Normal file
19
packages/ui/src/lib/elements/Float.svelte
Normal file
@ -0,0 +1,19 @@
|
||||
<script lang="ts">
|
||||
export let value: number = 0;
|
||||
export let min = 0;
|
||||
export let max = 10;
|
||||
export let step = 0.1;
|
||||
</script>
|
||||
|
||||
<input type="number" bind:value {min} {max} {step} />
|
||||
|
||||
<style>
|
||||
input {
|
||||
background: var(--background-color-lighter);
|
||||
color: var(--text-color);
|
||||
font-family: var(--font-family);
|
||||
padding: 0.8em 1em;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
17
packages/ui/src/lib/elements/Integer.story.svelte
Normal file
17
packages/ui/src/lib/elements/Integer.story.svelte
Normal file
@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Hst } from "@histoire/plugin-svelte";
|
||||
export let Hst: Hst;
|
||||
import Integer from "./Integer.svelte";
|
||||
</script>
|
||||
|
||||
<Hst.Story>
|
||||
<div>
|
||||
<Integer value={5} min={0} max={42} />
|
||||
</div>
|
||||
</Hst.Story>
|
||||
|
||||
<style>
|
||||
div {
|
||||
padding: 1em;
|
||||
}
|
||||
</style>
|
19
packages/ui/src/lib/elements/Integer.svelte
Normal file
19
packages/ui/src/lib/elements/Integer.svelte
Normal file
@ -0,0 +1,19 @@
|
||||
<script lang="ts">
|
||||
export let value: number = 0;
|
||||
export let min = 0;
|
||||
export let max = 10;
|
||||
export let step = 1;
|
||||
</script>
|
||||
|
||||
<input type="number" bind:value {min} {max} {step} />
|
||||
|
||||
<style>
|
||||
input {
|
||||
background: var(--background-color-lighter);
|
||||
color: var(--text-color);
|
||||
font-family: var(--font-family);
|
||||
padding: 0.8em 1em;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
17
packages/ui/src/lib/elements/Select.story.svelte
Normal file
17
packages/ui/src/lib/elements/Select.story.svelte
Normal file
@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Hst } from "@histoire/plugin-svelte";
|
||||
export let Hst: Hst;
|
||||
import Select from "./Select.svelte";
|
||||
</script>
|
||||
|
||||
<Hst.Story>
|
||||
<div>
|
||||
<Select value={"banana"} options={["strawberry", "apple", "banana"]} />
|
||||
</div>
|
||||
</Hst.Story>
|
||||
|
||||
<style>
|
||||
div {
|
||||
padding: 1em;
|
||||
}
|
||||
</style>
|
21
packages/ui/src/lib/elements/Select.svelte
Normal file
21
packages/ui/src/lib/elements/Select.svelte
Normal file
@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
export let labels: string[] = [];
|
||||
export let value: number = 0;
|
||||
</script>
|
||||
|
||||
<select bind:value>
|
||||
{#each labels as label, i}
|
||||
<option value={i}>{label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
<style>
|
||||
select {
|
||||
background: var(--background-color-lighter);
|
||||
color: var(--text-color);
|
||||
font-family: var(--font-family);
|
||||
padding: 0.8em 1em;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
12
packages/ui/src/lib/index.ts
Normal file
12
packages/ui/src/lib/index.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// Reexport your entry components here
|
||||
import Input from './Input.svelte';
|
||||
|
||||
import Float from "./elements/Float.svelte";
|
||||
import Integer from "./elements/Integer.svelte";
|
||||
import Select from "./elements/Select.svelte";
|
||||
import Checkbox from "./elements/Checkbox.svelte";
|
||||
import Details from "./Details.svelte";
|
||||
|
||||
export { Float, Integer, Select, Checkbox, Input, Details };
|
||||
|
||||
export default Input;
|
Reference in New Issue
Block a user