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
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import clsx from "clsx";
import React from "react";
import { Popover, PopoverModalContent } from "@appsmith/wds-headless";
import styles from "./styles.module.css";

import type { ModalProps } from "./types";
import clsx from "clsx";
import styles from "./styles.module.css";

export const Modal = (props: ModalProps) => {
const {
children,
dataAttributes = {},
overlayClassName,
overlayProps = {},
size = "medium",
triggerRef,
...rest
} = props;
Expand All @@ -17,7 +19,8 @@ export const Modal = (props: ModalProps) => {
// don't forget to change the transition-duration CSS as well
<Popover duration={200} modal triggerRef={triggerRef} {...rest}>
<PopoverModalContent
{...dataAttributes}
data-size={size}
{...overlayProps}
overlayClassName={clsx(styles.overlay, overlayClassName)}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
PopoverProps,
} from "@appsmith/wds-headless";
import type { ReactNode } from "react";
import type { SIZES } from "@appsmith/wds";

export interface ModalProps
extends Pick<
Expand All @@ -15,9 +16,14 @@ export interface ModalProps
| "dismissClickOutside"
>,
Pick<PopoverModalContentProps, "overlayClassName"> {
dataAttributes?: Record<string, string>;
/** size of the modal
* @default medium
*/
size?: Omit<keyof typeof SIZES, "xSmall">;
/** The children of the component. */
children: ReactNode;
/** Additional props to be passed to the overlay */
overlayProps?: Record<string, string>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the date attributes, there doesn't seem to be any point in pass anything else here, right? Maybe we should keep the prev name?

}

export interface ModalContentProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export const ModalExamples = () => {
}}
/>
<Modal
dataAttributes={{ "data-size": "large" }}
initialFocus={2}
isOpen={isLargeOpen}
setOpen={setLargeOpen}
size="large"
triggerRef={largeRef}
>
<Unstyled>
Expand Down Expand Up @@ -121,10 +121,10 @@ export const ModalExamples = () => {
</Unstyled>
</Modal>
<Modal
dataAttributes={{ "data-size": "small" }}
initialFocus={2}
isOpen={isSmallOpen}
setOpen={setSmallOpen}
size="small"
triggerRef={smallRef}
>
<Unstyled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ export const ComplexForm = () => {
Ok
</Button>
<Modal
dataAttributes={{ "data-size": "small" }}
initialFocus={2}
isOpen={isModalOpen}
setOpen={setModalOpen}
size="small"
triggerRef={submitRef}
>
<ModalContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,17 @@ class WDSModalWidget extends BaseWidget<ModalWidgetProps, WidgetState> {

return (
<Modal
dataAttributes={{
isOpen={this.state.isVisible as boolean}
onClose={this.onModalClose}
overlayProps={{
[AnvilDataAttributes.MODAL_SIZE]: this.props.size,
[AnvilDataAttributes.WIDGET_NAME]: this.props.widgetName,
[AnvilDataAttributes.IS_SELECTED_WIDGET]: this.props.isWidgetSelected
? "true"
: "false",
}}
isOpen={this.state.isVisible as boolean}
onClose={this.onModalClose}
setOpen={(val) => this.setState({ isVisible: val })}
size={this.props.size}
>
{this.state.isVisible && (
<ModalContent className={modalClassNames.trim()}>
Expand Down