-
Notifications
You must be signed in to change notification settings - Fork 116
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
Adding JSDoc to Paste Components #3902
base: main
Are you sure you want to change the base?
Changes from all commits
d4337be
9f75005
02b50e3
9197240
da43c60
917e9b3
b24f17b
2cab9ad
18b9a4e
9e98392
49db720
ba8d286
fd40224
d381439
597c200
05648d3
c8fc1c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import type { SpringValue } from "@react-spring/web"; | ||
import { useTransition } from "@twilio-paste/animation-library"; | ||
import { Box, safelySpreadBoxProps } from "@twilio-paste/box"; | ||
import type { BoxProps } from "@twilio-paste/box"; | ||
import { Box, safelySpreadBoxProps } from "@twilio-paste/box"; | ||
import { ModalDialogOverlay } from "@twilio-paste/modal"; | ||
import type { HTMLPasteProps } from "@twilio-paste/types"; | ||
import { useUID } from "@twilio-paste/uid-library"; | ||
|
@@ -11,8 +12,10 @@ import { AlertDialogContent } from "./AlertDialogContent"; | |
import { AlertDialogFooter } from "./AlertDialogFooter"; | ||
import { AlertDialogHeader } from "./AlertDialogHeader"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const getAnimationStates = (): any => ({ | ||
/** | ||
* Animation states for the Alert Dialog. | ||
*/ | ||
const AnimationStates = { | ||
Comment on lines
+15
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we were attempting to avoid using the ReactSpring types here. I replaced the function with a hard coded object so that we weren't creating new objects each time this component ran. Further down in the component I converted from the SpringValue type to the native type so we don't have to use |
||
from: { opacity: 0, transform: `scale(0.675)` }, | ||
enter: { opacity: 1, transform: `scale(1)` }, | ||
leave: { opacity: 0, transform: `scale(0.675)` }, | ||
|
@@ -22,7 +25,7 @@ const getAnimationStates = (): any => ({ | |
tension: 370, | ||
friction: 26, | ||
}, | ||
}); | ||
}; | ||
|
||
export interface AlertDialogProps extends HTMLPasteProps<"div"> { | ||
children: NonNullable<React.ReactNode>; | ||
|
@@ -92,6 +95,35 @@ export interface AlertDialogProps extends HTMLPasteProps<"div"> { | |
element?: BoxProps["element"]; | ||
} | ||
|
||
interface NormalizeStylesArg { | ||
opacity: SpringValue<number>; | ||
transform: SpringValue<string>; | ||
} | ||
|
||
interface NormalizeStylesReturn { | ||
opacity: number; | ||
transform: string; | ||
} | ||
|
||
/** | ||
* Normalize ReactSpring styles to be used in the AlertDialog. | ||
* | ||
* @param {NormalizeStylesArg} styles - ReactSpring styles | ||
* @returns {NormalizeStylesReturn} - Normalized styles | ||
*/ | ||
const normalizeStyles = (styles: NormalizeStylesArg): NormalizeStylesReturn => { | ||
return { | ||
...styles, | ||
opacity: styles.opacity.get(), | ||
transform: styles.transform.get(), | ||
}; | ||
}; | ||
|
||
/** | ||
* An Alert Dialog is a page overlay that displays critical information, blocks interaction with the page, and only closes after an action is performed. | ||
* | ||
* @link [Alert Dialog](https://paste.twilio.design/components/alert-dialog) | ||
*/ | ||
export const AlertDialog = React.forwardRef<HTMLDivElement, AlertDialogProps>( | ||
( | ||
{ | ||
|
@@ -109,48 +141,49 @@ export const AlertDialog = React.forwardRef<HTMLDivElement, AlertDialogProps>( | |
}, | ||
ref, | ||
) => { | ||
const transitions = useTransition(isOpen, getAnimationStates()); | ||
const transitions = useTransition(isOpen, AnimationStates); | ||
const headingID = useUID(); | ||
const bodyID = useUID(); | ||
|
||
return ( | ||
<> | ||
{transitions( | ||
Comment on lines
-116
to
-118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't need a fragment wrapping this so I removed some of the code wrapping this. |
||
(styles, item) => | ||
item && ( | ||
<ModalDialogOverlay isOpen={isOpen} style={{ opacity: styles.opacity }}> | ||
<Box | ||
// @ts-expect-error Render overlay as box for customization | ||
as={AlertDialogContent} | ||
{...safelySpreadBoxProps(props)} | ||
aria-labelledby={headingID} | ||
aria-describedby={bodyID} | ||
element={element} | ||
ref={ref} | ||
role="alertdialog" | ||
style={styles} | ||
> | ||
<AlertDialogHeader headingID={headingID} element={`${element}_HEADER`}> | ||
{heading} | ||
</AlertDialogHeader> | ||
<AlertDialogBody bodyID={bodyID} element={`${element}_BODY`}> | ||
{children} | ||
</AlertDialogBody> | ||
<AlertDialogFooter | ||
destructive={destructive} | ||
element={`${element}_FOOTER`} | ||
onDismiss={onDismiss} | ||
onDismissLabel={onDismissLabel} | ||
onConfirm={onConfirm} | ||
onConfirmLabel={onConfirmLabel} | ||
onConfirmDisabled={onConfirmDisabled} | ||
/> | ||
</Box> | ||
</ModalDialogOverlay> | ||
), | ||
)} | ||
</> | ||
); | ||
return transitions((rawStyles, item) => { | ||
if (!item) { | ||
return null; | ||
} | ||
// Normalizing ReactSpring styles. | ||
const styles = normalizeStyles(rawStyles); | ||
|
||
return ( | ||
<ModalDialogOverlay isOpen={isOpen} style={{ opacity: styles.opacity }}> | ||
<Box | ||
// @ts-expect-error Render overlay as box for customization | ||
as={AlertDialogContent} | ||
{...safelySpreadBoxProps(props)} | ||
aria-labelledby={headingID} | ||
aria-describedby={bodyID} | ||
element={element} | ||
ref={ref} | ||
role="alertdialog" | ||
style={styles} | ||
> | ||
<AlertDialogHeader headingID={headingID} element={`${element}_HEADER`}> | ||
{heading} | ||
</AlertDialogHeader> | ||
<AlertDialogBody bodyID={bodyID} element={`${element}_BODY`}> | ||
{children} | ||
</AlertDialogBody> | ||
<AlertDialogFooter | ||
destructive={destructive} | ||
element={`${element}_FOOTER`} | ||
onDismiss={onDismiss} | ||
onDismissLabel={onDismissLabel} | ||
onConfirm={onConfirm} | ||
onConfirmLabel={onConfirmLabel} | ||
onConfirmDisabled={onConfirmDisabled} | ||
/> | ||
</Box> | ||
</ModalDialogOverlay> | ||
); | ||
}); | ||
}, | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,25 @@ import type { HTMLPasteProps } from "@twilio-paste/types"; | |
import * as React from "react"; | ||
|
||
export interface AlertDialogFooterProps extends HTMLPasteProps<"div">, Pick<BoxProps, "element"> { | ||
/** Determines if the Alert Dialog is destructive. _Only changes the button color of confirm button._ */ | ||
destructive?: boolean; | ||
/** Function to run on confirmation of the Alert Dialog. */ | ||
onConfirm: () => void; | ||
/** Text of the confirm button. */ | ||
onConfirmLabel: string; | ||
/** Function to run on dismiss of the Alert Dialog. */ | ||
onDismiss: () => void; | ||
/** Text of the dismiss button. */ | ||
onDismissLabel: string; | ||
/** Property to disable the confirm button. _Has no effect if destructive is not true._ */ | ||
onConfirmDisabled?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made this comment in the discussions, but I think we should rename this internal components property to isConfirmDisabled to better communicate that it is a boolean. I would not make this change as part of this PR. |
||
} | ||
|
||
/** | ||
* Alert Dialog footer component for the AlertDialog component. | ||
* | ||
* @private | ||
*/ | ||
export const AlertDialogFooter = React.forwardRef<HTMLDivElement, AlertDialogFooterProps>( | ||
( | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review this file carefully to ensure no regressions were introduced please.