Class: Polaris::PageComponent

Inherits:
Component
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
app/components/polaris/page_component.rb

Defined Under Namespace

Classes: ActionGroupComponent

Constant Summary collapse

LONG_TITLE =
34

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from StylesListHelper

#styles_list

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested

Methods included from ClassNameHelper

#class_names

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_argumentsObject



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

Returns:

  • (Boolean)


112
113
114
# File 'app/components/polaris/page_component.rb', line 112

def has_pagination?
  @next_url.present? || @prev_url.present?
end

#header_argumentsObject



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

Returns:

  • (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

Returns:

  • (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_argumentsObject



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_argumentsObject



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_argumentsObject



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_lengthObject



57
58
59
60
# File 'app/components/polaris/page_component.rb', line 57

def title_length
  stripped_title = strip_tags(@title)&.strip
  stripped_title.present? ? stripped_title.length : 0
end