From 47a6e3597d35f72c51b741d022a11579ca0760c4 Mon Sep 17 00:00:00 2001 From: Dave Snider Date: Wed, 28 Nov 2018 13:05:22 -0800 Subject: [PATCH 1/4] horizontal rule conversion to ts --- ...horizontal_rule.js => horizontal_rule.tsx} | 2 +- ...e_margin.js => horizontal_rule_margin.tsx} | 2 +- ....js.snap => horizontal_rule.test.tsx.snap} | 0 ..._rule.test.js => horizontal_rule.test.tsx} | 0 ...horizontal_rule.js => horizontal_rule.tsx} | 36 +++++++++++-------- src/components/horizontal_rule/index.d.ts | 26 -------------- .../horizontal_rule/{index.js => index.ts} | 0 src/components/index.d.ts | 1 - 8 files changed, 24 insertions(+), 43 deletions(-) rename src-docs/src/views/horizontal_rule/{horizontal_rule.js => horizontal_rule.tsx} (79%) rename src-docs/src/views/horizontal_rule/{horizontal_rule_margin.js => horizontal_rule_margin.tsx} (88%) rename src/components/horizontal_rule/__snapshots__/{horizontal_rule.test.js.snap => horizontal_rule.test.tsx.snap} (100%) rename src/components/horizontal_rule/{horizontal_rule.test.js => horizontal_rule.test.tsx} (100%) rename src/components/horizontal_rule/{horizontal_rule.js => horizontal_rule.tsx} (56%) delete mode 100644 src/components/horizontal_rule/index.d.ts rename src/components/horizontal_rule/{index.js => index.ts} (100%) diff --git a/src-docs/src/views/horizontal_rule/horizontal_rule.js b/src-docs/src/views/horizontal_rule/horizontal_rule.tsx similarity index 79% rename from src-docs/src/views/horizontal_rule/horizontal_rule.js rename to src-docs/src/views/horizontal_rule/horizontal_rule.tsx index da02122e22c..7abca3742ac 100644 --- a/src-docs/src/views/horizontal_rule/horizontal_rule.js +++ b/src-docs/src/views/horizontal_rule/horizontal_rule.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { EuiHorizontalRule, -} from '../../../../src/components'; +} from '../../../../src/components/horizontal_rule'; export default () => (
diff --git a/src-docs/src/views/horizontal_rule/horizontal_rule_margin.js b/src-docs/src/views/horizontal_rule/horizontal_rule_margin.tsx similarity index 88% rename from src-docs/src/views/horizontal_rule/horizontal_rule_margin.js rename to src-docs/src/views/horizontal_rule/horizontal_rule_margin.tsx index bf0c750fbe1..0e2c10fe0cf 100644 --- a/src-docs/src/views/horizontal_rule/horizontal_rule_margin.js +++ b/src-docs/src/views/horizontal_rule/horizontal_rule_margin.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { EuiHorizontalRule, -} from '../../../../src/components'; +} from '../../../../src/components/horizontal_rule'; export default () => (
diff --git a/src/components/horizontal_rule/__snapshots__/horizontal_rule.test.js.snap b/src/components/horizontal_rule/__snapshots__/horizontal_rule.test.tsx.snap similarity index 100% rename from src/components/horizontal_rule/__snapshots__/horizontal_rule.test.js.snap rename to src/components/horizontal_rule/__snapshots__/horizontal_rule.test.tsx.snap diff --git a/src/components/horizontal_rule/horizontal_rule.test.js b/src/components/horizontal_rule/horizontal_rule.test.tsx similarity index 100% rename from src/components/horizontal_rule/horizontal_rule.test.js rename to src/components/horizontal_rule/horizontal_rule.test.tsx diff --git a/src/components/horizontal_rule/horizontal_rule.js b/src/components/horizontal_rule/horizontal_rule.tsx similarity index 56% rename from src/components/horizontal_rule/horizontal_rule.js rename to src/components/horizontal_rule/horizontal_rule.tsx index 9ce7cc6a128..1dadfc7a209 100644 --- a/src/components/horizontal_rule/horizontal_rule.js +++ b/src/components/horizontal_rule/horizontal_rule.tsx @@ -1,7 +1,20 @@ -import React from 'react'; -import PropTypes from 'prop-types'; +import React, { SFC, HTMLAttributes } from 'react'; import classNames from 'classnames'; +import { CommonProps } from '../common'; + +export type EuiHorizontalRuleSize = 'full' | 'half' | 'quarter'; + +export type EuiHorizontalRuleMargin = 'none' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'; + +export interface EuiHorizontalRuleProps { + /** + * Defines the width of the HR. + */ + size?: EuiHorizontalRuleSize; + margin?: EuiHorizontalRuleMargin; +} + const sizeToClassNameMap = { full: 'euiHorizontalRule--full', half: 'euiHorizontalRule--half', @@ -22,16 +35,18 @@ const marginToClassNameMap = { export const MARGINS = Object.keys(marginToClassNameMap); -export const EuiHorizontalRule = ({ +export const EuiHorizontalRule: SFC< +CommonProps & HTMLAttributes & EuiHorizontalRuleProps +> = ({ className, - size, - margin, + size = 'full', + margin = 'l', ...rest }) => { const classes = classNames( 'euiHorizontalRule', - sizeToClassNameMap[size], - marginToClassNameMap[margin], + size ? sizeToClassNameMap[size] : undefined, + margin ? marginToClassNameMap[margin] : undefined, className ); @@ -43,13 +58,6 @@ export const EuiHorizontalRule = ({ ); }; -EuiHorizontalRule.propTypes = { - children: PropTypes.node, - className: PropTypes.string, - size: PropTypes.oneOf(SIZES), - margin: PropTypes.oneOf(MARGINS), -}; - EuiHorizontalRule.defaultProps = { size: 'full', margin: 'l', diff --git a/src/components/horizontal_rule/index.d.ts b/src/components/horizontal_rule/index.d.ts deleted file mode 100644 index 0fd64f890dd..00000000000 --- a/src/components/horizontal_rule/index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { CommonProps } from '../common'; - -import { SFC, HTMLAttributes } from 'react'; - -declare module '@elastic/eui' { - - /** - * EuiHorizontalRule type defs - * - * @see './horizontal_rule.js' - */ - - export type EuiHorizontalRuleSize = 'full' | 'half' | 'quarter'; - - export type EuiHorizontalRuleMargin = 'none' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'; - - export interface EuiHorizontalRuleProps { - size?: EuiHorizontalRuleSize; - margin?: EuiHorizontalRuleMargin; - } - - export const EuiHorizontalRule: SFC< - CommonProps & HTMLAttributes & EuiHorizontalRuleProps - >; - -} diff --git a/src/components/horizontal_rule/index.js b/src/components/horizontal_rule/index.ts similarity index 100% rename from src/components/horizontal_rule/index.js rename to src/components/horizontal_rule/index.ts diff --git a/src/components/index.d.ts b/src/components/index.d.ts index cd4307f58f2..05fa53360e0 100644 --- a/src/components/index.d.ts +++ b/src/components/index.d.ts @@ -14,7 +14,6 @@ /// /// /// -/// /// /// /// From d14c25deae2de3cde7df7fd789eac04dc8ada435 Mon Sep 17 00:00:00 2001 From: Chandler Prall Date: Wed, 28 Nov 2018 13:17:06 -0800 Subject: [PATCH 2/4] Update src/components/horizontal_rule/horizontal_rule.tsx Co-Authored-By: snide --- src/components/horizontal_rule/horizontal_rule.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/horizontal_rule/horizontal_rule.tsx b/src/components/horizontal_rule/horizontal_rule.tsx index 1dadfc7a209..ce20d13d279 100644 --- a/src/components/horizontal_rule/horizontal_rule.tsx +++ b/src/components/horizontal_rule/horizontal_rule.tsx @@ -3,7 +3,7 @@ import classNames from 'classnames'; import { CommonProps } from '../common'; -export type EuiHorizontalRuleSize = 'full' | 'half' | 'quarter'; +export type EuiHorizontalRuleSize = keyof typeof sizeToClassNameMap; export type EuiHorizontalRuleMargin = 'none' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'; From 6b105f449378bcec546450c24e8c6e7ddb5b2d21 Mon Sep 17 00:00:00 2001 From: Dave Snider Date: Wed, 28 Nov 2018 13:17:43 -0800 Subject: [PATCH 3/4] feedback --- src/components/horizontal_rule/horizontal_rule.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/horizontal_rule/horizontal_rule.tsx b/src/components/horizontal_rule/horizontal_rule.tsx index ce20d13d279..bb89632dc17 100644 --- a/src/components/horizontal_rule/horizontal_rule.tsx +++ b/src/components/horizontal_rule/horizontal_rule.tsx @@ -39,8 +39,8 @@ export const EuiHorizontalRule: SFC< CommonProps & HTMLAttributes & EuiHorizontalRuleProps > = ({ className, - size = 'full', - margin = 'l', + size, + margin, ...rest }) => { const classes = classNames( From 28334c898a17e7485a03067b0458170d18359aa5 Mon Sep 17 00:00:00 2001 From: Dave Snider Date: Wed, 28 Nov 2018 13:35:05 -0800 Subject: [PATCH 4/4] feedback --- src/components/horizontal_rule/horizontal_rule.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/horizontal_rule/horizontal_rule.tsx b/src/components/horizontal_rule/horizontal_rule.tsx index bb89632dc17..c30291ae2ce 100644 --- a/src/components/horizontal_rule/horizontal_rule.tsx +++ b/src/components/horizontal_rule/horizontal_rule.tsx @@ -4,8 +4,7 @@ import classNames from 'classnames'; import { CommonProps } from '../common'; export type EuiHorizontalRuleSize = keyof typeof sizeToClassNameMap; - -export type EuiHorizontalRuleMargin = 'none' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'; +export type EuiHorizontalRuleMargin = keyof typeof marginToClassNameMap; export interface EuiHorizontalRuleProps { /**