diff --git a/src-docs/src/views/card/card.js b/src-docs/src/views/card/card.tsx similarity index 100% rename from src-docs/src/views/card/card.js rename to src-docs/src/views/card/card.tsx diff --git a/src-docs/src/views/card/card_beta.tsx b/src-docs/src/views/card/card_beta.tsx index cead3eb18a4..a0f526cb884 100644 --- a/src-docs/src/views/card/card_beta.tsx +++ b/src-docs/src/views/card/card_beta.tsx @@ -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.', + }} /> @@ -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={() => {}} /> @@ -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={() => {}} /> diff --git a/src-docs/src/views/card/card_checkable.js b/src-docs/src/views/card/card_checkable.tsx similarity index 95% rename from src-docs/src/views/card/card_checkable.js rename to src-docs/src/views/card/card_checkable.tsx index 7c3f917cef2..3745f95a9b5 100644 --- a/src-docs/src/views/card/card_checkable.js +++ b/src-docs/src/views/card/card_checkable.tsx @@ -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' }); diff --git a/src-docs/src/views/card/card_checkable_checkbox.js b/src-docs/src/views/card/card_checkable_checkbox.tsx similarity index 76% rename from src-docs/src/views/card/card_checkable_checkbox.js rename to src-docs/src/views/card/card_checkable_checkbox.tsx index 3cdd265f62c..6deb6bf35c3 100644 --- a/src-docs/src/views/card/card_checkable_checkbox.js +++ b/src-docs/src/views/card/card_checkable_checkbox.tsx @@ -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); diff --git a/src-docs/src/views/card/card_children.js b/src-docs/src/views/card/card_children.tsx similarity index 98% rename from src-docs/src/views/card/card_children.js rename to src-docs/src/views/card/card_children.tsx index ad7c5388b9f..9f04957292f 100644 --- a/src-docs/src/views/card/card_children.js +++ b/src-docs/src/views/card/card_children.tsx @@ -9,7 +9,7 @@ import { EuiText, EuiButton, EuiCode, -} from '../../../../src/components'; +} from '../../../../src'; const radios = [ { diff --git a/src-docs/src/views/card/card_display.tsx b/src-docs/src/views/card/card_display.tsx index 5e6cbedf567..779c9fd57ed 100644 --- a/src-docs/src/views/card/card_display.tsx +++ b/src-docs/src/views/card/card_display.tsx @@ -6,12 +6,12 @@ import { EuiFlexItem, EuiIcon, EuiSpacer, -} from '../../../../src/components'; +} from '../../../../src'; export default () => (
- + ( onClick={() => {}} /> + + } + title="Bordered" + display="plain" + hasBorder + description="This one has a plain background color and border." + onClick={() => {}} + /> +
); diff --git a/src-docs/src/views/card/card_footer.js b/src-docs/src/views/card/card_footer.tsx similarity index 98% rename from src-docs/src/views/card/card_footer.js rename to src-docs/src/views/card/card_footer.tsx index 21e340f2db1..80def4bc259 100644 --- a/src-docs/src/views/card/card_footer.js +++ b/src-docs/src/views/card/card_footer.tsx @@ -9,7 +9,7 @@ import { EuiLink, EuiSpacer, EuiText, -} from '../../../../src/components'; +} from '../../../../src'; export default () => ( diff --git a/src-docs/src/views/card/card_image.js b/src-docs/src/views/card/card_image.tsx similarity index 80% rename from src-docs/src/views/card/card_image.js rename to src-docs/src/views/card/card_image.tsx index 641de21b175..4f420364351 100644 --- a/src-docs/src/views/card/card_image.js +++ b/src-docs/src/views/card/card_image.tsx @@ -6,15 +6,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiIcon, -} from '../../../../src/components'; - -const cardFooterContent = ( - - - Go for it - - -); +} from '../../../../src'; export default () => ( @@ -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={ + + + Go for it + + + } />
@@ -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 /> diff --git a/src-docs/src/views/card/card_layout.js b/src-docs/src/views/card/card_layout.tsx similarity index 90% rename from src-docs/src/views/card/card_layout.js rename to src-docs/src/views/card/card_layout.tsx index cb8c2f4babc..3ad01189c56 100644 --- a/src-docs/src/views/card/card_layout.js +++ b/src-docs/src/views/card/card_layout.tsx @@ -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 () => ( diff --git a/src-docs/src/views/card/card_selectable.js b/src-docs/src/views/card/card_selectable.tsx similarity index 96% rename from src-docs/src/views/card/card_selectable.js rename to src-docs/src/views/card/card_selectable.tsx index f14f6c8176f..10e80515724 100644 --- a/src-docs/src/views/card/card_selectable.js +++ b/src-docs/src/views/card/card_selectable.tsx @@ -6,7 +6,7 @@ import { EuiIcon, EuiFlexGroup, EuiFlexItem, -} from '../../../../src/components'; +} from '../../../../src'; export default () => { const [card1Selected, setCard1] = useState(true); @@ -20,7 +20,7 @@ export default () => { setCard2(!card2Selected); }; - const detailsClicked = (e) => { + const detailsClicked = (e: { stopPropagation: () => void }) => { e.stopPropagation(); }; diff --git a/src/components/badge/beta_badge/__snapshots__/beta_badge.test.tsx.snap b/src/components/badge/beta_badge/__snapshots__/beta_badge.test.tsx.snap index 6b3d4c7b8c2..c5af38cf3a1 100644 --- a/src/components/badge/beta_badge/__snapshots__/beta_badge.test.tsx.snap +++ b/src/components/badge/beta_badge/__snapshots__/beta_badge.test.tsx.snap @@ -55,3 +55,18 @@ exports[`EuiBetaBadge props size s is rendered 1`] = ` Beta `; + +exports[`EuiBetaBadge props tooltip and anchorProps are rendered 1`] = ` + + + Beta + + +`; diff --git a/src/components/badge/beta_badge/_beta_badge.scss b/src/components/badge/beta_badge/_beta_badge.scss index 9e527a82457..30609421115 100644 --- a/src/components/badge/beta_badge/_beta_badge.scss +++ b/src/components/badge/beta_badge/_beta_badge.scss @@ -13,6 +13,8 @@ text-align: center; white-space: nowrap; cursor: default; + overflow: hidden; + text-overflow: ellipsis; &:focus { @include euiFocusRing; @@ -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); } } diff --git a/src/components/badge/beta_badge/beta_badge.test.tsx b/src/components/badge/beta_badge/beta_badge.test.tsx index 65c6154c00b..ff822c45f99 100644 --- a/src/components/badge/beta_badge/beta_badge.test.tsx +++ b/src/components/badge/beta_badge/beta_badge.test.tsx @@ -39,5 +39,20 @@ describe('EuiBetaBadge', () => { }); }); }); + + test('tooltip and anchorProps are rendered', () => { + const component = render( + + ); + + expect(component).toMatchSnapshot(); + }); }); }); diff --git a/src/components/badge/beta_badge/beta_badge.tsx b/src/components/badge/beta_badge/beta_badge.tsx index 4bf73618f96..7c001badfb2 100644 --- a/src/components/badge/beta_badge/beta_badge.tsx +++ b/src/components/badge/beta_badge/beta_badge.tsx @@ -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'; @@ -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 @@ -133,6 +138,7 @@ export const EuiBetaBadge: FunctionComponent = ({ color = 'hollow', tooltipContent, tooltipPosition = 'top', + anchorProps, title, iconType, onClick, @@ -211,6 +217,7 @@ export const EuiBetaBadge: FunctionComponent = ({ position={tooltipPosition} content={tooltipContent} title={title || label} + anchorProps={anchorProps} > {content} @@ -225,6 +232,7 @@ export const EuiBetaBadge: FunctionComponent = ({ position={tooltipPosition} content={tooltipContent} title={title || label} + anchorProps={anchorProps} > {icon || label} diff --git a/src/components/card/__snapshots__/card.test.tsx.snap b/src/components/card/__snapshots__/card.test.tsx.snap index 147a171d1a6..180403d861c 100644 --- a/src/components/card/__snapshots__/card.test.tsx.snap +++ b/src/components/card/__snapshots__/card.test.tsx.snap @@ -2,19 +2,23 @@ exports[`EuiCard betaBadgeProps renders href 1`] = `
- - Card title - + + Card title + +

