Class: Polaris::PageComponent
- Inherits:
-
Component
- Object
- Component
- Polaris::PageComponent
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- app/components/polaris/page_component.rb
Defined Under Namespace
Classes: ActionGroupComponent
Constant Summary collapse
- LONG_TITLE =
34
Instance Method Summary collapse
- #content_arguments ⇒ Object
- #has_pagination? ⇒ Boolean
- #header_arguments ⇒ Object
-
#initialize(title: nil, subtitle: nil, compact_title: false, back_url: nil, prev_url: nil, next_url: nil, pagination_label: nil, narrow_width: false, full_width: false, divider: false, secondary_actions: [], **system_arguments) ⇒ PageComponent
constructor
A new instance of PageComponent.
- #render_header? ⇒ Boolean
- #render_primary_action? ⇒ Boolean
- #subtitle_arguments ⇒ Object
- #system_arguments ⇒ Object
- #title_arguments ⇒ Object
- #title_length ⇒ Object
Constructor Details
#initialize(title: nil, subtitle: nil, compact_title: false, back_url: nil, prev_url: nil, next_url: nil, pagination_label: nil, narrow_width: false, full_width: false, divider: false, secondary_actions: [], **system_arguments) ⇒ PageComponent
Returns a new instance of PageComponent.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/components/polaris/page_component.rb', line 16 def initialize( title: nil, subtitle: nil, compact_title: false, back_url: nil, prev_url: nil, next_url: nil, pagination_label: nil, narrow_width: false, full_width: false, divider: false, secondary_actions: [], **system_arguments ) @title = title @subtitle = subtitle @compact_title = compact_title @back_url = back_url @prev_url = prev_url @next_url = next_url @pagination_label = pagination_label @narrow_width = narrow_width @full_width = full_width @divider = divider @secondary_actions = secondary_actions @system_arguments = system_arguments end |
Instance Method Details
#content_arguments ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'app/components/polaris/page_component.rb', line 82 def content_arguments { tag: "div", classes: class_names( "Polaris-Page__Content": !render_header?, "Polaris-Page--divider": @divider && render_header? ) } end |
#has_pagination? ⇒ Boolean
112 113 114 |
# File 'app/components/polaris/page_component.rb', line 112 def has_pagination? @next_url.present? || @prev_url.present? end |
#header_arguments ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/components/polaris/page_component.rb', line 44 def header_arguments { tag: "div", classes: class_names( "Polaris-Page-Header--mobileView", "Polaris-Page-Header--mediumTitle": @title.present? && title_length <= LONG_TITLE, "Polaris-Page-Header--longTitle": @title.present? && title_length > LONG_TITLE, "Polaris-Page-Header--hasNavigation": @back_url.present?, "Polaris-Page-Header--noBreadcrumbs": @back_url.blank? ) } end |
#render_header? ⇒ Boolean
104 105 106 |
# File 'app/components/polaris/page_component.rb', line 104 def render_header? @title.present? || @subtitle.present? || @back_url.present? || render_primary_action? end |
#render_primary_action? ⇒ Boolean
108 109 110 |
# File 'app/components/polaris/page_component.rb', line 108 def render_primary_action? primary_action.present? || custom_primary_action.present? end |
#subtitle_arguments ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'app/components/polaris/page_component.rb', line 72 def subtitle_arguments { tag: "div", classes: class_names( "Polaris-Header-Title__SubTitle", "Polaris-Header-Title__SubtitleCompact": @compact_title ) } end |
#system_arguments ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/components/polaris/page_component.rb', line 92 def system_arguments @system_arguments.tap do |opts| opts[:tag] = "div" opts[:classes] = class_names( opts[:classes], "Polaris-Page", "Polaris-Page--fullWidth": @full_width, "Polaris-Page--narrowWidth": @narrow_width ) end end |
#title_arguments ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'app/components/polaris/page_component.rb', line 62 def title_arguments { tag: "h1", classes: class_names( "Polaris-Header-Title", "Polaris-Header-Title__TitleWithSubtitle": @subtitle.present? ) } end |
#title_length ⇒ Object
57 58 59 60 |
# File 'app/components/polaris/page_component.rb', line 57 def title_length stripped_title = (@title)&.strip stripped_title.present? ? stripped_title.length : 0 end |