Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: accordion component (#6462)
* feat: add merge-refs * docs: update changelog * chore: update context * chore: update context * chore: add pure * refactor: accordion package * docs: add changelog * fix: update use-callback-ref * fix: typescript * chore: add script to update csb * chore: update context pkg * chore: update lockfile
- Loading branch information
1 parent
c89a802
commit dffc18b
Showing
25 changed files
with
284 additions
and
119 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@chakra-ui/accordion": patch | ||
--- | ||
|
||
Reduce bundle size of accordion by leverage smaller packages |
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,5 @@ | ||
--- | ||
"@chakra-ui/utils": patch | ||
--- | ||
|
||
Add pure annotation to utils package |
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
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import { useEffect, useMemo, useRef } from "react" | ||
import { useCallback, useEffect, useRef } from "react" | ||
|
||
export function useCallbackRef<T extends (...args: any[]) => any>( | ||
callback: T | undefined, | ||
deps: React.DependencyList = [], | ||
) { | ||
const callbackRef = useRef(callback) | ||
|
||
useEffect(() => { | ||
callbackRef.current = callback | ||
}) | ||
|
||
return useMemo<T>((...args) => callbackRef.current?.(...args), []) | ||
return useCallback(((...args) => callbackRef.current?.(...args)) as T, deps) | ||
} |
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,24 @@ | ||
# @chakra-ui/use-merge-refs | ||
|
||
A Quick description of the component | ||
|
||
> This is an internal utility, not intended for public usage. | ||
## Installation | ||
|
||
```sh | ||
yarn add @chakra-ui/use-merge-refs | ||
# or | ||
npm i @chakra-ui/use-merge-refs | ||
``` | ||
|
||
## Contribution | ||
|
||
Yes please! See the | ||
[contributing guidelines](https://github.com/chakra-ui/chakra-ui/blob/master/CONTRIBUTING.md) | ||
for details. | ||
|
||
## Licence | ||
|
||
This project is licensed under the terms of the | ||
[MIT license](https://github.com/chakra-ui/chakra-ui/blob/master/LICENSE). |
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 @@ | ||
export * from "./src" |
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,42 @@ | ||
{ | ||
"name": "@chakra-ui/react-use-merge-refs", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [ | ||
"use-merge-refs" | ||
], | ||
"author": "Segun Adebayo <sage@adebayosegun.com>", | ||
"homepage": "https://github.com/chakra-ui/chakra-ui#readme", | ||
"license": "MIT", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"types": "dist/index.d.ts", | ||
"sideEffects": false, | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/chakra-ui/chakra-ui.git", | ||
"directory": "hooks/use-merge-refs" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/chakra-ui/chakra-ui/issues" | ||
}, | ||
"scripts": { | ||
"build": "tsup src/index.ts --format=esm,cjs --dts", | ||
"dev": "pnpm build -- --watch", | ||
"clean": "rimraf dist .turbo", | ||
"typecheck": "tsc --noEmit", | ||
"build:fast": "tsup src/index.ts --format=esm,cjs" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=18" | ||
}, | ||
"devDependencies": { | ||
"react": "^18.0.0" | ||
} | ||
} |
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,33 @@ | ||
import { useMemo } from "react" | ||
|
||
export type ReactRef<T> = React.RefCallback<T> | React.MutableRefObject<T> | ||
|
||
export function assignRef<T = any>( | ||
ref: ReactRef<T> | null | undefined, | ||
value: T, | ||
) { | ||
if (ref == null) return | ||
|
||
if (typeof ref === "function") { | ||
ref(value) | ||
return | ||
} | ||
|
||
try { | ||
ref.current = value | ||
} catch (error) { | ||
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`) | ||
} | ||
} | ||
|
||
export function mergeRefs<T>(...refs: (ReactRef<T> | null | undefined)[]) { | ||
return (node: T | null) => { | ||
refs.forEach((ref) => { | ||
assignRef(ref, node) | ||
}) | ||
} | ||
} | ||
|
||
export function useMergeRefs<T>(...refs: (ReactRef<T> | null | undefined)[]) { | ||
return useMemo(() => mergeRefs(...refs), refs) | ||
} |
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
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
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.
dffc18b
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:
chakra-ui-storybook – ./
chakra-ui-storybook-chakra-ui.vercel.app
chakra-ui-storybook.vercel.app
chakra-ui-storybook-git-main-chakra-ui.vercel.app
storybook.chakra-ui.com