mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +00:00
Add a onClickOutside behavior that close the component if clicked outside Selector component doesn't handle its state but receive props from parent u
25 lines
500 B
Ruby
25 lines
500 B
Ruby
# frozen_string_literal: true
|
|
|
|
class SelectorComponent < ViewComponentReflex::Component
|
|
def initialize(title:, selected:, items:, data: {})
|
|
@title = title
|
|
@items = items.map do |item|
|
|
{
|
|
id: item,
|
|
name: I18n.t("admin.products_page.columns_selector.#{item}"),
|
|
selected: selected.include?(item)
|
|
}
|
|
end
|
|
@state = :close
|
|
@data = data
|
|
end
|
|
|
|
def toggle
|
|
@state = @state == :open ? :close : :open
|
|
end
|
|
|
|
def close
|
|
@state = :close
|
|
end
|
|
end
|