|
| 1 | +import { codeToHtml } from "shiki"; |
| 2 | +import { CodeTabs } from "./code-tabs"; |
| 3 | + |
| 4 | +const vercelDarkTheme = { |
| 5 | + name: "vercel-dark", |
| 6 | + type: "dark" as const, |
| 7 | + colors: { |
| 8 | + "editor.background": "transparent", |
| 9 | + "editor.foreground": "#EDEDED", |
| 10 | + }, |
| 11 | + settings: [ |
| 12 | + { |
| 13 | + scope: ["comment", "punctuation.definition.comment"], |
| 14 | + settings: { foreground: "#666666" }, |
| 15 | + }, |
| 16 | + { |
| 17 | + scope: ["string", "string.quoted", "string.template"], |
| 18 | + settings: { foreground: "#50E3C2" }, |
| 19 | + }, |
| 20 | + { |
| 21 | + scope: [ |
| 22 | + "constant.numeric", |
| 23 | + "constant.language.boolean", |
| 24 | + "constant.language.null", |
| 25 | + ], |
| 26 | + settings: { foreground: "#50E3C2" }, |
| 27 | + }, |
| 28 | + { |
| 29 | + scope: ["keyword", "storage.type", "storage.modifier"], |
| 30 | + settings: { foreground: "#FF0080" }, |
| 31 | + }, |
| 32 | + { |
| 33 | + scope: ["keyword.operator", "keyword.control"], |
| 34 | + settings: { foreground: "#FF0080" }, |
| 35 | + }, |
| 36 | + { |
| 37 | + scope: ["entity.name.function", "support.function", "meta.function-call"], |
| 38 | + settings: { foreground: "#7928CA" }, |
| 39 | + }, |
| 40 | + { |
| 41 | + scope: ["variable", "variable.other", "variable.parameter"], |
| 42 | + settings: { foreground: "#EDEDED" }, |
| 43 | + }, |
| 44 | + { |
| 45 | + scope: ["entity.name.tag", "support.class.component", "entity.name.type"], |
| 46 | + settings: { foreground: "#FF0080" }, |
| 47 | + }, |
| 48 | + { |
| 49 | + scope: ["punctuation", "meta.brace", "meta.bracket"], |
| 50 | + settings: { foreground: "#888888" }, |
| 51 | + }, |
| 52 | + { |
| 53 | + scope: [ |
| 54 | + "support.type.property-name", |
| 55 | + "entity.name.tag.json", |
| 56 | + "meta.object-literal.key", |
| 57 | + ], |
| 58 | + settings: { foreground: "#EDEDED" }, |
| 59 | + }, |
| 60 | + { |
| 61 | + scope: ["entity.other.attribute-name"], |
| 62 | + settings: { foreground: "#50E3C2" }, |
| 63 | + }, |
| 64 | + { |
| 65 | + scope: ["support.type.primitive", "entity.name.type.primitive"], |
| 66 | + settings: { foreground: "#50E3C2" }, |
| 67 | + }, |
| 68 | + ], |
| 69 | +}; |
| 70 | + |
| 71 | +const vercelLightTheme = { |
| 72 | + name: "vercel-light", |
| 73 | + type: "light" as const, |
| 74 | + colors: { |
| 75 | + "editor.background": "transparent", |
| 76 | + "editor.foreground": "#171717", |
| 77 | + }, |
| 78 | + settings: [ |
| 79 | + { |
| 80 | + scope: ["comment", "punctuation.definition.comment"], |
| 81 | + settings: { foreground: "#6b7280" }, |
| 82 | + }, |
| 83 | + { |
| 84 | + scope: ["string", "string.quoted", "string.template"], |
| 85 | + settings: { foreground: "#067a6e" }, |
| 86 | + }, |
| 87 | + { |
| 88 | + scope: [ |
| 89 | + "constant.numeric", |
| 90 | + "constant.language.boolean", |
| 91 | + "constant.language.null", |
| 92 | + ], |
| 93 | + settings: { foreground: "#067a6e" }, |
| 94 | + }, |
| 95 | + { |
| 96 | + scope: ["keyword", "storage.type", "storage.modifier"], |
| 97 | + settings: { foreground: "#d6409f" }, |
| 98 | + }, |
| 99 | + { |
| 100 | + scope: ["keyword.operator", "keyword.control"], |
| 101 | + settings: { foreground: "#d6409f" }, |
| 102 | + }, |
| 103 | + { |
| 104 | + scope: ["entity.name.function", "support.function", "meta.function-call"], |
| 105 | + settings: { foreground: "#6e56cf" }, |
| 106 | + }, |
| 107 | + { |
| 108 | + scope: ["variable", "variable.other", "variable.parameter"], |
| 109 | + settings: { foreground: "#171717" }, |
| 110 | + }, |
| 111 | + { |
| 112 | + scope: ["entity.name.tag", "support.class.component", "entity.name.type"], |
| 113 | + settings: { foreground: "#d6409f" }, |
| 114 | + }, |
| 115 | + { |
| 116 | + scope: ["punctuation", "meta.brace", "meta.bracket"], |
| 117 | + settings: { foreground: "#6b7280" }, |
| 118 | + }, |
| 119 | + { |
| 120 | + scope: [ |
| 121 | + "support.type.property-name", |
| 122 | + "entity.name.tag.json", |
| 123 | + "meta.object-literal.key", |
| 124 | + ], |
| 125 | + settings: { foreground: "#171717" }, |
| 126 | + }, |
| 127 | + { |
| 128 | + scope: ["entity.other.attribute-name"], |
| 129 | + settings: { foreground: "#067a6e" }, |
| 130 | + }, |
| 131 | + { |
| 132 | + scope: ["support.type.primitive", "entity.name.type.primitive"], |
| 133 | + settings: { foreground: "#067a6e" }, |
| 134 | + }, |
| 135 | + ], |
| 136 | +}; |
| 137 | + |
| 138 | +interface PackageInstallProps { |
| 139 | + packages: string; |
| 140 | +} |
| 141 | + |
| 142 | +const packageManagers = [ |
| 143 | + { label: "npm", value: "npm", command: "npm install" }, |
| 144 | + { label: "pnpm", value: "pnpm", command: "pnpm add" }, |
| 145 | + { label: "yarn", value: "yarn", command: "yarn add" }, |
| 146 | + { label: "bun", value: "bun", command: "bun add" }, |
| 147 | +]; |
| 148 | + |
| 149 | +export async function PackageInstall({ packages }: PackageInstallProps) { |
| 150 | + const tabs = await Promise.all( |
| 151 | + packageManagers.map(async (pm) => { |
| 152 | + const code = `${pm.command} ${packages}`; |
| 153 | + const html = await codeToHtml(code, { |
| 154 | + lang: "bash", |
| 155 | + themes: { |
| 156 | + light: vercelLightTheme, |
| 157 | + dark: vercelDarkTheme, |
| 158 | + }, |
| 159 | + defaultColor: false, |
| 160 | + }); |
| 161 | + return { |
| 162 | + label: pm.label, |
| 163 | + value: pm.value, |
| 164 | + code, |
| 165 | + html, |
| 166 | + }; |
| 167 | + }), |
| 168 | + ); |
| 169 | + |
| 170 | + return <CodeTabs tabs={tabs} />; |
| 171 | +} |
0 commit comments