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 08c1ba7 commit 3981cce
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 111 deletions.
16 changes: 4 additions & 12 deletions src/addons/TextArea/TextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

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

/**
* A TextArea can be used to allow for extended user input.
* @see Form
*/
const TextArea = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { rows, value } = props
const TextArea = React.forwardRef(function (props, ref) {
const { rows = 3, value } = props
const elementRef = useMergedRefs(ref, React.useRef())

const handleChange = (e) => {
Expand All @@ -26,7 +25,7 @@ const TextArea = React.forwardRef(function (partialProps, ref) {
}

const rest = getUnhandledProps(TextArea, props)
const ElementType = getElementType(TextArea, props)
const ElementType = getComponentType(props, { defaultAs: 'textarea' })

return (
<ElementType
Expand Down Expand Up @@ -66,11 +65,4 @@ TextArea.propTypes = {
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
}

function getDefaultProps() {
return {
as: 'textarea',
rows: 3,
}
}

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

import { getElementType, getUnhandledProps, SUI, useKeyOnly, useWidthProp } from '../../lib'
import { getComponentType, getUnhandledProps, SUI, useKeyOnly, useWidthProp } from '../../lib'
import FormButton from './FormButton'
import FormCheckbox from './FormCheckbox'
import FormDropdown from './FormDropdown'
Expand All @@ -24,8 +24,7 @@ import FormTextArea from './FormTextArea'
* @see Radio
* @see Select
*/
const Form = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const Form = React.forwardRef(function (props, ref) {
const {
action,
children,
Expand Down Expand Up @@ -63,7 +62,7 @@ const Form = React.forwardRef(function (partialProps, ref) {
className,
)
const rest = getUnhandledProps(Form, props)
const ElementType = getElementType(Form, props)
const ElementType = getComponentType(props, { defaultAs: 'form' })

return (
<ElementType {...rest} action={action} className={classes} onSubmit={handleSubmit} ref={ref}>
Expand Down Expand Up @@ -118,12 +117,6 @@ Form.propTypes = {
widths: PropTypes.oneOf(['equal']),
}

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

Form.Field = FormField
Form.Button = FormButton
Form.Checkbox = FormCheckbox
Expand Down
13 changes: 4 additions & 9 deletions src/collections/Form/FormButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types'
import React from 'react'

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

Expand All @@ -11,15 +11,15 @@ import FormField from './FormField'
* @see Form
*/
const FormButton = React.forwardRef((props, ref) => {
const { control } = props
const { control = Button } = props

const rest = getUnhandledProps(FormButton, props)
const ElementType = getElementType(FormButton, props)
const ElementType = getComponentType(props, { defaultAs: FormField })

return <ElementType {...rest} control={control} ref={ref} />
})

FormButton.displayName = 'FormButton'

FormButton.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
Expand All @@ -28,9 +28,4 @@ FormButton.propTypes = {
control: FormField.propTypes.control,
}

FormButton.defaultProps = {
as: FormField,
control: Button,
}

export default FormButton
13 changes: 4 additions & 9 deletions src/collections/Form/FormCheckbox.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types'
import React from 'react'

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

Expand All @@ -11,15 +11,15 @@ import FormField from './FormField'
* @see Form
*/
const FormCheckbox = React.forwardRef((props, ref) => {
const { control } = props
const { control = Checkbox } = props

const rest = getUnhandledProps(FormCheckbox, props)
const ElementType = getElementType(FormCheckbox, props)
const ElementType = getComponentType(props, { defaultAs: FormField })

return <ElementType {...rest} control={control} ref={ref} />
})

FormCheckbox.displayName = 'FormCheckbox'

FormCheckbox.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
Expand All @@ -28,9 +28,4 @@ FormCheckbox.propTypes = {
control: FormField.propTypes.control,
}

FormCheckbox.defaultProps = {
as: FormField,
control: Checkbox,
}

export default FormCheckbox
18 changes: 5 additions & 13 deletions src/collections/Form/FormDropdown.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

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

Expand All @@ -11,11 +10,11 @@ import FormField from './FormField'
* @see Dropdown
* @see Form
*/
const FormDropdown = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { control } = props
const FormDropdown = React.forwardRef(function (props, ref) {
const { control = Dropdown } = props

const rest = getUnhandledProps(FormDropdown, props)
const ElementType = getElementType(FormDropdown, props)
const ElementType = getComponentType(props, { defaultAs: FormField })

return <ElementType {...rest} control={control} ref={ref} />
})
Expand All @@ -29,11 +28,4 @@ FormDropdown.propTypes = {
control: FormField.propTypes.control,
}

function getDefaultProps() {
return {
as: FormField,
control: Dropdown,
}
}

export default FormDropdown
5 changes: 2 additions & 3 deletions src/collections/Form/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
childrenUtils,
createHTMLLabel,
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
SUI,
useKeyOnly,
Expand Down Expand Up @@ -53,7 +53,7 @@ const FormField = React.forwardRef(function (props, ref) {
className,
)
const rest = getUnhandledProps(FormField, props)
const ElementType = getElementType(FormField, props)
const ElementType = getComponentType(props)

const errorPointing = _.get(error, 'pointing', 'above')
const errorLabel = Label.create(error, {
Expand Down Expand Up @@ -145,7 +145,6 @@ const FormField = React.forwardRef(function (props, ref) {
})

FormField.displayName = 'FormField'

FormField.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
Expand Down
5 changes: 2 additions & 3 deletions src/collections/Form/FormGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'

import {
customPropTypes,
getElementType,
getComponentType,
getUnhandledProps,
SUI,
useKeyOnly,
Expand All @@ -29,7 +29,7 @@ const FormGroup = React.forwardRef((props, ref) => {
className,
)
const rest = getUnhandledProps(FormGroup, props)
const ElementType = getElementType(FormGroup, props)
const ElementType = getComponentType(props)

return (
<ElementType {...rest} className={classes} ref={ref}>
Expand All @@ -39,7 +39,6 @@ const FormGroup = React.forwardRef((props, ref) => {
})

FormGroup.displayName = 'FormGroup'

FormGroup.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
Expand Down
18 changes: 5 additions & 13 deletions src/collections/Form/FormInput.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

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

Expand All @@ -11,11 +10,11 @@ import FormField from './FormField'
* @see Form
* @see Input
*/
const FormInput = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { control } = props
const FormInput = React.forwardRef(function (props, ref) {
const { control = Input } = props

const rest = getUnhandledProps(FormInput, props)
const ElementType = getElementType(FormInput, props)
const ElementType = getComponentType(props, { defaultAs: FormField })

return <ElementType {...rest} control={control} ref={ref} />
})
Expand All @@ -29,11 +28,4 @@ FormInput.propTypes = {
control: FormField.propTypes.control,
}

function getDefaultProps() {
return {
as: FormField,
control: Input,
}
}

export default FormInput
18 changes: 5 additions & 13 deletions src/collections/Form/FormRadio.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

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

Expand All @@ -11,11 +10,11 @@ import FormField from './FormField'
* @see Form
* @see Radio
*/
const FormRadio = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { control } = props
const FormRadio = React.forwardRef(function (props, ref) {
const { control = Radio } = props

const rest = getUnhandledProps(FormRadio, props)
const ElementType = getElementType(FormRadio, props)
const ElementType = getComponentType(props, { defaultAs: FormField })

return <ElementType {...rest} control={control} ref={ref} />
})
Expand All @@ -29,11 +28,4 @@ FormRadio.propTypes = {
control: FormField.propTypes.control,
}

function getDefaultProps() {
return {
as: FormField,
control: Radio,
}
}

export default FormRadio
18 changes: 5 additions & 13 deletions src/collections/Form/FormSelect.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

import { getElementType, getUnhandledProps } from '../../lib'
import { getComponentType, getUnhandledProps } from '../../lib'
import Select from '../../addons/Select'
import Dropdown from '../../modules/Dropdown'
import FormField from './FormField'
Expand All @@ -12,11 +11,11 @@ import FormField from './FormField'
* @see Form
* @see Select
*/
const FormSelect = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { control, options } = props
const FormSelect = React.forwardRef(function (props, ref) {
const { control = Select, options } = props

const rest = getUnhandledProps(FormSelect, props)
const ElementType = getElementType(FormSelect, props)
const ElementType = getComponentType(props, { defaultAs: FormField })

return <ElementType {...rest} control={control} options={options} ref={ref} />
})
Expand All @@ -33,11 +32,4 @@ FormSelect.propTypes = {
options: PropTypes.arrayOf(PropTypes.shape(Dropdown.Item.propTypes)).isRequired,
}

function getDefaultProps() {
return {
as: FormField,
control: Select,
}
}

export default FormSelect
18 changes: 5 additions & 13 deletions src/collections/Form/FormTextArea.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'

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

Expand All @@ -11,11 +10,11 @@ import FormField from './FormField'
* @see Form
* @see TextArea
*/
const FormTextArea = React.forwardRef(function (partialProps, ref) {
const props = _.defaults(partialProps, getDefaultProps())
const { control } = props
const FormTextArea = React.forwardRef(function (props, ref) {
const { control = TextArea } = props

const rest = getUnhandledProps(FormTextArea, props)
const ElementType = getElementType(FormTextArea, props)
const ElementType = getComponentType(props, { defaultAs: FormField })

return <ElementType {...rest} control={control} ref={ref} />
})
Expand All @@ -29,11 +28,4 @@ FormTextArea.propTypes = {
control: FormField.propTypes.control,
}

function getDefaultProps() {
return {
as: FormField,
control: TextArea,
}
}

export default FormTextArea

0 comments on commit 3981cce

Please sign in to comment.