├── .dev └── styles.css ├── .eslintignore ├── .eslintrc ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── pull_request_template.md └── workflows │ ├── codeql-analysis.yml │ ├── development.yml │ └── npm-publish.yml ├── .gitignore ├── .npmrc ├── .prettierignore ├── .prettierrc ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── jest.config.js ├── lib ├── As │ ├── As.tsx │ ├── AsClone.tsx │ ├── index.ts │ └── utils.ts ├── Breadcrumb │ ├── Breadcrumb.test.tsx │ ├── Breadcrumb.tsx │ ├── components │ │ ├── Item.tsx │ │ ├── List.tsx │ │ ├── SeparatorItem.tsx │ │ └── index.ts │ ├── index.ts │ └── slots.ts ├── Button │ ├── Button.tsx │ ├── index.ts │ └── slots.ts ├── CheckGroup │ ├── CheckGroup.test.tsx │ ├── CheckGroup.tsx │ ├── context.ts │ ├── index.ts │ └── slots.ts ├── Checkbox │ ├── Checkbox.test.tsx │ ├── Checkbox.tsx │ ├── index.ts │ └── slots.ts ├── Dialog │ ├── Dialog.test.tsx │ ├── Dialog.tsx │ ├── components │ │ ├── Backdrop.tsx │ │ ├── Content.tsx │ │ ├── Description.tsx │ │ ├── Title.tsx │ │ └── index.ts │ ├── context.ts │ ├── index.ts │ └── slots.ts ├── Expandable │ ├── Expandable.test.tsx │ ├── Expandable.tsx │ ├── components │ │ ├── Content.tsx │ │ ├── Trigger.tsx │ │ └── index.ts │ ├── context.ts │ ├── index.ts │ └── slots.ts ├── InputSlider │ ├── InputSlider.test.tsx │ ├── InputSlider.tsx │ ├── components │ │ ├── InfimumThumb.tsx │ │ ├── Range.tsx │ │ ├── SupremumThumb.tsx │ │ ├── Thumb.tsx │ │ ├── Track.tsx │ │ └── index.ts │ ├── context.ts │ ├── index.ts │ ├── slots.ts │ ├── types.ts │ └── utils.ts ├── Menu │ ├── BaseMenu.tsx │ ├── Menu.test.tsx │ ├── Menu.tsx │ ├── components │ │ ├── CheckItem.tsx │ │ ├── Group.tsx │ │ ├── Item │ │ │ ├── Item.tsx │ │ │ ├── context.ts │ │ │ └── index.ts │ │ ├── RadioGroup │ │ │ ├── RadioGroup.tsx │ │ │ ├── context.ts │ │ │ └── index.ts │ │ ├── RadioItem.tsx │ │ ├── SeparatorItem.tsx │ │ ├── SubMenu.tsx │ │ └── index.ts │ ├── constants.ts │ ├── context.ts │ ├── index.ts │ ├── slots.ts │ └── utils.ts ├── Meter │ ├── Meter.tsx │ ├── index.ts │ └── slots.ts ├── Popper │ ├── Popper.tsx │ ├── index.ts │ ├── slots.ts │ ├── types.ts │ └── utils.ts ├── Portal │ ├── Portal.tsx │ ├── index.ts │ └── utils.ts ├── PortalConfigProvider │ ├── PortalConfigProvider.tsx │ ├── context.ts │ ├── index.ts │ └── usePortalConfig.ts ├── PreserveAspectRatio │ ├── PreserveAspectRatio.tsx │ ├── index.ts │ └── slots.ts ├── ProgressBar │ ├── ProgressBar.tsx │ ├── index.ts │ └── slots.ts ├── Radio │ ├── Radio.test.tsx │ ├── Radio.tsx │ ├── index.ts │ └── slots.ts ├── RadioGroup │ ├── RadioGroup.test.tsx │ ├── RadioGroup.tsx │ ├── context.ts │ ├── index.ts │ └── slots.ts ├── Select │ ├── Select.test.tsx │ ├── Select.tsx │ ├── components │ │ ├── Controller │ │ │ ├── Controller.tsx │ │ │ ├── index.ts │ │ │ └── utils.ts │ │ ├── EmptyStatement.tsx │ │ ├── Group.tsx │ │ ├── List │ │ │ ├── List.tsx │ │ │ ├── index.ts │ │ │ └── utils.ts │ │ ├── Option.tsx │ │ ├── Trigger.tsx │ │ └── index.ts │ ├── context.ts │ ├── index.ts │ ├── slots.ts │ └── utils.ts ├── SpinButton │ ├── SpinButton.test.tsx │ ├── SpinButton.tsx │ ├── components │ │ ├── DecrementButton.tsx │ │ ├── IncrementButton.tsx │ │ └── index.ts │ ├── context.ts │ ├── index.ts │ └── slots.ts ├── Switch │ ├── Switch.test.tsx │ ├── Switch.tsx │ ├── index.ts │ └── slots.ts ├── TabGroup │ ├── TabGroup.test.tsx │ ├── TabGroup.tsx │ ├── components │ │ ├── List.tsx │ │ ├── Panel.tsx │ │ ├── Tab.tsx │ │ └── index.ts │ ├── context.ts │ ├── index.ts │ └── slots.ts ├── Toast │ ├── Toast.test.tsx │ ├── Toast.tsx │ ├── components │ │ ├── Action.tsx │ │ ├── Content.tsx │ │ └── index.ts │ ├── context.ts │ ├── index.ts │ └── slots.ts ├── Toggle │ ├── Toggle.test.tsx │ ├── Toggle.tsx │ ├── index.ts │ └── slots.ts ├── ToggleGroup │ ├── ToggleGroup.test.tsx │ ├── ToggleGroup.tsx │ ├── context.ts │ ├── index.ts │ └── slots.ts ├── Tooltip │ ├── Tooltip.test.tsx │ ├── Tooltip.tsx │ └── index.ts ├── TreeView │ ├── TreeView.test.tsx │ ├── TreeView.tsx │ ├── components │ │ ├── Item │ │ │ ├── Item.tsx │ │ │ ├── context.ts │ │ │ └── index.ts │ │ ├── SubTree.tsx │ │ └── index.ts │ ├── contexts.ts │ ├── index.ts │ ├── slots.ts │ └── utils.ts ├── index.ts ├── internals │ ├── FocusRedirect │ │ ├── FocusRedirect.tsx │ │ └── index.ts │ ├── FocusTrap │ │ ├── FocusTrap.tsx │ │ └── index.ts │ ├── SystemError.ts │ ├── get-label-info.ts │ ├── index.ts │ ├── keys.ts │ ├── logger.ts │ ├── prefix-message.ts │ ├── resolve-prop-with-render-context.ts │ ├── styles.ts │ └── use-jump-to-char.ts ├── types.ts └── utils │ ├── component-with-forwarded-ref.ts │ ├── create-custom-event.ts │ ├── create-virtual-element.ts │ ├── dispatch-discrete-custom-event.ts │ ├── dom.ts │ ├── fork-refs.ts │ ├── get-direction.ts │ ├── get-scrolling-state.ts │ ├── index.ts │ ├── is.ts │ ├── math.ts │ ├── request-form-submit.ts │ ├── set-ref.ts │ ├── use-button-base.ts │ ├── use-check-base.ts │ ├── use-event-callback.ts │ ├── use-is-focus-visible.ts │ ├── use-is-initial-render-complete.ts │ ├── use-isomorphic-layout-effect.ts │ └── use-isomorphic-value.ts ├── next-env.d.ts ├── next.config.js ├── package.json ├── pages ├── _app.tsx ├── _document.tsx └── index.tsx ├── pnpm-lock.yaml ├── readme-dark-icon.svg ├── readme-light-icon.svg ├── scripts ├── build-package.ts ├── ci │ └── publish-package.ts └── minify-package.ts ├── tests ├── jest.setup.ts └── utils │ ├── index.ts │ ├── itIsPolymorphic.tsx │ ├── itShouldMount.tsx │ ├── itSupportsClassName.tsx │ ├── itSupportsDataSetProps.tsx │ ├── itSupportsFocusEvents.tsx │ ├── itSupportsRef.tsx │ ├── itSupportsStyle.tsx │ └── wait.ts ├── tsconfig.build.json ├── tsconfig.cjs.json ├── tsconfig.esm.json ├── tsconfig.json └── tsconfig.lint.json /.dev/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, 3 | Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif; 4 | } 5 | 6 | *, 7 | *::after, 8 | *::before { 9 | box-sizing: border-box; 10 | } 11 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .swc 4 | .github 5 | .next 6 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "eslint:recommended", 4 | "plugin:react/recommended", 5 | "plugin:react-hooks/recommended", 6 | "plugin:import/recommended", 7 | "plugin:import/typescript", 8 | "prettier", 9 | "plugin:prettier/recommended", 10 | ], 11 | "env": { 12 | "browser": true, 13 | "es6": true, 14 | "node": true, 15 | "commonjs": true, 16 | }, 17 | "globals": { 18 | "Atomics": "readonly", 19 | "SharedArrayBuffer": "readonly", 20 | "JSX": true, 21 | }, 22 | "plugins": [ 23 | "import", 24 | "react", 25 | "react-hooks", 26 | "@typescript-eslint/eslint-plugin", 27 | ], 28 | "parser": "@typescript-eslint/parser", 29 | "parserOptions": { 30 | "sourceType": "module", 31 | }, 32 | "rules": { 33 | "no-alert": "error", 34 | "no-console": "warn", 35 | "prefer-const": "error", 36 | "default-case": "warn", 37 | "eol-last": "error", 38 | "object-shorthand": "error", 39 | "require-atomic-updates": "error", 40 | "no-unused-private-class-members": "warn", 41 | "no-promise-executor-return": "error", 42 | "no-unmodified-loop-condition": "warn", 43 | "eqeqeq": ["error", "smart"], 44 | "no-duplicate-imports": [ 45 | "error", 46 | { 47 | "includeExports": true, 48 | }, 49 | ], 50 | "@typescript-eslint/consistent-type-imports": [ 51 | "error", 52 | { 53 | "fixStyle": "inline-type-imports", 54 | }, 55 | ], 56 | "padding-line-between-statements": [ 57 | "error", 58 | { 59 | "blankLine": "always", 60 | "prev": [ 61 | "const", 62 | "let", 63 | "var", 64 | "directive", 65 | "function", 66 | "class", 67 | "block", 68 | "block-like", 69 | "multiline-block-like", 70 | ], 71 | "next": "*", 72 | }, 73 | { 74 | "blankLine": "any", 75 | "prev": ["const", "let", "var", "directive"], 76 | "next": ["const", "let", "var", "directive"], 77 | }, 78 | { 79 | "blankLine": "always", 80 | "prev": ["multiline-const", "multiline-let"], 81 | "next": "*", 82 | }, 83 | ], 84 | "react/prop-types": "off", 85 | "react/react-in-jsx-scope": "off", 86 | "@typescript-eslint/no-unused-vars": [ 87 | "warn", 88 | { 89 | "argsIgnorePattern": "^_", 90 | "varsIgnorePattern": "^_", 91 | }, 92 | ], 93 | }, 94 | "overrides": [ 95 | { 96 | "files": ["*.ts", "*.tsx", "*.d.ts"], 97 | "extends": [ 98 | "plugin:import/typescript", 99 | "plugin:@typescript-eslint/recommended", 100 | "plugin:@typescript-eslint/recommended-requiring-type-checking", 101 | ], 102 | "parserOptions": { 103 | "sourceType": "module", 104 | "project": ["tsconfig.json"], 105 | }, 106 | }, 107 | { 108 | "files": [ 109 | "**/__tests__/**/*.[jt]s?(x)", 110 | "**/?(*.)+(spec|test).[jt]s?(x)", 111 | ], 112 | "extends": [ 113 | "plugin:testing-library/react", 114 | "plugin:jest-dom/recommended", 115 | "plugin:jest/recommended", 116 | ], 117 | }, 118 | ], 119 | "settings": { 120 | "react": { 121 | "version": "detect", 122 | }, 123 | }, 124 | } 125 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | ## Bug 8 | 9 | - [ ] Related issues linked using `fixes #number` 10 | - [ ] Tests added 11 | 12 | ## Feature 13 | 14 | - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. 15 | - [ ] Related issues linked using `fixes #number` 16 | - [ ] Tests added 17 | - [ ] Documentation added 18 | - [ ] Telemetry added. In case of a feature if it's used or not. 19 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: CodeQL 2 | 3 | on: 4 | push: 5 | branches: 6 | - "next" 7 | pull_request: 8 | schedule: 9 | # on sunday of each month at 5:55 10 | - cron: "55 5 * * 0" 11 | workflow_call: 12 | 13 | jobs: 14 | analyze: 15 | name: "Analyze" 16 | runs-on: ubuntu-latest 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | language: 21 | - javascript 22 | steps: 23 | - uses: actions/checkout@v4 24 | 25 | - name: "🎬 Initialize CodeQL" 26 | uses: github/codeql-action/init@v3 27 | with: 28 | languages: ${{ matrix.language }} 29 | 30 | - name: "🏗️ Autobuild" 31 | uses: github/codeql-action/autobuild@v3 32 | 33 | - name: "🧐 Perform CodeQL Analysis" 34 | uses: github/codeql-action/analyze@v3 35 | -------------------------------------------------------------------------------- /.github/workflows/development.yml: -------------------------------------------------------------------------------- 1 | name: Development 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - opened 7 | - edited 8 | - synchronize 9 | - reopened 10 | workflow_call: 11 | 12 | jobs: 13 | test: 14 | name: Test components 15 | runs-on: ubuntu-latest 16 | timeout-minutes: 10 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - uses: pnpm/action-setup@v3 21 | with: 22 | version: 9 23 | 24 | - uses: actions/setup-node@v4 25 | with: 26 | node-version: 20 27 | cache: "pnpm" 28 | 29 | - name: "📦 install dependencies" 30 | run: pnpm install 31 | 32 | - name: "🔍 run tests" 33 | run: pnpm test 34 | 35 | lint: 36 | name: Code standards 37 | runs-on: ubuntu-latest 38 | timeout-minutes: 10 39 | steps: 40 | - name: "☁️ checkout repository" 41 | uses: actions/checkout@v4 42 | 43 | - name: "🔧 setup pnpm" 44 | uses: pnpm/action-setup@v3 45 | with: 46 | version: 9 47 | 48 | - name: "🔧 setup node" 49 | uses: actions/setup-node@v4 50 | with: 51 | node-version: 20 52 | cache: "pnpm" 53 | 54 | - name: "📦 install dependencies" 55 | run: pnpm install 56 | 57 | - name: "🔍 lint code" 58 | run: pnpm lint 59 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | 13 | - uses: pnpm/action-setup@v3 14 | with: 15 | version: 9 16 | 17 | - uses: actions/setup-node@v4 18 | with: 19 | node-version: 20 20 | cache: "pnpm" 21 | 22 | - name: "📦 install dependencies" 23 | run: pnpm install 24 | 25 | - name: "🧱 build package" 26 | run: pnpm build 27 | 28 | - name: "🗄️ archive package" 29 | uses: actions/upload-artifact@v4 30 | with: 31 | name: dist 32 | path: dist 33 | 34 | publish-npm: 35 | needs: build 36 | runs-on: ubuntu-latest 37 | steps: 38 | - uses: actions/checkout@v4 39 | 40 | - uses: pnpm/action-setup@v3 41 | with: 42 | version: 9 43 | 44 | - uses: actions/setup-node@v4 45 | with: 46 | node-version: 20 47 | cache: "pnpm" 48 | registry-url: https://registry.npmjs.org/ 49 | 50 | - name: "📦 install dependencies" 51 | run: pnpm install 52 | 53 | - name: "🚚 download package" 54 | uses: actions/download-artifact@v4 55 | with: 56 | name: dist 57 | path: dist 58 | 59 | - name: "🚀 publish package" 60 | run: npx tsx ./scripts/ci/publish-package.ts 61 | env: 62 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | .DS_Store 107 | .vscode 108 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | public-hoist-pattern[]=*eslint* 2 | public-hoist-pattern[]=*prettier* 3 | public-hoist-pattern[]=@types* 4 | enable-pre-post-scripts=true 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .swc 4 | .github 5 | .next 6 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "bracketSpacing": true, 3 | "printWidth": 80, 4 | "semi": true, 5 | "singleQuote": false, 6 | "tabWidth": 2, 7 | "trailingComma": "all", 8 | "arrowParens": "avoid", 9 | "bracketSameLine": false, 10 | "endOfLine": "lf", 11 | "htmlWhitespaceSensitivity": "css", 12 | "jsxSingleQuote": false, 13 | "singleAttributePerLine": true, 14 | "plugins": ["prettier-plugin-organize-imports"] 15 | } 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 styleless-ui 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |

