Commit 65d97edb by Ivana Huckova Committed by GitHub

Create ComponentSize type and replace ButtonSize with it (#23059)

parent d6b6b0f2
...@@ -2,11 +2,12 @@ import React, { AnchorHTMLAttributes, ButtonHTMLAttributes, useContext } from 'r ...@@ -2,11 +2,12 @@ import React, { AnchorHTMLAttributes, ButtonHTMLAttributes, useContext } from 'r
import { ThemeContext } from '../../themes'; import { ThemeContext } from '../../themes';
import { getButtonStyles } from './styles'; import { getButtonStyles } from './styles';
import { ButtonContent } from './ButtonContent'; import { ButtonContent } from './ButtonContent';
import { ButtonSize, ButtonStyles, ButtonVariant } from './types'; import { ComponentSize } from '../../types/size';
import { ButtonStyles, ButtonVariant } from './types';
import { cx } from 'emotion'; import { cx } from 'emotion';
type CommonProps = { type CommonProps = {
size?: ButtonSize; size?: ComponentSize;
variant?: ButtonVariant; variant?: ButtonVariant;
/** /**
* icon prop is a temporary solution. It accepts legacy icon class names for the icon to be rendered. * icon prop is a temporary solution. It accepts legacy icon class names for the icon to be rendered.
......
import React from 'react'; import React from 'react';
import { css } from 'emotion'; import { css } from 'emotion';
import { stylesFactory, useTheme } from '../../themes'; import { stylesFactory, useTheme } from '../../themes';
import { ComponentSize } from '../../types/size';
import { GrafanaTheme } from '@grafana/data'; import { GrafanaTheme } from '@grafana/data';
import { ButtonSize } from './types';
const getStyles = stylesFactory((theme: GrafanaTheme) => ({ const getStyles = stylesFactory((theme: GrafanaTheme) => ({
content: css` content: css`
...@@ -26,7 +26,7 @@ type Props = { ...@@ -26,7 +26,7 @@ type Props = {
icon?: string; icon?: string;
className?: string; className?: string;
children: React.ReactNode; children: React.ReactNode;
size?: ButtonSize; size?: ComponentSize;
}; };
export function ButtonContent(props: Props) { export function ButtonContent(props: Props) {
......
import tinycolor from 'tinycolor2'; import tinycolor from 'tinycolor2';
import { css } from 'emotion'; import { css } from 'emotion';
import { selectThemeVariant, stylesFactory } from '../../themes'; import { selectThemeVariant, stylesFactory } from '../../themes';
import { StyleDeps, ButtonSize } from './types'; import { ComponentSize } from '../../types/size';
import { StyleDeps } from './types';
import { GrafanaTheme } from '@grafana/data'; import { GrafanaTheme } from '@grafana/data';
const buttonVariantStyles = ( const buttonVariantStyles = (
...@@ -116,7 +117,7 @@ type ButtonMeasures = { ...@@ -116,7 +117,7 @@ type ButtonMeasures = {
fontWeight: number; fontWeight: number;
}; };
const calculateMeasures = (theme: GrafanaTheme, size: ButtonSize, textAndIcon: boolean): ButtonMeasures => { const calculateMeasures = (theme: GrafanaTheme, size: ComponentSize, textAndIcon: boolean): ButtonMeasures => {
switch (size) { switch (size) {
case 'sm': { case 'sm': {
return { return {
......
import { GrafanaTheme } from '@grafana/data'; import { GrafanaTheme } from '@grafana/data';
import { ComponentSize } from '../../types/size';
export type ButtonVariant = 'primary' | 'secondary' | 'danger' | 'inverse' | 'transparent' | 'destructive' | 'link'; export type ButtonVariant = 'primary' | 'secondary' | 'danger' | 'inverse' | 'transparent' | 'destructive' | 'link';
export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg';
export interface StyleDeps { export interface StyleDeps {
theme: GrafanaTheme; theme: GrafanaTheme;
size: ButtonSize; size: ComponentSize;
variant: ButtonVariant; variant: ButtonVariant;
textAndIcon?: boolean; textAndIcon?: boolean;
} }
......
...@@ -3,9 +3,10 @@ import { cx, css } from 'emotion'; ...@@ -3,9 +3,10 @@ import { cx, css } from 'emotion';
import { stylesFactory, withTheme } from '../../themes'; import { stylesFactory, withTheme } from '../../themes';
import { GrafanaTheme } from '@grafana/data'; import { GrafanaTheme } from '@grafana/data';
import { Themeable } from '../../types'; import { Themeable } from '../../types';
import { ComponentSize } from '../../types/size';
import { Button } from '../Button/Button'; import { Button } from '../Button/Button';
import Forms from '../Forms'; import Forms from '../Forms';
import { ButtonVariant, ButtonSize } from '../Button/types'; import { ButtonVariant } from '../Button/types';
const getStyles = stylesFactory((theme: GrafanaTheme) => { const getStyles = stylesFactory((theme: GrafanaTheme) => {
return { return {
...@@ -55,7 +56,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { ...@@ -55,7 +56,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => {
interface Props extends Themeable { interface Props extends Themeable {
className?: string; className?: string;
size?: ButtonSize; size?: ComponentSize;
confirmText?: string; confirmText?: string;
disabled?: boolean; disabled?: boolean;
confirmVariant?: ButtonVariant; confirmVariant?: ButtonVariant;
......
import React, { FC } from 'react'; import React, { FC } from 'react';
import { ConfirmButton } from './ConfirmButton'; import { ConfirmButton } from './ConfirmButton';
import { Button } from '../Button/Button'; import { Button } from '../Button/Button';
import { ButtonSize } from '../Button/types'; import { ComponentSize } from '../../types/size';
interface Props { interface Props {
size?: ButtonSize; size?: ComponentSize;
disabled?: boolean; disabled?: boolean;
onConfirm(): void; onConfirm(): void;
} }
......
...@@ -3,7 +3,7 @@ import { select, text } from '@storybook/addon-knobs'; ...@@ -3,7 +3,7 @@ import { select, text } from '@storybook/addon-knobs';
import { Button, ButtonVariant } from './Button'; import { Button, ButtonVariant } from './Button';
import { withCenteredStory, withHorizontallyCenteredStory } from '../../utils/storybook/withCenteredStory'; import { withCenteredStory, withHorizontallyCenteredStory } from '../../utils/storybook/withCenteredStory';
import { getIconKnob } from '../../utils/storybook/knobs'; import { getIconKnob } from '../../utils/storybook/knobs';
import { ButtonSize } from '../Button/types'; import { ComponentSize } from '../../types/size';
import mdx from './Button.mdx'; import mdx from './Button.mdx';
export default { export default {
...@@ -28,7 +28,7 @@ export const simple = () => { ...@@ -28,7 +28,7 @@ export const simple = () => {
const icon = getIconKnob(); const icon = getIconKnob();
return ( return (
<Button variant={variant as ButtonVariant} size={size as ButtonSize} icon={icon && `fa fa-${icon}`}> <Button variant={variant as ButtonVariant} size={size as ComponentSize} icon={icon && `fa fa-${icon}`}>
{buttonText} {buttonText}
</Button> </Button>
); );
......
...@@ -4,7 +4,8 @@ import tinycolor from 'tinycolor2'; ...@@ -4,7 +4,8 @@ import tinycolor from 'tinycolor2';
import { selectThemeVariant, stylesFactory, ThemeContext } from '../../themes'; import { selectThemeVariant, stylesFactory, ThemeContext } from '../../themes';
import { Button as DefaultButton, LinkButton as DefaultLinkButton } from '../Button/Button'; import { Button as DefaultButton, LinkButton as DefaultLinkButton } from '../Button/Button';
import { getFocusStyle, getPropertiesForButtonSize } from './commonStyles'; import { getFocusStyle, getPropertiesForButtonSize } from './commonStyles';
import { ButtonSize, StyleDeps } from '../Button/types'; import { ComponentSize } from '../../types/size';
import { StyleDeps } from '../Button/types';
import { GrafanaTheme } from '@grafana/data'; import { GrafanaTheme } from '@grafana/data';
const buttonVariantStyles = (from: string, to: string, textColor: string) => css` const buttonVariantStyles = (from: string, to: string, textColor: string) => css`
...@@ -130,7 +131,7 @@ export type ButtonVariant = 'primary' | 'secondary' | 'destructive' | 'link'; ...@@ -130,7 +131,7 @@ export type ButtonVariant = 'primary' | 'secondary' | 'destructive' | 'link';
// These also needs to be different because the ButtonVariant is different // These also needs to be different because the ButtonVariant is different
type CommonProps = { type CommonProps = {
size?: ButtonSize; size?: ComponentSize;
variant?: ButtonVariant; variant?: ButtonVariant;
icon?: string; icon?: string;
className?: string; className?: string;
......
...@@ -3,7 +3,7 @@ import { css } from 'emotion'; ...@@ -3,7 +3,7 @@ import { css } from 'emotion';
import { GrafanaTheme } from '@grafana/data'; import { GrafanaTheme } from '@grafana/data';
import { Button, ButtonVariant, ButtonProps } from '../Button'; import { Button, ButtonVariant, ButtonProps } from '../Button';
import { ButtonSize } from '../../Button/types'; import { ComponentSize } from '../../../types/size';
import { SelectCommonProps, CustomControlProps } from './types'; import { SelectCommonProps, CustomControlProps } from './types';
import { SelectBase } from './SelectBase'; import { SelectBase } from './SelectBase';
import { stylesFactory, useTheme } from '../../../themes'; import { stylesFactory, useTheme } from '../../../themes';
...@@ -13,7 +13,7 @@ import { IconType } from '../../Icon/types'; ...@@ -13,7 +13,7 @@ import { IconType } from '../../Icon/types';
interface ButtonSelectProps<T> extends Omit<SelectCommonProps<T>, 'renderControl' | 'size' | 'prefix'> { interface ButtonSelectProps<T> extends Omit<SelectCommonProps<T>, 'renderControl' | 'size' | 'prefix'> {
icon?: IconType; icon?: IconType;
variant?: ButtonVariant; variant?: ButtonVariant;
size?: ButtonSize; size?: ComponentSize;
} }
interface SelectButtonProps extends Omit<ButtonProps, 'icon'> { interface SelectButtonProps extends Omit<ButtonProps, 'icon'> {
......
import { css } from 'emotion'; import { css } from 'emotion';
import { GrafanaTheme } from '@grafana/data'; import { GrafanaTheme } from '@grafana/data';
import { ButtonSize } from '../Button/types'; import { ComponentSize } from '../../types/size';
export const getFocusCss = (theme: GrafanaTheme) => ` export const getFocusCss = (theme: GrafanaTheme) => `
outline: 2px dotted transparent; outline: 2px dotted transparent;
...@@ -90,7 +90,7 @@ export const inputSizesPixels = (size: string) => { ...@@ -90,7 +90,7 @@ export const inputSizesPixels = (size: string) => {
} }
}; };
export const getPropertiesForButtonSize = (theme: GrafanaTheme, size: ButtonSize) => { export const getPropertiesForButtonSize = (theme: GrafanaTheme, size: ComponentSize) => {
switch (size) { switch (size) {
case 'sm': case 'sm':
return { return {
......
...@@ -4,13 +4,13 @@ import { getLabelStyles } from './Label'; ...@@ -4,13 +4,13 @@ import { getLabelStyles } from './Label';
import { getLegendStyles } from './Legend'; import { getLegendStyles } from './Legend';
import { getFieldValidationMessageStyles } from './FieldValidationMessage'; import { getFieldValidationMessageStyles } from './FieldValidationMessage';
import { getButtonStyles, ButtonVariant } from './Button'; import { getButtonStyles, ButtonVariant } from './Button';
import { ButtonSize } from '../Button/types'; import { ComponentSize } from '../../types/size';
import { getInputStyles } from './Input/Input'; import { getInputStyles } from './Input/Input';
import { getSwitchStyles } from './Switch'; import { getSwitchStyles } from './Switch';
import { getCheckboxStyles } from './Checkbox'; import { getCheckboxStyles } from './Checkbox';
export const getFormStyles = stylesFactory( export const getFormStyles = stylesFactory(
(theme: GrafanaTheme, options: { variant: ButtonVariant; size: ButtonSize; invalid: boolean }) => { (theme: GrafanaTheme, options: { variant: ButtonVariant; size: ComponentSize; invalid: boolean }) => {
return { return {
label: getLabelStyles(theme), label: getLabelStyles(theme),
legend: getLegendStyles(theme), legend: getLegendStyles(theme),
......
export type ComponentSize = 'xs' | 'sm' | 'md' | 'lg';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment