Skip to content

Commit

Permalink
feat: universal modal content atom export refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fulcanellee committed Dec 13, 2024
1 parent 2d88ef5 commit e4bb5d9
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 20 deletions.
5 changes: 3 additions & 2 deletions packages/universal-modal/src/Component.responsive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createResponsive } from './utils/createResponsive';
import { UniversalModalDesktop } from './desktop';
import { UniversalModalMobile } from './mobile';
import { UniversalModalResponsiveProps } from './typings';
import { ContentResponsive } from './components/content';

export const UniversalModal = forwardRef<HTMLDivElement, UniversalModalResponsiveProps>(
({ children, breakpoint, defaultMatchMediaValue, dataTestId, ...restProps }, ref) => {
Expand All @@ -25,9 +26,9 @@ export const UniversalModal = forwardRef<HTMLDivElement, UniversalModalResponsiv

export const UniversalModalResponsive = Object.assign(UniversalModal, {
Header: HeaderResponsive,
Controls,
Content: createResponsive(UniversalModalDesktop.Content, UniversalModalMobile.Content),
Content: ContentResponsive,
Footer: createResponsive(UniversalModalDesktop.Footer, UniversalModalMobile.Footer),
Controls,
});

UniversalModalResponsive.displayName = 'UniversalModalResponsive';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC } from 'react';
import cn from 'classnames';

import { Content, ContentProps } from './Component';
import { BaseContent, ContentProps } from './base-content';

export type ContentDesktopProps = ContentProps & {
/**
Expand All @@ -11,5 +11,5 @@ export type ContentDesktopProps = ContentProps & {
};

export const ContentDesktop: FC<ContentDesktopProps> = ({ className, ...restProps }) => (
<Content className={cn(className)} {...restProps} />
<BaseContent className={cn(className)} {...restProps} />
);
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { FC } from 'react';
import cn from 'classnames';

import { Content, ContentProps } from './Component';
import { BaseContent, ContentProps } from './base-content';

import styles from './mobile.module.css';

export type ContentMobileProps = ContentProps;

export const ContentMobile: FC<ContentMobileProps> = ({ className, ...restProps }) => (
<Content className={cn(styles.content, styles.withFooter, className)} {...restProps} />
<BaseContent className={cn(styles.content, styles.withFooter, className)} {...restProps} />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { FC } from 'react';
import { useIsDesktop } from '@alfalab/core-components-mq';

import type { ContentDesktopProps, ContentMobileProps } from '.';
import { ContentDesktop, ContentMobile } from '.';

export type ContentResponsiveProps = ContentDesktopProps | ContentMobileProps;

export const ContentResponsive: FC<ContentResponsiveProps> = ({ ...restProps }) => {
const isDesktop = useIsDesktop();

if (isDesktop) {
return <ContentDesktop {...restProps} />;
}

return <ContentMobile {...restProps} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type ContentProps = {
dataTestId?: string;
};

export const Content: FC<ContentProps> = ({ children, className, dataTestId }) => {
export const BaseContent: FC<ContentProps> = ({ children, className, dataTestId }) => {
const { contentRef, hasHeader, hasFooter } = useContext(ModalContext);

return (
Expand Down
3 changes: 3 additions & 0 deletions packages/universal-modal/src/components/content/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export { ContentResponsive } from './Component.responsive';
export type { ContentResponsiveProps } from './Component.responsive';

export { ContentDesktop } from './Component.desktop';
export type { ContentDesktopProps } from './Component.desktop';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import React, { FC } from 'react';

import { useIsDesktop } from '@alfalab/core-components-mq';

import type { HeaderPropsMobile } from '.';
import { HeaderDesktop, HeaderMobile, HeaderPropsDesktop } from '.';
import type { HeaderPropsDesktop, HeaderPropsMobile } from '.';
import { HeaderDesktop, HeaderMobile } from '.';

export type HeaderResponsiveProps = HeaderPropsDesktop | HeaderPropsMobile;

export const HeaderResponsive: FC<HeaderResponsiveProps> = ({ children, ...restProps }) => {
export const HeaderResponsive: FC<HeaderResponsiveProps> = ({ ...restProps }) => {
const isDesktop = useIsDesktop();

if (isDesktop) {
return <HeaderDesktop {...restProps}>{children}</HeaderDesktop>;
return <HeaderDesktop {...restProps} />;
}

return <HeaderMobile {...restProps}>{children}</HeaderMobile>;
return <HeaderMobile {...restProps} />;
};
8 changes: 4 additions & 4 deletions packages/universal-modal/src/desktop/Component.desktop.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { forwardRef, useState } from 'react';

import { ContentDesktop as Content } from '../components/content/Component.desktop';
import { ContentDesktop } from '../components/content/Component.desktop';
import { Controls, ControlsProps } from '../components/controls';
import { FooterDesktop as Footer } from '../components/footer/Component.desktop';
import { HeaderDesktop } from '../components/header';
Expand Down Expand Up @@ -37,9 +37,9 @@ export const UniversalModalDesktopComponent = forwardRef<
if (horizontalAlign === 'center') {
return (
<ModalByCenter
{...restProps}
horizontalAlign={horizontalAlign}
dataTestId={dataTestId}
{...restProps}
ref={ref}
>
{children}
Expand All @@ -49,9 +49,9 @@ export const UniversalModalDesktopComponent = forwardRef<

return (
<ModalBySide
{...restProps}
horizontalAlign={horizontalAlign}
dataTestId={dataTestId}
{...restProps}
ref={ref}
>
{children}
Expand All @@ -67,8 +67,8 @@ export const UniversalModalDesktopComponent = forwardRef<
});

export const UniversalModalDesktop = Object.assign(UniversalModalDesktopComponent, {
Content,
Header: HeaderDesktop,
Content: ContentDesktop,
Footer,
Controls: Controls as React.FC<Omit<ControlsProps, 'mobileLayout'>>,
});
4 changes: 2 additions & 2 deletions packages/universal-modal/src/docs/development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import { ArrowButtonDesktopMobile, CrossButtonDesktopMobile } from '@alfalab/cor
## Атомарный импорт внутренних компонентов

```jsx
import { ContentDesktop, ContentMobile } from '@alfalab/core-components/universal-modal';
import type { ContentDesktopProps, ContentMobileProps } from '@alfalab/core-components/universal-modal';
import { ContentResponsive, ContentDesktop, ContentMobile } from '@alfalab/core-components/universal-modal';
import type { ContentResponsiveProps, ContentDesktopProps, ContentMobileProps } from '@alfalab/core-components/universal-modal';

import { Controls } from '@alfalab/core-components/universal-modal';
import type { ControlsProps } from '@alfalab/core-components/universal-modal';
Expand Down
4 changes: 2 additions & 2 deletions packages/universal-modal/src/mobile/Component.mobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cn from 'classnames';

import { BaseModal } from '@alfalab/core-components-base-modal';

import { ContentMobile as Content } from '../components/content/Component.mobile';
import { ContentMobile } from '../components/content/Component.mobile';
import { Controls, ControlsProps } from '../components/controls';
import { FooterMobile as Footer } from '../components/footer/Component.mobile';
import { HeaderMobile } from '../components/header';
Expand Down Expand Up @@ -55,8 +55,8 @@ export const UniversalModalMobileComponent = forwardRef<HTMLDivElement, Universa
);

export const UniversalModalMobile = Object.assign(UniversalModalMobileComponent, {
Content,
Header: HeaderMobile,
Content: ContentMobile,
Footer,
Controls: Controls as React.FC<Omit<ControlsProps, 'mobileLayout'>>,
});

0 comments on commit e4bb5d9

Please sign in to comment.