Files
UT-Registration-Plus/src/views/components/injected/TableHead.tsx
doprz 8a6e9070e0 chore: lint-format-docs-tests-bugfixes (#105)
* docs: add jsdoc

* feat: change enums to as const objects

* chore(test): add themeColors.test.ts

* fix: fix tests and bugs with strings.ts util

* fix: path alias imports and tsconfig file bug

* fix: remove --max-warnings 0
2024-03-06 15:11:27 -06:00

30 lines
1016 B
TypeScript

import type { PropsWithChildren } from 'react';
import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
/**
* This adds a new column to the course catalog table header.
* @returns a react portal to the new column or null if the column has not been created yet.
*/
export default function TableHead({ children }: PropsWithChildren) {
const [container, setContainer] = useState<HTMLTableCellElement | null>(null);
useEffect(() => {
const container = document.createElement('th');
container.setAttribute('scope', 'col');
container.setAttribute('id', 'ut-registration-plus-table-head');
const lastTableHeadCell = document.querySelector('table thead th:last-child');
lastTableHeadCell!.after(container);
setContainer(container);
return () => {
container.remove();
};
}, []);
if (!container) {
return null;
}
return ReactDOM.createPortal(<span>{children}</span>, container);
}