|
| 1 | +import React, { useState } from "react"; |
| 2 | +import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; |
| 3 | +import { tomorrow } from "react-syntax-highlighter/dist/esm/styles/prism"; |
| 4 | +import { copytoData } from "../../constant/Utils"; |
| 5 | +import { useTranslation } from "react-i18next"; |
| 6 | + |
| 7 | +function EmbedTab(props) { |
| 8 | + const { t } = useTranslation(); |
| 9 | + const tabName = [ |
| 10 | + { title: "React/Next.js", icon: "fa-brands fa-react", color: "#61dafb" }, |
| 11 | + { title: "JavaScript", icon: "fa-brands fa-js", color: "#ffd43b" }, |
| 12 | + { title: "Angular", icon: "fa-brands fa-angular", color: "#ff5733" } |
| 13 | + ]; |
| 14 | + const [activeTab, setActiveTab] = useState(0); |
| 15 | + // State to track if the code has been copied |
| 16 | + const [isCopied, setIsCopied] = useState(false); |
| 17 | + const reactCode = [ |
| 18 | + { |
| 19 | + id: 0, |
| 20 | + title: "Installation", |
| 21 | + codeString: ` |
| 22 | +npm install opensign-react` |
| 23 | + }, |
| 24 | + { |
| 25 | + id: 1, |
| 26 | + title: "Usage", |
| 27 | + codeString: ` |
| 28 | +import React from "react"; |
| 29 | +import Opensign from "opensign-react"; |
| 30 | +
|
| 31 | +export function App() { |
| 32 | + return ( |
| 33 | + <div className="app"> |
| 34 | + <Opensign |
| 35 | + onLoad={() => console.log("success")} |
| 36 | + onLoadError={(error) => console.log(error)} |
| 37 | + templateId= {"${props.templateId}"} |
| 38 | + /> |
| 39 | + </div> |
| 40 | + ); |
| 41 | +} |
| 42 | +
|
| 43 | +
|
| 44 | +` |
| 45 | + } |
| 46 | + ]; |
| 47 | + |
| 48 | + const angularCode = [ |
| 49 | + { |
| 50 | + id: 0, |
| 51 | + title: "Installation", |
| 52 | + codeString: ` |
| 53 | +npm install opensign-angular-lib` |
| 54 | + }, |
| 55 | + { |
| 56 | + id: 1, |
| 57 | + title: "Usage", |
| 58 | + codeString: ` |
| 59 | +import { Component } from '@angular/core'; |
| 60 | +import {OpensignComponent} from "opensign-angular-lib" |
| 61 | + |
| 62 | +@Component({ |
| 63 | + selector:'app-root', |
| 64 | + standalone: true, |
| 65 | + imports: [OpensignComponent], |
| 66 | + template: '<opensign templateId={"${props.templateId}"} |
| 67 | + (onLoad)="handleLoad()" |
| 68 | + (onLoadError)="handleError($event)" |
| 69 | + ></opensign>', |
| 70 | +}) |
| 71 | +export class AppComponent{ |
| 72 | + handleLoad() { |
| 73 | + console.log("success"); |
| 74 | + } |
| 75 | + handleError(error: string) { |
| 76 | + console.log(error); |
| 77 | + } |
| 78 | +
|
| 79 | +} |
| 80 | +
|
| 81 | +
|
| 82 | +` |
| 83 | + } |
| 84 | + ]; |
| 85 | + const jsCodeString = ` |
| 86 | +<script |
| 87 | + src= "https://app.opensignlabs.com/static/js/public-template.bundle.js" |
| 88 | + id="opensign-script" |
| 89 | + templateId=${props.templateId} |
| 90 | + ></script> |
| 91 | + `; |
| 92 | + |
| 93 | + const handleCopy = (code, ind) => { |
| 94 | + copytoData(code); |
| 95 | + setIsCopied({ ...isCopied, [ind]: true }); |
| 96 | + setTimeout(() => setIsCopied(false), 3000); |
| 97 | + }; |
| 98 | + |
| 99 | + return ( |
| 100 | + <div className="mt-4 border-t-[1px]"> |
| 101 | + <div className="flex justify-center items-center mt-2"> |
| 102 | + <div role="tablist" className="op-tabs op-tabs-bordered"> |
| 103 | + {tabName.map((tabData, ind) => ( |
| 104 | + <div |
| 105 | + onClick={() => setActiveTab(ind)} |
| 106 | + key={ind} |
| 107 | + role="tab" |
| 108 | + className={`${ |
| 109 | + activeTab === ind ? "op-tab-active" : "" |
| 110 | + } op-tab flex items-center`} |
| 111 | + > |
| 112 | + <i |
| 113 | + className={`${tabData.icon}`} |
| 114 | + style={{ color: tabData.color }} |
| 115 | + ></i> |
| 116 | + <span className="ml-1 text-[10px] font-medium md:font-normal md:text-[15px]"> |
| 117 | + {tabData.title} |
| 118 | + </span> |
| 119 | + </div> |
| 120 | + ))} |
| 121 | + </div> |
| 122 | + </div> |
| 123 | + <div> |
| 124 | + {activeTab === 0 ? ( |
| 125 | + <div className="mt-4"> |
| 126 | + {reactCode.map((data, ind) => { |
| 127 | + return ( |
| 128 | + <div key={ind}> |
| 129 | + <p className="font-medium text-[18px]"> |
| 130 | + {t(`${data.title}`)} |
| 131 | + </p> |
| 132 | + <p className="text-[13px] mt-2"> |
| 133 | + {t("public-template-mssg-1")} |
| 134 | + </p> |
| 135 | + <div className="relative p-1"> |
| 136 | + <div |
| 137 | + onClick={() => handleCopy(data.codeString, ind)} |
| 138 | + className="absolute top-[20px] right-[20px] cursor-pointer" |
| 139 | + > |
| 140 | + <i className="fa-light fa-copy text-white mr-[2px]" /> |
| 141 | + <span className=" text-white"> |
| 142 | + {isCopied[ind] ? t("copied-code") : t("copy-code")} |
| 143 | + </span> |
| 144 | + </div> |
| 145 | + <SyntaxHighlighter |
| 146 | + customStyle={{ |
| 147 | + borderRadius: "15px" |
| 148 | + }} |
| 149 | + language="javascript" |
| 150 | + style={tomorrow} |
| 151 | + > |
| 152 | + {data.codeString} |
| 153 | + </SyntaxHighlighter> |
| 154 | + </div> |
| 155 | + </div> |
| 156 | + ); |
| 157 | + })} |
| 158 | + |
| 159 | + <p className="font-medium text-[15px]"> |
| 160 | + {t("public-template-mssg-3")} |
| 161 | + </p> |
| 162 | + <p className="my-[6px]"> |
| 163 | + {" "} |
| 164 | + {t("public-template-mssg-4")} |
| 165 | + <a |
| 166 | + href="https://www.npmjs.com/package/opensign-react" |
| 167 | + target="_blank" |
| 168 | + rel="noreferrer" |
| 169 | + className="cursor-pointer text-blue-700 " |
| 170 | + > |
| 171 | + {" "} |
| 172 | + OpenSign React package{" "} |
| 173 | + </a> |
| 174 | + {t("public-template-mssg-5")} |
| 175 | + </p> |
| 176 | + </div> |
| 177 | + ) : activeTab === 1 ? ( |
| 178 | + <div className="mt-4"> |
| 179 | + <div> |
| 180 | + {/* <p className="font-medium text-[18px]">{t(`${data.title}`)}</p> */} |
| 181 | + |
| 182 | + <div className="relative p-1"> |
| 183 | + <div |
| 184 | + onClick={() => handleCopy(jsCodeString, 0)} |
| 185 | + className="absolute top-[20px] right-[20px] cursor-pointer" |
| 186 | + > |
| 187 | + <i className="fa-light fa-copy text-white mr-[2px]" /> |
| 188 | + <span className=" text-white"> |
| 189 | + {isCopied[0] ? t("copied-code") : t("copy-code")} |
| 190 | + </span> |
| 191 | + </div> |
| 192 | + <SyntaxHighlighter |
| 193 | + customStyle={{ |
| 194 | + borderRadius: "15px" |
| 195 | + }} |
| 196 | + language="javascript" |
| 197 | + style={tomorrow} |
| 198 | + > |
| 199 | + {jsCodeString} |
| 200 | + </SyntaxHighlighter> |
| 201 | + </div> |
| 202 | + </div> |
| 203 | + </div> |
| 204 | + ) : ( |
| 205 | + activeTab === 2 && ( |
| 206 | + <div className="mt-4"> |
| 207 | + {angularCode.map((data, ind) => { |
| 208 | + return ( |
| 209 | + <div key={ind}> |
| 210 | + <p className="font-medium text-[18px]"> |
| 211 | + {t(`${data.title}`)} |
| 212 | + </p> |
| 213 | + |
| 214 | + <p className="text-[13px] mt-2"> |
| 215 | + {t("angular-npm-mssg-1")} |
| 216 | + </p> |
| 217 | + |
| 218 | + <div className="relative p-1"> |
| 219 | + <div |
| 220 | + onClick={() => handleCopy(data.codeString, ind)} |
| 221 | + className="absolute top-[20px] right-[20px] cursor-pointer" |
| 222 | + > |
| 223 | + <i className="fa-light fa-copy text-white mr-[2px]" /> |
| 224 | + <span className=" text-white"> |
| 225 | + {isCopied[ind] ? t("copied-code") : t("copy-code")} |
| 226 | + </span> |
| 227 | + </div> |
| 228 | + <SyntaxHighlighter |
| 229 | + customStyle={{ |
| 230 | + borderRadius: "15px" |
| 231 | + }} |
| 232 | + language="javascript" |
| 233 | + style={tomorrow} |
| 234 | + > |
| 235 | + {data.codeString} |
| 236 | + </SyntaxHighlighter> |
| 237 | + </div> |
| 238 | + </div> |
| 239 | + ); |
| 240 | + })} |
| 241 | + |
| 242 | + <p className="font-medium text-[15px]"> |
| 243 | + {t("public-template-mssg-3")} |
| 244 | + </p> |
| 245 | + <p className="my-[6px]"> |
| 246 | + {" "} |
| 247 | + {t("public-template-mssg-4")} |
| 248 | + <a |
| 249 | + href="https://www.npmjs.com/package/opensign-angular-lib" |
| 250 | + target="_blank" |
| 251 | + rel="noreferrer" |
| 252 | + className="cursor-pointer text-blue-700 " |
| 253 | + > |
| 254 | + {" "} |
| 255 | + OpenSign Angular package{" "} |
| 256 | + </a> |
| 257 | + {t("public-template-mssg-5")} |
| 258 | + </p> |
| 259 | + </div> |
| 260 | + ) |
| 261 | + )} |
| 262 | + </div> |
| 263 | + </div> |
| 264 | + ); |
| 265 | +} |
| 266 | + |
| 267 | +export default EmbedTab; |
0 commit comments