Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/components/experimental/Backdrop/Backdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@ import { ModalOverlayProps, ModalOverlay } from 'react-aria-components';
import { getSemanticHslValue } from '../../../essentials/experimental';
import { Elevation } from '../../../essentials';

type BackdropProps = ModalOverlayProps;
interface BackdropProps extends ModalOverlayProps {
isBackdropVisible?: boolean;
}

const Backdrop = styled(ModalOverlay)`
const Backdrop = styled(ModalOverlay)<{ isBackdropVisible?: boolean }>`
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: var(--visual-viewport-height);
background: hsla(${getSemanticHslValue('on-surface')}, 60%);
background: ${props =>
props.isBackdropVisible !== false ? `hsla(${getSemanticHslValue('on-surface')}, 60%)` : 'transparent'};
display: flex;
align-items: center;
justify-content: center;
z-index: ${Elevation.DIMMING};

${props =>
props.isBackdropVisible === false &&
`
pointer-events: none;

& > * {
pointer-events: auto;
}
`}

&[data-entering] {
animation: backdrop-fade 200ms;
}
Expand Down
8 changes: 8 additions & 0 deletions src/components/experimental/Dialog/Dialog.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,12 @@ describe('Dialog', () => {
fireEvent.click(screen.getByLabelText('Accept Terms'));
expect(handleCheckbox).toHaveBeenCalled();
});

it('correctly renders the component when isBackdropVisible is false', () => {
render(<Dialog {...defaultProps} isBackdropVisible={false} />);

expect(screen.getByText('Test Headline')).toBeInTheDocument();
expect(screen.getByText('Test Subtitle')).toBeInTheDocument();
expect(screen.getByRole('dialog')).toBeInTheDocument();
});
});
4 changes: 3 additions & 1 deletion src/components/experimental/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface DialogProps extends Omit<BackdropProps, 'isDismissable' | 'isKeyboardD
dismissButton?: ReactNode;
actionButton: ReactNode;
body?: ReactNode;
isBackdropVisible?: boolean;
}

const Dialog = ({
Expand All @@ -56,9 +57,10 @@ const Dialog = ({
dismissButton,
actionButton,
body,
isBackdropVisible = true,
...props
}: DialogProps): ReactElement => (
<Backdrop {...props} isDismissable={false} isKeyboardDismissDisabled>
<Backdrop {...props} isDismissable={false} isKeyboardDismissDisabled isBackdropVisible={isBackdropVisible}>
<StyledModal role={role}>
<Card>
<HeadlineText slot="title">{headline}</HeadlineText>
Expand Down
41 changes: 41 additions & 0 deletions src/components/experimental/Dialog/docs/Dialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const meta: Meta = {
component: Dialog,
parameters: {
layout: 'centered'
},
argTypes: {
isBackdropVisible: {
control: 'boolean',
description: 'Whether to show the backdrop behind the dialog',
defaultValue: true
}
}
};

Expand Down Expand Up @@ -93,6 +100,40 @@ export const Alert: Story = {
}
};

export const WithInvisibleBackdrop: Story = {
render: () => {
const [isOpen, setIsOpen] = useState(false);

return (
<>
<Button onPress={() => setIsOpen(true)}>Open dialog without backdrop</Button>
<Dialog
isOpen={isOpen}
onOpenChange={setIsOpen}
isBackdropVisible={false}
headline="No Backdrop Dialog"
subtitle="This dialog has no visible backdrop"
dismissButton={
<Button emphasis="secondary" onPress={() => setIsOpen(false)}>
Cancel
</Button>
}
actionButton={
<Button
onPress={() => {
action('Action')();
setIsOpen(false);
}}
>
Confirm
</Button>
}
/>
</>
);
}
};

export const WithCheckboxesAsBody: Story = {
render: () => {
const [isOpen, setIsOpen] = useState(false);
Expand Down