-
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
[EuiTourStep] className
consistency with EuiPopover + performance/cleanups
#7497
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4f0c2ce
Fix `className` DOM location to match EuiPopover
cee-chen 43241a6
Fix `style` DOM location to match EuiPopover
cee-chen 13f7ac2
[tests] Convert Enzyme to RTL
cee-chen 0f1971d
[css] Convert inline styles to logical property equivalents
cee-chen 049e269
[Perf] Memoize & clean up code
cee-chen f0b0603
TS fixes
cee-chen 85e5abe
changelog
cee-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { css } from '@emotion/react'; | ||
import { UseEuiTheme, shade, tint } from '../../services'; | ||
import { logicalCSS } from '../../global_styling'; | ||
|
||
export const _tourFooterBgColor = ({ colorMode, euiTheme }: UseEuiTheme) => | ||
colorMode === 'DARK' | ||
? shade(euiTheme.colors.lightestShade, 0.45) | ||
: tint(euiTheme.colors.lightestShade, 0.5); | ||
|
||
export const euiTourFooterStyles = (euiThemeContext: UseEuiTheme) => { | ||
const { euiTheme } = euiThemeContext; | ||
return { | ||
// Base | ||
euiTourFooter: css` | ||
background-color: ${_tourFooterBgColor(euiThemeContext)}; | ||
${logicalCSS('border-bottom-left-radius', euiTheme.border.radius.medium)} | ||
${logicalCSS('border-bottom-right-radius', euiTheme.border.radius.medium)} | ||
`, | ||
}; | ||
}; |
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,125 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { FunctionComponent, useMemo, memo } from 'react'; | ||
|
||
import { useEuiTheme } from '../../services'; | ||
import { EuiI18n } from '../i18n'; | ||
import { EuiPopoverFooter } from '../popover'; | ||
import { EuiButtonEmpty } from '../button'; | ||
import { EuiFlexGroup, EuiFlexItem } from '../flex'; | ||
|
||
import { | ||
EuiTourStepIndicator, | ||
type EuiTourStepStatus, | ||
} from './tour_step_indicator'; | ||
import type { EuiTourStepProps } from './tour_step'; | ||
|
||
import { euiTourFooterStyles } from './_tour_footer.styles'; | ||
|
||
type EuiTourFooterProps = Pick< | ||
EuiTourStepProps, | ||
'footerAction' | 'step' | 'stepsTotal' | 'onFinish' | ||
>; | ||
|
||
export const EuiTourFooter: FunctionComponent<EuiTourFooterProps> = memo( | ||
({ footerAction, step, stepsTotal, onFinish }) => { | ||
const euiTheme = useEuiTheme(); | ||
const footerStyles = euiTourFooterStyles(euiTheme); | ||
|
||
const customFooterAction = useMemo(() => { | ||
if (!footerAction) return null; | ||
|
||
return Array.isArray(footerAction) ? ( | ||
<EuiFlexGroup | ||
gutterSize="s" | ||
alignItems="center" | ||
justifyContent="flexEnd" | ||
responsive={false} | ||
wrap | ||
> | ||
{footerAction.map((action, index) => ( | ||
<EuiFlexItem key={index} grow={false}> | ||
{action} | ||
</EuiFlexItem> | ||
))} | ||
</EuiFlexGroup> | ||
) : ( | ||
<EuiFlexItem grow={false}>{footerAction}</EuiFlexItem> | ||
); | ||
}, [footerAction]); | ||
|
||
const indicators = useMemo(() => { | ||
if (stepsTotal <= 1) return null; | ||
|
||
return ( | ||
<EuiFlexItem grow={false}> | ||
<ul className="euiTourFooter__stepList"> | ||
{[...Array(stepsTotal).keys()].map((_, i) => { | ||
let status: EuiTourStepStatus = 'complete'; | ||
if (step === i + 1) { | ||
status = 'active'; | ||
} else if (step <= i) { | ||
status = 'incomplete'; | ||
} | ||
return ( | ||
<EuiTourStepIndicator key={i} number={i + 1} status={status} /> | ||
); | ||
})} | ||
</ul> | ||
</EuiFlexItem> | ||
); | ||
}, [step, stepsTotal]); | ||
|
||
return ( | ||
<EuiPopoverFooter | ||
css={footerStyles.euiTourFooter} | ||
className="euiTourFooter" | ||
> | ||
<EuiFlexGroup | ||
responsive={false} | ||
justifyContent={stepsTotal > 1 ? 'spaceBetween' : 'flexEnd'} | ||
alignItems="center" | ||
> | ||
{indicators} | ||
|
||
{footerAction ? ( | ||
customFooterAction | ||
) : ( | ||
<EuiFlexItem grow={false}> | ||
<EuiI18n | ||
tokens={[ | ||
'euiTourFooter.endTour', | ||
'euiTourFooter.skipTour', | ||
'euiTourFooter.closeTour', | ||
]} | ||
defaults={['End tour', 'Skip tour', 'Close tour']} | ||
> | ||
{([endTour, skipTour, closeTour]: string[]) => ( | ||
<EuiButtonEmpty | ||
onClick={onFinish} | ||
color="text" | ||
flush="right" | ||
size="xs" | ||
> | ||
{stepsTotal > 1 | ||
? stepsTotal === step | ||
? endTour | ||
: skipTour | ||
: closeTour} | ||
</EuiButtonEmpty> | ||
)} | ||
</EuiI18n> | ||
</EuiFlexItem> | ||
)} | ||
</EuiFlexGroup> | ||
</EuiPopoverFooter> | ||
); | ||
} | ||
); | ||
EuiTourFooter.displayName = '_EuiTourFooter'; |
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,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { css } from '@emotion/react'; | ||
import { UseEuiTheme } from '../../services'; | ||
import { logicalCSS } from '../../global_styling'; | ||
|
||
export const euiTourHeaderStyles = ({ euiTheme }: UseEuiTheme) => ({ | ||
// Base | ||
euiTourHeader: css` | ||
${logicalCSS('border-bottom', 'none')} | ||
/* Overriding default EuiPopoverTitle styles */ | ||
${logicalCSS('margin-bottom', euiTheme.size.s)} | ||
`, | ||
// Elements | ||
euiTourHeader__title: css` | ||
/* Removes extra margin applied to sibling EuiTitle's */ | ||
${logicalCSS('margin-top', 0)} | ||
`, | ||
euiTourHeader__subtitle: css` | ||
color: ${euiTheme.colors.subduedText}; | ||
padding-block-end: ${euiTheme.size.xs}; | ||
`, | ||
}); |
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,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { FunctionComponent, memo } from 'react'; | ||
|
||
import { useEuiTheme } from '../../services'; | ||
import { EuiPopoverTitle } from '../popover'; | ||
import { EuiTitle } from '../title'; | ||
|
||
import type { EuiTourStepProps } from './tour_step'; | ||
|
||
import { euiTourHeaderStyles } from './_tour_header.styles'; | ||
|
||
type EuiTourHeaderProps = { id: string } & Pick< | ||
EuiTourStepProps, | ||
'title' | 'subtitle' | ||
>; | ||
|
||
export const EuiTourHeader: FunctionComponent<EuiTourHeaderProps> = memo( | ||
({ id, title, subtitle }) => { | ||
const euiTheme = useEuiTheme(); | ||
const headerStyles = euiTourHeaderStyles(euiTheme); | ||
|
||
return ( | ||
<EuiPopoverTitle | ||
css={headerStyles.euiTourHeader} | ||
className="euiTourHeader" | ||
id={id} | ||
> | ||
{subtitle && ( | ||
<EuiTitle css={headerStyles.euiTourHeader__subtitle} size="xxxs"> | ||
<h2>{subtitle}</h2> | ||
</EuiTitle> | ||
)} | ||
<EuiTitle css={headerStyles.euiTourHeader__title} size="xxs"> | ||
{subtitle ? <h3>{title}</h3> : <h2>{title}</h2>} | ||
</EuiTitle> | ||
</EuiPopoverTitle> | ||
); | ||
} | ||
); | ||
EuiTourHeader.displayName = '_EuiTourHeader'; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think using a regular
if
statement would be cleaner here, but I have no strong preference!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.
I'm a huge sucker for early returns 😅 I like that they mean the rest of the code has one less set of indentations!