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: table: add table component #193

Merged
merged 46 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
bf110aa
chore: table: initial commit
dkilgore-eightfold May 31, 2022
1020af2
Merge branch 'main' into dkilgore-eightfold/table-component
dkilgore-eightfold May 31, 2022
8cddb17
chore: table: module name change and stories file
dkilgore-eightfold May 31, 2022
d4351e6
Merge commit 'bcfb1a66b0110b9e7f2ac9df579cf63596e7c249' into dkilgore…
dkilgore-eightfold Jun 1, 2022
8298d4f
feat: table: adds tree, empty, motion and list virtualization components
dkilgore-eightfold Jun 7, 2022
d7a26d0
Merge commit 'e9a5f0e23d2de336aa2bca64c319b20003ab8c7d' into dkilgore…
dkilgore-eightfold Jun 7, 2022
ce7bfeb
chore: table: commit ahead of merge
dkilgore-eightfold Jun 13, 2022
0b924c7
Merge commit '996f8d62f8dd28030f5fd41ce81434e24c6ae3a9' into dkilgore…
dkilgore-eightfold Jun 13, 2022
50befbd
feat: table: adds table component
dkilgore-eightfold Jun 16, 2022
1e64d78
chore: git: add lfs
dkilgore-eightfold Jun 16, 2022
394d18a
chore: lfs: removes large snap ahead of commit
dkilgore-eightfold Jun 16, 2022
2dbf277
Create .gitattributes
dkilgore-eightfold Jun 16, 2022
2842113
chore: table: merge with latest
dkilgore-eightfold Jun 16, 2022
c757a7e
chore: table: merge with latest
dkilgore-eightfold Jun 17, 2022
950628c
chore: ts: adds some typings
dkilgore-eightfold Jun 17, 2022
d682e4a
Merge branch 'EightfoldAI:main' into main
dkilgore-eightfold Jun 20, 2022
edf73c7
chore: table: fixes some linter errors
dkilgore-eightfold Jun 20, 2022
e71a6fb
Merge branch 'EightfoldAI:main' into main
dkilgore-eightfold Jun 20, 2022
fdb35f0
Merge commit 'e71a6fb2a201b62c82978cc4c3a4183da62e3a8a' into dkilgore…
dkilgore-eightfold Jun 20, 2022
52ac43e
chore: table: fix linter errors
dkilgore-eightfold Jun 20, 2022
71f1508
chore: table: fix linter errors and exclude ts classes from css modules
dkilgore-eightfold Jun 20, 2022
39b0949
chore: table: fix linter errors part three
dkilgore-eightfold Jun 20, 2022
058cf5d
chore: table: linter fix attempt three using updated imports
dkilgore-eightfold Jun 20, 2022
a2534a2
chore: table: linter fix attempt four using updated webpack config
dkilgore-eightfold Jun 20, 2022
1d2f1be
chore: table: compiler and linter fix attempt using updated tsx
dkilgore-eightfold Jun 20, 2022
2dcd662
chore: table: removes renamed files
dkilgore-eightfold Jun 20, 2022
f29e26a
chore: table: reverts renamed files
dkilgore-eightfold Jun 20, 2022
ac1de04
chore: table: update reat import in usestate
dkilgore-eightfold Jun 20, 2022
f57d441
chore: table: updates import type name
dkilgore-eightfold Jun 20, 2022
d3d3619
chore: table: removes default exports from motion hooks
dkilgore-eightfold Jun 20, 2022
6eaadb0
Merge branch 'EightfoldAI:main' into main
dkilgore-eightfold Jun 21, 2022
19b59ec
chore: imports: removes more defaults
dkilgore-eightfold Jun 21, 2022
65d8e91
chore: table: removes more defaults and updates exports in usestate
dkilgore-eightfold Jun 21, 2022
e13f835
chore: table: adds type and updates casing in a path
dkilgore-eightfold Jun 21, 2022
978e6d3
chore: table: updates casing in remaining error paths
dkilgore-eightfold Jun 21, 2022
d4f4667
chore: table: revert renamed dir to fix compilation path
dkilgore-eightfold Jun 21, 2022
a4ee46a
chore: table: update capitalization of import path
dkilgore-eightfold Jun 21, 2022
0f644f4
chore: table: reverts some updates to fix build
dkilgore-eightfold Jun 21, 2022
7c1cccc
Merge branch 'EightfoldAI:main' into main
dkilgore-eightfold Jun 22, 2022
781e3a9
chore: table: address pr feedback, remove lodash and adds theming
dkilgore-eightfold Jun 22, 2022
bf4ebf2
Merge branch 'EightfoldAI:main' into main
dkilgore-eightfold Jun 22, 2022
9963a41
Merge commit 'bf4ebf21d20c9f8bd932996d11a347ee6b18a8e5' into dkilgore…
dkilgore-eightfold Jun 23, 2022
b9bf26b
chore: lfs: adds gitattributes file to pr ahead of merge
dkilgore-eightfold Jun 23, 2022
d65c77c
Merge branch 'EightfoldAI:main' into main
dkilgore-eightfold Jun 23, 2022
aa9b9cf
Merge commit 'd65c77c77308e175b7d328948dcd480473d466b3' into dkilgore…
dkilgore-eightfold Jun 23, 2022
30d3d7f
chore: table: revert type property order change
dkilgore-eightfold Jun 23, 2022
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
2 changes: 2 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ declare module '*.scss' {
export default styles;
}

