Skip to content

Commit

Permalink
feat(ToolButton): apply design fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
inomdzhon committed Aug 30, 2024
1 parent fd2af58 commit 3cfbad6
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 30 deletions.
15 changes: 10 additions & 5 deletions packages/vkui/src/components/ToolButton/ToolButton.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
text-decoration: none;
border: 0;
margin: 0;
padding: 10px;
padding: var(--vkui--spacing_size_m);
border-radius: var(--vkui--size_border_radius_paper--regular);
inline-size: 100%;
flex-grow: 1;
Expand All @@ -17,6 +17,10 @@
line-height: var(--vkui--font_caption1--line_height--regular);
}

.ToolButton--padding-size-xl {
padding: var(--vkui--spacing_size_xl);
}

.ToolButton--rounded {
border-radius: var(--vkui--size_border_radius_rounded--regular);
}
Expand Down Expand Up @@ -71,15 +75,15 @@
}

.ToolButton--mode-primary.ToolButton--appearance-neutral {
background-color: var(--vkui--color_background_secondary);
background-color: var(--vkui--color_background_modal_inverse);
}

.ToolButton--mode-primary.ToolButton--appearance-neutral.ToolButton--hover {
background-color: var(--vkui--color_background_secondary--hover);
background-color: var(--vkui--color_background_modal_inverse--hover);
}

.ToolButton--mode-primary.ToolButton--appearance-neutral.ToolButton--active {
background-color: var(--vkui--color_background_secondary--active);
background-color: var(--vkui--color_background_modal_inverse--active);
}

/* Mode = Secondary */
Expand Down Expand Up @@ -122,7 +126,8 @@
color: var(--vkui--color_text_primary);
}

.ToolButton--mode-primary.ToolButton--appearance-accent {
.ToolButton--mode-primary.ToolButton--appearance-accent,
.ToolButton--mode-primary.ToolButton--appearance-neutral {
color: var(--vkui--color_text_contrast_themed);
}

Expand Down
24 changes: 21 additions & 3 deletions packages/vkui/src/components/ToolButton/ToolButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { render, screen } from '@testing-library/react';
import { Icon20Add, Icon24Add } from '@vkontakte/icons';
import { baselineComponent } from '../../testing/utils';
import { ToolButton, type ToolButtonProps } from './ToolButton';
import { getRoundedClassName, ToolButton, type ToolButtonProps } from './ToolButton';

const ToolButtonTest = (props: Omit<ToolButtonProps, 'IconCompact' | 'IconRegular'>) => (
<ToolButton data-testid="custom-btn" IconCompact={Icon20Add} IconRegular={Icon24Add} {...props} />
<ToolButton
data-testid="custom-btn"
IconCompact={Icon20Add}
IconRegular={Icon24Add}
rounded
{...props}
/>
);
const button = () => screen.getByTestId('custom-btn');

describe('ToolButton', () => {
describe(ToolButton, () => {
baselineComponent((props) => <ToolButtonTest {...props}>ToolButton</ToolButtonTest>);

it('Component: ToolButton is handled as a native button', () => {
Expand All @@ -21,3 +27,15 @@ describe('ToolButton', () => {
expect(button().tagName.toLowerCase()).toMatch('a');
});
});

describe(getRoundedClassName, () => {
it('should return class name', () => {
expect(getRoundedClassName('row', true)).not.toBeUndefined();
expect(getRoundedClassName('row', false)).not.toBeUndefined();
expect(getRoundedClassName('column', false)).not.toBeUndefined();
});

it('should return undefined', () => {
expect(getRoundedClassName('column', true)).toBeUndefined();
});
});
18 changes: 16 additions & 2 deletions packages/vkui/src/components/ToolButton/ToolButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface ToolButtonProps extends TappableProps, AdaptiveIconRendererProp
/**
* Задаёт `50%` закругления для контейнера.
*
* > Note: игнорируется при передаче `children`.
* > Note: игнорируется при `direction="column"` если передан `children`.
*/
rounded?: boolean;
}
Expand Down Expand Up @@ -71,7 +71,7 @@ export const ToolButton = ({
className={classNames(
className,
styles['ToolButton'],
rounded && !hasChildren && styles['ToolButton--rounded'],
rounded && getRoundedClassName(direction, hasChildren),
stylesMode[mode],
stylesAppearance[appearance],
stylesDirection[direction],
Expand All @@ -84,3 +84,17 @@ export const ToolButton = ({
</Tappable>
);
};

export function getRoundedClassName(
direction: 'row' | 'column',
hasChildren: boolean,
): string | undefined {
switch (direction) {
case 'row':
return hasChildren
? classNames(styles['ToolButton--rounded'], styles['ToolButton--padding-size-xl'])
: styles['ToolButton--rounded'];
case 'column':
return hasChildren ? undefined : styles['ToolButton--rounded'];
}
}
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.
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.

0 comments on commit 3cfbad6

Please sign in to comment.