Module: Polaris::ViewHelper

Included in:
Component
Defined in:
app/helpers/polaris/view_helper.rb

Overview

Module to allow shorthand calls for Polaris components

Constant Summary collapse

POLARIS_HELPERS =

standard:disable Layout/HashAlignment

{
  action_list:              "Polaris::ActionListComponent",
  autocomplete:             "Polaris::AutocompleteComponent",
  autocomplete_section:     "Polaris::Autocomplete::SectionComponent",
  autocomplete_option:      "Polaris::Autocomplete::OptionComponent",
  avatar:                   "Polaris::AvatarComponent",
  badge:                    "Polaris::BadgeComponent",
  banner:                   "Polaris::BannerComponent",
  bleed:                    "Polaris::BleedComponent",
  box:                      "Polaris::BoxComponent",
  button:                   "Polaris::ButtonComponent",
  button_group:             "Polaris::ButtonGroupComponent",
  callout_card:             "Polaris::CalloutCardComponent",
  caption:                  "Polaris::CaptionComponent",
  card:                     "Polaris::CardComponent",
  card_section:             "Polaris::Card::SectionComponent",
  checkbox:                 "Polaris::CheckboxComponent",
  check_box:                "Polaris::CheckboxComponent",
  choice_list:              "Polaris::ChoiceListComponent",
  collapsible:              "Polaris::CollapsibleComponent",
  data_table:               "Polaris::DataTableComponent",
  description_list:         "Polaris::DescriptionListComponent",
  display_text:             "Polaris::DisplayTextComponent",
  divider:                  "Polaris::DividerComponent",
  dropzone:                 "Polaris::DropzoneComponent",
  empty_search_results:     "Polaris::EmptySearchResultsComponent",
  empty_state:              "Polaris::EmptyStateComponent",
  exception_list:           "Polaris::ExceptionListComponent",
  footer_help:              "Polaris::FooterHelpComponent",
  form_layout:              "Polaris::FormLayoutComponent",
  frame:                    "Polaris::FrameComponent",
  filters:                  "Polaris::FiltersComponent",
  heading:                  "Polaris::HeadingComponent",
  horizontal_grid:          "Polaris::HorizontalGridComponent",
  horizontal_stack:         "Polaris::HorizontalStackComponent",
  icon:                     "Polaris::IconComponent",
  index_table:              "Polaris::IndexTableComponent",
  inline_code:              "Polaris::InlineCodeComponent",
  inline:                   "Polaris::InlineComponent",
  inline_error:             "Polaris::InlineErrorComponent",
  keyboard_key:             "Polaris::KeyboardKeyComponent",
  layout:                   "Polaris::LayoutComponent",
  link:                     "Polaris::LinkComponent",
  list:                     "Polaris::ListComponent",
  modal:                    "Polaris::ModalComponent",
  modal_section:            "Polaris::Modal::SectionComponent",
  navigation:               "Polaris::NavigationComponent",
  navigation_list:          "Polaris::NavigationListComponent",
  option_list:              "Polaris::OptionListComponent",
  page:                     "Polaris::PageComponent",
  page_actions:             "Polaris::PageActionsComponent",
  pagination:               "Polaris::PaginationComponent",
  placeholder:              "Polaris::PlaceholderComponent",
  progress_bar:             "Polaris::ProgressBarComponent",
  popover:                  "Polaris::PopoverComponent",
  radio_button:             "Polaris::RadioButtonComponent",
  resource_list:            "Polaris::ResourceListComponent",
  resource_item:            "Polaris::ResourceItemComponent",
  select:                   "Polaris::SelectComponent",
  setting_toggle:           "Polaris::SettingToggleComponent",
  shopify_navigation:       "Polaris::ShopifyNavigationComponent",
  stack:                    "Polaris::StackComponent",
  stack_item:               "Polaris::Stack::ItemComponent",
  subheading:               "Polaris::SubheadingComponent",
  scrollable:               "Polaris::ScrollableComponent",
  spinner:                  "Polaris::SpinnerComponent",
  skeleton_body_text:       "Polaris::SkeletonBodyTextComponent",
  skeleton_display_text:    "Polaris::SkeletonDisplayTextComponent",
  skeleton_page:            "Polaris::SkeletonPageComponent",
  skeleton_thumbnail:       "Polaris::SkeletonThumbnailComponent",
  spacer:                   "Polaris::SpacerComponent",
  tabs:                     "Polaris::TabsComponent",
  tag:                      "Polaris::TagComponent",
  text:                     "Polaris::TextComponent",
  text_container:           "Polaris::TextContainerComponent",
  text_field:               "Polaris::TextFieldComponent",
  text_style:               "Polaris::TextStyleComponent",
  thumbnail:                "Polaris::ThumbnailComponent",
  toast:                    "Polaris::ToastComponent",
  tooltip:                  "Polaris::TooltipComponent",
  vertical_stack:           "Polaris::VerticalStackComponent",
  visually_hidden:          "Polaris::VisuallyHiddenComponent"
}.freeze
POLARIS_TEXT_STYLES =
%i[subdued strong positive negative code].freeze

Instance Method Summary collapse

Instance Method Details

#polaris_body_stylesObject



128
129
130
# File 'app/helpers/polaris/view_helper.rb', line 128

def polaris_body_styles
  %(background-color: var(--p-color-bg-app);color: var(--p-color-text);)
end

#polaris_html_classesObject



120
121
122
# File 'app/helpers/polaris/view_helper.rb', line 120

def polaris_html_classes
  "Polaris-Summer-Editions-2023"
end

#polaris_html_stylesObject



124
125
126
# File 'app/helpers/polaris/view_helper.rb', line 124

def polaris_html_styles
  %(--pc-frame-global-ribbon-height:0px; --pc-frame-offset:0px;)
end

#polaris_icon_source(name) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/helpers/polaris/view_helper.rb', line 102

def polaris_icon_source(name)
  paths = [
    ViewComponents::Engine.root.join("app", "assets", "icons", "polaris", "#{name}.svg"),
    Rails.root.join("app", "assets", "icons", "polaris", "#{name}.svg")
  ]

  path = paths.find { |path| File.exist?(path) }
  return unless path

  file = File.read(path)
  doc = Nokogiri::HTML::DocumentFragment.parse(file)
  svg = doc.at_css "svg"
  svg[:class] = "Polaris-Icon__Svg"
  svg[:focusable] = false
  svg[:"aria-hidden"] = true
  doc.to_html.html_safe
end