Skip to content

Commit

Permalink
feat(plate): added mobile and responsive versions component
Browse files Browse the repository at this point in the history
  • Loading branch information
Валерия Чуричева authored and Валерия Чуричева committed Jul 19, 2023
1 parent 5bb0e0b commit 7806d4b
Show file tree
Hide file tree
Showing 32 changed files with 512 additions and 214 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-rules-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alfalab/core-components-plate": major
---

Для компонента Plate добавлены мобильная и адаптивная версии компонента. Responsive компонент теперь экспортируется из индексного файла
21 changes: 21 additions & 0 deletions packages/plate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
"license": "MIT",
"main": "index.js",
"module": "./esm/index.js",
"exports": {
".": {
"import": "./esm/index.js",
"require": "./index.js"
},
"./mobile": {
"import": "./esm/mobile.js",
"require": "./mobile.js"
},
"./desktop": {
"import": "./esm/desktop.js",
"require": "./desktop.js"
},
"./esm": "./esm/index.js",
"./cssm": "./cssm/index.js",
"./modern": "./modern/index.js",
"./esm/*": "./esm/*",
"./cssm/*": "./cssm/*",
"./modern/*": "./modern/*"
},
"scripts": {
"postinstall": "node -e \"if (require('fs').existsSync('./send-stats.js')){require('./send-stats.js')} \""
},
Expand All @@ -19,6 +39,7 @@
"dependencies": {
"@alfalab/core-components-button": "^8.4.0",
"@alfalab/core-components-icon-button": "^6.1.1",
"@alfalab/core-components-mq": "^4.1.4",
"@alfalab/hooks": "^1.13.0",
"classnames": "^2.3.1",
"react-merge-refs": "^1.1.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/plate/src/Component.desktop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { forwardRef } from 'react';

import { BasePlate, BasePlateProps } from './components/base-plate';

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

export type PlateDesktopProps = Omit<BasePlateProps, 'styles'>;

export const PlateDesktop = forwardRef<HTMLDivElement, PlateDesktopProps>((restProps, ref) => (
<BasePlate {...restProps} styles={styles} ref={ref} />
));
11 changes: 11 additions & 0 deletions packages/plate/src/Component.mobile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { forwardRef } from 'react';

import { BasePlate, BasePlateProps } from './components/base-plate';

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

export type PlateMobileProps = Omit<BasePlateProps, 'styles' | 'limitContentWidth'>;

export const PlateMobile = forwardRef<HTMLDivElement, PlateMobileProps>((restProps, ref) => (
<BasePlate {...restProps} styles={styles} ref={ref} />
));
31 changes: 31 additions & 0 deletions packages/plate/src/Component.responsive.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { forwardRef } from 'react';

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

import { BasePlateProps } from './components/base-plate';
import { PlateDesktop } from './Component.desktop';
import { PlateMobile } from './Component.mobile';

export type PlateProps = Omit<BasePlateProps, 'styles'> & {
/**
* Контрольная точка, с нее начинается desktop версия
* @default 1024
*/
breakpoint?: number;
};

export const Plate = forwardRef<HTMLDivElement, PlateProps>(
({ children, breakpoint = 1024, ...restProps }, ref) => {
const query = `(min-width: ${breakpoint}px)`;

const [isDesktop] = useMatchMedia(query);

const Component = isDesktop ? PlateDesktop : PlateMobile;

return (
<Component ref={ref} {...restProps}>
{children}
</Component>
);
},
);
2 changes: 1 addition & 1 deletion packages/plate/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fireEvent, render } from '@testing-library/react';
import { CheckmarkCircleMIcon } from '@alfalab/icons-glyph/CheckmarkCircleMIcon';

import userEvent from '@testing-library/user-event';
import { Plate, PlateProps } from './index';
import { PlateDesktop as Plate, PlateDesktopProps as PlateProps } from './desktop';
import { Button } from '../../button/src';

describe('Plate', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/plate/src/__image_snapshots__/plate-preview-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/plate/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ exports[`Plate Snapshots tests should match snapshot 1`] = `
class="contentContainer limitWidth"
>
<div
class="bold"
class="bold bold"
>
title
</div>
<div
class="content"
>
<div
class="description"
class="description description"
>
text
</div>
Expand Down
25 changes: 13 additions & 12 deletions packages/plate/src/component.screenshots.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ describe('Plate', () => {
buttons: true,
},
},
'transform:scale(1.3);padding:0 200px;',
'width:800px;transform:scale(1.3);padding:0 200px;',
{
viewport: { width: 1024, height: 600 },
},
);
});

Expand Down Expand Up @@ -54,10 +57,6 @@ describe(
screenshotOpts: {
fullPage: true,
},
viewport: {
width: 840,
height: 100,
},
}),
);

Expand All @@ -75,15 +74,15 @@ describe(
'Вам одобрено. Согласитесь на предложение, спустя какое-то время специалист с Вами свяжется для уточнения информации',
view: ['negative', 'positive', 'attention', 'common'],
},
size: { width: 400, height: 120 },
size: { width: 400, height: 140 },
}),
],
],
screenshotOpts: {
fullPage: true,
},
viewport: {
width: 840,
width: 1024,
height: 100,
},
}),
Expand All @@ -103,15 +102,15 @@ describe(
'Вам одобрено. Согласитесь на предложение, спустя какое-то время специалист с Вами свяжется для уточнения информации',
rowLimit: [undefined, 1, 2, 3],
},
size: { width: 400, height: 120 },
size: { width: 400, height: 140 },
}),
],
],
screenshotOpts: {
fullPage: true,
},
viewport: {
width: 840,
width: 1024,
height: 100,
},
}),
Expand All @@ -129,8 +128,9 @@ describe(
buttons: true,
leftAddons: [false, true],
},
wrapperStyles: 'width:500px',
}),
viewport: { width: 500, height: 160 },
viewport: { width: 1024, height: 160 },
}),
);

Expand All @@ -147,8 +147,9 @@ describe(
leftAddons: true,
buttons: true,
},
wrapperStyles: 'width:500px',
}),
viewport: { width: 500, height: 160 },
viewport: { width: 1024, height: 160 },
}),
);

Expand All @@ -173,7 +174,7 @@ describe(
fullPage: true,
},
viewport: {
width: 840,
width: 1024,
height: 100,
},
}),
Expand Down
Loading

0 comments on commit 7806d4b

Please sign in to comment.