Module: AppRail::Steps::Core::Stack

Included in:
Displayable
Defined in:
lib/app_rail/steps/core/stack.rb

Constant Summary collapse

CONTENT_MODE_OPTIONS =
%i[scale_aspect_fill scale_aspect_fit].freeze
IMAGE_STYLE_OPTIONS =
%i[full_width profile].freeze
TEXT_STYLE_OPTIONS =
%i[left large_center].freeze
BUTTON_STYLES =
%i[primary outline danger].freeze
ON_SUCCESS_OPTIONS =
%i[none reload backward forward].freeze

Instance Method Summary collapse

Instance Method Details

#ar_core_stack_button(label:, style: :primary, on_success: :forward, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/app_rail/steps/core/stack.rb', line 57

def ar_core_stack_button(label:, style: :primary, on_success: :forward, sf_symbol_name: nil, material_icon_name: nil)
  ar_core_stack_validate_on_success!(on_success)
  ar_core_stack_validate_button_style!(style)

  { type: :button, label: label, style: style, onSuccess: on_success, sfSymbolName: sf_symbol_name,
    materialIconName: material_icon_name }.compact
end

#ar_core_stack_delete_button(url:, label: "Delete", method: :delete, style: :danger, on_success: :backward, confirm_title: "Delete", confirm_text: "Are you sure?", sf_symbol_name: :trash, material_icon_name: :delete) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/app_rail/steps/core/stack.rb', line 65

def ar_core_stack_delete_button(url:, label: "Delete", method: :delete, style: :danger, on_success: :backward, confirm_title: "Delete", confirm_text: "Are you sure?", sf_symbol_name: :trash, material_icon_name: :delete)
  ar_core_stack_validate_on_success!(on_success)
  ar_core_stack_validate_button_style!(style)

  {
    type: :button,
    label: label,
    url: url,
    method: method,
    style: style,
    onSuccess: on_success,
    sfSymbolName: sf_symbol_name,
    materialIconName: material_icon_name,
    confirmTitle: confirm_title,
    confirmText: confirm_text
  }.compact
end

#ar_core_stack_image(image_url:, full_screen_image_url: nil, image_style: :full_width, content_mode: :scale_aspect_fill) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/app_rail/steps/core/stack.rb', line 26

def ar_core_stack_image(
  image_url:,
  full_screen_image_url: nil,
  image_style: :full_width,
  content_mode: :scale_aspect_fill
)
  validate_content_mode!(content_mode)
  validate_image_style!(image_style)

  {
    type: :image,
    contentMode: camelcase_converter(content_mode.to_s, first_letter: :lower),
    previewURL: image_url,
    fullScreenImageURL: full_screen_image_url,
    fullScreenImageOnTap: !full_screen_image_url.nil?,
    imageStyle: camelcase_converter(image_style.to_s, first_letter: :lower)
  }
end


101
102
103
104
105
106
107
# File 'lib/app_rail/steps/core/stack.rb', line 101

def ar_core_stack_link_button(label:, link_id:, style: :primary, on_success: :none, sf_symbol_name: nil, material_icon_name: nil)
  ar_core_stack_validate_on_success!(on_success)
  ar_core_stack_validate_button_style!(style)

  { type: :button, label: label, linkId: link_id, style: style, onSuccess: on_success,
    sfSymbolName: sf_symbol_name, materialIconName: material_icon_name }.compact
end

#ar_core_stack_modal_workflow_button(label:, modal_workflow_name:, style: :primary, on_success: :none, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object Also known as: ar_core_stack_button_for_modal_workflow

Remove this method once V1 is no longer being used



110
111
112
113
114
115
116
# File 'lib/app_rail/steps/core/stack.rb', line 110

def ar_core_stack_modal_workflow_button(label:, modal_workflow_name:, style: :primary, on_success: :none, sf_symbol_name: nil, material_icon_name: nil)
  ar_core_stack_validate_on_success!(on_success)
  ar_core_stack_validate_button_style!(style)

  { type: :button, label: label, modalWorkflow: modal_workflow_name, style: style, onSuccess: on_success,
    sfSymbolName: sf_symbol_name, materialIconName: material_icon_name }.compact
end

#ar_core_stack_system_url_button(label:, apple_system_url: nil, android_deep_link: nil, style: :primary, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object Also known as: ar_core_stack_button_for_system_url



92
93
94
95
96
97
98
# File 'lib/app_rail/steps/core/stack.rb', line 92

def ar_core_stack_system_url_button(label:, apple_system_url: nil, android_deep_link: nil, style: :primary, sf_symbol_name: nil, material_icon_name: nil)
  ar_core_stack_validate_button_style!(style)
  raise "Invalid android_deep_link" if android_deep_link && !android_deep_link.start_with?("http")

  { type: :button, label: label, appleSystemURL: apple_system_url, androidDeepLink: android_deep_link,
    style: style, sfSymbolName: sf_symbol_name, materialIconName: material_icon_name }.compact
end

#ar_core_stack_text(text:, text_style: :left, label: nil, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/app_rail/steps/core/stack.rb', line 13

def ar_core_stack_text(text:, text_style: :left, label: nil, sf_symbol_name: nil, material_icon_name: nil)
  validate_text_style!(text_style)

  {
    type: :text,
    textStyle: camelcase_converter(text_style.to_s, first_letter: :lower),
    label: label,
    text: text.to_s,
    sfSymbolName: sf_symbol_name,
    materialIconName: material_icon_name
  }.compact
end

#ar_core_stack_unsplash_image(image_url) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/app_rail/steps/core/stack.rb', line 45

def ar_core_stack_unsplash_image(image_url)
  if image_url.start_with? "https://unsplash.com/photos"
    unsplash_id = image_url.split("/").last
    image_url = "https://source.unsplash.com/#{unsplash_id}/800x600"
  end
  ar_core_stack_image(image_url: image_url, full_screen_image_url: image_url)
end

#ar_core_stack_url_button(url:, label:, method: :put, style: :primary, confirm_title: nil, confirm_text: nil, on_success: :reload, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object Also known as: ar_core_stack_button_for_url



83
84
85
86
87
88
89
# File 'lib/app_rail/steps/core/stack.rb', line 83

def ar_core_stack_url_button(url:, label:, method: :put, style: :primary, confirm_title: nil, confirm_text: nil, on_success: :reload, sf_symbol_name: nil, material_icon_name: nil)
  ar_core_stack_validate_on_success!(on_success)
  ar_core_stack_validate_button_style!(style)

  { type: :button, label: label, url: url, method: method, style: style, confirmTitle: confirm_title,
    confirmText: confirm_text, onSuccess: on_success, sfSymbolName: sf_symbol_name, materialIconName: material_icon_name }.compact
end

#ar_core_stack_video(preview_url:, attachment_url:) ⇒ Object



53
54
55
# File 'lib/app_rail/steps/core/stack.rb', line 53

def ar_core_stack_video(preview_url:, attachment_url:)
  { type: :video, previewURL: preview_url, url: attachment_url }
end