-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #36872 - Banner to show foreman instance
- Loading branch information
Showing
11 changed files
with
132 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,7 @@ | |
"nonpersistent", | ||
"noopener", | ||
"noreferrer", | ||
"nowrap", | ||
"num", | ||
"numpad", | ||
"operatingsystem", | ||
|
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
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
69 changes: 69 additions & 0 deletions
69
webpack/assets/javascripts/react_app/components/Layout/components/InstanceBanner.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,69 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Banner } from '@patternfly/react-core'; | ||
|
||
const getContrastColor = backgroundColor => { | ||
const hexToRgb = hex => { | ||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); | ||
return result | ||
? { | ||
r: parseInt(result[1], 16), | ||
g: parseInt(result[2], 16), | ||
b: parseInt(result[3], 16), | ||
} | ||
: null; | ||
}; | ||
backgroundColor = hexToRgb(backgroundColor); | ||
// Calculate the relative luminance of the background color | ||
const luminance = | ||
(0.2126 * backgroundColor.r + | ||
0.7152 * backgroundColor.g + | ||
0.0722 * backgroundColor.b) / | ||
255; | ||
|
||
// Choose black or white text based on the relative luminance | ||
return luminance > 0.5 ? 'black' : 'white'; | ||
}; | ||
const validateHexColor = instanceColor => { | ||
// Check if the string is a valid hex color code | ||
if (/^#([0-9A-Fa-f]{3}){1,2}$/.test(instanceColor)) { | ||
return instanceColor; | ||
} | ||
return '#000000'; | ||
}; | ||
|
||
export const InstanceBanner = ({ data }) => { | ||
if (!data || !data.instance_title) { | ||
return null; | ||
} | ||
const instance = data.instance_title; | ||
const instanceColor = validateHexColor(data.instance_color); | ||
return ( | ||
instance && ( | ||
<Banner | ||
isSticky | ||
style={{ '--pf-c-banner--BackgroundColor': instanceColor }} | ||
className="instance-banner" | ||
> | ||
<div | ||
style={{ | ||
color: getContrastColor(instanceColor), | ||
}} | ||
> | ||
{instance} | ||
</div> | ||
</Banner> | ||
) | ||
); | ||
}; | ||
|
||
InstanceBanner.propTypes = { | ||
data: PropTypes.shape({ | ||
instance_title: PropTypes.string, | ||
instance_color: PropTypes.string, | ||
}), | ||
}; | ||
|
||
InstanceBanner.defaultProps = { | ||
data: {}, | ||
}; |
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
29 changes: 0 additions & 29 deletions
29
.../assets/javascripts/react_app/components/Layout/components/Toolbar/InstanceTitleViewer.js
This file was deleted.
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