diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 1c2d4b524..000000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -test/coverage/ -dist/ diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 0e1b9c08b..000000000 --- a/.eslintrc.json +++ /dev/null @@ -1,92 +0,0 @@ -{ - "root": true, - "extends": [ - "airbnb", - "prettier", - "plugin:storybook/recommended" - ], - "parser": "@babel/eslint-parser", - "env": { - "browser": true, - "node": true, - "es6": true - }, - "plugins": [ - "react" - ], - "rules": { - "react/forbid-foreign-prop-types": 0, - "comma-dangle": 0, - "new-cap": 0, - "arrow-body-style": 0, - "prefer-template": 0, - "no-underscore-dangle": 0, - "object-shorthand": 0, - "func-names": 0, - "dot-notation": 0, - "max-len": 0, - "camelcase": 0, - "react/jsx-pascal-case": 0, - "prefer-const": 0, - "operator-linebreak": 0, - "react/jsx-filename-extension": 0, - "linebreak-style": 0, - "react/require-extension": 0, - "react/no-children-prop": 0, - "react/require-default-props": 0, - "react/forbid-prop-types": 0, - "jsx-a11y/no-noninteractive-element-interactions": 0, - "import/no-webpack-loader-syntax": 0, - "import/no-unresolved": 0, - "react/jsx-props-no-spreading": 0, - "react/destructuring-assignment": 0, - "jsx-a11y/click-events-have-key-events": 0, - "jsx-a11y/no-static-element-interactions": 0, - "react/jsx-no-constructed-context-values": 0, - "consistent-return": 0, - "no-restricted-globals": 0, - "no-nested-ternary": 0, - "import/prefer-default-export": 0, - "prefer-destructuring": [ - "error", - { - "array": false, - "object": true - } - ], - "import/no-extraneous-dependencies": 0, - "no-param-reassign": 0, - "jsx-a11y/mouse-events-have-key-events": 0 - }, - "parserOptions": { - "sourceType": "module", - "ecmaFeatures": { - "jsx": true, - "arrowFunctions": true, - "blockBindings": true, - "defaultParams": true, - "destructuring": true, - "forOf": true, - "generators": true, - "objectLiteralComputedProperties": true, - "objectLiteralShorthandMethods": true, - "objectLiteralShorthandProperties": true, - "experimentalObjectRestSpread": true, - "restParams": true, - "spread": true, - "templateStrings": true, - "modules": true, - "classes": true - } - }, - "overrides": [ - { - "files": [ - "testUtils.js" - ], - "env": { - "jest": true - } - } - ] -} \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 206c92516..9c3e99c13 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -1,7 +1,6 @@ --- name: Bug report about: Create a report to help us improve - --- - components: `name` @@ -34,6 +33,6 @@ paste error message with stacktrack here diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 601dea123..4d3b08f0a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,101 +1,15 @@ version: 2 updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - time: "13:00" - open-pull-requests-limit: 10 - ignore: - - dependency-name: conventional-recommended-bump - versions: - - ">= 5.a, < 6" - - dependency-name: conventional-recommended-bump - versions: - - ">= 6.a, < 7" - - dependency-name: cross-env - versions: - - ">= 5.a, < 6" - - dependency-name: cross-env - versions: - - ">= 6.a, < 7" - - dependency-name: cross-env - versions: - - ">= 7.a, < 8" - - dependency-name: css-loader - versions: - - ">= 3.a, < 4" - - dependency-name: customize-cra - versions: - - ">= 1.a, < 2" - - dependency-name: ejs - versions: - - ">= 3.a, < 4" - - dependency-name: raw-loader - versions: - - ">= 4.a, < 5" - - dependency-name: react-helmet - versions: - - ">= 6.a, < 7" - - dependency-name: react-router - versions: - - ">= 4.a, < 5" - - dependency-name: react-router - versions: - - ">= 5.a, < 6" - - dependency-name: react-scripts - versions: - - "> 2.1.1" - - dependency-name: react-scripts - versions: - - ">= 3.a, < 4" - - dependency-name: react-transition-group - versions: - - ">= 4.a, < 5" - - dependency-name: rollup - versions: - - ">= 2.a, < 3" - - dependency-name: rollup-plugin-babel-minify - versions: - - ">= 10.a, < 11" - - dependency-name: rollup-plugin-babel-minify - versions: - - ">= 9.a, < 10" - - dependency-name: rollup-plugin-node-resolve - versions: - - ">= 5.a, < 6" - - dependency-name: style-loader - versions: - - ">= 1.a, < 2" - - dependency-name: css-loader - versions: - - 5.0.1 - - 5.0.2 - - 5.1.0 - - 5.1.1 - - 5.1.2 - - 5.1.3 - - 5.1.4 - - 5.2.0 - - 5.2.1 - - 5.2.3 - - dependency-name: "@types/react" - versions: - - 17.0.1 - - 17.0.2 - - 17.0.3 - - dependency-name: mini-css-extract-plugin - versions: - - 1.3.5 - - 1.3.6 - - 1.3.7 - - 1.3.8 - - 1.3.9 - - dependency-name: "@babel/plugin-proposal-object-rest-spread" - versions: - - 7.12.13 - - 7.13.0 - - dependency-name: webpack-cli - versions: - - 4.4.0 - - 4.5.0 + - package-ecosystem: npm + directory: / + schedule: + interval: weekly + groups: + storybook: + patterns: ['storybook', '@storybook/*'] + testing: + patterns: ['vitest', '@vitest/*', '@testing-library/*', 'jsdom'] + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..0b46ac530 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,26 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + +permissions: + contents: read + +jobs: + ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-node@v7 + with: + node-version-file: .nvmrc + cache: npm + - run: npm ci + - run: npm run lint + - run: npm run format:check + - run: npm run typecheck + - run: npm run cover + - run: npm run build + - run: npm run build:docs diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index a7a230c82..000000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Test Coverage - -on: - push: - branches: [ master, bootstrap5 ] - pull_request: - branches: [ master, bootstrap5 ] - -jobs: - - build: - runs-on: ubuntu-latest - steps: - - - uses: actions/checkout@v2 - - - name: Use Node.js 12.x - uses: actions/setup-node@v1 - with: - node-version: 12.x - cache: 'yarn' - - - run: rm -rf node_modules && yarn install --frozen-lockfile - - name: Run Coverage - run: | - npm run cover -- --runInBand - - name: Upload to Coveralls - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 49b49a86e..b37f557ea 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,18 +1,34 @@ -name: Manually Publish Docs -on: workflow_dispatch +name: Docs + +on: + release: + types: [published] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: pages + cancel-in-progress: true + jobs: - build: + deploy: runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} steps: - - uses: actions/checkout@v2 - # Setup .npmrc file to publish to npm - - uses: actions/setup-node@v2 + - uses: actions/checkout@v7 + - uses: actions/setup-node@v7 with: - node-version: '12.x' - registry-url: 'https://registry.npmjs.org' - - name: Install dependencies - run: rm -rf node_modules && yarn install --frozen-lockfile - - name: Publish Docs - env: - GITHUB_TOKEN: ${{ secrets.REACTSTRAP_DOCS_GITHUB_TOKEN }} - run: ./scripts/docs + node-version-file: .nvmrc + cache: npm + - run: npm ci && npm run build:docs + - uses: actions/upload-pages-artifact@v5 + with: + path: build + - id: deployment + uses: actions/deploy-pages@v5 diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 10ffaedf7..20be4e618 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -1,46 +1,33 @@ +name: Release + on: push: - branches: - - master -name: Release Bot -jobs: - release-pr: - runs-on: ubuntu-latest - steps: - - uses: GoogleCloudPlatform/release-please-action@v3 - id: release-please - with: - release-type: node - package-name: "reactstrap" - changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":true},{"type":"refactor","section":"Miscellaneous","hidden":false}]' - command: release-pr + branches: [master] + +permissions: + contents: write + pull-requests: write + packages: write +jobs: release: runs-on: ubuntu-latest steps: - - uses: GoogleCloudPlatform/release-please-action@v3 + - uses: googleapis/release-please-action@v5 id: release with: - release-type: node - package-name: "reactstrap" - command: github-release - - uses: actions/checkout@v2 - if: ${{ steps.release.outputs.release_created }} - - uses: actions/setup-node@v2 + config-file: release-please-config.json + manifest-file: .release-please-manifest.json + - if: ${{ steps.release.outputs.release_created }} + uses: actions/checkout@v7 + - if: ${{ steps.release.outputs.release_created }} + uses: actions/setup-node@v7 with: - node-version: '16.x' - registry-url: 'https://registry.npmjs.org' - if: ${{ steps.release.outputs.release_created }} - - name: Install dependencies - run: rm -rf node_modules && yarn install --frozen-lockfile - if: ${{ steps.release.outputs.release_created }} - - name: Publish package - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - if: ${{ steps.release.outputs.release_created }} - - name: Publish Docs + node-version-file: .nvmrc + cache: npm + registry-url: https://npm.pkg.github.com + scope: '@conventioncatcorp' + - if: ${{ steps.release.outputs.release_created }} + run: npm ci && npm publish env: - GITHUB_TOKEN: ${{ secrets.REACTSTRAP_TOKEN }} - run: ./scripts/docs - if: ${{ steps.release.outputs.release_created }} + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 5332c8cd8..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,32 +0,0 @@ -# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node.js CI - -on: - push: - branches: [ master, release-* ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [12.x, 14.x, 16.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - cache: 'yarn' - - run: rm -rf node_modules && yarn install --frozen-lockfile - - run: npm run lint - - run: npm run build --if-present - - run: npm run test:ci diff --git a/.gitignore b/.gitignore index a296b70e6..273e1d723 100644 --- a/.gitignore +++ b/.gitignore @@ -2,11 +2,7 @@ node_modules /dist /build -/lib -/esm -/es +/storybook-static .DS_Store .idea -.history -npm-debug.log -package-lock.json +*.log diff --git a/.nvmrc b/.nvmrc index 48082f72f..6f4247a62 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -12 +26 diff --git a/.oxlintrc.json b/.oxlintrc.json new file mode 100644 index 000000000..0c33b3452 --- /dev/null +++ b/.oxlintrc.json @@ -0,0 +1,44 @@ +{ + "$schema": "./node_modules/oxlint/configuration_schema.json", + "plugins": ["typescript", "react", "jsx-a11y", "import", "unicorn", "vitest"], + "categories": { + "correctness": "error", + "suspicious": "warn" + }, + "env": { + "browser": true + }, + "ignorePatterns": [ + "dist", + "build", + "coverage", + "storybook-static", + "src/__tests__/typings.tsx" + ], + "rules": { + "react/react-in-jsx-scope": "off", + "react/no-children-prop": "off", + "react/jsx-key": "error", + "react/rules-of-hooks": "error", + "react/exhaustive-deps": "warn", + "import/no-cycle": "error", + "typescript/no-explicit-any": "off", + "vitest/require-mock-type-parameters": "off", + "vitest/expect-expect": [ + "error", + { + "assertFunctionNames": ["expect", "testFor*"] + } + ] + }, + "overrides": [ + { + "files": ["src/__tests__/**", "src/testUtils.tsx"], + "rules": { + "jsx-a11y/anchor-is-valid": "off", + "jsx-a11y/anchor-has-content": "off", + "unicorn/consistent-function-scoping": "off" + } + } + ] +} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..1436996e7 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +dist +build +coverage +CHANGELOG.md +package-lock.json +static diff --git a/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index 0967ef424..000000000 --- a/.prettierrc.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 000000000..3d6970222 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1 @@ +{ ".": "9.2.3" } diff --git a/.storybook/main.cjs b/.storybook/main.cjs deleted file mode 100644 index 3a41deab1..000000000 --- a/.storybook/main.cjs +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - stories: [ - '../stories/**/*.stories.mdx', - '../stories/**/*.stories.js' - ], - addons: [ - '@storybook/addon-links', - '@storybook/addon-docs' - ], - staticDirs: ['../static'] -}; diff --git a/.storybook/main.ts b/.storybook/main.ts new file mode 100644 index 000000000..b7857279c --- /dev/null +++ b/.storybook/main.ts @@ -0,0 +1,23 @@ +import { fileURLToPath } from 'node:url'; +import type { StorybookConfig } from '@storybook/react-vite'; + +export default { + framework: '@storybook/react-vite', + stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(ts|tsx)'], + addons: ['@storybook/addon-links', '@storybook/addon-docs'], + staticDirs: ['../static'], + viteFinal(config) { + // vite.config.ts is the library build; keep its plugins, drop lib mode. + delete config.build?.lib; + delete config.build?.rolldownOptions?.output; + config.resolve = { + ...config.resolve, + alias: { + '@conventioncatcorp/reactstrap': fileURLToPath( + new URL('../src/index.ts', import.meta.url), + ), + }, + }; + return config; + }, +} satisfies StorybookConfig; diff --git a/.storybook/manager-head.html b/.storybook/manager-head.html index 3266b9c00..fa88bea7a 100644 --- a/.storybook/manager-head.html +++ b/.storybook/manager-head.html @@ -1 +1 @@ - + diff --git a/.storybook/manager.cjs b/.storybook/manager.cjs deleted file mode 100644 index e5f450653..000000000 --- a/.storybook/manager.cjs +++ /dev/null @@ -1,43 +0,0 @@ -import { addons } from '@storybook/addons'; -import { STORY_RENDERED } from '@storybook/core-events' -import { create } from '@storybook/theming'; - -const theme = create({ - base: 'light', - brandTitle: 'Reactstrap', - brandUrl: 'https://github.com/reactstrap/reactstrap', - brandImage: 'logo.svg', -}); - -addons.setConfig({ - theme -}); - -addons.register('TitleAddon', api => { - const customTitle = 'Reactstrap'; - let interval = null; - const setTitle = () => { - clearTimeout(interval); - - let storyData = null; - try { - storyData = api.getCurrentStoryData(); - } catch(e) {} - - let title; - if (!storyData) { - title = customTitle; - } else { - title = `${storyData.kind} - ${storyData.name} ⋅ ${customTitle}` - } - - if (document.title !== title) { - document.title = title; - } - interval = setTimeout(setTitle, 100); - }; - setTitle(); - api.on(STORY_RENDERED, story => { - setTitle(); - }) -}) diff --git a/.storybook/manager.ts b/.storybook/manager.ts new file mode 100644 index 000000000..bacfb02c4 --- /dev/null +++ b/.storybook/manager.ts @@ -0,0 +1,11 @@ +import { addons } from 'storybook/manager-api'; +import { create } from 'storybook/theming'; + +addons.setConfig({ + theme: create({ + base: 'light', + brandTitle: 'Reactstrap', + brandUrl: 'https://github.com/ConventionCatCorp/reactstrap', + brandImage: 'logo.svg', + }), +}); diff --git a/.storybook/preview-head.html b/.storybook/preview-head.html index adfb667a5..9dae4a589 100644 --- a/.storybook/preview-head.html +++ b/.storybook/preview-head.html @@ -1,13 +1,9 @@ - \ No newline at end of file + diff --git a/.storybook/preview.cjs b/.storybook/preview.cjs deleted file mode 100644 index 660fc6f52..000000000 --- a/.storybook/preview.cjs +++ /dev/null @@ -1,18 +0,0 @@ -export const parameters = { - actions: { argTypesRegex: "^on[A-Z].*" }, - controls: { - hideNoControlsWarning: true, - matchers: { - date: /Date$/ - }, - }, - options: { - storySort: { - order: ['Home', ['Installation', 'GitHub', 'Upgrading', 'Themes'], '*'] - } - }, - viewMode: 'docs', - previewTabs: { - canvas: { hidden: true }, - }, -} diff --git a/.storybook/preview.ts b/.storybook/preview.ts new file mode 100644 index 000000000..33703817c --- /dev/null +++ b/.storybook/preview.ts @@ -0,0 +1,15 @@ +// oxlint-disable-next-line import/no-unassigned-import -- global Bootstrap styles +import 'bootstrap/dist/css/bootstrap.min.css'; +import type { Preview } from '@storybook/react-vite'; + +export default { + tags: ['autodocs'], + parameters: { + controls: { hideNoControlsWarning: true, matchers: { date: /Date$/ } }, + options: { + storySort: { + order: ['Home', ['Installation', 'GitHub', 'Upgrading', 'Themes'], '*'], + }, + }, + }, +} satisfies Preview; diff --git a/.storybook/webpack.config.cjs b/.storybook/webpack.config.cjs deleted file mode 100644 index 21208aa9a..000000000 --- a/.storybook/webpack.config.cjs +++ /dev/null @@ -1,11 +0,0 @@ -const path = require('path'); - -module.exports = async ({ config }) => { - config.resolve = { - alias: { - reactstrap: path.resolve(__dirname, '../src/') - }, - }; - - return config; -}; diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..4d4895d2d --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,66 @@ +# AGENTS.md + +Guidance for coding agents working in this repo. + +## What this is + +`reactstrap` v10 (fork): stateless-ish React 19 components rendering Bootstrap 5 markup. No Bootstrap JS, no jQuery. +Positioning via `@popperjs/core`. Bootstrap 6 is out of scope (separate migration). + +## Stack + +- Node 26 (`.nvmrc`), npm (no yarn). TypeScript 7 (`tsc` is the native compiler, no JS API). +- Library build: Vite 8 lib mode (oxc, no Babel), ESM only, `preserveModules` → `dist/`; `.d.ts` from `tsc -p tsconfig.build.json`. +- Tests: Vitest + jsdom + Testing Library (user-event 14, async). Lint: oxlint. Format: Prettier. Docs: Storybook 10 (Vite). + +## Commands + +```sh +npm ci +npm test # vitest watch +npm run test:ci # vitest run +npm run cover # with coverage (lcov → coveralls in CI) +npm run typecheck # tsc, whole repo incl. tests + stories +npm run lint # oxlint --deny-warnings +npm run format # prettier --write . +npm run build # dist/ +npm start # storybook on :8080 +npm run build:docs # storybook static build → build/ +``` + +Single test: `npx vitest run src/__tests__/Modal.spec.tsx -t "should close"`. +CI (`.github/workflows/ci.yml`) runs lint, format:check, typecheck, cover, build, build:docs — keep all green. + +## Layout + +- `src/.tsx` — one component per file: `export interface Props` + `export default`. +- `src/index.ts` — the public barrel. Anything not exported here is internal. +- `src/utils.ts` — shared helpers and shared types (`CSSModule`, `Tag`, `Target`, `InnerRef`). Exposed as `Util`. +- `src/Transition.tsx` — internal replacement for `react-transition-group` (`Transition`, `useNodeRef`). +- `src/popper.tsx` — internal replacement for `react-popper` (`Manager`, `Reference`, `Popper`). +- `src/*Context.ts` — typed React contexts. +- `src/__tests__/*.spec.tsx` — Vitest specs; `typings.tsx` and `polymorphic.*.tsx` are compile-only type tests. +- `src/__mocks__/popper.tsx` — used via `vi.mock('../popper')`. +- `stories/` — Storybook docs; `@conventioncatcorp/reactstrap` resolves to `src/index.ts` (tsconfig `paths` + Storybook alias). + +## Conventions + +- No `prop-types`, no `defaultProps` on function components (React 19 ignores them). Defaults live in destructuring. + Class components may keep `static defaultProps`; `PopperContent.defaultProps` is public API (apps patch `offset`). +- No index signatures on props. Components with `tag`: `XOwnProps` + `XProps = XOwnProps & +PolymorphicExtras` (spell `XOwnProps` out, or Storybook docgen loses the props table); + classes use `PolymorphicClassExtras` and `declare props: XProps`. Add ok/`@ts-expect-error` cases to + `src/__tests__/polymorphic.*.tsx`. +- `innerRef` is public API; function components render `ref={innerRef ?? ref}` so React 19 `ref` works too. +- Transitions: use `Transition` with a `nodeRef` (never `findDOMNode`). Callbacks receive `(node, isAppearing)`. +- Use `import type` for types (`verbatimModuleSyntax`). Named React imports, no `import React` unless needed. +- Class names go through `mapToCssModules(classNames(...), cssModule)`. +- Bootstrap 5 only: don't add Bootstrap 4 classes/props back. +- Commits: Conventional Commits (release-please builds the changelog and releases from `master`). + +## Gotchas + +- `tsc` has no JS API in TS 7: tools needing the TS compiler API (e.g. vite-plugin-dts, react-docgen-typescript) won't work. + Declarations come from `tsc`; Storybook uses `react-docgen`. +- Fake timers + user-event: `userEvent.setup({ advanceTimers: vi.advanceTimersByTime })` and wrap timer advances in `act`. +- `npm run typecheck` covers tests and stories too — they must compile. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 2680b24b8..dfdf56972 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation. Examples of behavior that contributes to creating a positive environment include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or - advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting ## Our Responsibilities diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea5d8a41b..0664ef5b8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,20 +5,20 @@ If you have found an issue or would like to request a new feature, simply create ## Found an Issue? If you find a bug in the source code or a mistake in the documentation, you can help us by -submitting an issue to our [GitHub Repository](https://github.com/reactstrap/reactstrap/issues/new). Even better you can submit a Pull Request +submitting an issue to our [GitHub Repository](https://github.com/ConventionCatCorp/reactstrap/issues/new). Even better you can submit a Pull Request with a fix. **Please see the Submission Guidelines below**. ## Want a Feature? -You can request a new feature by submitting an issue to our [GitHub Repository](https://github.com/reactstrap/reactstrap/issues/new). If you +You can request a new feature by submitting an issue to our [GitHub Repository](https://github.com/ConventionCatCorp/reactstrap/issues/new). If you would like to implement a new feature then consider what kind of change it is: -- **Major Changes** that you wish to contribute to the project should be discussed first in a [GitHub Issue](https://github.com/reactstrap/reactstrap/issues/new) or [Slack](https://reactstrap.slack.com) so that we can better coordinate our efforts, prevent +- **Major Changes** that you wish to contribute to the project should be discussed first in a [GitHub Issue](https://github.com/ConventionCatCorp/reactstrap/issues/new) so that we can better coordinate our efforts, prevent duplication of work, and help you to craft the change so that it is successfully accepted into the - project. Slack invites can be obtained [here](https://reactstrap.herokuapp.com/). -- **Small Changes** can be crafted and submitted to the [GitHub Repository](https://github.com/reactstrap/reactstrap) as a Pull Request. + project. +- **Small Changes** can be crafted and submitted to the [GitHub Repository](https://github.com/ConventionCatCorp/reactstrap) as a Pull Request. ### Submitting a Pull Request @@ -28,16 +28,14 @@ If you wish to submit a pull request for a new feature or issue, you should star - Intermediate and work-in-progress commits should be rebased out. - Keep pull requests tightly scoped to the issue or feature being addressed. - All changes from every developer must go through code review before they will be merged. -- All changes must pass the CI build. Travis CI will automatically update your PR with the build status. +- All changes must pass the CI build (GitHub Actions). - All changes must have unit tests. -- All changes must have Typescript types in the [`types`](./types) directory. -- All components must have a demo implementation in the `docs/lib/examples` directory. -- Make sure to run `yarn lint` and `yarn prettier` on your work before submitting the PR +- Components are TypeScript; their exported `XProps` are the public types (no separate `types/` folder). +- All components must have a story in `stories/`. +- Make sure `npm run lint`, `npm run typecheck`, `npm run format:check` and `npm run test:ci` pass before submitting the PR ## Resources - [Codepen Demo](http://codepen.io/eddywashere/pen/ZOjmkm) -- [Slack](https://reactstrap.slack.com) - - [Get Slack Invite](https://reactstrap.herokuapp.com/) - [Ask Stackoverflow](http://stackoverflow.com/questions/ask?tags=reactstrap+react) - [View Stackoverflow reactstrap tag](http://stackoverflow.com/questions/tagged/reactstrap) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 2fd9890a4..a5e70442e 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,4 +1,5 @@ + ### Issue description - components: `name` @@ -35,7 +36,6 @@ Fork one of the following links and update it to demonstrate your issue. [StackBlitz](https://stackblitz.com/edit/reactstrap?file=Example.js) [CodeSandbox Starter](https://codesandbox.io/s/github/reactstrap/code-sandbox-examples/tree/main/starter) [CodeSandbox TypeScript Starter](https://codesandbox.io/s/github/reactstrap/code-sandbox-examples/tree/main/starter-ts) - -and/or add the code which causes the issue directly here - --> +and/or add the code which causes the issue directly here + --> diff --git a/README.md b/README.md index de3b95b0d..b695ccb67 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,39 @@ [![reactstrap](https://cloud.githubusercontent.com/assets/399776/13906899/1de62f0c-ee9f-11e5-95c0-c515fee8e918.png)](https://reactstrap.github.io) -[![NPM Version](https://img.shields.io/npm/v/reactstrap.svg?branch=master)](https://www.npmjs.com/package/reactstrap) [![Build Status](https://github.com/reactstrap/reactstrap/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/reactstrap/reactstrap) [![Coverage Status](https://coveralls.io/repos/github/reactstrap/reactstrap/badge.svg?branch=master)](https://coveralls.io/github/reactstrap/reactstrap?branch=master) [![License](https://img.shields.io/npm/l/reactstrap.svg)](https://github.com/reactstrap/reactstrap/blob/master/LICENSE) +[![CI](https://github.com/ConventionCatCorp/reactstrap/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/ConventionCatCorp/reactstrap/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) -# reactstrap +# @conventioncatcorp/reactstrap -Stateless React Components for Bootstrap 5. - -If you're using Bootstrap 4, you'll need to use [Reactstrap v8](https://deploy-preview-2356--reactstrap.netlify.app/) - -## Getting Started - -Follow the [create-react-app instructions](https://create-react-app.dev/docs/getting-started) to get started and then follow the reactstrap version of [adding bootstrap](#adding-bootstrap). - -### tl;dr - - ``` -npx create-react-app my-app -cd my-app/ -npm start -``` -or, if npx (Node >= 6 and npm >= 5.2 ) not available +Stateless React components for Bootstrap 5. A maintained fork of [reactstrap](https://github.com/reactstrap/reactstrap) (v9), published to GitHub Packages. +```ini +# .npmrc +@conventioncatcorp:registry=https://npm.pkg.github.com ``` -npm install -g create-react-app - -create-react-app my-app -cd my-app/ -npm start -``` -Then open [http://localhost:3000/](http://localhost:3000/) to see your app. The initial structure of your app is setup. Next, let's [add reactstrap and bootstrap](#adding-bootstrap). - -### Adding Bootstrap +## Getting Started -Install reactstrap and Bootstrap from NPM. Reactstrap does not include Bootstrap CSS so this needs to be installed as well: +reactstrap 10 targets **React 19+** and **Bootstrap 5** and ships as ESM with bundled TypeScript types. -``` -npm i bootstrap -npm i reactstrap react react-dom +```sh +npm create vite@latest my-app -- --template react-ts +cd my-app +npm i @conventioncatcorp/reactstrap bootstrap ``` -Import Bootstrap CSS in the ```src/index.js``` file: +Import Bootstrap CSS once (e.g. `src/main.tsx`): -```js +```ts import 'bootstrap/dist/css/bootstrap.css'; ``` -Import required reactstrap components within ```src/App.js``` file or your custom component files: +Then use components: -```js -import { Button } from 'reactstrap'; +```tsx +import { Button } from '@conventioncatcorp/reactstrap'; ``` -Now you are ready to use the imported reactstrap components within your component hierarchy defined in the render -method. Here is an example [`App.js`](https://gist.github.com/Thomas-Smyth/006fd507a7295f17a8473451938f9935) redone -using reactstrap. +Upgrading from 9.x? See [v10-migration.md](v10-migration.md). ### Dependencies @@ -62,93 +41,81 @@ using reactstrap. These libraries are not bundled with Reactstrap and required at runtime: - * [**react**](https://www.npmjs.com/package/react) - * [**react-dom**](https://www.npmjs.com/package/react-dom) +- [**react**](https://www.npmjs.com/package/react) `>=19` +- [**react-dom**](https://www.npmjs.com/package/react-dom) `>=19` +- [**bootstrap**](https://getbootstrap.com/docs/5.3/) 5.x CSS (not a package dependency; you load it) ## About the Project -This library contains React Bootstrap components that favor composition and control. The library does not depend on jQuery or Bootstrap javascript. However, [Poppers.js](https://popper.js.org/) via [react-popper](https://github.com/popperjs/react-popper) is relied upon for advanced positioning of content like Tooltips, Popovers, and auto-flipping Dropdowns. +This library contains React Bootstrap components that favor composition and control. The library does not depend on jQuery or Bootstrap javascript. However, [Popper](https://popper.js.org/) (`@popperjs/core`) is relied upon for advanced positioning of content like Tooltips, Popovers, and auto-flipping Dropdowns. There are a few core concepts to understand in order to make the most out of this library. 1. Your content is expected to be composed via props.children rather than using named props to pass in Components. - ```js - // Content passed in via props - const Example = (props) => { - return ( -

