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
generic component to highlight any part of the ui #7131
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
nemesis09:highlight-component
Dec 1, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
frontend/packages/console-app/src/components/tour/Spotlight.scss
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
frontend/packages/console-app/src/components/tour/Spotlight.tsx
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
frontend/packages/console-app/src/components/tour/TourStepComponent.tsx
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
4 changes: 1 addition & 3 deletions
4
frontend/packages/console-app/src/components/tour/__tests__/TourStepComponent.spec.tsx
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
56 changes: 56 additions & 0 deletions
56
frontend/packages/console-shared/src/components/spotlight/InteractiveSpotlight.tsx
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,56 @@ | ||
import * as React from 'react'; | ||
import { PopperOptions } from 'popper.js'; | ||
import { Popper } from '../popper'; | ||
import './spotlight.scss'; | ||
|
||
type InteractiveSpotlightProps = { | ||
element: Element; | ||
}; | ||
|
||
const isInViewport = (elementToCheck: Element) => { | ||
const rect = elementToCheck.getBoundingClientRect(); | ||
return ( | ||
rect.top >= 0 && | ||
rect.left >= 0 && | ||
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | ||
rect.right <= (window.innerWidth || document.documentElement.clientWidth) | ||
); | ||
}; | ||
|
||
const popperOptions: PopperOptions = { | ||
modifiers: { | ||
preventOverflow: { | ||
enabled: false, | ||
}, | ||
}, | ||
}; | ||
|
||
const InteractiveSpotlight: React.FC<InteractiveSpotlightProps> = ({ element }) => { | ||
const { height, width } = element.getBoundingClientRect(); | ||
const style: React.CSSProperties = { | ||
height, | ||
width, | ||
}; | ||
const [clicked, setClicked] = React.useState(false); | ||
|
||
React.useEffect(() => { | ||
if (!isInViewport(element)) { | ||
element.scrollIntoView(); | ||
} | ||
const handleClick = () => setClicked(true); | ||
document.addEventListener('click', handleClick); | ||
return () => { | ||
document.removeEventListener('click', handleClick); | ||
}; | ||
}, [element]); | ||
|
||
if (clicked) return null; | ||
|
||
return ( | ||
<Popper reference={element} placement="top-start" popperOptions={popperOptions}> | ||
<div className="ocs-spotlight ocs-spotlight__element-highlight-animate" style={style} /> | ||
</Popper> | ||
); | ||
}; | ||
|
||
export default InteractiveSpotlight; |
19 changes: 19 additions & 0 deletions
19
frontend/packages/console-shared/src/components/spotlight/Spotlight.tsx
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,19 @@ | ||
import * as React from 'react'; | ||
import InteractiveSpotlight from './InteractiveSpotlight'; | ||
import StaticSpotlight from './StaticSpotlight'; | ||
|
||
type SpotlightProps = { | ||
selector: string; | ||
interactive?: boolean; | ||
}; | ||
|
||
const Spotlight: React.FC<SpotlightProps> = ({ selector, interactive }) => { | ||
const element = React.useMemo(() => document.querySelector(selector), [selector]); | ||
return interactive ? ( | ||
<InteractiveSpotlight element={element} /> | ||
) : ( | ||
<StaticSpotlight element={element} /> | ||
); | ||
}; | ||
|
||
export default Spotlight; |
26 changes: 26 additions & 0 deletions
26
frontend/packages/console-shared/src/components/spotlight/StaticSpotlight.tsx
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,26 @@ | ||
import * as React from 'react'; | ||
import Portal from '../popper/Portal'; | ||
import './spotlight.scss'; | ||
|
||
type StaticSpotlightProps = { | ||
element: Element; | ||
}; | ||
|
||
const StaticSpotlight: React.FC<StaticSpotlightProps> = ({ element }) => { | ||
const { top, left, height, width } = element.getBoundingClientRect(); | ||
const style: React.CSSProperties = { | ||
top, | ||
left, | ||
height, | ||
width, | ||
}; | ||
return ( | ||
<Portal> | ||
<div className="pf-c-backdrop ocs-spotlight__with-backdrop"> | ||
<div className="ocs-spotlight ocs-spotlight__element-highlight-noanimate" style={style} /> | ||
</div> | ||
</Portal> | ||
); | ||
}; | ||
|
||
export default StaticSpotlight; |
28 changes: 28 additions & 0 deletions
28
frontend/packages/console-shared/src/components/spotlight/__tests__/Spotlight.spec.tsx
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,28 @@ | ||
import * as React from 'react'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import Spotlight from '../Spotlight'; | ||
import StaticSpotlight from '../StaticSpotlight'; | ||
import InteractiveSpotlight from '../InteractiveSpotlight'; | ||
|
||
describe('Spotlight', () => { | ||
type SpotlightProps = React.ComponentProps<typeof Spotlight>; | ||
let wrapper: ShallowWrapper<SpotlightProps>; | ||
const uiElementPos = { height: 100, width: 100, top: 100, left: 100 }; | ||
const uiElement = { getBoundingClientRect: jest.fn().mockReturnValue(uiElementPos) }; | ||
beforeEach(() => { | ||
jest.spyOn(document, 'querySelector').mockImplementation(() => uiElement); | ||
}); | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('should render StaticSpotlight if interactive is not set to true', () => { | ||
wrapper = shallow(<Spotlight selector="selector" />); | ||
expect(wrapper.find(StaticSpotlight).exists()).toBe(true); | ||
}); | ||
|
||
it('should render InteractiveSpotlight if interactive is set to true', () => { | ||
wrapper = shallow(<Spotlight selector="selector" interactive />); | ||
expect(wrapper.find(InteractiveSpotlight).exists()).toBe(true); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
frontend/packages/console-shared/src/components/spotlight/index.ts
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 @@ | ||
export { default as Spotlight } from './Spotlight'; |
63 changes: 63 additions & 0 deletions
63
frontend/packages/console-shared/src/components/spotlight/spotlight.scss
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,63 @@ | ||||||
@keyframes ocs-spotlight-expand { | ||||||
0% { | ||||||
outline-offset: -4px; | ||||||
outline-width: 4px; | ||||||
opacity: 1; | ||||||
} | ||||||
100% { | ||||||
outline-offset: 21px; | ||||||
outline-width: 12px; | ||||||
opacity: 0; | ||||||
} | ||||||
} | ||||||
|
||||||
@keyframes ocs-spotlight-fade-in { | ||||||
0% { | ||||||
opacity: 0; | ||||||
} | ||||||
100% { | ||||||
opacity: 1; | ||||||
} | ||||||
} | ||||||
|
||||||
@keyframes ocs-spotlight-fade-out { | ||||||
0% { | ||||||
opacity: 1; | ||||||
} | ||||||
100% { | ||||||
opacity: 0; | ||||||
} | ||||||
} | ||||||
|
||||||
.ocs-spotlight { | ||||||
pointer-events: none; | ||||||
position: absolute; | ||||||
&__with-backdrop { | ||||||
mix-blend-mode: hard-light; | ||||||
} | ||||||
&__element-highlight-noanimate { | ||||||
border: var(--pf-global--BorderWidth--xl) solid var(--pf-global--palette--blue-200); | ||||||
background-color: var(--pf-global--palette--black-500); | ||||||
z-index: 9999; | ||||||
} | ||||||
&__element-highlight-animate { | ||||||
pointer-events: none; | ||||||
position: absolute; | ||||||
Comment on lines
+44
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
box-shadow: inset 0px 0px 0px 4px var(--pf-global--palette--blue-200); | ||||||
opacity: 0; | ||||||
animation: 0.4s ocs-spotlight-fade-in 0s ease-in-out, 5s ocs-spotlight-fade-out 12.8s ease-in-out; | ||||||
animation-fill-mode: forwards; | ||||||
&::after { | ||||||
content: ''; | ||||||
position: absolute; | ||||||
left: 0; | ||||||
right: 0; | ||||||
top: 0; | ||||||
bottom: 0; | ||||||
animation: 1.2s ocs-spotlight-expand 1.6s ease-out; | ||||||
animation-fill-mode: forwards; | ||||||
outline: 4px solid var(--pf-global--palette--blue-200); | ||||||
outline-offset: -4px; | ||||||
} | ||||||
} | ||||||
} |
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.
I don't think this
position
is needed either since you're not specifying thetop
/left
esk attributes.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.
this is being used by guided tours as well which uses top/left.
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.
🤔 Pretty sure if you don't use
top
/left
of 0 it does wonky things... but okay. Let's leave it and worry about it if it's an issue.