[ ui | styleless/react ]

5 |
6 | 7 |
8 | 9 | Completely unstyled, headless and accessible [React](https://reactjs.org/) UI components. 10 | 11 |
12 | 13 |
14 | 15 | ## Public Roadmap 16 | 17 | Our project [roadmap](https://github.com/orgs/styleless-ui/projects/1/views/1?visibleFields=%5B%22Title%22%2C%22Assignees%22%2C%22Status%22%2C%22Labels%22%2C%22Repository%22%2C%22Milestone%22%5D) is where you can learn about what features we're working on, what stage they're in, and when we expect to bring them to you. Have any questions or comments about items on the roadmap? Share your feedback via [StylelessUI public feedback discussions](https://github.com/styleless-ui/react-styleless-ui/discussions/categories/feedback). 18 | 19 | ## Contributing 20 | 21 | Read the [contributing guide](https://github.com/styleless-ui/react-styleless-ui/blob/stable/CONTRIBUTING.md) to learn about our development process, how to propose bug fixes and improvements, and how to build and test your changes. 22 | 23 | Contributing to styleless-ui is about more than just issues and pull requests! There are many other ways to support the project beyond contributing to the code base. 24 | 25 | ## License 26 | 27 | This project is licensed under the terms of the [MIT license](https://github.com/styleless-ui/react-styleless-ui/blob/stable/LICENSE). 28 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | import nextJest from "next/jest.js"; 2 | 3 | const createJestConfig = nextJest({ dir: "./" }); 4 | 5 | /** 6 | * @type {import("jest").Config} 7 | */ 8 | const jestConfig = { 9 | verbose: true, 10 | setupFilesAfterEnv: ["/tests/jest.setup.ts"], 11 | testPathIgnorePatterns: ["/.next/", "/node_modules/"], 12 | testRegex: ".*\\.test\\.tsx?$", 13 | testEnvironment: "jest-environment-jsdom", 14 | preset: "ts-jest", 15 | }; 16 | 17 | export default createJestConfig(jestConfig); 18 | -------------------------------------------------------------------------------- /lib/As/As.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { componentWithForwardedRef } from "../utils"; 3 | import AsClone from "./AsClone"; 4 | 5 | type OwnProps = { 6 | /** 7 | * The content of the component. It should be a single non-fragment React element. 8 | */ 9 | children: React.ReactElement; 10 | }; 11 | 12 | export type Props = React.HTMLAttributes & OwnProps; 13 | 14 | const AsBase = (props: Props, ref: React.Ref) => { 15 | const { children, ...otherProps } = props; 16 | 17 | return ( 18 | 22 | {children} 23 | 24 | ); 25 | }; 26 | 27 | const As = componentWithForwardedRef(AsBase, "As"); 28 | 29 | export default As; 30 | -------------------------------------------------------------------------------- /lib/As/AsClone.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { SystemError } from "../internals"; 3 | import type { UnknownObject } from "../types"; 4 | import { componentWithForwardedRef, forkRefs, isFragment } from "../utils"; 5 | import { type Props } from "./As"; 6 | import { mergeProps } from "./utils"; 7 | 8 | const AsCloneBase = ( 9 | props: Props & React.RefAttributes, 10 | ref: React.Ref, 11 | ) => { 12 | const { children, ...otherProps } = props; 13 | 14 | if (React.isValidElement(children)) { 15 | type SingleElement = typeof children; 16 | 17 | if (isFragment(children)) { 18 | throw new SystemError( 19 | "The component is not expected to receive a React Fragment child.", 20 | "As", 21 | ); 22 | } 23 | 24 | const childProps = (children as SingleElement).props as UnknownObject; 25 | const cloneProps = mergeProps(otherProps, childProps); 26 | 27 | cloneProps.ref = forkRefs( 28 | ref, 29 | (children as SingleElement & { ref: React.Ref }).ref, 30 | ); 31 | 32 | return React.cloneElement(children, cloneProps); 33 | } 34 | 35 | try { 36 | return React.Children.only(null); 37 | } catch { 38 | throw new SystemError( 39 | "The component expected to receive a single React element child.", 40 | "As", 41 | ); 42 | } 43 | }; 44 | 45 | const AsClone = componentWithForwardedRef(AsCloneBase, "AsClone"); 46 | 47 | export default AsClone; 48 | -------------------------------------------------------------------------------- /lib/As/index.ts: -------------------------------------------------------------------------------- 1 | export { default, type Props as AsProps } from "./As"; 2 | -------------------------------------------------------------------------------- /lib/As/utils.ts: -------------------------------------------------------------------------------- 1 | import type { AnyObject } from "../types"; 2 | 3 | export const mergeProps = (slotProps: AnyObject, childProps: AnyObject) => { 4 | const overrideProps = Object.keys(childProps).reduce( 5 | (result, key) => { 6 | const slotPropValue = slotProps[key] as unknown; 7 | const childPropValue = childProps[key] as unknown; 8 | 9 | const isEventHandler = /^on[A-Z]/.test(key); 10 | const isStyle = key === "style"; 11 | const isClassName = key === "className"; 12 | 13 | if (isEventHandler) { 14 | const existsOnBoth = slotPropValue && childPropValue; 15 | 16 | if (existsOnBoth) { 17 | type EventHandler = (...args: unknown[]) => void; 18 | 19 | return { 20 | ...result, 21 | [key]: (...args: unknown[]) => { 22 | (childPropValue as EventHandler)(...args); 23 | (slotPropValue as EventHandler)(...args); 24 | }, 25 | }; 26 | } else if (slotPropValue) overrideProps[key] = slotPropValue; 27 | } else if (isStyle) { 28 | return { 29 | ...result, 30 | [key]: { 31 | ...(slotPropValue as React.CSSProperties), 32 | ...(childPropValue as React.CSSProperties), 33 | }, 34 | }; 35 | } else if (isClassName) { 36 | return { 37 | ...result, 38 | [key]: [slotPropValue, childPropValue].filter(Boolean).join(" "), 39 | }; 40 | } 41 | 42 | return result; 43 | }, 44 | { ...childProps }, 45 | ); 46 | 47 | return { ...slotProps, ...overrideProps }; 48 | }; 49 | -------------------------------------------------------------------------------- /lib/Breadcrumb/Breadcrumb.test.tsx: -------------------------------------------------------------------------------- 1 | import * as Breadcrumb from "."; 2 | import { 3 | itShouldMount, 4 | itSupportsDataSetProps, 5 | itSupportsRef, 6 | itSupportsStyle, 7 | render, 8 | screen, 9 | } from "../../tests/utils"; 10 | 11 | const labelText = "Breadcrumb"; 12 | 13 | const mockRequiredProps: Breadcrumb.RootProps = { 14 | label: { screenReaderLabel: labelText }, 15 | }; 16 | 17 | describe("Breadcrumb", () => { 18 | afterEach(jest.clearAllMocks); 19 | 20 | itShouldMount(Breadcrumb.Root, mockRequiredProps); 21 | itSupportsStyle(Breadcrumb.Root, mockRequiredProps, "nav"); 22 | itSupportsRef(Breadcrumb.Root, mockRequiredProps, HTMLElement); 23 | itSupportsDataSetProps(Breadcrumb.Root, mockRequiredProps, "nav"); 24 | 25 | it("should have the required classNames", () => { 26 | render( 27 | 31 | 35 | 39 | 44 | 45 | , 46 | ); 47 | 48 | const nav = screen.getByRole("navigation"); 49 | const list = screen.getByTestId("list"); 50 | const item = screen.getByTestId("item"); 51 | const separator = screen.getByTestId("separator"); 52 | 53 | expect(nav).toHaveClass("root"); 54 | expect(list).toHaveClass("list"); 55 | expect(item).toHaveClass("item"); 56 | expect(separator).toHaveClass("separator"); 57 | }); 58 | 59 | it("should have `aria-label='label'` property when `label={{ screenReaderLabel: 'label' }}`", () => { 60 | render(); 61 | 62 | expect(screen.getByRole("navigation")).toHaveAttribute( 63 | "aria-label", 64 | labelText, 65 | ); 66 | }); 67 | 68 | it("should have `aria-labelledby='identifier'` property when `label={{ labelledBy: 'identifier' }}`", () => { 69 | render( 70 | , 74 | ); 75 | 76 | expect(screen.getByRole("navigation")).toHaveAttribute( 77 | "aria-labelledby", 78 | "identifier", 79 | ); 80 | }); 81 | }); 82 | -------------------------------------------------------------------------------- /lib/Breadcrumb/Breadcrumb.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { getLabelInfo, logger } from "../internals"; 3 | import type { MergeElementProps } from "../types"; 4 | import { 5 | componentWithForwardedRef, 6 | isFragment, 7 | useDeterministicId, 8 | } from "../utils"; 9 | import { List } from "./components"; 10 | import { Root as RootSlot } from "./slots"; 11 | 12 | type OwnProps = { 13 | /** 14 | * The content of the breadcrumb. 15 | */ 16 | children?: React.ReactNode; 17 | /** 18 | * The className applied to the component. 19 | */ 20 | className?: string; 21 | /** 22 | * The label of the breadcrumb. 23 | */ 24 | label: 25 | | { 26 | /** 27 | * The label to use as `aria-label` property. 28 | */ 29 | screenReaderLabel: string; 30 | } 31 | | { 32 | /** 33 | * Identifies the element (or elements) that labels the breadcrumb. 34 | * 35 | * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby MDN Web Docs} for more information. 36 | */ 37 | labelledBy: string; 38 | }; 39 | }; 40 | 41 | export type Props = Omit< 42 | MergeElementProps<"nav", OwnProps>, 43 | "defaultChecked" | "defaultValue" 44 | >; 45 | 46 | const BreadcrumbBase = (props: Props, ref: React.Ref) => { 47 | const { 48 | label, 49 | children: childrenProp, 50 | id: idProp, 51 | className, 52 | ...otherProps 53 | } = props; 54 | 55 | const id = useDeterministicId(idProp, "styleless-ui__breadcrumb"); 56 | 57 | const labelInfo = getLabelInfo(label, "Breadcrumb", { 58 | customErrorMessage: [ 59 | "Invalid `label` property.", 60 | "The `label` property must be in shape of " + 61 | "`{ screenReaderLabel: string; } | { labelledBy: string; }`", 62 | ].join("\n"), 63 | }); 64 | 65 | const children = React.Children.map(childrenProp, child => { 66 | if (!React.isValidElement(child) || isFragment(child)) { 67 | logger( 68 | "The component doesn't accept `Fragment` or any invalid element as children.", 69 | { scope: "Breadcrumb", type: "error" }, 70 | ); 71 | 72 | return null; 73 | } 74 | 75 | if ((child as React.ReactElement).type !== List) { 76 | logger( 77 | "The component only accepts as a children.", 78 | { scope: "Breadcrumb", type: "error" }, 79 | ); 80 | 81 | return null; 82 | } 83 | 84 | return child as React.ReactElement; 85 | }); 86 | 87 | return ( 88 | 99 | ); 100 | }; 101 | 102 | const Breadcrumb = componentWithForwardedRef(BreadcrumbBase, "Breadcrumb"); 103 | 104 | export default Breadcrumb; 105 | -------------------------------------------------------------------------------- /lib/Breadcrumb/components/Item.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import type { MergeElementProps } from "../../types"; 3 | import { componentWithForwardedRef } from "../../utils"; 4 | import { ItemRoot as ItemRootSlot } from "../slots"; 5 | 6 | type OwnProps = { 7 | /** 8 | * The content of the component. 9 | */ 10 | children?: React.ReactNode; 11 | /** 12 | * The className applied to the component. 13 | */ 14 | className?: string; 15 | }; 16 | 17 | export type Props = Omit< 18 | MergeElementProps<"li", OwnProps>, 19 | "defaultChecked" | "defaultValue" 20 | >; 21 | 22 | const ItemBase = (props: Props, ref: React.Ref) => { 23 | const { className, children, ...otherProps } = props; 24 | 25 | return ( 26 |
  • 32 | {children} 33 |
  • 34 | ); 35 | }; 36 | 37 | const Item = componentWithForwardedRef(ItemBase, "Breadcrumb.Item"); 38 | 39 | export default Item; 40 | -------------------------------------------------------------------------------- /lib/Breadcrumb/components/List.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { logger } from "../../internals"; 3 | import type { MergeElementProps } from "../../types"; 4 | import { componentWithForwardedRef, isFragment, setRef } from "../../utils"; 5 | import { ListRoot as ListRootSlot } from "../slots"; 6 | import Item from "./Item"; 7 | import SeparatorItem from "./SeparatorItem"; 8 | 9 | type OwnProps = { 10 | /** 11 | * The content of the component. 12 | */ 13 | children?: React.ReactNode; 14 | /** 15 | * The className applied to the component. 16 | */ 17 | className?: string; 18 | }; 19 | 20 | export type Props = Omit< 21 | MergeElementProps<"ol", OwnProps>, 22 | "defaultChecked" | "defaultValue" 23 | >; 24 | 25 | const ListBase = (props: Props, ref: React.Ref) => { 26 | const { className, children: childrenProp, ...otherProps } = props; 27 | 28 | const children = React.Children.map(childrenProp, child => { 29 | if (!React.isValidElement(child) || isFragment(child)) { 30 | logger( 31 | "The component doesn't accept `Fragment` or any invalid element as children.", 32 | { scope: "Breadcrumb.List", type: "error" }, 33 | ); 34 | 35 | return null; 36 | } 37 | 38 | if ( 39 | (child as React.ReactElement).type !== Item && 40 | (child as React.ReactElement).type !== SeparatorItem 41 | ) { 42 | logger( 43 | "The component only accepts and " + 44 | " as a children.", 45 | { scope: "Breadcrumb.List", type: "error" }, 46 | ); 47 | 48 | return null; 49 | } 50 | 51 | return child as React.ReactElement; 52 | }); 53 | 54 | const refCallback = (node: HTMLOListElement | null) => { 55 | setRef(ref, node); 56 | 57 | if (!node) return; 58 | 59 | const lastItem = node.lastElementChild; 60 | 61 | if (!lastItem?.firstElementChild) return; 62 | 63 | if (lastItem.firstElementChild.tagName === "A") { 64 | const anchorLink = lastItem.firstElementChild as HTMLAnchorElement; 65 | 66 | if (anchorLink.hasAttribute("aria-current")) return; 67 | 68 | logger( 69 | [ 70 | "The aria attribute `aria-current`" + 71 | " is missing from the last 's anchor element.", 72 | "For more information check out: " + 73 | "https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current", 74 | ].join("\n"), 75 | { scope: "Breadcrumb.List", type: "warn" }, 76 | ); 77 | } 78 | }; 79 | 80 | return ( 81 |
      88 | {children} 89 |
    90 | ); 91 | }; 92 | 93 | const List = componentWithForwardedRef(ListBase, "Breadcrumb.List"); 94 | 95 | export default List; 96 | -------------------------------------------------------------------------------- /lib/Breadcrumb/components/SeparatorItem.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import type { MergeElementProps } from "../../types"; 3 | import { componentWithForwardedRef } from "../../utils"; 4 | import { SeparatorItemRoot as SeparatorItemRootSlot } from "../slots"; 5 | 6 | type OwnProps = { 7 | /** 8 | * The symbol which is used as separator. 9 | */ 10 | separatorSymbol: JSX.Element | string; 11 | /** 12 | * The className applied to the component. 13 | */ 14 | className?: string; 15 | }; 16 | 17 | export type Props = Omit< 18 | MergeElementProps<"li", OwnProps>, 19 | "defaultChecked" | "defaultValue" | "children" 20 | >; 21 | 22 | const SeparatorItemBase = (props: Props, ref: React.Ref) => { 23 | const { className, separatorSymbol, ...otherProps } = props; 24 | 25 | return ( 26 |
  • 33 | {separatorSymbol} 34 |
  • 35 | ); 36 | }; 37 | 38 | const SeparatorItem = componentWithForwardedRef( 39 | SeparatorItemBase, 40 | "Breadcrumb.SeparatorItem", 41 | ); 42 | 43 | export default SeparatorItem; 44 | -------------------------------------------------------------------------------- /lib/Breadcrumb/components/index.ts: -------------------------------------------------------------------------------- 1 | export { default as Item, type Props as ItemProps } from "./Item"; 2 | export { default as List, type Props as ListProps } from "./List"; 3 | export { 4 | default as SeparatorItem, 5 | type Props as SeparatorItemProps, 6 | } from "./SeparatorItem"; 7 | -------------------------------------------------------------------------------- /lib/Breadcrumb/index.ts: -------------------------------------------------------------------------------- 1 | export { default as Root, type Props as RootProps } from "./Breadcrumb"; 2 | export * from "./components"; 3 | -------------------------------------------------------------------------------- /lib/Breadcrumb/slots.ts: -------------------------------------------------------------------------------- 1 | export const Root = "Breadcrumb:Root"; 2 | export const ListRoot = "Breadcrumb:List:Root"; 3 | export const ItemRoot = "Breadcrumb:Item:Root"; 4 | export const SeparatorItemRoot = "Breadcrumb:SeparatorItem:Root"; 5 | -------------------------------------------------------------------------------- /lib/Button/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | default, 3 | type ClassNameProps as ButtonClassNameProps, 4 | type Props as ButtonProps, 5 | type RenderProps as ButtonRenderProps, 6 | } from "./Button"; 7 | -------------------------------------------------------------------------------- /lib/Button/slots.ts: -------------------------------------------------------------------------------- 1 | export const Root = "Button:Root"; 2 | -------------------------------------------------------------------------------- /lib/CheckGroup/context.ts: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import type { PickAsMandatory } from "../types"; 3 | import { type Props } from "./CheckGroup"; 4 | 5 | type ContextValue = PickAsMandatory & 6 | Pick & { 7 | onChange: (newCheckedState: boolean, inputValue: string) => void; 8 | }; 9 | 10 | const Context = React.createContext(null); 11 | 12 | if (process.env.NODE_ENV !== "production") { 13 | Context.displayName = "CheckGroupContext"; 14 | } 15 | 16 | export { 17 | Context as CheckGroupContext, 18 | type ContextValue as CheckGroupContextValue, 19 | }; 20 | -------------------------------------------------------------------------------- /lib/CheckGroup/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | default, 3 | type ClassNameProps as CheckGroupClassNameProps, 4 | type Props as CheckGroupProps, 5 | type RenderProps as CheckGroupRenderProps, 6 | } from "./CheckGroup"; 7 | -------------------------------------------------------------------------------- /lib/CheckGroup/slots.ts: -------------------------------------------------------------------------------- 1 | export const Root = "CheckGroup:Root"; 2 | -------------------------------------------------------------------------------- /lib/Checkbox/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | default, 3 | type ClassNameProps as CheckboxClassNameProps, 4 | type Props as CheckboxProps, 5 | type RenderProps as CheckboxRenderProps, 6 | } from "./Checkbox"; 7 | -------------------------------------------------------------------------------- /lib/Checkbox/slots.ts: -------------------------------------------------------------------------------- 1 | export const Root = "Checkbox:Root"; 2 | -------------------------------------------------------------------------------- /lib/Dialog/components/Backdrop.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { logger } from "../../internals"; 3 | import type { MergeElementProps } from "../../types"; 4 | import { componentWithForwardedRef } from "../../utils"; 5 | import { DialogContext } from "../context"; 6 | import { BackdropRoot as BackdropRootSlot } from "../slots"; 7 | 8 | type OwnProps = { 9 | /** 10 | * The className applied to the component. 11 | */ 12 | className?: string; 13 | }; 14 | 15 | export type Props = Omit< 16 | MergeElementProps<"div", OwnProps>, 17 | "defaultChecked" | "defaultValue" | "children" 18 | >; 19 | 20 | const BackdropBase = (props: Props, ref: React.Ref) => { 21 | const { className, onClick, ...otherProps } = props; 22 | 23 | const ctx = React.useContext(DialogContext); 24 | 25 | if (!ctx) { 26 | logger("You have to use this component as a descendant of .", { 27 | scope: "Dialog.Backdrop", 28 | type: "error", 29 | }); 30 | 31 | return null; 32 | } 33 | 34 | const handleClick = (event: React.MouseEvent) => { 35 | onClick?.(event); 36 | 37 | if (event.isDefaultPrevented()) return; 38 | 39 | ctx.emitClose(); 40 | }; 41 | 42 | return ( 43 |