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

Convert EuiText, EuiTextColor and EuiTextAlign to TS #1791

Merged
merged 6 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Converted `EuiTitle` to TS ([#1810](https://github.com/elastic/eui/pull/1810))
- Added `adjustDateOnChange` prop to date pickers, enabling month and year changes to trigger `onChange` ([#1817](https://github.com/elastic/eui/pull/1817))
- Convert `EuiText`, `EuiTextColor` and `EuiTextAlign` to TS ([#1791](https://github.com/elastic/eui/pull/1791))

## [`9.9.1`](https://github.com/elastic/eui/tree/v9.9.1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ exports[`EuiDescribedFormGroup is rendered 1`] = `
<EuiText
className="euiDescribedFormGroup__description"
color="subdued"
grow={true}
id="generated-id"
size="s"
>
Expand Down Expand Up @@ -111,7 +110,6 @@ exports[`EuiDescribedFormGroup props fullWidth is rendered 1`] = `
<EuiText
className="euiDescribedFormGroup__description"
color="subdued"
grow={true}
id="generated-id"
size="s"
>
Expand Down Expand Up @@ -159,7 +157,6 @@ exports[`EuiDescribedFormGroup props gutterSize is rendered 1`] = `
<EuiText
className="euiDescribedFormGroup__description"
color="subdued"
grow={true}
id="generated-id"
size="s"
>
Expand Down Expand Up @@ -207,7 +204,6 @@ exports[`EuiDescribedFormGroup props titleSize is rendered 1`] = `
<EuiText
className="euiDescribedFormGroup__description"
color="subdued"
grow={true}
id="generated-id"
size="s"
>
Expand Down Expand Up @@ -279,7 +275,6 @@ exports[`EuiDescribedFormGroup ties together parts for accessibility 1`] = `
<EuiText
className="euiDescribedFormGroup__description"
color="subdued"
grow={true}
id="test-id"
size="s"
>
Expand Down
1 change: 0 additions & 1 deletion src/components/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
/// <reference path="./steps/index.d.ts" />
/// <reference path="./table/index.d.ts" />
/// <reference path="./tabs/index.d.ts" />
/// <reference path="./text/index.d.ts" />
/// <reference path="./toast/index.d.ts" />
/// <reference path="./tool_tip/index.d.ts" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { HTMLAttributes } from 'react';
import { CommonProps } from '../../common';
import { CommonProps, Omit } from '../../common';
import classNames from 'classnames';
// @ts-ignore
import { EuiText } from '../../text';

export type EuiSelectableMessageProps = HTMLAttributes<HTMLDivElement> &
export type EuiSelectableMessageProps = Omit<
HTMLAttributes<HTMLDivElement>,
'color'
> &
CommonProps & {};

export const EuiSelectableMessage: React.FunctionComponent<
Expand Down
52 changes: 0 additions & 52 deletions src/components/text/index.d.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/components/text/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions src/components/text/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { EuiText, TextSize, TEXT_SIZES } from './text';
Copy link
Contributor

Choose a reason for hiding this comment

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

This file should only export the components (match the same export signature as the removed index.js and index.d.ts, both of which only export the components). The other values shouldn't be used/usable outside of EUI, and internally other components an require them directly from their source files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chandlerprall I've changed the index to only export the components.


export { EuiTextColor, TextColor, COLORS } from './text_color';

export { EuiTextAlign, TextAlignment, ALIGNMENTS } from './text_align';
69 changes: 0 additions & 69 deletions src/components/text/text.js

This file was deleted.

File renamed without changes.
67 changes: 67 additions & 0 deletions src/components/text/text.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';
import { CommonProps, keysOf, Omit } from '../common';

import { TextColor, EuiTextColor } from './text_color';

import { EuiTextAlign, TextAlignment } from './text_align';

const textSizeToClassNameMap = {
xs: 'euiText--extraSmall',
s: 'euiText--small',
m: 'euiText--medium',
};

export type TextSize = keyof typeof textSizeToClassNameMap;

export const TEXT_SIZES = keysOf(textSizeToClassNameMap);

type Props = CommonProps &
Omit<HTMLAttributes<HTMLDivElement>, 'color'> & {
textAlign?: TextAlignment;
size?: TextSize;
color?: TextColor;
grow?: boolean;
};

export const EuiText: FunctionComponent<Props> = ({
size = 'm',
color,
grow = true,
textAlign,
children,
className,
...rest
}) => {
const classes = classNames(
'euiText',
textSizeToClassNameMap[size],
className,
{
'euiText--constrainedWidth': !grow,
}
);

let optionallyAlteredText;
if (color) {
optionallyAlteredText = (
<EuiTextColor color={color} component="div">
{children}
</EuiTextColor>
);
}

if (textAlign) {
optionallyAlteredText = (
<EuiTextAlign textAlign={textAlign}>
{optionallyAlteredText || children}
</EuiTextAlign>
);
}

return (
<div className={classes} {...rest}>
{optionallyAlteredText || children}
</div>
);
};
43 changes: 0 additions & 43 deletions src/components/text/text_align.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import { EuiTextAlign } from './text_align';

describe('EuiTextAlign', () => {
test('is rendered', () => {
const component = render(
<EuiTextAlign {...requiredProps} />
);
const component = render(<EuiTextAlign {...requiredProps} />);

expect(component)
.toMatchSnapshot();
expect(component).toMatchSnapshot();
});
});
37 changes: 37 additions & 0 deletions src/components/text/text_align.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';
import { CommonProps, keysOf } from '../common';

export const alignmentToClassNameMap = {
left: 'euiTextAlign--left',
right: 'euiTextAlign--right',
center: 'euiTextAlign--center',
};

export type TextAlignment = keyof typeof alignmentToClassNameMap;

export const ALIGNMENTS = keysOf(alignmentToClassNameMap);

type Props = CommonProps &
HTMLAttributes<HTMLDivElement> & {
textAlign?: TextAlignment;
};

export const EuiTextAlign: FunctionComponent<Props> = ({
children,
className,
textAlign = 'left',
...rest
}) => {
const classes = classNames(
'euiTextAlign',
alignmentToClassNameMap[textAlign],
className
);

return (
<div className={classes} {...rest}>
{children}
</div>
);
};
Loading