-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Adding avatar component for sistent project #6221
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
14 commits
Select commit
Hold shift + click to select a range
076c93c
feat: Adding avatar component for sistent project
Jaishree2310 05b9349
fix: eslint issues and unused component
Jaishree2310 2c4c64a
chore: updated the content.js
Jaishree2310 6d90004
fix: codeblock removed
Jaishree2310 0eb9ce6
feat: few changes made
Jaishree2310 56b622c
Code-block file added
Jaishree2310 00f803c
avatar-group removed empty
Jaishree2310 611cdcd
feat: Review changes made
Jaishree2310 da9e13f
details added
Jaishree2310 a4aa836
feat: tabs ui added in guidance
Jaishree2310 101422d
fix lint issue
Jaishree2310 6ceca58
tabs for overview in guidance
Jaishree2310 113638d
comments removed
Jaishree2310 f6cbdae
package.json resolved
Jaishree2310 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Empty file.
Empty file.
Empty file.
124 changes: 124 additions & 0 deletions
124
src/sections/Projects/Sistent/components/avatar/code.js
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,124 @@ | ||
| import React, { useState } from "react"; | ||
| import { Avatar, SistentThemeProvider } from "@layer5/sistent"; | ||
| import { SistentLayout } from "../../sistent-layout"; | ||
| import TabButton from "../../../../../reusecore/Button"; | ||
| import { useStyledDarkMode } from "../../../../../theme/app/useStyledDarkMode"; | ||
| import { CodeBlock } from "../button/code-block"; | ||
|
|
||
| const AvatarComponent = () => { | ||
| const { isDark } = useStyledDarkMode(); | ||
| const [activeTab, setActiveTab] = useState("Overview"); | ||
|
|
||
| const avatarExamples = [ | ||
| { | ||
| title: "Image Avatar", | ||
| description: "Display user profile images", | ||
| code: `<Avatar | ||
| src="/path/to/user-image.jpg" | ||
| alt="User Name" | ||
| />` | ||
| }, | ||
| { | ||
| title: "Initials Avatar", | ||
| description: "Use initials when image is unavailable", | ||
| code: `<Avatar> | ||
| JD | ||
| </Avatar>` | ||
| }, | ||
| { | ||
| title: "Icon Avatar", | ||
| description: "Use icons for generic representation", | ||
| code: `<Avatar> | ||
| <UserIcon /> | ||
| </Avatar>` | ||
| }, | ||
| { | ||
| title: "Sized Avatars", | ||
| description: "Adjust avatar sizes for different contexts", | ||
| code: `<Avatar size="small" /> | ||
| <Avatar size="medium" /> | ||
| <Avatar size="large" />` | ||
| }, | ||
| { | ||
| title: "Custom Styling", | ||
| description: "Apply custom styles and themes", | ||
| code: `<Avatar | ||
| src="/image.jpg" | ||
| sx={{ | ||
| border: '2px solid primary.main', | ||
| boxShadow: 2 | ||
| }} | ||
| />` | ||
| } | ||
| ]; | ||
|
|
||
| return ( | ||
| <SistentLayout title="Avatar"> | ||
| <div className="content"> | ||
| <a id="Identity"> | ||
| <h2>Avatar Component</h2> | ||
| </a> | ||
| <div className="filterBtns"> | ||
| {"Overview Guidance Code".split(" ").map((tab) => ( | ||
| <TabButton | ||
| key={tab} | ||
| title={tab} | ||
| className={activeTab === tab ? "active" : ""} | ||
| onClick={() => setActiveTab(tab)} | ||
| /> | ||
| ))} | ||
| </div> | ||
| <p> | ||
| The Avatar component provides a flexible visual representation of users | ||
| or entities across digital interfaces, supporting images, initials, and icons. | ||
| </p> | ||
| {activeTab === "Code" && ( | ||
| <div className="code-examples"> | ||
| <h3>Avatar Implementation Variants</h3> | ||
| {avatarExamples.map((example, index) => ( | ||
| <div key={index} className="code-example"> | ||
| <h4>{example.title}</h4> | ||
| <p>{example.description}</p> | ||
| <CodeBlock | ||
| name={`avatar-example-${index}`} | ||
| code={example.code} | ||
| /> | ||
| <div className="live-preview"> | ||
| <SistentThemeProvider initialMode={isDark ? "dark" : "light"}> | ||
| {example.title === "Image Avatar" && ( | ||
| <Avatar src="https://via.placeholder.com/150" alt="User Avatar" /> | ||
| )} | ||
| {example.title === "Initials Avatar" && ( | ||
| <Avatar>JD</Avatar> | ||
| )} | ||
| {example.title === "Icon Avatar" && ( | ||
| <Avatar>👤</Avatar> | ||
| )} | ||
| {example.title === "Sized Avatars" && ( | ||
| <> | ||
| <Avatar size="small" src="https://via.placeholder.com/50" /> | ||
| <Avatar size="medium" src="https://via.placeholder.com/75" sx={{ mx: 2 }} /> | ||
| <Avatar size="large" src="https://via.placeholder.com/100" /> | ||
| </> | ||
| )} | ||
| {example.title === "Custom Styling" && ( | ||
| <Avatar | ||
| src="https://via.placeholder.com/150" | ||
| sx={{ | ||
| border: "2px solid primary.main", | ||
| boxShadow: 2 | ||
| }} | ||
| /> | ||
| )} | ||
| </SistentThemeProvider> | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
| </SistentLayout> | ||
| ); | ||
| }; | ||
|
|
||
| export default AvatarComponent; |
132 changes: 132 additions & 0 deletions
132
src/sections/Projects/Sistent/components/avatar/guidance.js
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,132 @@ | ||
| import React from "react"; | ||
| import { navigate } from "gatsby"; | ||
| import { useLocation } from "@reach/router"; | ||
| import { SistentLayout } from "../../sistent-layout"; | ||
| import TabButton from "../../../../../reusecore/Button"; | ||
|
|
||
| const Guidance = () => { | ||
| const location = useLocation(); | ||
|
|
||
| return ( | ||
| <SistentLayout title="Avatar"> | ||
| <div className="content"> | ||
| <a id="identity"> | ||
| <h2>Avatar Usage Guidelines</h2> | ||
| </a> | ||
| <p> | ||
| The Avatar component represents a user using an image, initials, or an icon. | ||
| It is a crucial UI element for providing visual identity across digital platforms. | ||
| </p> | ||
|
|
||
| <div className="filterBtns"> | ||
| <TabButton | ||
| className={location.pathname === "/projects/sistent/components/avatar/overview" ? "active" : ""} | ||
| onClick={() => navigate("/projects/sistent/components/avatar/overview")} | ||
| title="Overview" | ||
| /> | ||
| <TabButton | ||
| className={location.pathname === "/projects/sistent/components/avatar/guidance" ? "active" : ""} | ||
| onClick={() => navigate("/projects/sistent/components/avatar/guidance")} | ||
| title="Guidance" | ||
| /> | ||
| <TabButton | ||
| className={location.pathname === "/projects/sistent/components/avatar/code" ? "active" : ""} | ||
| onClick={() => navigate("/projects/sistent/components/avatar/code")} | ||
| title="Code" | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="main-content"> | ||
| <a id="BestPractices"> | ||
| <h3>Best Practices</h3> | ||
| </a> | ||
| <ul> | ||
| <li> | ||
| <strong>Visual Representation:</strong> Choose clear, recognizable images that authentically represent the user or entity. | ||
| </li> | ||
| <li> | ||
| <strong>Fallback Mechanisms:</strong> Implement robust fallback strategies: | ||
| <code> | ||
| {"<Avatar src={userImage} alt={userName} fallback={<Avatar>{userInitials}</Avatar>}/>"} | ||
| </code> | ||
| </li> | ||
| <li>Maintain consistent avatar sizing and style across the application.</li> | ||
| <li>Optimize image resolution for performance and clarity.</li> | ||
| </ul> | ||
|
|
||
| <a id="Accessibility"> | ||
| <h3>Accessibility Considerations</h3> | ||
| </a> | ||
| <ul> | ||
| <li>Mandatory <code>alt</code> text for screen reader compatibility.</li> | ||
| <li>Ensure 4.5:1 color contrast ratio for initials and icons.</li> | ||
| <li>Add meaningful aria labels for context.</li> | ||
| </ul> | ||
|
|
||
| <a id="PerformanceOptimization"> | ||
| <h3>Performance Optimization</h3> | ||
| </a> | ||
| <ul> | ||
| <li>Use image compression techniques.</li> | ||
| <li>Implement lazy loading for avatar images.</li> | ||
| <li>Cache avatar images to reduce network requests.</li> | ||
| <li> | ||
| Example lazy loading implementation: | ||
| <code> | ||
| {"<Avatar loading=\"lazy\" src=\"/path/to/optimized/image.jpg\"/>"} | ||
| </code> | ||
| </li> | ||
| </ul> | ||
|
|
||
| <a id="AdvancedCustomization"> | ||
| <h3>Advanced Customization</h3> | ||
| </a> | ||
| <ul> | ||
| <li>Theme-aware color generation for initial avatars.</li> | ||
| <li>Status indicators (online/offline/away).</li> | ||
| <li> | ||
| Example status badge: | ||
| <code> | ||
| {"<Avatar src={userImage} status=\"online\" statusProps={{ color: 'green', position: 'bottom-right' }}/>"} | ||
| </code> | ||
| </li> | ||
| </ul> | ||
|
|
||
| <a id="IntegrationPatterns"> | ||
| <h3>Common Integration Patterns</h3> | ||
| </a> | ||
| <ul> | ||
| <li>User profile headers</li> | ||
| <li>Team member lists</li> | ||
| <li>Comment and messaging interfaces</li> | ||
| <li>Collaboration platform user representations</li> | ||
| </ul> | ||
|
|
||
| <a id="CodeSnippets"> | ||
| <h3>Code Snippet: Flexible Avatar Usage</h3> | ||
| </a> | ||
| <pre><code> | ||
| {`// Image Avatar | ||
| <Avatar src="/user-profile.jpg" alt="John Doe" /> | ||
|
|
||
| // Initials Avatar | ||
| <Avatar>JD</Avatar> | ||
|
|
||
| // Icon Avatar | ||
| <Avatar> | ||
| <UserIcon /> | ||
| </Avatar> | ||
|
|
||
| // Sized Avatars | ||
| <Avatar size="small" /> | ||
| <Avatar size="medium" /> | ||
| <Avatar size="large" /> | ||
| `} | ||
| </code></pre> | ||
| </div> | ||
| </div> | ||
| </SistentLayout> | ||
| ); | ||
| }; | ||
|
|
||
| export default Guidance; |
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.