Skip to content
New issue

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

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

Already on GitHub? # to your account

[PLAY-203] Full-height Variant for Dialog #2092

Merged
merged 7 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
33 changes: 32 additions & 1 deletion playbook/app/pb_kits/playbook/pb_dialog/_dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
$status_size: 375px;
$medium: 500px;
$large: 800px;
$xlarge: 1150px;
$animation-duration: 0.2s;
$z-index: 100;
$opacity_visible: 1;
Expand All @@ -71,14 +72,15 @@
background-color: $white;
box-shadow: $shadow_deepest;
border: 0;
border-radius: 0;
max-height: calc(100vh - #{$gutter * 2});
max-width: calc(100vw - #{$gutter * 2});
overflow: auto;
animation-name: modalFadeIn;
animation-duration: $animation-duration;
outline: none;
animation-timing-function: $easeInOutQuint;

&[class*="_status_size"] {
width: $status_size;
}
Expand Down Expand Up @@ -135,5 +137,34 @@
animation-duration: $animation-duration;
opacity: $opacity_hidden;
}
&[class*="full_height"] {

&[class*="_left"]{
justify-content: flex-start;
}

&[class*="_center"]{
justify-content: center;
}

&[class*="_right"]{
justify-content: flex-end;
}

.pb_dialog {
height: 100%;
max-height: 100%;
max-width: none;
&[class*="_sm"] {
width: $medium;
}
&[class*="_md"] {
width: $large;
}
&[class*="_lg"] {
width: $xlarge;
}
}
}
}
}
14 changes: 12 additions & 2 deletions playbook/app/pb_kits/playbook/pb_dialog/_dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ type DialogProps = {
confirmButton?: string;
data?: object;
id?: string;
fullHeight?: boolean;
loading?: boolean;
onCancel?: () => void;
onChange?: () => void;
onClose?: () => void;
onConfirm?: () => void;
opened: boolean;
portalClassName?: string;
placement?: "left" | "center" | "right";
shouldCloseOnOverlayClick: boolean;
size?: "sm" | "md" | "lg" | "status_size" | "content";
size?: "sm" | "md" | "lg" | "xl" | "status_size" | "content";
status?: "info" | "caution" | "delete" | "error" | "success";
text?: string;
title?: string;
Expand All @@ -53,10 +55,12 @@ const Dialog = (props: DialogProps) => {
size = "md",
children,
loading = false,
fullHeight = false,
opened,
onCancel = () => {},
onConfirm = () => {},
onClose = () => {},
placement = "center",
portalClassName,
shouldCloseOnOverlayClick = true,
status,
Expand All @@ -72,8 +76,14 @@ const Dialog = (props: DialogProps) => {
beforeClose: "pb_dialog_before_close",
};

const fullHeightClassNames = () => {
if(!fullHeight) return null
if(size === "xl") return `full_height_center`
return `full_height_${placement}`
}

const overlayClassNames = {
base: "pb_dialog_overlay",
base: `pb_dialog_overlay ${fullHeight !== null && fullHeightClassNames() }`,
afterOpen: "pb_dialog_overlay_after_open",
beforeClose: "pb_dialog_overlay_before_close",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import SectionSeparator from '../../pb_section_separator/_section_separator'


type DialogFooterProps = {
aria?: object,
aria?: {[key: string]: string},
children: React.ReactChild[] | React.ReactChild | string,
className?: string,
data?: object,
data?: {[key: string]: string},
id?: string,
padding?: string,
paddingBottom?: string,
Expand All @@ -39,7 +39,7 @@ const DialogFooter = (props: DialogFooterProps) => {
return (
<>
{separator &&
<SectionSeparator aria={{dd: 'ff'}} className="dd" data={{dd: 'ff'}} id="d" text="ss"/>
<SectionSeparator />
}
<Flex
className={classnames(footerCSS, footerSpacing, className)}
Expand Down
19 changes: 17 additions & 2 deletions playbook/app/pb_kits/playbook/pb_dialog/dialog.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const size="sm"
const confirmButton="Okay"
const cancelButton="Cancel Button"

function DialogTest() {
function DialogTest({ props }) {
const [isOpen, setIsOpen] = useState(false)
const close = () => setIsOpen(false)
const open = () => setIsOpen(true)
Expand All @@ -29,6 +29,7 @@ function DialogTest() {
size={size}
text={text}
title={title}
{...props}
/>
</>
);
Expand Down Expand Up @@ -71,6 +72,19 @@ test("renders the title and body text", async () => {
cleanup()
});

test("renders the full height version", async () => {

const { queryByText } = render(<DialogTest fullHeight />);

fireEvent.click(queryByText('Open Dialog'));

await waitFor(() => expect(queryByText("Header Title is the Title Prop")).toHaveTextContent(title));

await waitFor(() => expect(queryByText("Hello Body Text, Nice to meet ya.")).toHaveTextContent(text));

cleanup()
});

test("renders the buttons", async () => {

const { queryByText } = render(<DialogTest />);
Expand All @@ -82,4 +96,5 @@ test("renders the buttons", async () => {
await waitFor(() => expect(queryByText("Cancel Button")).toHaveTextContent(cancelButton));

cleanup()
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const DialogCompound = () => {
<>
<Button onClick={open}>{'Open a Complex Dialog'}</Button>
<Dialog
fullHeight
onClose={close}
opened={isOpen}
size="lg"
Expand Down
103 changes: 103 additions & 0 deletions playbook/app/pb_kits/playbook/pb_dialog/docs/_dialog_full_height.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import React, { useState } from "react";
import {
Body,
Button,
Caption,
Dialog,
Flex,
RichTextEditor,
Typeahead,
} from "../..";

const useDialog = (visible = false) => {
const [opened, setOpened] = useState(visible);
const toggle = () => setOpened(!opened);

return [opened, toggle];
};

const DialogFullHeight = () => {
const [headerSeparatorDialogOpened, toggleHeaderSeparatorDialog] =
useDialog();
const [footerSeparatorDialogOpened, toggleFooterSeparatorDialog] =
useDialog();
const [bothSeparatorsDialogOpened, toggleBothSeparatorsDialog] = useDialog();

const dialogs = [
{
size: "sm",
title: "Small Dialog",
toggle: toggleHeaderSeparatorDialog,
visible: headerSeparatorDialogOpened,
},
{
size: "md",
title: "Medium Dialog",
toggle: toggleFooterSeparatorDialog,
visible: footerSeparatorDialogOpened,
},
{
size: "lg",
title: "Large Dialog",
toggle: toggleBothSeparatorsDialog,
visible: bothSeparatorsDialogOpened,
},
];

return (
<>
<Flex wrap>
<Button id="sm"
marginRight="xl"
onClick={toggleHeaderSeparatorDialog}>
{"Small Dialog"}
</Button>
<Button marginRight="xl"
onClick={toggleFooterSeparatorDialog}>
{"Medium Dialog"}
</Button>
<Button marginRight="xl"
onClick={toggleBothSeparatorsDialog}>
{"Large Dialog"}
</Button>
</Flex>
<Flex>
{dialogs.map(({toggle, visible, placement, size, title}, index) => (
<Dialog
fullHeight
key={index}
onClose={toggle}
opened={visible}
placement={placement}
size={size}
>
<Dialog.Header>
<Body>{title}</Body>
</Dialog.Header>
<Dialog.Body>
<Caption marginBottom="xs">{"Description"}</Caption>
<RichTextEditor />
<br />
<Caption>
{
"Type in a word or term too help find tickets later. ex. training,"
}
{"phone setup, hr"}
</Caption>
<Typeahead placeholder="Tags.." />
</Dialog.Body>
<Dialog.Footer>
<Button onClick={toggle}>{"Send My Issue"}</Button>
<Button onClick={toggle}
variant="link">
{"Back"}
</Button>
</Dialog.Footer>
</Dialog>
))}
</Flex>
</>
);
};

export default DialogFullHeight;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The full height dialog can be size small, medium, and large
They may be left, center or right aligned. Except for the Xlarge dialog which should only be center aligned.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React, { useState } from "react";
import {
Body,
Button,
Caption,
Dialog,
Flex,
RichTextEditor,
Typeahead,
} from "../..";

const useDialog = (visible = false) => {
const [opened, setOpened] = useState(visible);
const toggle = () => setOpened(!opened);

return [opened, toggle];
};

const DialogFullHeightPlacement = () => {
const [headerSeparatorDialogOpened, toggleHeaderSeparatorDialog] =
useDialog();
const [footerSeparatorDialogOpened, toggleFooterSeparatorDialog] =
useDialog();
const [bothSeparatorsDialogOpened, toggleBothSeparatorsDialog] = useDialog();

const dialogs = [
{
title: "Left Dialog",
toggle: toggleHeaderSeparatorDialog,
visible: headerSeparatorDialogOpened,
placement: "left",
},
{
title: "Center Dialog",
toggle: toggleFooterSeparatorDialog,
visible: footerSeparatorDialogOpened,
},
{
title: "Right Dialog",
toggle: toggleBothSeparatorsDialog,
visible: bothSeparatorsDialogOpened,
placement: "right",
},
];

return (
<>
<Flex wrap>
<Button id="sm"
marginRight="xl"
onClick={toggleHeaderSeparatorDialog}>
{"Left Dialog"}
</Button>
<Button marginRight="xl"
onClick={toggleFooterSeparatorDialog}>
{"Center Dialog"}
</Button>
<Button marginRight="xl"
onClick={toggleBothSeparatorsDialog}>
{"Right Dialog"}
</Button>
</Flex>
<Flex>
{dialogs.map(({toggle, visible, placement, title}, index) => (
<Dialog
fullHeight
key={index}
onClose={toggle}
opened={visible}
placement={placement}
size={"md"}
>
<Dialog.Header>
<Body>{title}</Body>
</Dialog.Header>
<Dialog.Body>
<Caption marginBottom="xs">{"Description"}</Caption>
<RichTextEditor />
<br />
<Caption>
{
"Type in a word or term too help find tickets later. ex. training,"
}
{"phone setup, hr"}
</Caption>
<Typeahead placeholder="Tags.." />
</Dialog.Body>
<Dialog.Footer>
<Button onClick={toggle}>{"Send My Issue"}</Button>
<Button onClick={toggle}
variant="link">
{"Back"}
</Button>
</Dialog.Footer>
</Dialog>
))}
</Flex>
</>
);
};

export default DialogFullHeightPlacement;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The full height dialog is centered by default, but the placement can changed via `placement` prop with one of the following values: `left`, `center`, `right`.

The `large` variant will allways be centered even sending a preferred placement.

All dialogs with the `fullHeight` prop will be displayed full-width on mobile screens.
Loading