diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 55fdad025c..0000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,148 +0,0 @@ -version: 2 - -refs: - container: &container - docker: - - image: node:12.22.1 - working_directory: ~/repo - steps: - - &Versions - run: - name: Versions - command: node -v && npm -v && yarn -v - - &CacheRestore - restore_cache: - key: dependency-cache-{{ checksum "yarn.lock" }} - - &Install - run: - name: Install Dependencies - command: yarn install --pure-lockfile - - &CacheSave - save_cache: - key: dependency-cache-{{ checksum "yarn.lock" }} - paths: - - ./node_modules - - &Build - run: - name: Build - command: yarn build - - &Build_Storybook - run: - name: Build Storybook - command: yarn storybook:build - - &Lint - run: - name: Lint - command: yarn lint - - &Test - run: - name: Test - command: yarn test - - &Upload_Storybook - run: - name: Upload Storybook - command: yarn storybook:upload - - &Release - run: - name: Release - command: yarn release - - &Commit_Status_Storybook - run: - name: Post commit status for Storybook - command: | - npx cross-ci :run curl -H "'Authorization: token \${GITHUB_TOKEN}' -H 'Accept: application/vnd.github.v3+json'" \ - "'https://api.github.com/repos/\${PROJECT_OWNER}/\${PROJECT_NAME}/statuses/$CIRCLE_SHA1'" -X POST \ - -d "'{\"state\": \"success\", \"context\": \"Storybook\", \"description\": \"\${BUILD_VERSION}\", \"target_url\": \"https://$CIRCLE_BUILD_NUM-154950925-gh.circle-artifacts.com/0/root/repo/storybook-static/index.html\"}'" - -jobs: - all: - <<: *container - steps: - - checkout - - *Versions - - *CacheRestore - - *Install - - *CacheSave - - *Build - - *Build_Storybook - - *Test - - *Lint - - store_artifacts: - path: ~/repo/storybook-static - - *Commit_Status_Storybook - - next: - <<: *container - steps: - - checkout - - *Versions - - *CacheRestore - - *Install - - *CacheSave - - *Build - - *Build_Storybook - - *Test - - *Lint - - store_artifacts: - path: ~/repo/storybook-static - - *Commit_Status_Storybook - - run: - name: Setup GitHub - command: | - git config --global user.email "streamich@gmail.com" - git config --global user.name "streamich" - git remote rm origin - git remote add origin https://${GITHUB_TOKEN}@github.com/streamich/react-use - - *Release - - master: - <<: *container - steps: - - checkout - - *Versions - - *CacheRestore - - *Install - - *CacheSave - - *Build - - *Build_Storybook - - *Test - - *Lint - - store_artifacts: - path: ~/repo/storybook-static - - *Commit_Status_Storybook - - run: - name: Setup GitHub - command: | - git config --global user.email "streamich@gmail.com" - git config --global user.name "streamich" - git remote rm origin - git remote add origin https://${GITHUB_TOKEN}@github.com/streamich/react-use - - *Upload_Storybook - - *Release - -workflows: - version: 2 - all: - jobs: - - all: - context: common-env-vars - filters: - branches: - ignore: - - master - - next - - gh-pages - next: - jobs: - - next: - context: common-env-vars - filters: - branches: - only: next - master: - jobs: - - master: - context: common-env-vars - filters: - branches: - only: master diff --git a/.eslintrc.js b/.eslintrc.js index bc52136957..58d020238b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,5 @@ module.exports = { - extends: ['prettier/@typescript-eslint', 'react-app', 'plugin:prettier/recommended'], + extends: ['react-app', 'prettier'], plugins: ['prettier'], rules: { 'prettier/prettier': [ diff --git a/.github/workflows/check-codebase.yml b/.github/workflows/check-codebase.yml new file mode 100644 index 0000000000..be17d2e23d --- /dev/null +++ b/.github/workflows/check-codebase.yml @@ -0,0 +1,90 @@ +name: Check codebase + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: 20 + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run build + run: yarn build + + # storybook: + # name: Storybook + # runs-on: ubuntu-latest + # steps: + # - name: Check out repository + # uses: actions/checkout@v2 + + # - name: Setup node + # uses: actions/setup-node@v1 + # with: + # node-version: 20 + + # - name: Install dependencies + # run: yarn install --frozen-lockfile + + # - name: Run build:storybook + # run: yarn storybook:build + + lint: + name: Linting + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: 20 + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Lint with ESLint + run: yarn lint + + - name: Lint with TSC + if: ${{ always() }} + run: yarn lint:types + + unit-tests: + name: Unit tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, ubuntu-latest] + node: [20, 22] + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run unit tests + run: yarn test diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml new file mode 100644 index 0000000000..f732451311 --- /dev/null +++ b/.github/workflows/mirror.yml @@ -0,0 +1,21 @@ +name: Node.js CI + +on: + push: + branches: [master] + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Push To Gitlab + env: + token: ${{ secrets.GITLAB_TOKEN }} + run: | + git config user.name "streamich" + git config user.email "react-use+streamich@users.noreply.github.com" + git remote add mirror "https://oauth2:${token}@gitlab.com/streamich/react-use.git" + git push mirror master diff --git a/.github/workflows/pull_request_ci.yml b/.github/workflows/pull_request_ci.yml deleted file mode 100644 index 3d7b602b42..0000000000 --- a/.github/workflows/pull_request_ci.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Node CI - -on: [pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [10.x, 12.x] - - steps: - - uses: actions/checkout@v1 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: npm install, build, and test - run: | - yarn install --pure-lockfile - yarn build - yarn test - env: - CI: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..81ed2cc471 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Node.js CI + +on: + push: + branches: [master, next] + +jobs: + release: + if: ${{ github.event_name == 'push' && (github.event.ref == 'refs/heads/master' || github.event.ref == 'refs/heads/next') }} + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [22.x] + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: yarn + - run: yarn install --frozen-lockfile + - run: yarn lint + - run: yarn test + - run: yarn lint:types + - run: yarn build + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 628c2e767e..2b3362796e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,97 @@ +# [17.6.0](https://github.com/streamich/react-use/compare/v17.5.1...v17.6.0) (2024-12-09) + + +### Features + +* add onChange callback to useWindowSize ([ea656f7](https://github.com/streamich/react-use/commit/ea656f7e751b8366360ce2aa8238057bbbc1251a)) +* add onChange callback to useWindowSize ([3eb531a](https://github.com/streamich/react-use/commit/3eb531ac9e9e04641df29aafbd2677869cdcb085)) + +## [17.5.1](https://github.com/streamich/react-use/compare/v17.5.0...v17.5.1) (2024-07-20) + + +### Bug Fixes + +* 🐛 bump nano-css dependency ([adfb337](https://github.com/streamich/react-use/commit/adfb337d5b11427798afc5a21c6ebdaa76212182)) + +# [17.5.0](https://github.com/streamich/react-use/compare/v17.4.4...v17.5.0) (2024-01-22) + + +### Features + +* add `isFirst` and `isLast` methods to `useStateList` hook ([ac64414](https://github.com/streamich/react-use/commit/ac64414bea4c8afadfb382da9fea44ee89b41e2d)) +* **pencil:** add isFirst and isLast return value to 'useStateList' ([75218e4](https://github.com/streamich/react-use/commit/75218e45dfdcdc6ea193e278cb97ceee98c00f1b)) +* **pencil:** fix with yarn lint:fix ([6a9dde5](https://github.com/streamich/react-use/commit/6a9dde596ae25c0dd2fa97b0cf354143fbc5b5ff)) + +## [17.4.4](https://github.com/streamich/react-use/compare/v17.4.3...v17.4.4) (2024-01-21) + + +### Bug Fixes + +* typo in example ([0534648](https://github.com/streamich/react-use/commit/05346481a15a321b13838eead0bda3024b0d163f)) + +## [17.4.3](https://github.com/streamich/react-use/compare/v17.4.2...v17.4.3) (2024-01-13) + + +### Bug Fixes + +* update useMedia hook to use recommended approach of MDN ([e7379f0](https://github.com/streamich/react-use/commit/e7379f088787cbf9274c1fc21d36061f04855e4c)) + +## [17.4.2](https://github.com/streamich/react-use/compare/v17.4.1...v17.4.2) (2023-12-01) + + +### Bug Fixes + +* correct peer dependencies ([d770587](https://github.com/streamich/react-use/commit/d77058729654397b68b251e8211bf0edc0b4ed50)) + +## [17.4.1](https://github.com/streamich/react-use/compare/v17.4.0...v17.4.1) (2023-11-28) + + +### Bug Fixes + +* 🐛 bump nano-css version ([812952b](https://github.com/streamich/react-use/commit/812952bb9ff004a844ec4285ad6c65d39597b11c)) + +# [17.4.0](https://github.com/streamich/react-use/compare/v17.3.3...v17.4.0) (2022-05-20) + + +### Features + +* add usePinchZoom sensor hook ([3e042cb](https://github.com/streamich/react-use/commit/3e042cb2f3022349a53199b5cc5c380e3ebd9975)) + +## [17.3.3](https://github.com/streamich/react-use/compare/v17.3.2...v17.3.3) (2022-05-20) + + +### Bug Fixes + +* bump React peer dependency version ([532e865](https://github.com/streamich/react-use/commit/532e8653a50d39dd439d9664d4813a1d7a5b4f3c)) +* resolve [#2319](https://github.com/streamich/react-use/issues/2319) ([4884b2c](https://github.com/streamich/react-use/commit/4884b2c74085e0841af7c36cca34e16d698d1b4c)) +* resolve @types/react@18 break change, React.FC ([20b7817](https://github.com/streamich/react-use/commit/20b78178d0033cc2e0c2a904e413b20ee864c816)) + +## [17.3.2](https://github.com/streamich/react-use/compare/v17.3.1...v17.3.2) (2021-12-30) + + +### Bug Fixes + +* useMedia SSR hydration bug with defaultState ([#2216](https://github.com/streamich/react-use/issues/2216)) ([5c01189](https://github.com/streamich/react-use/commit/5c0118941280bb265ca7813afb987f89c8c97a17)) + +## [17.3.1](https://github.com/streamich/react-use/compare/v17.3.0...v17.3.1) (2021-08-31) + + +### Performance Improvements + +* ⚡️ change title only if it changed ([51ef8d9](https://github.com/streamich/react-use/commit/51ef8d99bad31186ec5420d8b729748507c8a1bf)) + +# [17.3.0](https://github.com/streamich/react-use/compare/v17.2.4...v17.3.0) (2021-08-31) + + +### Bug Fixes + +* do not re-render unncessarily in useAsyncFn hook ([fa3ba25](https://github.com/streamich/react-use/commit/fa3ba2520ede6866b599f6df55fdfa6395058cd2)) + + +### Features + +* useAudio add playing state ([3203610](https://github.com/streamich/react-use/commit/3203610efdcb8e1fe3c6a17ea19e41bacbeb851b)) + ## [17.2.4](https://github.com/streamich/react-use/compare/v17.2.3...v17.2.4) (2021-04-23) diff --git a/README.md b/README.md index 284f94e121..cc1728fafd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,3 @@ -
- - Collaborative editing for your app. Support on Kickstarter! - -
- -


