app/components/optics/button/component.rb in optics_view_components-0.1.7 vs app/components/optics/button/component.rb in optics_view_components-0.1.8
- old
+ new
@@ -4,34 +4,31 @@
module Button
class Component < ApplicationViewComponent
SIZES = %w[small medium large].freeze
STYLES = %w[default primary secondary delete].freeze
- renders_one :leading_icon, lambda { |name:, size: 'normal'|
- Optics::Icon::Component.new(name:, size:)
- }
-
accepts :label
+ accepts :active, default: false
accepts :border, default: true
+ accepts :disabled, default: false
accepts :icon, default: false
+ accepts :icon_with_label, default: false
+ accepts :pill, default: false
accepts :size, default: 'medium'
accepts :variant, default: 'default'
accepts :url
def call
build_button do
- capture do
- concat leading_icon
- concat label
- end
+ content || label
end
end
def build_button(&)
- return link_to(url, class: classes, **@attributes.except(:class), &) if url
+ return link_to(url, class: classes, **@attributes.except(:class), &) if url && !disabled
- tag.button(class: classes, **@attributes.except(:class), &)
+ tag.button(class: classes, disabled:, **@attributes.except(:class), &)
end
def button_class
return 'btn' if variant == 'default'
@@ -41,11 +38,15 @@
def classes
class_names(
@attributes[:class],
button_class,
size_class,
+ 'btn--active': active,
+ 'btn--disabled': disabled,
'btn--icon': icon,
- 'btn--no-border': !border
+ 'btn--icon-with-label': icon_with_label,
+ 'btn--no-border': !border,
+ 'btn--pill': pill
).join(' ')
end
def size_class
return if size == 'medium'