diff --git a/src/frontend/src/features/home/components/JoinMeetingDialogContent.tsx b/src/frontend/src/features/home/components/JoinMeetingDialog.tsx similarity index 84% rename from src/frontend/src/features/home/components/JoinMeetingDialogContent.tsx rename to src/frontend/src/features/home/components/JoinMeetingDialog.tsx index 6073259b..31a5f01a 100644 --- a/src/frontend/src/features/home/components/JoinMeetingDialogContent.tsx +++ b/src/frontend/src/features/home/components/JoinMeetingDialog.tsx @@ -1,11 +1,11 @@ import { useTranslation } from 'react-i18next' -import { Field, Ul, H, P, Form, DialogContent } from '@/primitives' +import { Field, Ul, H, P, Form, Dialog } from '@/primitives' import { isRoomValid, navigateToRoom } from '@/features/rooms' -export const JoinMeetingDialogContent = () => { +export const JoinMeetingDialog = () => { const { t } = useTranslation('home') return ( - +
{ navigateToRoom((data.roomId as string).trim()) @@ -34,6 +34,6 @@ export const JoinMeetingDialogContent = () => {
{t('joinMeetingTipHeading')}

{t('joinMeetingTipContent')}

-
+ ) } diff --git a/src/frontend/src/features/home/routes/Home.tsx b/src/frontend/src/features/home/routes/Home.tsx index 76051c4d..65187793 100644 --- a/src/frontend/src/features/home/routes/Home.tsx +++ b/src/frontend/src/features/home/routes/Home.tsx @@ -1,11 +1,12 @@ import { useTranslation } from 'react-i18next' -import { Button, Div, Text, VerticallyOffCenter, Dialog } from '@/primitives' +import { DialogTrigger } from 'react-aria-components' +import { Button, Div, Text, VerticallyOffCenter } from '@/primitives' import { HStack } from '@/styled-system/jsx' import { authUrl, useUser } from '@/features/auth' import { navigateToNewRoom } from '@/features/rooms' -import { Screen } from '@/layout/Screen' -import { JoinMeetingDialogContent } from '../components/JoinMeetingDialogContent' import { SettingsButton } from '@/features/settings' +import { Screen } from '@/layout/Screen' +import { JoinMeetingDialog } from '../components/JoinMeetingDialog' export const Home = () => { const { t } = useTranslation('home') @@ -34,12 +35,12 @@ export const Home = () => { {isLoggedIn ? t('createMeeting') : t('login', { ns: 'global' })} - + - - + + diff --git a/src/frontend/src/features/settings/components/SettingsButton.tsx b/src/frontend/src/features/settings/components/SettingsButton.tsx index ac7c2a47..63b59560 100644 --- a/src/frontend/src/features/settings/components/SettingsButton.tsx +++ b/src/frontend/src/features/settings/components/SettingsButton.tsx @@ -1,11 +1,13 @@ import { useTranslation } from 'react-i18next' +import { DialogTrigger } from 'react-aria-components' import { RiSettings3Line } from '@remixicon/react' -import { Dialog, Button } from '@/primitives' +import { Button } from '@/primitives' import { SettingsDialog } from './SettingsDialog' + export const SettingsButton = () => { const { t } = useTranslation('settings') return ( - + - + ) } diff --git a/src/frontend/src/features/settings/components/SettingsDialog.tsx b/src/frontend/src/features/settings/components/SettingsDialog.tsx index 9d592e5a..03689c35 100644 --- a/src/frontend/src/features/settings/components/SettingsDialog.tsx +++ b/src/frontend/src/features/settings/components/SettingsDialog.tsx @@ -1,6 +1,6 @@ import { Trans, useTranslation } from 'react-i18next' import { useLanguageLabels } from '@/i18n/useLanguageLabels' -import { A, Badge, DialogContent, Field, H, P } from '@/primitives' +import { A, Badge, Dialog, Field, H, P } from '@/primitives' import { authUrl, logoutUrl, useUser } from '@/features/auth' export const SettingsDialog = () => { @@ -8,7 +8,7 @@ export const SettingsDialog = () => { const { user, isLoggedIn } = useUser() const { languagesList, currentLanguage } = useLanguageLabels() return ( - + {t('account.heading')} {isLoggedIn ? ( <> @@ -41,6 +41,6 @@ export const SettingsDialog = () => { i18n.changeLanguage(lang as string) }} /> - + ) } diff --git a/src/frontend/src/features/settings/index.ts b/src/frontend/src/features/settings/index.ts index c1039a83..077df744 100644 --- a/src/frontend/src/features/settings/index.ts +++ b/src/frontend/src/features/settings/index.ts @@ -1 +1,2 @@ export { SettingsButton } from './components/SettingsButton' +export { SettingsDialog } from './components/SettingsDialog' diff --git a/src/frontend/src/primitives/AlertDialog.tsx b/src/frontend/src/primitives/AlertDialog.tsx deleted file mode 100644 index 6dfdc609..00000000 --- a/src/frontend/src/primitives/AlertDialog.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { Dialog, type DialogProps } from './Dialog' - -export const AlertDialog = (props: DialogProps) => { - return -} diff --git a/src/frontend/src/primitives/Dialog.tsx b/src/frontend/src/primitives/Dialog.tsx index 0a9c5df9..19c1dfca 100644 --- a/src/frontend/src/primitives/Dialog.tsx +++ b/src/frontend/src/primitives/Dialog.tsx @@ -1,16 +1,15 @@ -import { useContext, type ReactNode } from 'react' +import { styled } from '@/styled-system/jsx' +import { RiCloseLine } from '@remixicon/react' +import { t } from 'i18next' import { Dialog as RACDialog, - DialogTrigger, - Modal, - type DialogProps as RACDialogProps, ModalOverlay, - OverlayTriggerStateContext, + Modal, + type DialogProps, + Heading, } from 'react-aria-components' -import { RiCloseLine } from '@remixicon/react' -import { useTranslation } from 'react-i18next' -import { styled } from '@/styled-system/jsx' -import { Button, Box, Div, VerticallyOffCenter } from '@/primitives' +import { Div, Button, Box, VerticallyOffCenter } from '@/primitives' +import { text } from './Text' const StyledModalOverlay = styled(ModalOverlay, { base: { @@ -47,71 +46,56 @@ const StyledRACDialog = styled(RACDialog, { pointerEvents: 'none', }, }) - -export type DialogProps = { - children: [ - trigger: ReactNode, - dialogContent: - | (({ close }: { close: () => void }) => ReactNode) - | ReactNode, - ] -} & RACDialogProps - -/** - * a Dialog is a tuple of a trigger component (most usually a Button) that toggles some interactive content in a Dialog on top of the app. You should mostly use a DialogContent as second child. - */ -export const Dialog = ({ children, ...dialogProps }: DialogProps) => { - const { t } = useTranslation() +export const Dialog = ({ + title, + children, + ...dialogProps +}: DialogProps & { title: string }) => { const isAlert = dialogProps['role'] === 'alertdialog' - const [trigger, dialogContent] = children return ( - - {trigger} - - - - {({ close }) => ( - -
- - {typeof dialogContent === 'function' - ? dialogContent({ close }) - : dialogContent} - {!isAlert && ( -
- -
- )} -
-
-
- )} -
-
-
-
+ + + + {({ close }) => ( + +
+ + + {title} + + {typeof children === 'function' + ? children({ close }) + : children} + {!isAlert && ( +
+ +
+ )} +
+
+
+ )} +
+
+
) } - -export const useCloseDialog = () => { - const dialogState = useContext(OverlayTriggerStateContext) - if (dialogState) { - return dialogState.close - } - return null -} diff --git a/src/frontend/src/primitives/DialogContent.tsx b/src/frontend/src/primitives/DialogContent.tsx deleted file mode 100644 index af0afd16..00000000 --- a/src/frontend/src/primitives/DialogContent.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { type ReactNode } from 'react' -import { Heading } from 'react-aria-components' -import { text } from './Text' - -/** - * Dialog content Wrapper. - * - * Use this in a , next to the button triggering the dialog. - * This is helpful to easily add the title to the dialog and keep it - * next to the actual content code, if you happen to separate the dialog - * trigger from the dialog content in the code. - */ -export const DialogContent = ({ - children, - title, -}: { - title: ReactNode - children: ReactNode -}) => { - return ( - <> - - {title} - - {children} - - ) -} diff --git a/src/frontend/src/primitives/index.ts b/src/frontend/src/primitives/index.ts index e5493ce7..1d13b304 100644 --- a/src/frontend/src/primitives/index.ts +++ b/src/frontend/src/primitives/index.ts @@ -1,11 +1,10 @@ export { A } from './A' -export { AlertDialog } from './AlertDialog' export { Badge } from './Badge' export { Bold } from './Bold' export { Box } from './Box' export { Button } from './Button' -export { Dialog, useCloseDialog } from './Dialog' -export { DialogContent } from './DialogContent' +export { useCloseDialog } from './useCloseDialog' +export { Dialog } from './Dialog' export { Div } from './Div' export { Field } from './Field' export { Form } from './Form' diff --git a/src/frontend/src/primitives/useCloseDialog.tsx b/src/frontend/src/primitives/useCloseDialog.tsx new file mode 100644 index 00000000..b5ac1a7d --- /dev/null +++ b/src/frontend/src/primitives/useCloseDialog.tsx @@ -0,0 +1,10 @@ +import { useContext } from 'react' +import { OverlayTriggerStateContext } from 'react-aria-components' + +export const useCloseDialog = () => { + const dialogState = useContext(OverlayTriggerStateContext) + if (dialogState) { + return dialogState.close + } + return null +}