@@ -77,6 +70,7 @@ - [`useMeasure`](./docs/useMeasure.md) and [`useSize`](./docs/useSize.md) — tracks an HTML element's dimensions. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usemeasure--demo) - [`createBreakpoint`](./docs/createBreakpoint.md) — tracks `innerWidth` - [`useScrollbarWidth`](./docs/useScrollbarWidth.md) — detects browser's native scrollbars width. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usescrollbarwidth--demo) + - [`usePinchZoom`](./docs/usePinchZoom.md) — tracks pointer events to detect pinch zoom in and out status. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/sensors-usePinchZoom--demo)

- [**UI**](./docs/UI.md) @@ -128,8 +122,8 @@ - [`useMount`](./docs/useMount.md) — calls `mount` callbacks. - [`useUnmount`](./docs/useUnmount.md) — calls `unmount` callbacks. - [`useUpdateEffect`](./docs/useUpdateEffect.md) — run an `effect` only on updates. - - [`useIsomorphicLayoutEffect`](./docs/useIsomorphicLayoutEffect.md) — `useLayoutEffect` that does not show warning when server-side rendering. - - [`useDeepCompareEffect`](./docs/useDeepCompareEffect.md), [`useShallowCompareEffect`](./docs/useShallowCompareEffect.md), and [`useCustomCompareEffect`](./docs/useCustomCompareEffect.md) — run an `effect` depending on deep comparison of its dependencies + - [`useIsomorphicLayoutEffect`](./docs/useIsomorphicLayoutEffect.md) — `useLayoutEffect` that that works on server. + - [`useDeepCompareEffect`](./docs/useDeepCompareEffect.md), [`useShallowCompareEffect`](./docs/useShallowCompareEffect.md), and [`useCustomCompareEffect`](./docs/useCustomCompareEffect.md)

