Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(parts): add reusable component parts #345

Closed
wants to merge 6 commits into from
Closed
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 docs/app/Examples/views/Feed/Content/Date.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Date = () => {
<Feed.Event>
<Feed.Label image={imageSrc} />
<Feed.Content>
<Feed.Date date='3 days ago' />
<Feed.Date>3 days ago</Feed.Date>
<Feed.Summary>
You added <a>Jenny Hess</a> to your <a>coworker</a> group.
</Feed.Summary>
Expand Down
2 changes: 1 addition & 1 deletion docs/app/Examples/views/Feed/Content/DateSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const DateSummary = () => {
<Summary>
You added <a>Jenny Hess</a> to your <a>coworker</a> group.

<Date date='3 days ago' />
<Date children='3 days ago' />
</Summary>
</Content>
</Event>
Expand Down
1 change: 1 addition & 0 deletions src/lib/META.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'lodash/fp'

export const TYPES = {
ADDON: 'addon',
PART: 'part',
COLLECTION: 'collection',
ELEMENT: 'element',
VIEW: 'view',
Expand Down
43 changes: 26 additions & 17 deletions src/modules/Accordion/AccordionContent.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
import React, { PropTypes } from 'react'
import cx from 'classnames'

import { ContentPart } from '../../parts'
import { getElementType, getUnhandledProps, META, useKeyOnly } from '../../lib'

// ========================================================
// Brainstorming ways to abstract className buildup, etc.
//
// const AccordionContent = createContentPart({
// cx: ({ active }) => [
// useKeyOnly(active, 'active'),
// ],
// propTypes: {
// /** Whether or not the content is visible. */
// active: PropTypes.bool,
// },
// _meta: {
// name: 'AccordionContent',
// type: META.TYPES.MODULE,
// parent: 'Accordion',
// },
// })
// --------------------------------------------------------

function AccordionContent(props) {
const { active, children, className } = props
const classes = cx(
'content',
useKeyOnly(active, 'active'),
className
)

const rest = getUnhandledProps(AccordionContent, props)
const ElementType = getElementType(AccordionContent, props)

return (
<ElementType {...rest} className={classes}>
<ContentPart as={ElementType} {...rest} className={classes}>
{children}
</ElementType>
</ContentPart>
)
}

AccordionContent.displayName = 'AccordionContent'

AccordionContent.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
]),

...ContentPart.propTypes,
/** Whether or not the content is visible. */
active: PropTypes.bool,

/** Primary content of the Content. */
children: PropTypes.node,

/** Classes to add to the content className. */
className: PropTypes.string,
}

AccordionContent._meta = {
...ContentPart._meta,
name: 'AccordionContent',
type: META.TYPES.MODULE,
parent: 'Accordion',
Expand Down
20 changes: 14 additions & 6 deletions src/modules/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import _ from 'lodash'
import React, { PropTypes, Component } from 'react'
import cx from 'classnames'

import ModalHeader from './ModalHeader'
import {
ActionsPart,
DescriptionPart,
HeaderPart,
} from '../../parts'
// import ModalHeader from './ModalHeader'
import ModalContent from './ModalContent'
import ModalActions from './ModalActions'
import ModalDescription from './ModalDescription'
// import ModalActions from './ModalActions'
// import ModalDescription from './ModalDescription'
import Portal from 'react-portal'

import {
Expand Down Expand Up @@ -78,10 +83,13 @@ class Modal extends Component {
}

static _meta = _meta
static Header = ModalHeader
// static Header = ModalHeader
static Header = HeaderPart
static Content = ModalContent
static Description = ModalDescription
static Actions = ModalActions
// static Description = ModalDescription
static Description = DescriptionPart
// static Actions = ModalActions
static Actions = ActionsPart

state = {}

Expand Down
88 changes: 44 additions & 44 deletions src/modules/Modal/ModalActions.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import React, { PropTypes } from 'react'
import classNames from 'classnames'

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

function ModalActions(props) {
const { children, className } = props

const classes = classNames(
className,
'actions'
)

const rest = getUnhandledProps(ModalActions, props)
const ElementType = getElementType(ModalActions, props)

return (
<ElementType className={classes} {...rest}>
{children}
</ElementType>
)
}

ModalActions._meta = {
name: 'ModalActions',
type: META.TYPES.MODULE,
parent: 'Modal',
}

ModalActions.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
]),

/** Primary content of the modal actions */
children: PropTypes.any,

/** Classes to add to the modal actions className */
className: PropTypes.string,
}