@@ -22,37 +26,37 @@ exports[`EuiCard betaBadgeProps renders href 1`] = `

- - - Link - - + Link +
`; exports[`EuiCard horizontal selectable 1`] = `
- - Card title - + + Card title + +

@@ -60,18 +64,21 @@ exports[`EuiCard horizontal selectable 1`] = `

+
- +

@@ -629,19 +708,23 @@ exports[`EuiCard props isDisabled 1`] = ` exports[`EuiCard props paddingSize l is rendered 1`] = `

- - Card title - + + Card title + +

@@ -654,19 +737,23 @@ exports[`EuiCard props paddingSize l is rendered 1`] = ` exports[`EuiCard props paddingSize m is rendered 1`] = `

- - Card title - + + Card title + +

@@ -679,19 +766,23 @@ exports[`EuiCard props paddingSize m is rendered 1`] = ` exports[`EuiCard props paddingSize none is rendered 1`] = `

- - Card title - + + Card title + +

@@ -704,19 +795,23 @@ exports[`EuiCard props paddingSize none is rendered 1`] = ` exports[`EuiCard props paddingSize s is rendered 1`] = `

- - Card title - + + Card title + +

@@ -729,19 +824,23 @@ exports[`EuiCard props paddingSize s is rendered 1`] = ` exports[`EuiCard props paddingSize xl is rendered 1`] = `

- - Card title - + + Card title + +

