-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/view-components': minor | ||
--- | ||
|
||
Add an ActionMenu form input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
# :nodoc: | ||
class ActionMenuForm < ApplicationForm | ||
form do |action_menu_form| | ||
action_menu_form.action_menu(name: "city", label: "Favorite city", caption: "Select your favorite!") do |city_list| | ||
city_list.with_item(label: "Lopez Island", data: { value: "lopez_island" }) do |item| | ||
item.with_leading_visual_icon(icon: :log) | ||
end | ||
city_list.with_item(label: "Bellevue", data: { value: "bellevue" }) do |item| | ||
item.with_leading_visual_icon(icon: :paste) | ||
end | ||
city_list.with_item(label: "Seattle", data: { value: "seattle" }) do |item| | ||
item.with_leading_visual_icon(icon: :"device-camera") | ||
end | ||
end | ||
|
||
action_menu_form.submit(name: :submit, label: "Submit") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
# :nodoc: | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= render(FormControl.new(input: @input)) do %> | ||
<%= render(Primer::Alpha::ActionMenu.new(**@input.input_arguments)) do |menu| %> | ||
<% menu.with_show_button { "Select..." } %> | ||
<% @input.block.call(menu) if @input.block %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module Forms | ||
# :nodoc: | ||
class ActionMenu < BaseComponent | ||
delegate :builder, :form, to: :@input | ||
|
||
def initialize(input:) | ||
@input = input | ||
|
||
@input.input_arguments[:form_arguments] = { | ||
name: @input.name, | ||
builder: builder | ||
} | ||
|
||
@input.input_arguments[:select_variant] ||= :single | ||
|
||
unless @input.input_arguments.include?(:dynamic_label) | ||
@input.input_arguments[:dynamic_label] = true | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module Forms | ||
module Dsl | ||
# :nodoc: | ||
class ActionMenuInput < Input | ||
attr_reader :name, :label, :block | ||
|
||
def initialize(name:, label:, **system_arguments, &block) | ||
@name = name | ||
@label = label | ||
@block = block | ||
|
||
super(**system_arguments) | ||
end | ||
|
||
def to_component | ||
ActionMenu.new(input: self) | ||
end | ||
|
||
# :nocov: | ||
def type | ||
:action_menu | ||
end | ||
# :nocov: | ||
|
||
# :nocov: | ||
def focusable? | ||
true | ||
end | ||
# :nocov: | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= primer_form_with(url: action_menu_form_action_path(format: route_format)) do |f| %> | ||
<%= render(ActionMenuForm.new(f)) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters