-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom-button): split custom button by desktop / mobile (#1472)
* feat(custom-button): slit custom button by desktop / mobile
- Loading branch information
1 parent
98cd512
commit cefed5b
Showing
16 changed files
with
1,377 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@alfalab/core-components-custom-button': minor | ||
--- | ||
|
||
Добавлена возможность импортировать desktop / mobile по отдельности |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,16 @@ | ||
import React, { AnchorHTMLAttributes, ButtonHTMLAttributes } from 'react'; | ||
import cn from 'classnames'; | ||
import React, { forwardRef } from 'react'; | ||
|
||
import { Button, ButtonProps } from '@alfalab/core-components-button'; | ||
import { Button } from '@alfalab/core-components-button'; | ||
|
||
import styles from './index.module.css'; | ||
import { BaseCustomButton } from './components/base-custom-button'; | ||
import { CustomButtonProps } from './types/props'; | ||
|
||
const DEFAULT_BUTTON_COLOR = '#FF45C3'; | ||
const DEFAULT_CONTENT_COLOR = 'white'; | ||
|
||
export type ComponentProps = Omit<ButtonProps, 'view' | 'colors'> & { | ||
/** | ||
* Цвет кнопки | ||
*/ | ||
backgroundColor?: string; | ||
|
||
/** | ||
* Цвет контента | ||
*/ | ||
contentColor?: 'black' | 'white' | 'static-black' | 'static-white'; | ||
|
||
/** | ||
* Затемнение или осветление кнопки при hover и active | ||
*/ | ||
stateType?: 'darkening' | 'lightening' | 'static-darkening' | 'static-lightening'; | ||
|
||
/** | ||
* Блокировка кнопки | ||
*/ | ||
disabled?: boolean; | ||
|
||
/** | ||
* Тип цвета для заблокированного состояния | ||
* @default default | ||
*/ | ||
disableType?: 'default' | 'static' | 'inverted' | 'static-inverted'; | ||
}; | ||
|
||
type AnchorButtonProps = ComponentProps & AnchorHTMLAttributes<HTMLAnchorElement>; | ||
type NativeButtonProps = ComponentProps & ButtonHTMLAttributes<HTMLButtonElement>; | ||
|
||
export type CustomButtonProps = Partial<AnchorButtonProps | NativeButtonProps>; | ||
|
||
export const CustomButton = React.forwardRef< | ||
HTMLAnchorElement | HTMLButtonElement, | ||
CustomButtonProps | ||
>( | ||
( | ||
{ | ||
children, | ||
className, | ||
loading, | ||
backgroundColor = DEFAULT_BUTTON_COLOR, | ||
contentColor = DEFAULT_CONTENT_COLOR, | ||
stateType = 'darkening', | ||
disableType = 'default', | ||
...restProps | ||
}, | ||
ref, | ||
) => { | ||
const buttonProps = { | ||
style: { | ||
...(!restProps.disabled && { background: backgroundColor }), | ||
}, | ||
...restProps, | ||
}; | ||
|
||
const buttonClassName = cn( | ||
styles.customButton, | ||
styles.border, | ||
className, | ||
styles[contentColor], | ||
styles[stateType], | ||
styles[`disableType-${disableType}`], | ||
); | ||
|
||
return ( | ||
<Button | ||
{...buttonProps} | ||
view='primary' | ||
ref={ref} | ||
className={buttonClassName} | ||
loading={loading} | ||
> | ||
{children} | ||
</Button> | ||
); | ||
}, | ||
export const CustomButton = forwardRef<HTMLAnchorElement | HTMLButtonElement, CustomButtonProps>( | ||
({ children, ...restProps }, ref) => ( | ||
<BaseCustomButton ref={ref} {...restProps} componentButton={Button}> | ||
{children} | ||
</BaseCustomButton> | ||
), | ||
); | ||
|
||
CustomButton.displayName = 'CustomButton'; |
Oops, something went wrong.