-
Notifications
You must be signed in to change notification settings - Fork 3
feat(username): init component (#DS-3296) #944
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9871608
feat(username): init component (#DS-3296)
NikGurev 013158e
chore: added default view , refactor & examples
NikGurev af1bcb3
chore: added customization, replaced css classes with directives, ren…
NikGurev 75b7d34
chore: fixed examples
NikGurev 0e003e2
chore: fixed example name
NikGurev dbfcc8b
chore: added / updated examples, fixed lint errors
NikGurev 07969a5
chore: added tests, fixed types
NikGurev deed5e2
chore: fixed example
NikGurev a472b32
chore: fixed layout
NikGurev 947e5ba
chore: added expiration date
NikGurev 76b6f86
chore: fixed tests
NikGurev 0a53fa0
chore: fixed layout, exported types
NikGurev 642da73
chore: fixed golden checks
NikGurev e5faeca
chore: fixed public api
NikGurev 62cfeab
docs(username): edit article text (#DS-3296)
rmnturov 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { bootstrapApplication } from '@angular/platform-browser'; | ||
import { provideAnimations } from '@angular/platform-browser/animations'; | ||
import { DevApp } from './module'; | ||
|
||
bootstrapApplication(DevApp, { | ||
providers: [ | ||
provideAnimations() | ||
] | ||
}).catch((error) => console.error(error)); |
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,40 @@ | ||
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core'; | ||
import { UsernameExamplesModule } from '../../docs-examples/components/username'; | ||
|
||
@Component({ | ||
selector: 'dev-examples', | ||
standalone: true, | ||
imports: [UsernameExamplesModule], | ||
template: ` | ||
<username-overview-example /> | ||
<username-playground-example /> | ||
<username-custom-example /> | ||
<username-as-link-example /> | ||
`, | ||
styles: ` | ||
:host { | ||
display: flex; | ||
gap: var(--kbq-size-l); | ||
flex-wrap: wrap; | ||
} | ||
:host > * { | ||
border-radius: var(--kbq-size-border-radius); | ||
border: 1px solid var(--kbq-line-contrast-less); | ||
margin-bottom: var(--kbq-size-l); | ||
padding: var(--kbq-size-m); | ||
flex: 1 0 auto; | ||
} | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
class DevExamples {} | ||
|
||
@Component({ | ||
selector: 'dev-app', | ||
standalone: true, | ||
imports: [DevExamples], | ||
templateUrl: './template.html', | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class DevApp {} |
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 @@ | ||
<dev-examples /> |
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,5 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": ["**/*.d.ts"], | ||
"files": ["main.ts"] | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/components/username/__snapshots__/username.spec.ts.snap
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,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`KbqUsername should use default input values 1`] = ` | ||
{ | ||
"kbq-username": true, | ||
"kbq-username_default": true, | ||
"kbq-username_inline": true, | ||
} | ||
`; | ||
|
||
exports[`KbqUsernamePipe should format full name using custom format 1`] = ` | ||
[ | ||
"Alice B C", | ||
"Alice B. C.", | ||
"AliceB.C.", | ||
"A B C", | ||
"A.B.C.", | ||
"Alice B. C.", | ||
] | ||
`; |
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,30 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
import { KbqFormatKeyToProfileMapping, KbqFormatKeyToProfileMappingExtended, KbqUsernameFormatKey } from './types'; | ||
|
||
/** Default name format: Last name full, first and middle as initials. */ | ||
export const kbqDefaultFullNameFormatCustom = 'L f. m.'; | ||
/** Default name format: Last name full, first and middle as initials. */ | ||
export const kbqDefaultFullNameFormat = 'lf.m.'; | ||
|
||
/** | ||
* Throws an error when no profile field mapping is provided to the username pipe. | ||
* @docs-private | ||
*/ | ||
export function KbqMappingMissingError() { | ||
return new Error('KbqUsernamePipe: profile field mapping is required but was not provided.'); | ||
} | ||
|
||
/** | ||
* Injection token for providing a global username format-to-profile mapping. | ||
*/ | ||
export const KBQ_PROFILE_MAPPING = new InjectionToken< | ||
KbqFormatKeyToProfileMapping | KbqFormatKeyToProfileMappingExtended | ||
>('KBQ_PROFILE_MAPPING', { | ||
factory: () => | ||
({ | ||
[KbqUsernameFormatKey.FirstNameShort]: 'firstName', | ||
[KbqUsernameFormatKey.MiddleNameShort]: 'middleName', | ||
[KbqUsernameFormatKey.LastNameShort]: 'lastName', | ||
[KbqUsernameFormatKey.Dot]: undefined | ||
}) satisfies KbqFormatKeyToProfileMapping<{ firstName: string; middleName: string; lastName: string }> | ||
}); |
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,5 @@ | ||
export * from './constants'; | ||
export * from './module'; | ||
export * from './types'; | ||
export * from './username'; | ||
export * from './username.pipe'; |
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,18 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { KbqUsername, KbqUsernameCustomView, KbqUsernamePrimary, KbqUsernameSecondary } from './username'; | ||
import { KbqUsernameCustomPipe, KbqUsernamePipe } from './username.pipe'; | ||
|
||
const COMPONENTS = [ | ||
KbqUsername, | ||
KbqUsernameCustomView, | ||
KbqUsernamePrimary, | ||
KbqUsernameSecondary, | ||
KbqUsernameCustomPipe, | ||
KbqUsernamePipe | ||
]; | ||
|
||
@NgModule({ | ||
imports: COMPONENTS, | ||
exports: COMPONENTS | ||
}) | ||
export class KbqUsernameModule {} |
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,5 @@ | ||
{ | ||
"lib": { | ||
"entryFile": "index.ts" | ||
} | ||
} |
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,74 @@ | ||
/** | ||
* Keys for formatting username parts in short (initial) or full form. | ||
*/ | ||
export enum KbqUsernameFormatKey { | ||
/** | ||
* Short form of the first name (e.g., "John" → "J") | ||
*/ | ||
FirstNameShort = 'f', | ||
|
||
/** | ||
* Full form of the first name (e.g., "John") | ||
*/ | ||
FirstNameFull = 'F', | ||
|
||
/** | ||
* Short form of the middle name (e.g., "Henry" → "H") | ||
*/ | ||
MiddleNameShort = 'm', | ||
|
||
/** | ||
* Full form of the middle name (e.g., "Henry") | ||
*/ | ||
MiddleNameFull = 'M', | ||
|
||
/** | ||
* Short form of the last name (e.g., "Doe" → "D") | ||
*/ | ||
LastNameShort = 'l', | ||
|
||
/** | ||
* Full form of the last name (e.g., "Doe") | ||
*/ | ||
LastNameFull = 'L', | ||
Dot = '.' | ||
} | ||
|
||
/** | ||
* Maps each format key to a property name in the user profile object. | ||
* Allows flexible formatting regardless of profile field names. | ||
*/ | ||
export type KbqFormatKeyToProfileMapping<T = any> = { | ||
[key in Exclude< | ||
KbqUsernameFormatKey, | ||
KbqUsernameFormatKey.FirstNameFull | KbqUsernameFormatKey.MiddleNameFull | KbqUsernameFormatKey.LastNameFull | ||
>]: keyof T | undefined; | ||
}; | ||
|
||
/** | ||
* Maps each format key to a property name in the user profile object. | ||
* Allows flexible formatting regardless of profile field names. | ||
* @see KbqUsernameCustomPipe | ||
*/ | ||
export type KbqFormatKeyToProfileMappingExtended<T = any> = { | ||
[key in KbqUsernameFormatKey]: keyof T | undefined; | ||
}; | ||
|
||
/** | ||
* Layout mode for displaying a username and applying text-ellipsis. | ||
* | ||
* - `stacked`: Elements shown vertically. | ||
* - `inline`: Elements shown in one line. Text ellipsis is applied to both parts. | ||
* - `text`: Plain text, no layout styling. No text-ellipsis. | ||
*/ | ||
export type KbqUsernameMode = 'stacked' | 'inline' | 'text'; | ||
|
||
/** | ||
* Visual style of the username. | ||
* | ||
* - `default`: standard styling with primary and secondary colors. | ||
* - `error`: error colors (e.g., red). | ||
* - `accented`: no color theming; emphasizes via typography only. | ||
* - `inherit`: inherits parent styles, no theming. For example, useful when using inside links. | ||
*/ | ||
export type KbqUsernameStyle = 'default' | 'error' | 'accented' | 'inherit'; |
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,6 @@ | ||
:where(.kbq-username) { | ||
--kbq-username-primary-color: var(--kbq-foreground-contrast); | ||
--kbq-username-secondary-color: inherit; | ||
--kbq-username-vertical-gap: var(--kbq-size-xxs); | ||
--kbq-username-horizontal-gap: var(--kbq-size-xxs); | ||
} |
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,23 @@ | ||
The pattern is used when the interface refers to an internal user. | ||
|
||
Displaying the username means showing a set of attributes from the internal system user that help identify them in the interface. | ||
|
||
<!-- example(username-overview) --> | ||
|
||
### Configuration demo | ||
|
||
<!-- example(username-playground) --> | ||
|
||
### Custom template | ||
|
||
If flexible layout is required and the default template doesn’t meet your needs, use the `custom` mode with the `KbqUsernameCustomView` directive. | ||
|
||
This mode supports the same display styles and modes while maintaining consistency with the design system. | ||
|
||
To format the full name, use the `kbqUsernameCustom` pipe with a format string and a mapping definition (an object that links format elements to corresponding user properties, determining what data should be shown). | ||
|
||
<!-- example(username-custom) --> | ||
|
||
The component can be conveniently used inside links. To visually match the link style, set the `inherit` style — this ensures that color and appearance are inherited from the parent element. | ||
|
||
<!-- example(username-as-link) --> |
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,35 @@ | ||
@let profile = userInfo(); | ||
<ng-content select="kbq-username-custom-view,[kbq-username-custom-view]" /> | ||
|
||
@if (!customView() && profile) { | ||
@let fullName = profile | kbqUsername: fullNameFormat(); | ||
|
||
@if (!isCompact()) { | ||
@if (hasFullName()) { | ||
<span kbq-title kbqUsernamePrimary>{{ fullName }}</span> | ||
} | ||
|
||
@if (profile.login) { | ||
<span kbq-title kbqUsernameSecondary> | ||
{{ profile.login }} | ||
|
||
@if (profile.site) { | ||
<span kbqUsernameSecondaryHint>({{ profile.site }})</span> | ||
} | ||
</span> | ||
} | ||
} @else { | ||
<span kbq-title kbqUsernamePrimary> | ||
@if (hasFullName()) { | ||
<span>{{ fullName }}</span> | ||
} | ||
@if (!hasFullName() && profile.login) { | ||
{{ profile.login }} | ||
} | ||
|
||
@if (profile.site) { | ||
<span kbqUsernameSecondaryHint> ({{ profile.site }})</span> | ||
} | ||
</span> | ||
} | ||
} |
Oops, something went wrong.
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.