@@ -107,21 +107,22 @@ defmodule PeekAppSDK.UI.Odyssey.ProductPicker do
107107 id = { "#{ @ id } _checkboxes" }
108108 >
109109 < div :for = { product <- @ products } class = "flex items-center gap-3 " >
110+ <% product_id = product [ @ id_key ] %>
110111 < input
111112 type = "checkbox "
112- id = { "#{ @ id } _product_#{ product . id } " }
113- checked = { product . id in @ selected_ids }
114- data-product-id = { product . id }
113+ id = { "#{ @ id } _product_#{ product_id } " }
114+ checked = { product_id in @ selected_ids }
115+ data-product-id = { product_id }
115116 disabled = { @ disabled }
116117 class = "checkbox checkbox-sm product-picker-checkbox "
117118 />
118119 < div
119120 class = "w-3 h-3 rounded-sm flex-shrink-0 "
120- style = { "background-color: #{ product . color_hex } " }
121+ style = { "background-color: #{ product [ @ color_key ] || "#888888" } " }
121122 >
122123 </ div >
123- < label for = { "#{ @ id } _product_#{ product . id } " } class = "text-sm text-gray-700 cursor-pointer " >
124- { product . name }
124+ < label for = { "#{ @ id } _product_#{ product_id } " } class = "text-sm text-gray-700 cursor-pointer " >
125+ { product [ @ name_key ] }
125126 </ label >
126127 </ div >
127128 </ div >
@@ -174,10 +175,14 @@ defmodule PeekAppSDK.UI.Odyssey.ProductPicker do
174175 """
175176 attr :field , :any , required: true , doc: "a Phoenix.HTML.FormField struct"
176177 attr :id , :string , doc: "component id, defaults to form_field_product_picker"
177- attr :products , :list , required: true , doc: "list of %{id, name, color_hex} maps"
178+
179+ attr :products , :list , required: true , doc: "list of product maps"
178180
179181 attr :selected_ids , :list , doc: "list of pre-selected product IDs (auto-extracted from field value when omitted)"
180182
183+ attr :id_key , :atom , default: :id , doc: "key to read product ID from each product map"
184+ attr :name_key , :atom , default: :name , doc: "key to read product name from each product map"
185+ attr :color_key , :atom , default: :color_hex , doc: "key to read product color hex from each product map"
181186 attr :all_label , :string , default: "All Products" , doc: "label for the 'all' toggle option"
182187 attr :specific_label , :string , default: "Specific Products" , doc: "label for the 'specific' toggle option"
183188 attr :label , :string , required: false , doc: "label for the toggle button"
0 commit comments