forked from uber/baseweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(toaster) order when using custom icons (uber#3054)
- Loading branch information
1 parent
00eaf97
commit f1ba118
Showing
6 changed files
with
88 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright (c) 2018-2020 Uber Technologies, Inc. | ||
This source code is licensed under the MIT license found in the | ||
LICENSE file in the root directory of this source tree. | ||
*/ | ||
// @flow | ||
|
||
import * as React from 'react'; | ||
|
||
import {default as DeleteIcon} from '../delete.js'; | ||
import {ThemeProvider, LightTheme, styled} from '../../index.js'; | ||
import {getOverrides, mergeOverrides} from '../../helpers/overrides.js'; | ||
import {getSvgStyles} from '../../icon/styled-components.js'; | ||
|
||
const XSmallFilled = ({title, ...props}) => { | ||
return ( | ||
<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none"> | ||
<path | ||
d="M18.1 8.1l-2.2-2.2-3.9 4-3.9-4-2.2 2.2 4 3.9-4 3.9 2.2 2.2 3.9-4 3.9 4 2.2-2.2-4-3.9 4-3.9z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
); | ||
}; | ||
|
||
const theme = { | ||
...LightTheme, | ||
icons: { | ||
Delete: XSmallFilled, | ||
}, | ||
}; | ||
|
||
// ! All of these styles will be wiped out by the theme icons. | ||
const StyledCloseIcon = styled('svg', props => { | ||
return { | ||
...getSvgStyles(props), | ||
color: 'pink', | ||
order: 1, | ||
}; | ||
}); | ||
|
||
const StyledBody = styled('div', { | ||
display: 'flex', | ||
}); | ||
|
||
const Toast = props => { | ||
const closeRef = React.useRef(); | ||
const {CloseIcon: CloseIconOverride = {}} = props.overrides || {}; | ||
// eslint-disable-next-line no-unused-vars | ||
const [CloseIcon, closeIconProps] = getOverrides( | ||
CloseIconOverride, | ||
StyledCloseIcon, | ||
); | ||
const closeIconOverrides = mergeOverrides( | ||
{ | ||
Svg: { | ||
component: StyledCloseIcon, | ||
props: { | ||
ref: closeRef, | ||
}, | ||
}, | ||
}, | ||
// $FlowFixMe | ||
{Svg: CloseIconOverride}, | ||
); | ||
return ( | ||
<StyledBody> | ||
<DeleteIcon {...closeIconProps} overrides={closeIconOverrides} /> | ||
Stuff | ||
</StyledBody> | ||
); | ||
}; | ||
|
||
export default function Scenario() { | ||
return ( | ||
<div> | ||
<ThemeProvider theme={theme}> | ||
<Toast /> | ||
</ThemeProvider> | ||
</div> | ||
); | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.