|
1
|
import React from "react" |
|
2
|
import clsx from "clsx" |
|
3
|
import { FeatureTableFields, Block } from "../../../utils/types" |
|
4
|
import { getBlockLines } from "../../../utils/pricing" |
|
5
|
import { BorderedIcon, H3, MarkdownContent, MDXComponents } from "docs-ui" |
|
6
|
import slugify from "slugify" |
|
7
|
import { |
|
8
|
CodePullRequest, |
|
9
|
CurrencyDollar, |
|
10
|
EnvelopeContent, |
|
11
|
ServerStack, |
|
12
|
Shopping, |
|
13
|
Users, |
|
14
|
Window, |
|
15
|
Microchip, |
|
16
|
Robot, |
|
17
|
Bolt, |
|
18
|
MagnifyingGlass, |
|
19
|
} from "@medusajs/icons" |
|
20
|
import { config } from "../../../config" |
|
21
|
|
|
22
|
const P = MDXComponents.p |
|
23
|
|
|
24
|
interface FeatureSectionsProps { |
|
25
|
featureSections: FeatureTableFields["featureSections"] |
|
26
|
columnCount: number |
|
27
|
columns: string[] |
|
28
|
} |
|
29
|
|
|
30
|
const featureIcons: Record<string, React.FC> = { |
|
31
|
"Commerce features": Shopping, |
|
32
|
Agents: Robot, |
|
33
|
Infrastructure: CodePullRequest, |
|
34
|
Storefronts: Window, |
|
35
|
"High Reliability": ServerStack, |
|
36
|
"Enterprise License": Users, |
|
37
|
"Medusa Cache": Bolt, |
|
38
|
Search: MagnifyingGlass, |
|
39
|
"Medusa Emails": EnvelopeContent, |
|
40
|
"Compute & Resources": Microchip, |
|
41
|
"Organization & Billing": CurrencyDollar, |
|
42
|
} |
|
43
|
|
|
44
|
const renderBlockContent = (blocks: Block[]) => |
|
45
|
getBlockLines(blocks, config.baseUrl).join(" \n").replaceAll("-", "\\-") |
|
46
|
|
|
47
|
const FeatureSections: React.FC<FeatureSectionsProps> = ({ |
|
48
|
featureSections, |
|
49
|
columnCount, |
|
50
|
columns, |
|
51
|
}) => { |
|
52
|
if (!featureSections || featureSections.length === 0) { |
|
53
|
return null |
|
54
|
} |
|
55
|
|
|
56
|
// Calculate consistent column widths |
|
57
|
// Use fractional units to ensure all grids have matching column sizes |
|
58
|
const featureNameFraction = 2 // Feature name gets 2 units |
|
59
|
const featureColumnFraction = `minmax(0, 1fr)` // Each feature column gets 1 unit |
|
60
|
const gridTemplate = `${featureNameFraction}fr repeat(${columnCount}, ${featureColumnFraction})` |
|
61
|
|
|
62
|
return ( |
|
63
|
<div className="w-full flex flex-col rounded shadow-elevation-card-rest dark:shadow-elevation-card-rest-dark overflow-hidden"> |
|
64
|
{/* Header */} |
|
65
|
<div |
|
66
|
className="w-full grid gap-0 rounded-t" |
|
67
|
style={{ |
|
68
|
gridTemplateColumns: gridTemplate, |
|
69
|
}} |
|
70
|
> |
|
71
|
{/* Features label column */} |
|
72
|
<div className="flex items-center justify-start p-0.5 sm:px-1.5 sm:py-1 border-solid border-r border-medusa-border-base"> |
|
73
|
<p className="txt-medium sm:txt-large text-medusa-fg-subtle"> |
|
74
|
Features |
|
75
|
</p> |
|
76
|
</div> |
|
77
|
|
|
78
|
{/* Column headers */} |
|
79
|
{columns.map((column, index) => ( |
|
80
|
<div |
|
81
|
key={index} |
|
82
|
className={clsx( |
|
83
|
"flex items-center justify-center p-0.25 sm:p-1 bg-medusa-bg-base", |
|
84
|
index !== columns.length - 1 && |
|
85
|
"border-solid border-r border-medusa-border-base" |
|
86
|
)} |
|
87
|
> |
|
88
|
<p className="txt-medium sm:txt-large text-medusa-fg-base text-left w-full"> |
|
89
|
{column} |
|
90
|
</p> |
|
91
|
</div> |
|
92
|
))} |
|
93
|
</div> |
|
94
|
{/* Feature Sections */} |
|
95
|
{featureSections.map((section) => ( |
|
96
|
<div key={section._key} className="w-full"> |
|
97
|
{/* Section Header */} |
|
98
|
<div className="w-full p-1.5 bg-medusa-bg-component flex gap-1 border-medusa-border-base border-y items-center"> |
|
99
|
{featureIcons[section.header.subtitle] && ( |
|
100
|
<BorderedIcon |
|
101
|
IconComponent={featureIcons[section.header.subtitle]} |
|
102
|
wrapperClassName="p-[7.5px] bg-medusa-bg-component rounded-[5px]" |
|
103
|
/> |
|
104
|
)} |
|
105
|
<div> |
|
106
|
<H3 |
|
107
|
id={slugify(section.header.subtitle, { lower: true })} |
|
108
|
className="!my-0" |
|
109
|
> |
|
110
|
{section.header.subtitle} |
|
111
|
</H3> |
|
112
|
{/* @ts-expect-error this is a React component */} |
|
113
|
<P className="text-medusa-fg-subtle">{section.header.title}</P> |
|
114
|
</div> |
|
115
|
</div> |
|
116
|
|
|
117
|
{/* Section Rows */} |
|
118
|
<div className="w-full"> |
|
119
|
{section.rows.map((row, index) => ( |
|
120
|
<React.Fragment key={row._key}> |
|
121
|
<div |
|
122
|
className={clsx( |
|
123
|
"w-full grid gap-0 border-solid border-medusa-border-base", |
|
124
|
index !== section.rows.length - 1 && "border-b" |
|
125
|
)} |
|
126
|
style={{ |
|
127
|
gridTemplateColumns: gridTemplate, |
|
128
|
}} |
|
129
|
> |
|
130
|
{/* Feature name column */} |
|
131
|
<div className="p-0.25 sm:p-1 flex items-center justify-start border-solid border-r border-medusa-border-base"> |
|
132
|
<p className="txt-medium-plus text-medusa-fg-base"> |
|
133
|
<MarkdownContent |
|
134
|
allowedElements={["br", "a"]} |
|
135
|
unwrapDisallowed |
|
136
|
> |
|
137
|
{renderBlockContent(row.column1)} |
|
138
|
</MarkdownContent> |
|
139
|
</p> |
|
140
|
</div> |
|
141
|
|
|
142
|
{/* Feature value columns */} |
|
143
|
{Array.from({ length: columnCount }, (_, colIndex) => { |
|
144
|
const columnKey = `column${ |
|
145
|
colIndex + 2 |
|
146
|
}` as keyof typeof row |
|
147
|
const columnData = row[columnKey] as Block[] |
|
148
|
|
|
149
|
return ( |
|
150
|
<div |
|
151
|
key={colIndex} |
|
152
|
className={clsx( |
|
153
|
"p-0.25 sm:p-1 flex items-center justify-center", |
|
154
|
colIndex !== columnCount - 1 && |
|
155
|
"border-solid border-r border-medusa-border-base" |
|
156
|
)} |
|
157
|
> |
|
158
|
<p className="txt-medium text-medusa-fg-base text-left w-full"> |
|
159
|
<MarkdownContent |
|
160
|
allowedElements={["br", "a"]} |
|
161
|
unwrapDisallowed |
|
162
|
> |
|
163
|
{renderBlockContent(columnData)} |
|
164
|
</MarkdownContent> |
|
165
|
</p> |
|
166
|
</div> |
|
167
|
) |
|
168
|
})} |
|
169
|
</div> |
|
170
|
</React.Fragment> |
|
171
|
))} |
|
172
|
</div> |
|
173
|
</div> |
|
174
|
))} |
|
175
|
</div> |
|
176
|
) |
|
177
|
} |
|
178
|
|
|
179
|
export default FeatureSections |