-
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
[EuiButton][EuiButtonEmpty][EuiButtonIcon] Remove color="ghost"
#7296
Changes from all commits
e7c29fd
b7dc9b4
b5e5a8c
be0c695
76577f7
b95716e
d54b47b
5c871b2
6d6d79b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
import React from 'react'; | ||
|
||
import { EuiBottomBar, EuiSpacer, EuiText } from '../../../../src/components'; | ||
import { EuiBottomBar, EuiText } from '../../../../src/components'; | ||
|
||
export default () => { | ||
return ( | ||
<> | ||
<div css={{ overflow: 'auto', blockSize: 200 }}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a bonus fix in addition to the ghost changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! It's in its own separate commit as well 76577f7. I usually add a note to my PR descriptions recommending that folks follow along with changes by commit as I tend to throw in a lot of misc cleanup items in (but I try really hard to keep my git history clean so that optional cleanup items are separate from actual features or main functionality). TBH I noticed a while back that the demo was broken on prod and was too lazy to fix it then, this PR was a good excuse 😅 |
||
<EuiText> | ||
<p> | ||
When scrolling past this example block, the{' '} | ||
<strong>EuiBottomBar</strong> will stick to the bottom of the browser | ||
window (with a 10px offset), but keeps it within the bounds of its | ||
parent. | ||
When scrolling within this example, the <strong>EuiBottomBar</strong>{' '} | ||
will stick to the bottom of scrollable container (with a 10px offset), | ||
but will not scroll with the page itself. | ||
</p> | ||
</EuiText> | ||
<EuiSpacer size="xl" /> | ||
<EuiSpacer size="xl" /> | ||
<div css={{ blockSize: 400 }} /> | ||
<EuiBottomBar position="sticky" bottom={10}> | ||
<EuiText color="ghost" textAlign="center"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't we need color="text" here to maintain the ghost coloring? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EuiText defaults to Edit to add: And |
||
<EuiText textAlign="center"> | ||
<p>Scroll to see!</p> | ||
</EuiText> | ||
</EuiBottomBar> | ||
</> | ||
</div> | ||
); | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,9 @@ import { | |
EuiButtonDisplayCommonProps, | ||
isButtonDisabled, | ||
} from './button_display/_button_display'; | ||
import { EuiThemeProvider } from '../../services'; | ||
|
||
export const COLORS = [...BUTTON_COLORS, 'ghost'] as const; | ||
export type EuiButtonColor = _EuiButtonColor | 'ghost'; | ||
export const COLORS = BUTTON_COLORS; | ||
export type EuiButtonColor = _EuiButtonColor; | ||
|
||
export const SIZES = ['s', 'm'] as const; | ||
export type EuiButtonSize = (typeof SIZES)[number]; | ||
|
@@ -43,7 +42,6 @@ interface BaseProps { | |
fill?: boolean; | ||
/** | ||
* Any of the named color palette options. | ||
* **`'ghost'` is set for deprecation. Use EuiThemeProvide.colorMode = 'dark' instead.** | ||
*/ | ||
color?: EuiButtonColor; | ||
/** | ||
|
@@ -84,55 +82,36 @@ export type Props = ExclusiveUnion< | |
* EuiButton is largely responsible for providing relevant props | ||
* and the logic for element-specific attributes | ||
*/ | ||
export const EuiButton: FunctionComponent<Props> = (props) => { | ||
const { | ||
className, | ||
buttonRef, | ||
color: _color = 'primary', | ||
fill, | ||
...rest | ||
} = props; | ||
|
||
const buttonIsDisabled = isButtonDisabled({ | ||
export const EuiButton: FunctionComponent<Props> = ({ | ||
className, | ||
buttonRef, | ||
size = 'm', | ||
color = 'primary', | ||
fill, | ||
...rest | ||
}) => { | ||
const isDisabled = isButtonDisabled({ | ||
href: rest.href, | ||
isDisabled: rest.isDisabled || rest.disabled, | ||
isLoading: rest.isLoading, | ||
}); | ||
|
||
const color = buttonIsDisabled ? 'disabled' : _color; | ||
|
||
const buttonColorStyles = useEuiButtonColorCSS({ | ||
display: fill ? 'fill' : 'base', | ||
})[color === 'ghost' ? 'text' : color]; | ||
})[isDisabled ? 'disabled' : color]; | ||
|
||
const buttonFocusStyle = useEuiButtonFocusCSS(); | ||
|
||
const classes = classNames('euiButton', className); | ||
const cssStyles = [buttonColorStyles, buttonFocusStyle]; | ||
|
||
if (_color === 'ghost') { | ||
// INCEPTION: If `ghost`, re-implement with a wrapping dark mode theme provider | ||
return ( | ||
<EuiThemeProvider colorMode="dark" wrapperProps={{ cloneElement: true }}> | ||
<EuiButton {...props} color="text" /> | ||
</EuiThemeProvider> | ||
); | ||
} | ||
|
||
return ( | ||
<EuiButtonDisplay | ||
className={classes} | ||
css={cssStyles} | ||
ref={buttonRef} | ||
size={size} | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
EuiButton.displayName = 'EuiButton'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I take it this was just redundant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, unless we're using forwardRef or have some other reason for renaming components (e.g. HOCs and other shenanigans), we don't need to manually set a |
||
|
||
// Use defaultProps for simple pass-through props | ||
EuiButton.defaultProps = { | ||
size: 'm', | ||
color: 'primary', | ||
}; |
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.
Looking at the Update Paths, this would be a case where:
So in this context, we want to maintain the "ghost" coloring of this button, which is why we wrap it in a theme provider set explicitly to "dark".
This essentially makes the button permanently and independently exist in a "dark mode" context, isolating it from any other dark/light mode changes in any higher-level theme contexts.
Does that all track? I'm just trying to understand.
Does this only impact color mode? Meaning, if other theme changes are set in a higher-level theme context, would they still flow through to this button?
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.
Yeah, your understanding is totally correct!
Yes! Child theme providers will always inherit from their most recent parent. So you could even do something like this:
Here's the source code for that behavior if you're curious (we grab the parent React context and then merge in any modifications and then pass that down as the new context):
eui/src/services/theme/provider.tsx
Lines 74 to 77 in b1c8582
All the credit to Greg for creating that component with flexibility and future-proof-ness in mind!