Skip to content

Commit

Permalink
[EuiTabs] More Emotion cleanup (#6336)
Browse files Browse the repository at this point in the history
* Remove mounted snapshot

* Emotion cleanup - remove unnecessary `calc`s

* CSS cleanup - remove incorrect text color and unnecessary extra hover styles

- text color is set by `euiTitle` and should not be disabled by default

- disabled already inherits hover disabling from the default

* CSS - misc logical property conversion

- default shorthands sadly do not account for logical/direction changes

* Flatten/fix disabled selected selector

* Revert removed `__append/prepend` classNames

- we're generally not removing `__` classNames in our conversion to give consumers something to hook onto

* DRY out tab sizes types/consts

+ fix type name to match type name pre-Emotion conversion

* Add missing `shouldRenderCustomStyles` tests to sub components

* [misc] rename Emotion vars to match other components/conversions

* Remove unnecessary padding sizes on `euiTab`

Per old Amsterdam overrides, *all* padding for all sizes should be the same (0 xs)

* changelog
  • Loading branch information
Constance authored Nov 7, 2022
1 parent 849243f commit 83d7a6d
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 1,751 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ exports[`EuiPageHeader props page content props are passed down is rendered 1`]
>
<button
aria-selected="true"
class="euiTab euiTab-isSelected emotion-euiTab-selected-l"
class="euiTab euiTab-isSelected emotion-euiTab-selected"
role="tab"
type="button"
>
Expand All @@ -342,7 +342,7 @@ exports[`EuiPageHeader props page content props are passed down is rendered 1`]
</button>
<button
aria-selected="false"
class="euiTab emotion-euiTab-l"
class="euiTab emotion-euiTab"
role="tab"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ exports[`EuiPageHeaderContent props children is rendered even if content props a
>
<button
aria-selected="true"
class="euiTab euiTab-isSelected emotion-euiTab-selected-l"
class="euiTab euiTab-isSelected emotion-euiTab-selected"
role="tab"
type="button"
>
Expand All @@ -302,7 +302,7 @@ exports[`EuiPageHeaderContent props children is rendered even if content props a
</button>
<button
aria-selected="false"
class="euiTab emotion-euiTab-l"
class="euiTab emotion-euiTab"
role="tab"
type="button"
>
Expand Down Expand Up @@ -579,7 +579,7 @@ exports[`EuiPageHeaderContent props tabs is rendered 1`] = `
>
<button
aria-selected="true"
class="euiTab euiTab-isSelected emotion-euiTab-selected-xl"
class="euiTab euiTab-isSelected emotion-euiTab-selected"
role="tab"
type="button"
>
Expand All @@ -591,7 +591,7 @@ exports[`EuiPageHeaderContent props tabs is rendered 1`] = `
</button>
<button
aria-selected="false"
class="euiTab emotion-euiTab-xl"
class="euiTab emotion-euiTab"
role="tab"
type="button"
>
Expand Down Expand Up @@ -630,7 +630,7 @@ exports[`EuiPageHeaderContent props tabs is rendered with tabsProps 1`] = `
>
<button
aria-selected="true"
class="euiTab euiTab-isSelected emotion-euiTab-selected-xl"
class="euiTab euiTab-isSelected emotion-euiTab-selected"
role="tab"
type="button"
>
Expand All @@ -642,7 +642,7 @@ exports[`EuiPageHeaderContent props tabs is rendered with tabsProps 1`] = `
</button>
<button
aria-selected="false"
class="euiTab emotion-euiTab-xl"
class="euiTab emotion-euiTab"
role="tab"
type="button"
>
Expand Down
24 changes: 22 additions & 2 deletions src/components/tabs/__snapshots__/tab.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ exports[`EuiTab props append is rendered 1`] = `
role="tab"
type="button"
>
<span>
<span
class="euiTab__prepend"
>
Append
</span>
<span
Expand All @@ -18,6 +20,22 @@ exports[`EuiTab props append is rendered 1`] = `
</button>
`;

exports[`EuiTab props disabled and selected 1`] = `
<button
aria-selected="true"
class="euiTab euiTab-isSelected emotion-euiTab-disabled-selected"
disabled=""
role="tab"
type="button"
>
<span
class="euiTab__content emotion-euiTab__content-selected-disabled"
>
Click Me
</span>
</button>
`;

exports[`EuiTab props disabled is rendered 1`] = `
<button
aria-selected="false"
Expand Down Expand Up @@ -91,7 +109,9 @@ exports[`EuiTab props prepend is rendered 1`] = `
role="tab"
type="button"
>
<span>
<span
class="euiTab__prepend"
>
Prepend
</span>
<span
Expand Down
53 changes: 21 additions & 32 deletions src/components/tabs/tab.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { css } from '@emotion/react';
import { logicalCSS, mathWithUnits } from '../../global_styling';
import { UseEuiTheme } from '../../services';
import { euiTitle } from '../title/title.styles';

Expand All @@ -19,44 +20,32 @@ export const euiTabStyles = ({ euiTheme }: UseEuiTheme) => {
align-items: center;
font-weight: ${euiTheme.font.weight.semiBold};
gap: ${euiTheme.size.s};
${logicalCSS('padding-vertical', 0)}
${logicalCSS('padding-horizontal', euiTheme.size.xs)}
&:focus {
background-color: transparent;
outline-offset: -${euiTheme.focus.width};
}
`,
// sizes
s: css`
padding: 0 ${euiTheme.size.xs};
`,
m: css`
padding: 0 ${euiTheme.size.xs};
`,
l: css`
padding: 0 ${euiTheme.size.xs};
`,
xl: css`
padding: ${euiTheme.size.s} ${euiTheme.size.xs};
`,
// variations
expanded: css`
flex-basis: 0%;
flex-grow: 1;
justify-content: center;
`,
selected: css`
box-shadow: inset 0 calc(${euiTheme.border.width.thick} * -1) 0
${euiTheme.colors.primary};
`,
disabled: css`
cursor: not-allowed;
color: ${euiTheme.colors.disabledText};
.euiTab.euiTab__isSelected {
box-shadow: inset 0 calc(${euiTheme.border.width.thick} * -1) 0
${euiTheme.colors.disabledText};
}
box-shadow: inset 0 -${euiTheme.border.width.thick} 0 ${euiTheme.colors.primary};
`,
disabled: {
disabled: css`
cursor: not-allowed;
color: ${euiTheme.colors.disabledText};
`,
selected: css`
box-shadow: inset 0 -${euiTheme.border.width.thick} 0 ${euiTheme.colors.disabledText};
`,
},
};
};

