Lewati ke konten
MarkasUI
Ketik untuk mencari

    Panduan

    MarkasUI

    Form

    Feedback

    Overlay

    Navigasi

    Data

    Section

    Animasi

    Latar

    Tombol

    Template

    Halaman

    Radio Group

    Kelompok radio native dalam fieldset dan legend untuk memilih satu dari beberapa opsi.

    Subscription plan

    For personal projects.

    For small teams of up to 10 people.

    For organizations with custom needs.

    Billing cycle
    Subscription plan

    For personal projects.

    For small teams of up to 10 people.

    For organizations with custom needs.

    Billing cycle
    Subscription plan

    For personal projects.

    For small teams of up to 10 people.

    For organizations with custom needs.

    Billing cycle
    Subscription plan

    For personal projects.

    For small teams of up to 10 people.

    For organizations with custom needs.

    Billing cycle
    Subscription plan

    For personal projects.

    For small teams of up to 10 people.

    For organizations with custom needs.

    Billing cycle
    <div class="grid gap-6">
        <x-markas.radio-group
            name="plan"
            label="Subscription plan"
            value="pro"
            :options="[
                ['value' => 'free', 'label' => 'Free', 'description' => 'For personal projects.'],
                ['value' => 'pro', 'label' => 'Pro', 'description' => 'For small teams of up to 10 people.'],
                ['value' => 'business', 'label' => 'Business', 'description' => 'For organizations with custom needs.'],
            ]"
        />
        <x-markas.radio-group
            name="billing"
            label="Billing cycle"
            value="monthly"
            orientation="horizontal"
            :options="[
                ['value' => 'monthly', 'label' => 'Monthly'],
                ['value' => 'yearly', 'label' => 'Yearly'],
            ]"
        />
    </div>
    import { RadioGroup } from "@/components/markas/RadioGroup";
    
    const plan = [
      { value: "free", label: "Free", description: "For personal projects." },
      {
        value: "pro",
        label: "Pro",
        description: "For small teams of up to 10 people.",
      },
      {
        value: "business",
        label: "Business",
        description: "For organizations with custom needs.",
      },
    ];
    const billing = [
      { value: "monthly", label: "Monthly" },
      { value: "yearly", label: "Yearly" },
    ];
    
    export default function RadioGroupExample() {
      return (
        <div className="grid gap-6">
          <RadioGroup
            name="plan"
            label="Subscription plan"
            defaultValue="pro"
            options={plan}
          />
          <RadioGroup
            name="billing"
            label="Billing cycle"
            defaultValue="monthly"
            orientation="horizontal"
            options={billing}
          />
        </div>
      );
    }
    <script setup lang="ts">
    import { ref } from "vue";
    import RadioGroup from "@/components/markas/RadioGroup.vue";
    
    const planOptions = [
      { value: "free", label: "Free", description: "For personal projects." },
      {
        value: "pro",
        label: "Pro",
        description: "For small teams of up to 10 people.",
      },
      {
        value: "business",
        label: "Business",
        description: "For organizations with custom needs.",
      },
    ];
    const billingOptions = [
      { value: "monthly", label: "Monthly" },
      { value: "yearly", label: "Yearly" },
    ];
    const plan = ref("pro");
    const billing = ref("monthly");
    </script>
    
    <template>
      <div class="grid gap-6">
        <RadioGroup
          v-model="plan"
          name="plan"
          label="Subscription plan"
          :options="planOptions"
        />
        <RadioGroup
          v-model="billing"
          name="billing"
          label="Billing cycle"
          orientation="horizontal"
          :options="billingOptions"
        />
      </div>
    </template>
    <script lang="ts">
      import RadioGroup from "$lib/components/markas/RadioGroup.svelte";
    
      const plan = [
        {
          value: "free",
          label: "Free",
          description: "For personal projects.",
        },
        {
          value: "pro",
          label: "Pro",
          description: "For small teams of up to 10 people.",
        },
        {
          value: "business",
          label: "Business",
          description: "For organizations with custom needs.",
        },
      ];
      const billing = [
        {
          value: "monthly",
          label: "Monthly",
        },
        {
          value: "yearly",
          label: "Yearly",
        },
      ];
    </script>
    
    <div class="grid gap-6">
      <RadioGroup
        name="plan"
        label="Subscription plan"
        value="pro"
        options={plan}
      />
      <RadioGroup
        name="billing"
        label="Billing cycle"
        value="monthly"
        orientation="horizontal"
        options={billing}
      />
    </div>
    ---
    import RadioGroup from "@/components/markas/RadioGroup.astro";
    
    const plan = [
      {
        value: "free",
        label: "Free",
        description: "For personal projects."
      },
      {
        value: "pro",
        label: "Pro",
        description: "For small teams of up to 10 people."
      },
      {
        value: "business",
        label: "Business",
        description: "For organizations with custom needs."
      }
    ];
    const billing = [
      {
        value: "monthly",
        label: "Monthly"
      },
      {
        value: "yearly",
        label: "Yearly"
      }
    ];
    ---
    
    <div class="grid gap-6">
      <RadioGroup
        name="plan"
        label="Subscription plan"
        value="pro"
        options={plan}
      />
      <RadioGroup
        name="billing"
        label="Billing cycle"
        value="monthly"
        orientation="horizontal"
        options={billing}
      />
    </div>
    import { Component } from "@angular/core";
    import { RadioGroup } from "./markas/radio-group.component";
    
    @Component({
      selector: "markas-example",
      imports: [RadioGroup],
      template: `
        <div class="grid gap-6">
          <markas-radio-group
            name="plan"
            label="Subscription plan"
            value="pro"
            [options]="plan"
          />
          <markas-radio-group
            name="billing"
            label="Billing cycle"
            value="monthly"
            orientation="horizontal"
            [options]="billing"
          />
        </div>
      `,
    })
    export default class RadioGroupFixture {
      protected readonly plan = [
        {
          value: "free",
          label: "Free",
          description: "For personal projects.",
        },
        {
          value: "pro",
          label: "Pro",
          description: "For small teams of up to 10 people.",
        },
        {
          value: "business",
          label: "Business",
          description: "For organizations with custom needs.",
        },
      ];
      protected readonly billing = [
        {
          value: "monthly",
          label: "Monthly",
        },
        {
          value: "yearly",
          label: "Yearly",
        },
      ];
    }

    Contoh

    Horizontal

    Theme
    Size
    Theme
    Size
    Theme
    Size
    Theme
    Size
    Theme
    Size

    Dengan deskripsi

    Shipping method

    Arrives in 4 to 6 business days. Free.

    Arrives in 1 to 2 business days. $12.

    Ready for pickup tomorrow at 10:00.

    Shipping method

    Arrives in 4 to 6 business days. Free.

    Arrives in 1 to 2 business days. $12.

    Ready for pickup tomorrow at 10:00.

    Shipping method

    Arrives in 4 to 6 business days. Free.

    Arrives in 1 to 2 business days. $12.

    Ready for pickup tomorrow at 10:00.

    Shipping method

    Arrives in 4 to 6 business days. Free.

    Arrives in 1 to 2 business days. $12.

    Ready for pickup tomorrow at 10:00.

    Shipping method

    Arrives in 4 to 6 business days. Free.

    Arrives in 1 to 2 business days. $12.

    Ready for pickup tomorrow at 10:00.

    Kartu

    Plan

    1 project and 2 GB storage. Free forever.

    Unlimited projects and 100 GB storage. $29 per month.

    SSO, audit logs, and a dedicated manager.

    Plan

    1 project and 2 GB storage. Free forever.

    Unlimited projects and 100 GB storage. $29 per month.

    SSO, audit logs, and a dedicated manager.

    Plan

    1 project and 2 GB storage. Free forever.

    Unlimited projects and 100 GB storage. $29 per month.

    SSO, audit logs, and a dedicated manager.

    Plan

    1 project and 2 GB storage. Free forever.

    Unlimited projects and 100 GB storage. $29 per month.

    SSO, audit logs, and a dedicated manager.

    Plan

    1 project and 2 GB storage. Free forever.

    Unlimited projects and 100 GB storage. $29 per month.

    SSO, audit logs, and a dedicated manager.

    Nonaktif

    Payout schedule

    Verify your bank account to change the payout schedule.

    Payout schedule

    Verify your bank account to change the payout schedule.

    Payout schedule

    Verify your bank account to change the payout schedule.

    Payout schedule

    Verify your bank account to change the payout schedule.

    Payout schedule

    Verify your bank account to change the payout schedule.

    Dalam kartu

    Digest emails

    A summary of activity in projects you follow.

    Frequency

    Every morning at 08:00.

    Every Monday morning.

    Only important account notices.

    Digest emails

    A summary of activity in projects you follow.

    Frequency

    Every morning at 08:00.

    Every Monday morning.

    Only important account notices.

    Digest emails

    A summary of activity in projects you follow.

    Frequency

    Every morning at 08:00.

    Every Monday morning.

    Only important account notices.

    Digest emails

    A summary of activity in projects you follow.

    Frequency

    Every morning at 08:00.

    Every Monday morning.

    Only important account notices.

    Digest emails

    A summary of activity in projects you follow.

    Frequency

    Every morning at 08:00.

    Every Monday morning.

    Only important account notices.

    Instalasi

    npx markasui@latest add radio-group

    Pemakaian

    <x-markas.radio-group
        name="paket"
        label="Paket langganan"
        :value="old('paket', 'pro')"
        :options="[
            ['value' => 'gratis', 'label' => 'Gratis', 'description' => 'Untuk proyek pribadi.'],
            ['value' => 'pro', 'label' => 'Pro'],
        ]"
    />

    Livewire

    <x-markas.radio-group name="plan" wire:model.live="plan" :options="$plans" />

    wire:model (dan x-model) disalin ke setiap radio, jadi Livewire membaca nilai yang dicentang. Atribut lain tetap di fieldset.

    import { RadioGroup } from "@/components/markas/RadioGroup";
    
    <RadioGroup
      name="paket"
      label="Paket langganan"
      defaultValue="pro"
      onValueChange={(value) => console.log(value)}
      options={[
        { value: "gratis", label: "Gratis", description: "Untuk proyek pribadi." },
        { value: "pro", label: "Pro" },
      ]}
    />;
    <script setup lang="ts">
    import { ref } from "vue";
    import RadioGroup from "@/components/markas/RadioGroup.vue";
    
    const paket = ref("pro");
    </script>
    
    <template>
      <RadioGroup
        v-model="paket"
        name="paket"
        label="Paket langganan"
        :options="[
          {
            value: 'gratis',
            label: 'Gratis',
            description: 'Untuk proyek pribadi.',
          },
          { value: 'pro', label: 'Pro' },
        ]"
      />
    </template>
    <script lang="ts">
      import RadioGroup from "$lib/components/markas/RadioGroup.svelte";
    
      let plan = $state("pro");
    </script>
    
    <RadioGroup
      bind:value={plan}
      name="plan"
      label="Paket langganan"
      options={[
        { value: "free", label: "Gratis", description: "Untuk proyek pribadi." },
        { value: "pro", label: "Pro" },
      ]}
    />
    ---
    import RadioGroup from "@/components/markas/RadioGroup.astro";
    ---
    
    <RadioGroup
      name="plan"
      label="Paket langganan"
      value="pro"
      options={[
        { value: "free", label: "Gratis", description: "Untuk proyek pribadi." },
        { value: "pro", label: "Pro" },
      ]}
    />

    Tanpa script klien: opsinya radio native.

    import { Component, signal } from "@angular/core";
    import { RadioGroup } from "./markas/radio-group.component";
    
    @Component({
      selector: "app-tagihan",
      imports: [RadioGroup],
      template: `
        <markas-radio-group
          [(value)]="plan"
          name="plan"
          label="Paket langganan"
          [options]="plans"
        />
      `,
    })
    export class Tagihan {
      readonly plan = signal<string | undefined>("pro");
      readonly plans = [
        { value: "free", label: "Gratis", description: "Untuk proyek pribadi." },
        { value: "pro", label: "Pro" },
      ];
    }
    • Atribut tambahan (class, disabled, aria-*) jatuh ke <fieldset>. disabled di fieldset menonaktifkan semua radio sekaligus.
    • Value opsi dipakai sebagai bagian id, jadi pakai huruf kecil, angka, tanda hubung, atau underscore saja.
    • Pakai orientation="horizontal" untuk opsi pendek yang berjajar.
    • Komponen ini tidak punya teks bawaan. Cukup isi label serta label dan description tiap opsi dalam Bahasa Indonesia.

    Props

    NamaTipeDefaultKeterangan
    namestringrequiredAtribut name untuk semua radio di grup.
    options{ value, label, description? }[][]Daftar opsi. Value dipakai juga sebagai bagian id.
    labelstring-Judul grup, dirender sebagai legend.
    value / defaultValue / v-model / bind:valuestring-Opsi terpilih. Blade dan Astro memakai value, React value atau defaultValue, Vue v-model, Svelte bind:value, Angular value atau [(value)].
    onValueChange(value: string) => void-Khusus React. Dipanggil dengan value opsi yang baru dipilih.
    orientation"vertical" | "horizontal"verticalSusunan opsi: bertumpuk atau berjajar.
    idstringautoId fieldset, juga awalan id tiap radio. Dibuat otomatis kalau kosong.

    Aksesibilitas

    • Memakai fieldset dan legend sehingga judul grup dibacakan saat masuk ke radio.
    • Radio native: Tab masuk ke opsi terpilih, panah memindah pilihan.
    • Deskripsi opsi dihubungkan ke radio lewat aria-describedby.

    Komponen terkait

    Komponen form lain dengan class yang sama di setiap framework.