-
Notifications
You must be signed in to change notification settings - Fork 841
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
elizabetdev
merged 49 commits into
elastic:main
from
elizabetdev:emotion-facet-conversion
Jun 8, 2022
Merged
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 8be0805
Deleting `.scss` files
elizabetdev 265fc72
Moving buttons mixins to functions
elizabetdev 322793f
Removed unused mixin. Adding CL. Improving gutter size func.
elizabetdev f4784a1
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev b8f9133
Improving example
elizabetdev 1ddd2cd
Better code for calling `euiTheme`
elizabetdev cd2f2ec
Renaming `contentElementStyles` to `contentElementsStyles`
elizabetdev e29df48
Fix typo. CL.
elizabetdev 54172b4
Better gap styles
elizabetdev a8a4eec
Adding `euiCanAnimate` for transitions
elizabetdev 9db464c
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev 781f93b
Moving button functions and using `euiLinkFocusCSS`
elizabetdev 80a149b
Typo
elizabetdev 2452e51
Adding `logicalCSS`
elizabetdev bbfff1c
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev 45c412a
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev a037373
Adding new EuiButtonDisplay
elizabetdev e02cb0c
Adding `logicalTextAlignCSS`
elizabetdev 4f0d7d8
Removing `EuiFlexGroup`
elizabetdev 90572aa
Better styles
elizabetdev 4fd0f89
Better `isDisabled` styles
elizabetdev eaa0c90
Text`isSelected` style
elizabetdev 7f60484
Identantion
elizabetdev 955a32b
CL
elizabetdev 5adff69
Improving regex in render_custom_styles
elizabetdev cd757e4
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev 9c669da
Deprecating EuiButtonDisplay and EuiButtonContent components
elizabetdev 755774f
Adding `euiLoadingSpinnerBorderColorsCSS` mixin
elizabetdev 8bf188a
Adding `_buttonSize()` and renaming files to contain `_deprecated`
elizabetdev 3cd0483
Keeping `EuiButtonDisplay_Deprecated` in button file
elizabetdev c62946f
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev 024de57
Improving text
elizabetdev b0d2012
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev d72e521
Fixing error due to `euiFontSize` being updated in main
elizabetdev 7505bea
Preventing test to get `EuiButtonDisplay_Deprecated`
elizabetdev 3f51ca0
Renaming deprecated components
elizabetdev e5a1d1c
Addressing PR review
elizabetdev a522250
Added new `color` prop to `EuiLoadingSpinner`
elizabetdev 51eec20
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev fe6cbc9
Removing unnecessary prop comment
elizabetdev 533fa71
Making `EuiLoadingSpinnerProps['color']` show in props table
elizabetdev be920ca
Better props table for `EuiLoadingSpinnerColor`
elizabetdev 1555212
Update src/components/loading/loading_spinner.tsx
elizabetdev 8668a50
Update src/components/loading/loading_spinner.tsx
elizabetdev 344a8f0
Update upcoming_changelogs/5878.md
elizabetdev 9327062
Update src/components/button/button_display/_button_display.tsx
elizabetdev 2bc4cb9
Moving CL entry out of `CSS-in-JS`
elizabetdev daf148d
Merge remote-tracking branch 'upstream/main' into emotion-facet-conve…
elizabetdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch