Skip to content

Commit

Permalink
[EuiCard & friends] Convert to Emotion (#6110)
Browse files Browse the repository at this point in the history
* [EuiCheckableCard] Converted

Todo: Investigate why `shouldRenderCustomStyles` doesn’t work

* [EuiCardSelect] Converted and using basic EuiButton and styles

… to match proposed design from Figma

* WIP: Most text-based content converted

and cleaning up some outdated styles

* WIP: Refactored how `betaBadge` is presented

- Added `anchorProps` to EuiToolTip and EuiBetaBadge to allow passing through more options like `css`
- Added truncation to EuiBetaBadge and white background for `hollow`

* WIP: Styles for image and icon converted

- Passes through `paddingSize` and `display` for some generated styles
- Explicitely sets default padding to `m` and keeps `m` when `betaBadge` exists

* WIP: Final styles for `layout`

- Added progressive enhancement for `:has()` to propograte the outline to the whole card
- Deleted the Sass files

* Cleanup

- Logicals
- Converted docs to TSX
- Fixed top padding for badge

* Added bordered example

* [EuiToolTip] Allowing `anchorProps.className` and tests

* Fixes, tests, and CL

* update CL

Co-authored-by: cchaos <caroline.horn@elastic.co>
Co-authored-by: Greg Thompson <thompson.glowe@gmail.com>
  • Loading branch information
3 people authored Aug 22, 2022
1 parent 1505e2f commit 0b7a908
Show file tree
Hide file tree
Showing 47 changed files with 1,031 additions and 745 deletions.
File renamed without changes.
13 changes: 10 additions & 3 deletions src-docs/src/views/card/card_beta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default () => (
title="Dashboards"
description="Example of a card's description. Stick to one or two sentences."
onClick={() => {}}
betaBadgeProps={{
label: 'Beta',
tooltipContent:
'This module is not GA. Please help us by reporting any bugs.',
}}
/>
</EuiFlexItem>
<EuiFlexItem>
Expand All @@ -23,9 +28,10 @@ export default () => (
title="Monitoring"
description="Example of a card's description. Stick to one or two sentences."
betaBadgeProps={{
label: 'Beta',
label: 'Accent',
color: 'accent',
tooltipContent:
'This module is not GA. Please help us by reporting any bugs.',
'You can change the badge color using betaBadgeProps.color.',
}}
onClick={() => {}}
/>
Expand All @@ -40,7 +46,8 @@ export default () => (
href: 'http://www.elastic.co/subscriptions',
target: '_blank',
label: 'Basic',
tooltipContent: 'This feature requires a Basic License',
tooltipContent:
'Disabled cards with still clickable badges will stay hollow.',
}}
onClick={() => {}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import {
EuiRadioGroup,
EuiTitle,
EuiFormFieldset,
} from '../../../../src/components';

import { useGeneratedHtmlId } from '../../../../src/services';
useGeneratedHtmlId,
} from '../../../../src';

export default () => {
const radioGroupId = useGeneratedHtmlId({ prefix: 'radioGroup' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { useState } from 'react';

import { EuiCheckableCard } from '../../../../src/components';

import { useGeneratedHtmlId } from '../../../../src/services';
import { EuiCheckableCard, useGeneratedHtmlId } from '../../../../src';

export default () => {
const [checkbox, setCheckbox] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
EuiText,
EuiButton,
EuiCode,
} from '../../../../src/components';
} from '../../../../src';

const radios = [
{
Expand Down
14 changes: 12 additions & 2 deletions src-docs/src/views/card/card_display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
EuiFlexItem,
EuiIcon,
EuiSpacer,
} from '../../../../src/components';
} from '../../../../src';

export default () => (
<div>
<EuiSpacer size="s" />
<EuiFlexGroup gutterSize="l">
<EuiFlexGroup gutterSize="l" wrap>
<EuiFlexItem>
<EuiCard
layout="horizontal"
Expand Down Expand Up @@ -46,6 +46,16 @@ export default () => (
onClick={() => {}}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiCard
icon={<EuiIcon size="xl" type="logoLogging" />}
title="Bordered"
display="plain"
hasBorder
description="This one has a plain background color and border."
onClick={() => {}}
/>
</EuiFlexItem>
</EuiFlexGroup>
</div>
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
EuiLink,
EuiSpacer,
EuiText,
} from '../../../../src/components';
} from '../../../../src';

export default () => (
<EuiFlexGroup gutterSize="l">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
} from '../../../../src/components';

const cardFooterContent = (
<EuiFlexGroup justifyContent="flexEnd">
<EuiFlexItem grow={false}>
<EuiButton>Go for it</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
);
} from '../../../../src';

export default () => (
<EuiFlexGroup gutterSize="l">
Expand All @@ -31,7 +23,13 @@ export default () => (
}
title="Elastic in Nature"
description="Example of a card's description. Stick to one or two sentences."
footer={cardFooterContent}
footer={
<EuiFlexGroup justifyContent="flexEnd">
<EuiFlexItem grow={false}>
<EuiButton>Go for it</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
}
/>
</EuiFlexItem>
<EuiFlexItem>
Expand All @@ -40,7 +38,7 @@ export default () => (
image="https://source.unsplash.com/400x200/?Water"
title="Elastic in Water"
description="Example of a card's description. Stick to one or two sentences."
footer={cardFooterContent}
isDisabled
/>
</EuiFlexItem>
<EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import React from 'react';

import {
EuiCard,
EuiIcon,
EuiFlexGroup,
EuiFlexItem,
} from '../../../../src/components';
import { EuiCard, EuiIcon, EuiFlexGroup, EuiFlexItem } from '../../../../src';

export default () => (
<EuiFlexGroup gutterSize="l">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
EuiIcon,
EuiFlexGroup,
EuiFlexItem,
} from '../../../../src/components';
} from '../../../../src';

export default () => {
const [card1Selected, setCard1] = useState(true);
Expand All @@ -20,7 +20,7 @@ export default () => {
setCard2(!card2Selected);
};

const detailsClicked = (e) => {
const detailsClicked = (e: { stopPropagation: () => void }) => {
e.stopPropagation();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,18 @@ exports[`EuiBetaBadge props size s is rendered 1`] = `
Beta
</span>
`;

exports[`EuiBetaBadge props tooltip and anchorProps are rendered 1`] = `
<span
class="euiToolTipAnchor customAnchorClass"
data-test-subj="DTS"
>
<span
class="euiBetaBadge euiBetaBadge--hollow"
role="button"
tabindex="0"
>
Beta
</span>
</span>
`;
6 changes: 5 additions & 1 deletion src/components/badge/beta_badge/_beta_badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
text-align: center;
white-space: nowrap;
cursor: default;
overflow: hidden;
text-overflow: ellipsis;

&:focus {
@include euiFocusRing;
Expand Down Expand Up @@ -70,9 +72,11 @@
}

.euiBetaBadge--hollow {
background-color: $euiColorEmptyShade;

&.euiBetaBadge-isClickable {
$backgroundColor: tint($euiColorLightShade, 30%);
color: chooseLightOrDarkText($backgroundColor, $euiColorGhost, $euiColorInk);
color: chooseLightOrDarkText($euiColorEmptyShade, $euiColorGhost, $euiColorInk);
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/components/badge/beta_badge/beta_badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,20 @@ describe('EuiBetaBadge', () => {
});
});
});

test('tooltip and anchorProps are rendered', () => {
const component = render(
<EuiBetaBadge
label="Beta"
tooltipContent="Tooltip"
anchorProps={{
className: 'customAnchorClass',
'data-test-subj': 'DTS',
}}
/>
);

expect(component).toMatchSnapshot();
});
});
});
10 changes: 9 additions & 1 deletion src/components/badge/beta_badge/beta_badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CommonProps, ExclusiveUnion, keysOf } from '../../common';

import { getSecureRelForTarget } from '../../../services';

import { EuiToolTip, ToolTipPositions } from '../../tool_tip';
import { EuiToolTip, EuiToolTipProps, ToolTipPositions } from '../../tool_tip';

import { EuiIcon, IconType } from '../../icon';

Expand Down Expand Up @@ -108,6 +108,11 @@ type BadgeProps = {
*/
tooltipPosition?: ToolTipPositions;

/**
* Passes onto the span wrapping the badge
*/
anchorProps?: EuiToolTipProps['anchorProps'];

/**
* Optional title will be supplied as tooltip title or title attribute
* otherwise the label will be used
Expand All @@ -133,6 +138,7 @@ export const EuiBetaBadge: FunctionComponent<EuiBetaBadgeProps> = ({
color = 'hollow',
tooltipContent,
tooltipPosition = 'top',
anchorProps,
title,
iconType,
onClick,
Expand Down Expand Up @@ -211,6 +217,7 @@ export const EuiBetaBadge: FunctionComponent<EuiBetaBadgeProps> = ({
position={tooltipPosition}
content={tooltipContent}
title={title || label}
anchorProps={anchorProps}
>
{content}
</EuiToolTip>
Expand All @@ -225,6 +232,7 @@ export const EuiBetaBadge: FunctionComponent<EuiBetaBadgeProps> = ({
position={tooltipPosition}
content={tooltipContent}
title={title || label}
anchorProps={anchorProps}
>
<span tabIndex={0} className={classes} role="button" {...rest}>
{icon || label}
Expand Down
Loading

0 comments on commit 0b7a908

Please sign in to comment.