Skip to content

Commit

Permalink
feat: table: add table component (EightfoldAI#193)
Browse files Browse the repository at this point in the history
* chore: table: initial commit

adds table and its dependencies

* chore: table: module name change and stories file

* feat: table: adds tree, empty, motion and list virtualization components

also adds numerous deps

* chore: table: commit ahead of merge

* chore: git: add lfs

* chore: lfs: removes large snap ahead of commit

* Create .gitattributes

* chore: table: merge with latest

* chore: ts: adds some typings

* chore: table: fixes some linter errors

* chore: table: fix linter errors

* chore: table: fix linter errors and exclude ts classes from css modules

* chore: table: fix linter errors part three

* chore: table: linter fix attempt three using updated imports

* chore: table: linter fix attempt four using updated webpack config

* chore: table: compiler and linter fix attempt using updated tsx

* chore: table: removes renamed files

* chore: table: reverts renamed files

* chore: table: update reat import in usestate

* chore: table: updates import type name

* chore: table: removes default exports from motion hooks

* chore: imports: removes more defaults

* chore: table: removes more defaults and updates exports in usestate

* chore: table: adds type and updates casing in a path

* chore: table: updates casing in remaining error paths

* chore: table: revert renamed dir to fix compilation path

* chore: table: update capitalization of import path

* chore: table: reverts some updates to fix build

* chore: table: address pr feedback, remove lodash and adds theming

* chore: lfs: adds gitattributes file to pr ahead of merge

* chore: table: revert type property order change
  • Loading branch information
dkilgore-eightfold authored Jun 23, 2022
1 parent a007990 commit 77c9e6c
Show file tree
Hide file tree
Showing 249 changed files with 33,286 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-checkout'.\n"; exit 2; }
git lfs post-checkout "$@"
3 changes: 3 additions & 0 deletions .husky/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-commit'.\n"; exit 2; }
git lfs post-commit "$@"
3 changes: 3 additions & 0 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-merge'.\n"; exit 2; }
git lfs post-merge "$@"
3 changes: 3 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/pre-push'.\n"; exit 2; }
git lfs pre-push "$@"
23 changes: 21 additions & 2 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap" rel="stylesheet">
<link
href="https://fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap"
rel="stylesheet"
/>

<style>
html, body {
html,
body {
font-family: 'Source Sans Pro', sans-serif;
}

.virtual-table .table-container:before,
.virtual-table .table-container:after {
display: none;
}
.virtual-table-cell {
background: white;
border-bottom: 1px solid #d9dce1;
box-sizing: border-box;
overflow: hidden;
padding: 16px;
}
.grouped-th {
border-bottom: none !important;
}
</style>
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
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@
"@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",
"@types/lodash": "4.14.182",
"@types/react-is": "17.0.3",
"@types/shallowequal": "1.1.1",
"bodymovin": "4.13.0",
"lottie-web": "5.8.1",
"react-flip-toolkit": "7.0.13"
"react-flip-toolkit": "7.0.13",
"react-is": "18.1.0",
"resize-observer-polyfill": "1.5.1",
"shallowequal": "1.1.0"
},
"peerDependencies": {
"@types/react": "17.0.39",
Expand Down Expand Up @@ -95,6 +102,7 @@
"@types/jest": "24.0.23",
"@types/node": "16.11.26",
"@types/react-color": "3.0.6",
"@types/react-window": "1.8.2",
"@types/webpack": "5.28.0",
"@typescript-eslint/eslint-plugin": "5.14.0",
"@typescript-eslint/parser": "5.14.0",
Expand Down Expand Up @@ -138,6 +146,7 @@
"jest-watch-typeahead": "1.0.0",
"lint-staged": "12.3.6",
"mini-css-extract-plugin": "2.6.0",
"mockdate": "3.0.0",
"postcss": "8.4.4",
"postcss-flexbugs-fixes": "5.0.2",
"postcss-loader": "6.2.1",
Expand All @@ -149,7 +158,10 @@
"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",
"resolve": "1.20.0",
"resolve-url-loader": "4.0.0",
"sass": "1.47.0",
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/eventKeys';

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

Expand Down
56 changes: 56 additions & 0 deletions src/components/Empty/svg/DefaultEmptyImg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';

export const DefaultEmptyImg = (): JSX.Element => {
return (
<svg
className={'empty-image-default'}
width="200"
height="184"
viewBox="0 0 200 184"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M39.0718 177.839C21.8078 171.861 3.66074 162.325 0.510726 150.175C-2.63929 138.025 9.18787 123.359 24.8068 115.637C40.5358 108.029 59.9069 107.449 71.9662 102.257C83.9156 96.9498 88.5731 86.9309 99.9189 77.9985C111.265 69.066 129.299 61.2199 140.372 64.9517C151.555 68.798 155.648 84.2069 164.716 96.6426C173.785 109.078 187.68 118.625 194.904 131.657C202.237 144.804 202.768 161.422 189.061 166.219C175.355 171.016 147.3 163.877 128.36 165.625C109.569 167.288 99.7624 177.823 86.4541 181.955C73.2954 186.004 56.4854 183.734 39.0718 177.839Z"
fill="#EBF7FF"
/>
<path d="M26 108L38.5 59H160.5L174 108V154H26V108Z" fill="white" />
<path
fillRule="evenodd"
clipRule="evenodd"
d="M118.495 108.258C118.495 117.504 110.214 123.333 99.9993 123.333C89.7843 123.333 81.5034 117.504 81.5034 108.258C81.5034 107.958 81.5121 105.994 81.5293 105.698H46.666L60.2683 72.6258C60.8547 71.0563 62.4813 70 64.3116 70H135.687C137.517 70 139.144 71.0563 139.73 72.6258L153.333 105.698H118.469C118.487 105.994 118.495 107.958 118.495 108.258Z"
fill="#B0F3FE"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M152.505 59.9999L47.4938 60.0006C43.6128 60.0006 40.0926 62.6542 38.7909 66.7166L27.5922 101.666L74.0905 101.666C78.722 101.666 83.0934 103.873 86.0399 107.654L92.9658 116.542C96.6469 121.266 103.355 121.266 107.037 116.542L113.962 107.654C116.909 103.873 121.28 101.666 125.912 101.666L172.408 101.666L161.208 66.7158C159.906 62.6534 156.386 59.9999 152.505 59.9999ZM173.651 108.333L125.912 108.333C123.217 108.333 120.638 109.615 118.876 111.876L111.95 120.763C105.729 128.747 94.2733 128.747 88.0518 120.763L81.126 111.876C79.3647 109.615 76.7854 108.333 74.0906 108.333L26.3492 108.333L26.3493 143.333C26.3493 148.934 30.548 153.333 35.5634 153.333L164.436 153.333C169.452 153.333 173.65 148.934 173.651 143.333L173.651 108.333ZM47.4937 53.3339L152.505 53.3333C159.195 53.3332 165.081 57.8972 167.226 64.5898L180 104.454L180 143.333C180 152.46 173.105 159.999 164.436 159.999L35.5635 160C26.8946 160 20.0001 152.46 20 143.333L20 104.454L32.7731 64.5908C34.9176 57.898 40.804 53.334 47.4937 53.3339Z"
fill="#8ED0FA"
/>
<rect
x="93.334"
width="13.3333"
height="40"
rx="6.66667"
fill="#B0F3FE"
/>
<rect
x="46.666"
y="6.66675"
width="13.3333"
height="40"
rx="6.66667"
transform="rotate(-30 46.666 6.66675)"
fill="#B0F3FE"
/>
<rect
x="141.666"
width="13.3333"
height="40"
rx="6.66667"
transform="rotate(30 141.666 0)"
fill="#B0F3FE"
/>
</svg>
);
};
9 changes: 9 additions & 0 deletions src/components/Icon/mdi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ export enum IconName {
mdiFlaskEmpty = 'M6,22A3,3 0 0,1 3,19C3,18.4 3.18,17.84 3.5,17.37L9,7.81V6A1,1 0 0,1 8,5V4A2,2 0 0,1 10,2H14A2,2 0 0,1 16,4V5A1,1 0 0,1 15,6V7.81L20.5,17.37C20.82,17.84 21,18.4 21,19A3,3 0 0,1 18,22H6Z',
mdiFlaskEmptyOutline = 'M5,19A1,1 0 0,0 6,20H18A1,1 0 0,0 19,19C19,18.79 18.93,18.59 18.82,18.43L13,8.35V4H11V8.35L5.18,18.43C5.07,18.59 5,18.79 5,19M6,22A3,3 0 0,1 3,19C3,18.4 3.18,17.84 3.5,17.37L9,7.81V6A1,1 0 0,1 8,5V4A2,2 0 0,1 10,2H14A2,2 0 0,1 16,4V5A1,1 0 0,1 15,6V7.81L20.5,17.37C20.82,17.84 21,18.4 21,19A3,3 0 0,1 18,22H6Z',
mdiFlaskOutline = 'M5,19A1,1 0 0,0 6,20H18A1,1 0 0,0 19,19C19,18.79 18.93,18.59 18.82,18.43L13,8.35V4H11V8.35L5.18,18.43C5.07,18.59 5,18.79 5,19M6,22A3,3 0 0,1 3,19C3,18.4 3.18,17.84 3.5,17.37L9,7.81V6A1,1 0 0,1 8,5V4A2,2 0 0,1 10,2H14A2,2 0 0,1 16,4V5A1,1 0 0,1 15,6V7.81L20.5,17.37C20.82,17.84 21,18.4 21,19A3,3 0 0,1 18,22H6M13,16L14.34,14.66L16.27,18H7.73L10.39,13.39L13,16M12.5,12A0.5,0.5 0 0,1 13,12.5A0.5,0.5 0 0,1 12.5,13A0.5,0.5 0 0,1 12,12.5A0.5,0.5 0 0,1 12.5,12Z',
mdiFolder = 'M10,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V8C22,6.89 21.1,6 20,6H12L10,4Z',
mdiFolderOpen = 'M19,20H4C2.89,20 2,19.1 2,18V6C2,4.89 2.89,4 4,4H10L12,6H19A2,2 0 0,1 21,8H21L4,8V18L6.14,10H23.21L20.93,18.5C20.7,19.37 19.92,20 19,20Z',
mdiFolderOpenOutline = 'M6.1,10L4,18V8H21A2,2 0 0,0 19,6H12L10,4H4A2,2 0 0,0 2,6V18A2,2 0 0,0 4,20H19C19.9,20 20.7,19.4 20.9,18.5L23.2,10H6.1M19,18H6L7.6,12H20.6L19,18Z',
mdiFolderOutline = 'M20,18H4V8H20M20,6H12L10,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V8C22,6.89 21.1,6 20,6Z',
mdiFormatBold = 'M13.5,15.5H10V12.5H13.5A1.5,1.5 0 0,1 15,14A1.5,1.5 0 0,1 13.5,15.5M10,6.5H13A1.5,1.5 0 0,1 14.5,8A1.5,1.5 0 0,1 13,9.5H10M15.6,10.79C16.57,10.11 17.25,9 17.25,8C17.25,5.74 15.5,4 13.25,4H7V18H14.04C16.14,18 17.75,16.3 17.75,14.21C17.75,12.69 16.89,11.39 15.6,10.79Z',
mdiFormatColorText = 'M9.62,12L12,5.67L14.37,12M11,3L5.5,17H7.75L8.87,14H15.12L16.25,17H18.5L13,3H11Z',
mdiFormatItalic = 'M10,4V7H12.21L8.79,15H6V18H14V15H11.79L15.21,7H18V4H10Z',
Expand All @@ -231,6 +235,7 @@ export enum IconName {
mdiGenderNonBinary = 'M13 3H11V5.27L9.04 4.13L8.04 5.87L10 7L8.04 8.13L9.04 9.87L11 8.73V12.1C8.72 12.56 7 14.58 7 17C7 19.76 9.24 22 12 22S17 19.76 17 17C17 14.58 15.28 12.56 13 12.1V8.73L14.96 9.87L15.96 8.13L14 7L15.96 5.87L14.96 4.13L13 5.27V3M12 20C10.35 20 9 18.65 9 17S10.35 14 12 14 15 15.35 15 17 13.65 20 12 20Z',
mdiGenderTransgender = 'M19.58,3H15V1H23V9H21V4.41L16.17,9.24C16.69,10.03 17,11 17,12C17,14.42 15.28,16.44 13,16.9V19H15V21H13V23H11V21H9V19H11V16.9C8.72,16.44 7,14.42 7,12C7,11 7.3,10.04 7.82,9.26L6.64,8.07L5.24,9.46L3.83,8.04L5.23,6.65L3,4.42V8H1V1H8V3H4.41L6.64,5.24L8.08,3.81L9.5,5.23L8.06,6.66L9.23,7.84C10,7.31 11,7 12,7C13,7 13.96,7.3 14.75,7.83L19.58,3M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9Z',
mdiGoogle = 'M21.35,11.1H12.18V13.83H18.69C18.36,17.64 15.19,19.27 12.19,19.27C8.36,19.27 5,16.25 5,12C5,7.9 8.2,4.73 12.2,4.73C15.29,4.73 17.1,6.7 17.1,6.7L19,4.72C19,4.72 16.56,2 12.1,2C6.42,2 2.03,6.8 2.03,12C2.03,17.05 6.16,22 12.25,22C17.6,22 21.5,18.33 21.5,12.91C21.5,11.76 21.35,11.1 21.35,11.1V11.1Z',
mdiHandBackRight = 'M13 24C9.74 24 6.81 22 5.6 19L2.57 11.37C2.26 10.58 3 9.79 3.81 10.05L4.6 10.31C5.16 10.5 5.62 10.92 5.84 11.47L7.25 15H8V3.25C8 2.56 8.56 2 9.25 2S10.5 2.56 10.5 3.25V12H11.5V1.25C11.5 .56 12.06 0 12.75 0S14 .56 14 1.25V12H15V2.75C15 2.06 15.56 1.5 16.25 1.5C16.94 1.5 17.5 2.06 17.5 2.75V12H18.5V5.75C18.5 5.06 19.06 4.5 19.75 4.5S21 5.06 21 5.75V16C21 20.42 17.42 24 13 24Z',
mdiHelp = 'M10,19H13V22H10V19M12,2C17.35,2.22 19.68,7.62 16.5,11.67C15.67,12.67 14.33,13.33 13.67,14.17C13,15 13,16 13,17H10C10,15.33 10,13.92 10.67,12.92C11.33,11.92 12.67,11.33 13.5,10.67C15.92,8.43 15.32,5.26 12,5A3,3 0 0,0 9,8H6A6,6 0 0,1 12,2Z',
mdiHelpCircle = 'M15.07,11.25L14.17,12.17C13.45,12.89 13,13.5 13,15H11V14.5C11,13.39 11.45,12.39 12.17,11.67L13.41,10.41C13.78,10.05 14,9.55 14,9C14,7.89 13.1,7 12,7A2,2 0 0,0 10,9H8A4,4 0 0,1 12,5A4,4 0 0,1 16,9C16,9.88 15.64,10.67 15.07,11.25M13,19H11V17H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z',
mdiHelpCircleOutline = 'M11,18H13V16H11V18M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,6A4,4 0 0,0 8,10H10A2,2 0 0,1 12,8A2,2 0 0,1 14,10C14,12 11,11.75 11,15H13C13,12.75 16,12.5 16,10A4,4 0 0,0 12,6Z',
Expand Down Expand Up @@ -308,6 +313,10 @@ export enum IconName {
mdiPlayCircle = 'M10,16.5V7.5L16,12M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z',
mdiPlayCircleOutline = 'M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M10,16.5L16,12L10,7.5V16.5Z',
mdiPlus = 'M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z',
mdiPlusBox = 'M17,13H13V17H11V13H7V11H11V7H13V11H17M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3Z',
mdiPlusBoxMultiple = 'M19,11H15V15H13V11H9V9H13V5H15V9H19M20,2H8A2,2 0 0,0 6,4V16A2,2 0 0,0 8,18H20A2,2 0 0,0 22,16V4A2,2 0 0,0 20,2M4,6H2V20A2,2 0 0,0 4,22H18V20H4V6Z',
mdiPlusBoxMultipleOutline = 'M18 11H15V14H13V11H10V9H13V6H15V9H18M20 4V16H8V4H20M20 2H8C6.9 2 6 2.9 6 4V16C6 17.11 6.9 18 8 18H20C21.11 18 22 17.11 22 16V4C22 2.9 21.11 2 20 2M4 6H2V20C2 21.11 2.9 22 4 22H18V20H4V6Z',
mdiPlusBoxOutline = 'M19,19V5H5V19H19M19,3A2,2 0 0,1 21,5V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V5C3,3.89 3.9,3 5,3H19M11,7H13V11H17V13H13V17H11V13H7V11H11V7Z',
mdiPlusCircle = 'M17,13H13V17H11V13H7V11H11V7H13V11H17M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z',
mdiPlusCircleOutline = 'M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M13,7H11V11H7V13H11V17H13V13H17V11H13V7Z',
mdiPlusThick = 'M20 14H14V20H10V14H4V10H10V4H14V10H20V14Z',
Expand Down
149 changes: 149 additions & 0 deletions src/components/Motion/CSSMotion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import React from 'react';
import { useRef } from 'react';
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 { isActive } from './hooks/useStepQueue';

export function genCSSMotion(): React.ForwardRefExoticComponent<
CSSMotionProps & { ref?: React.Ref<any> }
> {
const CSSMotion = React.forwardRef<any, CSSMotionProps>((props, ref) => {
const {
// Default config
visible = true,
removeOnLeave = true,

forceRender,
children,
motionName,
leavedClassName,
eventProps,
} = 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
const wrapperNodeRef = useRef();

function getDomElement() {
try {
// Here we're avoiding call for findDOMNode since it's deprecated
// in strict mode. We're calling it only when node ref is not
// an instance of DOM HTMLElement. Otherwise use
// findDOMNode as a final resort
return nodeRef.current instanceof HTMLElement
? nodeRef.current
: findDOMNode<HTMLElement>(wrapperNodeRef.current);
} catch (e) {
// Only happen when `motionDeadline` trigger but element removed.
return null;
}
}

const [status, statusStep, statusStyle, mergedVisible] = useStatus(
visible,
getDomElement,
props
);

// Record whether content has rendered
// Will return null for un-rendered even when `removeOnLeave={false}`
const renderedRef = React.useRef(mergedVisible);
if (mergedVisible) {
renderedRef.current = true;
}

// ====================== Refs ======================
const setNodeRef = React.useCallback(
(node: any) => {
nodeRef.current = node;
fillRef(ref, node);
},
[ref]
);

// ===================== Render =====================
let motionChildren: React.ReactNode;
const mergedProps = { ...eventProps, visible };

if (!children) {
// No children
motionChildren = null;
} else if (status === STATUS_NONE) {
// Stable children
if (mergedVisible) {
motionChildren = children({ ...mergedProps }, setNodeRef);
} else if (!removeOnLeave && renderedRef.current) {
motionChildren = children(
{ ...mergedProps, className: leavedClassName },
setNodeRef
);
} else if (forceRender) {
motionChildren = children(
{ ...mergedProps, style: { display: 'none' } },
setNodeRef
);
} else {
motionChildren = null;
}
} else {
// In motion
let statusSuffix: string;
if (statusStep === STEP_PREPARE) {
statusSuffix = 'prepare';
} else if (isActive(statusStep)) {
statusSuffix = 'active';
} else if (statusStep === STEP_START) {
statusSuffix = 'start';
}

motionChildren = children(
{
...mergedProps,
className: mergeClasses([
getTransitionName(motionName, status),
{
[getTransitionName(
motionName,
`${status}-${statusSuffix}`
)]: statusSuffix,
},
{
[motionName as string]:
typeof motionName === 'string',
},
]),
style: statusStyle,
},
setNodeRef
);
}

// Auto inject ref if child node not have `ref` props
if (React.isValidElement(motionChildren)) {
const { ref: originNodeRef } = motionChildren as any;

if (!originNodeRef) {
motionChildren = React.cloneElement(motionChildren, {
ref: setNodeRef,
});
}
}

return <DomWrapper ref={wrapperNodeRef}>{motionChildren}</DomWrapper>;
});

CSSMotion.displayName = 'CSSMotion';

return CSSMotion;
}

export default genCSSMotion();
Loading

0 comments on commit 77c9e6c

Please sign in to comment.