Menu

Checkbox

render Checkbox.new(size: :sm)
render Checkbox.new(size: :md)
render Checkbox.new(size: :lg)

Installation

Add the component to your project

CLI

Run the following command in your terminal

bundle exec essence add checkbox
Manually

Copy and paste the following code into your project

components/checkbox.rb
# frozen_string_literal: true

class Components::Checkbox < Components::Essence
  BASE = "rounded-xs border border-gray-950/10 ring-gray-950/5 focus:outline-none focus:ring-offset-1 focus-visible:ring-1"
  SIZES = {
    sm: "size-3",
    md: "",
    lg: "size-5"
  }

  attr_reader :size

  def initialize(size: :md, **attributes)
    @size = size
    super(**attributes)
  end

  def view_template
    input(type: "checkbox", **attributes)
  end

  def initialize_merged_classes = merge_classes([ BASE, SIZES[size], attributes[:class] ])
end