-
Notifications
You must be signed in to change notification settings - Fork 6.8k
chore(api): overlay class audits #6372 #7454
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/* Parses arguments into a ngClass-like object */ | ||
export function parseClassList(classList: | ||
undefined|string|string[]|Set<string>|{[klass: string]: any}) { | ||
let klasses = {}; | ||
|
||
if (classList) { | ||
if (Array.isArray(classList) || classList instanceof Set) { | ||
(<any>classList).forEach((klass: string) => klasses[klass] = true); | ||
} else if (typeof classList === 'string') { | ||
klasses = (<string>classList).split(' ').reduce((obj: any, className: string) => { | ||
obj[className] = true; | ||
return obj; | ||
}, {}); | ||
} | ||
} | ||
|
||
return klasses; | ||
} | ||
|
||
/** Parses a ngClass-like object into an array of strings */ | ||
export function getClassList(classList: {[klass: string]: any}): string[] { | ||
return Object.keys(classList).reduce((arr: string[], className: string) => { | ||
if (classList[className]) { | ||
arr.push(className); | ||
} | ||
return arr; | ||
}, []); | ||
} | ||
|
||
/** Parses a ngClass-like object into an array of strings */ | ||
export function parseAndGetClassList( | ||
klasses: undefined|string|string[]|Set<string>|{[klass: string]: any}) { | ||
return getClassList(parseClassList(klasses)); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './css'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
export * from './css'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../tsconfig-build", | ||
"files": [ | ||
"public_api.ts" | ||
], | ||
"angularCompilerOptions": { | ||
"annotateForClosureCompiler": true, | ||
"strictMetadataEmit": true, | ||
"flatModuleOutFile": "index.js", | ||
"flatModuleId": "@angular/cdk/css", | ||
"skipTemplateCodegen": true | ||
} | ||
} |
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
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
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
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
I'm sure that we need to support all of these formats.
NgClass
has them, presumably, because the expressions are dynamic and there a lot of ways to combine static classes and dynamic ones. In our case we only add the classes on init and we don't care about updating them, which can be done just as easily with an array.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 original ticket expressed desire to standardize this format. Ref: #6372
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.
FWIW NgClass seemed like a natural thing to support for template-based overlays like select, menu, autocomplete, tooltip. For dialog and snackbar, it's probably less important, but there are some good use cases for having the ability to dynamically update classes, #6206 (comment).
Further, I would personally find an NgClass cdk utility useful for custom overlay-based components!
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.
Template-based overlays should "just work" as they are at the moment (you can stick an
NgClass
on an element inside theTemplateRef
). This PR adds a similar signature to the programmatic API, but it's not reallyNgClass
because it won't update dynamically.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.
Ok tbh, I hadn't actually read the pr 😄 . My initial concern in filing #6372 was how snackbar and dialog differed in support and naming. Combined with little type info available in the docs (as #6947 is trying to solve) it's hard to anticipate exactly what will happen just by looking at the docs.
I agree,
{[klass: string]: any}
is probably extraneous (and maybe misrepresenting) if classes don't update dynamically. While I still think that's a valid feature via #6206, maybe for another time.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.
Ya, so basically this PR:
panelClass
ngClass
-likeThat means you can pass it an string, string array or object key/value pair. In the cases of the snackbar and overlay, there is no
ngClass
used so it just does a evaluate of the condition and matches it. I personally think the consistent signature is valuable and in the situation where there isn't realngClass
I could do an actual implementation I just didn't do it because I didn't know how far we wanted to take this.@jelbourn - Can you advise on next steps with this? Currently the PR is just in a evaluation phase and I know you expressed concerns with adding another CDK lib here too so I didn't want to take it too far without first review.