declare module '@ngard/tiny-isequal';

/**
* userLanguage type for IE i18n
*/
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
"@floating-ui/react-dom": "0.6.0",
"@floating-ui/react-dom-interactions": "0.6.3",
"@mdi/react": "1.5.0",
"@ngard/tiny-isequal": "1.1.0",
jhoward-eightfold marked this conversation as resolved.
Show resolved Hide resolved
"@types/lodash": "4.14.182",
"@types/react-is": "17.0.3",
"@types/shallowequal": "1.1.1",
"bodymovin": "4.13.0",
"lodash": "4.17.21",
"lottie-web": "5.8.1",
"react-flip-toolkit": "7.0.13",
"react-is": "18.1.0",
Expand Down Expand Up @@ -159,6 +159,7 @@
"react-dev-utils": "12.0.0",
"react-docgen-typescript": "2.2.2",
"react-refresh": "0.11.0",
"react-sortable-hoc": "2.0.0",
"react-test-renderer": "17.0.2",
"react-window": "1.8.5",
"regenerator-runtime": "0.13.7",
Expand Down
4 changes: 2 additions & 2 deletions src/__snapshots__/storybook.test.js.snap
Git LFS file not shown
3 changes: 1 addition & 2 deletions src/components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { FC, Ref, useCallback, useState } from 'react';

import { mergeClasses, uniqueId } from '../../shared/utilities';
import { eventKeys, mergeClasses, uniqueId } from '../../shared/utilities';

import { AccordionProps, AccordionSummaryProps, AccordionBodyProps } from './';
import { Icon, IconName } from '../Icon';
import { eventKeys } from '../../shared/utilities/eventKeys';

import styles from './accordion.module.scss';

Expand Down
41 changes: 13 additions & 28 deletions src/components/Motion/CSSMotion.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
import React from 'react';
import { useRef } from 'react';
import { findDOMNode } from '../../shared/utilities/findDOMNode';
import { fillRef } from '../../shared/utilities/ref';
import { mergeClasses } from '../../shared/utilities/mergeClasses';
import { getTransitionName, supportTransition } from './util/motion';
import type { CSSMotionConfig, CSSMotionProps } from './CSSMotion.types';
import {
DomWrapper,
findDOMNode,
fillRef,
mergeClasses,
} from '../../shared/utilities';
import { getTransitionName } from './util/motion';
import type { CSSMotionProps } from './CSSMotion.types';
import { STATUS_NONE, STEP_PREPARE, STEP_START } from './CSSMotion.types';
import { useStatus } from './hooks/useStatus';
import { DomWrapper } from '../../shared/utilities/domWrapper';
import { isActive } from './hooks/useStepQueue';

