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] Converted EuiBeacon #5814

Merged
merged 18 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions src/components/beacon/__snapshots__/beacon.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`EuiBeacon accepts size 1`] = `
<div
aria-label="aria-label"
class="euiBeacon testClass1 testClass2"
class="euiBeacon testClass1 testClass2 css-haebed-euiBeacon-euiCanAnimate-euiBeacon-euiCanAnimate-euiBeacon"
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why this one is outputting -euiBeacon so many times...

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 tested and it is because of the :before and :after. I also showed it to @chandlerprall and he will take a look while trying to improve the euCanAnimate mixin.

data-test-subj="test subject string"
style="height:14px;width:14px"
/>
Expand All @@ -12,7 +12,7 @@ exports[`EuiBeacon accepts size 1`] = `
exports[`EuiBeacon is rendered 1`] = `
<div
aria-label="aria-label"
class="euiBeacon testClass1 testClass2"
class="euiBeacon testClass1 testClass2 css-haebed-euiBeacon-euiCanAnimate-euiBeacon-euiCanAnimate-euiBeacon"
data-test-subj="test subject string"
style="height:12px;width:12px"
/>
Expand Down
58 changes: 0 additions & 58 deletions src/components/beacon/_beacon.scss

This file was deleted.

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

This file was deleted.

83 changes: 83 additions & 0 deletions src/components/beacon/beacon.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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 { keyframes, css } from '@emotion/react';
import { euiPaletteColorBlind } from '../../services';
import { euiCanAnimate } from '../../global_styling/variables/_animations';

const visColors = euiPaletteColorBlind();

const euiBeaconPulseLarge = keyframes`
0% {
transform: scale(.1);
opacity: 1;
}

70% {
transform: scale(3);
opacity: 0;
}

100% {
opacity: 0;
}
`;

const euiBeaconPulseSmall = keyframes`
0% {
transform: scale(.1);
opacity: 1;
}

70% {
transform: scale(2);
opacity: 0;
}

100% {
opacity: 0;
}
`;

export const euiBeaconStyles = () => ({
// Base
euiBeacon: css`
position: relative;
background-color: ${visColors[0]};
border-radius: 50%;

&:before,
&:after {
position: absolute;
content: '';
height: 100%;
width: 100%;
left: 0;
top: 0;
miukimiu marked this conversation as resolved.
Show resolved Hide resolved
background-color: transparent;
border-radius: 50%;
box-shadow: 0 0 1px 1px ${visColors[0]};
cchaos marked this conversation as resolved.
Show resolved Hide resolved
}

&:before {
${euiCanAnimate(
css`
animation: ${euiBeaconPulseLarge} 2.5s infinite ease-out;
`
)}
}

&:after {
${euiCanAnimate(
css`
animation: ${euiBeaconPulseSmall} 2.5s infinite ease-out 0.25s;
`
)}
}
miukimiu marked this conversation as resolved.
Show resolved Hide resolved
`,
});
3 changes: 3 additions & 0 deletions src/components/beacon/beacon.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';
import { renderWithStyles } from '../../test/internal';

import { EuiBeacon } from './beacon';

describe('EuiBeacon', () => {
renderWithStyles(<EuiBeacon />);

test('is rendered', () => {
const component = render(<EuiBeacon {...requiredProps} />);

Expand Down
10 changes: 8 additions & 2 deletions src/components/beacon/beacon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import React, { FunctionComponent, HTMLAttributes } from 'react';
import { CommonProps } from '../common';
import classNames from 'classnames';

import { euiBeaconStyles } from './beacon.styles';

export type EuiBeaconProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> &
CommonProps & {
/**
Expand All @@ -25,12 +27,16 @@ export const EuiBeacon: FunctionComponent<EuiBeaconProps> = ({
...rest
}) => {
const classes = classNames('euiBeacon', className);
const styles = euiBeaconStyles();
const cssStyles = [styles.euiBeacon];

const styles = {
const beaconStyle = {
...style,
height: size,
width: size,
};

return <div className={classes} style={styles} {...rest} />;
return (
<div className={classes} css={cssStyles} style={beaconStyle} {...rest} />
);
};
1 change: 0 additions & 1 deletion src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@import 'aspect_ratio/index';
@import 'badge/index';
@import 'basic_table/index';
@import 'beacon/index';
@import 'bottom_bar/index';
@import 'button/index';
@import 'breadcrumbs/index';
Expand Down
8 changes: 4 additions & 4 deletions src/components/tour/__snapshots__/tour_step.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ exports[`EuiTourStep can change the minWidth and maxWidth 1`] = `
style="left: 0px; top: 10px;"
>
<div
class="euiBeacon euiTour__beacon"
class="euiBeacon euiTour__beacon css-haebed-euiBeacon-euiCanAnimate-euiBeacon-euiCanAnimate-euiBeacon"
style="height: 12px; width: 12px;"
/>
</div>
Expand Down Expand Up @@ -153,7 +153,7 @@ exports[`EuiTourStep can have subtitle 1`] = `
style="left: 0px; top: 10px;"
>
<div
class="euiBeacon euiTour__beacon"
class="euiBeacon euiTour__beacon css-haebed-euiBeacon-euiCanAnimate-euiBeacon-euiCanAnimate-euiBeacon"
style="height: 12px; width: 12px;"
/>
</div>
Expand Down Expand Up @@ -255,7 +255,7 @@ exports[`EuiTourStep can override the footer action 1`] = `
style="left: 0px; top: 10px;"
>
<div
class="euiBeacon euiTour__beacon"
class="euiBeacon euiTour__beacon css-haebed-euiBeacon-euiCanAnimate-euiBeacon-euiCanAnimate-euiBeacon"
style="height: 12px; width: 12px;"
/>
</div>
Expand Down Expand Up @@ -433,7 +433,7 @@ exports[`EuiTourStep is rendered 1`] = `
style="left: 0px; top: 10px;"
>
<div
class="euiBeacon euiTour__beacon"
class="euiBeacon euiTour__beacon css-haebed-euiBeacon-euiCanAnimate-euiBeacon-euiCanAnimate-euiBeacon"
style="height: 12px; width: 12px;"
/>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/global_styling/variables/_animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 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 { CSSProperties } from 'react';

/**
Expand All @@ -15,8 +15,8 @@ import { CSSProperties } from 'react';
* @param content
* @returns string
*/
export const euiCanAnimate = (content: string) => `
@media screen and (prefers-reduced-motion: no-preference) {
export const euiCanAnimate = (content: any) => css`
@media screen and (prefers-reduced-motion: no-preference) {
${content}
}
`;
Expand All @@ -28,8 +28,8 @@ export const euiCanAnimate = (content: string) => `
* @param content
* @returns string
*/
export const euiCantAnimate = (content: string) => `
@media screen and (prefers-reduced-motion: reduce) {
export const euiCantAnimate = (content: string) => css`
@media screen and (prefers-reduced-motion: reduce) {
${content}
}
`;
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/5814.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**CSS-in-JS conversions**

- Converted `EuiBeacon` to Emotion
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 add a CL item that says the canAnimate hooks have been changed to a constant?