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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tag): added mobile and responsive versions component #700

Merged
merged 21 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 19 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
5 changes: 5 additions & 0 deletions .changeset/moody-phones-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alfalab/core-components-tag": major
---

Для компонента Tag добавлены мобильная и адаптивная версии компонента. Responsive компонент теперь экспортируется из индексного файла
5 changes: 5 additions & 0 deletions .changeset/sharp-camels-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alfalab/core-components-filter-tag": major
---

Для компонента FilterTag добавлены мобильная и адаптивная версии компонента. Responsive компонент теперь экспортируется из индексного файла
14 changes: 14 additions & 0 deletions packages/checkbox-group/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ const TagGroup = ({ ...restProps }: Partial<CheckboxGroupProps>) => (
);

describe('Checkbox', () => {
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: true,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});

describe('Display tests', () => {
it('should display with children like boolean or string or others react children type correctly', () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ Object {
class="checkbox tagLabel"
>
<button
class="component component s outlined rounded my-tag"
class="component component component s s outlined rounded outlined my-tag"
type="button"
>
<span>
Expand All @@ -583,7 +583,7 @@ Object {
class="checkbox tagLabel"
>
<button
class="component component s outlined rounded"
class="component component component s s outlined rounded outlined"
type="button"
>
<span>
Expand All @@ -601,7 +601,7 @@ Object {
class="checkbox tagLabel"
>
<button
class="component component s outlined rounded"
class="component component component s s outlined rounded outlined"
type="button"
>
<span>
Expand Down Expand Up @@ -635,7 +635,7 @@ Object {
class="checkbox tagLabel"
>
<button
class="component component s outlined rounded my-tag"
class="component component component s s outlined rounded outlined my-tag"
type="button"
>
<span>
Expand All @@ -653,7 +653,7 @@ Object {
class="checkbox tagLabel"
>
<button
class="component component s outlined rounded"
class="component component component s s outlined rounded outlined"
type="button"
>
<span>
Expand All @@ -671,7 +671,7 @@ Object {
class="checkbox tagLabel"
>
<button
class="component component s outlined rounded"
class="component component component s s outlined rounded outlined"
type="button"
>
<span>
Expand Down
21 changes: 21 additions & 0 deletions packages/filter-tag/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 @@ -18,6 +38,7 @@
"react-dom": "^16.9.0 || ^17.0.1 || ^18.0.0"
},
"dependencies": {
"@alfalab/core-components-mq": "^4.1.4",
"@alfalab/hooks": "^1.13.0",
"@alfalab/icons-glyph": "^2.108.0",
"classnames": "^2.3.1",
Expand Down
11 changes: 11 additions & 0 deletions packages/filter-tag/src/Component.desktop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { forwardRef } from 'react';

import { BaseFilterTag, BaseFilterTagProps } from './components/base-filter-tag';

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

export type FilterTagDesktopProps = Omit<BaseFilterTagProps, 'styles'>;

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

import { BaseFilterTag, BaseFilterTagProps } from './components/base-filter-tag';

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

export type FilterTagMobileProps = Omit<BaseFilterTagProps, 'styles'>;

export const FilterTagMobile = forwardRef<HTMLDivElement, FilterTagMobileProps>((restProps, ref) => (
<BaseFilterTag {...restProps} ref={ref} styles={styles} />
));
31 changes: 31 additions & 0 deletions packages/filter-tag/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 { BaseFilterTagProps } from './components/base-filter-tag';
import { FilterTagDesktop } from './Component.desktop';
import { FilterTagMobile } from './Component.mobile';

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

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

const [isDesktop] = useMatchMedia(query);

const Component = isDesktop ? FilterTagDesktop : FilterTagMobile;

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

import { FilterTag } from './index';
import { FilterTagDesktop as FilterTag} from './desktop';

describe('Snapshots tests', () => {
it('should match snapshot', () => {
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.
Valeri8888 marked this conversation as resolved.
Show resolved Hide resolved
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 16 additions & 16 deletions packages/filter-tag/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Object {
"baseElement": <body>
<div>
<div
class="component rounded s"
class="component rounded s component rounded s"
>
<button
class="valueButton s rounded outlined"
class="valueButton valueButton s s rounded rounded outlined outlined"
type="button"
>
<span>
Expand Down Expand Up @@ -37,10 +37,10 @@ Object {
</body>,
"container": <div>
<div
class="component rounded s"
class="component rounded s component rounded s"
>
<button
class="valueButton s rounded outlined"
class="valueButton valueButton s s rounded rounded outlined outlined"
type="button"
>
<span>
Expand Down Expand Up @@ -125,10 +125,10 @@ Object {
"baseElement": <body>
<div>
<div
class="component rectangular s"
class="component rectangular s component rectangular s"
>
<button
class="valueButton s rectangular outlined"
class="valueButton valueButton s s rectangular rectangular outlined outlined"
type="button"
>
<span>
Expand Down Expand Up @@ -156,10 +156,10 @@ Object {
</body>,
"container": <div>
<div
class="component rectangular s"
class="component rectangular s component rectangular s"
>
<button
class="valueButton s rectangular outlined"
class="valueButton valueButton s s rectangular rectangular outlined outlined"
type="button"
>
<span>
Expand Down Expand Up @@ -244,10 +244,10 @@ Object {
"baseElement": <body>
<div>
<div
class="component rectangular s"
class="component rectangular s component rectangular s"
>
<button
class="valueButton s rectangular outlined"
class="valueButton valueButton s s rectangular rectangular outlined outlined"
type="button"
>
<span>
Expand Down Expand Up @@ -275,10 +275,10 @@ Object {
</body>,
"container": <div>
<div
class="component rectangular s"
class="component rectangular s component rectangular s"
>
<button
class="valueButton s rectangular outlined"
class="valueButton valueButton s s rectangular rectangular outlined outlined"
type="button"
>
<span>
Expand Down Expand Up @@ -363,10 +363,10 @@ Object {
"baseElement": <body>
<div>
<div
class="component rounded s"
class="component rounded s component rounded s"
>
<button
class="valueButton s rounded outlined"
class="valueButton valueButton s s rounded rounded outlined outlined"
type="button"
>
<span />
Expand All @@ -392,10 +392,10 @@ Object {
</body>,
"container": <div>
<div
class="component rounded s"
class="component rounded s component rounded s"
>
<button
class="valueButton s rounded outlined"
class="valueButton valueButton s s rounded rounded outlined outlined"
type="button"
>
<span />
Expand Down
7 changes: 5 additions & 2 deletions packages/filter-tag/src/component.screenshots.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ describe('FilterTag', () => {
checked: true,
},
},
'transform:scale(2.2)',
'width:800px;transform:scale(2.2)',
{
viewport: { width: 1024, height: 600 },
},
);
});

Expand Down Expand Up @@ -82,7 +85,7 @@ describe('FilterTag | main props', () => {
screenshotOpts: {
fullPage: true,
},
viewport: { width: 740, height: 100 },
viewport: { width: 1024, height: 100 },
theme,
})();

Expand Down
Loading
Loading