Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add variant="inside" for DBDrawer #3262

Merged
merged 6 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions packages/components/src/components/drawer/drawer.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export default function DBDrawer(props: DBDrawerProps) {
if (dialogContainerRef) {
dialogContainerRef.hidden = false;
}
if (props.backdrop === 'none') {
if (
props.backdrop === 'none' ||
props.variant === 'inside'
) {
ref.show();
mfranzke marked this conversation as resolved.
Show resolved Hide resolved
} else {
ref.showModal();
Expand Down Expand Up @@ -79,7 +82,8 @@ export default function DBDrawer(props: DBDrawerProps) {
state.handleClose(event);
}}
onKeyDown={(event) => state.handleClose(event)}
data-backdrop={props.backdrop}>
data-backdrop={props.backdrop}
data-variant={props.variant}>
<article
ref={dialogContainerRef}
class={cls('db-drawer-container', props.className)}
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/components/drawer/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ export type DrawerBackdropType = (typeof DrawerBackdropList)[number];
export const DrawerDirectionList = ['left', 'right', 'up', 'down'] as const;
export type DrawerDirectionType = (typeof DrawerDirectionList)[number];

export const DrawerVariantList = ['modal', 'inside'] as const;
export type DrawerVariantType = (typeof DrawerVariantList)[number];

export type DBDrawerDefaultProps = {
/**
* The backdrop attribute changes the opacity of the backdrop.
* The backdrop 'none' will use `dialog.show()` instead of `dialog.showModal()`
*/
backdrop?: DrawerBackdropType;

/**
* The direction attribute changes the position & animation of the drawer.
* E.g. "left" slides from left screen border to the right.
Expand All @@ -36,6 +38,7 @@ export type DBDrawerDefaultProps = {
* React specific to change the header of the drawer.
*/
drawerHeader?: unknown;

/**
* The open attribute opens or closes the drawer based on the state.
*/
Expand All @@ -45,6 +48,10 @@ export type DBDrawerDefaultProps = {
* The "end" depends on which direction you use.
*/
rounded?: boolean;
/**
* Set the variant modal|inside. Defaults to modal.
*/
variant?: DrawerVariantType;
};

export type DBDrawerProps = DBDrawerDefaultProps &
Expand Down
20 changes: 17 additions & 3 deletions packages/components/src/styles/dialog-init.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,38 @@ dialog {
z-index: 9996;
color: inherit;

&[data-variant],
&[data-backdrop] {
@extend %dialog-container;
}

&[data-variant="inside"] {
&:not([data-backdrop="none"]) {
&::before {
content: "";
position: fixed;
inset: 0;
}
}
}

&:not([data-backdrop="none"]) {
&::backdrop {
&::backdrop,
&::before {
background-color: $backdrop-color;
opacity: $backdrop-opacity-strong;
}

&[data-backdrop="invisible"] {
&::backdrop {
&::backdrop,
&::before {
opacity: 0;
}
}

&[data-backdrop="weak"] {
&::backdrop {
&::backdrop,
&::before {
opacity: $backdrop-opacity-weak;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
[width]="exampleProps?.width"
[spacing]="exampleProps?.spacing"
[direction]="exampleProps?.direction"
[variant]="exampleProps?.variant"
[open]="openDrawer === exampleName"
(onClose)="toggleDrawer(undefined)"
(close)="toggleDrawer(undefined)"
Expand Down
4 changes: 3 additions & 1 deletion showcases/react-showcase/src/components/drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const getDrawer = ({
setOpenDrawer,
direction,
children,
backdrop
backdrop,
variant
}: DBDrawerProps & AdditionalDrawerProperties) => (
<div>
<DBButton
Expand All @@ -34,6 +35,7 @@ const getDrawer = ({
spacing={spacing}
backdrop={backdrop}
direction={direction}
variant={variant}
open={openDrawer === id}
onClose={() => {
setOpenDrawer(undefined);
Expand Down
21 changes: 21 additions & 0 deletions showcases/shared/drawer.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,26 @@
}
}
]
},
{
"name": "Example",
"examples": [
{
"name": "(Default) As modal",
"props": {
"variant": "modal",
"open": "open",
"onClose": "toggleDrawer(false)"
}
},
{
"name": "Inside",
"props": {
"variant": "inside",
"open": "open",
"onClose": "toggleDrawer(false)"
}
}
]
}
]
1 change: 1 addition & 0 deletions showcases/vue-showcase/src/components/drawer/Drawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const toggleDrawer = (example?: string) => {
:width="exampleProps?.width"
:spacing="exampleProps?.spacing"
:direction="exampleProps?.direction"
:variant="exampleProps?.variant"
:open="openDrawer && openDrawer === exampleName"
@close="toggleDrawer(undefined)"
>
Expand Down
Loading