@collapsed/react
Advanced tools
Comparing version 4.1.0-experimental.79f518c to 5.0.0
{ | ||
"name": "@collapsed/react", | ||
"version": "4.1.0-experimental.79f518c", | ||
"version": "5.0.0", | ||
"author": "Rogin Farrer <rogin@roginfarrer.com>", | ||
"description": "A React custom-hook for creating flexible and accessible expand/collapse components.", | ||
"license": "MIT", | ||
"source": "src/index.ts", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"type": "module", | ||
"main": "./dist/useCollapse.cjs", | ||
"module": "./dist/useCollapse.js", | ||
"types": "./dist/useCollapse.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/useCollapse.cjs", | ||
"import": "./dist/useCollapse.js", | ||
"types": "./dist/useCollapse.d.ts" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"src" | ||
], | ||
@@ -22,26 +30,24 @@ "peerDependencies": { | ||
"@babel/preset-react": "^7.14.5", | ||
"@chromatic-com/storybook": "^1", | ||
"@cypress/vite-dev-server": "^5.0.0", | ||
"@storybook/addon-a11y": "^6.5.11", | ||
"@storybook/addon-actions": "^6.5.11", | ||
"@storybook/addon-essentials": "^6.5.11", | ||
"@storybook/addon-links": "^6.5.11", | ||
"@storybook/builder-vite": "^0.3.0", | ||
"@storybook/react": "^6.5.11", | ||
"@testing-library/cypress": "^8.0.7", | ||
"@testing-library/jest-dom": "^5.16.0", | ||
"@storybook/addon-a11y": "^8.1.3", | ||
"@storybook/addon-actions": "^8.1.3", | ||
"@storybook/addon-essentials": "^8.1.3", | ||
"@storybook/addon-links": "^8.1.3", | ||
"@storybook/react": "^8.1.3", | ||
"@storybook/react-vite": "^8.1.3", | ||
"@testing-library/cypress": "^10.0.2", | ||
"@testing-library/jest-dom": "^6.4.6", | ||
"@testing-library/react": "^13.4.0", | ||
"@types/jest": "^25.1.2", | ||
"@types/node": "^16.7.13", | ||
"@types/node": "^20", | ||
"@types/react": "^18", | ||
"@types/react-dom": "^18", | ||
"@types/styled-components": "^5.0.1", | ||
"@types/testing-library__jest-dom": "^5.14.5", | ||
"@types/testing-library__jest-dom": "^6.0.0", | ||
"@types/testing-library__react": "^10.2.0", | ||
"@vitejs/plugin-react": "^2.2.0", | ||
"@vitejs/plugin-react": "^4.3.0", | ||
"babel-loader": "^8.2.2", | ||
"cypress": "^11.2.0", | ||
"jest": "^29.3.1", | ||
"jest-environment-jsdom": "^29.3.1", | ||
"cypress": "^13.12.0", | ||
"happy-dom": "^14.12.0", | ||
"np": "^6.4.0", | ||
"prettier": "^2.3.2", | ||
"react": "^18", | ||
@@ -51,14 +57,14 @@ "react-docgen-typescript-loader": "^3.7.1", | ||
"styled-components": "^5.2.0", | ||
"ts-jest": "^29.0.3", | ||
"tslib": "^2.4.1", | ||
"tsup": "^6.5.0", | ||
"typescript": "^4.9", | ||
"vite": "^3.2.4", | ||
"eslint-config-collapsed": "0.0.0", | ||
"tsup": "^8", | ||
"typescript": "^5.4", | ||
"vite": "^4.5.3", | ||
"vitest": "^1.6.0", | ||
"@collapsed-internal/build": "0.0.0", | ||
"@collapsed-internal/tsconfig": "0.0.0" | ||
"@collapsed-internal/tsconfig": "0.0.0", | ||
"eslint-config-collapsed": "0.0.0" | ||
}, | ||
"dependencies": { | ||
"@collapsed/core": "4.1.0-experimental.79f518c", | ||
"tiny-warning": "^1.0.3" | ||
"tiny-warning": "^1.0.3", | ||
"@collapsed/core": "5.0.0" | ||
}, | ||
@@ -86,8 +92,8 @@ "repository": { | ||
"build": "tsup", | ||
"watch": "tsup --watch", | ||
"test": "jest src", | ||
"dev": "tsup --watch", | ||
"test": "vitest", | ||
"typecheck": "tsc --project tsconfig.json --noEmit", | ||
"lint": "eslint .", | ||
"storybook": "start-storybook -p 6006", | ||
"build-storybook": "build-storybook", | ||
"storybook": "storybook dev -p 6006", | ||
"build-storybook": "storybook build", | ||
"release": "np --no-2fa", | ||
@@ -94,0 +100,0 @@ "cypress:run": "cypress run --component" |
132
README.md
@@ -0,8 +1,9 @@ | ||
# NOTE | ||
You're probably looking for [react-collapsed](../react-collapsed). This package (alongside [@collapsed/core](../core)) is a WIP rewrite to create a Vanilla JS core. | ||
--- | ||
# @collapsed/react (useCollapse) | ||
[![CI][ci-badge]][ci] | ||
![npm bundle size (version)][minzipped-badge] | ||
[![npm version][npm-badge]][npm-version] | ||
[![Netlify Status](https://api.netlify.com/api/v1/badges/5a5b0e80-d15e-4983-976d-37fe6bdada7a/deploy-status)](https://app.netlify.com/sites/react-collapsed/deploys) | ||
A React hook for creating accessible expand/collapse components. Animates the height using CSS transitions from `0` to `auto`. | ||
@@ -35,7 +36,7 @@ | ||
```js | ||
import React from 'react' | ||
import { useCollapse } from '@collapsed/react' | ||
import React from "react"; | ||
import { useCollapse } from "@collapsed/react"; | ||
function Demo() { | ||
const { getCollapseProps, getToggleProps, isExpanded } = useCollapse() | ||
const { getCollapseProps, getToggleProps, isExpanded } = useCollapse(); | ||
@@ -45,7 +46,7 @@ return ( | ||
<button {...getToggleProps()}> | ||
{isExpanded ? 'Collapse' : 'Expand'} | ||
{isExpanded ? "Collapse" : "Expand"} | ||
</button> | ||
<section {...getCollapseProps()}>Collapsed content 🙈</section> | ||
</div> | ||
) | ||
); | ||
} | ||
@@ -57,8 +58,8 @@ ``` | ||
```js | ||
import React, { useState } from 'react' | ||
import { useCollapse } from '@collapsed/react' | ||
import React, { useState } from "react"; | ||
import { useCollapse } from "@collapsed/react"; | ||
function Demo() { | ||
const [isExpanded, setExpanded] = useState(false) | ||
const { getCollapseProps, getToggleProps } = useCollapse({ isExpanded }) | ||
const [isExpanded, setExpanded] = useState(false); | ||
const { getCollapseProps, getToggleProps } = useCollapse({ isExpanded }); | ||
@@ -72,7 +73,7 @@ return ( | ||
> | ||
{isExpanded ? 'Collapse' : 'Expand'} | ||
{isExpanded ? "Collapse" : "Expand"} | ||
</button> | ||
<section {...getCollapseProps()}>Collapsed content 🙈</section> | ||
</div> | ||
) | ||
); | ||
} | ||
@@ -83,47 +84,56 @@ ``` | ||
```js | ||
const { getCollapseProps, getToggleProps, isExpanded, setExpanded } = | ||
useCollapse({ | ||
isExpanded: boolean, | ||
defaultExpanded: boolean, | ||
expandStyles: {}, | ||
collapseStyles: {}, | ||
collapsedHeight: 0, | ||
easing: string, | ||
duration: number, | ||
onCollapseStart: func, | ||
onCollapseEnd: func, | ||
onExpandStart: func, | ||
onExpandEnd: func, | ||
}) | ||
`useCollapse` takes the following options: | ||
```ts | ||
interface UseCollapseOptions { | ||
/** If true, the disclosure is expanded. */ | ||
isExpanded?: boolean; | ||
/** | ||
* If true, the disclosure is expanded when it initially mounts. | ||
* @default false | ||
*/ | ||
defaultExpanded?: boolean; | ||
/** Handler called when the disclosure expands or collapses */ | ||
onExpandedChange?: (state: boolean) => void; | ||
/** Handler called at each stage of the animation. */ | ||
onTransitionStateChange?: ( | ||
state: | ||
| "expandStart" | ||
| "expanding" | ||
| "expandEnd" | ||
| "collapseStart" | ||
| "collapsing" | ||
| "collapseEnd", | ||
) => void; | ||
/** Timing function for the transition */ | ||
easing?: string; | ||
/** | ||
* Duration of the expand/collapse animation. | ||
* If 'auto', the duration will be calculated based on the height of the collapse element | ||
*/ | ||
duration?: "auto" | number; | ||
/** Height in pixels that the collapse element collapses to */ | ||
collapsedHeight?: number; | ||
/** | ||
* Unique identifier used to for associating elements appropriately for accessibility. | ||
*/ | ||
id?: string; | ||
} | ||
``` | ||
### `useCollapse` Config | ||
And returns the following API: | ||
The following are optional properties passed into `useCollapse({ })`: | ||
```ts | ||
interface CollapseAPI { | ||
isExpanded: boolean; | ||
setExpanded: (update: boolean | ((prev: boolean) => boolean)) => void; | ||
getToggleProps: <T extends HTMLElement>( | ||
props?: React.ComponentPropsWithoutRef<T> & { refKey?: string }, | ||
) => React.ComponentPropsWithRef<T>; | ||
getCollapseProps: <T extends HTMLElement>( | ||
props?: React.ComponentPropsWithoutRef<T> & { refKey?: string }, | ||
) => React.ComponentPropsWithRef<T>; | ||
} | ||
``` | ||
| Prop | Type | Default | Description | | ||
| -------------------- | -------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| isExpanded | boolean | `undefined` | If true, the Collapse is expanded | | ||
| defaultExpanded | boolean | `false` | If true, the Collapse will be expanded when mounted | | ||
| expandStyles | object | `{}` | Style object applied to the collapse panel when it expands | | ||
| collapseStyles | object | `{}` | Style object applied to the collapse panel when it collapses | | ||
| collapsedHeight | number | `0` | The height of the content when collapsed | | ||
| easing | string | `cubic-bezier(0.4, 0, 0.2, 1)` | The transition timing function for the animation | | ||
| duration | number | `undefined` | The duration of the animation in milliseconds. By default, the duration is programmatically calculated based on the height of the collapsed element | | ||
| onCollapseStart | function | no-op | Handler called when the collapse animation begins | | ||
| onCollapseEnd | function | no-op | Handler called when the collapse animation ends | | ||
| onExpandStart | function | no-op | Handler called when the expand animation begins | | ||
| onExpandEnd | function | no-op | Handler called when the expand animation ends | | ||
| hasDisabledAnimation | boolean | false | If true, will disable the animation | | ||
### What you get | ||
| Name | Description | | ||
| ---------------- | ----------------------------------------------------------------------------------------------------------- | | ||
| getCollapseProps | Function that returns a prop object, which should be spread onto the collapse element | | ||
| getToggleProps | Function that returns a prop object, which should be spread onto an element that toggles the collapse panel | | ||
| isExpanded | Whether or not the collapse is expanded (if not controlled) | | ||
| setExpanded | Sets the hook's internal isExpanded state | | ||
## Alternative Solutions | ||
@@ -158,9 +168,1 @@ | ||
</details> | ||
[minzipped-badge]: https://img.shields.io/bundlephobia/minzip/@collapsed/react/latest | ||
[npm-badge]: http://img.shields.io/npm/v/@collapsed/react.svg?style=flat | ||
[npm-version]: https://npmjs.org/package/@collapsed/react 'View this project on npm' | ||
[ci-badge]: https://github.com/roginfarrer/collapsed/workflows/CI/badge.svg | ||
[ci]: https://github.com/roginfarrer/collapsed/actions?query=workflow%3ACI+branch%3Amain | ||
[netlify]: https://app.netlify.com/sites/react-collapsed/deploys | ||
[netlify-badge]: https://api.netlify.com/api/v1/badges/4d285ffc-aa4f-4d32-8549-eb58e00dd2d1/deploy-status |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
45518
37
17
888
2
163
0
Yes
1
+ Added@collapsed/core@5.0.0(transitive)
- Removed@collapsed/core@4.1.0-experimental.79f518c(transitive)
Updated@collapsed/core@5.0.0