-
Notifications
You must be signed in to change notification settings - Fork 17
Avatar component implementation #2285
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
31 commits
Select commit
Hold shift + click to select a range
909af22
First Draft of Avatar component
PelayoFelgueroso 6bcb74e
Fix chromatic test fail with aria-label
PelayoFelgueroso 597c2a9
Fix aria-label when no role is assigned
PelayoFelgueroso 14c3416
Fix based on review and add disabled prop functionality
PelayoFelgueroso bad82a6
Fix based on feedback
PelayoFelgueroso 6e218a7
Fix border and outline of the component states
PelayoFelgueroso cdcde7c
Fix focus and active color
PelayoFelgueroso 7466164
Update storybook with all states
PelayoFelgueroso b19ebff
Fix story book errors by dividing storybook into 3 different pages
PelayoFelgueroso bde8a68
Merge branch 'master' into PelayoFelgueroso-avatar
PelayoFelgueroso 4df408d
Reduce storybook variants
PelayoFelgueroso 13d138f
Merge branch 'PelayoFelgueroso-avatar' of https://github.com/dxc-tech…
PelayoFelgueroso 364a08f
Avatar tooltip is displayed by default and reordered avatar circle an…
PelayoFelgueroso 1a6f5f0
Added new logic to ease displaying all the variants in stories
Mil4n0r 8060acf
Removed comment
Mil4n0r b3e64ed
Added status variant to pseudoStates story and added color variants t…
PelayoFelgueroso 6402845
Merge branch 'master' into PelayoFelgueroso-avatar
PelayoFelgueroso ec9be78
Add DxcTypography & some code improvements
PelayoFelgueroso 1dde622
Merge branch 'master' into PelayoFelgueroso-avatar
PelayoFelgueroso f8b7e15
Merge branch 'master' into PelayoFelgueroso-avatar
PelayoFelgueroso 13f2c21
Added new semantic token and changed color variants to fit same guide…
PelayoFelgueroso eb5bd12
Merge branch 'master' into PelayoFelgueroso-avatar
PelayoFelgueroso 8f53c5e
Minor fix on href prop
PelayoFelgueroso 7f3f77a
Added React.AnchorHTMLAttributes<HTMLAnchorElement> to Avatar.tsx
PelayoFelgueroso 33decde
Merge branch 'PelayoFelgueroso-avatar' of https://github.com/dxc-tech…
PelayoFelgueroso c765e92
Improve code quality
PelayoFelgueroso 72245c0
Merge branch 'master' into PelayoFelgueroso-avatar
PelayoFelgueroso 3d5fe3b
Add new vitest and storybook functionalities
PelayoFelgueroso 668135a
Added documentation for Avatar
PelayoFelgueroso de81852
Merge branch 'master' into PelayoFelgueroso-avatar
PelayoFelgueroso 08c2a98
Resolve comments
PelayoFelgueroso 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,17 @@ | ||
| import Head from "next/head"; | ||
| import { ReactElement } from "react-markdown/lib/react-markdown"; | ||
| import AvatarPageLayout from "screens/components/avatar/AvatarPageLayout"; | ||
| import AvatarCodePage from "screens/components/avatar/code/AvatarCodePage"; | ||
|
|
||
| const Code = () => ( | ||
| <> | ||
| <Head> | ||
| <title>Avatar code - Halstack Design</title> | ||
| </Head> | ||
| <AvatarCodePage /> | ||
| </> | ||
| ); | ||
|
|
||
| Code.getLayout = (page: ReactElement) => <AvatarPageLayout>{page}</AvatarPageLayout>; | ||
|
|
||
| export default Code; |
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,17 @@ | ||
| import Head from "next/head"; | ||
| import { ReactElement } from "react-markdown/lib/react-markdown"; | ||
| import AvatarPageLayout from "screens/components/avatar/AvatarPageLayout"; | ||
| import AvatarOverviewPage from "screens/components/avatar/overview/AvatarOverviewPage"; | ||
|
|
||
| const Index = () => ( | ||
| <> | ||
| <Head> | ||
| <title>Avatar - Halstack Design System</title> | ||
| </Head> | ||
| <AvatarOverviewPage /> | ||
| </> | ||
| ); | ||
|
|
||
| Index.getLayout = (page: ReactElement) => <AvatarPageLayout>{page}</AvatarPageLayout>; | ||
|
|
||
| export default Index; |
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
31 changes: 31 additions & 0 deletions
31
apps/website/screens/components/avatar/AvatarPageLayout.tsx
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,31 @@ | ||
| import ComponentHeading from "@/common/ComponentHeading"; | ||
| import PageHeading from "@/common/PageHeading"; | ||
| import TabsPageHeading from "@/common/TabsPageLayout"; | ||
| import { DxcFlex, DxcParagraph } from "@dxc-technology/halstack-react"; | ||
| import { ReactNode } from "react"; | ||
|
|
||
| const AvatarPageHeading = ({ children }: { children: ReactNode }) => { | ||
| const tabs = [ | ||
| { label: "Overview", path: "/components/avatar" }, | ||
| { label: "Code", path: "/components/avatar/code" }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <DxcFlex direction="column" gap="var(--spacing-gap-xxl)"> | ||
| <PageHeading> | ||
| <DxcFlex direction="column" gap="var(--spacing-gap-xl)"> | ||
| <ComponentHeading name="Avatar" /> | ||
| <DxcParagraph> | ||
| The Avatar component is a key visual element used to identify users, teams, or entities across the | ||
| interface. It helps create a recognizable and consistent user experience by visually representing people or | ||
| objects through images, icons, or initials. | ||
| </DxcParagraph> | ||
| <TabsPageHeading tabs={tabs} /> | ||
| </DxcFlex> | ||
| </PageHeading> | ||
| {children} | ||
| </DxcFlex> | ||
| ); | ||
| }; | ||
|
|
||
| export default AvatarPageHeading; |
178 changes: 178 additions & 0 deletions
178
apps/website/screens/components/avatar/code/AvatarCodePage.tsx
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,178 @@ | ||
| import { ExtendedTableCode, TableCode } from "@/common/Code"; | ||
| import Example from "@/common/example/Example"; | ||
| import DxcQuickNavContainer from "@/common/QuickNavContainer"; | ||
| import { DxcFlex, DxcTable } from "@dxc-technology/halstack-react"; | ||
| import DocFooter from "@/common/DocFooter"; | ||
| import basicUsage from "./examples/basicUsage"; | ||
| import clickable from "./examples/clickable"; | ||
| import tooltip from "./examples/tooltip"; | ||
| import status from "./examples/status"; | ||
|
|
||
| const statusTypeString = `{ | ||
| mode: 'default' | 'info' | | ||
| 'success' | 'warning' | 'error'; | ||
| position: 'top' | 'bottom'; | ||
| }`; | ||
|
|
||
| const sections = [ | ||
| { | ||
| title: "Props", | ||
| content: ( | ||
| <DxcTable> | ||
| <thead> | ||
| <tr> | ||
| <th>Name</th> | ||
| <th>Type</th> | ||
| <th>Description</th> | ||
| <th>Default</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr> | ||
| <td>color</td> | ||
| <td> | ||
| <TableCode> | ||
| 'primary' | 'secondary' | 'tertiary' | 'success' | 'info' | 'neutral' |'warning' | 'error' | ||
| </TableCode> | ||
| </td> | ||
| <td>Affects the visual style of the avatar. It can be used following semantic purposes or not.</td> | ||
| <td> | ||
| <TableCode>'neutral'</TableCode> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td>disabled</td> | ||
| <td> | ||
| <TableCode>boolean</TableCode> | ||
| </td> | ||
| <td>If true, the componente will be disabled.</td> | ||
| <td> | ||
| <TableCode>false</TableCode> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td>icon</td> | ||
| <td> | ||
| <TableCode>string | SVG</TableCode> | ||
| </td> | ||
| <td>Material Symbol name or SVG element as the icon that will be placed as avatar.</td> | ||
| <td> | ||
| <TableCode>'person'</TableCode> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td>imageSrc</td> | ||
| <td> | ||
| <TableCode>string</TableCode> | ||
| </td> | ||
| <td>URL of the image.</td> | ||
| <td>-</td> | ||
| </tr> | ||
| <tr> | ||
| <td>label</td> | ||
| <td> | ||
| <TableCode>string</TableCode> | ||
| </td> | ||
| <td>Text label associated with the avatar. Used to generate and display initials inside the avatar.</td> | ||
| <td>-</td> | ||
| </tr> | ||
| <tr> | ||
| <td>linkHref</td> | ||
| <td> | ||
| <TableCode>string</TableCode> | ||
| </td> | ||
| <td>Page to be opened when the user clicks on the link.</td> | ||
| <td>-</td> | ||
| </tr> | ||
| <tr> | ||
| <td>onClick</td> | ||
| <td> | ||
| <TableCode>{"() => void"}</TableCode> | ||
| </td> | ||
| <td>This function will be called when the user clicks the avatar. Makes it behave as a button.</td> | ||
| <td>-</td> | ||
| </tr> | ||
| <tr> | ||
| <td>shape</td> | ||
| <td> | ||
| <TableCode>'circle' | 'square'</TableCode> | ||
| </td> | ||
| <td>This will determine if the avatar will be a rounded square or a circle.</td> | ||
| <td> | ||
| <TableCode>'circle'</TableCode> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td>size</td> | ||
| <td> | ||
| <TableCode>'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge'</TableCode> | ||
| </td> | ||
| <td>Size of the component.</td> | ||
| <td> | ||
| <TableCode>'medium'</TableCode> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td>status</td> | ||
| <td> | ||
| <ExtendedTableCode>{statusTypeString}</ExtendedTableCode> | ||
| </td> | ||
| <td> | ||
| Defines the color of the status indicator displayed on the avatar and where it will be placed. If not | ||
| provided, no indicator will be rendered. | ||
| </td> | ||
| <td>-</td> | ||
| </tr> | ||
| <tr> | ||
| <td>tabIndex</td> | ||
| <td> | ||
| <TableCode>number</TableCode> | ||
| </td> | ||
| <td>Value of the tabindex attribute. It will only apply when the onClick property is passed.</td> | ||
| <td> | ||
| <TableCode>0</TableCode> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td>title</td> | ||
| <td> | ||
| <TableCode>string</TableCode> | ||
| </td> | ||
| <td>Text to be displayed inside a tooltip when hovering the avatar.</td> | ||
| <td>-</td> | ||
| </tr> | ||
| </tbody> | ||
| </DxcTable> | ||
| ), | ||
| }, | ||
| { | ||
| title: "Examples", | ||
| subSections: [ | ||
| { | ||
| title: "Basic usage", | ||
| content: <Example example={basicUsage} defaultIsVisible />, | ||
| }, | ||
| { | ||
| title: "Clickable", | ||
| content: <Example example={clickable} defaultIsVisible />, | ||
| }, | ||
| { | ||
| title: "Status", | ||
| content: <Example example={status} defaultIsVisible />, | ||
| }, | ||
| { | ||
| title: "Tooltip", | ||
| content: <Example example={tooltip} defaultIsVisible />, | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| const AvatarCodePage = () => ( | ||
| <DxcFlex direction="column" gap="4rem"> | ||
| <DxcQuickNavContainer sections={sections} startHeadingLevel={2} /> | ||
| <DocFooter githubLink="https://github.com/dxc-technology/halstack-react/blob/master/apps/website/screens/components/avatar/code/AvatarCodePage.tsx" /> | ||
| </DxcFlex> | ||
| ); | ||
|
|
||
| export default AvatarCodePage; | ||
19 changes: 19 additions & 0 deletions
19
apps/website/screens/components/avatar/code/examples/basicUsage.tsx
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,19 @@ | ||
| import { DxcAvatar, DxcInset } from "@dxc-technology/halstack-react"; | ||
|
|
||
| const code = `() => { | ||
| return ( | ||
| <DxcInset space="var(--spacing-padding-xl)"> | ||
| <DxcAvatar | ||
| label="John Doe" | ||
| color="success" | ||
| /> | ||
| </DxcInset> | ||
| ); | ||
| }`; | ||
|
|
||
| const scope = { | ||
| DxcAvatar, | ||
| DxcInset, | ||
| }; | ||
|
|
||
| export default { code, scope }; |
19 changes: 19 additions & 0 deletions
19
apps/website/screens/components/avatar/code/examples/clickable.tsx
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,19 @@ | ||
| import { DxcAvatar, DxcInset } from "@dxc-technology/halstack-react"; | ||
|
|
||
| const code = `() => { | ||
| return ( | ||
| <DxcInset space="var(--spacing-padding-xl)"> | ||
| <DxcAvatar | ||
| color="success" | ||
| onClick={() => console.log("Hello")} | ||
| /> | ||
| </DxcInset> | ||
| ); | ||
| }`; | ||
|
|
||
| const scope = { | ||
| DxcAvatar, | ||
| DxcInset, | ||
| }; | ||
|
|
||
| export default { code, scope }; |
19 changes: 19 additions & 0 deletions
19
apps/website/screens/components/avatar/code/examples/status.tsx
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,19 @@ | ||
| import { DxcAvatar, DxcInset } from "@dxc-technology/halstack-react"; | ||
|
|
||
| const code = `() => { | ||
| return ( | ||
| <DxcInset space="var(--spacing-padding-xl)"> | ||
| <DxcAvatar | ||
| color="error" | ||
| status={{mode: "success", position: "top"}} | ||
| /> | ||
| </DxcInset> | ||
| ); | ||
| }`; | ||
|
|
||
| const scope = { | ||
| DxcAvatar, | ||
| DxcInset, | ||
| }; | ||
|
|
||
| export default { code, scope }; |
19 changes: 19 additions & 0 deletions
19
apps/website/screens/components/avatar/code/examples/tooltip.tsx
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,19 @@ | ||
| import { DxcAvatar, DxcInset } from "@dxc-technology/halstack-react"; | ||
|
|
||
| const code = `() => { | ||
| return ( | ||
| <DxcInset space="var(--spacing-padding-xl)"> | ||
| <DxcAvatar | ||
| color="success" | ||
| title="User Name" | ||
| /> | ||
| </DxcInset> | ||
| ); | ||
| }`; | ||
|
|
||
| const scope = { | ||
| DxcAvatar, | ||
| DxcInset, | ||
| }; | ||
|
|
||
| export default { code, scope }; |
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.