Class: Alchemy::Admin::ToolbarButton

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/alchemy/admin/toolbar_button.rb

Overview

Renders a toolbar button for the Alchemy toolbar

Example

<%= render Alchemy::Admin::ToolbarButton.new(
  url: new_resource_path,
  icon: :plus,
  label: 'Create Resource',
  hotkey: 'alt+n',
  dialog_options: {
    title: 'Create Resource',
    size: "430x400"
  },
  if_permitted_to: [:create, resource_model]
) %>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, icon:, label:, hotkey: nil, title: nil, dialog: true, dialog_options: {}, skip_permission_check: false, if_permitted_to: [], active: false, link_options: {}, icon_style: "line", tooltip_placement: "top-start") ⇒ ToolbarButton

Returns a new instance of ToolbarButton.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/components/alchemy/admin/toolbar_button.rb', line 63

def initialize(
  url:,
  icon:,
  label:,
  hotkey: nil,
  title: nil,
  dialog: true,
  dialog_options: {},
  skip_permission_check: false,
  if_permitted_to: [],
  active: false,
  link_options: {},
  icon_style: "line",
  tooltip_placement: "top-start"
)
  @url = url
  @icon = icon
  @label = label
  @hotkey = hotkey
  @dialog = dialog
  @dialog_options = dialog_options
  @skip_permission_check = skip_permission_check
  @if_permitted_to = if_permitted_to
  @active = active
  @link_options = link_options
  @icon_style = icon_style
  @tooltip_placement = tooltip_placement
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def active
  @active
end

#dialogObject (readonly)

Returns the value of attribute dialog.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def dialog
  @dialog
end

#dialog_optionsObject (readonly)

Returns the value of attribute dialog_options.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def dialog_options
  @dialog_options
end

#hotkeyObject (readonly)

Returns the value of attribute hotkey.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def hotkey
  @hotkey
end

#iconObject (readonly)

Returns the value of attribute icon.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def icon
  @icon
end

#icon_styleObject (readonly)

Returns the value of attribute icon_style.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def icon_style
  @icon_style
end

#if_permitted_toObject (readonly)

Returns the value of attribute if_permitted_to.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def if_permitted_to
  @if_permitted_to
end

#labelObject (readonly)

Returns the value of attribute label.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def label
  @label
end

Returns the value of attribute link_options.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def link_options
  @link_options
end

#skip_permission_checkObject (readonly)

Returns the value of attribute skip_permission_check.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def skip_permission_check
  @skip_permission_check
end

#tooltip_placementObject (readonly)

Returns the value of attribute tooltip_placement.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def tooltip_placement
  @tooltip_placement
end

#urlObject (readonly)

Returns the value of attribute url.



50
51
52
# File 'app/components/alchemy/admin/toolbar_button.rb', line 50

def url
  @url
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'app/components/alchemy/admin/toolbar_button.rb', line 92

def render?
  skip_permission_check || can?(*permission_options)
end