-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add commit button as a widget with zoid
- Loading branch information
1 parent
5f87bf5
commit e243ac2
Showing
11 changed files
with
380 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,5 +40,5 @@ | |
"typescript": {} | ||
} | ||
}, | ||
"ignorePatterns": [] | ||
"ignorePatterns": ["public/scripts/zoid/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ npm-debug.log* | |
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
.env | ||
.env | ||
public/scripts/zoid |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
|
||
<head> | ||
<script src="./zoid/zoid.js"></script> | ||
<script src="../../scripts/commit-button.js"></script> | ||
<style> | ||
html, | ||
body { | ||
height: 100vh; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<h3>Commit button example</h3> | ||
|
||
<div id="container"></div> | ||
|
||
<script> | ||
const instance = CommitButton({ | ||
configId: "testing-80001-0", | ||
productUuid: "086b32-3fcd-00d1-0624-67513e85415c", | ||
sellerId: "138", | ||
modalMargin: "2%", | ||
lookAndFeel: "modal", | ||
onGetDimensions: function (dimensions) { | ||
const { boundingClientRect } = dimensions; | ||
document.querySelector( | ||
"#container" | ||
).style.height = `${boundingClientRect.height}px`; | ||
document.querySelector( | ||
"#container" | ||
).style.width = `${boundingClientRect.width}px`; | ||
} | ||
}); | ||
|
||
instance.render("#container"); | ||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/* eslint-disable no-undef */ | ||
|
||
var CommitButton = zoid.create({ | ||
tag: "boson-commit-button", | ||
url: ({ props }) => { | ||
return !props.configId || props.configId.startsWith("production") | ||
? "https://widgets-test.on.fleek.co/#/commit-button" | ||
: "http://localhost:3006/#/commit-button"; | ||
}, | ||
dimensions: { width: "100%", height: "100%" } | ||
}); | ||
const EVENT = { | ||
RENDER: "zoid-render", | ||
RENDERED: "zoid-rendered", | ||
PRERENDER: "zoid-prerender", | ||
PRERENDERED: "zoid-prerendered", | ||
DISPLAY: "zoid-display", | ||
ERROR: "zoid-error", | ||
CLOSE: "zoid-close", | ||
DESTROY: "zoid-destroy", | ||
PROPS: "zoid-props", | ||
RESIZE: "zoid-resize", | ||
FOCUS: "zoid-focus" | ||
}; | ||
const CLASS = { | ||
VISIBLE: "zoid-visible", | ||
INVISIBLE: "zoid-invisible" | ||
}; | ||
var Modal = zoid.create({ | ||
tag: "boson-commit-modal", | ||
url: "http://localhost:3006/#/commit?props=1", | ||
dimensions: { width: "100%", height: "100%" }, | ||
containerTemplate: function containerTemplate({ | ||
uid, | ||
frame, | ||
prerenderFrame, | ||
doc, | ||
props, | ||
event, | ||
dimensions | ||
}) { | ||
const { width, height } = dimensions; | ||
|
||
if (!frame || !prerenderFrame) { | ||
return; | ||
} | ||
|
||
const div = doc.createElement("div"); | ||
div.setAttribute("id", uid); | ||
const style = doc.createElement("style"); | ||
if (props.cspNonce) { | ||
style.setAttribute("nonce", props.cspNonce); | ||
} | ||
|
||
style.appendChild( | ||
doc.createTextNode(` | ||
#${uid} { | ||
display: inline-block; | ||
// position: relative; | ||
width: ${width}; | ||
height: ${height}; | ||
} | ||
#${uid} > iframe { | ||
display: inline-block; | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
top: 0; | ||
left: 0; | ||
transition: opacity .2s ease-in-out; | ||
} | ||
#${uid} > iframe.${CLASS.INVISIBLE} { | ||
opacity: 0; | ||
} | ||
#${uid} > iframe.${CLASS.VISIBLE} { | ||
opacity: 1; | ||
} | ||
`) | ||
); | ||
|
||
div.appendChild(prerenderFrame); | ||
div.appendChild(frame); | ||
div.appendChild(style); | ||
|
||
prerenderFrame.classList.add(CLASS.VISIBLE); | ||
frame.classList.add(CLASS.INVISIBLE); | ||
|
||
event.on(EVENT.RENDERED, () => { | ||
prerenderFrame.classList.remove(CLASS.VISIBLE); | ||
prerenderFrame.classList.add(CLASS.INVISIBLE); | ||
|
||
frame.classList.remove(CLASS.INVISIBLE); | ||
frame.classList.add(CLASS.VISIBLE); | ||
|
||
setTimeout(() => { | ||
destroyElement(prerenderFrame); | ||
}, 1); | ||
}); | ||
|
||
event.on(EVENT.RESIZE, ({ width: newWidth, height: newHeight }) => { | ||
if (typeof newWidth === "number") { | ||
div.style.width = toCSS(newWidth); | ||
} | ||
|
||
if (typeof newHeight === "number") { | ||
div.style.height = toCSS(newHeight); | ||
} | ||
}); | ||
|
||
return div; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.