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

[Emotion] Convert EuiFacetButton and EuiFacetGroup #5878

Merged
merged 49 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3aaf346
Convert `EuiFacetButton` and `EuiFacetGroup` to emotion
elizabetdev May 5, 2022
8be0805
Deleting `.scss` files
elizabetdev May 5, 2022
265fc72
Moving buttons mixins to functions
elizabetdev May 5, 2022
322793f
Removed unused mixin. Adding CL. Improving gutter size func.
elizabetdev May 6, 2022
f4784a1
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev May 6, 2022
b8f9133
Improving example
elizabetdev May 6, 2022
1ddd2cd
Better code for calling `euiTheme`
elizabetdev May 6, 2022
cd2f2ec
Renaming `contentElementStyles` to `contentElementsStyles`
elizabetdev May 6, 2022
e29df48
Fix typo. CL.
elizabetdev May 6, 2022
54172b4
Better gap styles
elizabetdev May 6, 2022
a8a4eec
Adding `euiCanAnimate` for transitions
elizabetdev May 6, 2022
9db464c
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev May 9, 2022
781f93b
Moving button functions and using `euiLinkFocusCSS`
elizabetdev May 9, 2022
80a149b
Typo
elizabetdev May 9, 2022
2452e51
Adding `logicalCSS`
elizabetdev May 12, 2022
bbfff1c
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev May 12, 2022
45c412a
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev May 18, 2022
a037373
Adding new EuiButtonDisplay
elizabetdev May 19, 2022
e02cb0c
Adding `logicalTextAlignCSS`
elizabetdev May 19, 2022
4f0d7d8
Removing `EuiFlexGroup`
elizabetdev May 19, 2022
90572aa
Better styles
elizabetdev May 20, 2022
4fd0f89
Better `isDisabled` styles
elizabetdev May 20, 2022
eaa0c90
Text`isSelected` style
elizabetdev May 20, 2022
7f60484
Identantion
elizabetdev May 20, 2022
955a32b
CL
elizabetdev May 20, 2022
5adff69
Improving regex in render_custom_styles
elizabetdev May 24, 2022
cd757e4
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev May 24, 2022
9c669da
Deprecating EuiButtonDisplay and EuiButtonContent components
elizabetdev May 25, 2022
755774f
Adding `euiLoadingSpinnerBorderColorsCSS` mixin
elizabetdev May 25, 2022
8bf188a
Adding `_buttonSize()` and renaming files to contain `_deprecated`
elizabetdev May 26, 2022
3cd0483
Keeping `EuiButtonDisplay_Deprecated` in button file
elizabetdev May 26, 2022
c62946f
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev May 26, 2022
024de57
Improving text
elizabetdev Jun 1, 2022
b0d2012
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev Jun 1, 2022
d72e521
Fixing error due to `euiFontSize` being updated in main
elizabetdev Jun 1, 2022
7505bea
Preventing test to get `EuiButtonDisplay_Deprecated`
elizabetdev Jun 1, 2022
3f51ca0
Renaming deprecated components
elizabetdev Jun 3, 2022
e5a1d1c
Addressing PR review
elizabetdev Jun 3, 2022
a522250
Added new `color` prop to `EuiLoadingSpinner`
elizabetdev Jun 3, 2022
51eec20
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev Jun 3, 2022
fe6cbc9
Removing unnecessary prop comment
elizabetdev Jun 3, 2022
533fa71
Making `EuiLoadingSpinnerProps['color']` show in props table
elizabetdev Jun 3, 2022
be920ca
Better props table for `EuiLoadingSpinnerColor`
elizabetdev Jun 3, 2022
1555212
Update src/components/loading/loading_spinner.tsx
elizabetdev Jun 8, 2022
8668a50
Update src/components/loading/loading_spinner.tsx
elizabetdev Jun 8, 2022
344a8f0
Update upcoming_changelogs/5878.md
elizabetdev Jun 8, 2022
9327062
Update src/components/button/button_display/_button_display.tsx
elizabetdev Jun 8, 2022
2bc4cb9
Moving CL entry out of `CSS-in-JS`
elizabetdev Jun 8, 2022
daf148d
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev Jun 8, 2022
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
22 changes: 3 additions & 19 deletions src-docs/src/views/facet/facet_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
EuiFacetGroup,
EuiIcon,
EuiAvatar,
EuiTitle,
EuiSpacer,
} from '../../../../src/components';

import { euiPaletteColorBlind } from '../../../../src/services';
Expand Down Expand Up @@ -146,22 +144,8 @@ export default () => {
};

