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 EuiBadgeGroup, EuiBetaBadge, and EuiNotificationBadge #6258

Merged
merged 8 commits into from
Sep 23, 2022
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
2 changes: 1 addition & 1 deletion src-docs/src/views/badge/badge_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export const BadgeExample = {
title: 'Beta badge type',
source: [
{
type: GuideSectionTypes.JS,
type: GuideSectionTypes.TSX,
code: betaBadgeSource,
},
],
Expand Down
60 changes: 0 additions & 60 deletions src-docs/src/views/badge/beta_badge.js

This file was deleted.

72 changes: 72 additions & 0 deletions src-docs/src/views/badge/beta_badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react';
import { css } from '@emotion/react';

import { EuiBetaBadge, EuiSpacer, EuiTitle } from '../../../../src/components';

const colors = ['hollow', 'accent', 'subdued'] as const;

export default () => (
<>
<div
css={css`
display: grid;
align-items: flex-start;
grid: repeat(3, max-content) / repeat(6, max-content);
gap: 0.75rem;
`}
>
{colors.map((item) => (
<>
<EuiBetaBadge
label="Beta"
color={item}
tooltipContent="This module is not GA. Please help us by reporting any bugs."
/>
<EuiBetaBadge
label="Beta"
color={item}
size="s"
tooltipContent="This module is not GA. Please help us by reporting any bugs."
/>
<EuiBetaBadge label="Beta" color={item} iconType="beta" />
<EuiBetaBadge size="s" label="Beta" color={item} iconType="beta" />
<EuiBetaBadge label="Lab" color={item} iconType="beaker" />
<EuiBetaBadge label="Lab" size="s" color={item} iconType="beaker" />
</>
))}
</div>
<EuiSpacer size="s" />
<EuiTitle size="s">
<h3>
Beta badges will also line up nicely with titles &nbsp;
<EuiBetaBadge
label="Lab"
tooltipContent="This module is not GA. Please help us by reporting any bugs."
/>
</h3>
</EuiTitle>
<EuiSpacer />
<EuiTitle size="xs">
<h3>Clickable beta badges</h3>
</EuiTitle>
<EuiSpacer size="s" />
<div
css={css`
display: flex;
align-items: center;
gap: 0.75rem;
`}
>
<EuiBetaBadge
label="Lens"
iconType="lensApp"
onClick={() => alert('Goes to Lens')}
/>
Comment on lines +60 to +64
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed in CodeSandbox that still has the .scss this example doesn't get a circular EuiBetaBadge:

Screenshot 2022-09-22 at 11 54 24

If I copy the new styles and add them in Chrome developer tool the beta badge doesn't get circular. So not sure if this issue keeps persisting with the new styles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CodeSandbox doesn't update until our releases, so I can't say for sure. If the staging/local example works, I think this should work.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you look at the current version (https://elastic.github.io/eui/#/display/badge#beta-badge-type) it works in staging/local but it looks different in CodeSandbox. The beta badge with the lens icon doesn't get circular.

So I'm not sure this problem will persist. But we can take a look after this PR is merged and there's a new release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let's wait until the release, it's a little too hard for me to debug right now with the different styles. If it persists after release I think I may have a solution however!

<EuiBetaBadge
label="Basic"
href="http://www.elastic.co/subscriptions"
target="_blank"
/>
</div>
</>
);
3 changes: 0 additions & 3 deletions src/components/badge/_index.scss

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,39 @@

exports[`EuiBadgeGroup gutterSize none is rendered 1`] = `
<div
class="euiBadgeGroup"
class="euiBadgeGroup emotion-euiBadgeGroup-none"
/>
`;

exports[`EuiBadgeGroup gutterSize s is rendered 1`] = `
<div
class="euiBadgeGroup euiBadgeGroup--gutterSmall"
class="euiBadgeGroup emotion-euiBadgeGroup-s"
/>
`;

exports[`EuiBadgeGroup gutterSize xs is rendered 1`] = `
<div
class="euiBadgeGroup euiBadgeGroup--gutterExtraSmall"
class="euiBadgeGroup emotion-euiBadgeGroup-xs"
/>
`;

exports[`EuiBadgeGroup is rendered 1`] = `
<div
aria-label="aria-label"
class="euiBadgeGroup euiBadgeGroup--gutterExtraSmall testClass1 testClass2"
class="euiBadgeGroup testClass1 testClass2 emotion-euiBadgeGroup-xs"
data-test-subj="test subject string"
>
<span
class="euiBadgeGroup__item"
class="euiBadge emotion-euiBadge"
style="background-color:#D3DAE6;color:#000"
>
<span
class="euiBadge emotion-euiBadge"
style="background-color:#D3DAE6;color:#000"
class="euiBadge__content emotion-euiBadge__content"
>
<span
class="euiBadge__content emotion-euiBadge__content"
class="euiBadge__text emotion-euiBadge__text"
>
<span
class="euiBadge__text emotion-euiBadge__text"
>
Content
</span>
Content
</span>
</span>
</span>
Expand Down
23 changes: 0 additions & 23 deletions src/components/badge/badge_group/_badge_group.scss

This file was deleted.

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

This file was deleted.

34 changes: 34 additions & 0 deletions src/components/badge/badge_group/badge_group.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 { logicalCSS } from '../../../global_styling';
import { UseEuiTheme } from '../../../services';

export const euiBadgeGroupStyles = ({ euiTheme }: UseEuiTheme) => {
return {
euiBadgeGroup: css`
display: inline-flex;
flex-wrap: wrap;
${logicalCSS('max-width', '100%')}

// Override the .euiBadge + .euiBadge CSS in badge.styles.ts
.euiBadge {
${logicalCSS('margin-left', 0)}
}
`,
// Gutter sizes
none: css``,
s: css`
gap: ${euiTheme.size.s};
`,
xs: css`
gap: ${euiTheme.size.xs};
`,
};
};
3 changes: 3 additions & 0 deletions src/components/badge/badge_group/badge_group.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../../test/required_props';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiBadge } from '../badge';
import { EuiBadgeGroup, GUTTER_SIZES } from './badge_group';

describe('EuiBadgeGroup', () => {
shouldRenderCustomStyles(<EuiBadgeGroup />);

test('is rendered', () => {
const component = render(
<EuiBadgeGroup {...requiredProps}>
Expand Down
33 changes: 14 additions & 19 deletions src/components/badge/badge_group/badge_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@

import React, { forwardRef, HTMLAttributes, Ref, ReactNode } from 'react';
import classNames from 'classnames';
import { CommonProps, keysOf } from '../../common';
import { CommonProps } from '../../common';
import { useEuiTheme } from '../../../services';

const gutterSizeToClassNameMap = {
none: null,
xs: 'euiBadgeGroup--gutterExtraSmall',
s: 'euiBadgeGroup--gutterSmall',
};
import { euiBadgeGroupStyles } from './badge_group.styles';

export const GUTTER_SIZES = keysOf(gutterSizeToClassNameMap);
type BadgeGroupGutterSize = keyof typeof gutterSizeToClassNameMap;
export const GUTTER_SIZES = ['none', 'xs', 's'] as const;
type BadgeGroupGutterSize = typeof GUTTER_SIZES[number];

export interface EuiBadgeGroupProps {
/**
* Space between badges
*/
gutterSize?: BadgeGroupGutterSize;
/**
* Should be a list of EuiBadge's but can also be any other element
* Will apply an extra class to add spacing
* Should be a list of `EuiBadge`s, but can also be any other element
*/
children?: ReactNode;
}
Expand All @@ -39,17 +35,16 @@ export const EuiBadgeGroup = forwardRef<
{ children, className, gutterSize = 'xs', ...rest },
ref: Ref<HTMLDivElement>
) => {
const classes = classNames(
'euiBadgeGroup',
gutterSizeToClassNameMap[gutterSize as BadgeGroupGutterSize],
className
);
const euiTheme = useEuiTheme();

const styles = euiBadgeGroupStyles(euiTheme);
const cssStyles = [styles.euiBadgeGroup, styles[gutterSize]];

const classes = classNames('euiBadgeGroup', className);

return (
<div className={classes} ref={ref} {...rest}>
{React.Children.map(children, (child: ReactNode) => (
<span className="euiBadgeGroup__item">{child}</span>
))}
<div css={cssStyles} className={classes} ref={ref} {...rest}>
{children}
</div>
);
}
Expand Down
Loading