Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Accordion/AccordionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ class AccordionContent extends UIComponent<Extendable<AccordionContentProps>, an
}
}

AccordionContent.create = createShorthandFactory(AccordionContent, content => ({ content }))
AccordionContent.create = createShorthandFactory(AccordionContent, 'content')

export default AccordionContent
2 changes: 1 addition & 1 deletion src/components/Accordion/AccordionTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ class AccordionTitle extends UIComponent<Extendable<AccordionTitleProps>, any> {
}
}

AccordionTitle.create = createShorthandFactory(AccordionTitle, content => ({ content }))
AccordionTitle.create = createShorthandFactory(AccordionTitle, 'content')

export default AccordionTitle
10 changes: 5 additions & 5 deletions src/components/Attachment/Attachment.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as _ from 'lodash'
import * as PropTypes from 'prop-types'
import * as React from 'react'

import { UIComponent, customPropTypes, createShorthandFactory, createHTMLDivision } from '../../lib'
import * as _ from 'lodash'
import { UIComponent, customPropTypes, createShorthandFactory } from '../../lib'
import { Extendable, ShorthandRenderFunction, ShorthandValue } from '../../../types/utils'
import Icon from '../Icon/Icon'
import Button from '../Button/Button'
import Text from '../Text/Text'
import Slot from '../Slot/Slot'
import { UIComponentProps, ChildrenComponentProps } from '../../lib/commonPropInterfaces'
import { commonUIComponentPropTypes, childrenComponentPropTypes } from '../../lib/commonPropTypes'