Expand All @@ -65,8 +54,6 @@ export const euiTabContentStyles = (euiThemeContext: UseEuiTheme) => {

return {
euiTab__content: css`
color: ${euiTheme.colors.disabledText};
&:hover {
text-decoration: none;
}
Expand All @@ -82,22 +69,24 @@ export const euiTabContentStyles = (euiThemeContext: UseEuiTheme) => {
`,
l: css`
${euiTitle(euiThemeContext, 'xs')};
line-height: calc(${euiTheme.size.xl} + ${euiTheme.size.s});
line-height: ${mathWithUnits(
[euiTheme.size.xl, euiTheme.size.s],
(x, y) => x + y
)};
`,
xl: css`
${euiTitle(euiThemeContext, 's')};
line-height: calc(${euiTheme.size.xxxl} + ${euiTheme.size.s});
line-height: ${mathWithUnits(
[euiTheme.size.xxxl, euiTheme.size.s],
(x, y) => x + y
)};
`,
// variations
selected: css`
color: ${euiTheme.colors.primaryText};
`,
disabled: css`
color: ${euiTheme.colors.disabledText};
&:hover {
text-decoration: none;
}
`,
};
};
13 changes: 13 additions & 0 deletions src/components/tabs/tab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

import React from 'react';
import { render, shallow } from 'enzyme';
import { shouldRenderCustomStyles } from '../../test/internal';
import { requiredProps } from '../../test/required_props';

import { EuiTab } from './tab';

describe('EuiTab', () => {
shouldRenderCustomStyles(<EuiTab onClick={() => {}}>children</EuiTab>);

describe('props', () => {
describe('onClick', () => {
test('renders button', () => {
Expand Down Expand Up @@ -57,6 +60,16 @@ describe('EuiTab', () => {
expect(render(component)).toMatchSnapshot();
});

test('disabled and selected', () => {
const component = render(
<EuiTab disabled isSelected>
Click Me
</EuiTab>
);

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

test('prepend is rendered', () => {
const component = (
<EuiTab onClick={() => {}} prepend="Prepend">
Expand Down
16 changes: 8 additions & 8 deletions src/components/tabs/tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getSecureRelForTarget, useEuiTheme } from '../../services';
import { validateHref } from '../../services/security/href_validator';

import { euiTabStyles, euiTabContentStyles } from './tab.styles';
import { EuiTabsProps, EuiTabSizes } from './tabs';
import { EuiTabsProps, EuiTabsSizes } from './tabs';

export interface EuiTabProps extends CommonProps {
isSelected?: boolean;
Expand All @@ -43,7 +43,7 @@ export interface EuiTabProps extends CommonProps {
* Sizes affect both font size and overall size.
* Only use the `xl` size when displayed as page titles.
*/
size?: EuiTabSizes;
size?: EuiTabsSizes;
}

type EuiTabPropsForAnchor = EuiTabProps &
Expand Down Expand Up @@ -86,9 +86,8 @@ export const EuiTab: FunctionComponent<Props> = ({
const cssTabStyles = [
tabStyles.euiTab,
expand && tabStyles.expanded,
isSelected && tabStyles.selected,
disabled && tabStyles.disabled,
size && tabStyles[size],
disabled && tabStyles.disabled.disabled,
isSelected && (disabled ? tabStyles.disabled.selected : tabStyles.selected),
];

const tabContentStyles = euiTabContentStyles(euiTheme);
Expand All @@ -99,12 +98,13 @@ export const EuiTab: FunctionComponent<Props> = ({
disabled && tabContentStyles.disabled,
];

const prependNode = prepend && <span>{prepend}</span>;
const appendNode = append && <span>{append}</span>;
const prependNode = prepend && (
<span className="euiTab__prepend">{prepend}</span>
);
const appendNode = append && <span className="euiTab__append">{append}</span>;

// <a> elements don't respect the `disabled` attribute. So if we're disabled, we'll just pretend
// this is a button and piggyback off its disabled styles.

if (href && !disabled) {
const secureRel = getSecureRelForTarget({ href, target, rel });

Expand Down
Loading

0 comments on commit 83d7a6d

Please sign in to comment.