-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Avatar): fix edge-cases for initials
- Loading branch information
1 parent
7c11211
commit 472e9ee
Showing
6 changed files
with
164 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
--- | ||
"@einride/ui": patch | ||
--- | ||
|
||
Avatar: Fix edge-cases for initials. |
65 changes: 65 additions & 0 deletions
65
packages/einride-ui/src/components/content/Avatar/Avatar.mdx
This file contains 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,65 @@ | ||
import { | ||
Meta, | ||
Primary, | ||
Description, | ||
Source, | ||
Title, | ||
ArgTypes, | ||
Subtitle, | ||
Controls, | ||
Story, | ||
Canvas, | ||
Stories, | ||
Markdown, | ||
} from "@storybook/blocks" | ||
import * as Avatar from "./Avatar.stories.tsx" | ||
|
||
<Meta of={Avatar} /> | ||
|
||
<Title /> | ||
|
||
<Description of={Avatar} /> | ||
|
||
```tsx | ||
import { Avatar } from "@einride/ui" | ||
``` | ||
|
||
## Basic | ||
|
||
<Description of={Avatar.Basic} /> | ||
|
||
<Canvas of={Avatar.Basic} /> | ||
|
||
<Controls of={Avatar.Basic} /> | ||
|
||
## Shape | ||
|
||
<Description of={Avatar.Square} /> | ||
|
||
<Canvas of={Avatar.Square} /> | ||
|
||
<Controls of={Avatar.Square} include="radius" /> | ||
|
||
## Size | ||
|
||
<Description of={Avatar.Small} /> | ||
|
||
<Canvas of={Avatar.Small} /> | ||
|
||
<Controls of={Avatar.Small} include="size" /> | ||
|
||
## Initials | ||
|
||
<Description of={Avatar.Initials} /> | ||
|
||
<Canvas of={Avatar.Initials} /> | ||
|
||
<Controls of={Avatar.Initials} include="name" /> | ||
|
||
## Custom colors | ||
|
||
<Description of={Avatar.CustomColors} /> | ||
|
||
<Canvas of={Avatar.CustomColors} /> | ||
|
||
<Controls of={Avatar.CustomColors} include={["color", "background"]} /> |
This file contains 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 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 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
8 changes: 4 additions & 4 deletions
8
packages/einride-ui/src/components/content/Avatar/getInitials.ts
This file contains 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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
export const getInitials = (name: string | undefined): string | null => { | ||
if (!name) return null | ||
export const getInitials = (name: string | undefined): string => { | ||
if (!name) return "" | ||
|
||
const parts = name.split(" ") | ||
const parts = name.trim().split(" ") | ||
|
||
if (parts.length === 1) return parts[0].charAt(0).toUpperCase() | ||
if (parts.length >= 2) | ||
return `${parts[0].charAt(0)}${parts[parts.length - 1].charAt(0)}`.toUpperCase() | ||
|
||
return null | ||
return "" | ||
} |