code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def initialize( menu_id: self.class.generate_id, anchor_align: Primer::Alpha::Overlay::DEFAULT_ANCHOR_ALIGN, anchor_side: Primer::Alpha::Overlay::DEFAULT_ANCHOR_SIDE, size: Primer::Alpha::Overlay::DEFAULT_SIZE, src: nil, preload: DEFAULT_PRELOAD, dynamic_label: false, dynamic_label_prefix: nil, select_variant: DEFAULT_SELECT_VARIANT, form_arguments: {}, overlay_arguments: {}, **system_arguments ) @menu_id = menu_id @src = src @preload = fetch_or_fallback_boolean(preload, DEFAULT_PRELOAD) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:preload] = true if @src.present? && preload? @select_variant = fetch_or_fallback(SELECT_VARIANT_OPTIONS, select_variant, DEFAULT_SELECT_VARIANT) @system_arguments[:tag] = :"action-menu" @system_arguments[:"data-select-variant"] = select_variant @system_arguments[:"data-dynamic-label"] = "" if dynamic_label @system_arguments[:"data-dynamic-label-prefix"] = dynamic_label_prefix if dynamic_label_prefix.present? overlay_arguments[:data] = merge_data( overlay_arguments, data: { target: "action-menu.overlay" } ) @overlay = Primer::Alpha::Overlay.new( id: "#{@menu_id}-overlay", title: "Menu", visually_hide_title: true, anchor_align: anchor_align, anchor_side: anchor_side, size: size, **overlay_arguments ) @list = Primer::Alpha::ActionMenu::List.new( menu_id: @menu_id, select_variant: select_variant, form_arguments: form_arguments ) end
@param menu_id [String] Id of the menu. @param anchor_align [Symbol] <%= one_of(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS) %>. @param anchor_side [Symbol] <%= one_of(Primer::Alpha::Overlay::ANCHOR_SIDE_OPTIONS) %>. @param size [Symbol] <%= one_of(Primer::Alpha::Overlay::SIZE_OPTIONS) %>. @param src [String] Used with an `include-fragment` element to load menu content from the given source URL. @param preload [Boolean] When true, and src is present, loads the `include-fragment` on trigger hover. @param dynamic_label [Boolean] Whether or not to display the text of the currently selected item in the show button. @param dynamic_label_prefix [String] If provided, the prefix is prepended to the dynamic label and displayed in the show button. @param select_variant [Symbol] <%= one_of(Primer::Alpha::ActionMenu::SELECT_VARIANT_OPTIONS) %> @param form_arguments [Hash] Allows an `ActionMenu` to act as a select list in multi- and single-select modes. Pass the `builder:` and `name:` options to this hash. `builder:` should be an instance of `ActionView::Helpers::FormBuilder`, which are created by the standard Rails `#form_with` and `#form_for` helpers. The `name:` option is the desired name of the field that will be included in the params sent to the server on form submission. @param overlay_arguments [Hash] Arguments to pass to the underlying <%= link_to_component(Primer::Alpha::Overlay) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>.
initialize
ruby
primer/view_components
app/components/primer/alpha/action_menu.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_menu.rb
MIT
def with_show_button(**system_arguments, &block) @overlay.with_show_button(**system_arguments, id: "#{@menu_id}-button", controls: "#{@menu_id}-list") do |button| evaluate_block(button, &block) end end
@!parse # Button to activate the menu. # # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::Overlay) %>'s `show_button` slot. renders_one(:show_button) Button to activate the menu. @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::Overlay) %>'s `show_button` slot.
with_show_button
ruby
primer/view_components
app/components/primer/alpha/action_menu.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_menu.rb
MIT
def with_item(**system_arguments, &block) @list.with_item(**system_arguments, &block) end
@!parse # Adds a new item to the list. # # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList::Item) %>. renders_many(:items) Adds a new item to the list. @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList::Item) %>.
with_item
ruby
primer/view_components
app/components/primer/alpha/action_menu.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_menu.rb
MIT
def with_divider(**system_arguments, &block) @list.with_divider(**system_arguments, &block) end
Adds a divider to the list. @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %>'s `divider` slot.
with_divider
ruby
primer/view_components
app/components/primer/alpha/action_menu.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_menu.rb
MIT
def with_avatar_item(**system_arguments, &block) @list.with_avatar_item(**system_arguments, &block) end
Adds an avatar item to the list. Avatar items are a convenient way to accessibly add an item with a leading avatar image. @param src [String] The source url of the avatar image. @param username [String] The username associated with the avatar. @param full_name [String] Optional. The user's full name. @param full_name_scheme [Symbol] Optional. How to display the user's full name. @param avatar_arguments [Hash] Optional. The arguments accepted by <%= link_to_component(Primer::Beta::Avatar) %>. @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList::Item) %>.
with_avatar_item
ruby
primer/view_components
app/components/primer/alpha/action_menu.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_menu.rb
MIT
def initialize(label_text:, src:, list_id:, input_id:, input_name: nil, is_label_visible: true, is_label_inline: false, with_icon: false, is_clearable: false, **system_arguments) @label_text = label_text @list_id = list_id @input_id = input_id @input_name = input_name || input_id @is_label_visible = is_label_visible @with_icon = with_icon @is_clearable = is_clearable @label_classes = label_classes(is_label_visible: is_label_visible, is_label_inline: is_label_inline) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = "auto-complete" @system_arguments[:src] = src @system_arguments[:for] = list_id end
@param label_text [String] The label of the input. @param src [String] The route to query. @param input_id [String] Id of the input element. @param input_name [String] Optional name of the input element, defaults to `input_id` when not set. @param list_id [String] Id of the list element. @param with_icon [Boolean] Controls if a search icon is visible, defaults to `false`. @param is_label_visible [Boolean] Controls if the label is visible. If `false`, screen reader only text will be added. @param is_clearable [Boolean] Adds optional clear button. @param is_label_inline [Boolean] Controls if the label is inline. On smaller screens, label will always become stacked. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/auto_complete.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/auto_complete.rb
MIT
def before_render with_results(classes: "") unless results? with_input(classes: "") unless input? end
add `input` and `results` without needing to explicitly call them in the view
before_render
ruby
primer/view_components
app/components/primer/alpha/auto_complete.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/auto_complete.rb
MIT
def label_classes(**args) return "" if args[:is_label_visible] == false args[:is_label_inline] ? "autocomplete-label-inline" : "autocomplete-label-stacked" end
Private: determines the label classes based on component configration. If the label is not visible, return an empty string. @param args [Hash] The component configuration. @return [String] The label classes.
label_classes
ruby
primer/view_components
app/components/primer/alpha/auto_complete.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/auto_complete.rb
MIT
def initialize(tag: DEFAULT_TAG, full: false, full_when_narrow: false, dismiss_scheme: DEFAULT_DISMISS_SCHEME, dismiss_label: DEFAULT_DISMISS_LABEL, description: nil, icon: nil, scheme: DEFAULT_SCHEME, **system_arguments) @scheme = fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, DEFAULT_SCHEME) @icon = icon || DEFAULT_ICONS[@scheme] @dismiss_scheme = dismiss_scheme @dismiss_label = dismiss_label @description = description @system_arguments = system_arguments @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) @system_arguments[:classes] = class_names( @system_arguments[:classes], "Banner", "flash", # legacy SCHEME_MAPPINGS[@scheme], LEGACY_SCHEME_MAPPINGS[@scheme], "Banner--full": full, "flash-full": full, # legacy "Banner--full-whenNarrow": full_when_narrow ) @message_arguments = { tag: :div, classes: "Banner-message" } @wrapper_arguments = { tag: custom_element_name, data: { dismiss_scheme: @dismiss_scheme } } end
@param tag [Symbol] <%= one_of(Primer::Alpha::Banner::TAG_OPTIONS) %> @param full [Boolean] Whether the component should take up the full width of the screen. @param full_when_narrow [Boolean] Whether the component should take up the full width of the screen when rendered inside smaller viewports. @param dismiss_scheme [Symbol] Whether the component can be dismissed with an "x" button. <%= one_of(Primer::Alpha::Banner::DISMISS_SCHEMES) %> @param dismiss_label [String] The aria-label text of the dismiss "x" button @param description [String] Description text rendered underneath the message. @param icon [Symbol] The name of an <%= link_to_octicons %> icon to use. If no icon is provided, a default one will be chosen based on the scheme. @param scheme [Symbol] <%= one_of(Primer::Alpha::Banner::SCHEME_MAPPINGS.keys) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/banner.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/banner.rb
MIT
def initialize( scheme: DEFAULT_SCHEME, variant: DEFAULT_VARIANT, tag: DEFAULT_TAG, type: DEFAULT_TYPE, disabled: false, **system_arguments ) @system_arguments = system_arguments @system_arguments[:block] = false @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) @system_arguments[:type] = fetch_or_fallback(TYPE_OPTIONS, type, DEFAULT_TYPE) @system_arguments[:classes] = class_names( "btn-mktg", SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)], VARIANT_MAPPINGS[fetch_or_fallback(VARIANT_OPTIONS, variant, DEFAULT_VARIANT)], system_arguments[:classes] ) @system_arguments[:disabled] = disabled end
@param scheme [Symbol] <%= one_of(Primer::Alpha::ButtonMarketing::SCHEME_OPTIONS) %> @param variant [Symbol] <%= one_of(Primer::Alpha::ButtonMarketing::VARIANT_OPTIONS) %> @param tag [Symbol] <%= one_of(Primer::Alpha::ButtonMarketing::TAG_OPTIONS) %> @param type [Symbol] <%= one_of(Primer::Alpha::ButtonMarketing::TYPE_OPTIONS) %> @param disabled [Boolean] Whether or not the button is disabled. If true, this option forces `tag:` to `:button`. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/button_marketing.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/button_marketing.rb
MIT
def initialize( title:, subtitle: nil, size: DEFAULT_SIZE, position: DEFAULT_POSITION, position_narrow: DEFAULT_POSITION_NARROW, visually_hide_title: false, id: self.class.generate_id, disable_scroll: true, **system_arguments ) @system_arguments = deny_tag_argument(**system_arguments) @id = id.to_s @title = title @subtitle = subtitle @size = size @position = position @position_narrow = position_narrow @visually_hide_title = visually_hide_title @disable_scroll = disable_scroll @system_arguments[:tag] = "dialog" @system_arguments[:id] = @id @system_arguments[:aria] = { modal: true } @system_arguments[:aria] = merge_aria( @system_arguments, { aria: { labelledby: labelledby, describedby: "#{@id}-description" } } ) @system_arguments[:classes] = class_names( "Overlay", "Overlay-whenNarrow", SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, @size, DEFAULT_SIZE)], "Overlay--motion-scaleFade", POSITION_MAPPINGS[fetch_or_fallback(POSITION_OPTIONS, @position, DEFAULT_POSITION)], POSITION_NARROW_MAPPINGS[fetch_or_fallback(POSITION_NARROW_MAPPINGS, @position_narrow, DEFAULT_POSITION_NARROW)], system_arguments[:classes], "Overlay--disableScroll" => @disable_scroll ) end
@param id [String] The id of the dialog. @param title [String] Describes the content of the dialog. @param subtitle [String] Provides additional context for the dialog, also setting the `aria-describedby` attribute. @param size [Symbol] The size of the dialog. <%= one_of(Primer::Alpha::Dialog::SIZE_OPTIONS) %> @param position [Symbol] The position of the dialog. <%= one_of(Primer::Alpha::Dialog::POSITION_OPTIONS) %> @param position_narrow [Symbol] The position of the dialog when narrow. <%= one_of(Primer::Alpha::Dialog::POSITION_NARROW_OPTIONS) %> @param visually_hide_title [Boolean] If true will hide the heading title, while still making it available to Screen Readers. @param disable_scroll [Boolean] When true, disables scrolling the page when the dialog is open. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/dialog.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/dialog.rb
MIT
def initialize(overlay: :default, with_caret: false, **system_arguments) @with_caret = with_caret @system_arguments = system_arguments @system_arguments[:overlay] = overlay @system_arguments[:reset] = true @system_arguments[:classes] = class_names( @system_arguments[:classes], "dropdown" ) end
@param overlay [Symbol] <%= one_of(Primer::Beta::Details::OVERLAY_MAPPINGS.keys) %> @param with_caret [Boolean] Whether or not a caret should be rendered in the button. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/dropdown.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/dropdown.rb
MIT
def initialize(label:, caption: nil, validation_message: nil, required: false, visually_hide_label: false, full_width: false, label_arguments: {}, **system_arguments) @label = label @init_caption = caption @validation_message = validation_message @required = required @visually_hide_label = visually_hide_label @full_width = full_width @label_arguments = label_arguments @system_arguments = system_arguments @system_arguments[:classes] = class_names( @system_arguments[:classes], "FormControl", "FormControl--fullWidth" => full_width? ) @label_arguments[:classes] = class_names( @label_arguments.delete(:classes), "FormControl-label", visually_hide_label? ? "sr-only" : nil ) base_id = self.class.generate_id @validation_id = "validation-#{base_id}" @caption_id = "caption-#{base_id}" @validation_arguments = { classes: "FormControl-inlineValidation", id: @validation_id } end
@param label [String] Label text displayed above the input. @param caption [String] Describes the field and what sort of input it expects. Displayed below the input. Note that the `caption` slot is also available and takes precedence over this argument when provided. @param validation_message [String] A string displayed in red between the caption and the input indicating the input's contents are invalid. @param required [Boolean] Default `false`. When set to `true`, causes an asterisk (*) to appear next to the field's label indicating it is a required field. Note that this option explicitly does _not_ add a `required` HTML attribute. Doing so would enable native browser validations, which are inaccessible and inconsistent with the Primer design system. @param visually_hide_label [Boolean] When set to `true`, hides the label. Although the label will be hidden visually, it will still be visible to screen readers. @param full_width [Boolean] When set to `true`, the form control will take up all the horizontal space allowed by its container. @param label_arguments [Hash] HTML attributes to attach to the `<label>` element that labels the input. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/form_control.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/form_control.rb
MIT
def with_input(&block) @input_block = block end
@!parse # The input content. Yields a set of <%= link_to_system_arguments_docs %> that should be added to the input. # renders_one(:input)
with_input
ruby
primer/view_components
app/components/primer/alpha/form_control.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/form_control.rb
MIT
def initialize(inline: false, disabled: false, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) validate_aria_label @system_arguments[:tag] = :button @system_arguments[:"aria-expanded"] = false @system_arguments[:classes] = class_names( @system_arguments[:classes], "inline" => inline ) @system_arguments[:disabled] = disabled end
@param inline [Boolean] Whether or not the button is inline. @param disabled [Boolean] Whether or not the button is disabled. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/hellip_button.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/hellip_button.rb
MIT
def initialize(inline: false, button_arguments: {}, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @button_arguments = button_arguments @system_arguments[:tag] = :span @system_arguments[:classes] = class_names( "hidden-text-expander", @system_arguments[:classes], "inline" => inline ) aria_label = system_arguments[:"aria-label"] || system_arguments.dig(:aria, :label) || @aria_label if aria_label.present? @button_arguments[:"aria-label"] = aria_label @system_arguments[:aria]&.delete(:label) end @button_arguments[:classes] = class_names( "ellipsis-expander", button_arguments[:classes] ) end
@param inline [Boolean] Whether or not the expander is inline. @param button_arguments [Hash] <%= link_to_system_arguments_docs %> for the button element. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/hidden_text_expander.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/hidden_text_expander.rb
MIT
def initialize(src:, alt:, lazy: false, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @src = src @system_arguments[:tag] = :img @system_arguments[:alt] = alt return unless lazy @system_arguments[:loading] = :lazy @system_arguments[:decoding] = :async end
@param src [String] The source url of the image. @param alt [String] Specifies an alternate text for the image. @param lazy [Boolean] Whether or not to lazily load the image. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/image.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/image.rb
MIT
def initialize(src: nil, loading: nil, accept: nil, **system_arguments) @system_arguments = system_arguments @system_arguments[:tag] = "include-fragment" @system_arguments[:loading] = loading @system_arguments[:src] = src @system_arguments[:accept] = accept if accept if loading @system_arguments[:loading] = fetch_or_fallback(ALLOWED_LOADING_VALUES, loading.to_sym, DEFAULT_LOADING) end if Primer::CurrentAttributes.nonce @system_arguments[:"data-nonce"] = Primer::CurrentAttributes.nonce end end
@param src [String] The URL from which to retrieve an HTML element fragment. @param loading [Symbol] <%= one_of([:lazy, :eager]) %> @param accept [String] What to send as the Accept header. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/include_fragment.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/include_fragment.rb
MIT
def initialize(icons: []) @icons = {} icons.each do |icon| symbol = icon[:symbol] size = Primer::Beta::Octicon::SIZE_MAPPINGS[ fetch_or_fallback(Primer::Beta::Octicon::SIZE_OPTIONS, icon[:size] || Primer::Beta::Octicon::SIZE_DEFAULT, Primer::Beta::Octicon::SIZE_DEFAULT) ] cache_key = Primer::Octicon::Cache.get_key(symbol: symbol, size: size) if (cache_icon = Primer::Octicon::Cache.read(cache_key)) icon_instance = cache_icon else icon_instance = Octicons::Octicon.new(symbol, height: size) Primer::Octicon::Cache.set(cache_key, icon_instance) end # Don't put the same icon twice @icons[[symbol, icon_instance.height]] = icon_instance if @icons[[symbol, icon_instance.height]].nil? end end
@param icons [Array<Hash>] List of icons to render, in the format { symbol: :icon_name, size: :small }
initialize
ruby
primer/view_components
app/components/primer/alpha/octicon_symbols.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/octicon_symbols.rb
MIT
def initialize( title:, role: nil, subtitle: nil, popover: DEFAULT_POPOVER, size: DEFAULT_SIZE, padding: DEFAULT_PADDING, anchor: nil, anchor_align: DEFAULT_ANCHOR_ALIGN, anchor_offset: DEFAULT_ANCHOR_OFFSET, anchor_side: DEFAULT_ANCHOR_SIDE, allow_out_of_bounds: false, visually_hide_title: false, id: self.class.generate_id, **system_arguments ) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:role] = fetch_or_fallback(ROLE_OPTIONS, role) if role.present? @system_arguments[:id] = id.to_s @wrapper_classes = class_names( "Overlay", SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)] ) @system_arguments[:tag] = "anchored-position" @system_arguments[:anchor] = anchor || "overlay-show-#{@system_arguments[:id]}" @system_arguments[:align] = fetch_or_fallback(ANCHOR_ALIGN_OPTIONS, anchor_align, DEFAULT_ANCHOR_ALIGN) @system_arguments[:side] = ANCHOR_SIDE_MAPPINGS[fetch_or_fallback(ANCHOR_SIDE_OPTIONS, anchor_side, DEFAULT_ANCHOR_SIDE)] @system_arguments["anchor-offset"] = fetch_or_fallback(ANCHOR_OFFSET_OPTIONS, anchor_offset, DEFAULT_ANCHOR_OFFSET) @system_arguments["allow-out-of-bounds"] = true if allow_out_of_bounds @id = id.to_s @title = title @subtitle = subtitle @visually_hide_title = visually_hide_title @padding = padding @system_arguments[:popover] = popover @system_arguments[:aria] ||= {} end
@param id [String] The id of the Overlay. @param title [String] Describes the content of the Overlay. @param subtitle [String] Provides dditional context for the Overlay, also setting the `aria-describedby` attribute. @param popover [Symbol] The popover behaviour. <%= one_of(Primer::Alpha::Overlay::POPOVER_OPTIONS) %> @param size [Symbol] The size of the Overlay. <%= one_of(Primer::Alpha::Overlay::SIZE_OPTIONS) %> @param padding [Symbol] The padding given to the Overlay body. <%= one_of(Primer::Alpha::Overlay::PADDING_OPTIONS) %> @param anchor [String] An ID of the element to anchor onto. Defaults to the `show_button`. @param anchor_align [Symbol] The anchor alignment of the Overlay. <%= one_of(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS) %> @param anchor_side [Symbol] The side to anchor the Overlay to. <%= one_of(Primer::Alpha::Overlay::ANCHOR_SIDE_OPTIONS) %> @param anchor_offset [Symbol] The anchor offset to give the Overlay. <%= one_of(Primer::Alpha::Overlay::ANCHOR_OFFSET_OPTIONS) %> @param allow_out_of_bounds [Boolean] Allow the Overlay to overflow its container. @param visually_hide_title [Boolean] If true will hide the heading title, while still making it available to Screen Readers. @param role [String] The ARIA role. <%= one_of(Primer::Alpha::Overlay::ROLE_OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/overlay.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/overlay.rb
MIT
def initialize(hide_labels: HIDE_LABELS_DEFAULT, full_width: FULL_WIDTH_DEFAULT, size: Primer::Beta::Button::DEFAULT_SIZE, **system_arguments) @full_width = full_width @size = size @hide_labels = hide_labels @system_arguments = system_arguments @system_arguments[:tag] = :ul @system_arguments[:role] = "list" @system_arguments[:classes] = class_names( system_arguments[:classes], SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)], "SegmentedControl", "SegmentedControl--iconOnly": hide_labels, "SegmentedControl--fullWidth": full_width ) validate_aria_label end
@param hide_labels [Boolean] Whether to hide the labels and only show the icons @param full_width [Boolean] If the component should be full width @param size [Symbol] <%= one_of(Primer::Beta::Button::SIZE_OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/segmented_control.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/segmented_control.rb
MIT
def initialize(**system_arguments) raise_if_role_given!(**system_arguments) select_variant = system_arguments.delete(:select_variant) || Primer::Alpha::ActionList::DEFAULT_SELECT_VARIANT super( p: 2, role: "listbox", aria_selection_variant: select_variant == :single ? :selected : :checked, select_variant: select_variant == :multiple ? :multiple_checkbox : :single, **system_arguments ) end
@param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %>.
initialize
ruby
primer/view_components
app/components/primer/alpha/select_panel.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/select_panel.rb
MIT
def initialize( src: nil, title: "Menu", id: self.class.generate_id, size: :small, select_variant: DEFAULT_SELECT_VARIANT, fetch_strategy: DEFAULT_FETCH_STRATEGY, no_results_label: "No results found", preload: DEFAULT_PRELOAD, dynamic_label: false, dynamic_label_prefix: nil, dynamic_aria_label_prefix: nil, body_id: nil, use_experimental_non_local_form: false, list_arguments: {}, form_arguments: {}, show_filter: true, open_on_load: false, anchor_align: Primer::Alpha::Overlay::DEFAULT_ANCHOR_ALIGN, anchor_side: Primer::Alpha::Overlay::DEFAULT_ANCHOR_SIDE, loading_label: "Loading content...", loading_description: nil, banner_scheme: DEFAULT_BANNER_SCHEME, **system_arguments ) raise_if_role_given!(**system_arguments) if src.present? url = URI(src) query = url.query || "" url.query = query.split("&").push("experimental=1").join("&") @src = url end @panel_id = id @body_id = body_id || "#{@panel_id}-body" @preload = fetch_or_fallback_boolean(preload, DEFAULT_PRELOAD) @select_variant = fetch_or_fallback(SELECT_VARIANT_OPTIONS, select_variant, DEFAULT_SELECT_VARIANT) @fetch_strategy = fetch_or_fallback(FETCH_STRATEGIES, fetch_strategy, DEFAULT_FETCH_STRATEGY) @no_results_label = no_results_label @show_filter = show_filter @dynamic_label = dynamic_label @dynamic_label_prefix = dynamic_label_prefix @dynamic_aria_label_prefix = dynamic_aria_label_prefix @loading_label = loading_label @loading_description_id = nil if use_experimental_non_local_form @form_builder = form_arguments[:builder] @value = form_arguments[:value] @input_name = form_arguments[:name] end @list_form_arguments = use_experimental_non_local_form ? {} : form_arguments if loading_description.present? @loading_description_id = "#{@panel_id}-loading-description" end @loading_description = loading_description @banner_scheme = fetch_or_fallback(BANNER_SCHEME_OPTIONS, banner_scheme, DEFAULT_BANNER_SCHEME) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:id] = @panel_id @system_arguments[:"anchor-align"] = fetch_or_fallback(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS, anchor_align, Primer::Alpha::Overlay::DEFAULT_ANCHOR_ALIGN) @system_arguments[:"anchor-side"] = Primer::Alpha::Overlay::ANCHOR_SIDE_MAPPINGS[fetch_or_fallback(Primer::Alpha::Overlay::ANCHOR_SIDE_OPTIONS, anchor_side, Primer::Alpha::Overlay::DEFAULT_ANCHOR_SIDE)] @title = title @system_arguments[:tag] = :"select-panel" @system_arguments[:preload] = true if @src.present? && preload? @system_arguments[:data] = merge_data( system_arguments, { data: { select_variant: @select_variant, fetch_strategy: @fetch_strategy, open_on_load: open_on_load }.tap do |data| data[:dynamic_label] = dynamic_label if dynamic_label data[:dynamic_label_prefix] = dynamic_label_prefix if dynamic_label_prefix.present? data[:dynamic_aria_label_prefix] = dynamic_aria_label_prefix if dynamic_aria_label_prefix.present? end } ) @dialog = Primer::BaseComponent.new( id: "#{@panel_id}-dialog", "aria-labelledby": "#{@panel_id}-dialog-title", tag: :dialog, data: { target: "select-panel.dialog" }, classes: class_names( "Overlay", "Overlay-whenNarrow", Primer::Alpha::Dialog::SIZE_MAPPINGS[ fetch_or_fallback(Primer::Alpha::Dialog::SIZE_OPTIONS, size, Primer::Alpha::Dialog::DEFAULT_SIZE) ], ), style: "position: absolute;", ) @list = Primer::Alpha::SelectPanel::ItemList.new( **list_arguments, form_arguments: @list_form_arguments, id: "#{@panel_id}-list", select_variant: @select_variant, aria: { label: "#{title} options" } ) return if @show_filter || @fetch_strategy != :remote return if shouldnt_raise_error? raise( "Hiding the filter input with a remote fetch strategy is not permitted, "\ "since such a combinaton of options will cause the component to only "\ "fetch items from the server once when the panel opens for the first time; "\ "this is what the `:eventually_local` fetch strategy is designed to do. "\ "Consider passing `show_filter: true` or use the `:eventually_local` fetch "\ "strategy instead." ) end
@param src [String] The URL to fetch search results from. @param title [String] The title that appears at the top of the panel. @param id [String] The unique ID of the panel. @param size [Symbol] The size of the panel. <%= one_of(Primer::Alpha::Overlay::SIZE_OPTIONS) %> @param select_variant [Symbol] <%= one_of(Primer::Alpha::SelectPanel::SELECT_VARIANT_OPTIONS) %> @param fetch_strategy [Symbol] <%= one_of(Primer::Alpha::SelectPanel::FETCH_STRATEGIES) %> @param no_results_label [String] The label to display when no results are found. @param preload [Boolean] Whether to preload search results when the page loads. If this option is false, results are loaded when the panel is opened. @param dynamic_label [Boolean] Whether or not to display the text of the currently selected item in the show button. @param dynamic_label_prefix [String] If provided, the prefix is prepended to the dynamic label and displayed in the show button. @param dynamic_aria_label_prefix [String] If provided, the prefix is prepended to the dynamic label and set as the value of the `aria-label` attribute on the show button. @param body_id [String] The unique ID of the panel body. If not provided, the body ID will be set to the panel ID with a "-body" suffix. @param list_arguments [Hash] Arguments to pass to the underlying <%= link_to_component(Primer::Alpha::ActionList) %> component. Only has an effect for the local fetch strategy. @param form_arguments [Hash] Form arguments. Supported for `local`, and experimentally supported for `remote` and `eventually_local` strategies by enabling the `use_experimental_non_local_form` flag. @param use_experimental_non_local_form [Boolean] A feature flag used to slowly roll out moving the input field (generated from form arguments) to the top of the SelectPanel HTML thus allowing remote fetching to have default form values. At this time, support is only available for the :single select variant. See: https://github.com/github/primer/issues/4923. @param show_filter [Boolean] Whether or not to show the filter input. @param open_on_load [Boolean] Open the panel when the page loads. @param anchor_align [Symbol] The anchor alignment of the Overlay. <%= one_of(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS) %> @param anchor_side [Symbol] The side to anchor the Overlay to. <%= one_of(Primer::Alpha::Overlay::ANCHOR_SIDE_OPTIONS) %> @param loading_label [String] The aria-label to use when the panel is loading, defaults to 'Loading content...'. @param loading_description [String] The description to use when the panel is loading. If not provided, no description will be used. @param banner_scheme [Symbol] The scheme for the error banner <%= one_of(Primer::Alpha::SelectPanel::BANNER_SCHEME_OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/select_panel.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/select_panel.rb
MIT
def initialize( tag: DEFAULT_TAG, justify: JustifyArg::DEFAULT, gap: GapArg::DEFAULT, direction: DirectionArg::DEFAULT, align: AlignArg::DEFAULT, wrap: WrapArg::DEFAULT, padding: PaddingArg::DEFAULT, **system_arguments ) @system_arguments = system_arguments @system_arguments[:tag] = tag @system_arguments[:classes] = class_names( @system_arguments.delete(:classes), "Stack" ) @system_arguments[:data] = merge_data( @system_arguments, { data: { **JustifyArg.for(justify).to_data_attributes, **GapArg.for(gap).to_data_attributes, **DirectionArg.for(direction).to_data_attributes, **AlignArg.for(align).to_data_attributes, **WrapArg.for(wrap).to_data_attributes, **PaddingArg.for(padding).to_data_attributes, } } ) end
@param tag [Symbol] Customize the element type of the rendered container. @param gap [Symbol] Specify the gap between children elements in the stack. <%= one_of(Primer::Alpha::Stack::GapArg::OPTIONS) %> @param direction [Symbol] Specify the direction for the stack container. <%= one_of(Primer::Alpha::Stack::DirectionArg::OPTIONS) %> @param align [Symbol] Specify the alignment between items in the cross-axis of the direction. <%= one_of(Primer::Alpha::Stack::AlignArg::OPTIONS) %> @param wrap [Symbol] Specify whether items are forced onto one line or can wrap onto multiple lines. <%= one_of(Primer::Alpha::Stack::WrapArg::OPTIONS) %> @param justify [Symbol] Specify how items will be distributed in the stacking direction. <%= one_of(Primer::Alpha::Stack::JustifyArg::OPTIONS) %> @param padding [Symbol] Specify the padding of the stack container. <%= one_of(Primer::Alpha::Stack::PaddingArg::OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/stack.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/stack.rb
MIT
def initialize(tag: DEFAULT_TAG, grow: false, **system_arguments) @tag = tag @grow = grow @system_arguments = system_arguments @system_arguments[:tag] = tag @system_arguments[:classes] = class_names( @system_arguments.delete(:classes), "StackItem" ) @system_arguments[:data] = merge_data( @system_arguments, { data: { **GrowArg.for(grow).to_data_attributes } } ) end
@param tag [Symbol] Customize the element type of the rendered container. @param grow [Boolean] Allow item to keep size or expand to fill the available space. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/stack_item.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/stack_item.rb
MIT
def initialize(label:, tag: TAG_DEFAULT, body_arguments: {}, **system_arguments) @align = EXTRA_ALIGN_DEFAULT @system_arguments = system_arguments @body_arguments = body_arguments @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT) @system_arguments[:classes] = tab_nav_classes(system_arguments[:classes]) @body_arguments[:tag] = BODY_TAG_DEFAULT @body_arguments[:classes] = tab_nav_body_classes(body_arguments[:classes]) aria_label_for_page_nav(label) end
@param tag [Symbol] <%= one_of(Primer::Alpha::TabNav::TAG_OPTIONS) %> @param label [String] Sets an `aria-label` that helps assistive technology users understand the purpose of the links, and distinguish it from similar elements. @param body_arguments [Hash] <%= link_to_system_arguments_docs %> for the body wrapper. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/tab_nav.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/tab_nav.rb
MIT
def initialize(label:, body_arguments: {}, wrapper_arguments: {}, **system_arguments) @align = EXTRA_ALIGN_DEFAULT @wrapper_arguments = wrapper_arguments @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :div @system_arguments[:classes] = tab_nav_classes(@system_arguments[:classes]) @body_arguments = deny_tag_argument(**body_arguments) @body_arguments[:tag] = :ul @body_arguments[:classes] = tab_nav_body_classes(@body_arguments[:classes]) @body_arguments[:role] = :tablist @body_arguments[:"aria-label"] = label end
@param label [String] Sets an `aria-label` that helps assistive technology users understand the purpose of the tabs. @param align [Symbol] <%= one_of(Primer::TabNavHelper::EXTRA_ALIGN_OPTIONS) %> - Defaults to <%= Primer::TabNavHelper::EXTRA_ALIGN_DEFAULT %> @param body_arguments [Hash] <%= link_to_system_arguments_docs %> for the body wrapper. @param wrapper_arguments [Hash] <%= link_to_system_arguments_docs %> for the `TabContainer` wrapper. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/tab_panels.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/tab_panels.rb
MIT
def initialize( src: nil, csrf_token: nil, checked: false, enabled: true, size: SIZE_DEFAULT, status_label_position: STATUS_LABEL_POSITION_DEFAULT, turbo: false, autofocus: nil, **system_arguments ) @src = src @csrf_token = csrf_token @checked = checked @enabled = enabled @turbo = turbo @system_arguments = system_arguments @size = fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT) @status_label_position = fetch_or_fallback( STATUS_LABEL_POSITION_OPTIONS, status_label_position, STATUS_LABEL_POSITION_DEFAULT ) @system_arguments[:classes] = class_names( @system_arguments.delete(:classes), "ToggleSwitch", on? ? "ToggleSwitch--checked" : nil, enabled? ? nil : "ToggleSwitch--disabled", STATUS_LABEL_POSITION_MAPPINGS[@status_label_position], SIZE_MAPPINGS[@size] ) @button_arguments = { aria: merge_aria( @system_arguments, aria: { pressed: on? } ) } @button_arguments[:autofocus] = true if autofocus @system_arguments[:src] = @src if @src end
@param src [String] The URL to POST to when the toggle switch is toggled. If `nil`, the toggle switch will not make any requests. @param csrf_token [String] A CSRF token that will be sent to the server as "authenticity_token" when the toggle switch is toggled. Unused if `src` is `nil`. @param checked [Boolean] Whether the toggle switch is on or off. @param enabled [Boolean] Whether or not the toggle switch responds to user input. @param size [Symbol] What size toggle switch to render. <%= one_of(Primer::Alpha::ToggleSwitch::SIZE_OPTIONS) %> @param status_label_position [Symbol] Which side of the toggle switch to render the status label. <%= one_of(Primer::Alpha::ToggleSwitch::STATUS_LABEL_POSITION_OPTIONS) %> @param turbo [Boolean] Whether or not to request a turbo stream and render the response as such. @param autofocus [Boolean] Whether switch should be autofocused when rendered. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/toggle_switch.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/toggle_switch.rb
MIT
def initialize(type:, for_id:, text:, direction: DIRECTION_DEFAULT, **system_arguments) raise TypeError, "tooltip text must be a string" unless text.is_a?(String) @text = text @system_arguments = system_arguments @id = @system_arguments[:id] ||= self.class.generate_id @system_arguments[:tag] = :"tool-tip" @system_arguments[:for] = for_id @system_arguments[:popover] = "manual" @system_arguments[:classes] = class_names( @system_arguments[:classes], "sr-only" ) @system_arguments[:position] = :absolute @system_arguments[:"data-direction"] = fetch_or_fallback(DIRECTION_OPTIONS, direction, DIRECTION_DEFAULT).to_s @system_arguments[:"data-type"] = fetch_or_fallback(TYPE_OPTIONS, type, TYPE_FALLBACK).to_s end
@param for_id [String] The ID of the element that the tooltip should be attached to. @param type [Symbol] <%= one_of(Primer::Alpha::Tooltip::TYPE_OPTIONS) %> @param direction [Symbol] <%= one_of(Primer::Alpha::Tooltip::DIRECTION_OPTIONS) %> @param text [String] The text content of the tooltip. This should be brief and no longer than a sentence. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/tooltip.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/tooltip.rb
MIT
def initialize(label:, tag: TAG_DEFAULT, align: ALIGN_DEFAULT, body_arguments: {}, **system_arguments) @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT) @system_arguments = system_arguments @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT) @system_arguments[:classes] = underline_nav_classes(@system_arguments[:classes], @align) @body_arguments = body_arguments @body_arguments[:tag] = :ul @body_arguments[:classes] = underline_nav_body_classes(@body_arguments[:classes]) aria_label_for_page_nav(label) end
@param tag [Symbol] <%= one_of(Primer::Alpha::UnderlineNav::TAG_OPTIONS) %> @param label [String] Sets an `aria-label` that helps assistive technology users understand the purpose of the links, and distinguish it from similar elements. @param align [Symbol] <%= one_of(Primer::UnderlineNavHelper::ALIGN_OPTIONS) %> - Defaults to <%= Primer::UnderlineNavHelper::ALIGN_DEFAULT %> @param body_arguments [Hash] <%= link_to_system_arguments_docs %> for the body wrapper. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/underline_nav.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/underline_nav.rb
MIT
def initialize(label:, align: ALIGN_DEFAULT, body_arguments: {}, wrapper_arguments: {}, **system_arguments) @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT) @wrapper_arguments = wrapper_arguments @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :div @system_arguments[:classes] = underline_nav_classes(@system_arguments[:classes], @align) @body_arguments = deny_tag_argument(**body_arguments) @body_arguments[:tag] = :ul @body_arguments[:classes] = underline_nav_body_classes(@body_arguments[:classes]) @body_arguments[:role] = :tablist @body_arguments[:"aria-label"] = label end
@param label [String] Sets an `aria-label` that helps assistive technology users understand the purpose of the tabs. @param align [Symbol] <%= one_of(Primer::UnderlineNavHelper::ALIGN_OPTIONS) %> - Defaults to <%= Primer::UnderlineNavHelper::ALIGN_DEFAULT %> @param body_arguments [Hash] <%= link_to_system_arguments_docs %> for the body wrapper. @param wrapper_arguments [Hash] <%= link_to_system_arguments_docs %> for the `TabContainer` wrapper. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/underline_panels.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/underline_panels.rb
MIT
def initialize(item_content, **item_arguments) @system_arguments = { tag: item_arguments[:tag] || :div, data: { targets: "action-bar.items" }.merge(item_arguments[:data] || {}), classes: class_names("ActionBar-item", item_arguments[:classes]) } @item_content = item_content end
@param item_content [String] The content to render inside the item. @param item_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/action_bar/item.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_bar/item.rb
MIT
def initialize(scheme: DEFAULT_SCHEME, **system_arguments) @system_arguments = system_arguments @system_arguments[:tag] = :li @system_arguments[:role] = :presentation @system_arguments[:'aria-hidden'] = true @scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME) @system_arguments[:classes] = class_names( "ActionList-sectionDivider", SCHEME_MAPPINGS[@scheme] ) end
@param scheme [Symbol] Display a background color if scheme is `filled`. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/action_list/divider.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_list/divider.rb
MIT
def initialize(title:, heading_level: 3, scheme: DEFAULT_SCHEME, subtitle: nil, **system_arguments) raise "Heading level must be between #{HEADING_MIN} and #{HEADING_MAX}" unless HEADING_LEVELS.include?(heading_level) @heading_level = heading_level @tag = :"h#{heading_level}" @system_arguments = deny_tag_argument(**system_arguments) @title = title @subtitle = subtitle @scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME) @system_arguments[:classes] = class_names( "ActionList-sectionDivider", SCHEME_MAPPINGS[@scheme], @system_arguments[:classes] ) @title_id = self.class.generate_id(base_name: "heading-title") @subtitle_id = self.class.generate_id(base_name: "heading-subtitle") end
@param title [String] Sub list title. @param heading_level [Integer] Heading level. Level 2 results in an `<h2>` tag, level 3 an `<h3>` tag, etc. @param subtitle [String] Optional sub list description. @param scheme [Symbol] Display a background color if scheme is `filled`. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/action_list/heading.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_list/heading.rb
MIT
def with_heading(**system_arguments, &block) super(component_klass: Primer::Alpha::ActionMenu::Heading, **system_arguments, &block) end
Heading text rendered above the list of items. @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionMenu::Heading) %>.
with_heading
ruby
primer/view_components
app/components/primer/alpha/action_menu/group.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_menu/group.rb
MIT
def initialize(**system_arguments) @items = [] @has_group = false @list = Primer::Alpha::ActionMenu::ListWrapper.new(**system_arguments) end
@param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %>
initialize
ruby
primer/view_components
app/components/primer/alpha/action_menu/list.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_menu/list.rb
MIT
def initialize(menu_id:, **system_arguments) @menu_id = menu_id system_arguments[:aria] = merge_aria( system_arguments, { aria: { labelledby: "#{@menu_id}-button" } } ) system_arguments[:role] = :menu system_arguments[:scheme] = :inset system_arguments[:id] = "#{@menu_id}-list" super(**system_arguments) end
@param menu_id [String] ID of the parent menu. @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %>
initialize
ruby
primer/view_components
app/components/primer/alpha/action_menu/list_wrapper.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/action_menu/list_wrapper.rb
MIT
def initialize(value:, selected: false, disabled: false, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :li @system_arguments[:role] = :option @system_arguments[:"data-autocomplete-value"] = value @system_arguments[:"aria-selected"] = true if selected @system_arguments[:"aria-disabled"] = true if disabled @system_arguments[:classes] = class_names( "autocomplete-item", system_arguments[:classes], "disabled" => disabled ) end
@param value [String] Value of the item. @param selected [Boolean] Whether the item is selected. @param disabled [Boolean] Whether the item is disabled. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/auto_complete/item.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/auto_complete/item.rb
MIT
def initialize( show_divider: false, **system_arguments ) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :div @system_arguments[:classes] = class_names( "Overlay-footer", "Overlay-footer--alignEnd", { "Overlay-footer--divided": show_divider }, system_arguments[:classes] ) end
@param show_divider [Boolean] Show a divider between the footer and body. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/dialog/footer.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/dialog/footer.rb
MIT
def initialize( id:, title:, subtitle: nil, show_divider: false, visually_hide_title: false, variant: DEFAULT_VARIANT, close_label: DEFAULT_CLOSE_LABEL, **system_arguments ) @id = id @title = title @subtitle = subtitle @visually_hide_title = visually_hide_title @close_label = close_label @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :div @system_arguments[:classes] = class_names( "Overlay-header", VARIANT_MAPPINGS[fetch_or_fallback(VARIANT_OPTIONS, variant, DEFAULT_VARIANT)], { "Overlay-header--divided": show_divider }, system_arguments[:classes] ) end
@param id [String] The HTML element's ID value. @param title [String] Describes the content of the dialog. @param subtitle [String] Provides additional context for the dialog, also setting the `aria-describedby` attribute. @param show_divider [Boolean] Show a divider between the header and body. @param visually_hide_title [Boolean] Visually hide the `title` while maintaining a label for assistive technologies. @param variant [Symbol] <%= one_of(Primer::Alpha::Dialog::Header::VARIANT_OPTIONS) %> @param close_label [String] The aria-label text of the close "x" button. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/dialog/header.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/dialog/header.rb
MIT
def initialize(as: AS_DEFAULT, direction: DIRECTION_DEFAULT, scheme: SCHEME_DEFAULT, header: nil, **system_arguments) @header = header @direction = direction @as = fetch_or_fallback(AS_OPTIONS, as, AS_DEFAULT) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = "details-menu" @system_arguments[:role] = "menu" @system_arguments[:classes] = class_names( @system_arguments[:classes], "dropdown-menu", "dropdown-menu-#{fetch_or_fallback(DIRECTION_OPTIONS, direction, DIRECTION_DEFAULT)}", SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, SCHEME_DEFAULT)] ) end
@param as [Symbol] When `as` is `:list`, wraps the menu in a `<ul>` with a `<li>` for each item. @param direction [Symbol] <%= one_of(Primer::Alpha::Dropdown::Menu::DIRECTION_OPTIONS) %>. @param header [String] Header to be displayed above the menu. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/dropdown/menu.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/dropdown/menu.rb
MIT
def initialize(list: false, selected: false, with_panel: false, panel_id: "", icon_classes: "", wrapper_arguments: {}, **system_arguments) @selected = selected @icon_classes = icon_classes @list = list @with_panel = with_panel @system_arguments = system_arguments @id = @system_arguments[:id] @wrapper_arguments = wrapper_arguments if with_panel || @system_arguments[:tag] == :button @system_arguments[:tag] = :button @system_arguments[:type] = :button @system_arguments[:role] = :tab panel_id(panel_id) # https://www.w3.org/TR/wai-aria-practices/#presentation_role @wrapper_arguments[:role] = :presentation else @system_arguments[:tag] = :a end @wrapper_arguments[:tag] = :li @wrapper_arguments[:display] ||= :inline_flex return unless @selected if @system_arguments[:tag] == :a aria_current = aria("current", system_arguments) || DEFAULT_ARIA_CURRENT_FOR_ANCHOR @system_arguments[:"aria-current"] = fetch_or_fallback(ARIA_CURRENT_OPTIONS_FOR_ANCHOR, aria_current, DEFAULT_ARIA_CURRENT_FOR_ANCHOR) else @system_arguments[:"aria-selected"] = true end end
@param list [Boolean] Whether the Tab is an item in a `<ul>` list. @param selected [Boolean] Whether the Tab is selected or not. @param with_panel [Boolean] Whether the Tab has an associated panel. @param panel_id [String] Only applies if `with_panel` is `true`. Unique id of panel. @param icon_classes [Boolean] Classes that must always be applied to icons. @param wrapper_arguments [Hash] <%= link_to_system_arguments_docs %> to be used in the `<li>` wrapper when the tab is an item in a list. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/navigation/tab.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/navigation/tab.rb
MIT
def initialize( show_divider: false, align_content: DEFAULT_ALIGN_CONTENT, **system_arguments ) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :div @system_arguments[:classes] = class_names( "Overlay-footer", ALIGN_CONTENT_MAPPINGS[fetch_or_fallback(ALIGN_CONTENT_OPTIONS, align_content, DEFAULT_ALIGN_CONTENT)], { "Overlay-footer--divided": show_divider }, system_arguments[:classes] ) end
@param show_divider [Boolean] Show a divider between the footer and body. @param align_content [Symbol] The alginment of contents. <%= one_of(Primer::Alpha::Overlay::ALIGN_CONTENT_OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/overlay/footer.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/overlay/footer.rb
MIT
def initialize( id:, title:, overlay_id: nil, subtitle: nil, size: DEFAULT_SIZE, divider: false, visually_hide_title: false, **system_arguments ) @overlay_id = overlay_id @id = id @title = title @subtitle = subtitle @visually_hide_title = visually_hide_title @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :header @system_arguments[:classes] = class_names( "Overlay-header", { "Overlay-header--divided": divider }, SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)], system_arguments[:classes] ) end
@param title [String] Describes the content of the Overlay. @param subtitle [String] Provides additional context for the Overlay, also setting the `aria-describedby` attribute. @param overlay_id [String] Provides the id of the overlay element so the close button can close it @param size [Symbol] The size of the Header. <%= one_of(Primer::Alpha::Overlay::Header::SIZE_OPTIONS) %> @param divider [Boolean] Show a divider between the header and body. @param visually_hide_title [Boolean] Visually hide the `title` while maintaining a label for assistive technologies. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/alpha/overlay/header.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/overlay/header.rb
MIT
def initialize( label:, selected: false, icon: nil, hide_labels: false, **system_arguments ) @selected = selected @system_arguments = system_arguments @system_arguments[:"data-action"] = "click:segmented-control#select" if system_arguments[:href].nil? @system_arguments[:"aria-current"] = selected @system_arguments[:scheme] = :invisible if hide_labels @button = Primer::Beta::IconButton.new( icon: icon, "aria-label": label, **@system_arguments ) else @button = Primer::Beta::Button.new(**@system_arguments) @button.with_leading_visual_icon(icon: icon) if icon @button.with_content(label) end end
@param label [String] The label to use @param selected [Boolean] Whether the item is selected @param icon [Symbol] The icon to use @param hide_labels [Symbol] Whether to only show the icon
initialize
ruby
primer/view_components
app/components/primer/alpha/segmented_control/item.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/segmented_control/item.rb
MIT
def with_trailing_visual_label(**system_arguments, &block) @button.with_trailing_visual_label(**system_arguments, &block) end
@!parse # Optional trailing Label # # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Beta::Button) %>'s `with_trailing_visual_label` slot. renders_one(:trailing_visual_label) Optional trailing label. @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Beta::Button) %>'s `with_trailing_visual_label` slot.
with_trailing_visual_label
ruby
primer/view_components
app/components/primer/alpha/segmented_control/item.rb
https://github.com/primer/view_components/blob/master/app/components/primer/alpha/segmented_control/item.rb
MIT
def initialize(label_text:, src:, list_id:, input_id:, input_name: nil, placeholder: nil, show_clear_button: false, visually_hide_label: false, size: DEFAULT_SIZE, full_width: false, width: DEFAULT_WIDTH, disabled: false, invalid: false, inset: false, monospace: false, **system_arguments) @label_text = label_text @list_id = list_id @input_id = input_id @input_name = input_name || input_id @placeholder = placeholder @visually_hide_label = visually_hide_label @show_clear_button = show_clear_button @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = "auto-complete" @system_arguments[:src] = src @system_arguments[:for] = list_id @disabled = disabled @invalid = invalid @size = size @inset = inset @monospace = monospace @full_width = full_width @width = width @field_wrap_classes = class_names( "FormControl-input-wrap", SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, @size, DEFAULT_SIZE)], "FormControl-input-wrap--trailingAction": show_clear_button ) @form_group_classes = class_names( "FormControl", "FormControl--fullWidth": full_width ) @overlay_classes = class_names( "Overlay", "Overlay--height-auto", WIDTH_MAPPINGS[fetch_or_fallback(WIDTH_OPTIONS, @width, DEFAULT_WIDTH)] ) end
@param label_text [String] The label of the input. @param src [String] The route to query. @param input_id [String] Id of the input element. @param input_name [String] Optional name of the input element, defaults to `input_id` when not set. @param list_id [String] Id of the list element. @param visually_hide_label [Boolean] Controls if the label is visible. If `true`, screen reader only text will be added. @param show_clear_button [Boolean] Adds optional clear button. @param system_arguments [Hash] <%= link_to_system_arguments_docs %> @param size [Hash] Input size can be small, medium (default), or large @param full_width [Boolean] Input can be full-width or fit to content @param width [String] Optional parameter to set max width of results list. <%= one_of(Primer::Beta::AutoComplete::WIDTH_OPTIONS) %> @param disabled [Boolean] Disabled input @param invalid [Boolean] Invalid input @param placeholder [String] The placeholder text displayed within the input @param inset [Boolean] subtle input background color @param monospace [Boolean] monospace input font family
initialize
ruby
primer/view_components
app/components/primer/beta/auto_complete.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/auto_complete.rb
MIT
def before_render with_results(classes: "") unless results? with_input(classes: "") unless input? end
add `input` and `results` without needing to explicitly call them in the view
before_render
ruby
primer/view_components
app/components/primer/beta/auto_complete.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/auto_complete.rb
MIT
def initialize(src:, alt: nil, size: DEFAULT_SIZE, shape: DEFAULT_SHAPE, href: nil, **system_arguments) @href = href @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :img @system_arguments[:src] = src @system_arguments[:alt] = alt @system_arguments[:size] = fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE) @system_arguments[:height] = @system_arguments[:size] @system_arguments[:width] = @system_arguments[:size] @system_arguments[:classes] = class_names( system_arguments[:classes], "avatar", "avatar-small" => size < SMALL_THRESHOLD, "circle" => shape == DEFAULT_SHAPE, "lh-0" => href # Addresses an overflow issue with linked avatars ) end
@param src [String] The source url of the avatar image. @param alt [String] Passed through to alt on img tag. @param size [Integer] <%= one_of(Primer::Beta::Avatar::SIZE_OPTIONS) %> @param shape [Symbol] Shape of the avatar. <%= one_of(Primer::Beta::Avatar::SHAPE_OPTIONS) %> @param href [String] The URL to link to. If used, component will be wrapped by an `<a>` tag. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/avatar.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/avatar.rb
MIT
def initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, tooltipped: false, body_arguments: {}, **system_arguments) @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT) @system_arguments = system_arguments @tooltipped = tooltipped @body_arguments = body_arguments body_tag = @body_arguments[:tag] || DEFAULT_BODY_TAG @body_arguments[:tag] = fetch_or_fallback(BODY_TAG_OPTIONS, body_tag, DEFAULT_BODY_TAG) @body_arguments[:classes] = class_names( "AvatarStack-body", @body_arguments[:classes] ) @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) @system_arguments[:classes] = class_names( "AvatarStack", system_arguments[:classes], "AvatarStack--right" => @align == :right ) end
@param tag [Symbol] <%= one_of(Primer::Beta::AvatarStack::TAG_OPTIONS) %> @param align [Symbol] <%= one_of(Primer::Beta::AvatarStack::ALIGN_OPTIONS) %> @param tooltipped [Boolean] Whether to add a tooltip to the stack or not. @param body_arguments [Hash] Parameters to add to the Body. If `tooltipped` is set, has the same arguments as <%= link_to_component(Primer::Tooltip) %>. The default tag is <%= pretty_value(Primer::Beta::AvatarStack::DEFAULT_BODY_TAG) %> but can be changed using `tag:` to <%= one_of(Primer::Beta::AvatarStack::BODY_TAG_OPTIONS, lower: true) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/avatar_stack.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/avatar_stack.rb
MIT
def initialize( tag: DEFAULT_TAG, type: DEFAULT_TYPE, block: false, disabled: false, inactive: false, **system_arguments ) @system_arguments = system_arguments @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) @system_arguments[:type] = fetch_or_fallback(TYPE_OPTIONS, type, DEFAULT_TYPE) if @system_arguments[:tag] == :button @system_arguments[:classes] = class_names( system_arguments[:classes], "btn-block" => block, "Button--inactive" => inactive ) @disabled = disabled return unless @disabled @system_arguments[:tag] = :button @system_arguments[:disabled] = "" end
@param tag [Symbol] <%= one_of(Primer::Beta::BaseButton::TAG_OPTIONS) %> @param type [Symbol] <%= one_of(Primer::Beta::BaseButton::TYPE_OPTIONS) %> @param block [Boolean] Whether button is full-width with `display: block`. @param disabled [Boolean] Whether or not the button is disabled. If true, this option forces `tag:` to `:button`. @param inactive [Boolean] Whether the button looks visually disabled, but can still accept all the same interactions as an enabled button. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/base_button.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/base_button.rb
MIT
def initialize(padding: DEFAULT_PADDING, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :div @system_arguments[:classes] = class_names( "Box", PADDING_MAPPINGS[fetch_or_fallback(PADDING_MAPPINGS.keys, padding, DEFAULT_PADDING)], system_arguments[:classes] ) @system_arguments[:system_arguments_denylist] = { [:p, :pt, :pb, :pr, :pl] => PADDING_SUGGESTION } @list_arguments = { tag: :ul } end
@param padding [Symbol] <%= one_of(Primer::Beta::BorderBox::PADDING_MAPPINGS.keys) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/border_box.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/border_box.rb
MIT
def initialize( base_button_class: Primer::Beta::BaseButton, scheme: DEFAULT_SCHEME, size: DEFAULT_SIZE, block: false, align_content: DEFAULT_ALIGN_CONTENT, disabled: false, label_wrap: false, **system_arguments ) @base_button_class = base_button_class @scheme = scheme @block = block @label_wrap = label_wrap @system_arguments = system_arguments @system_arguments[:disabled] = disabled @id = @system_arguments[:id] raise ArgumentError, "The `variant:` argument is no longer supported on Primer::Beta::Button. Consider `scheme:` or `size:`." if !Rails.env.production? && @system_arguments[:variant].present? raise ArgumentError, "The `dropdown:` argument is no longer supported on Primer::Beta::Button. Use the `trailing_action` slot instead." if !Rails.env.production? && @system_arguments[:dropdown].present? @align_content_classes = class_names( "Button-content", ALIGN_CONTENT_MAPPINGS[fetch_or_fallback(ALIGN_CONTENT_OPTIONS, align_content, DEFAULT_ALIGN_CONTENT)] ) @system_arguments[:classes] = class_names( system_arguments[:classes], SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)], SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)], "Button", "Button--fullWidth" => @block, "Button--labelWrap" => @label_wrap ) end
@param base_button_class [Class] The button class to render. @param scheme [Symbol] <%= one_of(Primer::Beta::Button::SCHEME_OPTIONS) %> @param size [Symbol] <%= one_of(Primer::Beta::Button::SIZE_OPTIONS) %> @param block [Boolean] Whether button is full-width with `display: block`. @param align_content [Symbol] <%= one_of(Primer::Beta::Button::ALIGN_CONTENT_OPTIONS) %> @param tag [Symbol] (Primer::Beta::BaseButton::DEFAULT_TAG) <%= one_of(Primer::Beta::BaseButton::TAG_OPTIONS) %> @param type [Symbol] (Primer::Beta::BaseButton::DEFAULT_TYPE) <%= one_of(Primer::Beta::BaseButton::TYPE_OPTIONS) %> @param inactive [Boolean] Whether the button looks visually disabled, but can still accept all the same interactions as an enabled button. @param disabled [Boolean] Whether or not the button is disabled. If true, this option forces `tag:` to `:button`. @param label_wrap [Boolean] Whether or not the button label text wraps and the button height expands. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/button.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/button.rb
MIT
def initialize(scheme: Primer::Beta::Button::DEFAULT_SCHEME, size: Primer::Beta::Button::DEFAULT_SIZE, **system_arguments) @size = size @scheme = scheme @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :div @system_arguments[:classes] = class_names( "ButtonGroup", system_arguments[:classes] ) end
@param scheme [Symbol] DEPRECATED. <%= one_of(Primer::Beta::Button::SCHEME_OPTIONS) %> @param size [Symbol] <%= one_of(Primer::Beta::Button::SIZE_OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/button_group.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/button_group.rb
MIT
def initialize(menu_arguments: {}, button_arguments: {}) @menu = Primer::Alpha::ActionMenu.new(**menu_arguments) @button = @menu.with_show_button(icon: "triangle-down", **button_arguments) end
@param menu_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionMenu) %>. @param button_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Beta::Button) %> or <%= link_to_component(Primer::Beta::IconButton) %>, depending on the value of the `icon:` argument.
initialize
ruby
primer/view_components
app/components/primer/beta/button_group.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/button_group.rb
MIT
def initialize(value: nil, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @value = value validate! @system_arguments[:tag] = "clipboard-copy" @system_arguments[:value] = value if value.present? end
@param aria-label [String] String that will be read to screenreaders when the component is focused @param value [String] Text to copy into the users clipboard when they click the component. @param for [String] Element id from where to get the copied value. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/clipboard_copy.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/clipboard_copy.rb
MIT
def initialize(**system_arguments) super(**system_arguments, base_button_class: ClipboardCopyBaseButton) end
@param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Beta::Button) %> and <%= link_to_component(Primer::Beta::ClipboardCopy) %>.
initialize
ruby
primer/view_components
app/components/primer/beta/clipboard_copy_button.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/clipboard_copy_button.rb
MIT
def initialize(overlay: NO_OVERLAY, reset: false, disabled: false, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :details @system_arguments[:classes] = class_names( system_arguments[:classes], OVERLAY_MAPPINGS[fetch_or_fallback(OVERLAY_MAPPINGS.keys, overlay, NO_OVERLAY)], "details-reset" => reset ) @system_arguments[:data] = merge_data( @system_arguments, { data: { target: "details-toggle.detailsTarget", } } ) # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details#open @open = !!@system_arguments[:open] @disabled = disabled @summary_info = nil end
@param overlay [Symbol] Dictates the type of overlay to render with. <%= one_of(Primer::Beta::Details::OVERLAY_MAPPINGS.keys) %> @param reset [Boolean] Defaults to false. If set to true, it will remove the default caret and remove style from the summary element @param disabled [Boolean] Whether or not to disable the summary button. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/details.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/details.rb
MIT
def initialize(full: false, spacious: false, dismissible: false, icon: nil, scheme: DEFAULT_SCHEME, **system_arguments) @icon = icon @dismissible = dismissible @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :div @system_arguments[:classes] = class_names( @system_arguments[:classes], "flash", SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, DEFAULT_SCHEME)], "flash-full": full ) @system_arguments[:mb] ||= spacious ? 4 : nil end
@param full [Boolean] Whether the component should take up the full width of the screen. @param spacious [Boolean] Whether to add margin to the bottom of the component. @param dismissible [Boolean] Whether the component can be dismissed with an X button. @param icon [Symbol] Name of Octicon icon to use. @param scheme [Symbol] <%= one_of(Primer::Beta::Flash::SCHEME_MAPPINGS.keys) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/flash.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/flash.rb
MIT
def initialize(tag:, **system_arguments) @system_arguments = system_arguments @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_FALLBACK) end
@param tag [String] <%= one_of(Primer::Beta::Heading::TAG_OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/heading.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/heading.rb
MIT
def initialize(icon:, scheme: DEFAULT_SCHEME, show_tooltip: true, tooltip_direction: Primer::Alpha::Tooltip::DIRECTION_DEFAULT, size: Primer::Beta::Button::DEFAULT_SIZE, disabled: false, **system_arguments) @icon = icon @show_tooltip = show_tooltip @system_arguments = system_arguments @system_arguments[:id] ||= self.class.generate_id @system_arguments[:disabled] = disabled @system_arguments[:classes] = class_names( "Button", "Button--iconOnly", SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)], Primer::Beta::Button::SIZE_MAPPINGS[fetch_or_fallback(Primer::Beta::Button::SIZE_OPTIONS, size, Primer::Beta::Button::DEFAULT_SIZE)], system_arguments[:classes] ) validate_aria_label @aria_label = aria("label", @system_arguments) @aria_description = aria("description", @system_arguments) return unless render_tooltip? @tooltip_arguments = { for_id: @system_arguments[:id], direction: tooltip_direction } # If we have both an `aria-label` and a `aria-description`, we create a `Tooltip` with the description type and keep the `aria-label` in the button. # Otherwise, the `aria-label` is used as the tooltip text, which is the `aria-labelled-by` of the button, so we don't set it in the button. if @aria_label.present? && @aria_description.present? @system_arguments.delete(:"aria-description") @system_arguments[:aria].delete(:description) if @system_arguments.include?(:aria) @tooltip_arguments[:text] = @aria_description @tooltip_arguments[:type] = :description else @system_arguments.delete(:"aria-label") @system_arguments[:aria].delete(:label) if @system_arguments.include?(:aria) @tooltip_arguments[:text] = @aria_label @tooltip_arguments[:type] = :label end @tooltip = Primer::Alpha::Tooltip.new(**@tooltip_arguments) aria_key = @tooltip_arguments[:type] == :label ? :labelledby : :describedby @system_arguments[:aria] = merge_aria( @system_arguments, { aria: { aria_key => @tooltip.id } } ) end
@param icon [String] Name of <%= link_to_octicons %> to use. @param tag [Symbol] <%= one_of(Primer::Beta::BaseButton::TAG_OPTIONS) %> @param scheme [Symbol] <%= one_of(Primer::Beta::IconButton::SCHEME_OPTIONS) %> @param size [Symbol] <%= one_of(Primer::Beta::Button::SIZE_OPTIONS) %> @param disabled [Boolean] Whether or not the button is disabled. If true, this option forces `tag:` to `:button`. @param type [Symbol] <%= one_of(Primer::Beta::BaseButton::TYPE_OPTIONS) %> @param aria-label [String] String that can be read by assistive technology. A label should be short and concise. See the accessibility section for more information. @param aria-description [String] String that can be read by assistive technology. A description can be longer as it is intended to provide more context and information. See the accessibility section for more information. @param show_tooltip [Boolean] Whether or not to show a tooltip when this button is hovered. Tooltips should only be hidden if the aria label is redundant, i.e. if the icon has a widely understood definition. @param tooltip_direction [Symbol] (Primer::Alpha::Tooltip::DIRECTION_DEFAULT) <%= one_of(Primer::Alpha::Tooltip::DIRECTION_OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/icon_button.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/icon_button.rb
MIT
def initialize(tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, size: DEFAULT_SIZE, inline: false, variant: DEFAULT_VARIANT, **system_arguments) @system_arguments = system_arguments @variant = fetch_or_fallback(VARIANT_OPTIONS, variant, nil, deprecated_values: DEPRECATED_VARIANT_OPTIONS) @scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME, deprecated_values: DEPRECATED_SCHEME_OPTIONS) @size = fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE) @size = :large if @variant == :large @inline = inline || @variant == :inline @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) @system_arguments[:classes] = class_names( "Label", system_arguments[:classes], SCHEME_MAPPINGS[@scheme], SIZE_MAPPINGS[@size], @inline ? INLINE_CLASS : nil ) end
@param tag [Symbol] <%= one_of(Primer::Beta::Label::TAG_OPTIONS) %> @param scheme [Symbol] <%= one_of(Primer::Beta::Label::SCHEME_MAPPINGS.keys) %> @param size [Symbol] <%= one_of(Primer::Beta::Label::SIZE_OPTIONS) %> @param inline [Boolean] Whether or not to render this label inline. @param variant [Symbol] <%= one_of(Primer::Beta::Label::VARIANT_OPTIONS + Primer::Beta::Label::DEPRECATED_VARIANT_OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/label.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/label.rb
MIT
def initialize(href: nil, scheme: DEFAULT_SCHEME, muted: false, underline: false, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @id = @system_arguments[:id] @system_arguments[:tag] = :a @system_arguments[:href] = href @system_arguments[:classes] = class_names( @system_arguments[:classes], SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, DEFAULT_SCHEME)], "Link", "Link--muted" => muted, "Link--underline" => underline ) end
@param href [String] URL to be used for the Link. Required. If the requirements are not met an error will be raised in non production environments. In production, an empty link element will be rendered. @param scheme [Symbol] <%= one_of(Primer::Beta::Link::SCHEME_MAPPINGS.keys) %> @param muted [Boolean] Uses light gray for Link color, and blue on hover. @param underline [Boolean] Whether or not to underline the link. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/link.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/link.rb
MIT
def initialize(tag: DEFAULT_TAG, **system_arguments) @system_arguments = system_arguments @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) @system_arguments[:classes] = class_names( "markdown-body", system_arguments[:classes] ) end
@param tag [Symbol] <%= one_of(Primer::Beta::Markdown::TAG_OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/markdown.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/markdown.rb
MIT
def initialize(selected_item_id: nil, **system_arguments) @system_arguments = system_arguments @selected_item_id = selected_item_id end
@param selected_item_id [Symbol] The ID of the currently selected item. The default is `nil`, meaning no item is selected. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/nav_list.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list.rb
MIT
def build_item(component_klass: Primer::Beta::NavList::Item, **system_arguments, &block) component_klass.new( list: top_level_group, selected_item_id: @selected_item_id, **system_arguments, &block ) end
Builds a new item but does not add it to the list. Use this method instead of the `#with_item` slot if you need to render an item outside the context of a list, eg. if rendering additional items to append to an existing list, perhaps via a separate HTTP request. @param component_klass [Class] The class to use instead of the default <%= link_to_component(Primer::Beta::NavList::Item) %> @param system_arguments [Hash] These arguments are forwarded to <%= link_to_component(Primer::Beta::NavList::Item) %>, or whatever class is passed as the `component_klass` argument.
build_item
ruby
primer/view_components
app/components/primer/beta/nav_list.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list.rb
MIT
def build_avatar_item(src:, username:, full_name: nil, full_name_scheme: Primer::Alpha::ActionList::Item::DEFAULT_DESCRIPTION_SCHEME, component_klass: Primer::Beta::NavList::Item, avatar_arguments: {}, **system_arguments) component_klass.new( list: top_level_group, selected_item_id: @selected_item_id, label: username, description_scheme: full_name_scheme, **system_arguments ).tap do |item| item.with_leading_visual_raw_content do # no alt text necessary item.render(Primer::Beta::Avatar.new(src: src, **avatar_arguments, role: :presentation, size: 16)) end item.with_description_content(full_name) if full_name end end
Builds a new avatar item but does not add it to the list. Avatar items are a convenient way to accessibly add an item with a leading avatar image. Use this method instead of the `#with_avatar_item` slot if you need to render an avatar item outside the context of a list, eg. if rendering additional items to append to an existing list, perhaps via a separate HTTP request. @param src [String] The source url of the avatar image. @param username [String] The username associated with the avatar. @param full_name [String] Optional. The user's full name. @param full_name_scheme [Symbol] Optional. How to display the user's full name. <%= one_of(Primer::Alpha::ActionList::Item::DESCRIPTION_SCHEME_OPTIONS) %> @param component_klass [Class] The class to use instead of the default <%= link_to_component(Primer::Beta::NavList::Item) %> @param avatar_arguments [Hash] Optional. The arguments accepted by <%= link_to_component(Primer::Beta::Avatar) %> @param system_arguments [Hash] These arguments are forwarded to <%= link_to_component(Primer::Beta::NavList::Item) %>, or whatever class is passed as the `component_klass` argument.
build_avatar_item
ruby
primer/view_components
app/components/primer/beta/nav_list.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list.rb
MIT
def render_outer_list? items.any? { |item| !group?(item) } end
Lists that contain top-level items (i.e. items outside of a group) should be wrapped in a `<ul>`
render_outer_list?
ruby
primer/view_components
app/components/primer/beta/nav_list.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list.rb
MIT
def initialize(icon_name = nil, icon: nil, size: SIZE_DEFAULT, use_symbol: false, **system_arguments) icon_key = icon_name || icon # Don't allow sizes under 16px if system_arguments[:height].present? && system_arguments[:height].to_i < 16 || system_arguments[:width].present? && system_arguments[:width].to_i < 16 system_arguments.delete(:height) system_arguments.delete(:width) end cache_key = Primer::Octicon::Cache.get_key( symbol: icon_key, size: size, height: system_arguments[:height], width: system_arguments[:width] ) @system_arguments = system_arguments @system_arguments[:tag] = :svg @system_arguments[:aria] ||= {} @use_symbol = use_symbol if @system_arguments[:aria][:label] || @system_arguments[:"aria-label"] @system_arguments[:role] = "img" else @system_arguments[:aria][:hidden] = true end if (cache_icon = Primer::Octicon::Cache.read(cache_key)) @icon = cache_icon else # Filter out classify options to prevent them from becoming invalid html attributes. # Note height and width are both classify options and valid html attributes. octicon_options = { height: @system_arguments[:height] || SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)], width: @system_arguments[:width] } octicon_options.compact! @icon = Octicons::Octicon.new(icon_key, octicon_options) Primer::Octicon::Cache.set(cache_key, @icon) end @system_arguments[:classes] = class_names( @icon.options[:class], @system_arguments[:classes] ) @system_arguments.merge!(@icon.options.except(:class, :'aria-hidden')) end
@param icon_name [Symbol, String] Name of <%= link_to_octicons %> to use. @param icon [Symbol, String] Name of <%= link_to_octicons %> to use. @param size [Symbol] <%= one_of(Primer::Beta::Octicon::SIZE_MAPPINGS, sort: false) %> @param use_symbol [Boolean] EXPERIMENTAL (May change or be removed) - Set to true when using with <%= link_to_component(Primer::Alpha::OcticonSymbols) %>. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/octicon.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/octicon.rb
MIT
def initialize(size: SIZE_DEFAULT, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:classes] = class_names( @system_arguments[:classes], "Progress", SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)] ) @system_arguments[:tag] = :span end
@param size [Symbol] <%= one_of(Primer::Beta::ProgressBar::SIZE_OPTIONS) %> Increases height. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/progress_bar.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/progress_bar.rb
MIT
def initialize( datetime:, tense: TENSE_DEFAULT, prefix: nil, second: SECOND_DEFAULT, minute: MINUTE_DEFAULT, hour: HOUR_DEFAULT, weekday: WEEKDAY_DEFAULT, day: DAY_DEFAULT, month: MONTH_DEFAULT, year: YEAR_DEFAULT, time_zone_name: TIMEZONENAME_DEFAULT, threshold: nil, precision: PRECISION_DEFAULT, format: nil, format_style: nil, lang: nil, title: nil, no_title: false, **system_arguments ) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = "relative-time" @system_arguments[:tense] = tense if tense.present? @system_arguments[:prefix] = prefix if prefix.present? @system_arguments[:second] = fetch_or_fallback(SECOND_OPTIONS, second, SECOND_DEFAULT) if second.present? @system_arguments[:minute] = fetch_or_fallback(MINUTE_OPTIONS, minute, MINUTE_DEFAULT) if minute.present? @system_arguments[:hour] = fetch_or_fallback(HOUR_OPTIONS, hour, HOUR_DEFAULT) if hour.present? @system_arguments[:weekday] = fetch_or_fallback(WEEKDAY_OPTIONS, weekday, WEEKDAY_DEFAULT) if weekday.present? @system_arguments[:day] = fetch_or_fallback(DAY_OPTIONS, day, DAY_DEFAULT) if day.present? @system_arguments[:month] = fetch_or_fallback(MONTH_OPTIONS, month, MONTH_DEFAULT) if month.present? @system_arguments[:year] = fetch_or_fallback(YEAR_OPTIONS, year, YEAR_DEFAULT) if year.present? @system_arguments[:"time-zone-name"] = fetch_or_fallback(TIMEZONENAME_OPTIONS, time_zone_name, TIMEZONENAME_DEFAULT) if time_zone_name.present? @system_arguments[:threshold] = threshold if threshold.present? @system_arguments[:precision] = precision if precision.present? @system_arguments[:title] = title if title.present? @system_arguments[:"no-title"] = no_title if no_title @system_arguments[:lang] = lang if lang.present? @system_arguments[:format] = fetch_or_fallback(FORMAT_OPTIONS, format, FORMAT_DEFAULT) if format.present? @system_arguments[:"format-style"] = format_style if format_style.present? if datetime.present? && datetime.respond_to?(:iso8601) @datetime = datetime @system_arguments[:datetime] = datetime.iso8601 elsif datetime.present? @datetime = Time.iso8601 datetime @system_arguments[:datetime] = @datetime end end
@param datetime [Time] The time to be formatted. @param tense [Symbol] Which tense to use. <%= one_of(Primer::Beta::RelativeTime::TENSE_OPTIONS) %> @param prefix [String] What to prefix the relative time display with. @param second [Symbol] What format seconds should take. <%= one_of(Primer::Beta::RelativeTime::SECOND_OPTIONS) %> @param minute [Symbol] What format minues should take. <%= one_of(Primer::Beta::RelativeTime::MINUTE_OPTIONS) %> @param hour [Symbol] What format hours should take. <%= one_of(Primer::Beta::RelativeTime::HOUR_OPTIONS) %> @param weekday [Symbol] What format weekdays should take. <%= one_of(Primer::Beta::RelativeTime::WEEKDAY_OPTIONS) %> @param day [Symbol] What format days should take. <%= one_of(Primer::Beta::RelativeTime::DAY_OPTIONS) %> @param month [Symbol] What format months should take. <%= one_of(Primer::Beta::RelativeTime::MONTH_OPTIONS) %> @param year [Symbol] What format years should take. <%= one_of(Primer::Beta::RelativeTime::YEAR_OPTIONS) %> @param time_zone_name [Symbol] What format the time zone should take. <%= one_of(Primer::Beta::RelativeTime::TIMEZONENAME_OPTIONS) %> @param threshold [String] The threshold, in ISO-8601 'durations' format, at which relative time displays become absolute. @param precision [Symbol] The precision elapsed time should display. <%= one_of(Primer::Beta::RelativeTime::PRECISION_OPTIONS) %> @param format [Symbol] The format the display should take. <%= one_of(Primer::Beta::RelativeTime::FORMAT_OPTIONS) %> @param format_style [Symbol] The format the display should take. <%= one_of(Primer::Beta::RelativeTime::FORMAT_STYLE_OPTIONS) %> @param lang [String] The language to use. @param title [String] Provide a custom title to the element. @param no_title [Boolean] Removes the `title` attribute provided on the element by default. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/relative_time.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/relative_time.rb
MIT
def initialize(size: DEFAULT_SIZE, style: DEFAULT_STYLE, sr_text: DEFAULT_SR_TEXT, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :svg @system_arguments[:style] ||= style @system_arguments[:animation] = :rotate @system_arguments[:width] = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)] @system_arguments[:height] = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)] @system_arguments[:viewBox] = "0 0 16 16" @system_arguments[:fill] = :none @system_arguments[:aria] ||= {} @sr_text = sr_text if no_aria_label? @system_arguments[:aria][:hidden] = true else @system_arguments[:role] = "img" end @target = extract_data(:target, @system_arguments) @hidden = @system_arguments.delete(:hidden) end
@param size [Symbol] <%= one_of(Primer::Beta::Spinner::SIZE_MAPPINGS) %> @param style [String] Custom element styles. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/spinner.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/spinner.rb
MIT
def initialize( title:, scheme: SCHEME_DEFAULT, tag: TAG_DEFAULT, size: SIZE_DEFAULT, **system_arguments ) @system_arguments = system_arguments @system_arguments[:title] = title @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT) @system_arguments[:classes] = class_names( @system_arguments[:classes], "State", SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, SCHEME_DEFAULT)], SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)] ) end
@param title [String] `title` HTML attribute. @param scheme [Symbol] Background color. <%= one_of(Primer::Beta::State::SCHEME_OPTIONS) %> @param tag [Symbol] HTML tag for element. <%= one_of(Primer::Beta::State::TAG_OPTIONS) %> @param size [Symbol] <%= one_of(Primer::Beta::State::SIZE_OPTIONS) %> @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/state.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/state.rb
MIT
def initialize(spacious: false, hide_border: false, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :div @system_arguments[:classes] = class_names( @system_arguments[:classes], "Subhead", "Subhead--spacious": spacious, "border-bottom-0": hide_border ) @system_arguments[:mb] ||= hide_border ? 0 : nil end
@param spacious [Boolean] Whether to add spacing to the Subhead. @param hide_border [Boolean] Whether to hide the border under the heading. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/subhead.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/subhead.rb
MIT
def initialize(value:, selected: false, disabled: false, description_variant: DEFAULT_DESCRIPTION_VARIANT, role: :option, **system_arguments) @description_variant = fetch_or_fallback( DESCRIPTION_VARIANT_OPTIONS, description_variant, DEFAULT_DESCRIPTION_VARIANT ) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :div @system_arguments[:role] = role @system_arguments[:"data-autocomplete-value"] = value @system_arguments[:"aria-selected"] = true if selected @system_arguments[:"aria-disabled"] = true if disabled @system_arguments[:classes] = class_names( "ActionListItem", system_arguments[:classes] ) @description_wrapper_arguments = { classes: class_names( "ActionListItem-descriptionWrap", DESCRIPTION_VARIANT_MAPPINGS[@description_variant] ) } end
@param value [String] Value of the item. @param selected [Boolean] Whether the item is selected. @param disabled [Boolean] Whether the item is disabled. @param description_variant [Hash] Changes the description style. Allowed values are :inline, :block @param description [String] Display description text below label @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/auto_complete/item.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/auto_complete/item.rb
MIT
def initialize(selected_item_id: nil, **system_arguments) @system_arguments = system_arguments @selected_item_id = selected_item_id super(**@system_arguments) end
@param selected_item_id [Symbol] The ID of the currently selected item. Used internally. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/nav_list/group.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list/group.rb
MIT
def expand! @expanded = true end
Cause this group to show its list of sub items when rendered. :nocov:
expand!
ruby
primer/view_components
app/components/primer/beta/nav_list/group.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list/group.rb
MIT
def build_item(component_klass: NavList::Item, **system_arguments) super( component_klass: component_klass, selected_item_id: @selected_item_id, **system_arguments ) end
:nocov: @!parse # Items. # # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Beta::NavList::Item) %>. renders_many :items @private
build_item
ruby
primer/view_components
app/components/primer/beta/nav_list/group.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list/group.rb
MIT
def initialize(title:, id: self.class.generate_id, heading_level: 2, **system_arguments) @title = title @id = id @heading_level = heading_level @system_arguments = system_arguments end
@param title [String] The text content of the heading. @param id [String] The value of the ID HTML attribute. Auto-generated by default. @param heading_level [Integer] The heading level, i.e. 2 for an `<h2>`, 3 for an `<h3>`, etc. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/nav_list/heading.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list/heading.rb
MIT
def initialize(selected_item_id: nil, selected_by_ids: [], sub_item: false, expanded: false, **system_arguments) @selected_item_id = selected_item_id @selected_by_ids = Array(selected_by_ids) @expanded = expanded @sub_item = sub_item system_arguments[:classes] = class_names( system_arguments[:classes], "ActionListItem--subItem" => @sub_item ) @sub_list_arguments = { classes: class_names( "ActionList", "ActionList--subGroup" ) } @list = system_arguments[:list] @sub_list_arguments["data-action"] = "keydown:#{@list.custom_element_name}#handleItemWithSubItemKeydown" if @list overrides = { "data-item-id": @selected_by_ids.join(" ") } super(**system_arguments, **overrides) end
@param selected_item_id [Symbol] The ID of the currently selected list item. Used internally. @param selected_by_ids [Array<Symbol>] The list of IDs that select this item. In other words, if the `selected_item_id` attribute on the parent `NavList` is set to one of these IDs, the item will appear selected. @param expanded [Boolean] Whether this item shows (expands) or hides (collapses) its list of sub items. @param sub_item [Boolean] Whether or not this item is nested under a parent item. Used internally. @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
initialize
ruby
primer/view_components
app/components/primer/beta/nav_list/item.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list/item.rb
MIT
def expand! @expanded = true end
Cause this item to show its list of sub items when rendered.
expand!
ruby
primer/view_components
app/components/primer/beta/nav_list/item.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list/item.rb
MIT
def item_active?(item) if item.selected_by_ids.present? item.selected_by_ids.include?(@selected_item_id) elsif item.href current_page?(item.href) else # :nocov: false # :nocov: end end
Normally it would be easier to simply ask each item for its active status, eg. items.any?(&:active?), but unfortunately the view context is not set on each item until _after_ the parent's before_render, etc methods have been called. This means helper methods like current_page? will blow up with an error, since `helpers` is simply an alias for the view context (i.e. an instance of ActionView::Base). Since we know the view context for the parent object must be set before `before_render` is invoked, we can call helper methods here in the parent and bypass the problem entirely. Maybe not the most OO approach, but it works.
item_active?
ruby
primer/view_components
app/components/primer/beta/nav_list/item.rb
https://github.com/primer/view_components/blob/master/app/components/primer/beta/nav_list/item.rb
MIT
def merge_aria(*hashes) merge_prefixed_attribute_hashes( *hashes, prefix: :aria, plural_keys: PLURAL_ARIA_ATTRIBUTES ) end
Merges hashes that contain "aria-*" keys and nested aria: hashes. Removes keys from each hash and returns them in the new hash. Eg. merge_aria({ "aria-disabled": "true" }, { aria: { invalid: "true" } }) => { disabled: "true", invalid: "true" } Certain aria attributes can contain multiple values separated by spaces. merge_aria will combine these plural attributes into a composite string. Eg. merge_aria({ "aria-labelledby": "foo" }, { aria: { labelledby: "bar" } }) => { labelledby: "foo bar" } It's designed to be used to normalize and merge aria information from system_arguments hashes. Consider using this pattern in component initializers: @system_arguments[:aria] = merge_aria( @system_arguments, { aria: { labelled_by: id } } )
merge_aria
ruby
primer/view_components
app/lib/primer/attributes_helper.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/attributes_helper.rb
MIT
def merge_data(*hashes) merge_prefixed_attribute_hashes( *hashes, prefix: :data, plural_keys: PLURAL_DATA_ATTRIBUTES ) end
Merges hashes that contain "data-*" keys and nested data: hashes. Removes keys from each hash and returns them in the new hash. Eg. merge_data({ "data-foo": "true" }, { data: { bar: "true" } }) => { foo: "true", bar: "true" } Certain data attributes can contain multiple values separated by spaces. merge_data will combine these plural attributes into a composite string. Eg. merge_data({ "data-target": "foo" }, { data: { target: "bar" } }) => { target: "foo bar" } It's designed to be used to normalize and merge data information from system_arguments hashes. Consider using this pattern in component initializers: @system_arguments[:data] = merge_data( @system_arguments, { data: { foo: "bar" } } )
merge_data
ruby
primer/view_components
app/lib/primer/attributes_helper.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/attributes_helper.rb
MIT
def render_in(view_context, &block) @builder = Primer::Forms::Builder.new( nil, nil, view_context, {} ) super end
Unlike other instances of Base, ToggleSwitchForm defines its own form and is not given a Rails form builder on instantiation. We do this mostly for ergonomic reasons; it's much less verbose than if you were required to call form_with/form_for, etc. That said, the rest of the forms framework assumes the presence of a builder so we create our own here. A builder cannot be constructed without a corresponding view context, which is why we have to override render_in and can't create it in the initializer.
render_in
ruby
primer/view_components
app/lib/primer/forms/toggle_switch_form.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/toggle_switch_form.rb
MIT
def const_source_location(class_name) return nil unless class_name if (location = Object.const_source_location(class_name)&.[](0)) return location end # NOTE: underscore respects namespacing, i.e. will convert Foo::Bar to foo/bar. class_path = "#{class_name.underscore}.rb" # Prefer Zeitwerk-managed paths, falling back to ActiveSupport::Dependencies if Zeitwerk # is disabled or not in use (i.e. the case for older Rails versions). autoload_paths = if Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled? Rails.autoloaders.main.dirs else ActiveSupport::Dependencies.autoload_paths end autoload_paths.each do |autoload_path| absolute_path = File.join(autoload_path, class_path) return absolute_path if File.exist?(absolute_path) end nil end
Unfortunately this bug (https://github.com/ruby/ruby/pull/5646) prevents us from using Ruby's native Module.const_source_location. Instead we have to fudge it by searching for the file in the configured autoload paths. Doing so relies on Rails' autoloading conventions, so it should work ok. Zeitwerk also has this information but lacks a public API to map constants to source files. Now that the Ruby bug above has been fixed and released, this method should be used only as a fallback for older Rubies.
const_source_location
ruby
primer/view_components
app/lib/primer/forms/utils.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/utils.rb
MIT
def classify(options) options[:classes] = class_names(options.delete(:class), options[:classes]) options.merge!(Primer::Classify.call(options)) options.except!(*PRIMER_UTILITY_KEYS) options[:class] = class_names(options[:class], options.delete(:classes)) options end
This method does the following: 1. Runs Primer's classify routine to convert entries like mb: 1 to mb-1. 2. Runs classify on both options[:class] and options[:classes]. The first is expected by Rails/HTML while the second is specific to Primer. 3. Combines options[:class] and options[:classes] into options[:class] so the options hash can be easily passed to Rails form builder methods.
classify
ruby
primer/view_components
app/lib/primer/forms/utils.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/utils.rb
MIT
def initialize(*fields_for_args, builder:, form:, nested: true, **fields_for_kwargs, &block) @fields_for_args = fields_for_args @fields_for_kwargs = fields_for_kwargs @nested = nested @ref_block = block super(builder: builder, form: form, **fields_for_kwargs) end
Pass `nested: false` to prevent the referenced form fields from being treated as nested under the parent form's model. For example, consider these models: class User < ActiveRecord::Base has_many :addresses end class Address < ActiveRecord::Base belongs_to :user end A sign-up form might include fields from `User` as well as `Address`. Since addresses are associated with users, it's perfectly natural to accept the address fields as nested attributes. Rails will name each field accordingly. For example, the `street` field on `Address` will be named `user[address][street]`. For situations like this where an association exists between two models, the nested attributes approach works great. However sometimes all you want is to compose two forms together that aren't connected by an association. In such cases the fields will still include the name of the parent model, eg. `user[address][street]` instead of what we want, `address[street]`. To render the form independent of the parent, pass `nested: false`.
initialize
ruby
primer/view_components
app/lib/primer/forms/dsl/form_reference_input.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/form_reference_input.rb
MIT
def fields_for(*args, **kwargs, &block) add_input FormReferenceInput.new(*args, builder: builder, form: form, **kwargs, &block) end
Used to render another form object. @param args [Array] Positional arguments passed to Rails' [`fields_for` helper](https://api.rubyonrails.org/v7.0.4/classes/ActionView/Helpers/FormHelper.html#method-i-fields_for). @param kwargs [Hash] The options accepted by the form reference input (see forms docs). Includes keyword arguments passed to Rails' [`fields_for` helper](https://api.rubyonrails.org/v7.0.4/classes/ActionView/Helpers/FormHelper.html#method-i-fields_for).
fields_for
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def multi(**options, &block) add_input MultiInput.new(builder: builder, form: form, **options, &block) end
Adds a multi input to this form. @param options [Hash] The options accepted by the multi input (see forms docs). @param block [Proc] A block that will be yielded a reference to the input object so it can be customized.
multi
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def hidden(**options) add_input HiddenInput.new(builder: builder, form: form, **options) end
Adds a hidden input to this form. @param options [Hash] The options accepted by the hidden input (see forms docs).
hidden
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def check_box(**options, &block) add_input CheckBoxInput.new(builder: builder, form: form, **options, &block) end
Adds a check box to this form. @param options [Hash] The options accepted by the check box input (see forms docs). @param block [Proc] A block that will be yielded a reference to the input object so it can be customized.
check_box
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def radio_button_group(**options, &block) add_input RadioButtonGroupInput.new(builder: builder, form: form, **options, &block) end
Adds a radio button group to this form. @param options [Hash] The options accepted by the radio button group input (see forms docs). @param block [Proc] A block that will be yielded a reference to the input object so it can be customized.
radio_button_group
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def check_box_group(**options, &block) add_input CheckBoxGroupInput.new(builder: builder, form: form, **options, &block) end
Adds a check box group to this form. @param options [Hash] The options accepted by the check box group input (see forms docs). @param block [Proc] A block that will be yielded a reference to the input object so it can be customized.
check_box_group
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def separator add_input Separator.new end
Adds a horizontal separator to the form.
separator
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def text_field(**options, &block) options = decorate_options(**options) add_input TextFieldInput.new(builder: builder, form: form, **options, &block) end
START text input methods Adds a text field to this form. @param options [Hash] The options accepted by the text field input (see forms docs). @param block [Proc] A block that will be yielded a reference to the input object so it can be customized.
text_field
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def auto_complete(**options, &block) options = decorate_options(**options) add_input AutoCompleteInput.new(builder: builder, form: form, **options, &block) end
Adds an autocomplete text field to this form. @param options [Hash] The options accepted by the autocomplete input (see forms docs). @param block [Proc] A block that will be yielded a reference to the input object so it can be customized.
auto_complete
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def text_area(**options, &block) options = decorate_options(**options) add_input TextAreaInput.new(builder: builder, form: form, **options, &block) end
Adds a text area to this form. @param options [Hash] The options accepted by the text area input (see forms docs). @param block [Proc] A block that will be yielded a reference to the input object so it can be customized.
text_area
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def select_list(**options, &block) options = decorate_options(**options) add_input SelectInput.new(builder: builder, form: form, **options, &block) end
END text input methods START select input methods Adds a select list to this form. @param options [Hash] The options accepted by the select list input (see forms docs). @param block [Proc] A block that will be yielded a reference to the input object so it can be customized.
select_list
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT
def action_menu(**options, &block) options = decorate_options(**options) add_input ActionMenuInput.new(builder: builder, form: form, **options, &block) end
Adds an <%= link_to_component(Primer::Alpha::ActionMenu) %> to this form. @param options [Hash] The options accepted by the <%= link_to_component(Primer::Alpha::ActionMenu) %> component. @param block [Proc] The block passed to `#render` when the <%= link_to_component(Primer::Alpha::ActionMenu) %> is rendered. This block is passed an instance of <%= link_to_component(Primer::Alpha::ActionMenu) %>, which can be used to add items, dividers, etc.
action_menu
ruby
primer/view_components
app/lib/primer/forms/dsl/input_methods.rb
https://github.com/primer/view_components/blob/master/app/lib/primer/forms/dsl/input_methods.rb
MIT