-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(Modal): Create a Modal using shorthand props #1508
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1c75f66
implement modal shorthand functionality
josie11 517cc88
remove and refactor a few lines
josie11 2f1ff84
delete redundant line
josie11 753bfa2
Merge branch 'master' into modal
josie11 3b1f6a7
Make requested changes to PR
josie11 38145d4
Remove import of Button in Modal
josie11 f99337d
add lodash import to modal actions file
josie11 2366f96
add implementsCreateShortMethod to Modal Actions tests, add default p…
josie11 394ab3f
Make requested changes to PR
josie11 1bb7927
add example to modal examples
josie11 bf7a411
fix linting error
josie11 48ee38b
make request chages to PR
josie11 bad477d
Merge remote-tracking branch 'origin' into modal
josie11 e2f8e30
add tests to Modal for shorthand props
josie11 512fb7e
minor adjustment to tests
josie11 d3a9dc3
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
cb58917
wip(ModalActions): update event handling
75a0a5a
Add missing ! to isNil
josie11 f7e59c8
tests(mixed): update tests
layershifter 76bfa3a
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
layershifter 09db74c
fix(ModalAction): add Component to imports
layershifter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
docs/app/Examples/modules/Modal/Types/ModalExampleShorthand.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
import { Button, Modal } from 'semantic-ui-react' | ||
|
||
const ModalShorthandExample = () => ( | ||
<Modal | ||
trigger={<Button>Show Modal</Button>} | ||
header='Delete Your Account' | ||
content='Are you sure you want to delete your account' | ||
actions={[ | ||
{ key: 'no', content: 'No', color: 'red', triggerClose: true }, | ||
{ key: 'yes', content: 'Yes', color: 'green', triggerClose: true }, | ||
]} | ||
/> | ||
) | ||
|
||
export default ModalShorthandExample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
import * as React from 'react'; | ||
import { ButtonProps } from '../../elements/Button'; | ||
|
||
export interface ModalActionsProps { | ||
[key: string]: any; | ||
|
||
/** An element type to render as (string or function). */ | ||
as?: any; | ||
|
||
/** An element type to render as (string or function). */ | ||
actions?: Array<any>; | ||
|
||
/** Primary content. */ | ||
children?: React.ReactNode; | ||
|
||
/** Additional classes. */ | ||
className?: string; | ||
|
||
/** | ||
* onClick handler for an action. Mutually exclusive with children. | ||
* | ||
* @param {SyntheticEvent} event - React's original SyntheticEvent. | ||
* @param {object} data - All item props. | ||
*/ | ||
onItemClick?: (event: React.MouseEvent<HTMLAnchorElement>, data: ButtonProps) => void; | ||
} | ||
|
||
declare const ModalActions: React.StatelessComponent<ModalActionsProps>; | ||
declare const ModalActions: React.ComponentClass<ModalActionsProps>; | ||
|
||
export default ModalActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,76 @@ | ||
import cx from 'classnames' | ||
import _ from 'lodash' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import React, { Component } from 'react' | ||
|
||
import { | ||
createShorthandFactory, | ||
customPropTypes, | ||
getElementType, | ||
getUnhandledProps, | ||
META, | ||
} from '../../lib' | ||
import Button from '../../elements/Button' | ||
|
||
/** | ||
* A modal can contain a row of actions. | ||
*/ | ||
function ModalActions(props) { | ||
const { children, className } = props | ||
const classes = cx('actions', className) | ||
const rest = getUnhandledProps(ModalActions, props) | ||
const ElementType = getElementType(ModalActions, props) | ||
export default class ModalActions extends Component { | ||
static propTypes = { | ||
/** An element type to render as (string or function). */ | ||
as: customPropTypes.as, | ||
|
||
return <ElementType {...rest} className={classes}>{children}</ElementType> | ||
} | ||
/** Elements to render as Modal action buttons. */ | ||
actions: customPropTypes.every([ | ||
customPropTypes.disallow(['children']), | ||
PropTypes.arrayOf(customPropTypes.itemShorthand), | ||
]), | ||
|
||
ModalActions._meta = { | ||
name: 'ModalActions', | ||
type: META.TYPES.MODULE, | ||
parent: 'Modal', | ||
} | ||
/** Primary content. */ | ||
children: PropTypes.node, | ||
|
||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
|
||
/** | ||
* onClick handler for an action. Mutually exclusive with children. | ||
* | ||
* @param {SyntheticEvent} event - React's original SyntheticEvent. | ||
* @param {object} data - All item props. | ||
*/ | ||
onActionClick: customPropTypes.every([ | ||
customPropTypes.disallow(['children']), | ||
PropTypes.func, | ||
]), | ||
} | ||
|
||
static _meta = { | ||
name: 'ModalActions', | ||
type: META.TYPES.MODULE, | ||
parent: 'Modal', | ||
} | ||
|
||
handleButtonOverrides = predefinedProps => ({ | ||
onClick: (e, buttonProps) => { | ||
_.invoke(predefinedProps, 'onClick', e, buttonProps) | ||
_.invoke(this.props, 'onActionClick', e, buttonProps) | ||
}, | ||
}) | ||
|
||
ModalActions.propTypes = { | ||
/** An element type to render as (string or function). */ | ||
as: customPropTypes.as, | ||
render() { | ||
const { actions, children, className } = this.props | ||
const classes = cx('actions', className) | ||
const rest = getUnhandledProps(ModalActions, this.props) | ||
const ElementType = getElementType(ModalActions, this.props) | ||
|
||
/** Primary content. */ | ||
children: PropTypes.node, | ||
if (!_.isNil(children)) return <ElementType {...rest} className={classes}>{children}</ElementType> | ||
|
||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
return ( | ||
<ElementType {...rest} className={classes}> | ||
{_.map(actions, action => Button.create(action, { overrideProps: this.handleButtonOverrides }))} | ||
</ElementType> | ||
) | ||
} | ||
} | ||
|
||
export default ModalActions | ||
ModalActions.create = createShorthandFactory(ModalActions, actions => ({ actions })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we update propTypes, we should also update the typings in the same directory. Example,
Modal.d.ts
.