Skip to content

Commit 70b54b6

Browse files
committed
Инициализация компонента FilterButton
1 parent e47daf0 commit 70b54b6

24 files changed

+338
-0
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"packages/file-upload-item",
5151
"packages/file-upload-item-v1",
5252
"packages/filter-tag",
53+
"packages/filter-button",
5354
"packages/form-control",
5455
"packages/gallery",
5556
"packages/gap",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @alfalab/core-components-filter-button
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "@alfalab/core-components-filter-button",
3+
"version": "7.0.0",
4+
"description": "",
5+
"keywords": [],
6+
"license": "MIT",
7+
"sideEffects": [
8+
"**/*.css"
9+
],
10+
"main": "index.js",
11+
"module": "./esm/index.js",
12+
"dependencies": {
13+
"@alfalab/core-components-mq": "^5.0.1",
14+
"@alfalab/hooks": "^1.13.1",
15+
"@alfalab/icons-glyph": "^2.247.0",
16+
"classnames": "^2.5.1",
17+
"tslib": "^2.4.0"
18+
},
19+
"peerDependencies": {
20+
"react": "^16.9.0 || ^17.0.1 || ^18.0.0",
21+
"react-dom": "^16.9.0 || ^17.0.1 || ^18.0.0"
22+
},
23+
"publishConfig": {
24+
"access": "public",
25+
"directory": "dist"
26+
},
27+
"themesVersion": "14.1.2",
28+
"varsVersion": "10.1.0"
29+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { forwardRef } from 'react';
2+
3+
import { useIsDesktop } from '@alfalab/core-components-mq';
4+
5+
import { FilterButtonDesktop } from './desktop';
6+
import { FilterButtonMobile } from './mobile';
7+
import { type BaseFilterButtonProps } from './types';
8+
9+
// todo: обратить внимание на codemode и разобраться зачем нужно 42-filter-button
10+
11+
export type FilterButtonProps = BaseFilterButtonProps & {
12+
/**
13+
* Контрольная точка, с нее начинается desktop версия
14+
* @default 1024
15+
*/
16+
breakpoint?: number;
17+
18+
/**
19+
* Версия, которая будет использоваться при серверном рендеринге
20+
*/
21+
client?: 'desktop' | 'mobile';
22+
23+
/**
24+
* Значение по-умолчанию для хука useMatchMedia
25+
* @deprecated Используйте client
26+
*/
27+
defaultMatchMediaValue?: boolean | (() => boolean);
28+
};
29+
30+
export const FilterButton = forwardRef<HTMLDivElement, FilterButtonProps>(
31+
(
32+
{
33+
children,
34+
breakpoint,
35+
client,
36+
defaultMatchMediaValue = client === undefined ? undefined : client === 'desktop',
37+
...restProps
38+
},
39+
ref,
40+
) => {
41+
const isDesktop = useIsDesktop(breakpoint, defaultMatchMediaValue);
42+
43+
const Component = isDesktop ? FilterButtonDesktop : FilterButtonMobile;
44+
45+
return (
46+
<Component ref={ref} {...restProps}>
47+
{children}
48+
</Component>
49+
);
50+
},
51+
);
52+
53+
FilterButton.displayName = 'FilterButton';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React, { forwardRef } from 'react';
2+
3+
import { type BaseFilterButtonProps } from '../../types';
4+
5+
export const BaseFilterButton = forwardRef<HTMLDivElement, BaseFilterButtonProps>(
6+
({ children, className, dataTestId, ...restProps }, ref) => (
7+
<div ref={ref} className={className} data-test-id={dataTestId} {...restProps}>
8+
{children}
9+
</div>
10+
),
11+
);

packages/filter-button/src/components/base-filter-button/index.module.css

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Component';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React, { forwardRef } from 'react';
2+
3+
import { BaseFilterButton } from '../components/base-filter-button';
4+
import { type BaseFilterButtonProps } from '../types';
5+
6+
export const FilterButtonDesktop = forwardRef<HTMLDivElement, BaseFilterButtonProps>(
7+
(restProps, ref) => <BaseFilterButton {...restProps} ref={ref} />,
8+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Component.desktop';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Meta, Markdown } from '@storybook/addon-docs';
2+
import { ComponentHeader, Tabs } from 'storybook/blocks';
3+
import * as Stories from './Component.stories.tsx';
4+
5+
import Description from './description.mdx';
6+
import Development from './development.mdx';
7+
import Changelog from '../../CHANGELOG.md?raw';
8+
9+
<Meta of={Stories} />
10+
11+
<ComponentHeader
12+
name='FilterButton'
13+
children='Используется чтобы вывести параметры фильтрации и отобразить примененное значение.'
14+
/>
15+
16+
<Tabs
17+
description={<Description />}
18+
development={<Development />}
19+
changelog={<Markdown>{Changelog}</Markdown>}
20+
/>

0 commit comments

Comments
 (0)