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

Avoid nested classes #11

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -324,30 +324,30 @@ exports[`EuiPageHeader props page content props are passed down is rendered 1`]
/>
<div
aria-label="aria-label"
class="euiTabs euiTabs--large testClass1 testClass2 emotion-euiTabs-tabSizeStyles-size_l"
class="euiTabs euiTabs--large testClass1 testClass2 emotion-euiTabs-l"
data-test-subj="test subject string"
role="tablist"
>
<button
aria-selected="true"
class="euiTab euiTab-isSelected emotion-euiTab-selected"
class="euiTab euiTab-isSelected emotion-euiTab-selected-l"
role="tab"
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content-l-selected"
>
Tab 1
</span>
</button>
<button
aria-selected="false"
class="euiTab emotion-euiTab"
class="euiTab emotion-euiTab-l"
role="tab"
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content-l"
>
Tab 2
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,29 +285,29 @@ exports[`EuiPageHeaderContent props children is rendered even if content props a
class="euiSpacer euiSpacer--l emotion-euiSpacer-l"
/>
<div
class="euiTabs euiTabs--large emotion-euiTabs-tabSizeStyles-size_l"
class="euiTabs euiTabs--large emotion-euiTabs-l"
role="tablist"
>
<button
aria-selected="true"
class="euiTab euiTab-isSelected emotion-euiTab-selected"
class="euiTab euiTab-isSelected emotion-euiTab-selected-l"
role="tab"
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content-l-selected"
>
Tab 1
</span>
</button>
<button
aria-selected="false"
class="euiTab emotion-euiTab"
class="euiTab emotion-euiTab-l"
role="tab"
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content-l"
>
Tab 2
</span>
Expand Down Expand Up @@ -574,29 +574,29 @@ exports[`EuiPageHeaderContent props tabs is rendered 1`] = `
Tab 1
</h1>
<div
class="euiTabs euiTabs--xlarge emotion-euiTabs-tabSizeStyles-size_xl"
class="euiTabs euiTabs--xlarge emotion-euiTabs-xl"
role="tablist"
>
<button
aria-selected="true"
class="euiTab euiTab-isSelected emotion-euiTab-selected"
class="euiTab euiTab-isSelected emotion-euiTab-selected-xl"
role="tab"
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content-xl-selected"
>
Tab 1
</span>
</button>
<button
aria-selected="false"
class="euiTab emotion-euiTab"
class="euiTab emotion-euiTab-xl"
role="tab"
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content-xl"
>
Tab 2
</span>
Expand Down Expand Up @@ -624,30 +624,30 @@ exports[`EuiPageHeaderContent props tabs is rendered with tabsProps 1`] = `
</h1>
<div
aria-label="aria-label"
class="euiTabs euiTabs--xlarge testClass1 testClass2 emotion-euiTabs-tabSizeStyles-size_xl"
class="euiTabs euiTabs--xlarge testClass1 testClass2 emotion-euiTabs-xl"
data-test-subj="test subject string"
role="tablist"
>
<button
aria-selected="true"
class="euiTab euiTab-isSelected emotion-euiTab-selected"
class="euiTab euiTab-isSelected emotion-euiTab-selected-xl"
role="tab"
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content-xl-selected"
>
Tab 1
</span>
</button>
<button
aria-selected="false"
class="euiTab emotion-euiTab"
class="euiTab emotion-euiTab-xl"
role="tab"
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content-xl"
>
Tab 2
</span>
Expand Down
12 changes: 6 additions & 6 deletions src/components/tabs/__snapshots__/tab.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`EuiTab props append is rendered 1`] = `
Append
</span>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content"
>
children
</span>
Expand All @@ -29,7 +29,7 @@ exports[`EuiTab props disabled is rendered 1`] = `
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content-disabled"
>
Click Me
</span>
Expand All @@ -47,7 +47,7 @@ exports[`EuiTab props href renders anchor 1`] = `
role="tab"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content"
>
children
</span>
Expand All @@ -62,7 +62,7 @@ exports[`EuiTab props isSelected is rendered 1`] = `
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content-selected"
>
children
</span>
Expand All @@ -79,7 +79,7 @@ exports[`EuiTab props onClick renders button 1`] = `
type="button"
>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content"
>
children
</span>
Expand All @@ -99,7 +99,7 @@ exports[`EuiTab props prepend is rendered 1`] = `
Prepend
</span>
<span
class="euiTab__content"
class="euiTab__content emotion-euiTab__content"
>
children
</span>
Expand Down
36 changes: 12 additions & 24 deletions src/components/tabs/__snapshots__/tabs.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,44 @@

exports[`EuiTabs props expand is rendered 1`] = `
<div
class="euiTabs euiTabs--medium euiTabs--expand euiTabs--bottomBorder emotion-euiTabs-tabSizeStyles-size_m-bottomBorder-expanded"
class="euiTabs euiTabs--medium euiTabs--expand euiTabs--bottomBorder emotion-euiTabs-m-bottomBorder"
role="tablist"
>
children
</div>
/>
`;

exports[`EuiTabs props size l is rendered 1`] = `
<div
class="euiTabs euiTabs--large euiTabs--bottomBorder emotion-euiTabs-tabSizeStyles-size_l-bottomBorder"
class="euiTabs euiTabs--large euiTabs--bottomBorder emotion-euiTabs-l-bottomBorder"
role="tablist"
>
children
</div>
/>
`;

exports[`EuiTabs props size m is rendered 1`] = `
<div
class="euiTabs euiTabs--medium euiTabs--bottomBorder emotion-euiTabs-tabSizeStyles-size_m-bottomBorder"
class="euiTabs euiTabs--medium euiTabs--bottomBorder emotion-euiTabs-m-bottomBorder"
role="tablist"
>
children
</div>
/>
`;

exports[`EuiTabs props size s is rendered 1`] = `
<div
class="euiTabs euiTabs--small euiTabs--bottomBorder emotion-euiTabs-tabSizeStyles-size_s-bottomBorder"
class="euiTabs euiTabs--small euiTabs--bottomBorder emotion-euiTabs-s-bottomBorder"
role="tablist"
>
children
</div>
/>
`;

exports[`EuiTabs props size xl is rendered 1`] = `
<div
class="euiTabs euiTabs--xlarge euiTabs--bottomBorder emotion-euiTabs-tabSizeStyles-size_xl-bottomBorder"
class="euiTabs euiTabs--xlarge euiTabs--bottomBorder emotion-euiTabs-xl-bottomBorder"
role="tablist"
>
children
</div>
/>
`;

exports[`EuiTabs renders 1`] = `
<div
aria-label="aria-label"
class="euiTabs euiTabs--medium euiTabs--bottomBorder testClass1 testClass2 emotion-euiTabs-tabSizeStyles-size_m-bottomBorder"
class="euiTabs euiTabs--medium euiTabs--bottomBorder testClass1 testClass2 emotion-euiTabs-m-bottomBorder"
data-test-subj="test subject string"
role="tablist"
>
children
</div>
/>
`;
82 changes: 60 additions & 22 deletions src/components/tabs/tab.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

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

export const euiTabStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;

export const euiTabStyles = ({ euiTheme }: UseEuiTheme) => {
return {
euiTab: css`
display: flex;
Expand All @@ -25,24 +24,30 @@ export const euiTabStyles = (euiThemeContext: UseEuiTheme) => {
background-color: transparent;
outline-offset: -${euiTheme.focus.width};
}

.euiTab__content {
color: ${euiTheme.colors.text};

&:hover {
text-decoration: underline;
}
}
`,

// 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};
.euiTab__content {
color: ${euiTheme.colors.primaryText};
}
`,

disabled: css`
cursor: not-allowed;

Expand All @@ -60,14 +65,47 @@ export const euiTabStyles = (euiThemeContext: UseEuiTheme) => {
box-shadow: inset 0 calc(${euiTheme.border.width.thick} * -1) 0
${euiTheme.colors.disabledText};
}
`,
};
};

/* Specificity to get the color applied properly */
span.euiTab__content {
color: ${euiTheme.colors.disabledText};
export const euiTabContentStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;

return {
euiTab__content: css`
color: ${euiTheme.colors.disabledText};

&:hover {
text-decoration: none;
}
`,
// sizes
s: css`
${euiTitle(euiThemeContext, 'xxxs')};
line-height: ${euiTheme.size.xl};
`,
m: css`
${euiTitle(euiThemeContext, 'xxs')};
line-height: ${euiTheme.size.xxl};
`,
l: css`
${euiTitle(euiThemeContext, 'xs')};
line-height: calc(${euiTheme.size.xl} + ${euiTheme.size.s});
`,
xl: css`
${euiTitle(euiThemeContext, 's')};
line-height: calc(${euiTheme.size.xxxl} + ${euiTheme.size.s});
`,
// variations
selected: css`
color: ${euiTheme.colors.primaryText};
`,
disabled: css`
color: ${euiTheme.colors.disabledText};

&:hover {
text-decoration: none;
}
&:hover {
text-decoration: none;
}
`,
};
Expand Down
Loading