Skip to content

Commit

Permalink
feat: add button styles, sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomatoVan committed Nov 4, 2023
1 parent dd7532e commit 9b99cfe
Show file tree
Hide file tree
Showing 19 changed files with 174 additions and 39 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
'import/extensions': 'off',
'import/no-extraneous-dependencies': 'off',
'no-underscore-dangle': 'off',
'no-tabs': 'off',
// 'i18next/no-literal-string': [
// 'error',
// {
Expand Down
3 changes: 0 additions & 3 deletions extractedTranslations/en/about.json

This file was deleted.

12 changes: 6 additions & 6 deletions extractedTranslations/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"throw error": "throw error",
"Главная": "Главная",
"Главная страница": "Главная страница",
"О сайте": "О сайте",
"Обновить страницу": "Обновить страницу",
"Произошла непредвиденная ошибка": "Произошла непредвиденная ошибка",
"Страница не найдена": "Страница не найдена",
"Главная": "",
"Главная страница": "",
"О сайте": "",
"Обновить страницу": "",
"Произошла непредвиденная ошибка": "",
"Страница не найдена": "",
"Язык": "Язык"
}
3 changes: 0 additions & 3 deletions extractedTranslations/ru/about.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/styles/themes/dark.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.app.dark {
--bg-color: #090949;
--inverted-bg-color: #e8e8ea;
--primary-color: #049604;
--secondary-color: #04ff04;
--primary-color: #04ff04;
--secondary-color: #049604;
--inverted-primary-color: #0232c2;
--inverted-secondary-color: #0452ff;
}
4 changes: 2 additions & 2 deletions src/app/styles/themes/normal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
--inverted-bg-color: #090949;
--primary-color: #0232c2;
--secondary-color: #0449e0;
--inverted-primary-color: #049604;
--inverted-secondary-color: #04ff04;
--inverted-primary-color: #04ff04;
--inverted-secondary-color: #049604;
}
3 changes: 3 additions & 0 deletions src/app/styles/variables/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
--font-size-l: 24px;
--font-line-l: 32px;
--font-l: var(--font-size-l) / var(--font-line-l) var(--font-family-main);
--font-size-xl: 32px;
--font-line-xl: 40px;
--font-xl: var(--font-size-xl) / var(--font-line-xl) var(--font-family-main);

// Размеры
--navbar-height: 50px;
Expand Down
47 changes: 47 additions & 0 deletions src/shared/ui/Button/Button.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,50 @@
color: var(--primary-color);
background: none;
}

.background {
background: var(--bg-color);
color: var(--primary-color);
border: none;

}

.backgroundInverted {
background: var(--inverted-bg-color);
color: var(--inverted-primary-color);
border: none;
}

.square {
padding: 0;
}

.square.size_m {
width: var(--font-line-m);
height: var(--font-line-m);
font: var(--font-m);
}

.square.size_l {
width: var(--font-line-l);
height: var(--font-line-l);
font: var(--font-l);
}

.square.size_xl {
width: var(--font-line-xl);
height: var(--font-line-xl);
font: var(--font-xl);
}

.size_m {
font: var(--font-m);
}

.size_l {
font: var(--font-m);
}

.size_xl {
font: var(--font-m);
}
65 changes: 61 additions & 4 deletions src/shared/ui/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ComponentStory, ComponentMeta } from '@storybook/react';

import { ThemeDecorator } from 'shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from 'app/providers/ThemeProvider';
import { Button, ThemeButton } from './Button';
import { Button, ButtonSize, ButtonTheme } from './Button';

