Add cn utility for Tailwind class management#397
Open
mohammad-hussein-dev wants to merge 2 commits into
Open
Conversation
FEATURES: - Add cn.ts: combines clsx + tailwind-merge for conflict-free class merging - Refactor Button, Checkbox, Chip components to use cn() utility - Comprehensive unit tests (17 tests, 100% coverage) - TSDoc documentation with @param, @returns, @example tags - GitHub Actions CI/CD workflow (lint, type-check, test, build) TECHNICAL DETAILS: - Uses clsx for conditional class composition - Uses tailwind-merge for intelligent Tailwind class conflict resolution - Supports strings, arrays, objects, and falsy values - Memoized Checkbox component to prevent unnecessary re-renders - Full TypeScript support with ClassValue type exports TESTING: - Unit tests cover: basic merging, conditional classes, falsy values - Tailwind conflict resolution tested across padding, colors, complex scenarios - Edge cases: deeply nested arrays, mixed input types, class ordering - v8 coverage tool: 100% lines, branches, functions, statements CI/CD: - Biome linting and formatting - TypeScript type checking (tsc --noEmit) - Vitest with coverage reporting - WXT extension build validation Closes widgetify-app#127
Author
|
Hi @sajjadmrx, this PR is ready for review whenever you have time. Let me know if you'd like any adjustments. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(I've reviewed the contributing guidelines and followed them.)
✨ Add
cnutility for conflict-free Tailwind class management🎯 What
Introduces a robust
cn()utility function and refactors three components to use it.Utility:
src/utils/cn.ts— combinesclsx+tailwind-mergeComponents refactored: Button, Checkbox, Chip
Test coverage: 17 tests, 100% coverage (lines, branches, functions, statements)
🤔 Why
Manual class concatenation (
${a} ${b} ${c}) breaks silently when Tailwind utilities conflict:p-4 p-2→ onlyp-4takes effect (silent failure)text-red-500 text-blue-500→ unpredictable resultstailwind-mergeresolves conflicts deterministically (last wins).clsxremoves boilerplate.✅ What's Changed
src/utils/cn.ts): 15 lines, fully documented with TSDocsrc/utils/__tests__/cn.test.ts): 17 tests covering edge cases.github/workflows/cn-utility.yml): Biome lint, TypeScript check, vitest, build🧪 Testing
All 17 tests pass with 100% coverage:
Run locally:
📚 Documentation
cn.ts: @param, @returns, @example tags for IDE IntelliSense/src/utils/cn.tsfor usage examples🔄 Backward Compatibility
✓ No breaking changes — components render identically to before
✓ Gradual adoption possible — other components can use
cn()in follow-up PRs✓ Optional — classNameOverrides still work perfectly
Closes
Closes #127