@@ -754,19 +853,23 @@ exports[`EuiCard props paddingSize xl is rendered 1`] = ` exports[`EuiCard props paddingSize xs is rendered 1`] = `

- - Card title - + + Card title + +

@@ -779,19 +882,23 @@ exports[`EuiCard props paddingSize xs is rendered 1`] = ` exports[`EuiCard props selectable 1`] = `

- - Card title - + + Card title + +

@@ -799,18 +906,21 @@ exports[`EuiCard props selectable 1`] = `

+
); } else { - theTitle = title; + theTitle = {title}; } /** - * Convert titleElement to a capital TitleElement + * Children and/or Description content */ + let optionalChildren; + if (children) { + const childrenStyles = [styles.euiCard__children]; + optionalChildren =
{children}
; + } - const TitleElement = titleElement; + let optionalDescription; + if (description) { + const descriptionStyles = [styles.euiCard__description]; + optionalDescription = ( + +

{description}

+
+ ); + } + + /** + * Footer content + */ + let optionalFooter; + if (layout === 'vertical' && footer) { + const footerStyles = [styles.euiCard__footer]; + optionalFooter =
{footer}
; + } return ( = ({ > {optionalCardTop} -
+
= ({ {theTitle} - {description && ( - -

{description}

-
- )} + {optionalDescription} - {children &&
{children}
} + {optionalChildren}
{/* Beta badge should always be after the title/description but before any footer buttons */} {optionalBetaBadge} - {layout === 'vertical' && footer && ( -
{footer}
- )} + {optionalFooter} + {optionalSelectButton} ); diff --git a/src/components/card/__snapshots__/card_select.test.tsx.snap b/src/components/card/card_select/__snapshots__/card_select.test.tsx.snap similarity index 54% rename from src/components/card/__snapshots__/card_select.test.tsx.snap rename to src/components/card/card_select/__snapshots__/card_select.test.tsx.snap index e09a992e541..c1f822cb43a 100644 --- a/src/components/card/__snapshots__/card_select.test.tsx.snap +++ b/src/components/card/card_select/__snapshots__/card_select.test.tsx.snap @@ -4,16 +4,16 @@ exports[`EuiCardSelect is rendered 1`] = ` + +`; + exports[`EuiToolTip display prop renders block 1`] = `
{ await waitForEuiToolTipVisible(); }); + test('anchor props are rendered', () => { + const component = mount( + + + + ); + + expect(component.render()).toMatchSnapshot(); + }); + // This is a legacy unit test to ensure tooltips/portal updates still play well with Enzyme it('[enzyme] shows tooltip on focus', () => { jest.useFakeTimers(); diff --git a/src/components/tool_tip/tool_tip.tsx b/src/components/tool_tip/tool_tip.tsx index d396d56e653..16d250b2809 100644 --- a/src/components/tool_tip/tool_tip.tsx +++ b/src/components/tool_tip/tool_tip.tsx @@ -13,10 +13,11 @@ import React, { ReactElement, ReactNode, MouseEvent as ReactMouseEvent, + HTMLAttributes, } from 'react'; import classNames from 'classnames'; -import { keysOf } from '../common'; +import { CommonProps, keysOf } from '../common'; import { EuiPortal } from '../portal'; import { EuiToolTipPopover } from './tool_tip_popover'; import { enqueueStateChange } from '../../services/react'; @@ -70,9 +71,13 @@ const DEFAULT_TOOLTIP_STYLES: ToolTipStyles = { export interface EuiToolTipProps { /** - * Passes onto the the trigger. + * Passes onto the span wrapping the trigger. */ anchorClassName?: string; + /** + * Passes onto the span wrapping the trigger. + */ + anchorProps?: CommonProps & HTMLAttributes; /** * The in-view trigger for your tooltip. */ @@ -290,6 +295,7 @@ export class EuiToolTip extends Component { children, className, anchorClassName, + anchorProps, content, title, delay, @@ -308,7 +314,8 @@ export class EuiToolTip extends Component { const anchorClasses = classNames( 'euiToolTipAnchor', display ? displayToClassNameMap[display] : null, - anchorClassName + anchorClassName, + anchorProps?.className ); let tooltip; @@ -338,6 +345,7 @@ export class EuiToolTip extends Component { // eslint-disable-next-line jsx-a11y/mouse-events-have-key-events (this.anchor = anchor)} + {...anchorProps} className={anchorClasses} onMouseOver={this.showToolTip} onMouseOut={this.onMouseOut} diff --git a/src/global_styling/mixins/_beta_badge.scss b/src/global_styling/mixins/_beta_badge.scss deleted file mode 100644 index 8900d3c5900..00000000000 --- a/src/global_styling/mixins/_beta_badge.scss +++ /dev/null @@ -1,30 +0,0 @@ - -// 1. Extend beta badges to at least 30% of the container's width -// 2. Fix for IE to ensure badges are visible outside of a