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 45982c1 commit 721e71c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 66 deletions.
35 changes: 15 additions & 20 deletions src/elements/Image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
childrenUtils,
createShorthandFactory,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
htmlImageProps,
partitionHTMLProps,
Expand All @@ -25,8 +25,7 @@ import ImageGroup from './ImageGroup'
* An image is a graphic representation of something.
* @see Icon
*/
const Image = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const Image = React.forwardRef(function (props, ref) {
const {
avatar,
bordered,
Expand All @@ -48,7 +47,7 @@ const Image = React.forwardRef(function (partialProps, ref) {
spaced,
verticalAlign,
wrapped,
ui,
ui = true,
} = props

const classes = cx(
Expand All @@ -73,15 +72,18 @@ const Image = React.forwardRef(function (partialProps, ref) {
const rest = getUnhandledProps(Image, props)
const [imgTagProps, rootProps] = partitionHTMLProps(rest, { htmlProps: htmlImageProps })

const ElementType = getElementType(Image, props, () => {
if (
!_.isNil(dimmer) ||
!_.isNil(label) ||
!_.isNil(wrapped) ||
!childrenUtils.isNil(children)
) {
return 'div'
}
const ElementType = getComponentType(props, {
defaultAs: 'img',
getDefault: () => {
if (
!_.isNil(dimmer) ||
!_.isNil(label) ||
!_.isNil(wrapped) ||
!childrenUtils.isNil(children)
) {
return 'div'
}
},
})

if (!childrenUtils.isNil(children)) {
Expand Down Expand Up @@ -184,13 +186,6 @@ Image.propTypes = {
wrapped: PropTypes.bool,
}

function getDefaultProps() {
return {
as: 'img',
ui: true,
}
}

Image.create = createShorthandFactory(Image, (value) => ({ src: value }))

export default Image
15 changes: 4 additions & 11 deletions src/elements/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
createHTMLInput,
createShorthandFactory,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
partitionHTMLProps,
useKeyOnly,
Expand All @@ -26,8 +26,7 @@ import Label from '../Label'
* @see Icon
* @see Label
*/
const Input = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const Input = React.forwardRef(function (props, ref) {
const {
action,
actionPosition,
Expand All @@ -47,7 +46,7 @@ const Input = React.forwardRef(function (partialProps, ref) {
size,
tabIndex,
transparent,
type,
type = 'text',
} = props

const computeIcon = () => {
Expand Down Expand Up @@ -109,7 +108,7 @@ const Input = React.forwardRef(function (partialProps, ref) {
'input',
className,
)
const ElementType = getElementType(Input, props)
const ElementType = getComponentType(props)
const [htmlInputProps, rest] = partitionProps()

// Render with children
Expand Down Expand Up @@ -235,12 +234,6 @@ Input.propTypes = {
type: PropTypes.string,
}

function getDefaultProps() {
return {
type: 'text',
}
}

Input.create = createShorthandFactory(Input, (type) => ({ type }))

export default Input
15 changes: 4 additions & 11 deletions src/modules/Accordion/AccordionAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
childrenUtils,
createShorthandFactory,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
useAutoControlledValue,
useEventCallback,
Expand Down Expand Up @@ -44,9 +44,8 @@ function computeNewIndex(exclusive, activeIndex, itemIndex) {
/**
* An Accordion can contain sub-accordions.
*/
const AccordionAccordion = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { className, children, exclusive, panels } = props
const AccordionAccordion = React.forwardRef(function (props, ref) {
const { className, children, exclusive = true, panels } = props
const [activeIndex, setActiveIndex] = useAutoControlledValue({
state: props.activeIndex,
defaultState: props.defaultActiveIndex,
Expand All @@ -55,7 +54,7 @@ const AccordionAccordion = React.forwardRef(function (partialProps, ref) {

const classes = cx('accordion', className)
const rest = getUnhandledProps(AccordionAccordion, props)
const ElementType = getElementType(AccordionAccordion, props)
const ElementType = getComponentType(props)

const handleTitleClick = useEventCallback((e, titleProps) => {
const { index } = titleProps
Expand Down Expand Up @@ -93,12 +92,6 @@ const AccordionAccordion = React.forwardRef(function (partialProps, ref) {
)
})

function getDefaultProps() {
return {
exclusive: true,
}
}

AccordionAccordion.displayName = 'AccordionAccordion'
AccordionAccordion.propTypes = {
/** An element type to render as (string or function). */
Expand Down
15 changes: 4 additions & 11 deletions src/modules/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react'
import {
createHTMLLabel,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
htmlInputAttrs,
makeDebugger,
Expand All @@ -24,8 +24,7 @@ const debug = makeDebugger('checkbox')
* @see Form
* @see Radio
*/
const Checkbox = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const Checkbox = React.forwardRef(function (props, ref) {
const {
className,
disabled,
Expand All @@ -37,7 +36,7 @@ const Checkbox = React.forwardRef(function (partialProps, ref) {
slider,
tabIndex,
toggle,
type,
type = 'checkbox',
value,
} = props

Expand Down Expand Up @@ -194,7 +193,7 @@ const Checkbox = React.forwardRef(function (partialProps, ref) {
className,
)
const unhandled = getUnhandledProps(Checkbox, props)
const ElementType = getElementType(Checkbox, props)
const ElementType = getComponentType(props)
const [htmlInputProps, rest] = partitionHTMLProps(unhandled, { htmlProps: htmlInputAttrs })

// Heads Up!
Expand Down Expand Up @@ -320,10 +319,4 @@ Checkbox.propTypes = {
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}

function getDefaultProps() {
return {
type: 'checkbox',
}
}

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

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

/**
* A search item sub-component for Dropdown component.
*/
const DropdownSearchInput = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { autoComplete, className, tabIndex, type, value } = props
const DropdownSearchInput = React.forwardRef(function (props, ref) {
const { autoComplete = 'off', className, tabIndex, type = 'text', value } = props

const handleChange = (e) => {
const newValue = _.get(e, 'target.value')
Expand All @@ -19,7 +18,7 @@ const DropdownSearchInput = React.forwardRef(function (partialProps, ref) {
}

const classes = cx('search', className)
const ElementType = getElementType(DropdownSearchInput, props)
const ElementType = getComponentType(props, { defaultAs: 'input' })
const rest = getUnhandledProps(DropdownSearchInput, props)

return (
Expand Down Expand Up @@ -58,14 +57,6 @@ DropdownSearchInput.propTypes = {
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
}

function getDefaultProps() {
return {
as: 'input',
autoComplete: 'off',
type: 'text',
}
}

DropdownSearchInput.create = createShorthandFactory(DropdownSearchInput, (type) => ({ type }))

export default DropdownSearchInput

0 comments on commit 721e71c

Please sign in to comment.