Skip to content

Commit

Permalink
chore: deprecate label prop and revert theme variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ishmatova committed Nov 11, 2021
1 parent bbfe750 commit e6834bd
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/react-ui/components/Checkbox/Checkbox.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const styles = memoizeStyle({
caption(t: Theme) {
return css`
color: ${t.checkboxTextColorDefault};
padding-left: ${t.checkboxCaptionGap};
padding-left: ${t.checkboxLabelGap};
`;
},

Expand Down
4 changes: 2 additions & 2 deletions packages/react-ui/components/Radio/Radio.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ export const styles = memoizeStyle({

caption(t: Theme) {
return css`
display: ${t.radioCaptionDisplay};
display: ${t.radioLabelDisplay};
line-height: ${t.radioLineHeight};
margin-left: ${t.radioCaptionGap};
margin-left: ${t.radioLabelGap};
white-space: normal;
font-size: ${t.radioFontSize};
color: ${t.radioTextColor};
Expand Down
18 changes: 9 additions & 9 deletions packages/react-ui/components/Switcher/Switcher.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ export const styles = memoizeStyle({

captionSmall(t: Theme) {
return css`
margin-right: ${t.switcherCaptionGapSmall};
font-size: ${t.switcherCaptionFontSizeSmall};
line-height: ${t.switcherCaptionLineHeightSmall};
margin-right: ${t.switcherLabelGapSmall};
font-size: ${t.switcherLabelFontSizeSmall};
line-height: ${t.switcherLabelLineHeightSmall};
`;
},

captionMedium(t: Theme) {
return css`
margin-right: ${t.switcherCaptionGapMedium};
font-size: ${t.switcherCaptionFontSizeMedium};
line-height: ${t.switcherCaptionLineHeightMedium};
margin-right: ${t.switcherLabelGapMedium};
font-size: ${t.switcherLabelFontSizeMedium};
line-height: ${t.switcherLabelLineHeightMedium};
`;
},

captionLarge(t: Theme) {
return css`
margin-right: ${t.switcherCaptionGapLarge};
font-size: ${t.switcherCaptionFontSizeLarge};
line-height: ${t.switcherCaptionLineHeightLarge};
margin-right: ${t.switcherLabelGapLarge};
font-size: ${t.switcherLabelFontSizeLarge};
line-height: ${t.switcherLabelLineHeightLarge};
`;
},

Expand Down
17 changes: 16 additions & 1 deletion packages/react-ui/components/Switcher/Switcher.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import warning from 'warning';

import { isKeyArrowHorizontal, isKeyArrowLeft, isKeyEnter } from '../../lib/events/keyboard/identifiers';
import { Group } from '../Group';
Expand All @@ -15,6 +16,8 @@ import { getSwitcherTheme } from './switcherTheme';

export type SwitcherSize = ButtonSize;

let labelWarningShown = false;

export interface SwitcherProps extends CommonProps {
/**
* Список строк или список элементов типа `{ label: string, value: string }`
Expand All @@ -24,6 +27,10 @@ export interface SwitcherProps extends CommonProps {
value?: string;

onValueChange?: (value: string) => void;
/**
* @deprecated используйте проп `caption` вместо `label`.
*/
label?: string;

caption?: string;

Expand Down Expand Up @@ -62,6 +69,12 @@ export class Switcher extends React.Component<SwitcherProps, SwitcherState> {
caption: PropTypes.string,
value: PropTypes.string,
onValueChange: PropTypes.func,
label(props: SwitcherProps) {
if (props.label && !labelWarningShown) {
warning(false, `[Switcher]: prop 'label' is deprecated. Please, use 'caption' instead. `);
labelWarningShown = true;
}
},
};

public state: SwitcherState = {
Expand Down Expand Up @@ -99,7 +112,9 @@ export class Switcher extends React.Component<SwitcherProps, SwitcherState> {
return (
<CommonWrapper {...this.props}>
<div>
{this.props.caption ? <div className={captionClassName}>{this.props.caption}</div> : null}
{this.props.caption || this.props.label ? (
<div className={captionClassName}>{this.props.caption || this.props.label}</div>
) : null}
<div className={styles.wrap()}>
<input {...inputProps} />
<div className={listClassName}>
Expand Down
24 changes: 12 additions & 12 deletions packages/react-ui/internal/themes/DefaultTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ export class DefaultTheme {
return this.controlLineHeightSmall;
}
public static checkboxBoxSize = '16px';
public static checkboxCaptionGap = '10px';
public static checkboxLabelGap = '10px';
public static checkboxPaddingY = '0';
public static checkboxBgStart = '#fdfdfd';
public static checkboxBgEnd = '#ededed';
Expand Down Expand Up @@ -1259,7 +1259,7 @@ export class DefaultTheme {
public static get radioLineHeight() {
return this.controlLineHeightSmall;
}
public static radioCaptionGap = '9px';
public static radioLabelGap = '9px';
public static radioPaddingY = '0';
public static radioVerticalAlign = '-2px';
public static radioBgImage = 'linear-gradient(-180deg, #fff 0, #ebebeb 100%)';
Expand Down Expand Up @@ -1300,7 +1300,7 @@ export class DefaultTheme {
public static get radioDisabledShadow() {
return `0 0 0 ${this.radioBorderWidth} rgba(0, 0, 0, 0.15)`;
}
public static radioCaptionDisplay = 'inline-table';
public static radioLabelDisplay = 'inline-table';
public static radioBorderWidthCompensation = '0px';
public static radioMarginY = '2px';
//#endregion
Expand Down Expand Up @@ -1385,15 +1385,15 @@ export class DefaultTheme {
return this.textColorDefault;
}
public static switcherOutlineWidth = '2px';
public static switcherCaptionFontSizeSmall = 'inherit';
public static switcherCaptionFontSizeMedium = 'inherit';
public static switcherCaptionFontSizeLarge = 'inherit';
public static switcherCaptionLineHeightSmall = 'inherit';
public static switcherCaptionLineHeightMedium = 'inherit';
public static switcherCaptionLineHeightLarge = 'inherit';
public static switcherCaptionGapSmall = '15px';
public static switcherCaptionGapMedium = '15px';
public static switcherCaptionGapLarge = '15px';
public static switcherLabelFontSizeSmall = 'inherit';
public static switcherLabelFontSizeMedium = 'inherit';
public static switcherLabelFontSizeLarge = 'inherit';
public static switcherLabelLineHeightSmall = 'inherit';
public static switcherLabelLineHeightMedium = 'inherit';
public static switcherLabelLineHeightLarge = 'inherit';
public static switcherLabelGapSmall = '15px';
public static switcherLabelGapMedium = '15px';
public static switcherLabelGapLarge = '15px';
public static get switcherButtonPaddingXSmall() {
return this.btnPaddingXSmall;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ui/internal/themes/FlatTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class FlatTheme extends (class {} as typeof DefaultThemeInternal) {
public static get radioDisabledShadow() {
return `0 0 0 ${this.radioBorderWidth} ${this.borderColorDisabled}`;
}
public static radioCaptionDisplay = 'inline-block';
public static radioLabelDisplay = 'inline-block';
public static get radioHoverBg() {
return this.checkboxHoverBg;
}
Expand Down
22 changes: 11 additions & 11 deletions packages/react-ui/internal/themes/Theme8px.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class Theme8px extends (class {} as typeof DefaultThemeInternal) {
public static get checkboxFontSize() {
return this.fontSizeSmall;
}
public static checkboxCaptionGap = '8px';
public static checkboxLabelGap = '8px';
public static get checkboxPaddingY() {
const controlHeight = parseInt(this.controlHeightSmall, 10) || 0;
const lineHeight = parseInt(this.checkboxLineHeight, 10) || 0;
Expand Down Expand Up @@ -353,7 +353,7 @@ export class Theme8px extends (class {} as typeof DefaultThemeInternal) {
public static get radioFontSize() {
return this.fontSizeSmall;
}
public static radioCaptionGap = '8px';
public static radioLabelGap = '8px';
public static get radioPaddingY() {
const controlHeight = parseInt(this.controlHeightSmall, 10) || 0;
const lineHeight = parseInt(this.radioLineHeight, 10) || 0;
Expand Down Expand Up @@ -405,31 +405,31 @@ export class Theme8px extends (class {} as typeof DefaultThemeInternal) {
public static get switcherOutlineWidth() {
return this.btnOutlineWidth;
}
public static get switcherCaptionFontSizeSmall() {
public static get switcherLabelFontSizeSmall() {
return this.btnFontSizeSmall;
}
public static get switcherCaptionFontSizeMedium() {
public static get switcherLabelFontSizeMedium() {
return this.btnFontSizeMedium;
}
public static get switcherCaptionFontSizeLarge() {
public static get switcherLabelFontSizeLarge() {
return this.btnFontSizeLarge;
}
public static get switcherCaptionLineHeightSmall() {
public static get switcherLabelLineHeightSmall() {
return this.btnLineHeightSmall;
}
public static get switcherCaptionLineHeightMedium() {
public static get switcherLabelLineHeightMedium() {
return this.btnLineHeightMedium;
}
public static get switcherCaptionLineHeightLarge() {
public static get switcherLabelLineHeightLarge() {
return this.btnLineHeightLarge;
}
public static get switcherCaptionGapSmall() {
public static get switcherLabelGapSmall() {
return this.btnPaddingXSmall;
}
public static get switcherCaptionGapMedium() {
public static get switcherLabelGapMedium() {
return this.btnPaddingXMedium;
}
public static get switcherCaptionGapLarge() {
public static get switcherLabelGapLarge() {
return this.btnPaddingXLarge;
}
public static switcherButtonPaddingXSmall = '7px';
Expand Down

0 comments on commit e6834bd

Please sign in to comment.