```
--------------------------------
### Get Raw SVG Content for an Icon
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Retrieve the raw SVG content for a specific icon programmatically using `LucideRails::IconProvider.icon`.
```ruby
# Get raw SVG content for an icon
svg_content = LucideRails::IconProvider.icon('check')
# => ""
```
--------------------------------
### Configure Filesystem Icon Provider
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Set the icon provider to `:filesystem` in an initializer for lower memory usage, which loads icons from disk I/O per request.
```ruby
# config/initializers/lucide_rails.rb
# Use filesystem provider (lower memory, disk I/O per icon)
LucideRails.provider = :filesystem
```
--------------------------------
### Set Default Options for All Icons
Source: https://github.com/heyvito/lucide-rails/blob/master/README.md
Configure default attributes for all icons by updating `LucideRails.default_options` in an initializer file.
```ruby
LucideRails.default_options = LucideRails.default_options.merge(
'class' => 'lucide-icon',
'some-extra-attr' => 'some-other-value',
)
```
--------------------------------
### Use Icon Provider in Custom Helper
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Demonstrates how to use `LucideRails::IconProvider.icon` within a custom helper or service to dynamically retrieve icon SVG content based on different conditions.
```ruby
# Use in a custom helper or service
class NotificationService
def self.icon_for(type)
case type
when :success then LucideRails::IconProvider.icon('check-circle')
when :error then LucideRails::IconProvider.icon('x-circle')
when :warning then LucideRails::IconProvider.icon('alert-triangle')
when :info then LucideRails::IconProvider.icon('info')
end
end
end
```
--------------------------------
### Handle Unknown Icons with Icon Provider
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Illustrates how calling `LucideRails::IconProvider.icon` with a non-existent icon name raises an `ArgumentError`, which can be caught and handled.
```ruby
# Unknown icons raise ArgumentError
begin
LucideRails::IconProvider.icon('nonexistent-icon')
rescue ArgumentError => e
puts e.message # => "Unknown icon nonexistent-icon"
end
```
--------------------------------
### Configure Memory Icon Provider
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Set the icon provider to `:memory` in an initializer to use the default behavior, which loads all icons into an in-memory cache for faster access.
```ruby
# Use memory provider (default - loads all icons into memory cache)
LucideRails.provider = :memory
```
--------------------------------
### Loading Spinner
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Implement a loading spinner using the `loader` icon with Tailwind CSS's `animate-spin` class. Adjust `size` as needed.
```erb
```
--------------------------------
### Override Default Icon Size Globally
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Change the default width and height for all icons by merging new values into `LucideRails.default_options`.
```ruby
# Override default size for all icons
LucideRails.default_options = LucideRails.default_options.merge(
'width' => '20',
'height' => '20'
)
```
--------------------------------
### Navigation Menu with Icons
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Integrate icons into navigation links using the `lucide_icon` helper with `size` and `class` options for styling with Tailwind CSS.
```erb
```
--------------------------------
### Set Multiple Default Icon Attributes
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Apply multiple default attributes, such as CSS classes and stroke width, to all icons by merging them into `LucideRails.default_options`.
```ruby
# Multiple default attributes
LucideRails.default_options = LucideRails.default_options.merge(
'class' => 'icon',
'data-controller' => 'icon',
'stroke-width' => '1.5'
)
```
--------------------------------
### Set Custom Icon Dimensions and Fill
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Specify exact width and height, along with fill and stroke colors, for an icon using dedicated attributes.
```erb
<%# Icon with custom dimensions %>
<%= lucide_icon('star', width: 48, height: 48, fill: 'gold', stroke: 'orange') %>
```
--------------------------------
### Icon Buttons
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Create icon buttons by embedding the `lucide_icon` helper within button elements. Use `size` and `class` for styling.
```erb
```
--------------------------------
### Basic Icon Usage in Rails View
Source: https://github.com/heyvito/lucide-rails/blob/master/README.md
Use the `lucide_icon` helper in your ERB views to render a Lucide icon by its name.
```erb
<%= lucide_icon('accessibility') %>
```
--------------------------------
### Set Default CSS Class for All Icons
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Configure a default CSS class to be applied to all icons rendered by the gem by merging it into `LucideRails.default_options` in an initializer.
```ruby
# config/initializers/lucide_rails.rb
# Add a default CSS class to all icons
LucideRails.default_options = LucideRails.default_options.merge(
'class' => 'lucide-icon'
)
```
--------------------------------
### Customize Lucide Icon Size
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Control the size of an icon using the `size` shorthand attribute, which sets both width and height.
```erb
<%# Icon with custom size using the size shorthand %>
<%= lucide_icon('settings', size: 32) %>
<%# Sets both width and height to 32 %>
```
--------------------------------
### Customize Lucide Icon with CSS Class
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Apply custom CSS classes to an icon by passing them as an attribute to the `lucide_icon` helper.
```erb
<%# Icon with custom CSS class %>
<%= lucide_icon('user', class: 'icon-primary') %>
```
--------------------------------
### Configure Icon Accessibility Attributes
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Override default accessibility attributes like `aria-hidden` and provide an `aria-label` for screen readers when necessary.
```erb
<%# Icon with accessibility label (overrides default aria-hidden) %>
<%= lucide_icon('alert-triangle', 'aria-hidden' => 'false', 'aria-label' => 'Warning') %>
```
--------------------------------
### Rendered SVG for Accessibility Icon
Source: https://github.com/heyvito/lucide-rails/blob/master/README.md
The `lucide_icon` helper renders an SVG element for the specified icon.
```html
```
--------------------------------
### Render Basic Lucide Icon
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Use the `lucide_icon` helper in your ERB views to render an icon by its name. The helper generates an inline SVG element with default accessibility attributes.
```erb
<%# Basic icon rendering %>
<%= lucide_icon('home') %>
<%# Output: %>
```
--------------------------------
### Form Input with Icon
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Add an icon to a form input field for visual cues, such as a search icon. Use absolute positioning and padding to align the icon.
```erb
```
--------------------------------
### Embed Lucide Icon in a Button
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Integrate icons directly within HTML buttons, combining icon and text content for enhanced user interface elements.
```erb
<%# Icon in a button %>
```
--------------------------------
### Alert Messages with Icons
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Display alert or flash messages with appropriate status icons. The `lucide_icon` helper is used with `size` and `class` for visual feedback.
```erb
<%= lucide_icon('check-circle', size: 20, class: 'mr-2 flex-shrink-0') %>
Your changes have been saved successfully.
<%= lucide_icon('alert-triangle', size: 20, class: 'mr-2 flex-shrink-0') %>
An error occurred while processing your request.
```
--------------------------------
### Apply Multiple Custom Attributes to Icon
Source: https://context7.com/heyvito/lucide-rails/llms.txt
Pass multiple custom attributes, including CSS classes and stroke properties, to the `lucide_icon` helper for fine-grained control over the icon's appearance.
```erb
<%# Icon with multiple custom attributes %>
<%= lucide_icon('heart', class: 'text-red-500', stroke: '#ff0000', 'stroke-width' => '3') %>
```
--------------------------------
### Icon Usage with Extra Attributes
Source: https://github.com/heyvito/lucide-rails/blob/master/README.md
Pass additional HTML attributes to the `lucide_icon` helper to customize a single icon's SVG element.
```erb
<%= lucide_icon('accessibility', 'extra-attr' => 'test') %>
```
--------------------------------
### Rendered SVG with Extra Attributes
Source: https://github.com/heyvito/lucide-rails/blob/master/README.md
The SVG output includes the custom attributes passed to the helper.
```html
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.