summaryrefslogtreecommitdiffhomepage
path: root/src/features/surface-host/ui/Toggle.svelte
blob: 03268516057e09157e13053eab9968232b483e85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<script lang="ts">
  import type { InvokeMessage } from "@dispatch/ui-contract";
  import type { ToggleFieldView } from "../logic/types";

  let {
    field,
    surfaceId,
    onInvoke,
  }: { field: ToggleFieldView; surfaceId: string; onInvoke: (msg: InvokeMessage) => void } =
    $props();

  function handleChange() {
    onInvoke({
      type: "invoke",
      surfaceId,
      actionId: field.action.actionId,
      payload: !field.value,
    });
  }
</script>

<label>
  <input type="checkbox" checked={field.value} onchange={handleChange} />
  {field.label}
</label>