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 all 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 @@ -9,6 +9,7 @@ No public interface changes since `10.0.0`.
- Updated the overflow shadows for `EuiModal` and `EuiFlyout` ([#1829](https://github.com/elastic/eui/pull/1829))
- Added `confirmButtonDisabled` prop to `EuiConfirmModal` ([#1829](https://github.com/elastic/eui/pull/1829))
- Fixed `EuiNavDrawer` overflow scroll behavior on Firefox ([#1837](https://github.com/elastic/eui/pull/1837))
- Convert `EuiText`, `EuiTextColor` and `EuiTextAlign` to TS ([#1791](https://github.com/elastic/eui/pull/1791))

**Bug fixes**

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.

3 changes: 3 additions & 0 deletions src/components/text/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { EuiText } from './text';
export { EuiTextColor } from './text_color';
export { EuiTextAlign } 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