Skip to content

Instantly share code, notes, and snippets.

@netgfx
Created August 19, 2022 10:13
Show Gist options
  • Save netgfx/970d6e2928fa708f427b10d06fa66669 to your computer and use it in GitHub Desktop.
Save netgfx/970d6e2928fa708f427b10d06fa66669 to your computer and use it in GitHub Desktop.
Framer + Airtable add product smart components
export function addProducts(Component): ComponentType {
return (props) => {
const [store, setStore] = globalStore()
function toggleProduct(title) {
var products = _.cloneDeep(store.selectedProducts)
var index = store.selectedProducts.indexOf(title)
if (index != -1) {
products.splice(index, 1)
setStore({ selectedProducts: products })
} else {
products.push(title)
setStore({
selectedProducts: products,
})
}
}
return (
<Component {...props}>
{store.productLabels.map((item) => (
<Product
variant={
store.selectedProducts.indexOf(item) != -1
? "enabled"
: "disabled"
}
title={item}
onClick={() => toggleProduct(item)}
/>
))}
</Component>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment