Skip to content

Commit

Permalink
fix(toaster) order when using custom icons (uber#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandgraham authored Mar 17, 2020
1 parent 00eaf97 commit f1ba118
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 8 deletions.
83 changes: 83 additions & 0 deletions src/icon/__tests__/icon-overrides.scenario.js
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>
);
}
1 change: 0 additions & 1 deletion src/toast/styled-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export const CloseIconSvg = styled<SharedStylePropsArgT>('svg', props => {
cursor: 'pointer',
width: '16px',
flexShrink: 0,
order: 1,
outline: props.$isFocusVisible
? `3px solid ${props.$theme.colors.accent}`
: 'none',
Expand Down
12 changes: 5 additions & 7 deletions src/toast/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,11 @@ class Toast extends React.Component<ToastPropsT, ToastPrivateStateT> {
onMouseEnter={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
>
{/* Close icon comes first so that we can tab to other content
inside of Toast body. We use flex order to move it back. */}
<InnerContainer {...sharedProps} {...innerContainerProps}>
{typeof children === 'function'
? children({dismiss: this.dismiss})
: children}
</InnerContainer>
{closeable ? (
<DeleteIcon
role="button"
Expand All @@ -259,11 +262,6 @@ class Toast extends React.Component<ToastPropsT, ToastPrivateStateT> {
overrides={closeIconOverrides}
/>
) : null}
<InnerContainer {...sharedProps} {...innerContainerProps}>
{typeof children === 'function'
? children({dismiss: this.dismiss})
: children}
</InnerContainer>
</Body>
)}
</LocaleContext.Consumer>
Expand Down
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.

0 comments on commit f1ba118

Please sign in to comment.