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

[Emotion] Convert EuiBottomBar to Emotion #5823

Merged
merged 19 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4e1db78
Merge pull request #1 from elastic/main
breehall Feb 28, 2022
0671ea5
Merge branch 'main' of https://github.com/breehall/eui
breehall Mar 9, 2022
b2acbfe
Merge branch 'main' of https://github.com/breehall/eui
breehall Mar 15, 2022
9ccab1b
Merge branch 'main' of https://github.com/breehall/eui
breehall Apr 6, 2022
91bfff4
Merge branch 'main' of https://github.com/breehall/eui
breehall Apr 19, 2022
475bc12
Merge branch 'main' of https://github.com/breehall/eui into emotion-b…
breehall Apr 19, 2022
9b35152
Converted EuiBottomBar to Emotion and updated related EuiBottomBar je…
breehall Apr 20, 2022
d294eef
Merge branch 'main' of https://github.com/breehall/eui into emotion-b…
breehall Apr 20, 2022
06fcd68
Updated EuiBottomBar tests to include the shouldRenderCustomStyles ut…
breehall Apr 20, 2022
639b5cb
Updated the EuiBottomBar component by making creating a new component…
breehall Apr 21, 2022
28a74d1
Updated the EuiBottomBar props. Updated BottomBar snapshots
breehall Apr 26, 2022
fd7aff7
Resolved merge conflicts in index.scss. Changelog
breehall Apr 26, 2022
0c84ad1
Handle PR comments and resolve a merge conflict in index.scss
breehall Apr 27, 2022
518690d
Re-adding index.scss file chanes
breehall Apr 28, 2022
6b5722e
Small PR change requests
breehall Apr 29, 2022
6b08296
Added documentation for colorMode specific component pattern creation
breehall Apr 29, 2022
99b57a1
Resolved merge conflict in Writing Styles with Emotion wiki page
breehall Apr 29, 2022
73d8e3b
Update wiki/writing-styles-with-emotion.md
breehall Apr 29, 2022
3ab6514
Update wiki/writing-styles-with-emotion.md
breehall Apr 29, 2022
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
28 changes: 14 additions & 14 deletions src/components/bottom_bar/__snapshots__/bottom_bar.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`EuiBottomBar is rendered 1`] = `
Array [
<section
aria-label="aria-label"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium testClass1 testClass2"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium testClass1 testClass2 css-a95hel-euiBottomBar-fixed-m"
data-test-subj="test subject string"
style="left:0;right:0;bottom:0"
>
Expand All @@ -28,7 +28,7 @@ exports[`EuiBottomBar props affordForDisplacement can be false 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium css-a95hel-euiBottomBar-fixed-m"
style="left:0;right:0;bottom:0"
>
<h2
Expand All @@ -49,7 +49,7 @@ Array [
exports[`EuiBottomBar props bodyClassName is rendered 1`] = `
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium css-a95hel-euiBottomBar-fixed-m"
style="left: 0px; right: 0px; bottom: 0px;"
>
<h2
Expand All @@ -64,7 +64,7 @@ exports[`EuiBottomBar props landmarkHeading 1`] = `
Array [
<section
aria-label="This should have been label"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium css-a95hel-euiBottomBar-fixed-m"
style="left:0;right:0;bottom:0"
>
<h2
Expand All @@ -86,7 +86,7 @@ exports[`EuiBottomBar props paddingSize l is rendered 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingLarge"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingLarge css-1yr8u98-euiBottomBar-fixed-l"
style="left:0;right:0;bottom:0"
>
<h2
Expand All @@ -108,7 +108,7 @@ exports[`EuiBottomBar props paddingSize m is rendered 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium css-a95hel-euiBottomBar-fixed-m"
style="left:0;right:0;bottom:0"
>
<h2
Expand All @@ -130,7 +130,7 @@ exports[`EuiBottomBar props paddingSize none is rendered 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--fixed"
class="euiBottomBar euiBottomBar--fixed css-h1j77c-euiBottomBar-fixed"
style="left:0;right:0;bottom:0"
>
<h2
Expand All @@ -152,7 +152,7 @@ exports[`EuiBottomBar props paddingSize s is rendered 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingSmall"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingSmall css-s3jjcy-euiBottomBar-fixed-s"
style="left:0;right:0;bottom:0"
>
<h2
Expand All @@ -174,7 +174,7 @@ exports[`EuiBottomBar props position fixed is rendered 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium css-a95hel-euiBottomBar-fixed-m"
style="left:0;right:0;bottom:0"
>
<h2
Expand All @@ -196,7 +196,7 @@ exports[`EuiBottomBar props position props are altered 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium css-a95hel-euiBottomBar-fixed-m"
style="left:30px;right:30px;bottom:30px;top:30px"
>
<h2
Expand All @@ -218,7 +218,7 @@ exports[`EuiBottomBar props position static is rendered 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--static euiBottomBar--paddingMedium"
class="euiBottomBar euiBottomBar--static euiBottomBar--paddingMedium css-1rhqml2-euiBottomBar-static-m"
style="left:0;right:0;bottom:0"
>
<h2
Expand All @@ -240,7 +240,7 @@ exports[`EuiBottomBar props position sticky is rendered 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--sticky euiBottomBar--paddingMedium"
class="euiBottomBar euiBottomBar--sticky euiBottomBar--paddingMedium css-1yvdf64-euiBottomBar-sticky-m"
style="left:0;right:0;bottom:0"
>
<h2
Expand All @@ -262,7 +262,7 @@ exports[`EuiBottomBar props style is customized 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium css-a95hel-euiBottomBar-fixed-m"
style="left:12px;right:0;bottom:0"
>
<h2
Expand All @@ -284,7 +284,7 @@ exports[`EuiBottomBar props usePortal can be false 1`] = `
Array [
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium"
class="euiBottomBar euiBottomBar--fixed euiBottomBar--paddingMedium css-a95hel-euiBottomBar-fixed-m"
style="left:0;right:0;bottom:0"
>
<h2
Expand Down
44 changes: 0 additions & 44 deletions src/components/bottom_bar/_bottom_bar.scss

This file was deleted.

1 change: 0 additions & 1 deletion src/components/bottom_bar/_index.scss

This file was deleted.

56 changes: 56 additions & 0 deletions src/components/bottom_bar/bottom_bar.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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, keyframes } from '@emotion/react';
import { euiCanAnimate } from '../../global_styling';
import { UseEuiTheme, shade } from '../../services';
import { euiShadowFlat } from '../../themes/amsterdam/global_styling/mixins';

const euiBottomBarAppear = keyframes`
0% {
transform: translateY(100%);
opacity: 0;
}

100% {
transform: translateY(0%);
opacity: 1;
}
`;

export const euiBottomBarStyles = ({ euiTheme, colorMode }: UseEuiTheme) => ({
// Base
// Text color needs to be reapplied to properly scope the forced `colorMode`
euiBottomBar: css`
${euiShadowFlat(euiTheme, undefined, colorMode)};
background: ${shade(euiTheme.colors.lightestShade, 0.5)};
color: ${euiTheme.colors.text};
breehall marked this conversation as resolved.
Show resolved Hide resolved
${euiCanAnimate} {
animation: ${euiBottomBarAppear} ${euiTheme.animation.slow}
${euiTheme.animation.resistance};
}
`,
static: css``,
cchaos marked this conversation as resolved.
Show resolved Hide resolved
fixed: css`
z-index: ${Number(euiTheme.levels.header) - 2};
`,
sticky: css`
z-index: ${Number(euiTheme.levels.header) - 2};
`,
// Padding
s: css`
padding: ${euiTheme.size.s};
`,
m: css`
padding: ${euiTheme.size.base};
`,
l: css`
padding: ${euiTheme.size.l};
`,
none: '',
});
30 changes: 28 additions & 2 deletions src/components/bottom_bar/bottom_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import React, {
useEffect,
useState,
} from 'react';
import { useCombinedRefs } from '../../services';
import { useCombinedRefs, useEuiTheme } from '../../services';
import { EuiScreenReaderOnly } from '../accessibility';
import { CommonProps, ExclusiveUnion } from '../common';
import { EuiI18n } from '../i18n';
import { useResizeObserver } from '../observer/resize_observer';
import { EuiPortal } from '../portal';
import { euiBottomBarStyles } from './bottom_bar.styles';
import { EuiThemeProvider } from '../../services/theme/provider';

type BottomBarPaddingSize = 'none' | 's' | 'm' | 'l';

Expand Down Expand Up @@ -96,7 +98,7 @@ export type EuiBottomBarProps = CommonProps &
left?: CSSProperties['left'];
};

export const EuiBottomBar = forwardRef<
const _EuiBottomBar = forwardRef<
HTMLElement, // type of element or component the ref will be passed to
EuiBottomBarProps // what properties apart from `ref` the component accepts
>(
Expand All @@ -119,6 +121,9 @@ export const EuiBottomBar = forwardRef<
},
ref
) => {
const euiTheme = useEuiTheme();
const styles = euiBottomBarStyles(euiTheme);

// Force some props if `fixed` position, but not if the user has supplied these
affordForDisplacement =
position !== 'fixed' ? false : affordForDisplacement;
Expand Down Expand Up @@ -156,6 +161,13 @@ export const EuiBottomBar = forwardRef<
className
);

const cssStyles = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added styles[position] back to the cssStyles array because I need to access the position to determine if the z-index should be added to the bottom bar. Since I already need it for that purpose, should we just attach the position styling in those style blocks instead of passing it in directly here?

styles.euiBottomBar,
styles[position],
styles[paddingSize],
{ position },
];

const newStyle = {
left,
right,
Expand All @@ -173,11 +185,13 @@ export const EuiBottomBar = forwardRef<
{(screenReaderHeading: string) => (
// Though it would be better to use aria-labelledby than aria-label and not repeat the same string twice
// A bug in voiceover won't list some landmarks in the rotor without an aria-label

<section
aria-label={
landmarkHeading ? landmarkHeading : screenReaderHeading
}
className={classes}
css={cssStyles}
ref={setRef}
style={newStyle}
{...rest}
Expand Down Expand Up @@ -214,4 +228,16 @@ export const EuiBottomBar = forwardRef<
}
);

export const EuiBottomBar = forwardRef<HTMLElement, EuiBottomBarProps>(
(props, ref) => {
const BottomBar = _EuiBottomBar;
return (
<EuiThemeProvider colorMode={'dark'}>
<BottomBar ref={ref} {...props} />
</EuiThemeProvider>
);
}
);
Comment on lines +231 to +240
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document this as a pattern for color-mode specific components in the Emotion styling wiki???


EuiBottomBar.displayName = 'EuiBottomBar';
_EuiBottomBar.displayName = 'EuiBottomBar';
1 change: 0 additions & 1 deletion src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
@import 'accordion/index';
@import 'badge/index';
@import 'basic_table/index';
@import 'bottom_bar/index';
@import 'button/index';
@import 'breadcrumbs/index';
@import 'call_out/index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ exports[`EuiPageTemplate with bottomBar is rendered 1`] = `
</div>
<section
aria-label="Page level controls"
class="euiBottomBar euiBottomBar--sticky"
class="euiBottomBar euiBottomBar--sticky css-1cjporg-euiBottomBar-sticky"
style="left:0;right:0;bottom:0"
>
<h2
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/5823.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**CSS-in-JS conversions**

- Converted `EuiBottomBar` to Emotion
23 changes: 23 additions & 0 deletions wiki/writing-styles-with-emotion.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,30 @@ export const euiComponentNameStyles = ({ euiTheme }: UseEuiTheme) => ({
`,
});
```
## Creating `colorMode` specific components

When creating components that rely on a specific `colorMode` from `<EuiThemeProvider>`, use this pattern to create a wrapper that will pass the entire component `<EuiThemeProvider>` details.

- `_EuiComponentName` is an internal component that contains the desired functionality and styles.
- `EuiComponentName` is the exportable component that wraps `_EuiComponentName` inside of `<EuiThemeProvider>`.

```tsx
const _EuiComponentName = ({ componentProps }) => {
return <div />;
}

export const EuiComponentName = ({ componentProps }) => {
const Component = _EuiComponentName;
return (
<EuiThemeProvider colorMode={ colorMode }>
<Component {...componentProps} />
</EuiThemeProvider>
);
}
);
```

**[Refer to EuiBottomBar to see an example of this pattern in practice and as an example of using `forwardRef`.](../src/components/bottom_bar/bottom_bar.tsx)**

## FAQ

Expand Down