Expand Down Expand Up @@ -147,7 +147,7 @@ class Attachment extends UIComponent<Extendable<AttachmentProps>, any> {
</div>
)}
{!_.isNil(progress) &&
createHTMLDivision('', {
Slot.create('', {
defaultProps: { className: classes.progress },
render: renderProgress,
})}
Expand All @@ -156,6 +156,6 @@ class Attachment extends UIComponent<Extendable<AttachmentProps>, any> {
}
}

Attachment.create = createShorthandFactory(Attachment, header => ({ header }))
Attachment.create = createShorthandFactory(Attachment, 'header')

export default Attachment
3 changes: 1 addition & 2 deletions src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ class Avatar extends UIComponent<Extendable<AvatarProps>, any> {
!renderImage &&
Label.create(label || {}, {
defaultProps: {
as: 'div',
content: getInitials(name),
circular: true,
title: name,
Expand All @@ -144,7 +143,7 @@ class Avatar extends UIComponent<Extendable<AvatarProps>, any> {
}
}

Avatar.create = createShorthandFactory(Avatar, name => ({ name }))
Avatar.create = createShorthandFactory(Avatar, 'name')

export default Avatar

Expand Down
6 changes: 3 additions & 3 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as _ from 'lodash'

import { UIComponent, childrenExist, customPropTypes, createShorthandFactory } from '../../lib'
import Icon from '../Icon/Icon'
import { createSlot } from '../Slot/Slot'
import Slot from '../Slot/Slot'
import { buttonBehavior } from '../../lib/accessibility'
import { Accessibility } from '../../lib/accessibility/types'
import {
Expand Down Expand Up @@ -155,7 +155,7 @@ class Button extends UIComponent<Extendable<ButtonProps>, ButtonState> {
>
{hasChildren && children}
{!hasChildren && iconPosition !== 'after' && this.renderIcon(variables, styles)}
{createSlot(!hasChildren && content, {
{Slot.create(!hasChildren && content, {
defaultProps: { as: 'span', className: classes.content },
})}
{!hasChildren && iconPosition === 'after' && this.renderIcon(variables, styles)}
Expand Down Expand Up @@ -194,6 +194,6 @@ class Button extends UIComponent<Extendable<ButtonProps>, ButtonState> {
}
}

Button.create = createShorthandFactory(Button, content => ({ content }))
Button.create = createShorthandFactory(Button, 'content')

export default Button
6 changes: 3 additions & 3 deletions src/components/Chat/ChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import * as PropTypes from 'prop-types'

import { childrenExist, createShorthandFactory, RenderResultConfig, UIComponent } from '../../lib'
import { createSlot } from '../Slot/Slot'
import Slot from '../Slot/Slot'
import { Extendable, ShorthandRenderFunction } from '../../../types/utils'
import {
UIComponentProps,
Expand Down Expand Up @@ -63,7 +63,7 @@ class ChatItem extends UIComponent<Extendable<ChatItemProps>, any> {
<ElementType {...rest} className={classes.root}>
{childrenExist(children)
? children
: createSlot(content, {
: Slot.create(content, {
styles: styles.content,
variables: variables.content,
render: renderContent,
Expand All @@ -73,6 +73,6 @@ class ChatItem extends UIComponent<Extendable<ChatItemProps>, any> {
}
}

ChatItem.create = createShorthandFactory(ChatItem, content => ({ content }))
ChatItem.create = createShorthandFactory(ChatItem, 'content')

export default ChatItem
6 changes: 3 additions & 3 deletions src/components/Chat/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { chatMessageBehavior } from '../../lib/accessibility'
import { Accessibility, AccessibilityActionHandlers } from '../../lib/accessibility/types'
import Layout from '../Layout/Layout'
import Text from '../Text/Text'
import { createSlot } from '../Slot/Slot'
import Slot from '../Slot/Slot'
import {
UIComponentProps,
ChildrenComponentProps,
Expand Down Expand Up @@ -197,7 +197,7 @@ class ChatMessage extends UIComponent<Extendable<ChatMessageProps>, any> {
render: renderTimestamp,
})

const contentElement = createSlot(content, {
const contentElement = Slot.create(content, {
styles: styles.content,
variables: variables.content,
render: renderContent,
Expand Down Expand Up @@ -225,6 +225,6 @@ class ChatMessage extends UIComponent<Extendable<ChatMessageProps>, any> {
}
}

ChatMessage.create = createShorthandFactory(ChatMessage, content => ({ content }))
ChatMessage.create = createShorthandFactory(ChatMessage, 'content')

export default ChatMessage
2 changes: 1 addition & 1 deletion src/components/Divider/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Divider extends UIComponent<Extendable<DividerProps>, any> {
}
}

Divider.create = createShorthandFactory(Divider, content => ({ content }))
Divider.create = createShorthandFactory(Divider, 'content')

export default Divider

Expand Down
6 changes: 3 additions & 3 deletions src/components/Form/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as React from 'react'
import { UIComponent, customPropTypes, childrenExist, createShorthandFactory } from '../../lib'
import { Extendable, ShorthandValue, ShorthandRenderFunction } from '../../../types/utils'
import Text from '../Text/Text'
import { createSlot } from '../Slot/Slot'
import Input from '../Input/Input'
import Slot from '../Slot/Slot'
import { UIComponentProps, ChildrenComponentProps } from '../../lib/commonPropInterfaces'
import { commonUIComponentPropTypes, childrenComponentPropTypes } from '../../lib/commonPropTypes'

Expand Down Expand Up @@ -131,7 +131,7 @@ class FormField extends UIComponent<Extendable<FormFieldProps>, any> {
render: renderMessage,
})

const controlElement = createSlot(control || {}, {
const controlElement = Slot.create(control || {}, {
defaultProps: { required, id, name, type, styles: styles.control },
render: renderControl,
})
Expand All @@ -158,6 +158,6 @@ class FormField extends UIComponent<Extendable<FormFieldProps>, any> {
}
}

FormField.create = createShorthandFactory(FormField, label => ({ label }))
FormField.create = createShorthandFactory(FormField, 'label')

export default FormField
2 changes: 1 addition & 1 deletion src/components/Header/HeaderDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ class HeaderDescription extends UIComponent<Extendable<HeaderDescriptionProps>,
}
}

HeaderDescription.create = createShorthandFactory(HeaderDescription, content => ({ content }))
HeaderDescription.create = createShorthandFactory(HeaderDescription, 'content')

export default HeaderDescription
2 changes: 1 addition & 1 deletion src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ class Icon extends UIComponent<Extendable<IconProps>, any> {
}
}

Icon.create = createShorthandFactory(Icon, name => ({ name }))
Icon.create = createShorthandFactory(Icon, 'name')

export default Icon
2 changes: 1 addition & 1 deletion src/components/Image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ class Image extends UIComponent<Extendable<ImageProps>, any> {
}
}

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

export default Image
13 changes: 8 additions & 5 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
ComponentEventHandler,
} from '../../../types/utils'
import Icon from '../Icon/Icon'
import { createHTMLInput, createSlot } from '../Slot/Slot'
import Ref from '../Ref/Ref'
import Slot from '../Slot/Slot'
import { UIComponentProps, ChildrenComponentProps } from '../../lib/commonPropInterfaces'
import { commonUIComponentPropTypes, childrenComponentPropTypes } from '../../lib/commonPropTypes'

Expand Down Expand Up @@ -136,7 +136,7 @@ class Input extends AutoControlledComponent<Extendable<InputProps>, InputState>

static defaultProps = {
type: 'text',
wrapper: 'div',
wrapper: {},
iconPosition: 'end',
}

Expand All @@ -153,16 +153,16 @@ class Input extends AutoControlledComponent<Extendable<InputProps>, InputState>
const { value = '' } = this.state
const [htmlInputProps, rest] = partitionHTMLProps(restProps)

return createSlot(wrapper, {
return Slot.create(wrapper, {
defaultProps: {
as: ElementType,
className: cx(Input.className, className),
children: (
<>
<Ref innerRef={this.handleInputRef}>
{createHTMLInput(input || type, {
{Slot.create(input || type, {
defaultProps: {
...htmlInputProps,
as: 'input',
type,
value,
className: classes.input,
Expand All @@ -184,6 +184,9 @@ class Input extends AutoControlledComponent<Extendable<InputProps>, InputState>
styles: styles.root,
...rest,
},
overrideProps: {
as: (wrapper && (wrapper as any).as) || ElementType,
},
render: renderWrapper,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ItemLayout/ItemLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class ItemLayout extends UIComponent<Extendable<ItemLayoutProps>, any> {
}
}

ItemLayout.create = createShorthandFactory(ItemLayout, main => ({ main }))
ItemLayout.create = createShorthandFactory(ItemLayout, 'main')

export default ItemLayout

Expand Down
2 changes: 1 addition & 1 deletion src/components/Label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ class Label extends UIComponent<Extendable<LabelProps>, any> {
}
}

Label.create = createShorthandFactory(Label, content => ({ content }))
Label.create = createShorthandFactory(Label, 'content')

export default Label
2 changes: 1 addition & 1 deletion src/components/List/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ class ListItem extends UIComponent<Extendable<ListItemProps>, ListItemState> {
}
}

ListItem.create = createShorthandFactory(ListItem, main => ({ main }))
ListItem.create = createShorthandFactory(ListItem, 'main')

export default ListItem
2 changes: 1 addition & 1 deletion src/components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,6 @@ class MenuItem extends UIComponent<Extendable<MenuItemProps>, MenuItemState> {
}
}

MenuItem.create = createShorthandFactory(MenuItem, content => ({ content }))
MenuItem.create = createShorthandFactory(MenuItem, 'content')

export default MenuItem
2 changes: 1 addition & 1 deletion src/components/Popup/PopupContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ class PopupContent extends UIComponent<Extendable<PopupContentProps>, any> {
}
}

PopupContent.create = createShorthandFactory(PopupContent, content => ({ content }))
PopupContent.create = createShorthandFactory(PopupContent, 'content')

export default PopupContent
2 changes: 1 addition & 1 deletion src/components/RadioGroup/RadioGroupItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,6 @@ class RadioGroupItem extends AutoControlledComponent<
}
}

RadioGroupItem.create = createShorthandFactory(RadioGroupItem, () => ({}))
RadioGroupItem.create = createShorthandFactory(RadioGroupItem)

export default RadioGroupItem
4 changes: 2 additions & 2 deletions src/components/Segment/Segment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { UIComponent, childrenExist } from '../../lib'
import { Extendable, ShorthandRenderFunction } from '../../../types/utils'
import { UIComponentProps, ContentComponentProps } from '../../lib/commonPropInterfaces'
import { commonUIComponentPropTypes, contentComponentPropsTypes } from '../../lib/commonPropTypes'
import { createSlot } from '../Slot/Slot'
import Slot from '../Slot/Slot'

export interface SegmentProps extends UIComponentProps<SegmentProps, any>, ContentComponentProps {
/** A segment can have its colors inverted for contrast. */
Expand Down Expand Up @@ -43,7 +43,7 @@ class Segment extends UIComponent<Extendable<SegmentProps>, any> {

return (
<ElementType {...rest} className={classes.root}>
{childrenExist(children) ? children : createSlot(content, { render: renderContent })}
{childrenExist(children) ? children : Slot.create(content, { render: renderContent })}
</ElementType>
)
}
Expand Down
20 changes: 6 additions & 14 deletions src/components/Slot/Slot.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { childrenExist, createShorthand } from '../../lib'
import { childrenExist, createShorthandFactory } from '../../lib'
import {
UIComponentProps,
ContentComponentProps,
Expand All @@ -10,8 +10,7 @@ import {
contentComponentPropsTypes,
childrenComponentPropTypes,
} from '../../lib/commonPropTypes'
import createComponent from '../../lib/createComponent'
import { MapValueToProps, Props } from 'types/utils'
import createComponent, { CreateComponentReturnType } from '../../lib/createComponent'

export interface SlotProps
extends UIComponentProps<SlotProps, any>,
Expand All @@ -21,7 +20,9 @@ export interface SlotProps
/**
* A Slot is a basic component (no default styles)
*/
const Slot = createComponent<SlotProps>({
const Slot: CreateComponentReturnType<SlotProps> & {
create?: Function
} = createComponent<SlotProps>({
displayName: 'Slot',

className: 'ui-slot',
Expand All @@ -44,15 +45,6 @@ const Slot = createComponent<SlotProps>({
},
})

const createSlotFactory = (as: any, mapValueToProps: MapValueToProps) => (
val,
options: Props = {},
) => {
options.defaultProps = { as, ...options.defaultProps }
return createShorthand(Slot, mapValueToProps, val, options)
}

export const createSlot = createSlotFactory(Slot.defaultProps.as, content => ({ content }))
export const createHTMLInput = createSlotFactory('input', type => ({ type }))
Slot.create = createShorthandFactory(Slot)

export default Slot
2 changes: 1 addition & 1 deletion src/components/Status/Status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Status extends UIComponent<Extendable<StatusProps>, any> {
}
}

Status.create = createShorthandFactory(Status, state => ({ state }))
Status.create = createShorthandFactory(Status, 'state')

export default Status
export type StatusPropsWithDefaults = StatusProps & typeof Status.defaultProps
2 changes: 1 addition & 1 deletion src/components/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ class Text extends UIComponent<Extendable<TextProps>, any> {
}
}

Text.create = createShorthandFactory(Text, content => ({ content }))
Text.create = createShorthandFactory(Text, 'content')

export default Text
Loading