Sha256: df39c71535f4c58d4c264c1e80ab9a865b50d5a1f96c6d96f365b8794ab1ce7b

Contents?: true

Size: 1.8 KB

Versions: 23

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbButton
    class Button < Playbook::KitBase
      prop :disabled, type: Playbook::Props::Boolean,
                      default: false
      prop :full_width, type: Playbook::Props::Boolean,
                        default: false
      prop :link
      prop :loading, type: Playbook::Props::Boolean,
                     default: false
      prop :new_window, type: Playbook::Props::Boolean,
                        default: false
      prop :variant, type: Playbook::Props::Enum,
                     values: %w[primary secondary link],
                     default: "primary"
      prop :text
      prop :type
      prop :value
      prop :size, type: Playbook::Props::Enum,
                  values: ["sm", "md", "lg", nil],
                  default: nil
      prop :form, default: nil

      def options
        {
          aria: aria,
          class: classname,
          data: data,
          disabled: disabled,
          id: id,
          role: "button",
          type: type,
          value: value,
          form: form,
        }.compact
      end

      def link_options
        options.merge(
          href: link,
          role: "link",
          target: new_window ? "_blank" : "_self"
        )
      end

      def tag
        link ? "a" : "button"
      end

      def classname
        button_class = generate_classname("pb_button_kit", variant, full_width_class, disabled_class, loading_class)
        button_class + size_class
      end

    private

      def disabled_class
        disabled ? "disabled" : "enabled"
      end

      def full_width_class
        full_width ? "block" : "inline"
      end

      def loading_class
        loading ? "loading" : nil
      end

      def size_class
        size ? " size_#{size}" : ""
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
playbook_ui-10.23.0.pre.alpha1 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-10.22.1 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-10.22.0 app/pb_kits/playbook/pb_button/button.rb