diff --git a/components/divider/index.tsx b/components/divider/index.tsx index e45e8a9e60..aa52bdd74d 100644 --- a/components/divider/index.tsx +++ b/components/divider/index.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import classNames from 'classnames'; -import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; +import { ConfigContext } from '../config-provider'; export interface DividerProps { prefixCls?: string; @@ -14,56 +14,54 @@ export interface DividerProps { plain?: boolean; } -const Divider: React.FC = props => ( - - {({ getPrefixCls, direction }: ConfigConsumerProps) => { - const { - prefixCls: customizePrefixCls, - type = 'horizontal', - orientation = 'center', - orientationMargin, - className, - children, - dashed, - plain, - ...restProps - } = props; - const prefixCls = getPrefixCls('divider', customizePrefixCls); - const orientationPrefix = orientation.length > 0 ? `-${orientation}` : orientation; - const hasChildren = !!children; - const hasCustomMarginLeft = orientation === 'left' && orientationMargin != null; - const hasCustomMarginRight = orientation === 'right' && orientationMargin != null; - const classString = classNames( - prefixCls, - `${prefixCls}-${type}`, - { - [`${prefixCls}-with-text`]: hasChildren, - [`${prefixCls}-with-text${orientationPrefix}`]: hasChildren, - [`${prefixCls}-dashed`]: !!dashed, - [`${prefixCls}-plain`]: !!plain, - [`${prefixCls}-rtl`]: direction === 'rtl', - [`${prefixCls}-no-default-orientation-margin-left`]: hasCustomMarginLeft, - [`${prefixCls}-no-default-orientation-margin-right`]: hasCustomMarginRight, - }, - className, - ); +const Divider: React.FC = props => { + const { getPrefixCls, direction } = React.useContext(ConfigContext); - const innerStyle = { - ...(hasCustomMarginLeft && { marginLeft: orientationMargin }), - ...(hasCustomMarginRight && { marginRight: orientationMargin }), - }; + const { + prefixCls: customizePrefixCls, + type = 'horizontal', + orientation = 'center', + orientationMargin, + className, + children, + dashed, + plain, + ...restProps + } = props; + const prefixCls = getPrefixCls('divider', customizePrefixCls); + const orientationPrefix = orientation.length > 0 ? `-${orientation}` : orientation; + const hasChildren = !!children; + const hasCustomMarginLeft = orientation === 'left' && orientationMargin != null; + const hasCustomMarginRight = orientation === 'right' && orientationMargin != null; + const classString = classNames( + prefixCls, + `${prefixCls}-${type}`, + { + [`${prefixCls}-with-text`]: hasChildren, + [`${prefixCls}-with-text${orientationPrefix}`]: hasChildren, + [`${prefixCls}-dashed`]: !!dashed, + [`${prefixCls}-plain`]: !!plain, + [`${prefixCls}-rtl`]: direction === 'rtl', + [`${prefixCls}-no-default-orientation-margin-left`]: hasCustomMarginLeft, + [`${prefixCls}-no-default-orientation-margin-right`]: hasCustomMarginRight, + }, + className, + ); - return ( -
- {children && ( - - {children} - - )} -
- ); - }} -
-); + const innerStyle = { + ...(hasCustomMarginLeft && { marginLeft: orientationMargin }), + ...(hasCustomMarginRight && { marginRight: orientationMargin }), + }; + + return ( +
+ {children && ( + + {children} + + )} +
+ ); +}; export default Divider;