Skip to content

Commit

Permalink
added QRcode block
Browse files Browse the repository at this point in the history
  • Loading branch information
dkashikar committed Jan 10, 2024
1 parent 73d68f0 commit e3bdd33
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 1 deletion.
37 changes: 37 additions & 0 deletions packages/forge/blocks/qrcode/actions/displayQr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createAction, option } from "@typebot.io/forge";
import qrcode from "qrcode-generator";


export const displayQr = createAction({
name: 'Display Qr',
options: option.object({
qrvalue: option.string.layout({
label: 'Qr Code',
helperText: 'QR code to show'
}),
qrlink: option.string.layout({
label: 'Qr link',
helperText: 'Link to goto on tapping QR code'
}),
}),
run: {
web: {
displayEmbedBubble: {
parseInitFunction: ({ options }) => {
if (!options.qrvalue) throw new Error('Missing Qr Code')
var qr = qrcode(8, 'L');
qr.addData(options.qrvalue);
qr.make();
const qrvalue = qr.createDataURL();
return {
args: {
qrvalue: qrvalue,
qrlink: options.qrlink ?? null
},
content: `let qr = document.createElement("img");qr.src = qrvalue;qr.classList.add('w-full');; let link = document.createElement("a"); link.href = qrlink; link.target = '_blank'; link.appendChild(qr); typebotElement.appendChild(qrlink ? link : qr);`,
}
},
},
}
},
})
11 changes: 11 additions & 0 deletions packages/forge/blocks/qrcode/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createBlock } from '@typebot.io/forge'
import { QrcodeLogo } from './logo'
import { displayQr } from './actions/displayQr'

export const qrcode = createBlock({
id: 'qrcode',
name: 'QRcode',
tags: ['QR Code', 'Scan'],
LightLogo: QrcodeLogo,
actions: [displayQr]
})
16 changes: 16 additions & 0 deletions packages/forge/blocks/qrcode/logo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'

export const QrcodeLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 24 24" {...props}>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M3.75 4.875c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5A1.125 1.125 0 0 1 3.75 9.375v-4.5ZM3.75 14.625c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5a1.125 1.125 0 0 1-1.125-1.125v-4.5ZM13.5 4.875c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5A1.125 1.125 0 0 1 13.5 9.375v-4.5Z"
/>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M6.75 6.75h.75v.75h-.75v-.75ZM6.75 16.5h.75v.75h-.75v-.75ZM16.5 6.75h.75v.75h-.75v-.75ZM13.5 13.5h.75v.75h-.75v-.75ZM13.5 19.5h.75v.75h-.75v-.75ZM19.5 13.5h.75v.75h-.75v-.75ZM19.5 19.5h.75v.75h-.75v-.75ZM16.5 16.5h.75v.75h-.75v-.75Z"
/>
</svg>
)
18 changes: 18 additions & 0 deletions packages/forge/blocks/qrcode/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@typebot.io/qrcode-block",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"keywords": [],
"license": "ISC",
"devDependencies": {
"@typebot.io/forge": "workspace:*",
"@typebot.io/lib": "workspace:*",
"@typebot.io/tsconfig": "workspace:*",
"@types/react": "18.2.15",
"typescript": "5.3.2"
},
"dependencies": {
"qrcode-generator": "^1.4.4"
}
}
10 changes: 10 additions & 0 deletions packages/forge/blocks/qrcode/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@typebot.io/tsconfig/base.json",
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"],
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
}
}
1 change: 1 addition & 0 deletions packages/forge/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export const enabledBlocks = [
'zemantic-ai',
'cal-com',
'chat-node',
'qrcode',
] as const
2 changes: 2 additions & 0 deletions packages/forge/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Do not edit this file manually
import { qrcode } from '@typebot.io/qrcode-block'
import { chatNode } from '@typebot.io/chat-node-block'
import { calCom } from '@typebot.io/cal-com-block'
import { zemanticAi } from '@typebot.io/zemantic-ai-block'
Expand All @@ -16,6 +17,7 @@ export const forgedBlocks = [
zemanticAi,
calCom,
chatNode,
qrcode,
] as BlockDefinition<(typeof enabledBlocks)[number], any, any>[]

export type ForgedBlockDefinition = (typeof forgedBlocks)[number]
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/schemas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@typebot.io/openai-block": "workspace:*",
"@typebot.io/zemantic-ai-block": "workspace:*",
"@typebot.io/cal-com-block": "workspace:*",
"@typebot.io/chat-node-block": "workspace:*"
"@typebot.io/chat-node-block": "workspace:*",
"@typebot.io/qrcode-block": "workspace:*"
}
}
29 changes: 29 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e3bdd33

Please sign in to comment.