Skip to content

Commit

Permalink
add conditional render + add fixed prop to Scrim
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeac123 committed Feb 9, 2024
1 parent 23d490f commit 858970b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
54 changes: 28 additions & 26 deletions packages/lab/src/drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,34 @@ export const Drawer = forwardRef<HTMLDivElement, DrawerProps>(function Drawer(
}
}, [open, showComponent, setShowComponent]);

if (!showComponent) return null;

return (
<Scrim>
<FloatingComponent
open={open}
ref={handleRef}
aria-modal="true"
aria-labelledby={`${id}-header`}
focusManagerProps={{
context: context,
}}
className={clsx(
withBaseName(),
withBaseName(position),
{
[withBaseName("enterAnimation")]: open,
[withBaseName("exitAnimation")]: !open,
[withBaseName(variant)]: variant,
},
className
)}
{...getDrawerProps(rest)}
>
{children}
</FloatingComponent>
</Scrim>
<>
{showComponent && (
<Scrim fixed>
<FloatingComponent
open={open}
ref={handleRef}
aria-modal="true"
aria-labelledby={`${id}-header`}
focusManagerProps={{
context: context,
}}
className={clsx(
withBaseName(),
withBaseName(position),
{
[withBaseName("enterAnimation")]: open,
[withBaseName("exitAnimation")]: !open,
[withBaseName(variant)]: variant,
},
className
)}
{...getDrawerProps(rest)}
>
{children}
</FloatingComponent>
</Scrim>
)}
</>
);
});
4 changes: 2 additions & 2 deletions site/src/examples/drawer/Default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Default = (): ReactElement => {
<Drawer
open={openPrimary}
onOpenChange={(newOpen) => setOpenPrimary(newOpen)}
id="primary"
id="primary-drawer"
style={{ width: 200 }}
>
<DrawerCloseButton onClick={() => setOpenPrimary(false)} />
Expand All @@ -25,7 +25,7 @@ export const Default = (): ReactElement => {
open={openSecondary}
onOpenChange={(newOpen) => setOpenSecondary(newOpen)}
variant="secondary"
id="secondary"
id="secondary-drawer"
style={{ width: 200 }}
>
<DrawerCloseButton onClick={() => setOpenSecondary(false)} />
Expand Down
8 changes: 4 additions & 4 deletions site/src/examples/drawer/Position.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Position = (): ReactElement => {
<Drawer
open={openLeft}
onOpenChange={(newOpen) => setOpenLeft(newOpen)}
id="left"
id="left-drawer"
style={{ width: 200 }}
>
<DrawerCloseButton onClick={() => setOpenLeft(false)} />
Expand All @@ -25,7 +25,7 @@ export const Position = (): ReactElement => {
open={openRight}
onOpenChange={(newOpen) => setOpenRight(newOpen)}
position="right"
id="right"
id="right-drawer"
style={{ width: 200 }}
>
<DrawerCloseButton onClick={() => setOpenRight(false)} />
Expand All @@ -35,7 +35,7 @@ export const Position = (): ReactElement => {
open={openTop}
onOpenChange={(newOpen) => setOpenTop(newOpen)}
position="top"
id="top"
id="top-drawer"
style={{ height: 200 }}
>
<DrawerCloseButton onClick={() => setOpenTop(false)} />
Expand All @@ -45,7 +45,7 @@ export const Position = (): ReactElement => {
open={openBottom}
onOpenChange={(newOpen) => setOpenBottom(newOpen)}
position="bottom"
id="bottom"
id="bottom-drawer"
style={{ height: 200 }}
>
<DrawerCloseButton onClick={() => setOpenBottom(false)} />
Expand Down

0 comments on commit 858970b

Please sign in to comment.