forked from chakra-ui/chakra-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5db3fa5
commit d744ded
Showing
10 changed files
with
454 additions
and
749 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,46 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
"ecmaVersion": 7 | ||
}, | ||
"plugins": ["@typescript-eslint", "react-hooks"], | ||
"extends": [ | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
"plugin:import/recommended", | ||
"plugin:import/typescript", | ||
"airbnb-typescript", | ||
"prettier", | ||
"prettier/react", | ||
"prettier/@typescript-eslint" | ||
], | ||
"plugins": [ | ||
"eslint-plugin-react-hooks", | ||
"@typescript-eslint/eslint-plugin", | ||
"eslint-plugin-testing-library" | ||
], | ||
"env": { | ||
"es6": true, | ||
"browser": true, | ||
"node": true | ||
}, | ||
"settings": { | ||
"react": { | ||
"pragma": "React", | ||
"version": "detect" | ||
} | ||
}, | ||
"rules": { | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/no-empty-interface": "off", | ||
"@typescript-eslint/camelcase": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/ban-ts-ignore": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"@typescript-eslint/no-use-before-define": "off", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/indent": "off", | ||
"@typescript-eslint/array-callback-return": "off", | ||
"@typescript-eslint/array-type": "off", | ||
"react-hooks/rules-of-hooks": "error", | ||
"react-hooks/exhaustive-deps": "warn", | ||
"@typescript-eslint/member-delimiter-style": "off", | ||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/ban-ts-comment": "off" | ||
"prettier/prettier": ["error", { "singleQuote": false }], | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"no-param-reassign": "off", | ||
"jsx-a11y/no-autofocus": "off", | ||
"react/forbid-prop-types": "off", | ||
"react/jsx-filename-extension": [ | ||
"error", | ||
{ "extensions": [".js", ".tsx"] } | ||
], | ||
"react/jsx-props-no-spreading": "off", | ||
"react/no-array-index-key": "off", | ||
"react/require-default-props": "off", | ||
"react/sort-prop-types": "error" | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { forwardRef, PropsOf } from "@chakra-ui/system" | ||
import { AnimatePresence, motion, Variant } from "framer-motion" | ||
import * as React from "react" | ||
|
||
export type MotionVariants<T extends string> = Record<T, Variant> | ||
|
||
export const collapseVariants: MotionVariants<"open" | "collapsed"> = { | ||
collapsed: (props: CollapseOptions) => ({ | ||
opacity: parseInt(props.startingHeight as string, 10) > 0 ? 1 : 0, | ||
height: props.startingHeight, | ||
transition: { duration: 0.15 }, | ||
}), | ||
open: (props: CollapseOptions) => ({ | ||
opacity: 1, | ||
height: props.endingHeight, | ||
transition: { | ||
duration: 0.3, | ||
ease: [0.04, 0.62, 0.23, 0.98], | ||
}, | ||
}), | ||
} | ||
|
||
export interface CollapseOptions { | ||
unMountOnExit?: boolean | ||
/** | ||
* If `true`, the content will be visible | ||
*/ | ||
isOpen?: boolean | ||
/** | ||
* The height you want the content in it's collapsed state. Set to `0` by default | ||
*/ | ||
startingHeight?: number | string | ||
/** | ||
* The height you want the content in it's expanded state. Set to `auto` by default | ||
*/ | ||
endingHeight?: number | string | ||
/** | ||
* The custom framer-motion variants to use | ||
*/ | ||
motionConfig?: MotionVariants<"open" | "collapsed"> | ||
} | ||
|
||
interface CollapseProps extends PropsOf<typeof motion.div>, CollapseOptions {} | ||
|
||
export const Collapse = forwardRef<CollapseProps, "div">((props, ref) => { | ||
const { | ||
isOpen, | ||
unMountOnExit, | ||
startingHeight = 0, | ||
endingHeight = "auto", | ||
motionConfig, | ||
style, | ||
...rest | ||
} = props | ||
|
||
/** | ||
* Warn 🚨: `startingHeight` and `unMountOnExit` are mutually exclusive | ||
* | ||
* If you specify a starting height, the collapsed needs to be mounted | ||
* for the height to take effect. | ||
*/ | ||
if (startingHeight > 0 && unMountOnExit) { | ||
console.warn( | ||
`startingHeight and unMountOnExit are mutually exclusive. You can't use them together`, | ||
) | ||
} | ||
|
||
const shouldExpand = unMountOnExit ? isOpen && unMountOnExit : true | ||
|
||
return ( | ||
<AnimatePresence initial={false} custom={{ startingHeight, endingHeight }}> | ||
{shouldExpand && ( | ||
<motion.div | ||
ref={ref} | ||
initial="collapsed" | ||
animate={isOpen || unMountOnExit ? "open" : "collapsed"} | ||
exit="collapsed" | ||
{...rest} | ||
variants={motionConfig ?? collapseVariants} | ||
style={{ overflow: "hidden", ...style }} | ||
custom={{ startingHeight, endingHeight }} | ||
/> | ||
)} | ||
</AnimatePresence> | ||
) | ||
}) | ||
|
||
Collapse.displayName = "Collapse" |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
export * from "./fade" | ||
export * from "./presets" | ||
export * from "./scale-fade" | ||
export * from "./slide" | ||
export * from "./slide-fade" | ||
export * from "./transition" | ||
export * from "./transition-config" | ||
export * from "./hidden-transition" | ||
export * from "./use-transition-config" | ||
export * from "./presets" | ||
export { CSSTransition } from "react-transition-group" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Variant } from "framer-motion" | ||
|
||
export type MotionVariants<T extends string> = { [K in T]?: Variant } | ||
|
||
export const fade: MotionVariants<"enter" | "exit"> = { | ||
enter: { | ||
opacity: 0, | ||
transition: { duration: 0.15, ease: [0.175, 0.885, 0.32, 1.175] }, | ||
}, | ||
exit: { opacity: 0 }, | ||
} | ||
|
||
export const collapse: MotionVariants<"open" | "collapsed"> = { | ||
open: { | ||
opacity: 1, | ||
height: "auto", | ||
transition: { | ||
duration: 0.3, | ||
ease: [0.04, 0.62, 0.23, 0.98], | ||
}, | ||
}, | ||
collapsed: { | ||
opacity: 0, | ||
height: 0, | ||
transition: { duration: 0.15 }, | ||
}, | ||
} |
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
Oops, something went wrong.