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] Style and a11y fixes #5225

Merged
merged 6 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `38.2.0`.
- Added `maxWidth` prop to `EuiTour`, made `subtitle` optional, and fixed heading levels and footer background ([#5225](https://github.com/elastic/eui/pull/5225))

**Breaking changes**

- Removed `boolean` from `EuiTour`'s `minWidth` type ([#5225](https://github.com/elastic/eui/pull/5225))

## [`38.2.0`](https://github.com/elastic/eui/tree/v38.2.0)

Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/tour/step.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default () => {
step={1}
stepsTotal={1}
title="Title of the current step"
subtitle="Title of the full tour"
subtitle="Title of the full tour (optional)"
anchorPosition="rightUp"
>
<EuiText>
Expand Down
18 changes: 17 additions & 1 deletion src/components/tour/__snapshots__/tour_step.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ exports[`EuiTourStep can be closed 1`] = `
</div>
`;

exports[`EuiTourStep can have subtitle 1`] = `
<div
class="euiPopover euiPopover--anchorLeftUp"
data-test-subj="test subject string"
offset="10"
>
<div
class="euiPopover__anchor"
>
<span>
Test
</span>
</div>
</div>
`;

exports[`EuiTourStep can override the footer action 1`] = `
<div
class="euiPopover euiPopover--anchorLeftUp"
Expand All @@ -32,7 +48,7 @@ exports[`EuiTourStep can override the footer action 1`] = `
</div>
`;

exports[`EuiTourStep can set a minWidth 1`] = `
exports[`EuiTourStep can set a minWidth and maxWidth 1`] = `
<div
class="euiPopover euiPopover--anchorLeftUp"
data-test-subj="test subject string"
Expand Down
13 changes: 4 additions & 9 deletions src/components/tour/_tour.scss
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
.euiTour--minWidth-default {
min-width: $euiSizeL * 10;
}

.euiTourHeader {
border-bottom: none;
// Overriding default `EuiPopoverTitle` styles
margin-bottom: $euiSizeS !important; // sass-lint:disable-line no-important


.euiTourHeader__title { // nested for additional specificity to override EuiTitle styles
// Removes extra margin applied to siblint EuiTitle's
margin-top: 0;
}
}

.euiTourHeader__subtitle {
color: $euiColorDarkShade;
color: $euiTextSubduedColor;
}

.euiTourFooter {
background-color: $euiColorLightestShade;
// Overriding default `EuiPopoverFooter` styles
margin-top: $euiSizeL !important; // sass-lint:disable-line no-important
background-color: $euiPageBackgroundColor;
border-radius: 0 0 $euiBorderRadius $euiBorderRadius;
}

.euiTour {
Expand Down
27 changes: 24 additions & 3 deletions src/components/tour/tour_step.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { EuiTourStep } from './tour_step';
const steps = [
{
step: 1,
subtitle: 'Step 1',
content: 'You are here',
},
];
Expand All @@ -37,6 +36,22 @@ describe('EuiTourStep', () => {
expect(component).toMatchSnapshot();
});

test('can have subtitle', () => {
const component = render(
<EuiTourStep
{...config}
{...steps[0]}
subtitle="Subtitle"
isStepOpen={false}
{...requiredProps}
>
<span>Test</span>
</EuiTourStep>
);

expect(component).toMatchSnapshot();
});

test('can be closed', () => {
const component = render(
<EuiTourStep
Expand All @@ -52,9 +67,15 @@ describe('EuiTourStep', () => {
expect(component).toMatchSnapshot();
});

test('can set a minWidth', () => {
test('can set a minWidth and maxWidth', () => {
const component = render(
<EuiTourStep {...config} {...steps[0]} minWidth={240} {...requiredProps}>
<EuiTourStep
{...config}
{...steps[0]}
minWidth={240}
maxWidth={420}
{...requiredProps}
>
<span>Test</span>
</EuiTourStep>
);
Expand Down
43 changes: 20 additions & 23 deletions src/components/tour/tour_step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ export interface EuiTourStepProps
isStepOpen?: boolean;

/**
* Sets the min-width of the tour popover,
* set to `true` to use the default size,
* set to `false` to not restrict the width,
* set to a number for a custom width in px,
* set to a string for a custom width in custom measurement.
* Change the default min width of the popover panel
*/
minWidth?: boolean | number | string;
minWidth?: CSSProperties['maxWidth'];

/**
* Change the default max width of the popover panel
*/
maxWidth?: CSSProperties['maxWidth'];

/**
* Function to call for 'Skip tour' and 'End tour' actions
Expand All @@ -86,7 +87,7 @@ export interface EuiTourStepProps
/**
* Smaller title text that appears atop each step in the tour. The subtitle gets wrapped in the appropriate heading level.
*/
subtitle: ReactNode;
subtitle?: ReactNode;

/**
* Larger title text specific to this step. The title gets wrapped in the appropriate heading level.
Expand All @@ -111,7 +112,8 @@ export const EuiTourStep: FunctionComponent<EuiTourStepProps> = ({
closePopover = () => {},
content,
isStepOpen = false,
minWidth = true,
minWidth = 300,
maxWidth = 600,
onFinish,
step = 1,
stepsTotal,
Expand All @@ -128,17 +130,10 @@ export const EuiTourStep: FunctionComponent<EuiTourStepProps> = ({
'EuiTourStep `step` should 1-based indexing. Please update to eliminate 0 indexes.'
);
}
let newStyle;

let widthClassName;
if (minWidth === true) {
widthClassName = 'euiTour--minWidth-default';
} else if (minWidth !== false) {
const value = typeof minWidth === 'number' ? `${minWidth}px` : minWidth;
newStyle = { ...style, minWidth: value };
}

const classes = classNames('euiTour', widthClassName, className);
const newStyle: CSSProperties = { ...style, maxWidth, minWidth };

const classes = classNames('euiTour', className);

const finishButtonProps: EuiButtonEmptyProps = {
color: 'text',
Expand Down Expand Up @@ -208,18 +203,20 @@ export const EuiTourStep: FunctionComponent<EuiTourStepProps> = ({
isOpen={isStepOpen}
ownFocus={false}
panelClassName={classes}
panelStyle={newStyle || style}
panelStyle={newStyle}
offset={hasBeacon ? 10 : 0}
aria-labelledby={titleId}
arrowChildren={hasBeacon && <EuiBeacon className="euiTour__beacon" />}
{...rest}
>
<EuiPopoverTitle className="euiTourHeader" id={titleId}>
<EuiTitle size="xxxs" className="euiTourHeader__subtitle">
<h1>{subtitle}</h1>
</EuiTitle>
{subtitle && (
<EuiTitle size="xxxs" className="euiTourHeader__subtitle">
<h2>{subtitle}</h2>
</EuiTitle>
)}
<EuiTitle size="xxs" className="euiTourHeader__title">
<h2>{title}</h2>
<h3>{title}</h3>
</EuiTitle>
</EuiPopoverTitle>
<div className="euiTour__content">{content}</div>
Expand Down