This is a tooltip example!

- ); - } - - // Content passed in as children (Preferred) - const PreferredExample = (props) => { - return ( -

- This is a tooltip example. - - - -

- ); - } - ``` + ```js + // Content passed in via props + const Example = (props) => { + return ( +

+ This is a tooltip{' '} + example! +

+ ); + }; + + // Content passed in as children (Preferred) + const PreferredExample = (props) => { + return ( +

+ This is a{' '} + + tooltip + {' '} + example. + + + +

+ ); + }; + ``` 2. Attributes in this library are used to pass in state, conveniently apply modifier classes, enable advanced functionality (like tether), or automatically include non-content based elements. - Examples: - - - `isOpen` - current state for items like dropdown, popover, tooltip - - `toggle` - callback for toggling `isOpen` in the controlling component - - `color` - applies color classes, ex: ` - - ); -} - -AccordionHeader.propTypes = propTypes; - -export default AccordionHeader; diff --git a/src/AccordionHeader.tsx b/src/AccordionHeader.tsx new file mode 100644 index 000000000..e19c4f45e --- /dev/null +++ b/src/AccordionHeader.tsx @@ -0,0 +1,63 @@ +import { useContext, type ElementType, type Ref } from 'react'; +import classNames from 'classnames'; +import { + mapToCssModules, + type CSSModule, + type PolymorphicExtras, +} from './utils'; +import { AccordionContext } from './AccordionContext'; + +export interface AccordionHeaderOwnProps { + /** Add custom class */ + className?: string; + /** Change existing base class name with a new class name */ + cssModule?: CSSModule; + innerRef?: Ref; + /** Unique key used to control item's collapse/expand */ + targetId: string; +} + +export type AccordionHeaderProps = + AccordionHeaderOwnProps & PolymorphicExtras; + +function AccordionHeader({ + className, + cssModule, + tag, + innerRef, + ref, + children, + targetId, + ...attributes +}: AccordionHeaderProps) { + const Tag: ElementType = tag ?? 'h2'; + const { open, toggle } = useContext(AccordionContext); + + const classes = mapToCssModules( + classNames(className, 'accordion-header'), + cssModule, + ); + + const buttonClasses = mapToCssModules( + classNames('accordion-button', { + collapsed: !(Array.isArray(open) + ? open.includes(targetId) + : open === targetId), + }), + cssModule, + ); + + return ( + + + + ); +} + +export default AccordionHeader; diff --git a/src/AccordionItem.js b/src/AccordionItem.js deleted file mode 100644 index 2c2fb3732..000000000 --- a/src/AccordionItem.js +++ /dev/null @@ -1,39 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import classNames from 'classnames'; -import { mapToCssModules, tagPropType } from './utils'; - -const propTypes = { - children: PropTypes.node, - /** To add custom class */ - className: PropTypes.string, - /** Change existing base class name with a new class name */ - cssModule: PropTypes.object, - innerRef: PropTypes.oneOfType([ - PropTypes.object, - PropTypes.string, - PropTypes.func, - ]), - /** Set a custom element for this component */ - tag: tagPropType, -}; - -function AccordionItem(props) { - const { - className, - cssModule, - tag: Tag = 'div', - innerRef, - ...attributes - } = props; - const classes = mapToCssModules( - classNames(className, 'accordion-item'), - cssModule, - ); - - return ; -} - -AccordionItem.propTypes = propTypes; - -export default AccordionItem; diff --git a/src/AccordionItem.tsx b/src/AccordionItem.tsx new file mode 100644 index 000000000..da46f35e9 --- /dev/null +++ b/src/AccordionItem.tsx @@ -0,0 +1,37 @@ +import type { ElementType, Ref } from 'react'; +import classNames from 'classnames'; +import { + mapToCssModules, + type CSSModule, + type PolymorphicExtras, +} from './utils'; + +export interface AccordionItemOwnProps { + /** To add custom class */ + className?: string; + /** Change existing base class name with a new class name */ + cssModule?: CSSModule; + innerRef?: Ref; +} + +export type AccordionItemProps = + AccordionItemOwnProps & PolymorphicExtras; + +function AccordionItem({ + className, + cssModule, + tag, + innerRef, + ref, + ...attributes +}: AccordionItemProps) { + const Tag: ElementType = tag ?? 'div'; + const classes = mapToCssModules( + classNames(className, 'accordion-item'), + cssModule, + ); + + return ; +} + +export default AccordionItem; diff --git a/src/Alert.js b/src/Alert.js deleted file mode 100644 index 655fcc088..000000000 --- a/src/Alert.js +++ /dev/null @@ -1,101 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import classNames from 'classnames'; -import { mapToCssModules, tagPropType } from './utils'; -import Fade from './Fade'; - -const propTypes = { - /** Pass children so this component can wrap the child elements */ - children: PropTypes.node, - /** Add custom class */ - className: PropTypes.string, - /** Add custom class for close button */ - closeClassName: PropTypes.string, - /** Aria label for close button */ - closeAriaLabel: PropTypes.string, - /** Change color of alert */ - color: PropTypes.string, - /** Change existing className with a new className */ - cssModule: PropTypes.object, - /** Toggle fade animation */ - fade: PropTypes.bool, - innerRef: PropTypes.oneOfType([ - PropTypes.object, - PropTypes.string, - PropTypes.func, - ]), - /** Control visibility state of Alert */ - isOpen: PropTypes.bool, - /** Set a custom element for this component */ - tag: tagPropType, - /** Function to toggle visibility */ - toggle: PropTypes.func, - /** Props to be passed to `Fade` to modify transition */ - transition: PropTypes.shape(Fade.propTypes), -}; - -function Alert(props) { - const { - className, - closeClassName, - closeAriaLabel = 'Close', - cssModule, - tag: Tag = 'div', - color = 'success', - isOpen = true, - toggle, - children, - transition = { - ...Fade.defaultProps, - unmountOnExit: true, - }, - fade = true, - innerRef, - ...attributes - } = props; - - const classes = mapToCssModules( - classNames(className, 'alert', `alert-${color}`, { - 'alert-dismissible': toggle, - }), - cssModule, - ); - - const closeClasses = mapToCssModules( - classNames('btn-close', closeClassName), - cssModule, - ); - - const alertTransition = { - ...Fade.defaultProps, - ...transition, - baseClass: fade ? transition.baseClass : '', - timeout: fade ? transition.timeout : 0, - }; - - return ( - - {toggle ? ( -