-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ModalFooter): allow tooltip for the modal footer's buttons (#2754)
- Loading branch information
1 parent
d69763f
commit 9f45266
Showing
6 changed files
with
104 additions
and
16 deletions.
There are no files selected for viewing
9 changes: 4 additions & 5 deletions
9
packages/core/src/components/Modal/footers/ModalFooter/ModalFooter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/core/src/components/Modal/footers/ModalFooterBase/ModalFooterBase.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/core/src/components/Modal/footers/utils/__tests__/getPropsForButton.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { getPropsForButton } from "../getPropsForButton"; | ||
import cx from "classnames"; | ||
|
||
describe("getPropsForButton", () => { | ||
it("should return undefined when button is undefined", () => { | ||
expect(getPropsForButton(undefined, "my-button-class")).toBeUndefined(); | ||
}); | ||
|
||
it("should apply buttonClassName to className when tooltipProps are not present", () => { | ||
const result = getPropsForButton({ className: "existing-class", text: "Click Me" }, "my-button-class"); | ||
expect(result).toEqual({ | ||
text: "Click Me", | ||
className: cx("existing-class", "my-button-class"), | ||
tooltipProps: undefined | ||
}); | ||
}); | ||
|
||
it("should apply buttonClassName to tooltipProps.referenceWrapperClassName when tooltipProps exist", () => { | ||
const result = getPropsForButton( | ||
{ text: "Click Me", tooltipProps: { content: "Hello", referenceWrapperClassName: "tooltip-class" } }, | ||
"my-button-class" | ||
); | ||
expect(result).toEqual({ | ||
text: "Click Me", | ||
className: undefined, | ||
tooltipProps: { content: "Hello", referenceWrapperClassName: cx("tooltip-class", "my-button-class") } | ||
}); | ||
}); | ||
|
||
it("should keep className unchanged if tooltipProps exist", () => { | ||
const result = getPropsForButton( | ||
{ className: "existing-class", text: "Click Me", tooltipProps: { content: "Hello" } }, | ||
"my-button-class" | ||
); | ||
expect(result).toEqual({ | ||
text: "Click Me", | ||
className: "existing-class", | ||
tooltipProps: { content: "Hello", referenceWrapperClassName: "my-button-class" } | ||
}); | ||
}); | ||
|
||
it("should attach the button className to button itself and return undefined tooltipProps if tooltip content is empty", () => { | ||
const result = getPropsForButton( | ||
{ | ||
className: "existing-class", | ||
text: "Click Me", | ||
tooltipProps: { referenceWrapperClassName: "original-tooltip-class", content: "" } | ||
}, | ||
"my-button-class" | ||
); | ||
expect(result).toEqual({ | ||
text: "Click Me", | ||
className: cx("existing-class", "my-button-class"), | ||
tooltipProps: undefined | ||
}); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/core/src/components/Modal/footers/utils/getPropsForButton.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ModalFooterActionProps } from "../ModalFooterBase/ModalFooterBase.types"; | ||
import cx from "classnames"; | ||
|
||
export function getPropsForButton(button?: ModalFooterActionProps, buttonClassName?: string) { | ||
if (!button) return undefined; | ||
const { tooltipProps, className, ...rest } = button; | ||
return { | ||
...rest, | ||
className: tooltipProps?.content ? className : cx(className, buttonClassName), | ||
tooltipProps: tooltipProps?.content | ||
? { ...tooltipProps, referenceWrapperClassName: cx(tooltipProps.referenceWrapperClassName, buttonClassName) } | ||
: undefined | ||
}; | ||
} |