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

[EuiTour] Fix panelProps overriding Emotion css + misc cleanup #6298

Merged
merged 7 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions src/components/tour/__snapshots__/tour_step.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ exports[`EuiTourStep can change the minWidth and maxWidth 1`] = `
style="left: 0px; top: 10px;"
>
<div
class="euiBeacon euiTour__beacon emotion-euiBeacon-euiTourBeacon-left"
class="euiBeacon euiTour__beacon emotion-euiBeacon-euiTourBeacon-isOpen-left"
style="height: 12px; width: 12px;"
/>
</div>
Expand Down Expand Up @@ -160,7 +160,7 @@ exports[`EuiTourStep can have subtitle 1`] = `
style="left: 0px; top: 10px;"
>
<div
class="euiBeacon euiTour__beacon emotion-euiBeacon-euiTourBeacon-left"
class="euiBeacon euiTour__beacon emotion-euiBeacon-euiTourBeacon-isOpen-left"
style="height: 12px; width: 12px;"
/>
</div>
Expand Down Expand Up @@ -268,7 +268,7 @@ exports[`EuiTourStep can override the footer action 1`] = `
style="left: 0px; top: 10px;"
>
<div
class="euiBeacon euiTour__beacon emotion-euiBeacon-euiTourBeacon-left"
class="euiBeacon euiTour__beacon emotion-euiBeacon-euiTourBeacon-isOpen-left"
style="height: 12px; width: 12px;"
/>
</div>
Expand Down Expand Up @@ -458,7 +458,7 @@ exports[`EuiTourStep is rendered 1`] = `
style="left: 0px; top: 10px;"
>
<div
class="euiBeacon euiTour__beacon emotion-euiBeacon-euiTourBeacon-left"
class="euiBeacon euiTour__beacon emotion-euiBeacon-euiTourBeacon-isOpen-left"
style="height: 12px; width: 12px;"
/>
</div>
Expand Down
33 changes: 15 additions & 18 deletions src/components/tour/tour.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
COLOR_MODES_STANDARD,
EuiThemeColorModeStandard,
} from '../../services';
import { logicalCSS, mathWithUnits } from '../../global_styling';
import { logicalCSS, mathWithUnits, euiCanAnimate } from '../../global_styling';
import { openAnimationTiming } from '../popover/popover_panel/_popover_panel.styles';
import { popoverArrowSize } from '../popover/popover_arrow/_popover_arrow.styles';