/**
* `transitionSupport` is used for none transition test case.
* Default we use browser transition event support check.
*/
export function genCSSMotion(
config: CSSMotionConfig
): React.ForwardRefExoticComponent<CSSMotionProps & { ref?: React.Ref<any> }> {
let transitionSupport = config;

if (typeof config === 'object') {
({ transitionSupport } = config);
}

function isSupportTransition(props: CSSMotionProps) {
return !!(props.motionName && transitionSupport);
}

export function genCSSMotion(): React.ForwardRefExoticComponent<
CSSMotionProps & { ref?: React.Ref<any> }
> {
const CSSMotion = React.forwardRef<any, CSSMotionProps>((props, ref) => {
const {
// Default config
Expand All @@ -40,8 +28,6 @@ export function genCSSMotion(
eventProps,
} = props;

const supportMotion = isSupportTransition(props);

// Ref to the react node, it may be a HTMLElement
const nodeRef = useRef<any>();
// Ref to the dom wrapper in case ref can not pass to HTMLElement
Expand All @@ -63,7 +49,6 @@ export function genCSSMotion(
}

const [status, statusStep, statusStyle, mergedVisible] = useStatus(
supportMotion,
visible,
getDomElement,
props
Expand Down Expand Up @@ -92,7 +77,7 @@ export function genCSSMotion(
if (!children) {
// No children
motionChildren = null;
} else if (status === STATUS_NONE || !isSupportTransition(props)) {
} else if (status === STATUS_NONE) {
// Stable children
if (mergedVisible) {
motionChildren = children({ ...mergedProps }, setNodeRef);
Expand Down Expand Up @@ -161,4 +146,4 @@ export function genCSSMotion(
return CSSMotion;
}

export default genCSSMotion(supportTransition);
export default genCSSMotion();
8 changes: 1 addition & 7 deletions src/components/Motion/CSSMotion.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ export type MotionEndEventHandler = (
event: MotionEvent
) => boolean | void;

export type CSSMotionConfig =
| boolean
| {
transitionSupport?: boolean;
};

export type MotionName =
| string
| {
Expand Down Expand Up @@ -146,7 +140,7 @@ export interface CSSMotionProps {
children?: (
props: {
visible?: boolean;
className?: string;
classNames?: string;
style?: React.CSSProperties;
[key: string]: any;
},
Expand Down
22 changes: 8 additions & 14 deletions src/components/Motion/CSSMotionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
CSSMotionListProps,
CSSMotionListState,
} from './CSSMotion.types';
import { supportTransition } from './util/motion';
import {
STATUS_ADD,
STATUS_KEEP,
Expand All @@ -18,11 +17,9 @@ import {

/**
* Generate a CSSMotionList component with config
* @param transitionSupport No need since CSSMotionList no longer depends on transition support
* @param CSSMotion CSSMotion component
*/
export function genCSSMotionList(
transitionSupport?: boolean,
CSSMotion = OriginCSSMotion
): React.ComponentClass<CSSMotionListProps> {
class CSSMotionList extends React.Component<
Expand Down Expand Up @@ -63,7 +60,6 @@ export function genCSSMotionList(
};
}

// ZombieJ: Return the count of rest keys. It's safe to refactor if need more info.
removeKey = (removeKey: React.Key) => {
const { keyEntities } = this.state;
const nextKeyEntities = keyEntities.map((entity) => {
Expand All @@ -90,23 +86,21 @@ export function genCSSMotionList(
children,
onVisibleChanged,
onAllRemoved,
...restProps
...rest
} = this.props;

const Component = component || React.Fragment;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _transitionSupport = transitionSupport;

const motionProps: CSSMotionProps = {};

MOTION_PROP_NAMES.forEach((prop) => {
(motionProps as any)[prop] = (restProps as any)[prop];
delete (restProps as any)[prop];
(motionProps as any)[prop] = (rest as any)[prop];
delete (rest as any)[prop];
});
delete restProps.keys;

delete rest.keys;

return (
<Component {...restProps}>
<Component {...rest}>
{keyEntities.map(({ status, ...eventProps }) => {
const visible =
status === STATUS_ADD || status === STATUS_KEEP;
Expand Down Expand Up @@ -147,4 +141,4 @@ export function genCSSMotionList(
return CSSMotionList;
}

export default genCSSMotionList(supportTransition);
export default genCSSMotionList();
7 changes: 0 additions & 7 deletions src/components/Motion/hooks/useIsomorphicLayoutEffect.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/components/Motion/hooks/useNextFrame.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { wrapperRaf } from '../../../shared/utilities/raf';
import { requestAnimationFrameWrapper } from '../../../shared/utilities';

export const useNextFrame = (): [
(callback: (info: { isCanceled: () => boolean }) => void) => void,
Expand All @@ -8,7 +8,7 @@ export const useNextFrame = (): [
const nextFrameRef = React.useRef<number>(null);

function cancelNextFrame() {
wrapperRaf.cancel(nextFrameRef.current);
requestAnimationFrameWrapper.cancel(nextFrameRef.current);
}

function nextFrame(
Expand All @@ -17,7 +17,7 @@ export const useNextFrame = (): [
) {
cancelNextFrame();

const nextFrameId = wrapperRaf(() => {
const nextFrameId = requestAnimationFrameWrapper(() => {
if (delay <= 1) {
callback({
isCanceled: () => nextFrameId !== nextFrameRef.current,
Expand Down
10 changes: 2 additions & 8 deletions src/components/Motion/hooks/useStatus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useEffect } from 'react';
import React, { useRef, useEffect, useLayoutEffect } from 'react';
import { useSafeState } from '../../../hooks/useState';
import {
STATUS_APPEAR,
Expand All @@ -19,10 +19,8 @@ import type {
} from '../CSSMotion.types';
import { DoStep, SkipStep, isActive, useStepQueue } from './useStepQueue';
import { useDomMotionEvents } from './useDomMotionEvents';
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';

export const useStatus = (
supportMotion: boolean,
visible: boolean,
getElement: () => HTMLElement,
{
Expand Down Expand Up @@ -166,16 +164,12 @@ export const useStatus = (

// ============================ Status ============================
// Update with new status
useIsomorphicLayoutEffect(() => {
useLayoutEffect(() => {
setAsyncVisible(visible);

const isMounted = mountedRef.current;
mountedRef.current = true;

if (!supportMotion) {
return;
}

let nextStatus: MotionStatus;

// Appear
Expand Down
5 changes: 2 additions & 3 deletions src/components/Motion/hooks/useStepQueue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useLayoutEffect } from 'react';
import { useSafeState } from '../../../hooks/useState';
import type { StepStatus, MotionStatus } from '../CSSMotion.types';
import {
Expand All @@ -9,7 +9,6 @@ import {
STEP_NONE,
} from '../CSSMotion.types';
import { useNextFrame } from './useNextFrame';
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';

const STEP_QUEUE: StepStatus[] = [
STEP_PREPARE,
Expand Down Expand Up @@ -41,7 +40,7 @@ export const useStepQueue = (
setStep(STEP_PREPARE, true);
}

useIsomorphicLayoutEffect(() => {
useLayoutEffect(() => {
if (step !== STEP_NONE && step !== STEP_ACTIVATED) {
const index = STEP_QUEUE.indexOf(step);
const nextStep = STEP_QUEUE[index + 1];
Expand Down
10 changes: 4 additions & 6 deletions src/components/Motion/tests/CSSMotion.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { mergeClasses } from '../../../shared/utilities/mergeClasses';
import { mergeClasses } from '../../../shared/utilities';
import { render, fireEvent } from '@testing-library/react';
import type { CSSMotionProps } from '../CSSMotion.types';
import RefCSSMotion, { genCSSMotion } from '../CSSMotion';
import ReactDOM from 'react-dom';

describe('CSSMotion', () => {
const CSSMotion = genCSSMotion({
transitionSupport: true,
});
const CSSMotion = genCSSMotion();

beforeEach(() => {
jest.useFakeTimers();
Expand Down Expand Up @@ -115,10 +113,10 @@ describe('CSSMotion', () => {
motionDeadline={233}
motionName="bamboo"
>
{({ style, className }) => (
{({ style, classNames }) => (
<Component
style={style}
className={mergeClasses(['motion-box', className])}
className={mergeClasses(['motion-box', classNames])}
/>
)}
</CSSMotion>
Expand Down
Loading