Class: SocialShareComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- SocialShareComponent
- Defined in:
- app/components/social_share_component.rb
Overview
ViewComponent: renders the social share block.
Constant Summary collapse
- LAYOUTS =
Layouts.
%i[auto desktop mobile hero].freeze
- DEFAULT_PLATFORMS =
Default platforms.
{ hero: %i[x facebook linkedin pinterest email copy], desktop: %i[x facebook linkedin pinterest email copy], mobile: %i[native x facebook whatsapp email copy], auto: %i[native x facebook whatsapp linkedin pinterest email copy] }.freeze
- PLATFORM_CONFIG =
Platform config.
{ x: { icon: 'x-twitter', family: 'fab', label: 'X' }, facebook: { icon: 'facebook-f', family: 'fab', label: 'Facebook' }, linkedin: { icon: 'linkedin-in', family: 'fab', label: 'LinkedIn' }, pinterest: { icon: 'pinterest-p', family: 'fab', label: 'Pinterest' }, whatsapp: { icon: 'whatsapp', family: 'fab', label: 'WhatsApp' }, email: { icon: 'envelope', family: 'far', label: 'Email' }, copy: { icon: 'link', family: 'far', label: 'Copy link', action: :copy }, native: { icon: 'share-nodes', family: 'far', label: 'Share', action: :native } }.freeze
Instance Method Summary collapse
- #hero? ⇒ Boolean
-
#initialize(title:, url:, image_url: nil, description: nil, utm_campaign: 'social-share', layout: :auto, platforms: nil) ⇒ SocialShareComponent
constructor
A new instance of SocialShareComponent.
- #platform_items ⇒ Object
- #show_desktop? ⇒ Boolean
- #show_mobile? ⇒ Boolean
Methods inherited from ApplicationComponent
#cms_link, #fetch_or_fallback, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_path, #post_url, #strip_tags
Constructor Details
#initialize(title:, url:, image_url: nil, description: nil, utm_campaign: 'social-share', layout: :auto, platforms: nil) ⇒ SocialShareComponent
Returns a new instance of SocialShareComponent.
35 36 37 38 39 40 41 42 43 44 |
# File 'app/components/social_share_component.rb', line 35 def initialize(title:, url:, image_url: nil, description: nil, utm_campaign: 'social-share', layout: :auto, platforms: nil) super() @title = title @url = url @image_url = image_url @description = description @utm_campaign = utm_campaign @layout = LAYOUTS.include?(layout) ? layout : :auto @platforms = platforms || DEFAULT_PLATFORMS[@layout] end |
Instance Method Details
#hero? ⇒ Boolean
54 55 56 |
# File 'app/components/social_share_component.rb', line 54 def hero? @layout == :hero end |
#platform_items ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/components/social_share_component.rb', line 58 def platform_items @platforms.filter_map do |key| config = PLATFORM_CONFIG[key] next unless config { key: key, icon: config[:icon], family: config[:family], label: config[:label], action: config[:action], href: platform_href(key) } end end |
#show_desktop? ⇒ Boolean
50 51 52 |
# File 'app/components/social_share_component.rb', line 50 def show_desktop? @layout == :auto || @layout == :desktop end |
#show_mobile? ⇒ Boolean
46 47 48 |
# File 'app/components/social_share_component.rb', line 46 def show_mobile? @layout == :auto || @layout == :mobile end |