feat: make icon type a restricted string union#699
Open
fateeand wants to merge 2 commits into
Open
Conversation
Contributor
Coverage report for library
Test suite run success2193 tests passing in 63 suites. Report generated by 🧪jest coverage report action from a56a624 |
Contributor
There was a problem hiding this comment.
Pull request overview
Tightens the icon API surface in cps-ui-kit by making the icon name type a true restricted string-literal union (improving autocomplete and catching typos), renaming related public exports to consistent Cps* names, and updating downstream usage and generated API docs accordingly.
Changes:
- Make
cpsIconNamesaconsttuple and exposeCpsIconType = (typeof cpsIconNames)[number] | '', plus rename icon-related exports (CPS_ICONS_PATH,CpsIconSizeType, etc.). - Update components/services/composition pages to use
CpsIconType/CpsIconSizeTypeinstead of loosestring/old type names, plus small internal cleanups (e.g.,cps-toast). - Improve the API docs generator to expand
typeof SomeArray[number]even when it appears within a top-level union, and regenerate affectedapi-data/*.json.
Reviewed changes
Copilot reviewed 42 out of 42 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/cps-ui-kit/src/lib/services/cps-notification/internal/components/cps-toast/cps-toast.component.ts | Computes toast icon once, switches to inject(NgZone), and tightens timeout typing. |
| projects/cps-ui-kit/src/lib/services/cps-notification/internal/components/cps-toast/cps-toast.component.html | Binds toast icon via a typed component field rather than string concatenation in-template. |
| projects/cps-ui-kit/src/lib/services/cps-dialog/utils/cps-dialog-ref.ts | Converts CpsDialogComponent import to type-only import. |
| projects/cps-ui-kit/src/lib/services/cps-dialog/utils/cps-dialog-config.ts | Changes headerIcon to CpsIconType and uses type-only imports. |
| projects/cps-ui-kit/src/lib/services/cps-dialog/cps-dialog.service.spec.ts | Updates test icon name to a valid CpsIconType value. |
| projects/cps-ui-kit/src/lib/components/internal/cps-base-tree-dropdown/cps-base-tree-dropdown.component.ts | Migrates icon-related inputs to CpsIconType/CpsIconSizeType. |
| projects/cps-ui-kit/src/lib/components/cps-tree-table/cps-tree-table.component.ts | Migrates toolbar/action icon inputs to CpsIconType. |
| projects/cps-ui-kit/src/lib/components/cps-table/cps-table.component.ts | Migrates toolbar/action icon inputs to CpsIconType. |
| projects/cps-ui-kit/src/lib/components/cps-sidebar-menu/cps-sidebar-menu.component.ts | Changes sidebar menu item icon to CpsIconType. |
| projects/cps-ui-kit/src/lib/components/cps-sidebar-menu/cps-sidebar-menu.component.spec.ts | Updates test data icon strings to valid icon names. |
| projects/cps-ui-kit/src/lib/components/cps-select/cps-select.component.ts | Migrates prefix icon inputs to CpsIconType/CpsIconSizeType. |
| projects/cps-ui-kit/src/lib/components/cps-input/cps-input.component.ts | Migrates prefix icon inputs to CpsIconType/CpsIconSizeType and type-only imports. |
| projects/cps-ui-kit/src/lib/components/cps-info-circle/cps-info-circle.component.ts | Migrates size type to CpsIconSizeType and uses type-only imports. |
| projects/cps-ui-kit/src/lib/components/cps-icon/cps-icon.component.ts | Renames public exports and makes icon names a const tuple; defines CpsIconType union. |
| projects/cps-ui-kit/src/lib/components/cps-icon/cps-icon.component.spec.ts | Updates tests for renamed injection token CPS_ICONS_PATH. |
| projects/cps-ui-kit/src/lib/components/cps-expansion-panel/cps-expansion-panel.component.ts | Migrates prefixIcon to CpsIconType. |
| projects/cps-ui-kit/src/lib/components/cps-chip/cps-chip.component.ts | Migrates icon to CpsIconType. |
| projects/cps-ui-kit/src/lib/components/cps-checkbox/cps-checkbox.component.ts | Migrates icon to CpsIconType. |
| projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.ts | Migrates icon to CpsIconType and uses type-only imports. |
| projects/cps-ui-kit/src/lib/components/cps-autocomplete/cps-autocomplete.component.ts | Migrates prefix icon inputs to CpsIconType/CpsIconSizeType. |
| projects/composition/src/app/pages/tab-group-page/tab-group-page.component.ts | Updates tab icon typing to CpsIconType for composition examples. |
| projects/composition/src/app/pages/icons-page/icons-page/icons-page.component.ts | Uses cpsIconNames/CpsIconType for icon list and filtering. |
| projects/composition/src/app/components/dialog-content/dialog-content.component.ts | Types dialog content icon as CpsIconType. |
| projects/composition/src/app/api-data/types_map.json | Updates type mapping to CpsIconType/CpsIconSizeType. |
| projects/composition/src/app/api-data/internal.json | Updates generated type names for icon-related props. |
| projects/composition/src/app/api-data/cps-tree-table.json | Updates generated prop types to CpsIconType for tree-table icons. |
| projects/composition/src/app/api-data/cps-tree-select.json | Updates generated prop types to CpsIconType/CpsIconSizeType. |
| projects/composition/src/app/api-data/cps-tree-autocomplete.json | Updates generated prop types to CpsIconType/CpsIconSizeType. |
| projects/composition/src/app/api-data/cps-table.json | Updates generated prop types to CpsIconType for table icons. |
| projects/composition/src/app/api-data/cps-sidebar-menu.json | Updates generated CpsSidebarMenuItem.icon type to CpsIconType. |
| projects/composition/src/app/api-data/cps-select.json | Updates generated prop types to CpsIconType/CpsIconSizeType. |
| projects/composition/src/app/api-data/cps-input.json | Updates generated prop types to CpsIconType/CpsIconSizeType. |
| projects/composition/src/app/api-data/cps-info-circle.json | Updates generated prop type to CpsIconSizeType. |
| projects/composition/src/app/api-data/cps-icon.json | Updates generated types to CpsIconType/CpsIconSizeType and expands the literal union. |
| projects/composition/src/app/api-data/cps-expansion-panel.json | Updates generated prop type to CpsIconType. |
| projects/composition/src/app/api-data/cps-dialog.json | Updates generated headerIcon type to CpsIconType. |
| projects/composition/src/app/api-data/cps-chip.json | Updates generated prop type to CpsIconType. |
| projects/composition/src/app/api-data/cps-checkbox.json | Updates generated prop type to CpsIconType. |
| projects/composition/src/app/api-data/cps-button.json | Updates generated prop type to CpsIconType. |
| projects/composition/src/app/api-data/cps-autocomplete.json | Updates generated prop types to CpsIconType/CpsIconSizeType. |
| api-generator/api-generator.js | Enhances union expansion for `typeof SomeArray[number] |
| .github/workflows/check_pr_title_cc.yml | Enables PR title conventional-commit checks on next-major in addition to master. |
Contributor
Playwright test resultsDetails
|
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.
This PR targets the
next-majorbranch, rather thanmaster, as it is part of the next major version update.Summary
IconTypewas defined as(typeof iconNames)[number], but sinceiconNameswasn't declaredas const, it widened to plainstring- so it accepted (and silently allowed typos in) any string, defeating the point of the type and losing IDE autocomplete.iconNamesis now declaredas const, so the type is a real restricted union of the actual icon names (plus''for "no icon" as a fallback state).While in there, the icon-related public type names were also renamed to be consistently
Cps-prefixed, and a few small internal cleanups were made tocps-toastand the internal API-docs generator.IconTypeis now a real restricted union, notstring. Any code passing a string that isn't a valid icon name (or'') to anicon/prefixIcon/etc. prop will now fail to compile.cps-ui-kit:IconType→CpsIconTypeiconNames→cpsIconNamesiconSizeType→CpsIconSizeTypeICONS_PATH→CPS_ICONS_PATHCpsSidebarMenuItem.iconchanged fromstringtoCpsIconType.CpsDialogConfig.headerIconchanged fromstringtoCpsIconType.CpsTableComponent/CpsTreeTableComponent—toolbarIcon,actionBtnIcon, andadditionalBtnOnSelectIconinputs changed fromstringtoCpsIconType.Migration guide
Any icon prop values (
icon,prefixIcon,toolbarIcon,actionBtnIcon,additionalBtnOnSelectIcon,CpsSidebarMenuItem.icon,CpsDialogConfig.headerIcon, etc.) must now be one of the values exported incpsIconNames, or''for no icon.Other changes
cps-toast: the icon-per-notification-type mapping was a getter re-evaluated on every change detection cycle; it's now computed once inngOnInit(matching howcoloris already computed) and stored as a field.cps-toast: removed redundant optional chaining ondata/config(both are required, always-bound inputs), replaced constructor-injectedNgZonewithinject(), and gavetimeouta proper type (ReturnType<typeof setTimeout> | null) instead ofany.api-generator.js: fixed API-docs generation for type aliases shaped liketypeof someArray[number] | ''— it previously only expanded a baretypeof X[number]into a readable literal union, not one nested in a top-level union, soCpsIconType's generated docs showed the unhelpfultypeof cpsIconNames[number] | ""instead of the actual list of icon names. Regenerated all affectedapi-data/*.jsonfiles.Release notes: