Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add type declarations to libs and styles #2435

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/**/*.d.ts
13 changes: 1 addition & 12 deletions src/components/Application/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { ReactNode } from 'react';
import { BaseProps } from '../types';

type ThemeType = {
rainbow?: {
palette?: {
brand?: string;
success?: string;
error?: string;
warning?: string;
mainBackground?: string;
};
};
};
import { ThemeType } from '../../styled';

export interface ApplicationProps extends BaseProps {
children?: ReactNode;
Expand Down
6 changes: 6 additions & 0 deletions src/libs/ResizeSensor/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare class ResizeSensor {
constructor(element: Element, resizeListener: () => void);
detach(): void;
reset(): void;
}
export default ResizeSensor;
6 changes: 6 additions & 0 deletions src/libs/WindowResize/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare class WindowResize {
constructor();
startListening(callback: (event: UIEvent) => void): void;
stopListening(): void;
}
export default WindowResize;
13 changes: 13 additions & 0 deletions src/libs/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const LEFT_KEY = 37;
export const UP_KEY = 38;
export const RIGHT_KEY = 39;
export const DOWN_KEY = 40;
export const ESCAPE_KEY = 27;
export const TAB_KEY = 9;
export const ENTER_KEY = 13;
export const DELETE_KEY = 8;
export const SPACE_KEY = 32;
export const PAGEUP_KEY = 33;
export const PAGEDN_KEY = 34;
export const END_KEY = 35;
export const HOME_KEY = 36;
9 changes: 9 additions & 0 deletions src/libs/counterManager/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare class CounterManager {
constructor();
increment(): void;
decrement(): void;
hasModalOpen(): boolean;
}

const counterManager = new CounterManager();
export default counterManager;
3 changes: 3 additions & 0 deletions src/libs/debounce/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare function debounce(callback: Function, time?: number): (...args: unknown[]) => void;

export default debounce;
2 changes: 2 additions & 0 deletions src/libs/hocs/withDebounce/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function withDebounce<P>(WrappedComponent: React.ComponentType<P>): React.Component<P>;
export default withDebounce;
2 changes: 2 additions & 0 deletions src/libs/hocs/withReduxForm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function withReduxForm<P>(WrappedComponent: React.ComponentType<P>): React.Component<P>;
export default withReduxForm;
9 changes: 9 additions & 0 deletions src/libs/hooks/useDisclosure.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface Disclosure {
isOpen: boolean;
open: () => void;
close: () => void;
toggle: () => void;
}

declare function useDisclosure(defaultIsOpen?: unknown): Disclosure;
export default useDisclosure;
2 changes: 2 additions & 0 deletions src/libs/hooks/useErrorMessageId.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function useErrorMessageId(error: unknown): string | undefined;
export default useErrorMessageId;
5 changes: 5 additions & 0 deletions src/libs/hooks/useIsomorphicLayoutEffect.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare function useIsomorphicLayoutEffect(
effect: React.EffectCallback,
deps?: React.DependencyList | undefined,
): void;
export default useIsomorphicLayoutEffect;
2 changes: 2 additions & 0 deletions src/libs/hooks/useLabelId.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function useLabelId(label?: unknown): string | undefined;
export default useLabelId;
2 changes: 2 additions & 0 deletions src/libs/hooks/useLocale.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function useLocale(localProp?: string): string;
export default useLocale;
2 changes: 2 additions & 0 deletions src/libs/hooks/useTheme.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function useTheme(): Record<string, any>;
export default useTheme;
2 changes: 2 additions & 0 deletions src/libs/hooks/useUniqueIdentifier.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function useUniqueIdentifier(prefix?: string): string;
export default useUniqueIdentifier;
5 changes: 5 additions & 0 deletions src/libs/hooks/useWindowResize.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare function useWindowResize(
handler: (this: Window, ev: UIEvent) => void,
isListening?: boolean,
): void;
export default useWindowResize;
5 changes: 2 additions & 3 deletions src/libs/manageTab/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import { KeyboardEvent } from 'react';

export default function manageTab(node: HTMLElement, event: KeyboardEvent<Element>): void;
declare function manageTab(node: HTMLElement, event: React.KeyboardEvent<Element>): void;
export default manageTab;
9 changes: 9 additions & 0 deletions src/libs/outsideClick/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare class OutsideClick {
constructor();
startListening(
containerRef?: Element,
callback?: (this: OutsideClick, event: MouseEvent) => void,
): void;
}

export default OutsideClick;
4 changes: 4 additions & 0 deletions src/libs/scrollController/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function disableBodyScroll(targetElement: Element, options: Record<string, any>): void;
export function clearAllBodyScrollLocks(): void;
export function enableBodyScroll(targetElement: Element): void;
export { default as WindowScrolling } from './windowScrolling';
6 changes: 6 additions & 0 deletions src/libs/scrollController/windowScrolling.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare class WindowScrolling {
constructor();
startListening(callback: (event: UIEvent) => void): void;
stopListening(): void;
}
export default WindowScrolling;
2 changes: 2 additions & 0 deletions src/libs/utils/getBrowserLocale.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function getBrowserLocale(): string;
export default getBrowserLocale;
2 changes: 2 additions & 0 deletions src/libs/utils/getLocale.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function getLocale(context?: unknown, localProp?: string): string;
export default getLocale;
2 changes: 2 additions & 0 deletions src/libs/utils/getSuffixSI.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function getSuffixSI(number?: number): string;
export default getSuffixSI;
2 changes: 2 additions & 0 deletions src/libs/utils/isServer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const isServer: boolean;
export default isServer;
2 changes: 2 additions & 0 deletions src/libs/utils/uniqueId.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function uniqueId(prefix?: string): string;
export default uniqueId;
87 changes: 87 additions & 0 deletions src/styled.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
export type ThemeType = {
rainbow?: {
palette?: {
brand?: string;
success?: string;
error?: string;
warning?: string;
mainBackground?: string;
};
};
};

export interface Palette {
brand: {
main: string;
dark: string;
light: string;
};
success: {
main: string;
dark: string;
light: string;
};
error: {
main: string;
dark: string;
light: string;
};
warning: {
main: string;
dark: string;
light: string;
};
background: {
main: string;
secondary: string;
highlight: string;
active: string;
};
text: {
main: string;
title: string;
header: string;
label: string;
disabled: string;
};
border: {
main: string;
divider: string;
disabled: string;
};
action: {
active: string;
hover: string;
};
getContrastText: (background: string) => string;
isDark: boolean;
}

export interface Shadows {
brand: string;
success: string;
error: string;
shadow_1: string;
shadow_2: string;
shadow_3: string;
shadow_4: string;
shadow_5: string;
shadow_6: string;
shadow_7: string;
shadow_8: string;
shadow_9: string;
shadow_10: string;
shadow_11: string;
shadow_12: string;
}

export interface RainbowTheme {
palette: Palette;
shadows: Shadows;
}

declare module 'styled-components' {
export interface DefaultTheme {
rainbow: RainbowTheme;
}
}
4 changes: 4 additions & 0 deletions src/styles/borderRadius.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const BORDER_RADIUS_1: '0.875rem';
export const BORDER_RADIUS_2: '12rem';
export const BORDER_RADIUS_3: '0.4rem';
export const BORDER_RADIUS_4: '0.5rem';
40 changes: 40 additions & 0 deletions src/styles/colors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// white
export const COLOR_WHITE: '#fff';

// brand colors
export const COLOR_BRAND: '#01b6f5';
export const COLOR_BRAND_ACTIVE: '#009acf';
export const COLOR_BRAND_LIGHT: 'rgba(0, 184, 245, 0.2)';
export const COLOR_BRAND_2: '#07b0ea';

// success colors
export const COLOR_SUCCESS: '#1de9b6';
export const COLOR_SUCCESS_ACTIVE: '#1ad1a3';
export const COLOR_SUCCESS_LIGHT: 'rgba(29, 233, 182, 0.2)';

// error colors
export const COLOR_ERROR: '#fe4849';
export const COLOR_ERROR_ACTIVE: '#ea4243';

// gray colors
export const COLOR_GRAY_1: '#F6F7F9';
export const COLOR_GRAY_2: '#D7D9E2';
export const COLOR_GRAY_3: '#a4a7b5';
export const COLOR_GRAY_4: '#3F4954';
export const COLOR_GRAY_TRANSPARENT_1: 'rgba(244, 246, 249, 0.4)';
export const COLOR_GRAY_TRANSPARENT_2: 'rgba(82, 95, 127, 0.3)';
export const COLOR_GRAY_TRANSPARENT_3: 'rgba(82, 95, 127, 0.15)';
export const COLOR_GRAY_DARK_TRANSPARENT: 'rgba(42, 48, 57, 0.2)';

// text colors
export const COLOR_DARK_1: '#2A3039';

// yellow colors
// TODO: only warning const should remain
export const COLOR_YELLOW_1: '#fc0';
export const COLOR_WARNING: '#fc0';
export const COLOR_WARNING_DARK: '#FFB900';
export const COLOR_WARNING_LIGHT: '#FFDC7F';

// purple colors
export const COLOR_PURPLE: '#663398';
4 changes: 4 additions & 0 deletions src/styles/defaultTheme.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { RainbowTheme } from '../styled';

const defaultTheme: RainbowTheme;
export default defaultTheme;
11 changes: 11 additions & 0 deletions src/styles/fontSizes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// font sizes heading
export const FONT_SIZE_HEADING_SMALL: '1rem';
export const FONT_SIZE_HEADING_MEDIUM: '1.25rem';
export const FONT_SIZE_HEADING_LARGE: '1.5rem';
export const FONT_SIZE_HEADING_X_LARGE: '2rem';

// font sizes text
export const FONT_SIZE_TEXT_X_SMALL: '0.625rem';
export const FONT_SIZE_TEXT_SMALL: '0.75rem';
export const FONT_SIZE_TEXT_MEDIUM: '0.875rem';
export const FONT_SIZE_TEXT_LARGE: '1rem';
6 changes: 6 additions & 0 deletions src/styles/helpers/attachThemeAttrs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ThemedStyledFunction } from 'styled-components';