export default ModalActions
// import React, { PropTypes } from 'react'
// import classNames from 'classnames'
//
// import { getElementType, getUnhandledProps, META } from '../../lib'
//
// function ModalActions(props) {
// const { children, className } = props
//
// const classes = classNames(
// className,
// 'actions'
// )
//
// const rest = getUnhandledProps(ModalActions, props)
// const ElementType = getElementType(ModalActions, props)
//
// return (
// <ElementType className={classes} {...rest}>
// {children}
// </ElementType>
// )
// }
//
// ModalActions._meta = {
// name: 'ModalActions',
// type: META.TYPES.MODULE,
// parent: 'Modal',
// }
//
// ModalActions.propTypes = {
// /** An element type to render as (string or function). */
// as: PropTypes.oneOfType([
// PropTypes.string,
// PropTypes.func,
// ]),
//
// /** Primary content of the modal actions */
// children: PropTypes.any,
//
// /** Classes to add to the modal actions className */
// className: PropTypes.string,
// }
//
// export default ModalActions
86 changes: 43 additions & 43 deletions src/modules/Modal/ModalDescription.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import React, { PropTypes } from 'react'
import cx from 'classnames'

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

function ModalDescription(props) {
const { children, className } = props

const classes = cx(
className,
'description'
)

const rest = getUnhandledProps(ModalDescription, props)
const ElementType = getElementType(ModalDescription, props)
return (
<ElementType className={classes} {...rest}>
{children}
</ElementType>
)
}

ModalDescription._meta = {
name: 'ModalDescription',
type: META.TYPES.MODULE,
parent: 'Modal',
}

ModalDescription.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
]),

/** Primary content */
children: PropTypes.any,

/** Classes to add to the className */
className: PropTypes.string,
}

export default ModalDescription
// import React, { PropTypes } from 'react'
// import cx from 'classnames'
//
// import { getElementType, getUnhandledProps, META } from '../../lib'
//
// function ModalDescription(props) {
// const { children, className } = props
//
// const classes = cx(
// className,
// 'description'
// )
//
// const rest = getUnhandledProps(ModalDescription, props)
// const ElementType = getElementType(ModalDescription, props)
// return (
// <ElementType className={classes} {...rest}>
// {children}
// </ElementType>
// )
// }
//
// ModalDescription._meta = {
// name: 'ModalDescription',
// type: META.TYPES.MODULE,
// parent: 'Modal',
// }
//
// ModalDescription.propTypes = {
// /** An element type to render as (string or function). */
// as: PropTypes.oneOfType([
// PropTypes.string,
// PropTypes.func,
// ]),
//
// /** Primary content */
// children: PropTypes.any,
//
// /** Classes to add to the className */
// className: PropTypes.string,
// }
//
// export default ModalDescription
88 changes: 44 additions & 44 deletions src/modules/Modal/ModalHeader.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import React, { PropTypes } from 'react'
import classNames from 'classnames'

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

function ModalHeader(props) {
const { children, className } = props

const classes = classNames(
className,
'header'
)

const rest = getUnhandledProps(ModalHeader, props)
const ElementType = getElementType(ModalHeader, props)

return (
<ElementType className={classes} {...rest}>
{children}
</ElementType>
)
}

ModalHeader._meta = {
name: 'ModalHeader',
type: META.TYPES.MODULE,
parent: 'Modal',
}

ModalHeader.propTypes = {
/** An element type to render as (string or function). */
as: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
]),

/** Primary content of the modal header */
children: PropTypes.any,

/** Classes to add to the modal header className */
className: PropTypes.string,
}

export default ModalHeader
// import React, { PropTypes } from 'react'
// import classNames from 'classnames'
//
// import { getElementType, getUnhandledProps, META } from '../../lib'
//
// function ModalHeader(props) {
// const { children, className } = props
//
// const classes = classNames(
// className,
// 'header'
// )
//
// const rest = getUnhandledProps(ModalHeader, props)
// const ElementType = getElementType(ModalHeader, props)
//
// return (
// <ElementType className={classes} {...rest}>
// {children}
// </ElementType>
// )
// }
//
// ModalHeader._meta = {
// name: 'ModalHeader',
// type: META.TYPES.MODULE,
// parent: 'Modal',
// }
//
// ModalHeader.propTypes = {
// /** An element type to render as (string or function). */
// as: PropTypes.oneOfType([
// PropTypes.string,
// PropTypes.func,
// ]),
//
// /** Primary content of the modal header */
// children: PropTypes.any,
//
// /** Classes to add to the modal header className */
// className: PropTypes.string,
// }
//
// export default ModalHeader
Loading