Sha256: a024b880405231bd62faa223ad85c7cc5c51f7ccae130478a23165d5c35629f5

Contents?: true

Size: 1.99 KB

Versions: 43

Compression:

Stored size: 1.99 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 :icon
      prop :icon_right, 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",
          tabindex: 0,
          type: type,
          value: value,
          form: form,
        }.compact
      end

      def link_options
        options.tap do |option|
          option[:href] = link
          option[:role] = "link"
          option[:target] = "_blank" if new_window
          option[:tabindex] = 0
        end
      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

43 entries across 43 versions & 1 rubygems

Version Path
playbook_ui-12.10.0.pre.alpha.PLAY705phonenumberreturn372 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.10.0.pre.alpha.PLAY677richtexteditorts370 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.10.0 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.9.1.pre.alpha.play664tiptapinvestigation353 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.9.1.pre.alpha.PLAY689bugtxtinputlabel346 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.9.1.pre.alpha.menucleanup345 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.9.1.pre.alpha.menucleanup342 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.9.1 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.9.0 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.8.0.pre.alpha.PLAY625phonenumberdark301 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.8.0.pre.alpha.PLAY625phonenumberdark300 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.8.0.pre.alpha.PLAY649mapkitstyles299 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.8.0.pre.alpha.PLAY645typescriptprogresstep298 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.8.0.pre.alpha.PLAY645typescriptprogresstep297 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.8.0.pre.alpha.rubyandnpmalpharelease296 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.8.0.pre.alpha.rubyandnpmalpharelease295 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.8.0.pre.alpha.rubyandnpmalpharelease294 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.8.0 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.7.1.pre.alpha.rubyandnpmalpharelease293 app/pb_kits/playbook/pb_button/button.rb
playbook_ui-12.7.1.pre.alpha.rubyandnpmalpharelease292 app/pb_kits/playbook/pb_button/button.rb