-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AdaptiveCardsActionToggleVisibility): create Action.ToggleVisibi…
…lity component
- Loading branch information
1 parent
5d28902
commit ac551a2
Showing
21 changed files
with
731 additions
and
300 deletions.
There are no files selected for viewing
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
62 changes: 62 additions & 0 deletions
62
src/components/adaptive-cards/ActionToggleVisibility/ActionToggleVisibility.jsx
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,62 @@ | ||
import React, {useContext} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {acPropTypes, registerComponent} from '../Component/Component'; | ||
import webexComponentClasses from '../../helpers'; | ||
import Action from '../Action/Action'; | ||
import AdaptiveCardContext from '../context/adaptive-card-context'; | ||
|
||
/** | ||
* Adaptive Cards Action.ToggleVisibility component | ||
* https://adaptivecards.io/explorer/Action.ToggleVisibility.html | ||
* | ||
* @param {object} props React props passed to the component | ||
* @param {string} [props.className] Custom CSS class to apply | ||
* @param {object} props.data Active cards definition | ||
* @param {object} [props.style] Custom style to apply | ||
* @returns {object} JSX of the component | ||
*/ | ||
export default function ActionToggleVisibility({className, data, style}) { | ||
const [cssClasses] = webexComponentClasses('ac-action-toggle-visibility', className); | ||
const {getIsVisible, setIsVisible} = useContext(AdaptiveCardContext); | ||
|
||
const handleClick = () => { | ||
(data.targetElements || []).map((elem) => ( | ||
typeof elem === 'string' | ||
? setIsVisible(elem, !getIsVisible(elem)) | ||
: setIsVisible(elem.elementId, elem.isVisible))); | ||
}; | ||
|
||
return ( | ||
<Action data={data} className={cssClasses} onClick={handleClick} style={style} /> | ||
); | ||
} | ||
|
||
ActionToggleVisibility.propTypes = { | ||
className: PropTypes.string, | ||
data: PropTypes.shape().isRequired, | ||
style: PropTypes.shape(), | ||
}; | ||
|
||
ActionToggleVisibility.defaultProps = { | ||
className: undefined, | ||
style: undefined, | ||
}; | ||
|
||
ActionToggleVisibility.acPropTypes = { | ||
iconUrl: acPropTypes.iconUrl, | ||
id: acPropTypes.id, | ||
isEnabled: acPropTypes.isEnabled, | ||
mode: acPropTypes.mode, | ||
style: acPropTypes.actionStyle, | ||
title: acPropTypes.title, | ||
tooltip: acPropTypes.tooltip, | ||
targetElements: acPropTypes.targetElements, | ||
type: acPropTypes.type, | ||
url: acPropTypes.url, | ||
}; | ||
|
||
ActionToggleVisibility.acDefaultProps = { | ||
style: 'default', | ||
}; | ||
|
||
registerComponent('Action.ToggleVisibility', ActionToggleVisibility); |
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
Oops, something went wrong.