Class: Polaris::BoxComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/box_component.rb

Constant Summary collapse

AS_DEFAULT =
:div
AS_OPTIONS =
%i[div span section legend ul li]
LINE_STYLES =
%i[solid dashed]
OVERFLOW_OPTIONS =
%i[hidden scroll]
POSITION_OPTIONS =
%i[relative absolute fixed sticky]
ROLE_OPTIONS =
%i[status presentation menu listbox combobox]

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(as: AS_DEFAULT, background: nil, border_color: "transparent", border_style: nil, border_radius: nil, border_radius_end_start: nil, border_radius_end_end: nil, border_radius_start_start: nil, border_radius_start_end: nil, border_width: nil, border_block_start_width: nil, border_block_end_width: nil, border_inline_start_width: nil, border_inline_end_width: nil, color: nil, min_height: nil, min_width: nil, max_width: nil, overflow_x: nil, overflow_y: nil, padding: nil, padding_block_start: nil, padding_block_end: nil, padding_inline_start: nil, padding_inline_end: nil, role: nil, shadow: nil, width: nil, position: nil, inset_block_start: nil, inset_block_end: nil, inset_inline_start: nil, inset_inline_end: nil, opacity: nil, outline_color: nil, outline_style: nil, outline_width: nil, print_hidden: false, visually_hidden: false, z_index: nil, **system_arguments) ⇒ BoxComponent

Returns a new instance of BoxComponent.



11
12
13
14
15
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/components/polaris/box_component.rb', line 11

def initialize(
  as: AS_DEFAULT,
  background: nil,
  border_color: "transparent",
  border_style: nil,
  border_radius: nil,
  border_radius_end_start: nil,
  border_radius_end_end: nil,
  border_radius_start_start: nil,
  border_radius_start_end: nil,
  border_width: nil,
  border_block_start_width: nil,
  border_block_end_width: nil,
  border_inline_start_width: nil,
  border_inline_end_width: nil,
  color: nil,
  min_height: nil,
  min_width: nil,
  max_width: nil,
  overflow_x: nil,
  overflow_y: nil,
  padding: nil,
  padding_block_start: nil,
  padding_block_end: nil,
  padding_inline_start: nil,
  padding_inline_end: nil,
  role: nil,
  shadow: nil,
  width: nil,
  position: nil,
  inset_block_start: nil,
  inset_block_end: nil,
  inset_inline_start: nil,
  inset_inline_end: nil,
  opacity: nil,
  outline_color: nil,
  outline_style: nil,
  outline_width: nil,
  print_hidden: false,
  visually_hidden: false,
  z_index: nil,
  **system_arguments
)
  @system_arguments = system_arguments.tap do |args|
    args[:tag] = fetch_or_fallback(AS_OPTIONS, as, AS_DEFAULT)
    args[:role] = role_value(role)
    args[:classes] = class_names(
      args[:classes],
      "Polaris-Box",
      "Polaris-Box--visuallyHidden": visually_hidden,
      "Polaris-Box--printHidden": print_hidden,
      "Polaris-Box--listReset": as == :ul
    )
    args[:style] = styles_list(
      args[:style],
      "--pc-box-color": color_value(color),
      "--pc-box-background": background_value(background),
      "--pc-box-border-color": (border_color == "transparent") ? "transparent" : border_color_value(border_color),
      "--pc-box-border-style": style_value(border_style, border_color, border_width, border_block_start_width, border_block_end_width, border_inline_start_width, border_inline_end_width),
      "--pc-box-border-radius": border_radius_value(border_radius),
      "--pc-box-border-radius-end-start": border_radius_value(border_radius_end_start),
      "--pc-box-border-radius-end-end": border_radius_value(border_radius_end_end),
      "--pc-box-border-radius-start-start": border_radius_value(border_radius_start_start),
      "--pc-box-border-radius-start-end": border_radius_value(border_radius_start_end),
      "--pc-box-border-width": border_width_value(border_width),
      "--pc-box-border-block-start-width": border_width_value(border_block_start_width),
      "--pc-box-border-block-end-width": border_width_value(border_block_end_width),
      "--pc-box-border-inline-start-width": border_width_value(border_inline_start_width),
      "--pc-box-border-inline-end-width": border_width_value(border_inline_end_width),
      "--pc-box-min-height": min_height,
      "--pc-box-min-width": min_width,
      "--pc-box-max-width": max_width,
      "--pc-box-outline-color": border_color_value(outline_color),
      "--pc-box-outline-style": style_value(outline_style, outline_color, outline_width),
      "--pc-box-outline-width": border_width_value(outline_width),
      "--pc-box-overflow-x": overflow_value(overflow_x),
      "--pc-box-overflow-y": overflow_value(overflow_y),
      **padding_value("block-end", padding_block_end || padding),
      **padding_value("block-start", padding_block_start || padding),
      **padding_value("inline-end", padding_inline_end || padding),
      **padding_value("inline-start", padding_inline_start || padding),
      "--pc-box-shadow": shadow_value(shadow),
      "--pc-box-width": width,
      position: position_value(position),
      "--pc-box-inset-block-start": space_value(inset_block_start),
      "--pc-box-inset-block-end": space_value(inset_block_end),
      "--pc-box-inset-inline-start": space_value(inset_inline_start),
      "--pc-box-inset-inline-end": space_value(inset_inline_end),
      "z-index": z_index,
      opacity: opacity
    )
  end
end

Instance Method Details

#callObject



105
106
107
# File 'app/components/polaris/box_component.rb', line 105

def call
  render(Polaris::BaseComponent.new(**@system_arguments)) { content }
end