TypeScriptify more navigation_header files

test plan:
  - build passes

flag=none

Change-Id: I91245ac900c1a92151253d628f70fd9fe3d96a19
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/331294
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Martin Ochoa <martin.ochoa@instructure.com>
QA-Review: Aaron Shafovaloff <ashafovaloff@instructure.com>
Product-Review: Aaron Shafovaloff <ashafovaloff@instructure.com>
This commit is contained in:
Aaron Shafovaloff 2023-10-25 11:15:31 -06:00
parent 3c7c6ef48f
commit 1f8123141c
3 changed files with 27 additions and 15 deletions

View File

@ -61,7 +61,9 @@ ready(() => {
ReactDOM.render(
<Navigation
// @ts-expect-error
ref={DesktopNavComponent}
// @ts-expect-error
onDataReceived={() => mobileNavComponent.current?.forceUpdate()}
/>,
globalNavTrayContainer,
@ -70,6 +72,7 @@ ready(() => {
if (mobileContextNavContainer) {
ReactDOM.render(
<MobileNavigation
// @ts-expect-error
ref={mobileNavComponent}
DesktopNavComponent={DesktopNavComponent.current}
/>,
@ -81,12 +84,12 @@ ready(() => {
}
const newTabContainers = document.getElementsByClassName('new-tab-indicator')
if (newTabContainers) {
for (const newTabContainer of newTabContainers) {
Array.from(newTabContainers).forEach(newTabContainer => {
if (newTabContainer instanceof HTMLElement && newTabContainer.dataset.tabname) {
ReactDOM.render(
<NewTabIndicator tabName={newTabContainer.dataset.tabname} />,
newTabContainer
)
}
}
})
})

View File

@ -50,12 +50,19 @@ const checkboxThemeOverrides = {
focusOutlineColor: brand,
}
const HighContrastLabel = ({loading, isMobile}) => {
type HighContrastLabelProps = {
loading: boolean
isMobile: boolean
}
type TipTrigger = 'click' | 'hover' | 'focus'
const HighContrastLabel = ({loading, isMobile}: HighContrastLabelProps) => {
const labelText = isMobile ? I18n.t('Hi-contrast') : I18n.t('Use High Contrast UI')
const mobileTipText = I18n.t('Enhance color contrast of content')
const dekstopTipText = I18n.t('Enhances the color contrast of text, buttons, etc.')
const tipText = isMobile ? mobileTipText : dekstopTipText
const tipTriggers = ['click']
const tipTriggers: TipTrigger[] = ['click']
if (!isMobile) {
tipTriggers.push('hover')
@ -112,7 +119,11 @@ HighContrastLabel.propTypes = {
isMobile: bool.isRequired,
}
export default function HighContrastModeToggle({isMobile}) {
type HighContrastModeToggleProps = {
isMobile: boolean
}
export default function HighContrastModeToggle({isMobile}: HighContrastModeToggleProps) {
const originalSetting = useRef(ENV.use_high_contrast)
const [enabled, setEnabled] = useState(ENV.use_high_contrast)
const [loading, setLoading] = useState(false)
@ -139,10 +150,12 @@ export default function HighContrastModeToggle({isMobile}) {
setEnabled(json.state === 'on')
ENV.use_high_contrast = json.state === 'on'
} catch (err) {
showFlashAlert({
message: I18n.t('An error occurred while trying to change the UI'),
err,
})
if (err instanceof Error) {
showFlashAlert({
message: I18n.t('An error occurred while trying to change the UI'),
err,
})
}
} finally {
setLoading(false)
}
@ -170,10 +183,6 @@ export default function HighContrastModeToggle({isMobile}) {
)
}
HighContrastModeToggle.propTypes = {
isMobile: bool,
}
HighContrastModeToggle.defaultProps = {
isMobile: false,
}

View File

@ -99,7 +99,7 @@ const isLoadingChunkError = (a?: string): boolean => {
// more info about the error when pressed.
// Is displayed at the top of the document, and will close itself after a while
type FlashAlertProps = typeof FlashAlert.defaultProps & {
type FlashAlertProps = {
onClose: () => void
message: HTMLElement | string
error?: Error | null