diff --git a/CHANGELOG.md b/CHANGELOG.md index 27eea67907e..711f96e5d44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## [`master`](https://github.com/elastic/eui/tree/master) -No public interface changes since `9.9.1`. +- Converted `EuiTitle` to TS ([#1810](https://github.com/elastic/eui/pull/1810)) ## [`9.9.1`](https://github.com/elastic/eui/tree/v9.9.1) diff --git a/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select.test.js.snap b/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select.test.js.snap index c4465c2eb6a..2670ccd60ad 100644 --- a/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select.test.js.snap +++ b/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select.test.js.snap @@ -10,7 +10,6 @@ exports[`EuiQuickSelect is rendered 1`] = ` Quick select @@ -201,7 +200,6 @@ exports[`EuiQuickSelect prevQuickSelect 1`] = ` Quick select diff --git a/src/components/empty_prompt/index.d.ts b/src/components/empty_prompt/index.d.ts index 6867001cdc0..7c9ff3f32c0 100644 --- a/src/components/empty_prompt/index.d.ts +++ b/src/components/empty_prompt/index.d.ts @@ -1,6 +1,6 @@ import { CommonProps, Omit } from '../common'; -import { IconColor, IconType } from '../icon' -/// +import { IconColor, IconType } from '../icon'; +import { EuiTitleSize } from '../title/title'; import { FunctionComponent, ReactNode, HTMLAttributes } from 'react'; diff --git a/src/components/form/described_form_group/__snapshots__/described_form_group.test.js.snap b/src/components/form/described_form_group/__snapshots__/described_form_group.test.js.snap index 72170c1f845..19e1154ee61 100644 --- a/src/components/form/described_form_group/__snapshots__/described_form_group.test.js.snap +++ b/src/components/form/described_form_group/__snapshots__/described_form_group.test.js.snap @@ -17,7 +17,6 @@ exports[`EuiDescribedFormGroup is rendered 1`] = ` className="euiDescribedFormGroup__title" id="generated-id-title" size="xs" - textTransform="none" >

