class Primer::BaseComponent
“‘
<h1 class=“mt-0 mt-lg-4 mt-xl-2”>Hello world</h1>
“`html
Renders:
“`
<% end %>
Hello world
<%= render Primer::Beta::Heading.new(mt: [0, nil, nil, 4, 2]) do %>
“`erb
For example:
To apply different values across responsive breakpoints, pass an array with up to five values in the order `[default, small, medium, large, xlarge]`. To skip a breakpoint, pass `nil`.
## Responsive values
Under the hood, system arguments are [mapped](github.com/primer/view_components/blob/main/lib/primer/classify.rb) to Primer CSS classes, with any remaining options passed to Rails’ [‘content_tag`](api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag).
All Primer ViewComponents accept a standard set of options called system arguments, mimicking the [styled-system API](styled-system.com/table) used by [Primer React](primer.style/components/system-props).
def call
def call if SELF_CLOSING_TAGS.include?(@tag) tag(@tag, @content_tag_args.merge(@result)) else content_tag(@tag, content, @content_tag_args.merge(@result)) end end
def initialize(tag:, classes: nil, **system_arguments)
| classes | String | CSS class name value to be concatenated with generated Primer CSS classes. |
| :- | :- | :- |
| Name | Type | Description |
## Other
| `word_break` | Symbol | Whether to break words on line breaks. <%= one_of(Primer::Classify::Utilities.mappings(:word_break)) %> |
| `underline` | Boolean | Whether text should be underlined. |
| `text_transform` | Symbol | Text transformation. <%= one_of([:uppercase, :capitalize]) %> |
| `text_align` | Symbol | Text alignment. <%= one_of([:left, :right, :center]) %> |
| `font_weight` | Symbol | Font weight. <%= one_of([:light, :normal, :bold, :emphasized]) %> |
| `font_style` | Symbol | Font style. <%= one_of([:italic]) %> |
| `font_size` | String, Integer, Symbol | <%= one_of(["00", 0, 1, 2, 3, 4, 5, 6, :small, :normal]) %> |
| `font_family` | Symbol | Font family. <%= one_of([:mono]) %> |
| :- | :- | :- |
| Name | Type | Description |
## Typography
| `py` | Integer | Vertical padding. <%= one_of(Primer::Classify::Utilities.mappings(:py)) %> |
| `px` | Integer | Horizontal padding. <%= one_of(Primer::Classify::Utilities.mappings(:px)) %> |
| `pt` | Integer | Padding left. <%= one_of(Primer::Classify::Utilities.mappings(:pt)) %> |
| `pr` | Integer | Padding right. <%= one_of(Primer::Classify::Utilities.mappings(:pr)) %> |
| `pl` | Integer | Padding left. <%= one_of(Primer::Classify::Utilities.mappings(:pl)) %> |
| `pb` | Integer | Padding bottom. <%= one_of(Primer::Classify::Utilities.mappings(:pb)) %> |
| `p` | Integer | Padding. <%= one_of(Primer::Classify::Utilities.mappings(:p)) %> |
| `my` | Integer | Vertical margins. <%= one_of(Primer::Classify::Utilities.mappings(:my)) %> |
| `mx` | Integer | Horizontal margins. <%= one_of(Primer::Classify::Utilities.mappings(:mx)) %> |
| `mt` | Integer | Margin top. <%= one_of(Primer::Classify::Utilities.mappings(:mt)) %> |
| `mr` | Integer | Margin right. <%= one_of(Primer::Classify::Utilities.mappings(:mr)) %> |
| `ml` | Integer | Margin left. <%= one_of(Primer::Classify::Utilities.mappings(:ml)) %> |
| `mb` | Integer | Margin bottom. <%= one_of(Primer::Classify::Utilities.mappings(:mb)) %> |
| `m` | Integer | Margin. <%= one_of(Primer::Classify::Utilities.mappings(:m)) %> |
| :- | :- | :- |
| Name | Type | Description |
## Spacing
| `top` | Boolean | If `false`, sets `top: 0`. |
| `right` | Boolean | If `false`, sets `right: 0`. |
| `position` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:position)) %> |
| `left` | Boolean | If `false`, sets `left: 0`. |
| `float` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:float)) %> |
| `bottom` | Boolean | If `false`, sets `bottom: 0`. |
| :- | :- | :- |
| Name | Type | Description |
## Position
| `vertical_align` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:vertical_align)) %> |
| `visibility` | Symbol | Visibility. <%= one_of(Primer::Classify::Utilities.mappings(:visibility)) %> |
| `hide` | Symbol | Hide the element at a specific breakpoint. <%= one_of(Primer::Classify::Utilities.mappings(:hide)) %> |
| `h` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:h)) %> |
| `w` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:w)) %> |
| `display` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:display)) %> |
| :- | :- | :- |
| Name | Type | Description |
## Layout
| `container` | Symbol | Size of the container. <%= one_of(Primer::Classify::Utilities.mappings(:container)) %> |
| `col` | Integer | Number of columns. <%= one_of(Primer::Classify::Utilities.mappings(:col)) %> |
| `clearfix` | Boolean | Whether to assign the `clearfix` class. |
| :- | :- | :- |
| Name | Type | Description |
## Grid
| `justify_content` | Symbol | <%= one_of(Primer::Classify::FLEX_JUSTIFY_CONTENT_VALUES) %> |
| `flex_wrap` | Symbol | <%= one_of(Primer::Classify::FLEX_WRAP_MAPPINGS.keys) %> |
| `flex_shrink` | Integer | To enable, set to `0`. |
| `flex_grow` | Integer | To enable, set to `0`. |
| `flex` | Integer, Symbol | <%= one_of(Primer::Classify::FLEX_VALUES) %> |
| `direction` | Symbol | <%= one_of(Primer::Classify::FLEX_DIRECTION_VALUES) %> |
| `align_self` | Symbol | <%= one_of(Primer::Classify::FLEX_ALIGN_SELF_VALUES) %> |
| `align_items` | Symbol | <%= one_of(Primer::Classify::FLEX_ALIGN_ITEMS_VALUES) %> |
| :- | :- | :- |
| Name | Type | Description |
## Flex
| `color` | Symbol | Text color. <%= one_of(Primer::Classify::Utilities.mappings(:color)) %> |
| `border_color` | Symbol | Border color. <%= one_of(Primer::Classify::Utilities.mappings(:border_color)) %> |
| `bg` | Symbol | Background color. <%= one_of(Primer::Classify::Utilities.mappings(:bg)) %> |
| :- | :- | :- |
| Name | Type | Description |
## Color
| `box_shadow` | Boolean, Symbol | Box shadow. <%= one_of([true, :medium, :large, :extra_large, :none]) %> |
| `border` | Symbol | <%= one_of([:left, :top, :bottom, :right, :y, :x, true]) %> |
| `border_top` | Integer | Set to `0` to remove the top border. |
| `border_right` | Integer | Set to `0` to remove the right border. |
| `border_radius` | Integer | <%= one_of([0, 1, 2, 3]) %> |
| `border_left` | Integer | Set to `0` to remove the left border. |
| `border_bottom` | Integer | Set to `0` to remove the bottom border. |
| :- | :- | :- |
| Name | Type | Description |
## Border
| `animation` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:animation)) %> |
| :- | :- | :- |
| Name | Type | Description |
## Animation
| `width` | `Integer` | Width. |
| `title` | `String` | The `title` attribute. |
| `style` | `String` | Inline styles. |
| `hidden` | `Boolean` | Whether to assign the `hidden` attribute. |
| `height` | `Integer` | Height. |
| `data` | `Hash` | Data attributes: `data: { foo: :bar }` renders `data-foo='bar'`. |
| `aria` | `Hash` | Aria attributes: `aria: { label: "foo" }` renders `aria-label='foo'`. |
| :- | :- | :- |
| Name | Type | Description |
System arguments include most HTML attributes. For example:
## HTML attributes
def initialize(tag:, classes: nil, **system_arguments) @tag = tag @system_arguments = validate_arguments(tag: tag, **system_arguments) @result = Primer::Classify.call(**@system_arguments.merge(classes: classes)) @system_arguments[:"data-view-component"] = true # Filter out Primer keys so they don't get assigned as HTML attributes @content_tag_args = add_test_selector(@system_arguments).except(*Primer::Classify::Utilities::UTILITIES.keys) end