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(button): added mobile and responsive versions component #687

Merged
merged 30 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
26d28ba
feat(button): added mobile and responsive versions component
May 26, 2023
9c03388
feat: merge master
May 29, 2023
b5d5996
feat(button): change files css
May 30, 2023
ea28973
feat(button): fix conflicts input-autocomplete
May 30, 2023
35bc337
feat(button): fix import
May 30, 2023
861b9ab
fix build
v-gevak May 31, 2023
e4bb7d7
Merge branch 'master' into feat/button-mobile-component
Valeri8888 May 31, 2023
f7241f2
feat(button): fix build picker-button
May 31, 2023
b55dbd0
Merge branch 'master' into feat/button-mobile-component
Jun 2, 2023
b94ef77
feat(button): fix review
Jun 6, 2023
5c76a3c
feat(button): fix tests
Jun 7, 2023
a2053bd
chore: fix tests
v-gevak Jun 8, 2023
b4b4b7a
feat(button): fix screenshots tabs
Jun 8, 2023
ea9c4bd
feat(button): fix styles mobile
Jun 14, 2023
58f3883
feat(button): fix screenshot test confirmation
Jun 15, 2023
5c09be7
Merge branch 'master' into feat/button-mobile-component
Jun 19, 2023
b8da83f
feat(button): fix review design
Jun 20, 2023
a996810
feat(button): fix import
Jun 20, 2023
290964e
feat(button): fix button size in tooltip
Jun 21, 2023
924275f
feat(button): fix review
Jun 23, 2023
ddf6e3d
Merge branch 'master' into feat/button-mobile-component
Jun 23, 2023
8ee57f1
feat(button): fix comment
Jun 23, 2023
babf705
Create tame-apes-refuse.md
Valeri8888 Jul 3, 2023
e97996b
Create chilly-turtles-design.md
Valeri8888 Jul 3, 2023
5fe04fe
feat(button): fix bug
Jul 3, 2023
d1457c0
fix(button): fix bg/secondary
Jul 13, 2023
46487c0
feat(button): fix screenshots test
Jul 17, 2023
b1d4708
Merge branch 'master' into feat/button-mobile-component
Valeri8888 Aug 3, 2023
3267022
fix(button): fix bugs
Aug 4, 2023
35c7e65
chore: merge master
v-gevak Aug 7, 2023
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
1 change: 1 addition & 0 deletions packages/button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"react": "^16.9.0 || ^17.0.1 || ^18.0.0"
},
"dependencies": {
"@alfalab/core-components-mq": "^4.1.4",
"@alfalab/core-components-spinner": "^3.0.5",
"@alfalab/hooks": "^1.4.1",
"classnames": "^2.3.1",
Expand Down
22 changes: 22 additions & 0 deletions packages/button/src/Component.desktop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// TODO Вид кнопок зависит от порядка импорта стилей. Исправить!!!.
/* eslint-disable simple-import-sort/imports */
import React, { forwardRef } from 'react';

import { BaseButton } from './components/base-button';
import { ButtonDesktopProps } from './typings';

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

import defaultColors from './default.desktop.module.css';
import invertedColors from './inverted.desktop.module.css';

const colorStyles = {
default: defaultColors,
inverted: invertedColors,
};

export const ButtonDesktop = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonDesktopProps>(
(restProps, ref) => (
<BaseButton {...restProps} ref={ref} colorStyles={colorStyles} styles={styles} />
),
);
22 changes: 22 additions & 0 deletions packages/button/src/Component.mobile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// TODO Вид кнопок зависит от порядка импорта стилей. Исправить!!!.
Valeri8888 marked this conversation as resolved.
Show resolved Hide resolved
/* eslint-disable simple-import-sort/imports */
import React, { forwardRef } from 'react';

import { BaseButton } from './components/base-button';
import { ButtonMobileProps } from './typings';

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

import defaultColors from './default.mobile.module.css';
import invertedColors from './inverted.mobile.module.css';

const colorStyles = {
default: defaultColors,
inverted: invertedColors,
};

export const ButtonMobile = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonMobileProps>(
(restProps, ref) => (
<BaseButton {...restProps} ref={ref} colorStyles={colorStyles} styles={styles} />
),
);
28 changes: 28 additions & 0 deletions packages/button/src/Component.responsive.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { forwardRef } from 'react';

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

import { isClient } from '../../utils';

import { ButtonDesktop } from './Component.desktop';
import { ButtonMobile } from './Component.mobile';
import { ButtonResponsiveProps } from './typings';

export const ButtonResponsive = forwardRef<
HTMLAnchorElement | HTMLButtonElement,
ButtonResponsiveProps
>(({ children, breakpoint = 1024, defaultMatchMediaValue, ...restProps }, ref) => {
Valeri8888 marked this conversation as resolved.
Show resolved Hide resolved
const query = `(min-width: ${breakpoint}px)`;

const getDefaultValue = () => (isClient() ? window.matchMedia(query).matches : false);

const [isDesktop] = useMatchMedia(query, defaultMatchMediaValue ?? getDefaultValue);

const Component = isDesktop ? ButtonDesktop : ButtonMobile;

return (
<Component ref={ref} {...restProps}>
{children}
</Component>
);
});
3 changes: 2 additions & 1 deletion packages/button/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
waitForElementToBeRemoved,
} from '@testing-library/react';

