feat: Добавлен переиспользуемый компонент кнопки с задаваемыми размерами, вариантами и цветовыми схемами. Добавлен декоратор стилей для сторибука, установлена библиотека для работы с классами

This commit is contained in:
Ilia Mashkov
2025-11-20 09:26:01 +03:00
parent e440005e60
commit 5c869eb215
12 changed files with 281 additions and 2 deletions

View File

@@ -6,6 +6,7 @@
--color-bg: #F4F5F9;
--color-border: rgb(66 86 122 / 10%);
--color-blue: #3877EE;
--color-white: #FFFFFF;
// Градиенты
--gradient-primary: linear-gradient(to right, #3877EE, #EF5DA8);

View File

@@ -0,0 +1,3 @@
<svg width="9" height="14" viewBox="0 0 9 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M7.66418 0.707108L1.41419 6.95711L7.66418 13.2071" stroke="#42567A" stroke-width="2"/>
</svg>

After

Width:  |  Height:  |  Size: 197 B

View File

@@ -0,0 +1,78 @@
.button {
display: inline-flex;
align-items: center;
justify-content: center;
border: none;
background: transparent;
cursor: pointer;
transition: all 0.3s ease;
padding: 0;
outline: none;
font-family: var(--font-family-main);
&:disabled {
opacity: 0.5;
cursor: not-allowed;
}
// Variants
&.round {
border-radius: 50%;
aspect-ratio: 1;
}
&.regular {
border-radius: 1em;
padding: 0.5em 1em;
}
// Sizes
&.small {
height: 40px;
font-size: 14px;
}
&.medium {
height: 50px;
font-size: 18px;
}
&.large {
height: 60px;
font-size: 24px;
}
// Color Schemes
&.primary {
$color-primary: var(--color-primary);
background-color: transparent;
color: $color-primary;
border: 1px solid $color-primary;
&:hover:not(:disabled) {
background-color: var(--color-white);
}
}
&.secondary {
$color-blue: var(--color-blue);
background-color: var(--color-white);
color: $color-blue;
box-shadow: 0px 0px 15px rgb($color-blue / 10%);
}
// Icon handling
.icon {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
svg {
width: 40%;
height: 40%;
object-fit: contain;
}
}
}

View File

@@ -0,0 +1,102 @@
import type { Meta, StoryObj } from '@storybook/react'
import { Button } from './Button'
import ChevronLeftIcon from '@/shared/assets/chevron--left.svg'
const meta = {
title: 'Shared/Button',
component: Button,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
variant: {
control: 'select',
options: ['round', 'regular'],
description: 'Вариант внешнего вида',
},
size: {
control: 'select',
options: ['small', 'medium', 'large'],
description: 'Размер кнопки',
},
colorScheme: {
control: 'select',
options: ['primary', 'secondary'],
description: 'Цветовая схема',
},
disabled: {
control: 'boolean',
description: 'Активность кнопки',
},
onClick: { action: 'clicked' },
},
} satisfies Meta<typeof Button>
export default meta
type Story = StoryObj<typeof meta>
/**
* Базовая кнопка
*/
export const Default: Story = {
args: {
children: 'Submit',
variant: 'regular',
size: 'medium',
colorScheme: 'primary',
},
}
/**
* Альтернативная цветовая схема
*/
export const SecondaryColorScheme: Story = {
args: {
children: 'Submit',
variant: 'regular',
size: 'medium',
colorScheme: 'secondary',
},
}
/**
* Маленькая кнопка
*/
export const Small: Story = {
args: {
children: 'Submit',
size: 'small',
},
}
/**
* Большая кнопка
*/
export const Large: Story = {
args: {
children: 'Submit',
size: 'large',
},
}
/**
* Кнопка с SVG иконкой (шеврон)
*/
export const WithIcon: Story = {
args: {
children: <ChevronLeftIcon />,
variant: 'round',
size: 'medium',
},
}
/**
* Отключенная кнопка
*/
export const Disabled: Story = {
args: {
children: 'Submit',
disabled: true,
},
}

View File

@@ -0,0 +1,60 @@
import { ButtonHTMLAttributes, memo, PropsWithChildren } from 'react'
import classNames from 'classnames'
import styles from './Button.module.scss'
export type ButtonVariant = 'round' | 'regular'
export type ButtonSize = 'small' | 'medium' | 'large'
export type ButtonColorScheme = 'primary' | 'secondary'
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, PropsWithChildren {
/**
* Вариант внешнего вида кнопки
* @default 'round'
*/
variant?: ButtonVariant
/**
* Размер кнопки
* @default 'medium'
*/
size?: ButtonSize
/**
* Цветовая схема
* @default 'timeframe'
*/
colorScheme?: ButtonColorScheme
}
/**
* Универсальный компонент кнопки для использования в слайдерах и других элементах интерфейса.
* Поддерживает различные варианты отображения, размеры и цветовые схемы.
*/
export const Button = memo((props: ButtonProps) => {
const {
className,
children,
variant = 'round',
size = 'medium',
colorScheme = 'primary',
disabled,
...otherProps
} = props
const mods: Record<string, boolean | undefined> = {
[styles[variant]]: true,
[styles[size]]: true,
[styles[colorScheme]]: true,
}
return (
<button
type="button"
className={classNames(styles.button, mods, className)}
disabled={disabled}
{...otherProps}
>
{children}
</button>
)
})
Button.displayName = 'Button'

View File

@@ -0,0 +1,2 @@
export { Button } from './Button'
export type { ButtonProps, ButtonVariant, ButtonSize, ButtonColorScheme } from './Button'

2
src/shared/ui/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export { Button } from './Button'
export type { ButtonProps } from './Button'