return (
<div>
<EuiTitle size="s">
<h3>Vertical</h3>
</EuiTitle>
<EuiFacetGroup style={{ maxWidth: 200 }}>
{facets('Vertical')}
</EuiFacetGroup>

<EuiSpacer />

<EuiTitle size="s">
<h3>Horizontal and large gutter</h3>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

</EuiTitle>
<EuiFacetGroup layout="horizontal" gutterSize="l">
{facets('Horizontal')}
</EuiFacetGroup>
</div>
<EuiFacetGroup style={{ maxWidth: 200 }}>
{facets('Vertical')}
</EuiFacetGroup>
);
};
5 changes: 3 additions & 2 deletions src/components/accessibility/skip_link/skip_link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
import React, { FunctionComponent, Ref } from 'react';
import classNames from 'classnames';
import { useEuiTheme } from '../../../services';
import { EuiButton, EuiButtonProps } from '../../button/button';
import { EuiButton } from '../../button/button';
import { EuiButtonDisplayCommonProps_Deprecated } from '../../button/_button_display_deprecated';
import { PropsForAnchor, PropsForButton, ExclusiveUnion } from '../../common';
import { EuiScreenReaderOnly } from '../screen_reader_only';
import { euiSkipLinkStyles } from './skip_link.styles';

export const POSITIONS = ['static', 'fixed', 'absolute'] as const;
type Positions = typeof POSITIONS[number];