Expand All @@ -26,19 +26,11 @@ const backgroundColor = (color: string, colorMode: EuiThemeColorModeStandard) =>
export const euiTourStyles = ({ euiTheme, colorMode }: UseEuiTheme) => ({
// Targets EuiPopoverPanel
euiTour: css`
&[data-popover-open='true'] {
[class*='euiTourBeacon'] {
opacity: 1; // Must alter here otherwise the transition does not occur
}
}

[data-popover-arrow='top'] {
&:before {
${logicalCSS(
'border-top-color',
backgroundColor(euiTheme.colors.lightestShade, colorMode)
)};
}
[data-popover-arrow='top']::before {
${logicalCSS(
'border-top-color',
backgroundColor(euiTheme.colors.lightestShade, colorMode)
)};
}
`,
});
Expand All @@ -53,10 +45,16 @@ export const euiTourBeaconStyles = ({ euiTheme }: UseEuiTheme) => {
euiTourBeacon: css`
pointer-events: none;
position: absolute;
opacity: 0;
transition: opacity 0s ${euiTheme.animation[openAnimationTiming]};
${euiCanAnimate} {
opacity: 0;
transition: opacity 0s ${euiTheme.animation[openAnimationTiming]};
}
`,
isOpen: css`
${euiCanAnimate} {
opacity: 1; // Must alter here otherwise the transition does not occur
}
`,

// Positions
right: css`
${logicalCSS('top', arrowHalfSize)};
Expand Down Expand Up @@ -84,7 +82,6 @@ export const euiTourHeaderStyles = ({ euiTheme }: UseEuiTheme) => ({
// Overriding default EuiPopoverTitle styles
${logicalCSS('margin-bottom', euiTheme.size.s)};
`,

// Elements
euiTourHeader__title: css`
// Removes extra margin applied to sibling EuiTitle's
Expand Down
53 changes: 21 additions & 32 deletions src/components/tour/tour_step.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import { mount } from 'enzyme';
import { requiredProps } from '../../test/required_props';
import { shouldRenderCustomStyles } from '../../test/internal';

import { EuiTourStep } from './tour_step';

Expand All @@ -29,10 +30,24 @@ const config = {
title: 'A demo',
};

const props = { ...config, ...steps[0], ...requiredProps };

describe('EuiTourStep', () => {
shouldRenderCustomStyles(
<EuiTourStep {...props} isStepOpen>
<span>Test</span>
</EuiTourStep>
);
shouldRenderCustomStyles(
<EuiTourStep {...props} isStepOpen panelProps={requiredProps}>
<span>Test</span>
</EuiTourStep>,
{ childProps: ['panelProps'], skipStyles: true, skipParentTest: true }
);

test('is rendered', () => {
const component = mount(
<EuiTourStep {...config} {...steps[0]} isStepOpen {...requiredProps}>
<EuiTourStep {...props} isStepOpen>
<span>Test</span>
</EuiTourStep>
);
Expand All @@ -42,13 +57,7 @@ describe('EuiTourStep', () => {

test('can have subtitle', () => {
const component = mount(
<EuiTourStep
{...config}
{...steps[0]}
isStepOpen
subtitle="Subtitle"
{...requiredProps}
>
<EuiTourStep {...props} isStepOpen subtitle="Subtitle">
<span>Test</span>
</EuiTourStep>
);
Expand All @@ -58,12 +67,7 @@ describe('EuiTourStep', () => {

test('can be closed', () => {
const component = mount(
<EuiTourStep
{...config}
{...steps[0]}
isStepOpen={false}
{...requiredProps}
>
<EuiTourStep {...props} isStepOpen={false}>
<span>Test</span>
</EuiTourStep>
);
Expand All @@ -73,14 +77,7 @@ describe('EuiTourStep', () => {

test('can change the minWidth and maxWidth', () => {
const component = mount(
<EuiTourStep
{...config}
{...steps[0]}
minWidth={240}
maxWidth={420}
isStepOpen
{...requiredProps}
>
<EuiTourStep {...props} minWidth={240} maxWidth={420} isStepOpen>
<span>Test</span>
</EuiTourStep>
);
Expand All @@ -91,11 +88,9 @@ describe('EuiTourStep', () => {
test('can override the footer action', () => {
const component = mount(
<EuiTourStep
{...config}
{...steps[0]}
{...props}
isStepOpen
footerAction={<button onClick={() => {}}>Test</button>}
{...requiredProps}
>
<span>Test</span>
</EuiTourStep>
Expand All @@ -106,13 +101,7 @@ describe('EuiTourStep', () => {

test('can turn off the beacon', () => {
const component = mount(
<EuiTourStep
{...config}
{...steps[0]}
isStepOpen
decoration="none"
{...requiredProps}
>
<EuiTourStep {...props} isStepOpen decoration="none">
<span>Test</span>
</EuiTourStep>
);
Expand Down
8 changes: 7 additions & 1 deletion src/components/tour/tour_step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const EuiTourStep: FunctionComponent<EuiTourStepProps> = ({
anchor,
children,
className,
css,
closePopover = () => {},
content,
isStepOpen = false,
Expand All @@ -152,6 +153,7 @@ export const EuiTourStep: FunctionComponent<EuiTourStepProps> = ({
title,
decoration = 'beacon',
footerAction,
panelProps,
...rest
}) => {
const titleId = useGeneratedHtmlId();
Expand Down Expand Up @@ -192,6 +194,7 @@ export const EuiTourStep: FunctionComponent<EuiTourStepProps> = ({
const beaconStyles = euiTourBeaconStyles(euiTheme);
const beaconCss = [
beaconStyles.euiTourBeacon,
isStepOpen && beaconStyles.isOpen,
popoverPosition && beaconStyles[popoverPosition],
];

Expand Down Expand Up @@ -262,7 +265,10 @@ export const EuiTourStep: FunctionComponent<EuiTourStepProps> = ({
ownFocus: false,
panelClassName: classes,
panelStyle: style,
panelProps: { css: tourStyles.euiTour },
panelProps: {
...panelProps,
css: [tourStyles.euiTour, css, panelProps?.css],
},
offset: hasBeacon ? 10 : 0,
'aria-labelledby': titleId,
arrowChildren: hasBeacon && (
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/6298.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Fixed a bug with `EuiTour` where passing any `panelProps` would cause the beacon to disappear