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 721e71c commit 08c1ba7
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 119 deletions.
14 changes: 3 additions & 11 deletions src/collections/Message/MessageItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash'
import cx from 'clsx'
import PropTypes from 'prop-types'
import React from 'react'
Expand All @@ -7,20 +6,19 @@ import {
childrenUtils,
createShorthandFactory,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
} from '../../lib'

/**
* A message list can contain an item.
*/
const MessageItem = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const MessageItem = React.forwardRef(function (props, ref) {
const { children, className, content } = props

const classes = cx('content', className)
const rest = getUnhandledProps(MessageItem, props)
const ElementType = getElementType(MessageItem, props)
const ElementType = getComponentType(props, { defaultAs: 'li' })

return (
<ElementType {...rest} className={classes} ref={ref}>
Expand All @@ -44,12 +42,6 @@ MessageItem.propTypes = {
content: customPropTypes.contentShorthand,
}

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

MessageItem.create = createShorthandFactory(MessageItem, (content) => ({ content }))

export default MessageItem
13 changes: 3 additions & 10 deletions src/collections/Message/MessageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ import {
childrenUtils,
createShorthandFactory,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
} from '../../lib'
import MessageItem from './MessageItem'

/**
* A message can contain a list of items.
*/
const MessageList = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const MessageList = React.forwardRef(function (props, ref) {
const { children, className, items } = props

const classes = cx('list', className)
const rest = getUnhandledProps(MessageList, props)
const ElementType = getElementType(MessageList, props)
const ElementType = getComponentType(props, { defaultAs: 'ul' })

return (
<ElementType {...rest} className={classes} ref={ref}>
Expand All @@ -45,12 +44,6 @@ MessageList.propTypes = {
items: customPropTypes.collectionShorthand,
}

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

MessageList.create = createShorthandFactory(MessageList, (val) => ({ items: val }))

export default MessageList
13 changes: 3 additions & 10 deletions src/collections/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react'
import {
childrenUtils,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
SUI,
useKeyOnly,
Expand All @@ -25,8 +25,7 @@ import TableRow from './TableRow'
/**
* A table displays a collections of data grouped into rows.
*/
const Table = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const Table = React.forwardRef(function (props, ref) {
const {
attached,
basic,
Expand Down Expand Up @@ -85,7 +84,7 @@ const Table = React.forwardRef(function (partialProps, ref) {
className,
)
const rest = getUnhandledProps(Table, props)
const ElementType = getElementType(Table, props)
const ElementType = getComponentType(props, { defaultAs: 'table' })

if (!childrenUtils.isNil(children)) {
return (
Expand Down Expand Up @@ -117,12 +116,6 @@ const Table = React.forwardRef(function (partialProps, ref) {
})

Table.displayName = 'Table'
function getDefaultProps() {
return {
as: 'table',
}
}

Table.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
Expand Down
15 changes: 4 additions & 11 deletions src/collections/Table/TableBody.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import _ from 'lodash'
import cx from 'clsx'
import PropTypes from 'prop-types'
import React from 'react'

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

const TableBody = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const TableBody = React.forwardRef(function (props, ref) {
const { children, className } = props

const classes = cx(className)
const rest = getUnhandledProps(TableBody, props)
const ElementType = getElementType(TableBody, props)
const ElementType = getComponentType(props, { defaultAs: 'tbody' })

return (
<ElementType {...rest} className={classes} ref={ref}>
Expand All @@ -20,12 +19,6 @@ const TableBody = React.forwardRef(function (partialProps, ref) {
})

TableBody.displayName = 'TableBody'
function getDefaultProps() {
return {
as: 'tbody',
}
}

TableBody.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
Expand Down
13 changes: 3 additions & 10 deletions src/collections/Table/TableCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
childrenUtils,
createShorthandFactory,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
SUI,
useKeyOnly,
Expand All @@ -20,8 +20,7 @@ import Icon from '../../elements/Icon'
/**
* A table row can have cells.
*/
const TableCell = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const TableCell = React.forwardRef(function (props, ref) {
const {
active,
children,
Expand Down Expand Up @@ -57,7 +56,7 @@ const TableCell = React.forwardRef(function (partialProps, ref) {
className,
)
const rest = getUnhandledProps(TableCell, props)
const ElementType = getElementType(TableCell, props)
const ElementType = getComponentType(props, { defaultAs: 'td' })

if (!childrenUtils.isNil(children)) {
return (
Expand All @@ -75,12 +74,6 @@ const TableCell = React.forwardRef(function (partialProps, ref) {
)
})

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

TableCell.displayName = 'TableCell'
TableCell.propTypes = {
/** An element type to render as (string or function). */
Expand Down
12 changes: 2 additions & 10 deletions src/collections/Table/TableFooter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

Expand All @@ -8,9 +7,8 @@ import TableHeader from './TableHeader'
/**
* A table can have a footer.
*/
const TableFooter = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { as } = props
const TableFooter = React.forwardRef(function (props, ref) {
const { as = 'tfoot' } = props
const rest = getUnhandledProps(TableFooter, props)

return <TableHeader {...rest} as={as} ref={ref} />
Expand All @@ -22,10 +20,4 @@ TableFooter.propTypes = {
as: PropTypes.elementType,
}

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

export default TableFooter
15 changes: 4 additions & 11 deletions src/collections/Table/TableHeader.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
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'

/**
* A table can have a header.
*/
const TableHeader = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const TableHeader = React.forwardRef(function (props, ref) {
const { children, className, content, fullWidth } = props

const classes = cx(useKeyOnly(fullWidth, 'full-width'), className)
const rest = getUnhandledProps(TableHeader, props)
const ElementType = getElementType(TableHeader, props)
const ElementType = getComponentType(props, { defaultAs: 'thead' })

return (
<ElementType {...rest} className={classes} ref={ref}>
Expand All @@ -28,12 +27,6 @@ const TableHeader = React.forwardRef(function (partialProps, ref) {
)
})

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

TableHeader.displayName = 'TableHeader'
TableHeader.propTypes = {
/** An element type to render as (string or function). */
Expand Down
14 changes: 3 additions & 11 deletions src/collections/Table/TableHeaderCell.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash'
import cx from 'clsx'
import PropTypes from 'prop-types'
import React from 'react'
Expand All @@ -9,11 +8,10 @@ import TableCell from './TableCell'
/**
* A table can have a header cell.
*/
const TableHeaderCell = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { as, className, sorted } = props
const TableHeaderCell = React.forwardRef(function (props, ref) {
const { as = 'th', className, sorted } = props
const classes = cx(useValueAndKey(sorted, 'sorted'), className)
const rest = getUnhandledProps(TableHeaderCell, props)
const rest = getUnhandledProps(props)

return <TableCell {...rest} as={as} className={classes} ref={ref} />
})
Expand All @@ -30,10 +28,4 @@ TableHeaderCell.propTypes = {
sorted: PropTypes.oneOf(['ascending', 'descending']),
}

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

export default TableHeaderCell
16 changes: 4 additions & 12 deletions src/collections/Table/TableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
childrenUtils,
createShorthandFactory,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
SUI,
useKeyOnly,
Expand All @@ -19,11 +19,10 @@ import TableCell from './TableCell'
/**
* A table can have rows.
*/
const TableRow = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const TableRow = React.forwardRef(function (props, ref) {
const {
active,
cellAs,
cellAs = 'td',
cells,
children,
className,
Expand All @@ -48,7 +47,7 @@ const TableRow = React.forwardRef(function (partialProps, ref) {
className,
)
const rest = getUnhandledProps(TableRow, props)
const ElementType = getElementType(TableRow, props)
const ElementType = getComponentType(props, { defaultAs: 'tr' })

if (!childrenUtils.isNil(children)) {
return (
Expand All @@ -65,13 +64,6 @@ const TableRow = React.forwardRef(function (partialProps, ref) {
)
})

function getDefaultProps() {
return {
as: 'tr',
cellAs: 'td',
}
}

TableRow.displayName = 'TableRow'
TableRow.propTypes = {
/** An element type to render as (string or function). */
Expand Down
22 changes: 9 additions & 13 deletions src/elements/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
childrenUtils,
customPropTypes,
createShorthandFactory,
getElementType,
getComponentType,
getUnhandledProps,
SUI,
useKeyOnly,
Expand Down Expand Up @@ -70,8 +70,7 @@ function hasIconClass(props) {
* @see Icon
* @see Label
*/
const Button = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const Button = React.forwardRef(function (props, ref) {
const {
active,
animated,
Expand Down Expand Up @@ -124,10 +123,13 @@ const Button = React.forwardRef(function (partialProps, ref) {
const wrapperClasses = cx(useKeyOnly(disabled, 'disabled'), useValueAndKey(floated, 'floated'))

const rest = getUnhandledProps(Button, props)
const ElementType = getElementType(Button, props, () => {
if (!_.isNil(attached) || !_.isNil(label)) {
return 'div'
}
const ElementType = getComponentType(props, {
defaultAs: 'button',
getDefault: () => {
if (!_.isNil(attached) || !_.isNil(label)) {
return 'div'
}
},
})
const tabIndex = computeTabIndex(ElementType, disabled, props.tabIndex)

Expand Down Expand Up @@ -316,12 +318,6 @@ Button.propTypes = {
type: PropTypes.oneOf(['button', 'submit', 'reset']),
}

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

Button.Content = ButtonContent
Button.Group = ButtonGroup
Button.Or = ButtonOr
Expand Down
Loading

0 comments on commit 08c1ba7

Please sign in to comment.