-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Masthead): React masthead alternate logo and tooltip options (#4401
) ### Related Ticket(s) #3906 ### Description The masthead now accepts an optional logo options from IBM.com translation files which allows the setting of an alternate IBM logo to use, as well as an optional tooltip when the icon is hovered over. When an alternate logo is used, settings include an expiration date and allow/deny lists for controlling paths on which it can be displayed. The tooltip can be used with both default and alternate logos. ### Changelog **New** - `MastheadLogo` service to determine whether an alternate logo can be used based on values passed in the object - React `Masthead` component now accepts options from IBM.com translations for an alternate logo and tooltip - internal `ConditionalWrapper` component **Changed** - add masthead logo svg dimension styles <!-- React and Web Component deploy previews are enabled by default. --> <!-- To enable additional available deploy previews, apply the following --> <!-- labels for the corresponding package: --> <!-- *** "package: services": Services --> <!-- *** "package: utilities": Utilities --> <!-- *** "package: styles": Carbon Expressive --> <!-- *** "RTL": React / Web Components (RTL) --> <!-- *** "feature flag": React / Web Components (experimental) -->
- Loading branch information
Showing
10 changed files
with
519 additions
and
243 deletions.
There are no files selected for viewing
546 changes: 312 additions & 234 deletions
546
packages/react/src/__tests__/__snapshots__/storyshots.test.js.snap
Large diffs are not rendered by default.
Oops, something went wrong.
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
53 changes: 53 additions & 0 deletions
53
packages/react/src/internal/components/ConditionalWrapper/ConditionalWrapper.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,53 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2020 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Conditional wrapper internal component | ||
* | ||
* @param {object} props React props object | ||
* @param {boolean} props.condition whether to use wrapper | ||
* @param {*} props.wrapper JSX components | ||
* @param {*} props.children element(s) | ||
* @returns {*} JSX element | ||
* | ||
* @example | ||
* import ConditionalWrapper from '../../internal/components/ConditionalWrapper/ConditionalWrapper'; | ||
* | ||
* const example = ({ link, copy }) => { | ||
* return ( | ||
* <ConditionalWrapper | ||
* condition={link} | ||
* wrapper={children => <a href={link}>{children}</a>} | ||
* > | ||
* <p>{children}</p> | ||
* </ConditionalWrapper> | ||
* ); | ||
* } | ||
*/ | ||
const ConditionalWrapper = ({ condition, wrapper, children }) => | ||
condition ? wrapper(children) : children; | ||
|
||
ConditionalWrapper.propTypes = { | ||
/** | ||
* Condition whether to use wrapper or not | ||
*/ | ||
condition: PropTypes.bool, | ||
|
||
/** | ||
* Wrapper element | ||
*/ | ||
wrapper: PropTypes.node, | ||
|
||
/** | ||
* Children elements | ||
*/ | ||
children: PropTypes.node, | ||
}; | ||
|
||
export default ConditionalWrapper; |
47 changes: 47 additions & 0 deletions
47
packages/services/src/services/MastheadLogo/MastheadLogo.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,47 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2020 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
class MastheadLogoAPI { | ||
/** | ||
* Determines whether to return custom or default IBM logo | ||
* | ||
* @returns {boolean} Use alternate logo or not | ||
* | ||
* @example | ||
* import { MastheadLogoAPI } from '@carbon/ibmdotcom-services'; | ||
* | ||
* const useAlternateLogo = MastheadLogoAPI.setMastheadLogo(logoData); | ||
*/ | ||
static setMastheadLogo(logoData) { | ||
if (logoData === undefined) return false; | ||
|
||
const currentTime = new Date().getTime(); | ||
const expireTime = logoData.expire | ||
? new Date(logoData.expire).getTime() | ||
: null; | ||
const isExpired = expireTime && currentTime > expireTime ? true : false; | ||
|
||
if ( | ||
logoData.svg === null || | ||
isExpired || | ||
(logoData.denylist && logoData.denylist.indexOf(location.pathname) !== -1) | ||
) { | ||
return false; | ||
} else if ( | ||
logoData.allowlist && | ||
(logoData.allowlist.length == 0 || | ||
logoData.allowlist.indexOf(location.pathname) !== -1) && | ||
logoData.svg | ||
) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
export default MastheadLogoAPI; |
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,8 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2020 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export { default as MastheadLogo } from './MastheadLogo'; |
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