Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
51b6e9e
convert part of the shared folder
alexasselin008 Feb 4, 2021
f6b2961
couple more files converted to TS
alexasselin008 Feb 4, 2021
5af70f6
Merge branch 'menu' into conversion_ts
alexasselin008 Feb 4, 2021
3e7d8d5
keep converting shared folder
alexasselin008 Feb 4, 2021
4c663cb
conversion de plus de méthode helpers
alexasselin008 Feb 4, 2021
c7d8dce
couple more shared utils converted
alexasselin008 Feb 4, 2021
285b84a
creation of a size type, and converted couple of files
alexasselin008 Feb 4, 2021
165c868
convert semantic folder and add eslint exception for react files
alexasselin008 Feb 4, 2021
8376fef
convert focus manager, add options to tsconfig and modified some types
alexasselin008 Feb 4, 2021
c43e948
couple of conversion of shared files
alexasselin008 Feb 4, 2021
f8fe8f9
conversion de keyboard navigation
alexasselin008 Feb 4, 2021
5676590
treewalker
alexasselin008 Feb 5, 2021
b551fe2
Merge branch 'menu' into conversion_ts
alexasselin008 Feb 5, 2021
873ca86
convert merged refs
alexasselin008 Feb 5, 2021
9fa0680
more file conversion
alexasselin008 Feb 5, 2021
9176d20
converted rovingfocus
alexasselin008 Feb 5, 2021
0b4524c
converted the remaining files
alexasselin008 Feb 5, 2021
0509404
cleanup
alexasselin008 Feb 5, 2021
dec46b3
cleanup part 2
alexasselin008 Feb 5, 2021
cc43be8
Merge branch 'menu' into conversion_ts
alexasselin008 Feb 5, 2021
a4de2a3
code review fixes
alexasselin008 Feb 8, 2021
a0bfb41
more review fixes
alexasselin008 Feb 8, 2021
ab4a794
review fixes
alexasselin008 Feb 8, 2021
e1f9765
extracted a type
alexasselin008 Feb 8, 2021
0a1f7a2
remove as const, and more cr fixes
alexasselin008 Feb 8, 2021
ab87a32
review fixes
alexasselin008 Feb 8, 2021
5dc44bd
review fixes
alexasselin008 Feb 8, 2021
71fc034
fix eslint
alexasselin008 Feb 8, 2021
61fa8a9
fix eslint
alexasselin008 Feb 8, 2021
a8edbac
fix eslint
alexasselin008 Feb 8, 2021
4cfcd6e
added necessary dev dependancy and update eslint config
alexasselin008 Feb 9, 2021
338481f
add return types to functions
alexasselin008 Feb 9, 2021
67b8cdd
fixed the return type of the useHasChildren function
alexasselin008 Feb 9, 2021
cb21bf6
Merge branch 'conversion_ts' into explicit_returns
alexasselin008 Feb 9, 2021
410cd2d
add return types explicitly
alexasselin008 Feb 9, 2021
c0e7c09
added tsx files to babel transformation for tests
alexasselin008 Feb 9, 2021
b1ba4f1
Merge branch 'menu' into conversion_ts
alexasselin008 Feb 9, 2021
36113db
Merge branch 'conversion_ts' into explicit_returns
alexasselin008 Feb 9, 2021
daf64d6
Updated config so we don't have to import React on every tsx file
Feb 9, 2021
29ddb2e
Merge branch 'menu' into conversion_ts
alexasselin008 Feb 11, 2021
b32d4b4
fix of bad typing that caused jest issues
alexasselin008 Feb 11, 2021
621f3ba
Merge branch 'conversion_ts' into explicit_returns
alexasselin008 Feb 11, 2021
38281d0
Merge branch 'conversion_ts' of https://github.com/gsoft-inc/sg-orbit…
Feb 11, 2021
2e53b22
Merge pull request #446 from gsoft-inc/explicit_returns
alexasselin008 Feb 11, 2021
2d5b0c1
Merge pull request #447 from BobbyWhiskey/conversion_ts_react_import
alexasselin008 Feb 11, 2021
283e58d
Merge branch 'menu' into conversion_ts
alexasselin008 Feb 11, 2021
8f3a8e4
remove unnecessary typings
alexasselin008 Feb 12, 2021
b4bf658
review fixes
alexasselin008 Feb 12, 2021
7090992
Merge branch 'menu' into conversion_ts
alexasselin008 Feb 12, 2021
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
3 changes: 1 addition & 2 deletions build/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
[
"@babel/preset-react",
{
// runtime: "automatic",
runtime: "automatic",
useBuiltIns: true,
development: !IS_PRODUCTION
}
Expand All @@ -49,7 +49,6 @@ module.exports = {
}
],
"babel-plugin-jsx-control-statements",
"babel-plugin-react-require",
IS_PRODUCTION && "babel-plugin-jsx-remove-data-test-id",
!IS_TEST && [
"babel-plugin-named-asset-import",
Expand Down
2 changes: 1 addition & 1 deletion jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
rootDir: path.resolve(__dirname, ".."),
roots: ["<rootDir>/packages/react-components"],
transform: {
"^.+\\.(js|jsx)$": path.resolve("jest/babel-transform.js")
"^.+\\.(js|jsx|ts|tsx)$": path.resolve("jest/babel-transform.js")
},
// https://github.com/facebook/jest/issues/6229#issuecomment-403539460
transformIgnorePatterns: [
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"delete-yarn-lock:root": "rimraf yarn.lock",
"delete-yarn-lock:storybook": "cd storybook && rimraf yarn.lock",
"eslint": "run-s \"eslint:* --max-warnings={1:--1}\"",
"eslint:pkg": "eslint --ext .js,.jsx packages",
"eslint:sb": "eslint --ext .js,.jsx storybook",
"eslint-fix": "eslint --ext .js,.jsx . --fix",
"eslint:pkg": "eslint --ext .js,.jsx,.ts,.tsx packages",
"eslint:sb": "eslint --ext .js,.jsx,.ts,.tsx storybook",
"eslint-fix": "eslint --ext .js,.jsx,.ts,.tsx . --fix",
"install:pkg": "yarn install --ignore-scripts",
"install:sb": "cd storybook && yarn install",
"lint": "run-s eslint stylelint check-types",
Expand Down Expand Up @@ -82,16 +82,19 @@
"@babel/preset-typescript": "7.12.7",
"@sharegate/browserslist-config-recommended": "1.0.1",
"@sharegate/eslint-config-lodash": "1.0.2",
"@sharegate/eslint-config-react": "2.0.0",
"@sharegate/eslint-config-react": "2.1.0",
"@sharegate/eslint-config-recommended": "1.1.0",
"@sharegate/eslint-config-sort-imports": "1.0.2",
"@sharegate/eslint-config-typescript": "1.3.0",
"@sharegate/stylelint-config-recommended": "2.0.0",
"@types/lodash": "4.14.168",
"@types/react-with-styles": "4.0.5",
"@types/react-dates": "21.8.1",
"@types/react-dom": "17.0.0",
"@types/react": "17.0.0",
"@sharegate/eslint-config-typescript": "1.0.0",
"@types/react-is": "17.0.0",
"@types/resize-observer-browser": "0.1.5",
"@typescript-eslint/parser": "4.15.0",
"@storybook/addon-essentials": "6.1.8",
"@storybook/react": "6.1.8",
"@svgr/webpack": "5.5.0",
Expand All @@ -104,7 +107,6 @@
"babel-plugin-jsx-control-statements": "4.1.0",
"babel-plugin-jsx-remove-data-test-id": "2.1.3",
"babel-plugin-named-asset-import": "0.3.7",
"babel-plugin-react-require": "3.1.3",
"browserslist": "4.14.7",
"chalk": "4.1.0",
"chromatic": "5.4.0",
Expand Down
12 changes: 7 additions & 5 deletions packages/react-components/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,22 @@ module.exports = {
}
},
{
files: ["*.tsx"],
files: ["*.ts?(x)"],
extends:[
"@sharegate/eslint-config-typescript"
],
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-use-before-define": ["error", { "functions": false, "classes": true, "variables": false }]
"no-param-reassign": "off",
"@typescript-eslint/no-explicit-any": "off",

"jsx-control-statements/jsx-jcs-no-undef": "off",
"@typescript-eslint/explicit-function-return-type": ["warn", { allowExpressions: true }]
}
}
],
rules: {
"no-param-reassign": "off",
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx", ".mdx"] }],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx",".ts", ".tsx", ".mdx"] }],
"react/destructuring-assignment": "off",
"jsx-control-statements/jsx-use-if-tag": "off"
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function resolvePopperPosition(upward: boolean, direction: "left" | "right"): string {
return `${upward ? "top" : "bottom"}-${direction === "left" ? "end" : "start"}`;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function arrayify(value) {
export function arrayify<T>(value: T | T[]): T[] {
return Array.isArray(value) ? value : [value];
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

import { isNil } from "lodash";

export function isNilOrEmpty(value) {
export function isNilOrEmpty(value: any): value is null | undefined | "" {
return isNil(value) || value === "";
}
32 changes: 0 additions & 32 deletions packages/react-components/src/shared/src/augmentElement.js

This file was deleted.

37 changes: 37 additions & 0 deletions packages/react-components/src/shared/src/augmentElement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ElementType, HTMLAttributes, ReactElement, RefAttributes, cloneElement } from "react";
import { isString } from "lodash";
import { isValidElementType } from "react-is";
import { mergeProps } from "./mergeProps";
import { normalizeSize } from "./normalizeSize";
import type { SizeAdapter } from "./createSizeAdapter";

export function augmentElement(element: ReactElement & RefAttributes<any>, newProps: Record<string, any>): ReactElement {
const augmentedProps = mergeProps({ ...element.props, ref: element.ref }, newProps);

return cloneElement(element, augmentedProps);
}

export function createOrAugmentElement<T extends string, P extends HTMLAttributes<T>>(element: ReactElement<P, T> | ElementType, props: P): ReactElement {
if (isValidElementType(element) && !isString(element)) {
const Type = element;

return <Type {...props} />;
}

// The isString in the previous condition assume it can be possible that element is a string. however, if its the case, cloneElement does not support string, so it does not make sense
// Therefore, since we are only typing the code and i don't want to introduce regression bugs, i will disable the ts compiler for that line
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return augmentElement(element, props);
}

export function createEmbeddableAdapter(sizeAdapter: SizeAdapter) {
return <P extends Record<string, any>>(element: ReactElement<P, any>, { size, ...props }: P) => {
const newProps = {
...props,
size: sizeAdapter[normalizeSize(size)]
};

return augmentElement(element, newProps);
};
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { createContext, useContext } from "react";
import { isNil } from "lodash";

export const CheckableContext = createContext();
interface CheckableContextProps {
checkedValue?: boolean;
[x: string]: any;
}

export const CheckableContext = createContext<CheckableContextProps>(undefined);

export function useCheckableContext() {
export function useCheckableContext(): [CheckableContextProps, boolean] {
const context = useContext(CheckableContext);

if (!isNil(context)) {
Expand All @@ -13,7 +18,7 @@ export function useCheckableContext() {
return [context, false];
}

export function useCheckableProps({ value }) {
export function useCheckableProps({ value }: { value: boolean }): [{ checked: boolean } & any, boolean] {
const [context, isCheckable] = useCheckableContext();

if (isCheckable) {
Expand Down
9 changes: 0 additions & 9 deletions packages/react-components/src/shared/src/createSizeAdapter.js

This file was deleted.

12 changes: 12 additions & 0 deletions packages/react-components/src/shared/src/createSizeAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { normalizeSize } from "./normalizeSize";
import type { Size } from "./size";

export type SizeAdapter = Record<Size, Size>;

export function createSizeAdapter(adapter: SizeAdapter): (size: Size) => Size {
return (size: Size) => adapter[normalizeSize(size)];
}

export function adaptSize(size: Size, adapter: SizeAdapter): Size {
return adapter[normalizeSize(size)];
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function cssModule(moduleName, ...values) {
export function cssModule(moduleName: string, ...values: (false | string)[]): string {
const classes = values
.filter(Boolean)
.map(x => `${moduleName}-${x}`);
Expand Down
4 changes: 0 additions & 4 deletions packages/react-components/src/shared/src/focusTarget.js

This file was deleted.

4 changes: 4 additions & 0 deletions packages/react-components/src/shared/src/focusTarget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum FocusTarget {
first = "first",
last = "last"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ export const FocusableElementSelector = [...FocusableElement, "[tabindex]"].join

export const TabbableElementSelector = [...FocusableElement, "[tabindex]:not([tabindex=\"-1\"])"].join(":not([tabindex=\"-1\"]),");

export function createFocusableTreeWalker(root, { tabbable } = {}) {
interface FocusableTreeWalkerOptions {
tabbable?: boolean;
}

export function createFocusableTreeWalker(root: HTMLElement, { tabbable }: FocusableTreeWalkerOptions = {}): TreeWalker {
const selector = tabbable ? TabbableElementSelector : FocusableElementSelector;

const walker = document.createTreeWalker(
root,
NodeFilter.SHOW_ELEMENT,
{
acceptNode(node) {
if (node.matches(selector)) {
if ((node as HTMLElement).matches(selector)) {
return NodeFilter.FILTER_ACCEPT;
}

Expand All @@ -41,6 +45,6 @@ export function createFocusableTreeWalker(root, { tabbable } = {}) {
return walker;
}

export function walkFocusableElements(root, onElement) {
export function walkFocusableElements(root: HTMLElement, onElement: (element: Element, index?: number) => void): void {
root.querySelectorAll(FocusableElementSelector).forEach((x, index) => onElement(x, index));
}
14 changes: 0 additions & 14 deletions packages/react-components/src/shared/src/keys.js

This file was deleted.

14 changes: 14 additions & 0 deletions packages/react-components/src/shared/src/keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export enum Keys {
backspace = 8,
tab = 9,
enter = 13,
esc = 27,
space = 32,
end = 35,
home = 36,
left = 37,
up = 38,
right = 39,
down = 40,
delete = 46
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isFunction, isNil } from "lodash";

// Took from https://github.com/tailwindlabs/headlessui/blob/develop/packages/%40headlessui-react/src/utils/match.ts
export function match(value, lookup, ...args) {
export function match<TValue extends string | number = string, TReturnValue = unknown>(value: TValue, lookup: Record<TValue, TReturnValue | ((...arg: any[]) => TReturnValue)>, ...args: any[]): TReturnValue {
const handler = lookup[value];

if (!isNil(handler)) {
Expand Down
13 changes: 0 additions & 13 deletions packages/react-components/src/shared/src/mergeClasses.js

This file was deleted.

13 changes: 13 additions & 0 deletions packages/react-components/src/shared/src/mergeClasses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function mergeClasses(...values: (string | false)[]): string {
const deduped = (values
.filter(Boolean) as string[])
.reduce((set, x) => {
x.split(" ").forEach(y => {
set.add(y);
});

return set;
}, new Set<string>());

return Array.from(deduped).join(" ");
}
Loading