Skip to content

Commit

Permalink
test: avatar (#183)
Browse files Browse the repository at this point in the history
tests: avatar, colors, sizes, badge positions, texts

tests: added accessibility tests

tests: added tests for initials

tests: added golden tests

fix: changed avatar xs so it shows two initals

fix: changed example back

fix: added some commas

chore(automated): Lint commit and format

test: added loop for zetaavatar with border color for $size

docs: added brief docs for fontSize function in avatar

fix: get initials now returns the first and last name initials rather than first and second names.

test: changed extension test to reflect changes

test: removed comment that was cause github action to fail
  • Loading branch information
DE7924 authored Oct 11, 2024
1 parent 7fba9b2 commit ef050af
Show file tree
Hide file tree
Showing 59 changed files with 418 additions and 8 deletions.
22 changes: 16 additions & 6 deletions lib/src/components/avatars/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ZetaAvatar extends ZetaStatelessWidget {
(initials != null
? Center(
child: Text(
size == ZetaAvatarSize.xs ? initials!.substring(0, 1) : initials!,
initials!,
style: initialTextStyle ??
TextStyle(
fontSize: size.fontSize(context),
Expand Down Expand Up @@ -288,11 +288,10 @@ class ZetaAvatar extends ZetaStatelessWidget {
..add(StringProperty('semanticLowerBadgeValue', semanticLowerBadgeLabel))
..add(DiagnosticsProperty<TextStyle>('initialTextStyle', initialTextStyle));
}
}

extension on ZetaAvatarSize {
double pixelSize(BuildContext context) {
switch (this) {
/// Returns pixel size for [ZetaAvatarSize]
static double pixelSize(BuildContext context, ZetaAvatarSize size) {
switch (size) {
case ZetaAvatarSize.xxxl:
return Zeta.of(context).spacing.minimum * 50; // TODO(UX-1202): ZetaSpacingBase
// return ZetaSpacingBase.x50;
Expand All @@ -316,6 +315,17 @@ extension on ZetaAvatarSize {
}
}

/// Font size for initials
static double fontSize(BuildContext context, ZetaAvatarSize size) {
return pixelSize(context, size) * 4 / 9;
}
}

extension on ZetaAvatarSize {
double pixelSize(BuildContext context) {
return ZetaAvatar.pixelSize(context, this);
}

double borderSize(BuildContext context) {
switch (this) {
case ZetaAvatarSize.xxxl:
Expand All @@ -335,7 +345,7 @@ extension on ZetaAvatarSize {
}

double fontSize(BuildContext context) {
return pixelSize(context) * 4 / 9;
return ZetaAvatar.fontSize(context, this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension StringExtensions on String? {
final List<String> nameParts = this!.split(RegExp(r'\W+'))..removeWhere((item) => item.isEmpty);
if (nameParts.isEmpty) return '';
return (nameParts.length > 1
? nameParts[0].substring(0, 1) + nameParts[1].substring(0, 1)
? nameParts[0].substring(0, 1) + nameParts[nameParts.length - 1].substring(0, 1)
: nameParts[0].length > 1
? nameParts[0].substring(0, 2)
: nameParts[0])
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ef050af

Please sign in to comment.