Skip to content
Open
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: 6 additions & 0 deletions .changeset/three-geese-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@alfalab/core-components': patch
'@alfalab/core-components-markdown': patch
---

Сплит внутреннего компонента десктоп / мобайл
4 changes: 3 additions & 1 deletion packages/markdown/src/Component.desktop.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';

import { TitleDesktop } from '@alfalab/core-components-typography';

import { BaseMarkdown } from './components/base-markdown';
import { type MarkdownDesktopProps } from './typings';

export const MarkdownDesktopComponent: React.FC<MarkdownDesktopProps> = ({
children,
...restProps
}) => (
<BaseMarkdown {...restProps} platform='desktop'>
<BaseMarkdown {...restProps} Title={TitleDesktop}>
{children}
</BaseMarkdown>
);
4 changes: 3 additions & 1 deletion packages/markdown/src/Component.mobile.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';

import { TitleMobile } from '@alfalab/core-components-typography';

import { BaseMarkdown } from './components/base-markdown';
import { type MarkdownMobileProps } from './typings';

export const MarkdownMobileComponent: React.FC<MarkdownMobileProps> = ({
children,
...restProps
}) => (
<BaseMarkdown {...restProps} platform='mobile'>
<BaseMarkdown {...restProps} Title={TitleMobile}>
{children}
</BaseMarkdown>
);
13 changes: 7 additions & 6 deletions packages/markdown/src/Component.responsive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';

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

import { BaseMarkdown } from './components/base-markdown';
import { MarkdownDesktop } from './desktop';
import { MarkdownMobile } from './mobile';
import { type MarkdownResponsiveProps } from './typings';

export const MarkdownResponsiveComponent: React.FC<MarkdownResponsiveProps> = ({
Expand All @@ -14,9 +15,9 @@ export const MarkdownResponsiveComponent: React.FC<MarkdownResponsiveProps> = ({
}) => {
const isDesktop = useIsDesktop(breakpoint, defaultMatchMediaValue);

return (
<BaseMarkdown {...restProps} platform={isDesktop ? 'desktop' : 'mobile'}>
{children}
</BaseMarkdown>
);
if (isDesktop) {
return <MarkdownDesktop {...restProps}>{children}</MarkdownDesktop>;
}

return <MarkdownMobile {...restProps}>{children}</MarkdownMobile>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export const BaseMarkdown: FC<BaseMarkdownProps> = (props) => {
const {
children,
className,
platform,
font = 'system',
overrides,
transformLinkUri = true,
Title,
} = props;
const defaultOverrides = useOverrides(platform, font);
const defaultOverrides = useOverrides(Title, font);

return (
<ReactMarkdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import cn from 'classnames';

import { Link } from '@alfalab/core-components-link';
import { List } from '@alfalab/core-components-list';
import { Text, TitleDesktop, TitleMobile } from '@alfalab/core-components-typography';
import { Text } from '@alfalab/core-components-typography';

import { type FontType, type OverridesComponents, type PlatformType } from '../../typings';
import { type BaseMarkdownProps, type FontType, type OverridesComponents } from '../../typings';

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

export const useOverrides = (platform?: PlatformType, font?: FontType): OverridesComponents =>
useMemo(() => {
const Title = platform === 'desktop' ? TitleDesktop : TitleMobile;

return {
export const useOverrides = (
Title: BaseMarkdownProps['Title'],
font?: FontType,
): OverridesComponents =>
useMemo(
() => ({
h1: (props) => (
<Title
font={font}
Expand Down Expand Up @@ -117,5 +118,8 @@ export const useOverrides = (platform?: PlatformType, font?: FontType): Override
{props.children}
</Text>
),
};
}, [font, platform]);
}),
// Зависимости от DI импортов (Title) не нужны
// eslint-disable-next-line react-hooks/exhaustive-deps
[font],
);
19 changes: 10 additions & 9 deletions packages/markdown/src/typings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { type NormalComponents, type SpecialComponents } from 'react-markdown/src/ast-to-react';

import { type TitleDesktop, type TitleMobile } from '@alfalab/core-components-typography';

export type FontType = 'styrene' | 'system' | undefined;
export type PlatformType = 'desktop' | 'mobile';

export type OverridesComponents =
| Partial<Omit<NormalComponents, keyof SpecialComponents> & SpecialComponents>
Expand All @@ -15,11 +16,6 @@ export type BaseMarkdownProps = {
*/
className?: string;

/**
* Платформа
*/
platform?: PlatformType;

/**
* Шрифт разметки
*/
Expand All @@ -36,13 +32,18 @@ export type BaseMarkdownProps = {
* @default true
*/
transformLinkUri?: boolean;

/**
* Компонент Typography Title
*/
Title: typeof TitleDesktop | typeof TitleMobile;
};

export type MarkdownDesktopProps = Omit<BaseMarkdownProps, 'platform'>;
export type MarkdownDesktopProps = Omit<BaseMarkdownProps, 'Title'>;

export type MarkdownMobileProps = Omit<BaseMarkdownProps, 'platform'>;
export type MarkdownMobileProps = Omit<BaseMarkdownProps, 'Title'>;

export type MarkdownResponsiveProps = Omit<BaseMarkdownProps, 'platform'> & {
export type MarkdownResponsiveProps = Omit<BaseMarkdownProps, 'Title'> & {
/**
* Контрольная точка, с нее начинается desktop версия
* @default 1024
Expand Down