83 lines
2.7 KiB
Ruby
83 lines
2.7 KiB
Ruby
module LucideHelper
|
|
# Create a Lucide icon element
|
|
#
|
|
# @param name [String] The name of the Lucide icon
|
|
# @param options [Hash] Additional options
|
|
# @option options [String] :class Additional CSS classes
|
|
# @option options [String] :size Size class (e.g., 'w-4 h-4', 'w-6 h-6')
|
|
# @option options [Hash] :data Additional data attributes
|
|
#
|
|
# @return [String] HTML string for the icon
|
|
#
|
|
# Usage:
|
|
# lucide_icon('user')
|
|
# lucide_icon('check-circle', class: 'text-green-500', size: 'w-5 h-5')
|
|
# lucide_icon('menu', data: { action: 'click->header#toggleMenu' })
|
|
def lucide_icon(name, options = {})
|
|
css_classes = [ "lucide-icon" ]
|
|
css_classes << options[:size] if options[:size]
|
|
css_classes << options[:class] if options[:class]
|
|
|
|
data_attributes = { lucide: name }
|
|
data_attributes.merge!(options[:data]) if options[:data]
|
|
|
|
content_tag :i, "",
|
|
class: css_classes.join(" "),
|
|
data: data_attributes,
|
|
**options.except(:class, :size, :data)
|
|
end
|
|
|
|
# Create a button with a Lucide icon
|
|
#
|
|
# @param name [String] The name of the Lucide icon
|
|
# @param options [Hash] Button options
|
|
# @option options [String] :text Button text (optional)
|
|
# @option options [String] :class Additional CSS classes for button
|
|
# @option options [String] :icon_class Additional CSS classes for icon
|
|
# @option options [String] :icon_size Size class for icon
|
|
#
|
|
# Usage:
|
|
# lucide_button('plus', text: 'Add Item', class: 'btn btn-primary')
|
|
# lucide_button('trash-2', class: 'btn-danger', data: { confirm: 'Are you sure?' })
|
|
def lucide_button(name, options = {})
|
|
text = options.delete(:text)
|
|
icon_class = options.delete(:icon_class)
|
|
icon_size = options.delete(:icon_size) || "w-4 h-4"
|
|
|
|
icon = lucide_icon(name, class: icon_class, size: icon_size)
|
|
|
|
content = if text.present?
|
|
safe_join([ icon, " ", text ])
|
|
else
|
|
icon
|
|
end
|
|
|
|
content_tag :button, content, options
|
|
end
|
|
|
|
# Create a link with a Lucide icon
|
|
#
|
|
# @param name [String] The name of the Lucide icon
|
|
# @param url [String] The URL for the link
|
|
# @param options [Hash] Link options
|
|
#
|
|
# Usage:
|
|
# lucide_link('edit', edit_user_path(user), text: 'Edit')
|
|
# lucide_link('external-link', 'https://example.com', text: 'Visit', target: '_blank')
|
|
def lucide_link(name, url, options = {})
|
|
text = options.delete(:text)
|
|
icon_class = options.delete(:icon_class)
|
|
icon_size = options.delete(:icon_size) || "w-4 h-4"
|
|
|
|
icon = lucide_icon(name, class: icon_class, size: icon_size)
|
|
|
|
content = if text.present?
|
|
safe_join([ icon, " ", text ])
|
|
else
|
|
icon
|
|
end
|
|
|
|
link_to content, url, options
|
|
end
|
|
end
|