Skip to content

Commit

Permalink
Export missing type definitions (#2434)
Browse files Browse the repository at this point in the history
* export missing type definitions

* more button type exports

* clean up

* CL

* Fix eui.d.ts generation to correctly map imports to @elastic/eui module instead of index.ts
  • Loading branch information
thompsongl authored Oct 15, 2019
1 parent fccc6ae commit 307e640
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 15 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `14.5.0`.
**Bug fixes**

- Fixed missing misc. button and link type definition exports ([#2434](https://github.com/elastic/eui/pull/2434))

## [`14.5.0`](https://github.com/elastic/eui/tree/v14.5.0)

Expand Down
18 changes: 17 additions & 1 deletion scripts/dtsgenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,23 @@ generator.then(() => {
// replace relative imports by attaching them to the module's namespace
/import\("([.]{1,2}\/.*?)"\)/g,
(importStatement, importPath) => {
const target = path.join(path.dirname(moduleName), importPath);
let target = path.join(path.dirname(moduleName), importPath);

// if the target resolves to an orphaned index.ts file, remap to '@elastic/eui'
const filePath = target.replace('@elastic/eui', baseDir);
const filePathTs = `${filePath}.ts`;
const filePathTsx = `${filePath}.tsx`;
const filePathResolvedToIndex = path.join(filePath, 'index.ts');
if (
// fs.existsSync(filePath) === false && // target file doesn't exist
fs.existsSync(filePathTs) === false && // target file (.ts) doesn't exist
fs.existsSync(filePathTsx) === false && // target file (.tsx) doesn't exist
fs.existsSync(filePathResolvedToIndex) && // and it resolves to an index.ts
hasParentIndex(filePathResolvedToIndex) === false // does not get exported at a higher level
) {
target = '@elastic/eui';
}

return `import ("${target}")`;
}
);
Expand Down
9 changes: 6 additions & 3 deletions src/components/button/button_empty/button_empty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { EuiLoadingSpinner } from '../../loading';
import { getSecureRelForTarget } from '../../../services';
import { IconType, EuiIcon } from '../../icon';
import { ButtonIconSide } from '../button';

export type EuiButtonEmptyColor =
| 'primary'
Expand All @@ -37,7 +38,9 @@ const sizeToClassNameMap = {

export const SIZES = keysOf(sizeToClassNameMap);

const iconSideToClassNameMap = {
export type EuiButtonEmptySizes = keyof typeof sizeToClassNameMap;

const iconSideToClassNameMap: { [side in ButtonIconSide]: string } = {
left: '',
right: 'euiButtonEmpty--iconRight',
};
Expand All @@ -53,9 +56,9 @@ export const FLUSH_TYPES = keysOf(flushTypeToClassNameMap);

interface CommonEuiButtonEmptyProps extends CommonProps {
iconType?: IconType;
iconSide?: keyof typeof iconSideToClassNameMap;
iconSide?: ButtonIconSide;
color?: EuiButtonEmptyColor;
size?: keyof typeof sizeToClassNameMap;
size?: EuiButtonEmptySizes;
flush?: keyof typeof flushTypeToClassNameMap;
isDisabled?: boolean;
href?: string;
Expand Down
3 changes: 2 additions & 1 deletion src/components/button/button_empty/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export {
COLORS,
ICON_SIDES,
EuiButtonEmpty,
EuiButtonEmptyProps,
EuiButtonEmptyColor,
EuiButtonEmptyProps,
EuiButtonEmptySizes,
} from './button_empty';
4 changes: 2 additions & 2 deletions src/components/button/button_group/button_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ToggleType } from '../../toggle';
import { EuiButtonToggle } from '../button_toggle';
import { Omit, CommonProps } from '../../common';

import { ButtonColor } from '../button';
import { ButtonColor, ButtonIconSide } from '../button';
import { IconType } from '../../icon';

export interface EuiButtonGroupIdToSelectedMap {
Expand All @@ -22,7 +22,7 @@ export interface EuiButtonGroupOption extends CommonProps {
name?: string;
isDisabled?: boolean;
value?: any;
iconSide?: 'left' | 'right';
iconSide?: ButtonIconSide;
iconType?: IconType;
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/button/button_icon/button_icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { IconType, IconSize, EuiIcon } from '../../icon';

import { ButtonSize } from '../button';

export type ButtonIconColor =
export type EuiButtonIconColor =
| 'danger'
| 'disabled'
| 'ghost'
Expand All @@ -31,7 +31,7 @@ export type ButtonIconColor =

export interface EuiButtonIconProps extends CommonProps {
iconType?: IconType;
color?: ButtonIconColor;
color?: EuiButtonIconColor;
'aria-label'?: string;
'aria-labelledby'?: string;
isDisabled?: boolean;
Expand All @@ -58,7 +58,7 @@ type Props = ExclusiveUnion<
EuiButtonIconPropsForButton
>;

const colorToClassNameMap: { [color in ButtonIconColor]: string } = {
const colorToClassNameMap: { [color in EuiButtonIconColor]: string } = {
danger: 'euiButtonIcon--danger',
disabled: 'euiButtonIcon--disabled',
ghost: 'euiButtonIcon--ghost',
Expand Down
1 change: 1 addition & 0 deletions src/components/button/button_icon/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {
EuiButtonIcon,
EuiButtonIconColor,
EuiButtonIconProps,
EuiButtonIconPropsForButton,
} from './button_icon';
17 changes: 15 additions & 2 deletions src/components/button/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
export { COLORS, ButtonColor, EuiButton, EuiButtonProps } from './button';
export {
COLORS,
ButtonColor,
ButtonSize,
ButtonIconSide,
EuiButton,
EuiButtonProps,
} from './button';

export { EuiButtonEmpty, EuiButtonEmptyProps } from './button_empty';
export {
EuiButtonEmpty,
EuiButtonEmptyColor,
EuiButtonEmptyProps,
EuiButtonEmptySizes,
} from './button_empty';

export {
EuiButtonIcon,
EuiButtonIconColor,
EuiButtonIconProps,
EuiButtonIconPropsForButton,
} from './button_icon';
Expand Down
2 changes: 2 additions & 0 deletions src/components/link/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export {
EuiLink,
EuiLinkColor,
EuiLinkProps,
EuiLinkType,
EuiLinkAnchorProps,
EuiLinkButtonProps,
} from './link';
4 changes: 2 additions & 2 deletions src/components/link/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import classNames from 'classnames';
import { CommonProps, ExclusiveUnion, keysOf } from '../common';
import { getSecureRelForTarget } from '../../services';

type EuiLinkType = 'button' | 'reset' | 'submit';
type EuiLinkColor =
export type EuiLinkType = 'button' | 'reset' | 'submit';
export type EuiLinkColor =
| 'primary'
| 'subdued'
| 'secondary'
Expand Down

0 comments on commit 307e640

Please sign in to comment.