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 EuiPage and related components to TS #2669

Merged
merged 11 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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 @@

- Improved a11y of `EuiNavDrawer` lock button state via `aria-pressed` ([#2643](https://github.com/elastic/eui/pull/2643))
- Added exports for available types related to `EuiDataGrid` ([#2640](https://github.com/elastic/eui/pull/2640))
- Converted `EuiPage` and related child components to TypeScript ([#2669](https://github.com/elastic/eui/pull/2669))

**Bug fixes**

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 @@ -5,7 +5,6 @@
/// <reference path="./filter_group/index.d.ts" />
/// <reference path="./form/index.d.ts" />
/// <reference path="./modal/index.d.ts" />
/// <reference path="./page/index.d.ts" />
/// <reference path="./tabs/index.d.ts" />

declare module '@elastic/eui' {
Expand Down
91 changes: 0 additions & 91 deletions src/components/page/index.d.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
46 changes: 18 additions & 28 deletions src/components/page/page.js → src/components/page/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { FunctionComponent } from 'react';
import classNames from 'classnames';
import { CommonProps } from '../common';

export const EuiPage = ({
export interface EuiPageProps extends CommonProps {
restrictWidth?: boolean | number | string;
style?: React.CSSProperties;
}

export const EuiPage: FunctionComponent<EuiPageProps> = ({
children,
className,
restrictWidth,
/**
* Sets the max-width of the page,
* set to `true` to use the default size,
* set to `false` to not restrict the width,
* set to a number for a custom width in px,
* set to a string for a custom width in custom measurement.
*/
restrictWidth = false,
style,
className,
...rest
}) => {
let widthClassname;
Expand All @@ -17,7 +29,7 @@ export const EuiPage = ({
} else if (restrictWidth !== false) {
widthClassname = 'euiPage--restrictWidth-custom';
const value =
typeof maxWidth === 'number' ? `${restrictWidth}px` : restrictWidth;
typeof restrictWidth === 'number' ? `${restrictWidth}px` : restrictWidth;
newStyle = { ...style, maxWidth: value };
}

Expand All @@ -29,25 +41,3 @@ export const EuiPage = ({
</div>
);
};

EuiPage.propTypes = {
children: PropTypes.node,
className: PropTypes.string,

/**
* Sets the max-width of the page,
* set to `true` to use the default size,
* set to `false` to not restrict the width,
* set to a number for a custom width in px,
* set to a string for a custom width in custom measurement.
*/
restrictWidth: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.number,
PropTypes.string,
]),
};

EuiPage.defaultProps = {
restrictWidth: false,
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { FunctionComponent } from 'react';
import classNames from 'classnames';
import { CommonProps } from '../../common';

export const EuiPageBody = ({
export interface EuiPageBodyProps extends CommonProps {
/**
* Sets the max-width of the page,
* set to `true` to use the default size,
* set to `false` to not restrict the width,
* set to a number for a custom width in px,
* set to a string for a custom width in custom measurement.
*/
restrictWidth?: boolean | number | string;
style?: React.CSSProperties;
/**
* Sets the HTML element for `EuiPageBody`.
*/
component?: keyof JSX.IntrinsicElements;
}

export const EuiPageBody: FunctionComponent<EuiPageBodyProps> = ({
children,
restrictWidth,
restrictWidth = false,
style,
className,
component,
component: Component = 'main',
...rest
}) => {
let widthClassname;
Expand All @@ -18,43 +34,15 @@ export const EuiPageBody = ({
} else if (restrictWidth !== false) {
widthClassname = 'euiPageBody--restrictWidth-custom';
const value =
typeof maxWidth === 'number' ? `${restrictWidth}px` : restrictWidth;
typeof restrictWidth === 'number' ? `${restrictWidth}px` : restrictWidth;
newStyle = { ...style, maxWidth: value };
}

const classes = classNames('euiPageBody', widthClassname, className);

const OuterElement = component;

return (
<OuterElement className={classes} style={newStyle || style} {...rest}>
<Component className={classes} style={newStyle || style} {...rest}>
{children}
</OuterElement>
</Component>
);
};

EuiPageBody.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
/**
* Sets the HTML element for `EuiPageBody`.
*/
component: PropTypes.string,
/**
* Sets the max-width of the page,
* set to `true` to use the default size,
* set to `false` to not restrict the width,
* set to a number for a custom width in px,
* set to a string for a custom width in custom measurement.
*/
restrictWidth: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.number,
PropTypes.string,
]),
};

EuiPageBody.defaultProps = {
restrictWidth: false,
component: 'main',
};
52 changes: 0 additions & 52 deletions src/components/page/page_content/page_content.js

This file was deleted.

50 changes: 50 additions & 0 deletions src/components/page/page_content/page_content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { FunctionComponent } from 'react';
import classNames from 'classnames';
import { CommonProps } from '../../common';

import { EuiPanel, PanelPaddingSize } from '../../panel/panel';

export type EuiPageContentVerticalPositions = 'center';
export type EuiPageContentHorizontalPositions = 'center';

const verticalPositionToClassNameMap: {
[position in EuiPageContentVerticalPositions]: string | null
} = {
center: 'euiPageContent--verticalCenter',
};

const horizontalPositionToClassNameMap: {
[position in EuiPageContentHorizontalPositions]: string | null
} = {
center: 'euiPageContent--horizontalCenter',
};

export interface EuiPageContentProps extends CommonProps {
panelPaddingSize?: PanelPaddingSize;
verticalPosition?: EuiPageContentVerticalPositions;
horizontalPosition?: EuiPageContentHorizontalPositions;
}

export const EuiPageContent: FunctionComponent<EuiPageContentProps> = ({
verticalPosition,
horizontalPosition,
panelPaddingSize = 'l',
children,
className,
...rest
}) => {
const classes = classNames(
'euiPageContent',
verticalPosition ? verticalPositionToClassNameMap[verticalPosition] : null,
horizontalPosition
? horizontalPositionToClassNameMap[horizontalPosition]
: null,
className
);

return (
<EuiPanel className={classes} paddingSize={panelPaddingSize} {...rest}>
{children}
</EuiPanel>
);
};
18 changes: 0 additions & 18 deletions src/components/page/page_content/page_content_body.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/components/page/page_content/page_content_body.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { FunctionComponent } from 'react';
import classNames from 'classnames';
import { CommonProps } from '../../common';

export const EuiPageContentBody: FunctionComponent<CommonProps> = ({
children,
className,
...rest
}) => {
const classes = classNames('euiPageContentBody', className);

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