interface EuiSkipLinkInterface extends EuiButtonProps {
interface EuiSkipLinkInterface extends EuiButtonDisplayCommonProps_Deprecated {
/**
* Change the display position of the element when focused.
* If 'fixed', the link will be fixed to the top left of the viewport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,34 @@ import { CommonProps, keysOf } from '../common';
import { EuiLoadingSpinner } from '../loading';
import { EuiIcon, IconType } from '../icon';

export type ButtonContentIconSide = 'left' | 'right';
export type ButtonContentIconSide_Deprecated = 'left' | 'right';

const iconSideToClassNameMap: {
[side in ButtonContentIconSide]: string | null;
[side in ButtonContentIconSide_Deprecated]: string | null;
} = {
left: null,
right: 'euiButtonContent--iconRight',
};

export const ICON_SIDES = keysOf(iconSideToClassNameMap);

export type EuiButtonContentType = HTMLAttributes<HTMLSpanElement>;
export type EuiButtonContentType_Deprecated = HTMLAttributes<HTMLSpanElement>;

/**
* *INTERNAL ONLY*
* *INTERNAL ONLY / DEPRECATED*
* This component is simply a helper component for reuse within other button components
* This component has been deprecated in favor of the new EuiButtonDisplayContent
* that can be found in `src/components/button/button_display/_button_display_content.tsx`.
*/
export interface EuiButtonContentProps extends CommonProps {
export interface EuiButtonContentProps_Deprecated extends CommonProps {
/**
* Any `type` accepted by EuiIcon
*/
iconType?: IconType;
/**
* Can only be one side `left` or `right`
*/
iconSide?: ButtonContentIconSide;
iconSide?: ButtonContentIconSide_Deprecated;
isLoading?: boolean;
/**
* Object of props passed to the <span/> wrapping the content's text/children only (not icon)
Expand All @@ -50,8 +52,8 @@ export interface EuiButtonContentProps extends CommonProps {
iconSize?: 's' | 'm';
}

export const EuiButtonContent: FunctionComponent<
EuiButtonContentType & EuiButtonContentProps
export const EuiButtonContent_Deprecated: FunctionComponent<
EuiButtonContentType_Deprecated & EuiButtonContentProps_Deprecated
> = ({
children,
textProps,
Expand Down
245 changes: 245 additions & 0 deletions src/components/button/_button_display_deprecated.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React, {
forwardRef,
CSSProperties,
HTMLAttributes,
ReactNode,
Ref,
} from 'react';
import classNames from 'classnames';

import {
EuiButtonContent_Deprecated as EuiButtonContent,
EuiButtonContentProps_Deprecated as EuiButtonContentDisplayProps,
EuiButtonContentType_Deprecated as EuiButtonContentType,
} from './_button_content_deprecated';

import {
CommonProps,
ExclusiveUnion,
PropsForAnchor,
PropsForButton,
keysOf,
} from '../common';

export type ButtonDisplayColor_Deprecated =
| 'primary'
| 'accent'
| 'success'
| 'warning'
| 'danger'
| 'ghost'
| 'text';

export type ButtonDisplaySize_Deprecated = 's' | 'm';

export const colorToClassNameMap: {
[color in ButtonDisplayColor_Deprecated]: string;
} = {
primary: '--primary',
accent: '--accent',
success: '--success',
warning: '--warning',
danger: '--danger',
ghost: '--ghost',
text: '--text',
};

export const COLORS = keysOf(colorToClassNameMap);

export const sizeToClassNameMap: {
[size in ButtonDisplaySize_Deprecated]: string | null;
} = {
s: '--small',
m: null,
};

export const SIZES = keysOf(sizeToClassNameMap);

/**
* Extends EuiButtonContentDisplayProps which provides
* `iconType`, `iconSide`, and `textProps`
*/
export interface EuiButtonDisplayCommonProps_Deprecated
extends EuiButtonContentDisplayProps,
CommonProps {
children?: ReactNode;
/**
* Make button a solid color for prominence
*/
fill?: boolean;
/**
* Any of our named colors.
*/
color?: ButtonDisplayColor_Deprecated;
/**
* Use size `s` in confined spaces
*/
size?: ButtonDisplaySize_Deprecated;
/**
* `disabled` is also allowed
*/
isDisabled?: boolean;
/**
* Applies the boolean state as the `aria-pressed` property to create a toggle button.
* *Only use when the readable text does not change between states.*
*/
isSelected?: boolean;
/**
* Extends the button to 100% width
*/
fullWidth?: boolean;
/**
* Override the default minimum width
*/
minWidth?: CSSProperties['minWidth'];
/**
* Force disables the button and changes the icon to a loading spinner
*/
isLoading?: boolean;
/**
* Object of props passed to the <span/> wrapping the button's content
*/
contentProps?: EuiButtonContentType;
style?: CSSProperties;
}

export type EuiButtonDisplayPropsForAnchor_Deprecated = PropsForAnchor<
EuiButtonDisplayCommonProps_Deprecated,
{
buttonRef?: Ref<HTMLAnchorElement>;
}
>;

export type EuiButtonDisplayPropsForButton_Deprecated = PropsForButton<
EuiButtonDisplayCommonProps_Deprecated,
{
buttonRef?: Ref<HTMLButtonElement>;
}
>;

export type EuiButtonDisplayUnionProps_Deprecated = ExclusiveUnion<
EuiButtonDisplayPropsForAnchor_Deprecated,
EuiButtonDisplayPropsForButton_Deprecated
>;

export type EuiButtonDisplayProps_Deprecated = EuiButtonDisplayCommonProps_Deprecated &
HTMLAttributes<HTMLElement> & {
/**
* Provide a valid element to render the element as
*/
element: 'a' | 'button' | 'span' | 'label';
/**
* Provide the component's base class name to build the class list on
*/
baseClassName: string;
};

/**
* *INTERNAL ONLY / DEPRECATED*
* EuiButtonDisplay is an internal-only component used for displaying
* any element as a button.
* This component has been deprecated in favor of the new EuiButtonDisplay
* that can be found in `src/components/button/button_display/_button_display.tsx`
*/
export const EuiButtonDisplay_Deprecated = forwardRef<
HTMLElement,
EuiButtonDisplayProps_Deprecated
>(
(
{
element = 'button',
baseClassName,
children,
className,
iconType,
iconSide = 'left',
color = 'primary',
size = 'm',
fill = false,
isDisabled,
isLoading,
isSelected,
contentProps,
textProps,
fullWidth,
minWidth,
style,
...rest
},
ref
) => {
const buttonIsDisabled = isLoading || isDisabled;

const classes = classNames(
baseClassName,
color && colorToClassNameMap[color]
? `${baseClassName}${colorToClassNameMap[color]}`
: `${baseClassName}${colorToClassNameMap.primary}`,
size && sizeToClassNameMap[size]
? `${baseClassName}${sizeToClassNameMap[size]}`
: null,
fill && `${baseClassName}--fill`,
fullWidth && `${baseClassName}--fullWidth`,
buttonIsDisabled && `${baseClassName}-isDisabled`,
className
);

/**
* Not changing the content or text class names to match baseClassName yet,
* as it is a major breaking change.
*/
const contentClassNames = classNames(
'euiButton__content',
contentProps && contentProps.className
);

const textClassNames = classNames(
'euiButton__text',
textProps && textProps.className
);

const innerNode = (
<EuiButtonContent
isLoading={isLoading}
iconType={iconType}
iconSide={iconSide}
textProps={{ ...textProps, className: textClassNames }}
{...contentProps}
// className has to come last to override contentProps.className
className={contentClassNames}
>
{children}
</EuiButtonContent>
);

let calculatedStyle: CSSProperties | undefined = style;
if (minWidth !== undefined || minWidth !== null) {
calculatedStyle = {
...calculatedStyle,
minWidth,
};
}

return React.createElement(
element,
{
className: classes,
style: calculatedStyle,
disabled: element === 'button' && buttonIsDisabled,
'aria-pressed': element === 'button' ? isSelected : undefined,
ref,
...rest,
},
innerNode
);
}
);
EuiButtonDisplay_Deprecated.displayName = 'EuiButtonDisplay_Deprecated';
5 changes: 3 additions & 2 deletions src/components/button/button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import React from 'react';
import { render, mount } from 'enzyme';
import { requiredProps } from '../../test/required_props';

import { EuiButton, COLORS, SIZES } from './button';
import { ICON_SIDES } from './button_content';
import { EuiButton } from './button';
import { COLORS, SIZES } from './_button_display_deprecated';
import { ICON_SIDES } from './_button_content_deprecated';

describe('EuiButton', () => {
test('is rendered', () => {
Expand Down
Loading