Skip to content

Commit f4b1ba8

Browse files
author
Juli Ovechkina
authored
feat(Button): add prop width (#346)
Release-As: 2.19.0
1 parent 95c94d1 commit f4b1ba8

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/components/Button/Button.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,12 @@ $block: '.#{$ns}button-block';
5353
--btn-image-margin: 25px;
5454
}
5555
}
56+
57+
&_width {
58+
&_max {
59+
#{$block}__text {
60+
width: 100%;
61+
}
62+
}
63+
}
5664
}

src/components/Button/Button.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const Button = (props: ButtonProps) => {
3737
img,
3838
onClick: onClickOrigin,
3939
text,
40+
width,
4041
...rest
4142
} = props;
4243
const defaultImgPosition = 'left';
@@ -53,14 +54,16 @@ const Button = (props: ButtonProps) => {
5354
[handleMetrika, metrikaGoals, pixelEvents, handleAnalytics, analyticsEvents, onClickOrigin],
5455
);
5556

57+
const buttonModifiers = {size, theme, width};
58+
5659
const buttonImg =
5760
img instanceof Object
5861
? {url: img.url, position: img.position || defaultImgPosition, alt: img.alt}
5962
: {url: img, position: defaultImgPosition};
6063

6164
const buttonClass = img
62-
? b({position: buttonImg.position, size, theme}, className)
63-
: b({size, theme}, className);
65+
? b({position: buttonImg.position, ...buttonModifiers}, className)
66+
: b({...buttonModifiers}, className);
6467

6568
const buttonProps = {
6669
...rest,
@@ -91,6 +94,7 @@ const Button = (props: ButtonProps) => {
9194
view={toCommonView(buttonTheme as OldButtonTheme)}
9295
size={toCommonSize(size as OldButtonSize)}
9396
href={url ? setUrlTld(url, tld) : undefined}
97+
width={width}
9498
{...buttonProps}
9599
>
96100
{icon && buttonImg.position === 'left' ? icon : null}

src/components/Button/__stories__/Button.stories.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,21 @@ const ThemesSizesTemplate: Story<ButtonProps> = (args) => (
6363
</Fragment>
6464
);
6565

66+
const WidthTemplate: Story<ButtonProps> = (args) => (
67+
<Row>
68+
<Col>
69+
<Button {...args} width="auto" />
70+
</Col>
71+
<Col>
72+
<Button {...args} width="max" />
73+
</Col>
74+
</Row>
75+
);
76+
6677
export const Default = DefaultTemplate.bind({});
6778
export const ThemesSizes = ThemesSizesTemplate.bind({});
79+
export const Width = WidthTemplate.bind({});
6880

6981
Default.args = data.default.content as ButtonProps;
7082
ThemesSizes.args = data.themesSizes.content as ButtonProps;
83+
Width.args = data.themesSizes.content as ButtonProps;

src/models/constructor-items/common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {CSSProperties, ReactNode} from 'react';
22

3-
import {ButtonSize, ButtonView} from '@gravity-ui/uikit';
3+
import {ButtonView, ButtonProps as UikitButtonProps} from '@gravity-ui/uikit';
44

55
import {ThemeSupporting} from '../../utils/theme';
66
import {AnalyticsEventsBase, ClassNameProps, PixelEventType} from '../common';
@@ -177,11 +177,10 @@ export type ButtonTheme =
177177
| 'scale'
178178
| 'monochrome';
179179

180-
export interface ButtonProps extends AnalyticsEventsBase {
180+
export interface ButtonProps extends AnalyticsEventsBase, Pick<UikitButtonProps, 'size' | 'width'> {
181181
text: string;
182182
url: string;
183183
primary?: boolean;
184-
size?: ButtonSize;
185184
theme?: ButtonTheme;
186185
img?: ButtonImageProps | string;
187186
metrikaGoals?: MetrikaGoal;
@@ -262,6 +261,7 @@ export type Coordinate = number[];
262261
export interface MapBaseProps {
263262
zoom?: number;
264263
}
264+
265265
export interface GMapProps extends MapBaseProps {
266266
address: string;
267267
}

0 commit comments

Comments
 (0)