Lewati ke konten
MarkasUI
Ketik untuk mencari

    Panduan

    MarkasUI

    Form

    Feedback

    Overlay

    Navigasi

    Data

    Section

    Animasi

    Latar

    Tombol

    Template

    Halaman

    Switch

    Saklar nyala/mati dari checkbox native dengan role switch, tanpa JavaScript di Blade.

    Switch

    <x-markas.switch label="Airplane mode" />
    import { Switch } from "@/components/markas/Switch";
    
    <Switch label="Airplane mode" />
    import Switch from "@/components/markas/Switch.vue";
    
    <Switch label="Airplane mode" />
    <script lang="ts">
      import Switch from "$lib/components/markas/Switch.svelte";
    </script>
    
    <div class="grid gap-4">
      <Switch name="notifications" label="Email notifications" checked />
      <Switch name="saver" label="Data saver mode" />
      <Switch name="beta" label="Beta features" disabled />
    </div>
    ---
    import Switch from "@/components/markas/Switch.astro";
    ---
    
    <div class="grid gap-4">
      <Switch name="notifications" label="Email notifications" checked />
      <Switch name="saver" label="Data saver mode" />
      <Switch name="beta" label="Beta features" disabled />
    </div>
    import { Component } from "@angular/core";
    import { Switch } from "./markas/switch.component";
    
    @Component({
      selector: "markas-example",
      imports: [Switch],
      template: `
        <div class="grid gap-4">
          <markas-switch name="notifications" label="Email notifications" checked />
          <markas-switch name="saver" label="Data saver mode" />
          <markas-switch name="beta" label="Beta features" disabled />
        </div>
      `,
    })
    export default class SwitchExample {}

    Contoh

    Status

    Daftar pengaturan

    Push notifications

    Alerts on your phone for new messages.

    Weekly digest

    A summary of activity every Monday.

    Product news

    Occasional emails about new features.

    Push notifications

    Alerts on your phone for new messages.

    Weekly digest

    A summary of activity every Monday.

    Product news

    Occasional emails about new features.

    Push notifications

    Alerts on your phone for new messages.

    Weekly digest

    A summary of activity every Monday.

    Product news

    Occasional emails about new features.

    Push notifications

    Alerts on your phone for new messages.

    Weekly digest

    A summary of activity every Monday.

    Product news

    Occasional emails about new features.

    Push notifications

    Alerts on your phone for new messages.

    Weekly digest

    A summary of activity every Monday.

    Product news

    Occasional emails about new features.

    Kartu fitur

    Two-factor authentication

    Ask for a code from your authenticator app each time you sign in.

    Two-factor authentication

    Ask for a code from your authenticator app each time you sign in.

    Two-factor authentication

    Ask for a code from your authenticator app each time you sign in.

    Two-factor authentication

    Ask for a code from your authenticator app each time you sign in.

    Two-factor authentication

    Ask for a code from your authenticator app each time you sign in.

    Horizontal

    Instalasi

    npx markasui@latest add switch

    Pemakaian

    <x-markas.switch name="notifikasi" label="Notifikasi email" :checked="$user->wants_email" />

    Tidak butuh Alpine.js.

    import { Switch } from "@/components/markas/Switch";
    
    <Switch
      name="notifikasi"
      label="Notifikasi email"
      defaultChecked
      onCheckedChange={(checked) => console.log(checked)}
    />;
    <script setup lang="ts">
    import { ref } from "vue";
    import Switch from "@/components/markas/Switch.vue";
    
    const notifikasi = ref(true);
    </script>
    
    <template>
      <Switch v-model="notifikasi" name="notifikasi" label="Notifikasi email" />
    </template>
    <script lang="ts">
      import Switch from "$lib/components/markas/Switch.svelte";
    
      let notifikasi = $state(true);
    </script>
    
    <Switch
      bind:checked={notifikasi}
      name="notifications"
      label="Notifikasi email"
    />
    ---
    import Switch from "@/components/markas/Switch.astro";
    ---
    
    <Switch name="notifications" label="Notifikasi email" checked />

    Tanpa script klien: switch adalah checkbox native.

    import { Component, signal } from "@angular/core";
    import { Switch } from "./markas/switch.component";
    
    @Component({
      selector: "app-pengaturan",
      imports: [Switch],
      template: `
        <markas-switch
          [(checked)]="notifikasi"
          name="notifications"
          label="Notifikasi email"
        />
      `,
    })
    export class Pengaturan {
      readonly notifikasi = signal(true);
    }
    • Switch adalah <input type="checkbox" role="switch">, jadi nilainya ikut terkirim bersama form seperti checkbox biasa.
    • Status aktif dibacakan dari checked native, sehingga tidak perlu aria-checked. Tampilan memakai checked: dan peer-checked:, bukan data-state.
    • Komponen ini tidak punya teks bawaan. Cukup isi label dalam Bahasa Indonesia.

    Props

    NamaTipeDefaultKeterangan
    labelstring-Teks label di samping saklar, terhubung lewat for/id.
    checked / defaultChecked / v-model / bind:checkedbooleanfalseKeadaan aktif. Blade dan Astro memakai atribut checked, React checked atau defaultChecked, Vue v-model, Svelte bind:checked, Angular checked atau [(checked)].
    onCheckedChange(checked: boolean) => void-Khusus React. Dipanggil dengan status baru setiap kali saklar berubah.
    checkedChangeoutput<boolean>-Khusus Angular. Memancarkan keadaan baru setiap kali switch berubah.
    disabledbooleanfalseMenonaktifkan saklar dan meredupkan label.
    idstringautoId input. Dibuat otomatis kalau kosong.

    Aksesibilitas

    • Input checkbox native dengan role switch, sehingga screen reader membacakan aktif atau nonaktif dari status checked.
    • Spasi mengubah status, label yang diklik ikut mengubah status.
    • Thumb hanya dekorasi (aria-hidden) dan bergerak lewat CSS peer-checked.

    Komponen terkait

    Komponen form lain dengan class yang sama di setiap framework.