declare function attachThemeAttrs<C, T, O, A>(
styledElement: ThemedStyledFunction<C, T, O, A>,
): ThemedStyledFunction<C, T, O, A>;
export default attachThemeAttrs;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/bound01.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function bound01(value: number, max: number): number;
export default bound01;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/clamp.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function clamp(value: number, min?: number, max?: number): number;
export default clamp;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/colorToRgba.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function colorToRgba(color: string): string;
export default colorToRgba;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/darken.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function darken(color: string, coefficient?: number): string;
export default darken;
4 changes: 4 additions & 0 deletions src/styles/helpers/color/decomposeColor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare function decomposeColor(
color: string | { type: string; values: number[] },
): { type: string; values: number[] };
export default decomposeColor;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/getBrightness.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function getBrightness(color: string): number;
export default getBrightness;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/getContrastRatio.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function getContrastRatio(foreground: string, background: string): number;
export default getContrastRatio;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/getContrastText.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function getContrastText(background: string): string;
export default getContrastText;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/getLuminance.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function getLuminance(color: string): number;
export default getLuminance;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/hexToRgb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function hexToRgb(color: string): string;
export default hexToRgb;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/hexToRgba.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function hexToRgba(color: string, alpha?: number): string;
export default hexToRgba;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/hslToRgb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function hslToRgb(color: string): string;
export default hslToRgb;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/hsvToRgb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function hsvToRgb(color: string): string;
export default hsvToRgb;
20 changes: 20 additions & 0 deletions src/styles/helpers/color/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export { default as hexToRgb } from './hexToRgb';
export { default as hexToRgba } from './hexToRgba';
export { default as replaceAlpha } from './replaceAlpha';
export { default as rgbaToRgb } from './rgbaToRgb';
export { default as rgbToRgba } from './rgbToRgba';
export { default as decomposeColor } from './decomposeColor';
export { default as recomposeColor } from './recomposeColor';
export { default as darken } from './darken';
export { default as lighten } from './lighten';
export { default as getLuminance } from './getLuminance';
export { default as getContrastRatio } from './getContrastRatio';
export { default as getContrastText } from './getContrastText';
export { default as isValidColor } from './isValidColor';
export { default as getBrightness } from './getBrightness';
export { default as isDark } from './isDark';
export { default as colorToRgba } from './colorToRgba';
export { default as rgbaToHex } from './rgbaToHex';
export { default as rgbToHsv } from './rgbToHsv';
export { default as hsvToRgb } from './hsvToRgb';
export { default as isHsvColor } from './isHsvColor';
2 changes: 2 additions & 0 deletions src/styles/helpers/color/isDark.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function isDark(color: string): boolean;
export default isDark;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/isHexColor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function isHexColor(color: string): boolean;
export default isHexColor;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/isHsvColor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function isHsvColor(color: string): boolean;
export default isHsvColor;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/isOnePointZero.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function isOnePointZero(value?: string): boolean;
export default isOnePointZero;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/isPercentage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function isPercentage(value?: string): boolean;
export default isPercentage;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/isValidColor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function isValidColor(color?: string): boolean;
export default isValidColor;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/lighten.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function lighten(color: string, coefficient?: number): string;
export default lighten;
5 changes: 5 additions & 0 deletions src/styles/helpers/color/recomposeColor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare function recomposeColor(color: {
type: string;
values: { type: string; values: number[] };
}): string;
export default recomposeColor;
2 changes: 2 additions & 0 deletions src/styles/helpers/color/replaceAlpha.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function replaceAlpha(color: string, alpha?: number): string;
export default replaceAlpha;
Loading