From baed0afab1dfc5c365f617cf3fc856aa5f61aea3 Mon Sep 17 00:00:00 2001 From: Oleksandr Fediashov Date: Fri, 29 Dec 2023 19:03:34 +0100 Subject: [PATCH] remove transform --- src/modules/Tab/Tab.js | 25 +++++++++-------------- src/modules/Tab/TabPane.js | 17 ++++----------- src/modules/Transition/TransitionGroup.js | 21 ++++++------------- src/views/Comment/CommentAction.js | 14 +++---------- 4 files changed, 23 insertions(+), 54 deletions(-) diff --git a/src/modules/Tab/Tab.js b/src/modules/Tab/Tab.js index d691024cfd..03ef505cea 100644 --- a/src/modules/Tab/Tab.js +++ b/src/modules/Tab/Tab.js @@ -4,7 +4,7 @@ import React from 'react' import { customPropTypes, - getElementType, + getComponentType, getUnhandledProps, useAutoControlledValue, } from '../../lib' @@ -18,9 +18,14 @@ import TabPane from './TabPane' * @see Menu * @see Segment */ -const Tab = React.forwardRef(function (partialProps, ref) { - const props = _.defaults(partialProps, getDefaultProps()) - const { grid, menu, panes, menuPosition, renderActiveOnly } = props +const Tab = React.forwardRef(function (props, ref) { + const { + grid = { paneWidth: 12, tabWidth: 4 }, + menu = { attached: true, tabular: true }, + menuPosition, + panes, + renderActiveOnly = true, + } = props const [activeIndex, setActiveIndex] = useAutoControlledValue({ state: props.activeIndex, @@ -87,7 +92,7 @@ const Tab = React.forwardRef(function (partialProps, ref) { const menuElement = renderMenu() const rest = getUnhandledProps(Tab, props) - const ElementType = getElementType(Tab, props) + const ElementType = getComponentType(props) if (menuElement.props.vertical) { return ( @@ -156,16 +161,6 @@ Tab.propTypes = { renderActiveOnly: PropTypes.bool, } -Tab.autoControlledProps = ['activeIndex'] - -function getDefaultProps() { - return { - grid: { paneWidth: 12, tabWidth: 4 }, - menu: { attached: true, tabular: true }, - renderActiveOnly: true, - } -} - Tab.Pane = TabPane export default Tab diff --git a/src/modules/Tab/TabPane.js b/src/modules/Tab/TabPane.js index 30a6b0f630..0e1bdbad45 100644 --- a/src/modules/Tab/TabPane.js +++ b/src/modules/Tab/TabPane.js @@ -1,4 +1,3 @@ -import _ from 'lodash' import cx from 'clsx' import PropTypes from 'prop-types' import React from 'react' @@ -7,7 +6,7 @@ import { childrenUtils, createShorthandFactory, customPropTypes, - getElementType, + getComponentType, getUnhandledProps, useKeyOnly, } from '../../lib' @@ -16,13 +15,12 @@ import Segment from '../../elements/Segment/Segment' /** * A tab pane holds the content of a tab. */ -const TabPane = React.forwardRef(function (partialProps, ref) { - const props = _.defaults(partialProps, getDefaultProps()) - const { active, children, className, content, loading } = props +const TabPane = React.forwardRef(function (props, ref) { + const { active = true, children, className, content, loading } = props const classes = cx(useKeyOnly(active, 'active'), useKeyOnly(loading, 'loading'), 'tab', className) const rest = getUnhandledProps(TabPane, props) - const ElementType = getElementType(TabPane, props) + const ElementType = getComponentType(props, { defaultAs: Segment }) const calculatedDefaultProps = {} @@ -37,13 +35,6 @@ const TabPane = React.forwardRef(function (partialProps, ref) { ) }) -function getDefaultProps() { - return { - as: Segment, - active: true, - } -} - TabPane.displayName = 'TabPane' TabPane.propTypes = { /** An element type to render as (string or function). */ diff --git a/src/modules/Transition/TransitionGroup.js b/src/modules/Transition/TransitionGroup.js index 0780331d87..4708820aba 100644 --- a/src/modules/Transition/TransitionGroup.js +++ b/src/modules/Transition/TransitionGroup.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types' import React from 'react' import { - getElementType, + getComponentType, getUnhandledProps, makeDebugger, SUI, @@ -19,7 +19,7 @@ const debug = makeDebugger('transition_group') * Wraps all children elements with proper callbacks and props. * * @param {React.ReactNode} children - * @param {Stream} animation + * @param {String} animation * @param {Number|String|Object} duration * @param {Boolean} directional * @@ -107,19 +107,18 @@ function useWrappedChildren(children, animation, duration, directional) { /** * A Transition.Group animates children as they mount and unmount. */ -const TransitionGroup = React.forwardRef(function (partialProps, ref) { - const props = _.defaults(partialProps, getDefaultProps()) +const TransitionGroup = React.forwardRef(function (props, ref) { debug('render') debug('props', props) const children = useWrappedChildren( props.children, - props.animation, - props.duration, + props.animation ?? 'fade', + props.duration ?? 500, props.directional, ) - const ElementType = getElementType(TransitionGroup, props) + const ElementType = getComponentType(props, { defaultAs: React.Fragment }) const rest = getUnhandledProps(TransitionGroup, props) return ( @@ -154,12 +153,4 @@ TransitionGroup.propTypes = { ]), } -function getDefaultProps() { - return { - as: React.Fragment, - animation: 'fade', - duration: 500, - } -} - export default TransitionGroup diff --git a/src/views/Comment/CommentAction.js b/src/views/Comment/CommentAction.js index ef5fd25426..82eae2cc95 100644 --- a/src/views/Comment/CommentAction.js +++ b/src/views/Comment/CommentAction.js @@ -1,4 +1,3 @@ -import _ from 'lodash' import cx from 'clsx' import PropTypes from 'prop-types' import React from 'react' @@ -6,7 +5,7 @@ import React from 'react' import { childrenUtils, customPropTypes, - getElementType, + getComponentType, getUnhandledProps, useKeyOnly, } from '../../lib' @@ -14,13 +13,12 @@ import { /** * A comment can contain an action. */ -const CommentAction = React.forwardRef(function (partialProps, ref) { - const props = _.defaults(partialProps, getDefaultProps()) +const CommentAction = React.forwardRef(function (props, ref) { const { active, className, children, content } = props const classes = cx(useKeyOnly(active, 'active'), className) const rest = getUnhandledProps(CommentAction, props) - const ElementType = getElementType(CommentAction, props) + const ElementType = getComponentType(props, { defaultAs: 'a' }) return ( @@ -29,12 +27,6 @@ const CommentAction = React.forwardRef(function (partialProps, ref) { ) }) -function getDefaultProps() { - return { - as: 'a', - } -} - CommentAction.displayName = 'CommentAction' CommentAction.propTypes = { /** An element type to render as (string or function). */