From c280e8a363b119af4100ecd74c8742bff96ffbec Mon Sep 17 00:00:00 2001 From: Tom <20648924+moT01@users.noreply.github.com> Date: Sun, 4 Sep 2022 06:15:54 -0500 Subject: [PATCH] feat: add preview popout window (#46251) * feat: add preview popout window * fix: remove unused * fix: add title to window * fix: add preview to window title * feat: it works * chore: clean up * chore: more clean up * fix: add better screen reader messages --- client/i18n/locales/english/translations.json | 6 ++ .../Challenges/classic/action-row.tsx | 51 ++++++++-- .../Challenges/classic/desktop-layout.tsx | 42 +++++--- .../src/templates/Challenges/classic/show.tsx | 6 +- .../Challenges/components/preview-portal.tsx | 97 +++++++++++++++++++ .../Challenges/redux/action-types.js | 2 + .../redux/execute-challenge-saga.js | 6 +- .../src/templates/Challenges/redux/index.js | 20 +++- 8 files changed, 206 insertions(+), 24 deletions(-) create mode 100644 client/src/templates/Challenges/components/preview-portal.tsx diff --git a/client/i18n/locales/english/translations.json b/client/i18n/locales/english/translations.json index d872b38e89c..9b4d3801515 100644 --- a/client/i18n/locales/english/translations.json +++ b/client/i18n/locales/english/translations.json @@ -488,6 +488,12 @@ "breadcrumb-nav": "breadcrumb", "submit": "Use Ctrl + Enter to submit.", "running-tests": "Running tests", + "hide-preview": "Hide the preview", + "move-preview-to-new-window": "Move the preview to a new window and focus it", + "move-preview-to-main-window": "Move the preview to this window and close the external preview window", + "close-external-preview-window": "Close the external preview window", + "show-preview": "Show the preview in this window", + "open-preview-in-new-window": "Open the preview in a new window and focus it", "step": "Step", "steps": "Steps", "steps-for": "Steps for {{blockTitle}}" diff --git a/client/src/templates/Challenges/classic/action-row.tsx b/client/src/templates/Challenges/classic/action-row.tsx index 3fedc739580..68a40bd2867 100644 --- a/client/src/templates/Challenges/classic/action-row.tsx +++ b/client/src/templates/Challenges/classic/action-row.tsx @@ -1,4 +1,6 @@ import React from 'react'; +import { faExternalLinkAlt } from '@fortawesome/free-solid-svg-icons'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { useTranslation } from 'react-i18next'; import BreadCrumb from '../components/bread-crumb'; @@ -11,7 +13,8 @@ interface ActionRowProps { showConsole: boolean; showNotes: boolean; showInstructions: boolean; - showPreview: boolean; + showPreviewPane: boolean; + showPreviewPortal: boolean; superBlock: string; togglePane: (pane: string) => void; } @@ -20,7 +23,8 @@ const ActionRow = ({ hasNotes, togglePane, showNotes, - showPreview, + showPreviewPane, + showPreviewPortal, showConsole, showInstructions, isProjectBasedChallenge, @@ -28,6 +32,29 @@ const ActionRow = ({ block }: ActionRowProps): JSX.Element => { const { t } = useTranslation(); + + // sets screen reader text for the two preview buttons + function getPreviewBtnsSrText() { + // no preview open + const previewBtnsSrText = { + pane: t('aria.show-preview'), + portal: t('aria.open-preview-in-new-window') + }; + + // preview open in main window + if (showPreviewPane && !showPreviewPortal) { + previewBtnsSrText.pane = t('aria.hide-preview'); + previewBtnsSrText.portal = t('aria.move-preview-to-new-window'); + + // preview open in external window + } else if (showPreviewPortal && !showPreviewPane) { + previewBtnsSrText.pane = t('aria.move-preview-to-main-window'); + previewBtnsSrText.portal = t('aria.close-external-preview-window'); + } + + return previewBtnsSrText; + } + return (