Skip to content

Commit

Permalink
Merge pull request #148 from bosonprotocol/add-context-prop-commit-bu…
Browse files Browse the repository at this point in the history
…tton

feat: add context prop to support popup version
  • Loading branch information
albertfolch-redeemeum committed May 9, 2024
2 parents 677a4ed + c4ff713 commit facf028
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions public/scripts/commit-button-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h3>Commit button example</h3>
configId: "testing-80002-0",
productUuid: "086b32-3fcd-00d1-0624-67513e85415c",
sellerId: "138",
context: "iframe",
modalMargin: "2%",
lookAndFeel: "modal",
disabled,
Expand Down
23 changes: 20 additions & 3 deletions src/components/widgets/commitButton/CommitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const yupStringOrNumber = yup
export function CommitButton() {
const ref = useRef<ElementRef<"div">>(null);
const [props, setProps] = useState(window.xprops ?? {});
const { renderToSelector, buttonStyle, ...commitWidgetProps } = props;
const { renderToSelector, buttonStyle, context, ...commitWidgetProps } =
props;
useEffect(() => {
if ("xprops" in window && typeof window.xprops.onProps === "function") {
window.xprops.onProps((newProps: typeof props) => {
Expand Down Expand Up @@ -77,6 +78,18 @@ export function CommitButton() {
}
return {} as typeof buttonStyleValidated;
}, [buttonStyle]);
const validatedContext = useMemo(() => {
if (!context) {
return "iframe";
}

if (yup.mixed().oneOf(["iframe", "popup"]).isValidSync(context)) {
return context;
}
throw new Error(
`"context" must be either "iframe" or "popup", "${context}" given`
);
}, [context]);
return (
<>
<GlobalStyle />
Expand All @@ -91,13 +104,17 @@ export function CommitButton() {
CommitWidgetModal({ ...commitWidgetProps, modalMargin }).renderTo(
window.parent,
renderToSelector || "body",
"iframe"
validatedContext
);
}}
onTaglineClick={() => {
PurchaseOverviewModal({
modalMargin
}).renderTo(window.parent, renderToSelector || "body", "iframe");
}).renderTo(
window.parent,
renderToSelector || "body",
validatedContext
);
}}
/>
</>
Expand Down

0 comments on commit facf028

Please sign in to comment.