diff --git a/.changeset/README.md b/.changeset/README.md new file mode 100644 index 0000000..e5b6d8d --- /dev/null +++ b/.changeset/README.md @@ -0,0 +1,8 @@ +# Changesets + +Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works +with multi-package repos, or single-package repos to help you version and publish your code. You can +find the full documentation for it [in our repository](https://github.com/changesets/changesets) + +We have a quick list of common questions to get you started engaging with this project in +[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/.changeset/config.json b/.changeset/config.json new file mode 100644 index 0000000..7fcf973 --- /dev/null +++ b/.changeset/config.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://unpkg.com/@changesets/config@2.2.0/schema.json", + "changelog": "@changesets/cli/changelog", + "commit": false, + "fixed": [], + "linked": [], + "access": "restricted", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/.changeset/witty-birds-search.md b/.changeset/witty-birds-search.md new file mode 100644 index 0000000..bddbe7a --- /dev/null +++ b/.changeset/witty-birds-search.md @@ -0,0 +1,17 @@ +--- +'@collapsed/core': major +'@collapsed/react': major +--- + +## BREAKING CHANGES + +- Adopts React 18's `useId`, making the library incompatible with React <18 +- Switch to `tsup` from `microbundle` for bundling library. No longer exports a UMD version, just CJS and MJS + +## Features & Bug fixes + +- Refactors core functionality to vanilla JS (with a React) adapter, which I think should fix #103 and fix #100 +- Added `onExpandedChange` option +- Tries to detect if `getToggleProps` is used. If the toggle element ref can be accessed, the `aria-labelledby` attribute will be added to the collapse element +- Added `role="region"` to collapse +- Updated toggle props to pass the appropriate attributes to the element, whether it's a button or not diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..d944fff --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,55 @@ +name: Tests + +on: + push: + branches: + - main + pull_request: + +jobs: + main: + runs-on: ubuntu-latest + # To use Turborepo Remote Caching, set the following environment variables for the job. + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - uses: pnpm/action-setup@v2 + name: Install pnpm + id: pnpm-install + with: + version: latest + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'pnpm' + + - name: Install Dependencies + run: pnpm install + + - name: Build + run: pnpm build + + - name: Lint + run: pnpm lint + + - name: Test + run: pnpm test + + - name: Cypress + run: cd packages/react && npx cypress install && npx cypress run --component && cd - + + # - name: Cypress run + # uses: cypress-io/github-action@v5 + # with: + # command-prefix: npx + # install: false + # component: true + # working-directory: ./packages/react diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a29c8b6..55b3c61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,45 +1,59 @@ -name: Release npm package +name: Release on: push: branches: - main - pull_request: jobs: - test: - name: 'CI' + release: + name: Publish & Deploy runs-on: ubuntu-latest + env: + CI: true + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Node.js + uses: actions/setup-node@v3 with: - node-version: 14 - - name: Install Dependencies - uses: bahmutov/npm-install@v1 - - name: Build - run: yarn build - - name: Lint - run: yarn lint - - name: Test - run: yarn test + node-version: 16 - release: - name: Publish to NPM - needs: test - # publish only when merged in master on original repo, not on PR - if: github.repository == 'roginfarrer/react-collapsed' && github.ref == 'refs/heads/main' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: pnpm/action-setup@v2 + name: Install pnpm + id: pnpm-install with: - node-version: 14 + version: 7 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install Dependencies - uses: bahmutov/npm-install@v1 + run: pnpm install + - name: Build - run: yarn build - - run: npx semantic-release + run: pnpm build + + - name: Create release PR or publish to npm + uses: changesets/action@v1 + with: + publish: pnpm publish env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index 37bf862..c9d81e6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ node_modules .cache dist storybook-static +.turbo +.parcel-cache diff --git a/.nvmrc b/.nvmrc index c2324e8..6f7f377 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -14.18.0 +v16 diff --git a/LICENSE b/LICENSE index fa36fcc..e7cfe86 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,20 @@ -MIT License +The MIT License (MIT) -Copyright (c) 2019-2020 Rogin Farrer +Copyright (c) 2019-2023, Rogin Farrer -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/MIGRATION-2.x-to-3.x.md b/MIGRATION-2.x-to-3.x.md deleted file mode 100644 index e0d1a3d..0000000 --- a/MIGRATION-2.x-to-3.x.md +++ /dev/null @@ -1,98 +0,0 @@ -# Migrating from 2.x to 3.x - -## BREAKING CHANGES - -- `useCollapse` has been completely rewritten in TypeScript, and now exports types. -- `useCollapse` configuration has changed: - - `isOpen` -> `isExpanded` - - `defaultOpen` -> `defaultExpanded` - - `expandStyles.transitionDuration` and `collapseStyles.transitionDuration` have been moved to a single `duration` property - - `expandStyles.transitionTimingFunction` and `collapseStyles.transitionTimingFunction` have been moved to a single `easing` property -- `useCollapse` output has changed: - - `isOpen` -> `isExpanded` - - `mountChildren` has been removed. Event hooks are now provided to recreate this feature. [See below for more](#mountChildren) - - `toggleOpen` has been replaced with `setExpanded`, which requires a boolean that sets the expanded state, or a callback that returns a boolean. -- The default transition duration has been changed from `500ms` to being calculated based on the height of the collapsed content. Encouraged to leave this default since it will provide more natural animations. -- The default transition curve has been changed from `cubic-bezier(0.250, 0.460, 0.450, 0.940)` to `ease-in-out`, or `cubic-bezier(0.4, 0, 0.2, 1)` - -See below for more detail on the above changes. - -## Input - -The hook's property names have been changed for clarity: - -- `isOpen` -> `isExpanded` -- `defaultOpen` -> `defaultExpanded` - -In 2.x, the customizing the transition duration and easing was done by setting `transitionDuration` and `transitionTimingFunction` in `expandStyles` or `collapseStyles`. Those have been both pulled out and promoted to top-level settings via `duration` and `easing`, respectively. - -The default value for `duration` is also no longer a fixed value. Instead, the duration is calculated based on the height of the collapsed content to create more natural transitions. - -The transition easing was also updated from a custom curve to a more basic `ease-in-out` curve. - -In summary: - -```diff -const collapse = useCollaspse({ - collapseStyles: {}, - expandStyles: {}, - collapsedHeight: number, -- isOpen: boolean, -- defaultOpen: boolean, -+ duration: number, -+ easing: string, -+ isExpanded: boolean, -+ defaultExpanded: boolean, -+ onCollapseStart() {}, -+ onCollapseEnd() {}, -+ onExpandStart() {}, -+ onExpandEnd() {}, -}) -``` - -## Output - -- `isOpen` -> `isExpanded` -- `toggleOpen` -> `setExpanded` -- `mountChildren` has been removed. - -`setExpanded` now also supports an argument to set the expanded state. Previously, to toggle the expanded state, you would just call the `toggleOpen` function: - -```javascript - -``` - -Now, you must provide a boolean or a function that returns a boolean: - -```javascript - -``` - -### `mountChildren` - -`mountChildren` has been removed. In order to recreate the same functionality, you can hook into the `onExpandStart` and `onCollapseEnd` hooks: - -```javascript -function Collapse() { - const [mountChildren, setMountChildren] = useState(false) - const { getToggleProps, getCollapseProps } = useCollapse({ - onCollapseEnd() { - setMountChildren(false) - }, - onExpandStart() { - setMountChildren(true) - }, - }) - - return ( -
I will only render when expanded!
} -padding
to the component that gets getCollapseProps
, the animation is janky and it doesn't collapse all the way. What gives?