|
1
|
import React from "react" |
|
2
|
import { IconButton } from "@medusajs/ui" |
|
3
|
import { TriangleDownMini, XMarkMini } from "@medusajs/icons" |
|
4
|
import { Accordion as RadixAccordion } from "radix-ui" |
|
5
|
import { clx } from "@medusajs/ui" |
|
6
|
import { AmountDisplay } from "./amount-display" |
|
7
|
import { getRuleValue } from "./tiered-price-list" |
|
8
|
import { CurrencyInfo } from "../../../lib/data/currencies" |
|
9
|
|
|
10
|
interface TieredPriceItemProps { |
|
11
|
index: number |
|
12
|
currency: CurrencyInfo |
|
13
|
onRemove: (index: number) => void |
|
14
|
children: React.ReactNode |
|
15
|
triggerContent: React.ReactNode |
|
16
|
control: any |
|
17
|
} |
|
18
|
|
|
19
|
export const TieredPriceItem = ({ |
|
20
|
index, |
|
21
|
currency, |
|
22
|
onRemove, |
|
23
|
children, |
|
24
|
triggerContent, |
|
25
|
control, |
|
26
|
}: TieredPriceItemProps) => { |
|
27
|
const handleRemove = (e: React.MouseEvent<HTMLButtonElement>) => { |
|
28
|
e.stopPropagation() |
|
29
|
onRemove(index) |
|
30
|
} |
|
31
|
|
|
32
|
return ( |
|
33
|
<RadixAccordion.Item |
|
34
|
value={getRuleValue(index)} |
|
35
|
className={clx( |
|
36
|
"bg-ui-bg-component shadow-elevation-card-rest rounded-lg" |
|
37
|
)} |
|
38
|
> |
|
39
|
<RadixAccordion.Trigger asChild> |
|
40
|
<div className="group/trigger flex w-full cursor-pointer items-start justify-between gap-x-2 p-3"> |
|
41
|
<div className="flex flex-1 flex-wrap items-center justify-between gap-2"> |
|
42
|
<div className="flex h-7 items-center"> |
|
43
|
<AmountDisplay |
|
44
|
index={index} |
|
45
|
currency={currency} |
|
46
|
control={control} |
|
47
|
/> |
|
48
|
</div> |
|
49
|
<div className="flex min-h-7 items-center">{triggerContent}</div> |
|
50
|
</div> |
|
51
|
<div className="flex items-center gap-x-2"> |
|
52
|
<IconButton |
|
53
|
size="small" |
|
54
|
variant="transparent" |
|
55
|
className="text-ui-fg-muted hover:text-ui-fg-subtle focus-visible:text-ui-fg-subtle" |
|
56
|
onClick={handleRemove} |
|
57
|
> |
|
58
|
<XMarkMini /> |
|
59
|
</IconButton> |
|
60
|
<IconButton |
|
61
|
size="small" |
|
62
|
variant="transparent" |
|
63
|
className="text-ui-fg-muted hover:text-ui-fg-subtle focus-visible:text-ui-fg-subtle" |
|
64
|
> |
|
65
|
<TriangleDownMini className="transition-transform group-data-[state=open]/trigger:rotate-180" /> |
|
66
|
</IconButton> |
|
67
|
</div> |
|
68
|
</div> |
|
69
|
</RadixAccordion.Trigger> |
|
70
|
<RadixAccordion.Content className="text-ui-fg-subtle"> |
|
71
|
{children} |
|
72
|
</RadixAccordion.Content> |
|
73
|
</RadixAccordion.Item> |
|
74
|
) |
|
75
|
} |