2020-10-02 15:10:00 +00:00
|
|
|
import {IExampleInfo} from 'app/client/ui/ExampleInfo';
|
|
|
|
import {prepareForTransition, TransitionWatcher} from 'app/client/ui/transitions';
|
2021-02-28 05:27:34 +00:00
|
|
|
import {colors, mediaXSmall, testId, vars} from 'app/client/ui2018/cssVars';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
|
|
|
import {cssLink} from 'app/client/ui2018/links';
|
2021-07-27 16:03:35 +00:00
|
|
|
import {dom, styled} from 'grainjs';
|
|
|
|
import {AutomaticHelpToolInfo} from "app/client/ui/Tools";
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2020-11-10 02:36:03 +00:00
|
|
|
let prevCardClose: (() => void)|null = null;
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// Open a popup with a card introducing this example, if the user hasn't dismissed it in the past.
|
|
|
|
export function showExampleCard(
|
2021-07-27 16:03:35 +00:00
|
|
|
example: IExampleInfo, toolInfo: AutomaticHelpToolInfo
|
2020-10-02 15:10:00 +00:00
|
|
|
) {
|
2021-07-27 16:03:35 +00:00
|
|
|
const {elem: btnElem, markAsSeen, reopen} = toolInfo;
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Close the example card.
|
|
|
|
function close() {
|
2020-11-10 02:36:03 +00:00
|
|
|
prevCardClose = null;
|
2020-10-02 15:10:00 +00:00
|
|
|
collapseAndRemoveCard(cardElem, btnElem.getBoundingClientRect());
|
2021-07-27 16:03:35 +00:00
|
|
|
markAsSeen();
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const card = example.welcomeCard;
|
|
|
|
if (!card) { return null; }
|
|
|
|
const cardElem = cssCard(
|
|
|
|
cssImage({src: example.imgUrl}),
|
|
|
|
cssBody(
|
|
|
|
cssTitle(card.title),
|
|
|
|
cssInfo(card.text),
|
|
|
|
cssButtons(
|
|
|
|
cssLinkBtn(cssLinkIcon('Page'), card.tutorialName,
|
|
|
|
{href: example.tutorialUrl, target: '_blank'},
|
|
|
|
),
|
|
|
|
// TODO: Add a link to the overview video (as popup or to a support page that shows the
|
|
|
|
// video). Also include a 'Video' icon.
|
|
|
|
// cssLinkBtn(cssLinkIcon('Video'), 'Grist Video Tour'),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
cssCloseButton(cssBigIcon('CrossBig'),
|
|
|
|
dom.on('click', close),
|
|
|
|
testId('example-card-close'),
|
|
|
|
),
|
|
|
|
testId('example-card'),
|
|
|
|
);
|
|
|
|
document.body.appendChild(cardElem);
|
|
|
|
|
|
|
|
// When reopening, open the card smoothly, for a nicer-looking effect.
|
|
|
|
if (reopen) {
|
|
|
|
expandCard(cardElem, btnElem.getBoundingClientRect());
|
|
|
|
}
|
2020-11-10 02:36:03 +00:00
|
|
|
|
|
|
|
prevCardClose?.();
|
|
|
|
prevCardClose = () => disposeCard(cardElem);
|
|
|
|
}
|
|
|
|
|
|
|
|
function disposeCard(cardElem: HTMLElement) {
|
|
|
|
dom.domDispose(cardElem);
|
|
|
|
cardElem.remove();
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// When closing the card, collapse it visually into the button that can open it again, to hint to
|
|
|
|
// the user where to find that button. Remove the card after the animation.
|
|
|
|
function collapseAndRemoveCard(card: HTMLElement, collapsedRect: DOMRect) {
|
|
|
|
const watcher = new TransitionWatcher(card);
|
2020-11-10 02:36:03 +00:00
|
|
|
watcher.onDispose(() => disposeCard(card));
|
2020-10-02 15:10:00 +00:00
|
|
|
collapseCard(card, collapsedRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implements the collapsing animation by simply setting a scale transform with a suitable origin.
|
|
|
|
function collapseCard(card: HTMLElement, collapsedRect: DOMRect) {
|
|
|
|
const rect = card.getBoundingClientRect();
|
|
|
|
const originX = (collapsedRect.left + collapsedRect.width / 2) - rect.left;
|
|
|
|
const originY = (collapsedRect.top + collapsedRect.height / 2) - rect.top;
|
|
|
|
Object.assign(card.style, {
|
|
|
|
transform: `scale(${collapsedRect.width / rect.width}, ${collapsedRect.height / rect.height})`,
|
|
|
|
transformOrigin: `${originX}px ${originY}px`,
|
|
|
|
opacity: '0',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// To expand the card visually, we reverse the process by collapsing it first with transitions
|
|
|
|
// disabled, then resetting properties to their defaults with transitions enabled again.
|
|
|
|
function expandCard(card: HTMLElement, collapsedRect: DOMRect) {
|
|
|
|
prepareForTransition(card, () => collapseCard(card, collapsedRect));
|
|
|
|
Object.assign(card.style, {
|
|
|
|
transform: '',
|
|
|
|
opacity: '',
|
|
|
|
visibility: 'visible',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const cssCard = styled('div', `
|
|
|
|
position: absolute;
|
|
|
|
left: 24px;
|
|
|
|
bottom: 24px;
|
|
|
|
margin-right: 24px;
|
|
|
|
max-width: 624px;
|
|
|
|
padding: 32px 56px 32px 32px;
|
|
|
|
background-color: white;
|
|
|
|
box-shadow: 0 2px 18px 0 rgba(31,37,50,0.31), 0 0 1px 0 rgba(76,86,103,0.24);
|
|
|
|
display: flex;
|
|
|
|
overflow: hidden;
|
|
|
|
transition-property: opacity, transform;
|
|
|
|
transition-duration: 0.5s;
|
|
|
|
transition-timing-func: ease-in;
|
2021-02-28 05:27:34 +00:00
|
|
|
--title-font-size: ${vars.headerControlFontSize};
|
|
|
|
|
|
|
|
@media ${mediaXSmall} {
|
|
|
|
& {
|
|
|
|
flex-direction: column;
|
|
|
|
padding: 32px;
|
|
|
|
--title-font-size: 18px;
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const cssImage = styled('img', `
|
|
|
|
flex: none;
|
|
|
|
width: 180px;
|
|
|
|
height: 140px;
|
2021-02-28 05:27:34 +00:00
|
|
|
margin: 0 16px 0 -8px;
|
|
|
|
@media ${mediaXSmall} {
|
|
|
|
& {
|
|
|
|
margin: auto;
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const cssBody = styled('div', `
|
|
|
|
min-width: 0px;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssTitle = styled('div', `
|
2021-02-28 05:27:34 +00:00
|
|
|
font-size: var(--title-font-size);
|
2020-10-02 15:10:00 +00:00
|
|
|
font-weight: ${vars.headerControlTextWeight};
|
|
|
|
margin-bottom: 16px;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssInfo = styled('div', `
|
|
|
|
margin: 16px 0 24px 0;
|
|
|
|
line-height: 1.6;
|
|
|
|
`);
|
|
|
|
|
2021-07-28 18:20:14 +00:00
|
|
|
export const cssButtons = styled('div', `
|
2020-10-02 15:10:00 +00:00
|
|
|
display: flex;
|
|
|
|
`);
|
|
|
|
|
2021-07-28 18:20:14 +00:00
|
|
|
export const cssLinkBtn = styled(cssLink, `
|
2020-10-02 15:10:00 +00:00
|
|
|
&:not(:last-child) {
|
|
|
|
margin-right: 32px;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
2021-07-28 18:20:14 +00:00
|
|
|
export const cssLinkIcon = styled(icon, `
|
2020-10-02 15:10:00 +00:00
|
|
|
margin-right: 8px;
|
|
|
|
margin-top: -2px;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssCloseButton = styled('div', `
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
right: 8px;
|
|
|
|
padding: 4px;
|
|
|
|
border-radius: 4px;
|
|
|
|
cursor: pointer;
|
|
|
|
--icon-color: ${colors.slate};
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background-color: ${colors.mediumGreyOpaque};
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssBigIcon = styled(icon, `
|
|
|
|
padding: 12px;
|
|
|
|
`);
|