Toggle

It's like a light switch for your app or website, letting you turn things on or off with just a click.

Adding the component

php artisan spur:add forms/toggle

If you use this to add the component, it will automatically add it to config/spur.php and auto-fetch the components files.

config/spur.php
"components": [
  'forms/toggle',
]

If you manually add the component in config/spur.php you would need to run
php artisan spur:fetch to import the component

Usage

Simple Toggle

<x-spur.toggle id="accept-terms" />

With Label

<x-spur.field id="accept-terms" type="toggle">
  <x-spur.label>Accept Terms & Conditions</x-spur.label>
  <x-spur.toggle name="accept-terms" />
</x-spur.field>

With Label and Description

Please read the terms and conditions carefully before proceeding

We promise not to spam your email

<x-spur.field id="accept-terms" type="toggle">
  <x-spur.label>Accept Terms & Conditions</x-spur.label>
  <x-spur.toggle name="accept-terms" />
  <x-spur.description>Please read the terms and conditions carefully before proceeding</x-spur.description>
</x-spur.field>

<x-spur.field id="accept-marketing" type="toggle">
  <x-spur.label>Accept to receive marketing emails</x-spur.label>
  <x-spur.toggle name="accept-marketing" />
  <x-spur.description>We promise not to spam your email</x-spur.description>
</x-spur.field>

Default checked state

Please read the terms and conditions carefully before proceeding

We promise not to spam your email

<x-spur.field id="accept-terms" type="toggle">
  <x-spur.label>Accept Terms & Conditions</x-spur.label>
  <x-spur.toggle name="accept-terms" checked />
  <x-spur.description>Please read the terms and conditions carefully before proceeding</x-spur.description>
</x-spur.field>

<x-spur.field id="accept-marketing" type="toggle">
  <x-spur.label>Accept to receive marketing emails</x-spur.label>
  <x-spur.toggle name="accept-marketing" />
  <x-spur.description>We promise not to spam your email</x-spur.description>
</x-spur.field>

Dense Toggle

You can use the attribute `dense` for a more compact version of toggle

To process please accept terms & conditions

<x-spur.field id="accept-terms" type="toggle">
  <x-spur.label>Accept Terms & Condition</x-spur.label>
  <x-spur.toggle name="accept-terms" dense/>
  <x-spur.description>To process please accept terms & conditions</x-spur.description>
</x-spur.field>

Disabled Toggle

Please read the terms and conditions carefully before proceeding

We promise not to spam your email

<x-spur.field id="accept-terms" type="toggle" disabled>
  <x-spur.label>Accept Terms & Conditions</x-spur.label>
  <x-spur.toggle name="accept-terms" />
  <x-spur.description>Please read the terms and conditions carefully before proceeding</x-spur.description>
</x-spur.field>

<x-spur.field id="accept-marketing" type="toggle">
  <x-spur.label>Accept to receive marketing emails</x-spur.label>
  <x-spur.toggle name="accept-marketing" />
  <x-spur.description>We promise not to spam your email</x-spur.description>
</x-spur.field>

Invalid Toggle

To process please accept terms & conditions

<x-spur.field id="accept-terms" type="toggle" invalid>
  <x-spur.label>Accept Terms & Condition</x-spur.label>
  <x-spur.toggle name="accept-terms" />
  <x-spur.description>To process please accept terms & conditions</x-spur.description>
</x-spur.field>

Accent Colors

<x-spur.toggle />
<x-spur.toggle color="indigo" />
<x-spur.toggle color="blue" />
<x-spur.toggle color="green" />
<x-spur.toggle color="yellow" />
<x-spur.toggle color="red" />