-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert EuiText, EuiTextColor and EuiTextAlign to TS (#1791)
Convert EuiText, EuiTextColor and EuiTextAlign to TypeScript.
- Loading branch information
1 parent
36eb514
commit 2b71d39
Showing
19 changed files
with
164 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
src/components/selectable/selectable_message/selectable_message.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
Oops, something went wrong.