Skip to content

Commit

Permalink
fix: modal inner scroll (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertfolch-redeemeum committed May 22, 2024
1 parent 469b3df commit 7259677
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 43 deletions.
4 changes: 2 additions & 2 deletions packages/react-kit/src/components/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Root = styled.div`
left: 0;
right: 0;
z-index: ${zIndex.Modal};
max-height: inherit;
`;

const RootBG = styled.div`
Expand Down Expand Up @@ -90,8 +91,7 @@ const Wrapper = styled.div<{
}>`
display: flex;
flex-direction: column;
max-height: 96vh;
overflow: auto;
max-height: inherit;
position: relative;
z-index: ${zIndex.Modal};
color: ${({ $themeVal }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { ReactNode, useCallback } from "react";
import { PurchaseOverviewView } from "../common/StepsOverview/PurchaseOverviewView";
import NonModal from "../../nonModal/NonModal";
import { BosonLogo } from "../common/BosonLogo";
import { theme } from "../../../../theme";
import React from "react";
import { CSSProperties } from "styled-components";
import { theme } from "../../../../theme";
import { MarginContainer } from "../../../widgets/MarginContainer";
import NonModal from "../../nonModal/NonModal";
import { PurchaseOverviewView } from "../common/StepsOverview/PurchaseOverviewView";
const colors = theme.colors.light;

export type PurchaseOverviewProps = {
Expand All @@ -17,18 +17,8 @@ export const PurchaseOverview: React.FC<PurchaseOverviewProps> = ({
hideModal,
modalMargin
}) => {
const Wrapper = useCallback(
({ children }: { children: ReactNode }) => {
return lookAndFeel === "regular" ? (
<>{children}</>
) : (
<div style={{ margin: modalMargin }}>{children}</div>
);
},
[lookAndFeel, modalMargin]
);
return (
<Wrapper>
<MarginContainer lookAndFeel={lookAndFeel} modalMargin={modalMargin}>
<NonModal
hideModal={hideModal}
footerComponent={null}
Expand All @@ -40,6 +30,6 @@ export const PurchaseOverview: React.FC<PurchaseOverviewProps> = ({
>
<PurchaseOverviewView />
</NonModal>
</Wrapper>
</MarginContainer>
);
};
4 changes: 2 additions & 2 deletions packages/react-kit/src/components/modal/nonModal/NonModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Root = styled.div`
left: 0;
right: 0;
z-index: ${zIndex.Modal};
max-height: inherit;
`;

const RootBG = styled.div`
Expand Down Expand Up @@ -93,8 +94,7 @@ const Wrapper = styled.div<{
}>`
display: flex;
flex-direction: column;
max-height: 96vh;
overflow: auto;
max-height: inherit;
position: relative;
z-index: ${zIndex.Modal};
color: ${({ $themeVal }) => {
Expand Down
50 changes: 50 additions & 0 deletions packages/react-kit/src/components/widgets/MarginContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { ReactNode, useLayoutEffect, useRef, useState } from "react";
import styled, { CSSProperties, css } from "styled-components";

const StyledContainer = styled.div<{
$margin: CSSProperties["margin"];
$marginVertical: string;
}>`
${({ $margin, $marginVertical }) => css`
margin: ${$margin};
max-height: calc(100vh - ${$marginVertical});
overflow: hidden;
> * {
max-height: inherit;
}
`}
`;
export type MarginContainerProps = {
children: ReactNode;
lookAndFeel: "regular" | "modal";
modalMargin?: CSSProperties["margin"];
};
export function MarginContainer({
lookAndFeel,
modalMargin,
children
}: MarginContainerProps) {
const containerRef = useRef<HTMLDivElement>(null);
const [marginVertical, setMarginVertical] = useState("");

useLayoutEffect(() => {
if (containerRef.current) {
const { marginTop, marginBottom } = window.getComputedStyle(
containerRef.current
);
setMarginVertical(`(${marginTop} + ${marginBottom})`);
}
}, [containerRef, modalMargin]);
return lookAndFeel === "regular" ? (
<>{children}</>
) : (
<StyledContainer
$margin={modalMargin}
data-margin
ref={containerRef}
$marginVertical={marginVertical}
>
{children}
</StyledContainer>
);
}
25 changes: 7 additions & 18 deletions packages/react-kit/src/components/widgets/commit/CommitWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { ComponentType, ReactNode, useCallback } from "react";
import React, { ComponentType } from "react";
import { CSSProperties } from "styled-components";
import { ButtonProps } from "../../buttons/Button";
import { CommitNonModalProps } from "../../modal/components/Commit/CommitNonModal";
import GlobalStyle from "../../styles/GlobalStyle";
import { MarginContainer } from "../MarginContainer";
import { CommitModalWithOffer } from "./CommitModalWithOffer";
import {
CommitWidgetProviders,
CommitWidgetProvidersProps
} from "./CommitWidgetProviders";
import GlobalStyle from "../../styles/GlobalStyle";
import { CSSProperties } from "styled-components";

type CommitProps = {
buttonProps?: Omit<ButtonProps, "onClick">;
Expand All @@ -34,26 +35,14 @@ type CommitProps = {
};
export type CommitWidgetProps = CommitProps &
Omit<CommitWidgetProvidersProps, "withReduxProvider" | "provider">;
export function CommitWidget(props: CommitWidgetProps) {
const Container = useCallback(
({ children }: { children: ReactNode }) => {
return props.lookAndFeel === "regular" ? (
<>{children}</>
) : (
<div style={{ margin: props.modalMargin }}>{children}</div>
);
},
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
[props.lookAndFeel, props.modalMargin]
);

export function CommitWidget(props: CommitWidgetProps) {
return (
<Container>
<MarginContainer {...props}>
<CommitWidgetProviders {...props} withReduxProvider>
<GlobalStyle />
<CommitModalWithOffer {...props} hideModal={props.closeWidgetClick} />
</CommitWidgetProviders>
</Container>
</MarginContainer>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import {
RedemptionWidgetProvidersProps
} from "./RedemptionWidgetProviders";
import { CSSProperties } from "styled-components";
import { MarginContainer } from "../MarginContainer";

type RedemptionProps = {
buttonProps?: Omit<ButtonProps, "onClick">;
trigger?: ComponentType<{ onClick: () => unknown }> | undefined;
} & Omit<RedeemNonModalProps, "exchange" | "hideModal" | "parentOrigin"> & {
exchangeId?: string;
closeWidgetClick?: () => void;
lookAndFeel: "regular" | "modal";
modalMargin?: CSSProperties["margin"];
};

Expand All @@ -30,7 +32,7 @@ export function RedemptionWidget(props: RedemptionWidgetProps) {
? props.signatures
: undefined;
return (
<div style={{ margin: props.modalMargin || "0" }}>
<MarginContainer {...props}>
<RedemptionWidgetProviders {...props}>
<RedeemModalWithExchange
{...props}
Expand All @@ -40,6 +42,6 @@ export function RedemptionWidget(props: RedemptionWidgetProps) {
hideModal={props.closeWidgetClick}
/>
</RedemptionWidgetProviders>
</div>
</MarginContainer>
);
}
4 changes: 2 additions & 2 deletions packages/react-kit/src/stories/widgets/Commit.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Commit.args = {
defaultSelectedOfferId: "",
disableVariationsSelects: false,
bundleUuid: "",
productUuid: "086b32-3fcd-00d1-0624-67513e85415c", // with size variations
sellerId: "138",
productUuid: "f4bb0f8-2f2c-d151-2801-0d3c6250461", // with size variations
sellerId: "4",
metaTx: {
apiKey: process.env.STORYBOOK_DATA_META_TX_API_KEY as string,
apiIds: process.env.STORYBOOK_DATA_META_TX_API_IDS as string
Expand Down

0 comments on commit 7259677

Please sign in to comment.