Skip to content

Commit

Permalink
apply changes
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter committed Dec 29, 2023
1 parent baed0af commit 45982c1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 103 deletions.
27 changes: 8 additions & 19 deletions src/modules/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
customPropTypes,
doesNodeContainClick,
eventStack,
getElementType,
getComponentType,
getUnhandledProps,
isBrowser,
makeDebugger,
Expand All @@ -33,20 +33,19 @@ const debug = makeDebugger('modal')
* @see Confirm
* @see Portal
*/
const Modal = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const Modal = React.forwardRef(function (props, ref) {
const {
actions,
basic,
centered,
centered = true,
children,
className,
closeIcon,
closeOnDimmerClick,
closeOnDocumentClick,
closeOnDimmerClick = true,
closeOnDocumentClick = false,
content,
dimmer,
eventPool,
dimmer = true,
eventPool = 'Modal',
header,
size,
style,
Expand Down Expand Up @@ -186,7 +185,7 @@ const Modal = React.forwardRef(function (partialProps, ref) {
'modal transition visible active',
className,
)
const ElementType = getElementType(Modal, props)
const ElementType = getComponentType(props)

const closeIconName = closeIcon === true ? 'close' : closeIcon
const closeIconJSX = Icon.create(closeIconName, {
Expand Down Expand Up @@ -399,16 +398,6 @@ Modal.propTypes = {
*/
}

function getDefaultProps() {
return {
centered: true,
dimmer: true,
closeOnDimmerClick: true,
closeOnDocumentClick: false,
eventPool: 'Modal',
}
}

Modal.Actions = ModalActions
Modal.Content = ModalContent
Modal.Description = ModalDescription
Expand Down
30 changes: 9 additions & 21 deletions src/modules/Popup/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
childrenUtils,
createHTMLDivision,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
makeDebugger,
SUI,
Expand All @@ -35,7 +35,7 @@ const debug = makeDebugger('popup')
*/
function getPortalProps(props) {
const portalProps = {}
const normalizedOn = _.isArray(props.on) ? props.on : [props.on]
const normalizedOn = _.isArray(props.on) ? props.on ?? ['click', 'hover'] : [props.on]

if (props.hoverable) {
portalProps.closeOnPortalMouseLeave = true
Expand Down Expand Up @@ -111,25 +111,24 @@ function usePositioningEffect(popperDependencies, positionUpdate) {
/**
* A Popup displays additional information on top of a page.
*/
const Popup = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const Popup = React.forwardRef(function (props, ref) {
const {
basic,
className,
content,
context,
children,
disabled,
eventsEnabled,
disabled = false,
eventsEnabled = true,
flowing,
header,
inverted,
offset,
pinned,
pinned = false,
popper,
popperDependencies,
popperModifiers,
position,
popperModifiers = [],
position = 'top left',
positionFixed,
size,
style,
Expand Down Expand Up @@ -231,7 +230,7 @@ const Popup = React.forwardRef(function (partialProps, ref) {
'popup transition visible',
className,
)
const ElementType = getElementType(Popup, props)
const ElementType = getComponentType(props)

const styles = {
// Heads up! We need default styles to get working correctly `flowing`
Expand Down Expand Up @@ -470,17 +469,6 @@ Popup.propTypes = {
wide: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['very'])]),
}

function getDefaultProps() {
return {
disabled: false,
eventsEnabled: true,
on: ['click', 'hover'],
pinned: false,
popperModifiers: [],
position: 'top left',
}
}

Popup.Content = PopupContent
Popup.Header = PopupHeader

Expand Down
16 changes: 4 additions & 12 deletions src/modules/Rating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
import React from 'react'

import {
getElementType,
getComponentType,
getUnhandledProps,
SUI,
useKeyOnly,
Expand All @@ -15,9 +15,8 @@ import RatingIcon from './RatingIcon'
/**
* A rating indicates user interest in content.
*/
const Rating = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { className, clearable, disabled, icon, maxRating, size } = props
const Rating = React.forwardRef(function (props, ref) {
const { className, clearable = 'auto', disabled, icon, maxRating = 1, size } = props

const [rating, setRating] = useAutoControlledValue({
state: props.rating,
Expand All @@ -37,7 +36,7 @@ const Rating = React.forwardRef(function (partialProps, ref) {
className,
)
const rest = getUnhandledProps(Rating, props)
const ElementType = getElementType(Rating, props)
const ElementType = getComponentType(props)

const handleIconClick = (e, { index }) => {
if (disabled) {
Expand Down Expand Up @@ -152,13 +151,6 @@ Rating.propTypes = {
size: PropTypes.oneOf(_.without(SUI.SIZES, 'medium', 'big')),
}

function getDefaultProps() {
return {
clearable: 'auto',
maxRating: 1,
}
}

Rating.Icon = RatingIcon

export default Rating
13 changes: 3 additions & 10 deletions src/modules/Rating/RatingIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

import { getElementType, getUnhandledProps, useKeyOnly } from '../../lib'
import { getComponentType, getUnhandledProps, useKeyOnly } from '../../lib'

/**
* An internal icon sub-component for Rating component
*/
const RatingIcon = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const RatingIcon = React.forwardRef(function (props, ref) {
const { active, className, selected } = props

const classes = cx(
Expand All @@ -20,7 +19,7 @@ const RatingIcon = React.forwardRef(function (partialProps, ref) {
className,
)
const rest = getUnhandledProps(RatingIcon, props)
const ElementType = getElementType(RatingIcon, props)
const ElementType = getComponentType(props, { as: 'i' })

const handleClick = (e) => {
_.invoke(props, 'onClick', e, props)
Expand Down Expand Up @@ -98,10 +97,4 @@ RatingIcon.propTypes = {
selected: PropTypes.bool,
}

function getDefaultProps() {
return {
as: 'i',
}
}

export default RatingIcon
24 changes: 11 additions & 13 deletions src/modules/Search/SearchCategory.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import _ from 'lodash'
import cx from 'clsx'
import PropTypes from 'prop-types'
import React from 'react'

import {
childrenUtils,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
useKeyOnly,
} from '../../lib'
import SearchCategoryLayout from './SearchCategoryLayout'

const SearchCategory = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { active, children, className, content, layoutRenderer, renderer } = props
const SearchCategory = React.forwardRef(function (props, ref) {
const {
active,
children,
className,
content,
layoutRenderer = SearchCategoryLayout,
renderer = ({ name }) => name,
} = props

const classes = cx(useKeyOnly(active, 'active'), 'category', className)
const rest = getUnhandledProps(SearchCategory, props)
const ElementType = getElementType(SearchCategory, props)
const ElementType = getComponentType(props)

const categoryContent = renderer(props)
const resultsContent = childrenUtils.isNil(children) ? content : children
Expand All @@ -30,13 +35,6 @@ const SearchCategory = React.forwardRef(function (partialProps, ref) {
)
})

function getDefaultProps() {
return {
layoutRenderer: SearchCategoryLayout,
renderer: ({ name }) => name,
}
}

SearchCategory.displayName = 'SearchCategory'
SearchCategory.propTypes = {
/** An element type to render as (string or function). */
Expand Down
15 changes: 4 additions & 11 deletions src/modules/Search/SearchResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react'
import {
createHTMLImage,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
useKeyOnly,
} from '../../lib'
Expand All @@ -31,17 +31,16 @@ const defaultRenderer = ({ image, price, title, description }) => [
</div>,
]

const SearchResult = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { active, className, renderer } = props
const SearchResult = React.forwardRef(function (props, ref) {
const { active, className, renderer = defaultRenderer } = props

const handleClick = (e) => {
_.invoke(props, 'onClick', e, props)
}

const classes = cx(useKeyOnly(active, 'active'), 'result', className)
const rest = getUnhandledProps(SearchResult, props)
const ElementType = getElementType(SearchResult, props)
const ElementType = getComponentType(props)

// Note: You technically only need the 'content' wrapper when there's an
// image. However, optionally wrapping it makes this function a lot more
Expand Down Expand Up @@ -100,10 +99,4 @@ SearchResult.propTypes = {
title: PropTypes.string.isRequired,
}

function getDefaultProps() {
return {
renderer: defaultRenderer,
}
}

export default SearchResult
24 changes: 7 additions & 17 deletions src/modules/Sticky/Sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react'

import {
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
isRefObject,
isBrowser,
Expand All @@ -16,16 +16,15 @@ import {
/**
* Sticky content stays fixed to the browser viewport while another column of content is visible on the page.
*/
const Sticky = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const Sticky = React.forwardRef(function (props, ref) {
const {
active,
bottomOffset,
active = true,
bottomOffset = 0,
children,
className,
context,
offset,
scrollContext,
offset = 0,
scrollContext = isBrowser() ? window : null,
styleElement,
} = props

Expand Down Expand Up @@ -243,7 +242,7 @@ const Sticky = React.forwardRef(function (partialProps, ref) {
// ----------------------------------------

const rest = getUnhandledProps(Sticky, props)
const ElementType = getElementType(Sticky, props)
const ElementType = getComponentType(props)

const containerClasses = cx(
sticky && 'ui',
Expand Down Expand Up @@ -334,13 +333,4 @@ Sticky.propTypes = {
styleElement: PropTypes.object,
}

function getDefaultProps() {
return {
active: true,
bottomOffset: 0,
offset: 0,
scrollContext: isBrowser() ? window : null,
}
}

export default Sticky

0 comments on commit 45982c1

Please sign in to comment.