import { Button, ButtonProps, LOADER_MIN_DISPLAY_INTERVAL } from './index';
import { LOADER_MIN_DISPLAY_INTERVAL } from './components/base-button';
import { Button, ButtonProps } from './index';

const dataTestId = 'test-id';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// TODO Вид кнопок зависит от порядка импорта стилей. Исправить!!!.
/* eslint-disable simple-import-sort/imports */
import React, {
AnchorHTMLAttributes,
ButtonHTMLAttributes,
ElementType,
ReactNode,
useEffect,
useRef,
useState,
Expand All @@ -15,95 +11,7 @@ import cn from 'classnames';
import { Spinner } from '@alfalab/core-components-spinner';
import { useFocus } from '@alfalab/hooks';

import styles from './index.module.css';
import defaultColors from './default.module.css';
import invertedColors from './inverted.module.css';

const colorStyles = {
default: defaultColors,
inverted: invertedColors,
};

export type ComponentProps = {
/**
* Тип кнопки
*/
view?:
| 'accent'
| 'primary'
| 'secondary'
| 'tertiary'
| 'outlined' // deprecated
| 'filled' // deprecated
| 'transparent' // deprecated
| 'link'
| 'ghost';

/**
* Слот слева
*/
leftAddons?: ReactNode;

/**
* Слот справа
*/
rightAddons?: ReactNode;

/**
* Размер компонента
*/
size?: 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl';

/**
* Растягивает компонент на ширину контейнера
*/
block?: boolean;

/**
* Дополнительный класс
*/
className?: string;

/**
* Выводит ссылку в виде кнопки
*/
href?: string;

/**
* Позволяет использовать кастомный компонент для кнопки (например Link из роутера)
*/
Component?: ElementType;

/**
* Идентификатор для систем автоматизированного тестирования
*/
dataTestId?: string;

/**
* Показать лоадер
*/
loading?: boolean;

/**
* Не переносить текст кнопки на новую строку
*/
nowrap?: boolean;

/**
* Набор цветов для компонента
*/
colors?: 'default' | 'inverted';

/**
* Дочерние элементы.
*/
children?: ReactNode;
};

export type AnchorButtonProps = ComponentProps & AnchorHTMLAttributes<HTMLAnchorElement>;
export type NativeButtonProps = ComponentProps & ButtonHTMLAttributes<HTMLButtonElement>;

export type ButtonProps = Partial<AnchorButtonProps | NativeButtonProps>;
import { BaseButtonProps, ComponentProps } from '../../typings';

/**
* Минимальное время отображения лоадера - 500мс,
Expand Down Expand Up @@ -131,7 +39,7 @@ const logWarning = (view: Required<ComponentProps>['view']) => {
);
};

export const Button = React.forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonProps>(
export const BaseButton = React.forwardRef<HTMLAnchorElement | HTMLButtonElement, BaseButtonProps>(
(
{
children,
Expand All @@ -148,6 +56,11 @@ export const Button = React.forwardRef<HTMLAnchorElement | HTMLButtonElement, Bu
colors = 'default',
Component = href ? 'a' : 'button',
onClick,
styles = {},
colorStyles = {
default: {},
inverted: {},
},
...restProps
},
ref,
Expand Down Expand Up @@ -285,14 +198,3 @@ export const Button = React.forwardRef<HTMLAnchorElement | HTMLButtonElement, Bu
);
},
);

/**
* Для отображения в сторибуке
*/
Button.defaultProps = {
view: 'secondary',
size: 'm',
block: false,
loading: false,
nowrap: false,
};
1 change: 1 addition & 0 deletions packages/button/src/components/base-button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Component';
Original file line number Diff line number Diff line change
@@ -1,70 +1,4 @@
@import '../../themes/src/default.css';

:root {
/* primary */
--button-primary-base-bg-color: var(--color-light-bg-secondary-inverted);
--button-primary-hover-bg-color: var(--color-light-bg-secondary-inverted-tint-15);
--button-primary-active-bg-color: var(--color-light-bg-secondary-inverted-tint-20);
--button-primary-disabled-bg-color: var(--color-light-specialbg-secondary-transparent);
--button-primary-color: var(--color-light-text-primary-inverted);
--button-primary-disabled-color: var(--color-light-text-tertiary);

/* accent */
--button-accent-base-bg-color: var(--color-light-bg-accent);
--button-accent-hover-bg-color: var(--color-light-bg-accent-shade-7);
--button-accent-active-bg-color: var(--color-light-bg-accent-shade-15);
--button-accent-disabled-bg-color: var(--color-light-specialbg-secondary-transparent);
--button-accent-color: var(--color-static-text-primary-light);
--button-accent-disabled-color: var(--color-light-text-tertiary);

/* secondary */
--button-secondary-base-bg-color: var(--color-light-specialbg-tertiary-transparent);
--button-secondary-hover-bg-color: var(--color-light-specialbg-tertiary-transparent-shade-7);
--button-secondary-active-bg-color: var(--color-light-specialbg-tertiary-transparent-shade-15);
--button-secondary-disabled-bg-color: var(--color-light-specialbg-secondary-transparent);
--button-secondary-base-border-color: transparent;
--button-secondary-disabled-border-color: transparent;
--button-secondary-color: var(--color-light-text-primary);
--button-secondary-disabled-color: var(--color-light-text-tertiary);

/* tertiary */
--button-tertiary-base-bg-color: transparent;
--button-tertiary-hover-bg-color: var(--color-light-bg-primary-inverted-alpha-7);
--button-tertiary-active-bg-color: var(--color-light-bg-primary-inverted-alpha-15);
--button-tertiary-hover-border-color: var(--color-light-border-tertiary-inverted);
--button-tertiary-disabled-bg-color: transparent;
--button-tertiary-base-border-color: var(--color-light-border-underline-inverted);
--button-tertiary-disabled-border-color: var(--color-light-graphic-tertiary);
--button-tertiary-color: var(--color-light-text-primary);
--button-tertiary-disabled-color: var(--color-light-text-tertiary);

/* outlined */
--button-outlined-base-bg-color: transparent;
--button-outlined-hover-bg-color: rgba(0, 0, 0, 0.07);
--button-outlined-active-bg-color: rgba(0, 0, 0, 0.15);
--button-outlined-disabled-bg-color: transparent;
--button-outlined-base-border-color: var(--color-light-border-underline-inverted);
--button-outlined-disabled-border-color: var(--color-light-border-underline-inverted-alpha-30);
--button-outlined-color: var(--color-light-text-primary);
--button-outlined-disabled-color: var(--color-light-text-primary-alpha-30);

/* ghost */
--button-ghost-base-color: var(--color-light-text-primary);
--button-ghost-hover-color: var(--color-light-text-primary-tint-24);
--button-ghost-active-color: var(--color-light-text-primary-tint-40);
--button-ghost-disabled-color: var(--color-light-text-tertiary);

/* link */
--button-link-base-color: var(--color-light-text-primary);
--button-link-hover-bg-color: var(--color-light-bg-primary-inverted-alpha-7);
--button-link-active-bg-color: var(--color-light-bg-primary-inverted-alpha-15);
--button-link-disabled-color: var(--color-light-text-tertiary);

/* loader */
--button-spinner-static-color: var(--color-static-graphic-light);
--button-spinner-primary-color: var(--color-light-graphic-primary-inverted);
--button-spinner-default-color: var(--color-light-graphic-primary);
}
@import './vars.css';

.accent {
color: var(--button-accent-color);
Expand Down
Loading