-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(LightBox): add LightBox component (#972)
- Loading branch information
Showing
23 changed files
with
314 additions
and
14 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
32 changes: 32 additions & 0 deletions
32
packages/components/src/components/LightBox/LightBox.module.scss
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,32 @@ | ||
.lightBox { | ||
background-color: var(--light-box--overlay-background-color); | ||
|
||
[role="dialog"] { | ||
outline: none; | ||
display: flex; | ||
justify-content: center; | ||
column-gap: var(--light-box--spacing); | ||
max-width: var(--light-box--max-width); | ||
max-height: var(--light-box--max-height); | ||
} | ||
|
||
.content { | ||
overflow: auto; | ||
} | ||
|
||
&.fitScreen { | ||
.content { | ||
> * { | ||
max-height: var(--light-box--max-height); | ||
} | ||
} | ||
} | ||
|
||
.actions, | ||
.actionGroup [role="group"] { | ||
display: flex; | ||
row-gap: var(--light-box--spacing); | ||
flex-direction: column; | ||
flex-shrink: 0; | ||
} | ||
} |
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,76 @@ | ||
import { | ||
flowComponent, | ||
type FlowComponentProps, | ||
} from "@/lib/componentFactory/flowComponent"; | ||
import type { PropsWithChildren } from "react"; | ||
import React from "react"; | ||
import type { PropsWithClassName } from "@/lib/types/props"; | ||
import { Overlay } from "@/components/Overlay"; | ||
import clsx from "clsx"; | ||
import type { OverlayController } 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"; | ||
|
||
export interface LightBoxProps | ||
extends PropsWithChildren, | ||
FlowComponentProps, | ||
PropsWithClassName { | ||
controller?: OverlayController; | ||
fitScreen?: boolean; | ||
} | ||
|
||
export const LightBox = flowComponent("LightBox", (props) => { | ||
const { | ||
controller, | ||
children, | ||
refProp: ignoredRef, | ||
className, | ||
fitScreen = true, | ||
...rest | ||
} = props; | ||
|
||
const rootClassName = clsx( | ||
styles.lightBox, | ||
fitScreen && styles.fitScreen, | ||
className, | ||
); | ||
|
||
const propsContext: PropsContext = { | ||
ActionGroup: { | ||
className: styles.actionGroup, | ||
Button: { variant: "soft", color: "light" }, | ||
tunnelId: "actionGroup", | ||
ignoreBreakpoint: true, | ||
}, | ||
}; | ||
|
||
return ( | ||
<Overlay | ||
overlayType="LightBox" | ||
className={rootClassName} | ||
controller={controller} | ||
{...rest} | ||
> | ||
<PropsContextProvider props={propsContext}> | ||
<TunnelProvider> | ||
<div className={styles.content}>{children}</div> | ||
<div className={styles.actions}> | ||
<Action closeOverlay="LightBox"> | ||
<Button color="light" variant="soft"> | ||
<IconClose /> | ||
</Button> | ||
</Action> | ||
<TunnelExit id="actionGroup" /> | ||
</div> | ||
</TunnelProvider> | ||
</PropsContextProvider> | ||
</Overlay> | ||
); | ||
}); | ||
|
||
export default LightBox; |
18 changes: 18 additions & 0 deletions
18
packages/components/src/components/LightBox/components/LightBoxTrigger/LightBoxTrigger.tsx
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,18 @@ | ||
import * as Aria from "react-aria-components"; | ||
import type { FC } from "react"; | ||
import React from "react"; | ||
import type { OverlayTriggerProps } from "@/components/OverlayTrigger"; | ||
import { OverlayTrigger } from "@/components/OverlayTrigger"; | ||
|
||
export const LightBoxTrigger: FC<OverlayTriggerProps> = (props) => { | ||
const { children, ...triggerProps } = props; | ||
return ( | ||
<OverlayTrigger | ||
overlayType="LightBox" | ||
{...triggerProps} | ||
component={Aria.DialogTrigger} | ||
> | ||
{children} | ||
</OverlayTrigger> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/components/src/components/LightBox/components/LightBoxTrigger/index.ts
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,4 @@ | ||
import { LightBoxTrigger } from "./LightBoxTrigger"; | ||
|
||
export * from "./LightBoxTrigger"; | ||
export default LightBoxTrigger; |
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,5 @@ | ||
import { LightBox } from "./LightBox"; | ||
|
||
export * from "./components/LightBoxTrigger"; | ||
export { type LightBoxProps, LightBox } from "./LightBox"; | ||
export default LightBox; |
42 changes: 42 additions & 0 deletions
42
packages/components/src/components/LightBox/stories/Default.stories.tsx
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,42 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import React from "react"; | ||
import Button from "@/components/Button"; | ||
import { ActionGroup } from "@/components/ActionGroup"; | ||
import { LightBox } from "@/components/LightBox"; | ||
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"; | ||
|
||
const meta: Meta<typeof LightBox> = { | ||
title: "Overlays/LightBox", | ||
component: LightBox, | ||
parameters: { | ||
controls: { exclude: ["controller"] }, | ||
}, | ||
render: (props) => { | ||
return ( | ||
<LightBoxTrigger> | ||
<Button>Open LightBox</Button> | ||
<LightBox {...props}> | ||
<Image src={dummyText.imageSrc} /> | ||
<ActionGroup> | ||
<Button> | ||
<IconDownload /> | ||
</Button> | ||
<Button> | ||
<IconDelete /> | ||
</Button> | ||
</ActionGroup> | ||
</LightBox> | ||
</LightBoxTrigger> | ||
); | ||
}, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof LightBox>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const WithoutFitScreen: Story = { args: { fitScreen: false } }; |
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 was deleted.
Oops, something went wrong.
File renamed without changes.
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,4 @@ | ||
import { Overlay } from "./Overlay"; | ||
|
||
export { type OverlayProps, Overlay } from "./Overlay"; | ||
export default Overlay; |
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,9 @@ | ||
light-box: | ||
overlay-background-color: | ||
value: "{dark.color.600}" | ||
max-width: | ||
value: "calc(100dvw - {size-px.l})" | ||
max-height: | ||
value: "calc(100dvh - {size-px.l})" | ||
spacing: | ||
value: "{size-px.s}" |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
overlay: | ||
background-color: | ||
value: rgba(0, 0, 0, 0.3) | ||
value: "{dark.color.200}" |
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
26 changes: 26 additions & 0 deletions
26
packages/docs/src/content/03-components/overlays/light-box/examples/actions.tsx
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,26 @@ | ||
import ActionGroup from "@mittwald/flow-react-components/ActionGroup"; | ||
import Button from "@mittwald/flow-react-components/Button"; | ||
import { | ||
LightBox, | ||
LightBoxTrigger, | ||
} from "@mittwald/flow-react-components/LightBox"; | ||
import { Image } from "@mittwald/flow-react-components/Image"; | ||
import { | ||
IconDelete, | ||
IconDownload, | ||
} from "@mittwald/flow-react-components/Icons"; | ||
|
||
<LightBoxTrigger> | ||
<Button>Open LightBox</Button> | ||
<LightBox> | ||
<Image src="https://mittwald.github.io/flow/assets/mittwald_logo_rgb.jpg" /> | ||
<ActionGroup> | ||
<Button> | ||
<IconDownload /> | ||
</Button> | ||
<Button> | ||
<IconDelete /> | ||
</Button> | ||
</ActionGroup> | ||
</LightBox> | ||
</LightBoxTrigger>; |
13 changes: 13 additions & 0 deletions
13
packages/docs/src/content/03-components/overlays/light-box/examples/default.tsx
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,13 @@ | ||
import Button from "@mittwald/flow-react-components/Button"; | ||
import { | ||
LightBox, | ||
LightBoxTrigger, | ||
} from "@mittwald/flow-react-components/LightBox"; | ||
import { Image } from "@mittwald/flow-react-components/Image"; | ||
|
||
<LightBoxTrigger> | ||
<Button>Open LightBox</Button> | ||
<LightBox> | ||
<Image src="https://mittwald.github.io/flow/assets/mittwald_logo_rgb.jpg" /> | ||
</LightBox> | ||
</LightBoxTrigger>; |
13 changes: 13 additions & 0 deletions
13
packages/docs/src/content/03-components/overlays/light-box/examples/fitScreenFalse.tsx
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,13 @@ | ||
import Button from "@mittwald/flow-react-components/Button"; | ||
import { | ||
LightBox, | ||
LightBoxTrigger, | ||
} from "@mittwald/flow-react-components/LightBox"; | ||
import { Image } from "@mittwald/flow-react-components/Image"; | ||
|
||
<LightBoxTrigger> | ||
<Button>Open LightBox</Button> | ||
<LightBox fitScreen={false}> | ||
<Image src="https://mittwald.github.io/flow/assets/mittwald_logo_rgb.jpg" /> | ||
</LightBox> | ||
</LightBoxTrigger>; |
Oops, something went wrong.