auto generate classes using scss magic, some restyling and refactoring'
This commit is contained in:
@@ -66,10 +66,8 @@ export default function CourseCatalogMain({ support }: Props) {
|
|||||||
return (
|
return (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={row.course.uniqueId}
|
key={row.course.uniqueId}
|
||||||
element={row.element}
|
row={row}
|
||||||
course={row.course}
|
|
||||||
isSelected={row.course.uniqueId === selectedCourse?.uniqueId}
|
isSelected={row.course.uniqueId === selectedCourse?.uniqueId}
|
||||||
support={support}
|
|
||||||
onClick={handleRowButtonClick(row.course)}
|
onClick={handleRowButtonClick(row.course)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -16,123 +16,57 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
&:active {
|
|
||||||
animation: ripple 1s ease-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
$primary: $burnt_orange;
|
|
||||||
$secondary: $charcoal;
|
|
||||||
$tertiary: $bluebonnet;
|
|
||||||
$danger: $speedway_brick;
|
|
||||||
$warning: $tangerine;
|
|
||||||
$success: $turtle_pond;
|
|
||||||
$info: $turquoise;
|
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.primary {
|
&.disabled {
|
||||||
background-color: $primary;
|
cursor: not-allowed !important;
|
||||||
color: #fff;
|
opacity: 0.5 !important;
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: lighten($primary, 10%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:active,
|
|
||||||
&:active {
|
&:active {
|
||||||
background-color: darken($primary, 10%);
|
animation: none !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.secondary {
|
|
||||||
background-color: $secondary;
|
|
||||||
color: #fff;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: lighten($secondary, 10%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:active,
|
|
||||||
&:active {
|
&:active {
|
||||||
background-color: darken($secondary, 10%);
|
animation: click_animation 0.5s ease-in-out;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.tertiary {
|
@each $color,
|
||||||
background-color: $tertiary;
|
$value
|
||||||
|
in (
|
||||||
|
primary: $burnt_orange,
|
||||||
|
secondary: $charcoal,
|
||||||
|
tertiary: $bluebonnet,
|
||||||
|
danger: $speedway_brick,
|
||||||
|
warning: $tangerine,
|
||||||
|
success: $turtle_pond,
|
||||||
|
info: $turquoise
|
||||||
|
)
|
||||||
|
{
|
||||||
|
&.#{$color} {
|
||||||
|
background-color: $value;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: lighten($tertiary, 10%);
|
background-color: lighten($value, 10%);
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus,
|
&:focus,
|
||||||
&:active {
|
&:active {
|
||||||
background-color: darken($tertiary, 10%);
|
background-color: darken($value, 10%);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.danger {
|
&.disabled {
|
||||||
background-color: $danger;
|
background-color: $value !important;
|
||||||
color: #fff;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: lighten($danger, 10%);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus,
|
|
||||||
&:active {
|
|
||||||
background-color: darken($danger, 10%);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.warning {
|
|
||||||
background-color: $warning;
|
|
||||||
color: #fff;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: lighten($warning, 10%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:focus,
|
|
||||||
&:active {
|
|
||||||
background-color: darken($warning, 10%);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.success {
|
|
||||||
background-color: $success;
|
|
||||||
color: #fff;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: lighten($success, 10%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:focus,
|
|
||||||
&:active {
|
|
||||||
background-color: darken($success, 10%);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.info {
|
|
||||||
background-color: $info;
|
|
||||||
color: #fff;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: lighten($info, 10%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:focus,
|
|
||||||
&:active {
|
|
||||||
background-color: darken($info, 10%);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes ripple {
|
@keyframes click_animation {
|
||||||
0% {
|
0% {
|
||||||
transform: scale(1);
|
transform: scale(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ interface Props {
|
|||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
type?: 'primary' | 'secondary' | 'tertiary' | 'danger' | 'warning' | 'success' | 'info';
|
type?: 'primary' | 'secondary' | 'tertiary' | 'danger' | 'warning' | 'success' | 'info';
|
||||||
|
disabled?: boolean;
|
||||||
testId?: string;
|
testId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,14 +21,17 @@ export function Button({
|
|||||||
type,
|
type,
|
||||||
testId,
|
testId,
|
||||||
children,
|
children,
|
||||||
|
disabled,
|
||||||
onClick,
|
onClick,
|
||||||
}: React.PropsWithChildren<Props>): JSX.Element {
|
}: React.PropsWithChildren<Props>): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
style={style}
|
style={style}
|
||||||
data-testId={testId}
|
data-testId={testId}
|
||||||
className={classNames(styles.button, className, styles[type ?? 'primary'])}
|
className={classNames(styles.button, className, styles[type ?? 'primary'], {
|
||||||
onClick={onClick}
|
[styles.disabled]: disabled,
|
||||||
|
})}
|
||||||
|
onClick={disabled ? undefined : onClick}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
@import 'src/views/styles/base.module.scss';
|
@import 'src/views/styles/base.module.scss';
|
||||||
|
|
||||||
.selectedRow {
|
.selectedRow {
|
||||||
td {
|
* {
|
||||||
background: green !important;
|
background: $burnt_orange !important;
|
||||||
color: white !important;
|
color: white !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { Course, ScrapedRow } from 'src/shared/types/Course';
|
import { Course, ScrapedRow } from 'src/shared/types/Course';
|
||||||
import { SiteSupport } from 'src/views/lib/getSiteSupport';
|
import {} from 'src/views/lib/getSiteSupport';
|
||||||
import { Button } from '../../common/Button/Button';
|
import { Button } from '../../common/Button/Button';
|
||||||
import Icon from '../../common/Icon/Icon';
|
import Icon from '../../common/Icon/Icon';
|
||||||
import styles from './TableRow.module.scss';
|
import styles from './TableRow.module.scss';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
support: SiteSupport;
|
|
||||||
isSelected: boolean;
|
isSelected: boolean;
|
||||||
course: Course;
|
row: ScrapedRow;
|
||||||
element: HTMLTableRowElement;
|
|
||||||
onClick: (...args: any[]) => any;
|
onClick: (...args: any[]) => any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,19 +16,25 @@ interface Props {
|
|||||||
* This component is injected into each row of the course catalog table.
|
* This component is injected into each row of the course catalog table.
|
||||||
* @returns a react portal to the new td in the column or null if the column has not been created yet.
|
* @returns a react portal to the new td in the column or null if the column has not been created yet.
|
||||||
*/
|
*/
|
||||||
export default function TableRow({ support, course, element, isSelected, onClick }: Props): JSX.Element | null {
|
export default function TableRow({ row, isSelected, onClick }: Props): JSX.Element | null {
|
||||||
const [container, setContainer] = useState<HTMLTableCellElement | null>(null);
|
const [container, setContainer] = useState<HTMLTableCellElement | null>(null);
|
||||||
|
|
||||||
|
const { element, course } = row;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const portalContainer = document.createElement('td');
|
const portalContainer = document.createElement('td');
|
||||||
const lastTableCell = element.querySelector('td:last-child');
|
const lastTableCell = element.querySelector('td:last-child');
|
||||||
lastTableCell!.after(portalContainer);
|
lastTableCell!.after(portalContainer);
|
||||||
setContainer(portalContainer);
|
setContainer(portalContainer);
|
||||||
}, []);
|
|
||||||
|
return () => {
|
||||||
|
portalContainer.remove();
|
||||||
|
};
|
||||||
|
}, [element]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
element.classList[isSelected ? 'add' : 'remove'](styles.selectedRow);
|
element.classList[isSelected ? 'add' : 'remove'](styles.selectedRow);
|
||||||
}, [course, isSelected, element.classList]);
|
}, [isSelected, element.classList]);
|
||||||
|
|
||||||
if (!container) {
|
if (!container) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user