- [**State**](./docs/State.md) diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000000..a5497b62af --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,13 @@ +# Security Policy + +## Supported Versions + +We release patches for security vulnerabilities. The latest major version +will support security patches. + +## Reporting a Vulnerability + +Please report (suspected) security vulnerabilities to +**[streamich@gmail.com](mailto:streamich@gmail.com)**. We will try to respond +within 48 hours. If the issue is confirmed, we will release a patch as soon +as possible depending on complexity. diff --git a/docs/Usage.md b/docs/Usage.md index 90da532b99..243e354f88 100644 --- a/docs/Usage.md +++ b/docs/Usage.md @@ -16,10 +16,19 @@ Depending on your bundler you might run into a missing dependency error with ES6 ```json [ - "import", { - "libraryName": "react-use", - "libraryDirectory": "lib", - "camel2DashComponentName": false - } -] + 'import', + { + libraryName: 'react-use', + camel2DashComponentName: false, + customName(/** @type {string} */ name) { + const libraryDirectory = name.startsWith('Use') + ? 'lib/component' + : name.startsWith('create') + ? 'lib/factory' + : 'lib' + return `react-use/${libraryDirectory}/${name}` + } + }, + 'import-react-use' + ] ``` diff --git a/docs/useAudio.md b/docs/useAudio.md index 84184037e5..8939060400 100644 --- a/docs/useAudio.md +++ b/docs/useAudio.md @@ -64,10 +64,13 @@ render tree, for example: "duration": 425.952625, "paused": false, "muted": false, - "volume": 1 + "volume": 1, + "playing": true } ``` +`playing`: The audio is being played and is affected by the network. If it starts to buffer audio, it will be false + `controls` is a list collection of methods that allow you to control the playback of the audio, it has the following interface: @@ -85,4 +88,4 @@ interface AudioControls { `ref` is a React reference to HTML `