Title @@ -65,7 +64,6 @@ exports[`EuiDescribedFormGroup props description is not rendered when it's not p className="euiDescribedFormGroup__title" id="generated-id-title" size="xs" - textTransform="none" >

Title @@ -105,7 +103,6 @@ exports[`EuiDescribedFormGroup props fullWidth is rendered 1`] = ` className="euiDescribedFormGroup__title" id="generated-id-title" size="xs" - textTransform="none" >

Title @@ -154,7 +151,6 @@ exports[`EuiDescribedFormGroup props gutterSize is rendered 1`] = ` className="euiDescribedFormGroup__title" id="generated-id-title" size="xs" - textTransform="none" >

Title @@ -203,7 +199,6 @@ exports[`EuiDescribedFormGroup props titleSize is rendered 1`] = ` className="euiDescribedFormGroup__title" id="generated-id-title" size="l" - textTransform="none" >

Title @@ -273,7 +268,6 @@ exports[`EuiDescribedFormGroup ties together parts for accessibility 1`] = ` className="euiDescribedFormGroup__title" id="test-id-title" size="xs" - textTransform="none" >

/// /// -/// /// /// diff --git a/src/components/title/__snapshots__/title.test.js.snap b/src/components/title/__snapshots__/title.test.tsx.snap similarity index 100% rename from src/components/title/__snapshots__/title.test.js.snap rename to src/components/title/__snapshots__/title.test.tsx.snap diff --git a/src/components/title/index.d.ts b/src/components/title/index.d.ts deleted file mode 100644 index 4a3ab221539..00000000000 --- a/src/components/title/index.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { CommonProps } from '../common'; -import { FunctionComponent } from 'react'; - -declare module '@elastic/eui' { - /** - * title type defs - * - * @see './title.js' - */ - - type EuiTitleSize = 'xxxs' | 'xxs' | 'xs' | 's' | 'm' | 'l'; - - type EuiTitleTextTransform = 'uppercase'; - - type EuiTitleProps = CommonProps & { - size?: EuiTitleSize; - textTransform?: EuiTitleTextTransform; - }; - - export const EuiTitle: FunctionComponent; -} diff --git a/src/components/title/index.js b/src/components/title/index.js deleted file mode 100644 index 7768a4e64c5..00000000000 --- a/src/components/title/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { - EuiTitle, -} from './title'; diff --git a/src/components/title/index.ts b/src/components/title/index.ts new file mode 100644 index 00000000000..a61eccd23ee --- /dev/null +++ b/src/components/title/index.ts @@ -0,0 +1 @@ +export { EuiTitle } from './title'; diff --git a/src/components/title/title.js b/src/components/title/title.js deleted file mode 100644 index e0d9c1a424f..00000000000 --- a/src/components/title/title.js +++ /dev/null @@ -1,50 +0,0 @@ -import React from 'react'; -import classNames from 'classnames'; -import PropTypes from 'prop-types'; - -const titleSizeToClassNameMap = { - xxxs: 'euiTitle--xxxsmall', - xxs: 'euiTitle--xxsmall', - xs: 'euiTitle--xsmall', - s: 'euiTitle--small', - m: 'euiTitle--medium', - l: 'euiTitle--large', -}; - -export const TITLE_SIZES = Object.keys(titleSizeToClassNameMap); - -const textTransformToClassNameMap = { - none: '', - uppercase: 'euiTitle--uppercase', -}; - -export const TEXT_TRANSFORM = Object.keys(textTransformToClassNameMap); - -export const EuiTitle = ({ size, children, className, textTransform, ...rest }) => { - - const classes = classNames( - 'euiTitle', - titleSizeToClassNameMap[size], - textTransformToClassNameMap[textTransform], - className - ); - - const props = { - className: classes, - ...rest - }; - - return React.cloneElement(children, props); -}; - -EuiTitle.propTypes = { - children: PropTypes.element.isRequired, - className: PropTypes.string, - size: PropTypes.oneOf(TITLE_SIZES).isRequired, - textTransform: PropTypes.oneOf(TEXT_TRANSFORM), -}; - -EuiTitle.defaultProps = { - size: 'm', - textTransform: 'none', -}; diff --git a/src/components/title/title.test.js b/src/components/title/title.test.tsx similarity index 72% rename from src/components/title/title.test.js rename to src/components/title/title.test.tsx index 16b907516f2..48ea7b746ee 100644 --- a/src/components/title/title.test.js +++ b/src/components/title/title.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { render } from 'enzyme'; -import { requiredProps } from '../../test/required_props'; +import { requiredProps } from '../../test'; import { EuiTitle } from './title'; @@ -12,7 +12,6 @@ describe('EuiTitle', () => { ); - expect(component) - .toMatchSnapshot(); + expect(component).toMatchSnapshot(); }); }); diff --git a/src/components/title/title.tsx b/src/components/title/title.tsx new file mode 100644 index 00000000000..c4e05aecf4f --- /dev/null +++ b/src/components/title/title.tsx @@ -0,0 +1,51 @@ +import React, { FunctionComponent, ReactElement } from 'react'; +import classNames from 'classnames'; +import { CommonProps, keysOf } from '../common'; + +const titleSizeToClassNameMap = { + xxxs: 'euiTitle--xxxsmall', + xxs: 'euiTitle--xxsmall', + xs: 'euiTitle--xsmall', + s: 'euiTitle--small', + m: 'euiTitle--medium', + l: 'euiTitle--large', +}; + +export const TITLE_SIZES = keysOf(titleSizeToClassNameMap); +export type EuiTitleSize = keyof typeof titleSizeToClassNameMap; + +const textTransformToClassNameMap = { + uppercase: 'euiTitle--uppercase', +}; + +export const TEXT_TRANSFORM = keysOf(textTransformToClassNameMap); +export type EuiTitleTextTransform = keyof typeof textTransformToClassNameMap; + +export type EuiTitleProps = CommonProps & { + children: ReactElement; + className?: string; + size?: EuiTitleSize; + textTransform?: EuiTitleTextTransform; +}; + +export const EuiTitle: FunctionComponent = ({ + size = 'm', + children, + className, + textTransform, + ...rest +}) => { + const classes = classNames( + 'euiTitle', + titleSizeToClassNameMap[size], + textTransform ? textTransformToClassNameMap[textTransform] : undefined, + className + ); + + const props = { + className: classes, + ...rest, + }; + + return React.cloneElement(children, props); +};