This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Maybe<T> = T | null | undefined; | |
/** | |
* Позволяет переопределить тип свойства {PropertyName} у типа {T} на новое значение {NewValue} | |
*/ | |
type Override<T, PropertyName extends keyof T, NewValue> = Omit<T, PropertyName> & | |
{ [K in keyof T]: K extends PropertyName ? NewValue : T[K] }; | |
interface FixedLengthArray<T extends unknown, L extends number> extends Array<T> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MutableRefObject, useEffect, useRef, useState } from "react"; | |
type AsyncResult<T> = { | |
status: AsyncStatus; | |
data?: T; | |
error?: Error; | |
}; | |
enum AsyncStatus { | |
Loading, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.mtk13 { | |
color: #9cdcfe; | |
text-shadow: 0 0 2px #100c0f, 0 0 5px #ffdda926, 0 0 10px #fff3; | |
} | |
.mtk12 { | |
color: #ffdda9; | |
text-shadow: 0 0 2px #100c0f, 0 0 5px #ffdda926, 0 0 10px #fff3; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-size: calc([minimum size] + ([maximum size] - [minimum size]) * ((100vw - [minimum viewport width]) / ([maximum viewport width] - [minimum viewport width]))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.fixed-header-table { overflow-y: auto; height: 100px; } | |
.fixed-header-table thead th { | |
position: sticky; | |
top: 0; | |
/* don't use border, just use box-shadow */ | |
box-shadow: 0 1px 0 #c6c7c9; | |
} | |
table { border-collapse: collapse; width: 100%; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const clamp = (num: number, min: number, max: number): number => | |
Math.max(min, Math.min(max, num)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRef } from 'react' | |
/** | |
* Создает константное значение в функциональном React компоненте | |
* useMemo не дает гарантий, что функция определения значения не вызовется повторно | |
* https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily | |
* https://reactjs.org/docs/hooks-reference.html#usememo | |
* | |
* @param defineValue функция определения значения | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const clone = <O extends unknown | unknown[]>(value: O, history?: Set<unknown>): O => { | |
if (value == null || typeof value !== "object") return value; | |
const stack = history || new WeakSet(); | |
if (stack.has(value)) { | |
return value; | |
} | |
stack.add(value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MutableRefObject, useEffect, useRef } from 'react' | |
export const useSyncRef = <T>(value: T): MutableRefObject<T> => { | |
const ref = useRef<T>(value) | |
useEffect(() => { | |
ref.current = value | |
}, [value]) | |
return ref |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable @typescript-eslint/ban-types */ | |
import { Reducer, useCallback, useReducer } from 'react' | |
import { useConstant } from 'hooks/useConstant' | |
const reducerCreator = | |
<S extends object>(filter?: (prev: S, curr: S) => boolean) => | |
(state: S, update: (prevState: S) => S | void) => { | |
const nextState = update(state) | |
return nextState === void 0 || (filter && filter(state, nextState)) |
NewerOlder