-
Notifications
You must be signed in to change notification settings - Fork 989
refactor: share icon ligature conversion across renderers #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| declare module '@a2ui/web_core/styles/icons' { | ||
| export function toMaterialSymbolLigature(iconName: string): string; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import * as assert from 'node:assert'; | ||
| import { describe, it } from 'node:test'; | ||
| import { toMaterialSymbolLigature } from './icons.js'; | ||
|
|
||
| describe('Icon styles helpers', () => { | ||
| it('leaves simple icon names unchanged', () => { | ||
| assert.strictEqual(toMaterialSymbolLigature('home'), 'home'); | ||
| }); | ||
|
|
||
| it('converts camelCase names to snake_case ligatures', () => { | ||
| assert.strictEqual(toMaterialSymbolLigature('shoppingCart'), 'shopping_cart'); | ||
| assert.strictEqual(toMaterialSymbolLigature('accountCircle'), 'account_circle'); | ||
|
Comment on lines
+27
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to add test cases for icon names that start with a capital letter to ensure they are converted correctly without a leading underscore, which would align with the suggested change in assert.strictEqual(toMaterialSymbolLigature('shoppingCart'), 'shopping_cart');
assert.strictEqual(toMaterialSymbolLigature('ShoppingCart'), 'shopping_cart');
assert.strictEqual(toMaterialSymbolLigature('accountCircle'), 'account_circle');
assert.strictEqual(toMaterialSymbolLigature('AccountCircle'), 'account_circle'); |
||
| }); | ||
|
|
||
| it('keeps existing separators and lowercases the result', () => { | ||
| assert.strictEqual( | ||
| toMaterialSymbolLigature('unknownIconName12345'), | ||
| 'unknown_icon_name12345' | ||
| ); | ||
| assert.strictEqual(toMaterialSymbolLigature('already_snake_case'), 'already_snake_case'); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,14 @@ | |||||
| * limitations under the License. | ||||||
| */ | ||||||
|
|
||||||
| /** | ||||||
| * Convert an A2UI camelCase icon name into the snake_case ligature used by | ||||||
| * Material Symbols. | ||||||
| */ | ||||||
| export function toMaterialSymbolLigature(iconName: string): string { | ||||||
| return iconName.replace(/([A-Z])/g, '_$1').toLowerCase(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation can produce a leading underscore if You can fix this by removing the leading underscore after the replacement, before converting to lower case.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * CSS classes for Google Symbols. | ||||||
| * | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path alias you've added here should be sufficient for TypeScript to resolve the module and its types directly from the source
.tsfile. The new declaration filerenderers/react/src/web-core-icons.d.tsappears to be redundant and adds a maintenance burden, as it would need to be manually kept in sync withicons.ts.Consider removing
renderers/react/src/web-core-icons.d.tsand relying solely on the path mapping.