Skip to content

Commit

Permalink
fix(LightBox): fix LightBox controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisa18289 committed Nov 19, 2024
1 parent 9abd015 commit f3e84af
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/components/src/components/Action/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const Action = flowComponent("Action", (props) => {
? action.confirmationModalController
: action.getOverlayController("Modal");
}),

ActionGroup: {
Button: actionButtonContext,
},
Expand Down
18 changes: 11 additions & 7 deletions packages/components/src/components/LightBox/LightBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import type { PropsWithClassName } from "@/lib/types/props";
import { Overlay } from "@/components/Overlay";
import clsx from "clsx";
import type { OverlayController } from "@/lib/controller";
import { useOverlayController } from "@/lib/controller";
import type { PropsContext } from "@/lib/propsContext";
import { PropsContextProvider } from "@/lib/propsContext";
import { Button } from "@/components/Button";
import { IconClose } from "@/components/Icon/components/icons";
import { Action } from "@/components/Action";
import styles from "./LightBox.module.scss";
import { TunnelExit, TunnelProvider } from "@mittwald/react-tunnel";

Expand All @@ -26,7 +26,7 @@ export interface LightBoxProps

export const LightBox = flowComponent("LightBox", (props) => {
const {
controller,
controller: controllerFromProps,
children,
refProp: ignoredRef,
className,
Expand All @@ -49,6 +49,12 @@ export const LightBox = flowComponent("LightBox", (props) => {
},
};

const controllerFromContext = useOverlayController("LightBox", {
reuseControllerFromContext: true,
});

const controller = controllerFromProps ?? controllerFromContext;

return (
<Overlay
overlayType="LightBox"
Expand All @@ -60,11 +66,9 @@ export const LightBox = flowComponent("LightBox", (props) => {
<TunnelProvider>
<div className={styles.content}>{children}</div>
<div className={styles.actions}>
<Action closeOverlay="LightBox">
<Button color="light" variant="soft">
<IconClose />
</Button>
</Action>
<Button color="light" variant="soft" onPress={controller?.close}>
<IconClose />
</Button>
<TunnelExit id="actionGroup" />
</div>
</TunnelProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import LightBoxTrigger from "@/components/LightBox/components/LightBoxTrigger";
import { Image } from "@/components/Image";
import { dummyText } from "@/lib/dev/dummyText";
import { IconDelete, IconDownload } from "@/components/Icon/components/icons";
import { useOverlayController } from "@/lib/controller";

const meta: Meta<typeof LightBox> = {
title: "Overlays/LightBox",
Expand Down Expand Up @@ -40,3 +41,26 @@ type Story = StoryObj<typeof LightBox>;
export const Default: Story = {};

export const WithoutFitScreen: Story = { args: { fitScreen: false } };

export const WithController: Story = {
render: (props) => {
const controller = useOverlayController("LightBox");

return (
<>
<Button onPress={controller.open}>Open LightBox</Button>
<LightBox {...props} controller={controller}>
<Image src={dummyText.imageSrc} />
<ActionGroup>
<Button>
<IconDownload />
</Button>
<Button>
<IconDelete />
</Button>
</ActionGroup>
</LightBox>
</>
);
},
};

0 comments on commit f3e84af

Please sign in to comment.