diff --git a/.env b/.env index 3d6d6f7..0bcc887 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ REACT_APP_RADAR_NAME=AOE Technology Radar -PUBLIC_URL=/techradar \ No newline at end of file +PUBLIC_URL=/techradar diff --git a/dist_scripts/src/model.js b/dist_scripts/src/model.js index bb15587..615bc4d 100644 --- a/dist_scripts/src/model.js +++ b/dist_scripts/src/model.js @@ -16,15 +16,15 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) { return to; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getFirstLetter = exports.groupByFirstLetter = exports.groupByQuadrants = exports.unfeaturedOnly = exports.featuredOnly = void 0; +exports.getFirstLetter = exports.groupByFirstLetter = exports.groupByQuadrants = exports.nonFeaturedOnly = exports.featuredOnly = void 0; var featuredOnly = function (items) { return items.filter(function (item) { return item.featured; }); }; exports.featuredOnly = featuredOnly; -var unfeaturedOnly = function (items) { +var nonFeaturedOnly = function (items) { return items.filter(function (item) { return !item.featured; }); }; -exports.unfeaturedOnly = unfeaturedOnly; +exports.nonFeaturedOnly = nonFeaturedOnly; var groupByQuadrants = function (items) { return items.reduce(function (quadrants, item) { var _a; diff --git a/src/animation.ts b/src/animation.ts index 279235d..ede4f8d 100644 --- a/src/animation.ts +++ b/src/animation.ts @@ -1,110 +1,135 @@ -import React from 'react'; +import React from "react"; + +export interface AnimationConfig { + [k: string]: Animation | Animation[]; +} export type Animations = { - [k: string]: Animation[] -} + [k: string]: Animation[]; +}; export type AnimationStates = { - [k: string]: React.CSSProperties[] -} + [k: string]: React.CSSProperties[]; +}; -type Animation = { - stateA: React.CSSProperties - stateB: React.CSSProperties - delay: number - run?(callback: (state: any) => any): any // todo fix - prepare?(callback: (state: any) => any): any // todo fix -} +export type Animation = { + stateA: React.CSSProperties; + stateB: React.CSSProperties; + delay: number; + run?(callback: (state: any) => any): any; // todo fix + prepare?(callback: (state: any) => any): any; // todo fix +}; export type AnimationRunner = { - getState(): AnimationStates - run(): any - awaitAnimationComplete(callback: () => void): any -} + getState(): AnimationStates; + run(): any; + awaitAnimationComplete(callback: () => void): any; +}; -export const createAnimation = (stateA: React.CSSProperties, stateB: React.CSSProperties, delay: number): Animation => ({ - stateA, - stateB, - delay, +export const createAnimation = ( + stateA: React.CSSProperties, + stateB: React.CSSProperties, + delay: number +): Animation => ({ + stateA, + stateB, + delay, }); -const getAnimationStates = (animations: Animation[], stateName: 'stateA' | 'stateB' = 'stateA'): React.CSSProperties[] => { - return animations.map(animation => animation[stateName]); +const getAnimationStates = ( + animations: Animation[], + stateName: "stateA" | "stateB" = "stateA" +): React.CSSProperties[] => { + return animations.map((animation) => animation[stateName]); }; const getMaxTransitionTime = (transition: string) => { - const re = /(\d+)ms/g; - const times: number[] = []; - let matches; - while ((matches = re.exec(transition)) != null) { - times.push(parseInt(matches[1], 10)); - } - return Math.max(...times); + const re = /(\d+)ms/g; + const times: number[] = []; + let matches; + while ((matches = re.exec(transition)) != null) { + times.push(parseInt(matches[1], 10)); + } + return Math.max(...times); }; const getAnimationDuration = (animation: Animation | Animation[]): number => { - if (animation instanceof Array) { - return animation.reduce((maxDuration, a) => { - const duration = getAnimationDuration(a); - if (duration > maxDuration) { - return duration; - } - return maxDuration; - }, 0); - } + if (animation instanceof Array) { + return animation.reduce((maxDuration, a) => { + const duration = getAnimationDuration(a); + if (duration > maxDuration) { + return duration; + } + return maxDuration; + }, 0); + } - const state = animation.stateB; - const maxTransition = state.transition ? getMaxTransitionTime(state.transition) : 0; - return maxTransition + animation.delay; + const state = animation.stateB; + const maxTransition = state.transition + ? getMaxTransitionTime(state.transition) + : 0; + return maxTransition + animation.delay; }; -const getMaxAnimationsDuration = (animations: Animations) => ( - Math.max(...Object.values(animations).map(animations => getAnimationDuration(Object.values(animations)))) -); +const getMaxAnimationsDuration = (animations: Animations) => + Math.max( + ...Object.values(animations).map((animations) => + getAnimationDuration(Object.values(animations)) + ) + ); -export const createAnimationRunner = (animationsIn: { [k: string]: (Animation | Animation[]) }, subscriber: () => void = () => { -}): AnimationRunner => { - const animations = Object.entries(animationsIn).reduce((state, [name, animation]) => ({ - ...state, - [name]: animation instanceof Array ? animation : [animation] as Animation[], - }), {} as Animations); +export const createAnimationRunner = ( + animationsIn: AnimationConfig, + subscriber: () => void = () => {} +): AnimationRunner => { + const animations = Object.entries(animationsIn).reduce( + (state, [name, animation]) => ({ + ...state, + [name]: + animation instanceof Array ? animation : ([animation] as Animation[]), + }), + {} as Animations + ); - let state = Object.entries(animations).reduce((state, [name, animation]) => ({ - ...state, - [name]: getAnimationStates(animation), - }), {} as AnimationStates); + let state = Object.entries(animations).reduce( + (state, [name, animation]) => ({ + ...state, + [name]: getAnimationStates(animation), + }), + {} as AnimationStates + ); - const animationsDuration = getMaxAnimationsDuration(animations); + const animationsDuration = getMaxAnimationsDuration(animations); - const animate = (name: string, animation: Animation[]) => { - animation.forEach((a, index) => { - window.requestAnimationFrame(() => { - window.setTimeout(() => { - state = { - ...state, - [name]: [ - ...(state[name]?.slice(0, index)), - a.stateB, - ...(state[name]?.slice(index + 1, state[name].length)), - ], - }; - subscriber(); - }, a.delay); - }); - }); - } + const animate = (name: string, animation: Animation[]) => { + animation.forEach((a, index) => { + window.requestAnimationFrame(() => { + window.setTimeout(() => { + state = { + ...state, + [name]: [ + ...state[name]?.slice(0, index), + a.stateB, + ...state[name]?.slice(index + 1, state[name].length), + ], + }; + subscriber(); + }, a.delay); + }); + }); + }; - return { - getState() { - return state; - }, - run() { - Object.entries(animations).forEach(([name, animation]) => { - animate(name, animation) - }); - }, - awaitAnimationComplete(callback) { - window.setTimeout(callback, animationsDuration); - }, - } -} + return { + getState() { + return state; + }, + run() { + Object.entries(animations).forEach(([name, animation]) => { + animate(name, animation); + }); + }, + awaitAnimationComplete(callback) { + window.setTimeout(callback, animationsDuration); + }, + }; +}; diff --git a/src/components/Item/Item.tsx b/src/components/Item/Item.tsx index dc47c0a..225d66b 100644 --- a/src/components/Item/Item.tsx +++ b/src/components/Item/Item.tsx @@ -1,31 +1,43 @@ -import React from 'react'; -import classNames from 'classnames'; -import Link from '../Link/Link'; -import Flag from '../Flag/Flag'; -import { Item as mItem } from '../../model'; -import './item.scss'; -type ItemProps = { +import React from "react"; +import classNames from "classnames"; +import Link from "../Link/Link"; +import Flag from "../Flag/Flag"; +import { Item as mItem } from "../../model"; +import "./item.scss"; + +type Props = { item: mItem; noLeadingBorder?: boolean; active?: boolean; style: React.CSSProperties; + greyedOut?: boolean; }; -export default function Item({ item, noLeadingBorder = false, active = false, style = {} }: ItemProps) { - return ( - = ({ + item, + noLeadingBorder = false, + active = false, + style = {}, + greyedOut = false, +}) => ( + +