-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(annotations): tooltip * feat(annotations): tooltip * feat(annotations): tooltip * feat(annotations): tooltip * feat(annotations): tooltip * feat(annotations): tooltip * feat(annotations): tooltip
- Loading branch information
megansmith-box
authored
May 4, 2021
1 parent
528b065
commit d030fe3
Showing
23 changed files
with
280 additions
and
25 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
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,2 +1,4 @@ | ||
declare module 'box-ui-elements/es/components/preview'; | ||
declare module 'box-ui-elements/es/components/tooltip/Tooltip'; | ||
declare module 'box-ui-elements/es/features/targeting/hocs'; | ||
declare module 'box-ui-elements/es/styles/variables'; |
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 +1,2 @@ | ||
export * from './annotations'; | ||
export * from './targeting'; |
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,10 @@ | ||
export type Experiences = { | ||
[key: string]: TargetingApi; | ||
}; | ||
|
||
export type TargetingApi = { | ||
canShow: boolean; | ||
onClose: () => void; | ||
onComplete: () => void; | ||
onShow: () => void; | ||
}; |
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
14 changes: 14 additions & 0 deletions
14
src/lib/viewers/controls/annotations/AnnotationsTargetedTooltip.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,14 @@ | ||
.bp-AnnotationsTooltip { | ||
max-width: 408px; | ||
padding: 18px 0 12px 18px; | ||
} | ||
|
||
.bp-AnnotationsTooltip-title { | ||
font-weight: bold; | ||
font-size: 18px; | ||
} | ||
|
||
.bp-AnnotationsTooltip-body { | ||
font-size: 14px; | ||
line-height: 20px; | ||
} |
65 changes: 65 additions & 0 deletions
65
src/lib/viewers/controls/annotations/AnnotationsTargetedTooltip.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,65 @@ | ||
import React from 'react'; | ||
import TargetedClickThroughTooltip from '../tooltip'; | ||
import { ControlsLayerContext } from '../controls-layer'; | ||
import { ExperiencesContext } from '../experiences'; | ||
import { TargetingApi } from '../../../types'; | ||
import './AnnotationsTargetedTooltip.scss'; | ||
|
||
export type Props = React.PropsWithChildren<{ | ||
isEnabled?: boolean; | ||
}>; | ||
|
||
function AnnotationsTargetedTooltip({ children, isEnabled = false }: Props): JSX.Element | null { | ||
const { experiences } = React.useContext(ExperiencesContext); | ||
const { setIsForced } = React.useContext(ControlsLayerContext); | ||
const [wasClosedByUser, setWasClosedByUser] = React.useState(false); | ||
|
||
const shouldTarget = !!( | ||
isEnabled && | ||
experiences && | ||
experiences.tooltipFlowAnnotationsExperience && | ||
experiences.tooltipFlowAnnotationsExperience.canShow | ||
); | ||
|
||
if (!shouldTarget) { | ||
return <>{children}</>; | ||
} | ||
|
||
return ( | ||
<TargetedClickThroughTooltip | ||
className="bp-AnnotationsTooltip" | ||
shouldTarget | ||
showCloseButton | ||
text={ | ||
<div> | ||
<h3 className="bp-AnnotationsTooltip-title">{__('annotations_tooltip_title')}</h3> | ||
<p className="bp-AnnotationsTooltip-body">{__('annotations_tooltip_body')}</p> | ||
</div> | ||
} | ||
theme="callout" | ||
useTargetingApi={(): TargetingApi => { | ||
return { | ||
...experiences.tooltipFlowAnnotationsExperience, | ||
onClose: (): void => { | ||
experiences.tooltipFlowAnnotationsExperience.onClose(); | ||
setIsForced(false); | ||
}, | ||
onShow: (): void => { | ||
experiences.tooltipFlowAnnotationsExperience.onShow(); | ||
|
||
if (wasClosedByUser) { | ||
return; | ||
} | ||
|
||
setWasClosedByUser(true); | ||
setIsForced(true); | ||
}, | ||
}; | ||
}} | ||
> | ||
{children} | ||
</TargetedClickThroughTooltip> | ||
); | ||
} | ||
|
||
export default AnnotationsTargetedTooltip; |
48 changes: 48 additions & 0 deletions
48
src/lib/viewers/controls/annotations/__tests__/AnnotationsTargetedTooltip-test.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,48 @@ | ||
import React from 'react'; | ||
import { ReactWrapper, mount } from 'enzyme'; | ||
import AnnotationsTargetedTooltip from '../AnnotationsTargetedTooltip'; | ||
|
||
describe('AnnotationsTargetedTooltip', () => { | ||
const getWrapper = (props = {}): ReactWrapper => | ||
mount( | ||
<AnnotationsTargetedTooltip {...props}> | ||
<div>Child</div> | ||
</AnnotationsTargetedTooltip>, | ||
); | ||
|
||
describe('render', () => { | ||
beforeEach(() => { | ||
jest.spyOn(React, 'useContext').mockImplementation(() => ({ | ||
experiences: { | ||
tooltipFlowAnnotationsExperience: { | ||
canShow: true, | ||
onClose: jest.fn(), | ||
onComplete: jest.fn(), | ||
onShow: jest.fn(), | ||
}, | ||
}, | ||
setIsForced: jest.fn(), | ||
})); | ||
}); | ||
|
||
test('should return tooltip when is enabled', () => { | ||
const wrapper = getWrapper({ | ||
isEnabled: true, | ||
}); | ||
|
||
expect(wrapper.children().text()).not.toBe('Child'); | ||
expect(wrapper.children().prop('shouldTarget')).toBe(true); | ||
expect(wrapper.children().prop('theme')).toBe('callout'); | ||
expect(wrapper.children().prop('useTargetingApi')().canShow).toBe(true); | ||
}); | ||
|
||
test('should return children when tooltip is disabled', () => { | ||
const wrapper = getWrapper({ | ||
isEnabled: false, | ||
}); | ||
|
||
expect(wrapper.children().text()).toBe('Child'); | ||
expect(wrapper.children().prop('shouldTarget')).toBe(undefined); | ||
}); | ||
}); | ||
}); |
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
10 changes: 10 additions & 0 deletions
10
src/lib/viewers/controls/controls-layer/ControlsLayerContext.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,10 @@ | ||
import React from 'react'; | ||
import noop from 'lodash/noop'; | ||
|
||
export type Context = { | ||
setIsForced: (isForced: boolean) => void; | ||
}; | ||
|
||
export default React.createContext<Context>({ | ||
setIsForced: noop, | ||
}); |
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,2 +1,3 @@ | ||
export * from './ControlsLayer'; | ||
export { default } from './ControlsLayer'; | ||
export { default as ControlsLayerContext } from './ControlsLayerContext'; |
10 changes: 10 additions & 0 deletions
10
src/lib/viewers/controls/experiences/ExperiencesContext.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,10 @@ | ||
import React from 'react'; | ||
import { Experiences } from '../../../types'; | ||
|
||
export type Context = { | ||
experiences: Experiences; | ||
}; | ||
|
||
export default React.createContext<Context>({ | ||
experiences: {}, | ||
}); |
11 changes: 11 additions & 0 deletions
11
src/lib/viewers/controls/experiences/ExperiencesProvider.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,11 @@ | ||
import React from 'react'; | ||
import ExperiencesContext from './ExperiencesContext'; | ||
import { Experiences } from '../../../types'; | ||
|
||
export type Props = React.PropsWithChildren<{ | ||
experiences?: Experiences; | ||
}>; | ||
|
||
export default function ExperiencesProvider({ children, experiences = {} }: Props): JSX.Element { | ||
return <ExperiencesContext.Provider value={{ experiences }}>{children}</ExperiencesContext.Provider>; | ||
} |
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,3 @@ | ||
export * from './ExperiencesProvider'; | ||
export { default } from './ExperiencesProvider'; | ||
export { default as ExperiencesContext } from './ExperiencesContext'; |
11 changes: 11 additions & 0 deletions
11
src/lib/viewers/controls/tooltip/TargetedClickThroughTooltip.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,11 @@ | ||
import React from 'react'; | ||
import Tooltip from 'box-ui-elements/es/components/tooltip/Tooltip'; | ||
import { withTargetedClickThrough } from 'box-ui-elements/es/features/targeting/hocs'; | ||
|
||
const TargetedClickThroughTooltip = withTargetedClickThrough( | ||
({ children, ...props }: { children: React.ReactNode }): JSX.Element => { | ||
return <Tooltip {...props}>{children}</Tooltip>; | ||
}, | ||
); | ||
|
||
export default TargetedClickThroughTooltip; |
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,2 @@ | ||
export { default } from './TargetedClickThroughTooltip'; | ||
export * from './TargetedClickThroughTooltip'; |
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.