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

Added iconProps to EuiIconTip #1420

Merged
merged 8 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
- Added `isAutoRefreshOnly` prop to `EuiSuperDatePicker` ([#1412](https://github.com/elastic/eui/pull/1412))
- Migrate remaining files in `accessiblity/` to TS ([#1408](https://github.com/elastic/eui/pull/1408))
- Added `titleProps` and `descriptionProps` to `EuiDescriptionList` ([#1419](https://github.com/elastic/eui/pull/1419))
- Added `iconProps` prop to `EuiIconTip` ([#1420](https://github.com/elastic/eui/pull/1420))

**Bug fixes**

- Support extended characters (e.g. non-latin, unicode) in `EuiSearchBar` and `EuiQuery` ([#1415](https://github.com/elastic/eui/pull/1415))
- Fixed line-heights of the differently sized `EuiDescriptionList` alternates ([#1419](https://github.com/elastic/eui/pull/1419))
- Updated `EuiIconTip` TS definitions to inherit those from `EuiToolTip` as well ([#1420](https://github.com/elastic/eui/pull/1420))

## [`6.2.0`](https://github.com/elastic/eui/tree/v6.2.0)

Expand Down
21 changes: 21 additions & 0 deletions src-docs/src/views/tool_tip/icon_tip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
EuiFlexItem,
EuiIconTip,
EuiSpacer,
EuiText,
EuiCode,
} from '../../../../src/components';

export default () => (
Expand Down Expand Up @@ -36,5 +38,24 @@ export default () => (
color="warning"
content="I do not think it means what you think it means"
/>

<EuiSpacer />

<EuiText>
<p>
Pass a position utility class via <EuiCode>iconProps</EuiCode> to shift for
better alignment.
<EuiIconTip
type="iInCircle"
color="subdued"
content={
<span>This was passed <EuiCode>.eui-alignTop</EuiCode></span>
}
iconProps={{
className: 'eui-alignTop',
}}
/>
</p>
</EuiText>
</Fragment>
);
8 changes: 8 additions & 0 deletions src/components/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Component, FunctionComponent, SFC } from 'react';

export interface CommonProps {
className?: string;
'aria-label'?: string;
Expand All @@ -18,6 +20,12 @@ export function keysOf<T, K extends keyof T>(obj: T): K[] {
return Object.keys(obj) as K[];
}

export type PropsOf<C> =
C extends SFC<infer SFCProps> ? SFCProps :
C extends FunctionComponent<infer FunctionalProps> ? FunctionalProps :
C extends Component<infer ComponentProps> ? ComponentProps
: never;

/*
TypeScript's discriminated unions are overly permissive: as long as one type of the union is satisfied
the other types are not validated against. For example:
Expand Down
9 changes: 7 additions & 2 deletions src/components/tool_tip/icon_tip.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import PropTypes from 'prop-types';
import { EuiIcon } from '../icon';
import { EuiToolTip } from './tool_tip';

export const EuiIconTip = ({ type, 'aria-label': ariaLabel, color, size, ...rest }) => (
export const EuiIconTip = ({ type, 'aria-label': ariaLabel, color, size, iconProps, ...rest }) => (
<EuiToolTip {...rest}>
<EuiIcon tabIndex="0" type={type} color={color} size={size} aria-label={ariaLabel} />
<EuiIcon tabIndex="0" type={type} color={color} size={size} aria-label={ariaLabel} {...iconProps} />
</EuiToolTip>
);

Expand All @@ -30,6 +30,11 @@ EuiIconTip.propTypes = {
* Explain what this icon means for screen readers.
*/
'aria-label': PropTypes.string,

/**
* Pass certain props down to `EuiIcon`
*/
iconProps: PropTypes.object,
};

EuiIconTip.defaultProps = {
Expand Down
8 changes: 5 additions & 3 deletions src/components/tool_tip/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ReactElement, ReactNode, SFC } from 'react';
import { EuiIcon } from '../icon';
import { Omit, PropsOf } from '../common';

declare module '@elastic/eui' {
export type ToolTipPositions =
Expand All @@ -14,7 +16,7 @@ declare module '@elastic/eui' {
export interface EuiToolTipProps {
children: ReactElement<any>;
className?: string;
content: ReactNode;
content?: ReactNode;
delay?: ToolTipDelay;
title?: ReactNode;
id?: string;
Expand All @@ -27,7 +29,7 @@ declare module '@elastic/eui' {
type?: string;
size?: string;
'aria-label'?: string;
content: ReactNode;
iconProps?: PropsOf<typeof EuiIcon>;
}
export const EuiIconTip: SFC<EuiIconTipProps>;
export const EuiIconTip: SFC<Omit<EuiToolTipProps, 'children'> & EuiIconTipProps>;
}