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(custom-button): update docs, change colors #1452

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/tender-ladybugs-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@alfalab/core-components-custom-button': minor
---

Изменены цвета заблокированного состояния
fulcanellee marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 27 additions & 0 deletions packages/custom-button/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,33 @@ describe('CustomButton', () => {
const { container } = render(<CustomButton contentColor='black' />);
expect(container.firstElementChild).toHaveClass('black');
});

describe('disableType test', () => {
it('should have `disableType_default` class', () => {
const { container } = render(<CustomButton disableType='default' />);
expect(container.firstElementChild).toHaveClass('disableType-default');
});

it('should have `disableType_static` class', () => {
const { container } = render(<CustomButton disableType='static' />);
expect(container.firstElementChild).toHaveClass('disableType-static');
});

it('should have `disableType_inverted` class', () => {
const { container } = render(<CustomButton disableType='inverted' />);
expect(container.firstElementChild).toHaveClass('disableType-inverted');
});

it('should have `disableType_static-inverted` class', () => {
const { container } = render(<CustomButton disableType='static-inverted' />);
expect(container.firstElementChild).toHaveClass('disableType-static-inverted');
});
});

it('should have custom className', () => {
const { container } = render(<CustomButton className='customClass' />);
expect(container.firstElementChild).toHaveClass('customClass');
});
});

it('should unmount without errors', () => {
Expand Down
19 changes: 15 additions & 4 deletions packages/custom-button/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ export type ComponentProps = Omit<ButtonProps, 'view' | 'colors'> & {
* Затемнение или осветление кнопки при hover и active
*/
stateType?: 'darkening' | 'lightening' | 'static-darkening' | 'static-lightening';

/**
* Блокировка кнопки
*/
disabled?: boolean;

/**
* Тип цвета для заблокированного состояния
fulcanellee marked this conversation as resolved.
Show resolved Hide resolved
*/
disableType?: 'default' | 'static' | 'inverted' | 'static-inverted';
};

type AnchorButtonProps = ComponentProps & AnchorHTMLAttributes<HTMLAnchorElement>;
Expand All @@ -42,12 +52,15 @@ export const CustomButton = React.forwardRef<
backgroundColor = DEFAULT_BUTTON_COLOR,
contentColor = DEFAULT_CONTENT_COLOR,
stateType = 'darkening',
disableType = 'default',
...restProps
},
ref,
) => {
const buttonProps = {
style: { background: backgroundColor },
style: {
...(!restProps.disabled && { background: backgroundColor }),
},
...restProps,
};

Expand All @@ -57,9 +70,7 @@ export const CustomButton = React.forwardRef<
className,
styles[contentColor],
styles[stateType],
{
[styles.customLoading]: loading,
},
styles[`disableType-${disableType}`],
);

return (
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions packages/custom-button/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Object {
"baseElement": <body>
<div>
<button
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening"
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening disableType-default"
style="background: rgb(255, 69, 195);"
type="button"
/>
</div>
</body>,
"container": <div>
<button
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening"
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening disableType-default"
style="background: rgb(255, 69, 195);"
type="button"
/>
Expand Down Expand Up @@ -79,15 +79,15 @@ Object {
"baseElement": <body>
<div>
<button
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening"
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening disableType-default"
style="background: rgb(255, 69, 195);"
type="button"
/>
</div>
</body>,
"container": <div>
<button
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening"
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening disableType-default"
style="background: rgb(255, 69, 195);"
type="button"
/>
Expand Down Expand Up @@ -152,15 +152,15 @@ Object {
"baseElement": <body>
<div>
<button
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border black darkening"
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border black darkening disableType-default"
style="background: rgb(255, 69, 195);"
type="button"
/>
</div>
</body>,
"container": <div>
<button
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border black darkening"
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border black darkening disableType-default"
style="background: rgb(255, 69, 195);"
type="button"
/>
Expand Down Expand Up @@ -225,15 +225,15 @@ Object {
"baseElement": <body>
<div>
<button
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening"
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening disableType-default"
style="background: rgb(0, 255, 0);"
type="button"
/>
</div>
</body>,
"container": <div>
<button
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening"
class="component primary size-56 hug size-56 component primary component primary iconOnly customButton border white darkening disableType-default"
style="background: rgb(0, 255, 0);"
type="button"
/>
Expand Down Expand Up @@ -298,7 +298,7 @@ Object {
"baseElement": <body>
<div>
<button
class="component primary size-56 hug size-56 component primary component primary iconOnly loading customButton border white darkening customLoading"
class="component primary size-56 hug size-56 component primary component primary iconOnly loading customButton border white darkening disableType-default"
disabled=""
style="background: rgb(255, 69, 195);"
type="button"
Expand Down Expand Up @@ -364,7 +364,7 @@ Object {
</body>,
"container": <div>
<button
class="component primary size-56 hug size-56 component primary component primary iconOnly loading customButton border white darkening customLoading"
class="component primary size-56 hug size-56 component primary component primary iconOnly loading customButton border white darkening disableType-default"
disabled=""
style="background: rgb(255, 69, 195);"
type="button"
Expand Down
Loading
Loading