export default {
title: 'shared/Button',
Expand All @@ -23,18 +23,75 @@ Primary.args = {
export const Clear = Template.bind({});
Clear.args = {
children: 'Text',
theme: ThemeButton.CLEAR,
theme: ButtonTheme.CLEAR,
};

export const Outline = Template.bind({});
Outline.args = {
children: 'Text',
theme: ThemeButton.OUTLINE,
theme: ButtonTheme.OUTLINE,
};

export const OutlineSizeL = Template.bind({});
OutlineSizeL.args = {
children: 'Text',
theme: ButtonTheme.OUTLINE,
size: ButtonSize.L,
};

export const OutlineSizeXL = Template.bind({});
OutlineSizeXL.args = {
children: 'Text',
theme: ButtonTheme.OUTLINE,
size: ButtonSize.XL,
};

export const OutlineDark = Template.bind({});
OutlineDark.args = {
children: 'Text',
theme: ThemeButton.OUTLINE,
theme: ButtonTheme.OUTLINE,
};
OutlineDark.decorators = [ThemeDecorator(Theme.DARK)];

export const BackgroundTheme = Template.bind({});
BackgroundTheme.args = {
children: 'Text',
theme: ButtonTheme.BACKGROUND,
};

export const BackgroundInverted = Template.bind({});
BackgroundInverted.args = {
children: 'Text',
theme: ButtonTheme.BACKGROUND_INVERTED,
};

export const Square = Template.bind({});
Square.args = {
children: '>',
theme: ButtonTheme.BACKGROUND_INVERTED,
square: true,
};

export const SquareM = Template.bind({});
SquareM.args = {
children: '>',
theme: ButtonTheme.BACKGROUND_INVERTED,
square: true,
size: ButtonSize.M,
};

export const SquareL = Template.bind({});
SquareL.args = {
children: '>',
theme: ButtonTheme.BACKGROUND_INVERTED,
square: true,
size: ButtonSize.L,
};

export const SquareXL = Template.bind({});
SquareXL.args = {
children: '>',
theme: ButtonTheme.BACKGROUND_INVERTED,
square: true,
size: ButtonSize.XL,
};
4 changes: 2 additions & 2 deletions src/shared/ui/Button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, screen } from '@testing-library/react';
import { Button, ThemeButton } from 'shared/ui/Button/Button';
import { Button, ButtonTheme } from 'shared/ui/Button/Button';

describe('Button', () => {
test('Test render', () => {
Expand All @@ -8,7 +8,7 @@ describe('Button', () => {
});

test('Test clear theme', () => {
render(<Button theme={ThemeButton.CLEAR}>TEST</Button>);
render(<Button theme={ButtonTheme.CLEAR}>TEST</Button>);
expect(screen.getByText('TEST')).toHaveClass('clear');
screen.debug();
});
Expand Down
34 changes: 28 additions & 6 deletions src/shared/ui/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,50 @@ import { classNames } from 'shared/lib/classNames/classNames';
import { ButtonHTMLAttributes, FC } from 'react';
import cls from './Button.module.scss';

export enum ThemeButton {
CLEAR = 'clear',
OUTLINE = 'outline',
export enum ButtonTheme {
CLEAR = 'clear',
OUTLINE = 'outline',
BACKGROUND = 'background',
BACKGROUND_INVERTED = 'backgroundInverted',
}

export enum ButtonSize {
M='size_m',
L='size_l',
XL='size_xl',
}

interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>{
className?: string;
theme?: ThemeButton;
className?: string;
theme?: ButtonTheme;
square?: boolean;
size?: ButtonSize;
}

export const Button: FC<ButtonProps> = (props) => {
const {
className,
children,
theme,
square,
size = ButtonSize.M,
...otherProps
} = props;

const mods:Record<string, boolean> = {
[cls.square]: square,
};

const additional = [
className,
cls[theme],
cls[size],
];

return (
<button
type="button"
className={classNames(cls.Button, { [cls[theme]]: true }, [className])}
className={classNames(cls.Button, mods, additional)}
{...otherProps}
>
{children}
Expand Down
4 changes: 2 additions & 2 deletions src/shared/ui/LangSwitcher/LangSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { classNames } from 'shared/lib/classNames/classNames';
import { useTranslation } from 'react-i18next';
import React from 'react';
import { Button, ThemeButton } from 'shared/ui/Button/Button';
import { Button, ButtonTheme } from 'shared/ui/Button/Button';

interface LangSwitcherProps {
className?: string;
Expand All @@ -17,7 +17,7 @@ export const LangSwitcher = ({ className }: LangSwitcherProps) => {
return (
<Button
className={classNames('', {}, [className])}
theme={ThemeButton.CLEAR}
theme={ButtonTheme.CLEAR}
onClick={toggle}
>
{t('Язык')}
Expand Down
4 changes: 2 additions & 2 deletions src/shared/ui/ThemeSwitcher/ui/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { Theme, useTheme } from 'app/providers/ThemeProvider';
import LightIcon from 'shared/assets/icons/theme-light.svg';
import DarkIcon from 'shared/assets/icons/theme-dark.svg';
import { Button, ThemeButton } from 'shared/ui/Button/Button';
import { Button, ButtonTheme } from 'shared/ui/Button/Button';

interface ThemeSwitcherProps {
className?: string;
Expand All @@ -14,7 +14,7 @@ export const ThemeSwitcher = ({ className }: ThemeSwitcherProps) => {

return (
<Button
theme={ThemeButton.CLEAR}
theme={ButtonTheme.CLEAR}
className={classNames('', {}, [className])}
onClick={toggleTheme}
>
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/LangSwitcher/LangSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTranslation } from 'react-i18next';
import React from 'react';
import { classNames } from 'shared/lib/classNames/classNames';
import { Button, ThemeButton } from 'shared/ui/Button/Button';
import { Button, ButtonTheme } from 'shared/ui/Button/Button';

interface LangSwitcherProps {
className?: string;
Expand All @@ -17,7 +17,7 @@ export const LangSwitcher = ({ className }: LangSwitcherProps) => {
return (
<Button
className={classNames('', {}, [className])}
theme={ThemeButton.CLEAR}
theme={ButtonTheme.CLEAR}
onClick={toggle}
>
{t('language')}
Expand Down
6 changes: 6 additions & 0 deletions src/widgets/Sidebar/ui/Sidebar/Sidebar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@
.lang {
margin-left: 20px;
}

.collapseBtn {
position: absolute;
right: -32px;
bottom: 32px;
}
10 changes: 7 additions & 3 deletions src/widgets/Sidebar/ui/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { classNames } from 'shared/lib/classNames/classNames';
import { useState } from 'react';
import { ThemeSwitcher } from 'shared/ui/ThemeSwitcher';
import { LangSwitcher } from 'shared/ui/LangSwitcher/LangSwitcher';
import { Button } from 'shared/ui/Button/Button';
import { Button, ButtonSize, ButtonTheme } from 'shared/ui/Button/Button';
import cls from './Sidebar.module.scss';

interface SidebarProps {
className?: string;
className?: string;
}

export const Sidebar = ({ className }: SidebarProps) => {
Expand All @@ -24,8 +24,12 @@ export const Sidebar = ({ className }: SidebarProps) => {
<Button
data-testid="sidebar-toggle"
onClick={onToggle}
className={cls.collapseBtn}
theme={ButtonTheme.BACKGROUND_INVERTED}
square
size={ButtonSize.L}
>
toggle
{collapsed ? '>' : '<'}
</Button>
<div className={cls.switchers}>
<ThemeSwitcher />
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/ThemeSwitcher/ui/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { classNames } from 'shared/lib/classNames/classNames';
import { Theme, useTheme } from 'app/providers/ThemeProvider';
import { Button, ThemeButton } from 'shared/ui/Button/Button';
import { Button, ButtonTheme } from 'shared/ui/Button/Button';
import LightIcon from '../../../shared/assets/icons/theme-light.svg';
import DarkIcon from '../../../shared/assets/icons/theme-dark.svg';

Expand All @@ -14,7 +14,7 @@ export const ThemeSwitcher = ({ className }: ThemeSwitcherProps) => {

return (
<Button
theme={ThemeButton.CLEAR}
theme={ButtonTheme.CLEAR}
className={classNames('', {}, [className])}
onClick={toggleTheme}
>
Expand Down
Binary file added storybook-static/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions storybook-static/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"generatedAt":1698944214657,"builder":{"name":"webpack5"},"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":false,"hasStorybookEslint":false,"refCount":0,"packageManager":{"type":"yarn","version":"1.22.15"},"storybookVersion":"6.5.16","language":"typescript","storybookPackages":{"@storybook/addon-actions":{"version":"6.5.16"},"@storybook/builder-webpack5":{"version":"6.5.16"},"@storybook/manager-webpack5":{"version":"6.5.16"},"@storybook/react":{"version":"6.5.16"},"@storybook/testing-library":{"version":"0.0.9"}},"framework":{"name":"react"},"addons":{"@storybook/addon-links":{"version":"6.5.16"},"@storybook/addon-essentials":{"version":"6.5.16"},"@storybook/addon-interactions":{"version":"6.5.16"}}}

0 comments on commit 9b99cfe

Please sign in to comment.