-
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.
Merge pull request #2 from tannguyencse19/v0.0.1
Update to V0.0.1
- Loading branch information
Showing
11 changed files
with
511 additions
and
85 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
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,113 @@ | ||
import { CSSObject } from "@chakra-ui/react"; | ||
import { nav } from "utils"; | ||
|
||
/** | ||
* @description CSSStyleObject for `_after, ::after` pseudo-element | ||
* @param condition Condition to generate underline | ||
* @returns | ||
* | ||
* _**NOTES**_ | ||
* | ||
* * Element contain `_after` must have style: `position: relative` | ||
* @example | ||
* ```jsx | ||
* <Box | ||
* position="relative" | ||
* _after={_afterUnderlineStyle(your_condition)} | ||
* > | ||
* ``` | ||
* | ||
* * To display animation, use `:hover:after` with `_sxHoverAfterUnderlineStyle`. See below. | ||
* | ||
* --- | ||
* * Basic usage | ||
* @example | ||
* ```jsx | ||
* _after={_afterUnderlineStyle(your_condition)} | ||
* ``` | ||
* * Extend/Override style. If overrideStyle don't work, try to use `!important` | ||
* @example | ||
* ```jsx | ||
* _after={_afterUnderlineStyle(your_condition, { | ||
* transition: "transform 1s ease-in-out !important", | ||
* })} | ||
* ``` | ||
* | ||
* * Animation | ||
* @example | ||
* ```jsx | ||
* _after={_afterUnderlineStyle(your_condition)} | ||
* sx={{ | ||
* "&:hover:after": _sxHoverAfterUnderlineStyle() | ||
* }} | ||
* ``` | ||
*/ | ||
export function _afterUnderlineStyle( | ||
condition: boolean, | ||
overrideStyle?: CSSObject | ||
) { | ||
const baseStyle: CSSObject = { | ||
content: `""`, | ||
width: "100%", | ||
height: "2px", | ||
position: "absolute", | ||
bottom: "0", | ||
overflow: "hidden", | ||
transition: "transform 275ms ease", | ||
}; | ||
const conditionStyle: CSSObject = condition | ||
? { | ||
// active state | ||
opacity: "1", | ||
backgroundColor: nav._bordorColor?.active, | ||
transform: "scaleX(1)", | ||
} | ||
: { | ||
// hover state | ||
opacity: "0.5", | ||
backgroundColor: nav._bordorColor?.hover, | ||
transform: "scaleX(0)", | ||
}; | ||
|
||
return Object.assign(baseStyle, conditionStyle, overrideStyle); | ||
} | ||
|
||
/** | ||
* @description Animation for `_afterUnderlineStyle()` | ||
* @returns CSSObject | ||
* | ||
* --- | ||
* | ||
* * Basic usage | ||
* @example | ||
* ```jsx | ||
* _after={_afterUnderlineStyle(your_condition)} | ||
* sx={{ | ||
* "&:hover:after": _sxHoverAfterUnderlineStyle() | ||
* }} | ||
* ``` | ||
* | ||
* * Extend/Override style. If overrideStyle don't work, try to use `!important` | ||
* @example | ||
* ```jsx | ||
* "&:hover:after": _sxHoverAfterUnderlineStyle({ | ||
* transform: "unset", | ||
transformOrigin: "0% 50% !important", | ||
* }) | ||
* ``` | ||
* | ||
* --- | ||
* | ||
* Animation example | ||
* @see https://stackoverflow.com/questions/28623446/hover-effect-expand-bottom-border | ||
*/ | ||
export function _sxHoverAfterUnderlineStyle(overrideStyle?: CSSObject) { | ||
const baseStyle = { | ||
backgroundColor: nav._bordorColor?.hover, | ||
transform: "scaleX(1) !important", | ||
mixBlendMode: "normal", | ||
opacity: "0.5", | ||
}; | ||
|
||
return Object.assign(baseStyle, overrideStyle); | ||
} |
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,64 @@ | ||
import { Variant } from "framer-motion"; | ||
|
||
// type Merge<P, T> = Omit<P, keyof T> & T; | ||
|
||
// type BoxMotionProps = Merge<BoxProps, HTMLMotionProps<"div">>; | ||
// export const BoxMotion: React.FC<BoxMotionProps> = motion(Box); | ||
|
||
/** | ||
* @description Strengthen _framer-motion_ `Variants, Variant` type | ||
* @example | ||
* ```jsx | ||
* const boxVariants: CustomVariantsProps = { | ||
* // syntax --> key_name: { properties } | ||
* hidden: { transform: "translateY(25%)", opacity: 0 }, | ||
* visible: { | ||
* transform: "translateY(0%)", | ||
* opacity: 1, | ||
* transition: { duration: 1.5, ease: "linear" }, | ||
* }, | ||
* }; | ||
* ``` | ||
*/ | ||
export interface CustomVariantsProps { | ||
[key: string]: Variant | any; | ||
} | ||
|
||
/** | ||
* @description Use to create Rotate with Zoom animation | ||
* | ||
* * Defining | ||
* @example | ||
* ```jsx | ||
* const planetVariant: RotateWithZoomVariantProps = { | ||
* visible: { | ||
* rotate: [0, 360], | ||
* transition: { duration: 60, ease: "linear", repeat: Infinity }, // for rotate | ||
* }, | ||
* hover: { | ||
* scale: 1.1, | ||
* }, | ||
* // for hover | ||
* hoverTransition: { | ||
* duration: 0.6, | ||
* ease: "easeOut", | ||
* }, | ||
* }; | ||
* ``` | ||
* | ||
* * Usage | ||
* @example | ||
* ```jsx | ||
* <motion.div | ||
* variants={planetVariant} | ||
* animate="visible" | ||
* whileHover="hover" | ||
* transition={planetVariant.hoverTransition} | ||
* > | ||
* ``` | ||
*/ | ||
export interface RotateWithZoomVariantProps extends CustomVariantsProps { | ||
visible: Variant; | ||
hover: Variant; | ||
hoverTransition: Variant | any; | ||
} |
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,37 @@ | ||
import { chakra, shouldForwardProp } from "@chakra-ui/react"; | ||
import NextLink from "next/link"; | ||
import { NextRouter } from "next/router"; | ||
|
||
export const NextLinkHelper = chakra(NextLink, { | ||
shouldForwardProp: (prop) => { | ||
// don't forward Chakra's props | ||
const isChakraProp = !shouldForwardProp(prop); | ||
if (isChakraProp) return false; | ||
|
||
// else, only forward `sample` prop | ||
return [ | ||
"href", | ||
"as", | ||
"replace", | ||
"scroll", | ||
"shallow", | ||
"passHref", | ||
"prefetch", | ||
"locale", | ||
].includes(prop); | ||
}, | ||
}); | ||
|
||
// https://stackoverflow.com/questions/43335962/purpose-of-declare-keyword-in-typescript | ||
// Summary: declare fix loi bien nay da khai bao roi --> khai bao lai | ||
declare type Url = URL | string; | ||
|
||
/** | ||
* Strengthen original router.push() | ||
* @param router Component's current using router | ||
* @param url | ||
* @returns `router.push(url, undefined, { shallow: true })` | ||
*/ | ||
export function routerShallowPush(router: NextRouter, url: Url) { | ||
return router.push(url, undefined, { shallow: true }); | ||
} |
This file was deleted.
Oops, something went wrong.
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,2 +1,3 @@ | ||
export * from "./NextLinkHelper" | ||
export * from "./framer-motion" | ||
export * from "./NextHelper" | ||
export * from "./FramerMotionHelper" | ||
export * from "./DynamicStyle" |
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.
bc97f44
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: