|
| 1 | +import React from "react" |
| 2 | +import clsx from "clsx" |
| 3 | +import { |
| 4 | + FeatureTableFields, |
| 5 | + Block, |
| 6 | + Span, |
| 7 | + TooltipBlock, |
| 8 | +} from "../../../utils/types" |
| 9 | +import { BorderedIcon, H3, MarkdownContent, MDXComponents } from "docs-ui" |
| 10 | +import slugify from "slugify" |
| 11 | +import { |
| 12 | + CodePullRequest, |
| 13 | + CurrencyDollar, |
| 14 | + ServerStack, |
| 15 | + Shopping, |
| 16 | + WIP, |
| 17 | +} from "@medusajs/icons" |
| 18 | + |
| 19 | +const P = MDXComponents.p |
| 20 | + |
| 21 | +interface FeatureSectionsProps { |
| 22 | + featureSections: FeatureTableFields["featureSections"] |
| 23 | + columnCount: number |
| 24 | + columns: string[] |
| 25 | +} |
| 26 | + |
| 27 | +const featureLinks: Record<string, string> = { |
| 28 | + Orders: "https://docs.medusajs.com/commerce-modules/order", |
| 29 | + Products: "https://docs.medusajs.com/commerce-modules/product", |
| 30 | + "Sales Channels": "https://docs.medusajs.com/commerce-modules/sales-channels", |
| 31 | + "Regions & currencies": "https://docs.medusajs.com/commerce-modules/region", |
| 32 | + "GitHub integration": |
| 33 | + "https://docs.medusajs.com/cloud/projects#2-create-project-from-an-existing-application", |
| 34 | + "Push-to-deploy flow": |
| 35 | + "https://docs.medusajs.com/cloud/deployments#how-are-deployments-created", |
| 36 | + Previews: "https://docs.medusajs.com/cloud/environments/preview", |
| 37 | + "Auto configuration:": |
| 38 | + "https://docs.medusajs.com/cloud/projects#prerequisite-medusa-application-configurations", |
| 39 | + Postgres: "https://docs.medusajs.com/cloud/database", |
| 40 | + Redis: "https://docs.medusajs.com/cloud/redis", |
| 41 | + S3: "https://docs.medusajs.com/cloud/s3", |
| 42 | + "Environment variables": |
| 43 | + "https://docs.medusajs.com/cloud/environments/environment-variables", |
| 44 | + "Data import/export": |
| 45 | + "https://docs.medusajs.com/cloud/database#importexport-database-dumps", |
| 46 | + Logs: "https://docs.medusajs.com/cloud/logs", |
| 47 | + "Multiple Long-Lived Environments": |
| 48 | + "https://docs.medusajs.com/cloud/environments/long-lived", |
| 49 | + "Cloud seats": |
| 50 | + "https://docs.medusajs.com/cloud/organizations#view-organization-members", |
| 51 | +} |
| 52 | + |
| 53 | +const featureIcons: Record<string, React.FC> = { |
| 54 | + "Commerce features": Shopping, |
| 55 | + "Development Platform": CodePullRequest, |
| 56 | + "Hosting & Deployment": ServerStack, |
| 57 | + "Compute & Resources": WIP, |
| 58 | + "Organization & Billing": CurrencyDollar, |
| 59 | +} |
| 60 | + |
| 61 | +// Helper function to render Block content (Sanity rich text) |
| 62 | +const renderBlockContent = (blocks: Block[]) => { |
| 63 | + if (!blocks || blocks.length === 0) { |
| 64 | + return "" |
| 65 | + } |
| 66 | + |
| 67 | + return blocks |
| 68 | + .map((block) => { |
| 69 | + if (block._type === "block" && block.children) { |
| 70 | + return block.children |
| 71 | + .map((child: Span | TooltipBlock) => { |
| 72 | + if (child._type === "span") { |
| 73 | + const key = child.text.trim() |
| 74 | + return featureLinks[key] |
| 75 | + ? "[" + child.text + "](" + featureLinks[key] + ")" |
| 76 | + : child.text |
| 77 | + } |
| 78 | + return "" |
| 79 | + }) |
| 80 | + .join(" \n") |
| 81 | + } |
| 82 | + return "" |
| 83 | + }) |
| 84 | + .join(" \n") |
| 85 | + .replaceAll("-", "\\-") |
| 86 | +} |
| 87 | + |
| 88 | +const FeatureSections: React.FC<FeatureSectionsProps> = ({ |
| 89 | + featureSections, |
| 90 | + columnCount, |
| 91 | + columns, |
| 92 | +}) => { |
| 93 | + if (!featureSections || featureSections.length === 0) { |
| 94 | + return null |
| 95 | + } |
| 96 | + |
| 97 | + // Calculate consistent column widths |
| 98 | + // Use fractional units to ensure all grids have matching column sizes |
| 99 | + const featureNameFraction = 2 // Feature name gets 2 units |
| 100 | + const featureColumnFraction = 1 // Each feature column gets 1 unit |
| 101 | + const gridTemplate = `${featureNameFraction}fr repeat(${columnCount}, ${featureColumnFraction}fr)` |
| 102 | + |
| 103 | + return ( |
| 104 | + <div className="w-full flex flex-col rounded shadow-elevation-card-rest dark:shadow-elevation-card-rest-dark"> |
| 105 | + {/* Header */} |
| 106 | + <div |
| 107 | + className="w-full grid gap-0 rounded-t" |
| 108 | + style={{ |
| 109 | + gridTemplateColumns: gridTemplate, |
| 110 | + }} |
| 111 | + > |
| 112 | + {/* Features label column */} |
| 113 | + <div className="flex items-center justify-start px-1.5 py-1 border-solid border-r border-medusa-border-base"> |
| 114 | + <p className="txt-large text-medusa-fg-subtle">Features</p> |
| 115 | + </div> |
| 116 | + |
| 117 | + {/* Column headers */} |
| 118 | + {columns.map((column, index) => ( |
| 119 | + <div |
| 120 | + key={index} |
| 121 | + className={clsx( |
| 122 | + "flex items-center justify-center px-1 py-1 bg-medusa-bg-base", |
| 123 | + index !== columns.length - 1 && |
| 124 | + "border-solid border-r border-medusa-border-base" |
| 125 | + )} |
| 126 | + > |
| 127 | + <p className="txt-large text-medusa-fg-base text-left w-full"> |
| 128 | + {column} |
| 129 | + </p> |
| 130 | + </div> |
| 131 | + ))} |
| 132 | + </div> |
| 133 | + {/* Feature Sections */} |
| 134 | + {featureSections.map((section) => ( |
| 135 | + <div key={section._key} className="w-full"> |
| 136 | + {/* Section Header */} |
| 137 | + <div className="w-full p-1.5 bg-medusa-bg-component flex gap-1 border-medusa-border-base border-y items-center"> |
| 138 | + {featureIcons[section.header.subtitle] && ( |
| 139 | + <BorderedIcon |
| 140 | + IconComponent={featureIcons[section.header.subtitle]} |
| 141 | + wrapperClassName="p-[7.5px] bg-medusa-bg-component rounded-[5px]" |
| 142 | + /> |
| 143 | + )} |
| 144 | + <div> |
| 145 | + <H3 |
| 146 | + id={slugify(section.header.subtitle, { lower: true })} |
| 147 | + className="!my-0" |
| 148 | + > |
| 149 | + {section.header.subtitle} |
| 150 | + </H3> |
| 151 | + {/* @ts-expect-error this is a React component */} |
| 152 | + <P className="text-medusa-fg-subtle">{section.header.title}</P> |
| 153 | + </div> |
| 154 | + </div> |
| 155 | + |
| 156 | + {/* Section Rows */} |
| 157 | + <div className="w-full"> |
| 158 | + {section.rows.map((row, index) => ( |
| 159 | + <React.Fragment key={row._key}> |
| 160 | + <div |
| 161 | + className={clsx( |
| 162 | + "w-full grid gap-0 border-solid border-medusa-border-base", |
| 163 | + index !== section.rows.length - 1 && "border-b" |
| 164 | + )} |
| 165 | + style={{ |
| 166 | + gridTemplateColumns: gridTemplate, |
| 167 | + }} |
| 168 | + > |
| 169 | + {/* Feature name column */} |
| 170 | + <div className="px-1 py-1 flex items-center justify-start border-solid border-r border-medusa-border-base"> |
| 171 | + <p className="txt-medium-plus text-medusa-fg-base"> |
| 172 | + <MarkdownContent |
| 173 | + allowedElements={["br", "a"]} |
| 174 | + unwrapDisallowed |
| 175 | + > |
| 176 | + {renderBlockContent(row.column1)} |
| 177 | + </MarkdownContent> |
| 178 | + </p> |
| 179 | + </div> |
| 180 | + |
| 181 | + {/* Feature value columns */} |
| 182 | + {Array.from({ length: columnCount }, (_, colIndex) => { |
| 183 | + const columnKey = `column${ |
| 184 | + colIndex + 2 |
| 185 | + }` as keyof typeof row |
| 186 | + const columnData = row[columnKey] as Block[] |
| 187 | + |
| 188 | + return ( |
| 189 | + <div |
| 190 | + key={colIndex} |
| 191 | + className={clsx( |
| 192 | + "px-1 py-1 flex items-center justify-center", |
| 193 | + colIndex !== columnCount - 1 && |
| 194 | + "border-solid border-r border-medusa-border-base" |
| 195 | + )} |
| 196 | + > |
| 197 | + <p className="txt-medium text-medusa-fg-base text-left w-full"> |
| 198 | + <MarkdownContent |
| 199 | + allowedElements={["br", "a"]} |
| 200 | + unwrapDisallowed |
| 201 | + > |
| 202 | + {renderBlockContent(columnData)} |
| 203 | + </MarkdownContent> |
| 204 | + </p> |
| 205 | + </div> |
| 206 | + ) |
| 207 | + })} |
| 208 | + </div> |
| 209 | + </React.Fragment> |
| 210 | + ))} |
| 211 | + </div> |
| 212 | + </div> |
| 213 | + ))} |
| 214 | + </div> |
| 215 | + ) |
| 216 | +} |
| 217 | + |
| 218 | +export default FeatureSections |
0 commit comments