feat: Add product routes and components to v2 in admin-next (#6958)

This commit is contained in:
Stevche Radevski
2024-04-06 11:59:52 +02:00
committed by GitHub
parent d333db0842
commit 07fb058d96
81 changed files with 597 additions and 144 deletions

View File

@@ -0,0 +1 @@
export * from "./list"

View File

@@ -0,0 +1,54 @@
import { Checkbox, Text } from "@medusajs/ui"
export interface ListProps<T> {
options: { title: string; value: T }[]
value?: T[]
onChange?: (value: T[]) => void
compare?: (a: T, b: T) => boolean
disabled?: boolean
}
export const List = <T extends any>({
options,
onChange,
value,
compare,
disabled,
}: ListProps<T>) => {
if (options.length === 0) {
return <div>No options</div>
}
return (
<div className="flex-row justify-center border divide-y rounded-lg">
{options.map((option) => {
return (
<div className="flex p-4 gap-x-4">
{onChange && value !== undefined && (
<Checkbox
disabled={disabled}
checked={value.some(
(v) => compare?.(v, option.value) ?? v === option.value
)}
onCheckedChange={(checked) => {
if (checked) {
onChange([...value, option.value])
} else {
onChange(
value.filter(
(v) =>
!(compare?.(v, option.value) ?? v === option.value)
)
)
}
}}
/>
)}
<Text key={option.title}>{option.title}</Text>
</div>
)
})}
</div>
)
}