@@ -171,143 +171,69 @@ module Alpha
171171 class ActionMenu < Primer ::Component
172172 status :alpha
173173
174- DEFAULT_PRELOAD = false
174+ delegate :preload , :preload? , :list , to : :@primary_menu
175+ delegate :with_show_button , :with_item , :items , :with_divider , :with_avatar_item , :with_group , :with_sub_menu_item , to : :@primary_menu
175176
176- DEFAULT_SELECT_VARIANT = :none
177- SELECT_VARIANT_OPTIONS = [
178- :single ,
179- :multiple ,
180- DEFAULT_SELECT_VARIANT
181- ] . freeze
182-
183- attr_reader :list , :preload
184-
185- alias preload? preload
186-
187- # @param menu_id [String] Id of the menu.
188- # @param anchor_align [Symbol] <%= one_of(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS) %>.
189- # @param anchor_side [Symbol] <%= one_of(Primer::Alpha::Overlay::ANCHOR_SIDE_OPTIONS) %>.
190- # @param size [Symbol] <%= one_of(Primer::Alpha::Overlay::SIZE_OPTIONS) %>.
191- # @param src [String] Used with an `include-fragment` element to load menu content from the given source URL.
192- # @param preload [Boolean] When true, and src is present, loads the `include-fragment` on trigger hover.
193- # @param dynamic_label [Boolean] Whether or not to display the text of the currently selected item in the show button.
194- # @param dynamic_label_prefix [String] If provided, the prefix is prepended to the dynamic label and displayed in the show button.
195- # @param select_variant [Symbol] <%= one_of(Primer::Alpha::ActionMenu::SELECT_VARIANT_OPTIONS) %>
196- # @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.
197- # @param overlay_arguments [Hash] Arguments to pass to the underlying <%= link_to_component(Primer::Alpha::Overlay) %>
198- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>.
199- def initialize (
200- menu_id : self . class . generate_id ,
201- anchor_align : Primer ::Alpha ::Overlay ::DEFAULT_ANCHOR_ALIGN ,
202- anchor_side : Primer ::Alpha ::Overlay ::DEFAULT_ANCHOR_SIDE ,
203- size : Primer ::Alpha ::Overlay ::DEFAULT_SIZE ,
204- src : nil ,
205- preload : DEFAULT_PRELOAD ,
206- dynamic_label : false ,
207- dynamic_label_prefix : nil ,
208- select_variant : DEFAULT_SELECT_VARIANT ,
209- form_arguments : { } ,
210- overlay_arguments : { } ,
211- **system_arguments
212- )
213- @menu_id = menu_id
214- @src = src
215- @preload = fetch_or_fallback_boolean ( preload , DEFAULT_PRELOAD )
216- @system_arguments = deny_tag_argument ( **system_arguments )
217-
218- @system_arguments [ :preload ] = true if @src . present? && preload?
177+ # @!parse
178+ # # Adds an item to the menu.
179+ # #
180+ # # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %>'s `item` slot.
181+ # def with_item(**system_arguments)
182+ # end
183+ #
184+ # # Adds an avatar item to the menu.
185+ # #
186+ # # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %>'s `item` slot.
187+ # def with_avatar_item(**system_arguments)
188+ # end
189+ #
190+ # # Adds a divider to the list. Dividers visually separate items.
191+ # #
192+ # # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList::Divider) %>.
193+ # def with_divider(**system_arguments)
194+ # end
195+ #
196+ # # Adds a group to the menu. Groups are a logical set of items with a header.
197+ # #
198+ # # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionMenu::Group) %>.
199+ # def with_group(**system_arguments)
200+ # end
201+ #
202+ # # Gets the list of configured menu items, which includes regular items, avatar items, groups, and dividers.
203+ # #
204+ # # @return [Array<ViewComponent::Slot>]
205+ # def items
206+ # end
219207
220- @select_variant = fetch_or_fallback ( SELECT_VARIANT_OPTIONS , select_variant , DEFAULT_SELECT_VARIANT )
208+ # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionMenu::PrimaryMenu) %>.
209+ def initialize ( **system_arguments )
210+ @primary_menu = PrimaryMenu . allocate
211+ @system_arguments = @primary_menu . send ( :initialize , **system_arguments )
221212
222213 @system_arguments [ :tag ] = :"action-menu"
223- @system_arguments [ :"data-select-variant" ] = select_variant
224- @system_arguments [ :"data-dynamic-label" ] = "" if dynamic_label
225- @system_arguments [ :"data-dynamic-label-prefix" ] = dynamic_label_prefix if dynamic_label_prefix . present?
214+ @system_arguments [ :preload ] = true if @primary_menu . preload?
226215
227- overlay_arguments [ :data ] = merge_data (
228- overlay_arguments , data : {
229- target : "action-menu.overlay"
216+ @system_arguments [ :data ] = merge_data (
217+ @system_arguments , {
218+ data : { "select-variant" : @primary_menu . select_variant }
230219 }
231220 )
232221
233- @overlay = Primer ::Alpha ::Overlay . new (
234- id : "#{ @menu_id } -overlay" ,
235- title : "Menu" ,
236- visually_hide_title : true ,
237- anchor_align : anchor_align ,
238- anchor_side : anchor_side ,
239- size : size ,
240- **overlay_arguments
241- )
222+ @system_arguments [ :"data-dynamic-label" ] = "" if @primary_menu . dynamic_label
242223
243- @list = Primer ::Alpha ::ActionMenu ::List . new (
244- menu_id : @menu_id ,
245- select_variant : select_variant ,
246- form_arguments : form_arguments
247- )
248- end
249-
250- # @!parse
251- # # Button to activate the menu.
252- # #
253- # # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::Overlay) %>'s `show_button` slot.
254- # renders_one(:show_button)
255-
256- # Button to activate the menu.
257- #
258- # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::Overlay) %>'s `show_button` slot.
259- def with_show_button ( **system_arguments , &block )
260- @overlay . with_show_button ( **system_arguments , id : "#{ @menu_id } -button" , controls : "#{ @menu_id } -list" ) do |button |
261- evaluate_block ( button , &block )
224+ if @primary_menu . dynamic_label_prefix . present?
225+ @system_arguments [ :"data-dynamic-label-prefix" ] = @primary_menu . dynamic_label_prefix
262226 end
263227 end
264228
265- # @!parse
266- # # Adds a new item to the list.
267- # #
268- # # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList::Item) %>.
269- # renders_many(:items)
270-
271- # Adds a new item to the list.
272- #
273- # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList::Item) %>.
274- def with_item ( **system_arguments , &block )
275- @list . with_item ( **system_arguments , &block )
276- end
277-
278- # Adds a divider to the list.
279- #
280- # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %>'s `divider` slot.
281- def with_divider ( **system_arguments , &block )
282- @list . with_divider ( **system_arguments , &block )
283- end
284-
285- # Adds an avatar item to the list. Avatar items are a convenient way to accessibly add an item with a leading avatar image.
286- #
287- # @param src [String] The source url of the avatar image.
288- # @param username [String] The username associated with the avatar.
289- # @param full_name [String] Optional. The user's full name.
290- # @param full_name_scheme [Symbol] Optional. How to display the user's full name.
291- # @param avatar_arguments [Hash] Optional. The arguments accepted by <%= link_to_component(Primer::Beta::Avatar) %>.
292- # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList::Item) %>.
293- def with_avatar_item ( **system_arguments , &block )
294- @list . with_avatar_item ( **system_arguments , &block )
295- end
296-
297- def with_group ( **system_arguments , &block )
298- @list . with_group ( **system_arguments , &block )
299- end
300-
301229 private
302230
303231 def before_render
304232 content
305-
306- raise ArgumentError , "`items` cannot be set when `src` is specified" if @src . present? && @list . items . any?
307233 end
308234
309235 def render?
310- @list . items . any? || @src . present?
236+ @primary_menu . items . any? || @primary_menu . src . present?
311237 end
312238 end
313239 end
0 commit comments