Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
perf: remove Box usages where it is redundant (#2023)
Browse files Browse the repository at this point in the history
* perf: remove Box usages where it is redundant

* add changelog
  • Loading branch information
layershifter authored Oct 11, 2019
1 parent 0ccdfa0 commit d4cc17b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Documentation
- Fix 'RTL' and 'Theme it' in examples @miroslavstastny ([#2020](https://github.com/stardust-ui/react/pull/2020))

### Performance
- Remove redundant usages of `Box` component in `Attachment`, `Popup` and `Tooltip` @layershifter ([#2023](https://github.com/stardust-ui/react/pull/2023))

<!--------------------------------[ v0.40.0 ]------------------------------- -->
## [v0.40.0](https://github.com/stardust-ui/react/tree/v0.40.0) (2019-10-09)
[Compare changes](https://github.com/stardust-ui/react/compare/v0.39.0...v0.40.0)
Expand Down
6 changes: 1 addition & 5 deletions packages/react/src/components/Attachment/Attachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import Icon, { IconProps } from '../Icon/Icon'
import Button, { ButtonProps } from '../Button/Button'
import Text, { TextProps } from '../Text/Text'
import Box from '../Box/Box'
import { UIComponentProps, ChildrenComponentProps } from '../../lib/commonPropInterfaces'

export interface AttachmentProps extends UIComponentProps, ChildrenComponentProps {
Expand Down Expand Up @@ -114,10 +113,7 @@ class Attachment extends UIComponent<WithAsProp<AttachmentProps>> {
className: Attachment.slotClassNames.action,
},
})}
{!_.isNil(progress) &&
Box.create('', {
defaultProps: { styles: styles.progress },
})}
{!_.isNil(progress) && <div className={classes.progress} />}
</ElementType>
)
}
Expand Down
24 changes: 6 additions & 18 deletions packages/react/src/components/Popup/PopupContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
AutoFocusZoneProps,
AutoFocusZone,
} from '@stardust-ui/react-bindings'
import { Ref } from '@stardust-ui/react-component-ref'
import cx from 'classnames'
import * as React from 'react'
import * as PropTypes from 'prop-types'
import * as _ from 'lodash'
Expand All @@ -25,7 +25,6 @@ import {
import { Accessibility } from '@stardust-ui/accessibility'
import { PopperChildrenProps } from '../../lib/positioner'
import { WithAsProp, ComponentEventHandler, withSafeTypeForAs } from '../../types'
import Box from '../Box/Box'

export interface PopupContentSlotClassNames {
content: string
Expand Down Expand Up @@ -59,7 +58,7 @@ export interface PopupContentProps
pointing?: boolean

/** A ref to a pointer element. */
pointerRef?: React.Ref<Element>
pointerRef?: React.Ref<HTMLDivElement>

/** Controls whether or not focus trap should be applied, using boolean or FocusTrapZoneProps type value. */
trapFocus?: boolean | FocusTrapZoneProps
Expand Down Expand Up @@ -114,21 +113,10 @@ class PopupContent extends UIComponent<WithAsProp<PopupContentProps>> {

const popupContent = (
<>
{pointing && (
<Ref innerRef={pointerRef}>
{Box.create({}, { defaultProps: { styles: styles.pointer } })}
</Ref>
)}
{Box.create(
{},
{
defaultProps: {
className: PopupContent.slotClassNames.content,
children: childrenExist(children) ? children : content,
styles: styles.content,
},
},
)}
{pointing && <div className={classes.pointer} ref={pointerRef} />}
<div className={cx(PopupContent.slotClassNames.content, classes.content)}>
{childrenExist(children) ? children : content}
</div>
</>
)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default class Tooltip extends AutoControlledComponent<TooltipProps, Toolt

static create: ShorthandFactory<TooltipProps>

pointerTargetRef = React.createRef<HTMLElement>()
pointerTargetRef = React.createRef<HTMLDivElement>()
triggerRef = React.createRef<HTMLElement>()
contentRef = React.createRef<HTMLElement>()
closeTimeoutId
Expand Down
10 changes: 2 additions & 8 deletions packages/react/src/components/Tooltip/TooltipContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Ref } from '@stardust-ui/react-component-ref'
import * as React from 'react'
import * as PropTypes from 'prop-types'
import * as customPropTypes from '@stardust-ui/react-proptypes'
Expand All @@ -19,7 +18,6 @@ import { Accessibility } from '@stardust-ui/accessibility'

import { PopperChildrenProps } from '../../lib/positioner'
import { WithAsProp, withSafeTypeForAs } from '../../types'
import Box from '../Box/Box'

export interface TooltipContentProps
extends UIComponentProps,
Expand All @@ -40,7 +38,7 @@ export interface TooltipContentProps
pointing?: boolean

/** A ref to a pointer element. */
pointerRef?: React.Ref<Element>
pointerRef?: React.Ref<HTMLDivElement>
}

class TooltipContent extends UIComponent<WithAsProp<TooltipContentProps>> {
Expand Down Expand Up @@ -72,11 +70,7 @@ class TooltipContent extends UIComponent<WithAsProp<TooltipContentProps>> {
{...accessibility.attributes.root}
{...unhandledProps}
>
{open && pointing && (
<Ref innerRef={pointerRef}>
{Box.create({}, { defaultProps: { styles: styles.pointer } })}
</Ref>
)}
{open && pointing && <div className={classes.pointer} ref={pointerRef} />}

<div className={classes.content}>{childrenExist(children) ? children : content}</div>
</ElementType>
Expand Down

0 comments on commit d4cc17b

Please sign in to comment.