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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow custom class on Modal root div #2410

Merged
merged 2 commits into from
May 31, 2024
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
6 changes: 5 additions & 1 deletion src/components/Gallery/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@
return (
<div className={className}>
{renderImages}
<Modal onClose={() => setModalOpen((modalOpen) => !modalOpen)} open={modalOpen}>
<Modal
className='str-chat__gallery-modal'
onClose={() => setModalOpen((modalOpen) => !modalOpen)}

Check warning on line 109 in src/components/Gallery/Gallery.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Gallery/Gallery.tsx#L109

Added line #L109 was not covered by tests
open={modalOpen}
>
<ModalGallery images={images} index={index} />
</Modal>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Gallery/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const ImageComponent = <
{...dimensions}
{...(innerRef && { ref: innerRef })}
/>
<Modal onClose={toggleModal} open={modalIsOpen}>
<Modal className='str-chat__image-modal' onClose={toggleModal} open={modalIsOpen}>
<ModalGallery images={[props]} index={0} />
</Modal>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Message/MessageSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const MessageSimpleWithContext = <
return (
<>
{editing && (
<Modal onClose={clearEditingState} open={editing}>
<Modal className='str-chat__edit-message-modal' onClose={clearEditingState} open={editing}>
<MessageInput
clearEditingState={clearEditingState}
grow
Expand Down
2 changes: 1 addition & 1 deletion src/components/MessageBounce/MessageBounceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function MessageBounceModal({
...modalProps
}: MessageBounceModalProps) {
return (
<Modal {...modalProps}>
<Modal className='str-chat__message-bounce-modal' {...modalProps}>
<MessageBounceProvider>
<MessageBouncePrompt onClose={modalProps.onClose} />
</MessageBounceProvider>
Expand Down
7 changes: 5 additions & 2 deletions src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from 'clsx';
import React, { PropsWithChildren, useEffect, useRef } from 'react';
import { FocusScope } from '@react-aria/focus';

Expand All @@ -8,13 +9,15 @@ import { useChatContext, useTranslationContext } from '../../context';
export type ModalProps = {
/** If true, modal is opened or visible. */
open: boolean;
/** Custom class to be applied to the modal root div */
className?: string;
/** Callback handler for closing of modal. */
onClose?: (
event: React.KeyboardEvent | React.MouseEvent<HTMLButtonElement | HTMLDivElement>,
) => void;
};

export const Modal = ({ children, onClose, open }: PropsWithChildren<ModalProps>) => {
export const Modal = ({ children, className, onClose, open }: PropsWithChildren<ModalProps>) => {
const { t } = useTranslationContext('Modal');
const { themeVersion } = useChatContext('Modal');

Expand Down Expand Up @@ -42,7 +45,7 @@ export const Modal = ({ children, onClose, open }: PropsWithChildren<ModalProps>
if (!open) return null;

return (
<div className='str-chat__modal str-chat__modal--open' onClick={handleClick}>
<div className={clsx('str-chat__modal str-chat__modal--open', className)} onClick={handleClick}>
Copy link
Contributor

Choose a reason for hiding this comment

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

str-chat__modal--open - that's funny

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would not remove it as it would be a breaking change

Copy link
Contributor

Choose a reason for hiding this comment

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

I know, I'm not suggesting - treat this as "completely useless comment". :)

<FocusScope autoFocus contain>
<button className='str-chat__modal__close-button' ref={closeRef} title={t<string>('Close')}>
{themeVersion === '2' && <CloseIconRound />}
Expand Down
5 changes: 4 additions & 1 deletion src/components/Reactions/ReactionsListModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export function ReactionsListModal<
);

return (
<Modal {...modalProps}>
<Modal
{...modalProps}
className={clsx('str-chat__message-reactions-details-modal', modalProps.className)}
>
<div className='str-chat__message-reactions-details' data-testid='reactions-list-modal'>
<div className='str-chat__message-reactions-details-reaction-types'>
{reactions.map(
Expand Down
Loading