-
Notifications
You must be signed in to change notification settings - Fork 3
ProfileCard component #318
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
Open
sreidthomas
wants to merge
45
commits into
dev
Choose a base branch
from
feature.issue.294
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
d4a1704
Initial set up for ProfileCard component
sreidthomas c104eea
Fixed prettier issues in 3 files
sreidthomas eb6cd79
Created full profile-card component with completed javascript
sreidthomas 3f31755
Fixed prettier issues in 1 file by removing the console.warn
sreidthomas 0745bad
Added scss/css for profilecard
sreidthomas f320697
Fixed prettier issues in 2 files
sreidthomas d43edd2
Changed object fit to cover and pixels to rems
sreidthomas 1bc632b
Fixed prettier issues in 1 file
sreidthomas 3ce7e17
Added link-href as an attribute and the ability to click the profile …
sreidthomas 9dc03b6
Fixed prettier issues in 2 files
sreidthomas cbe49d1
Removed text decoration from name and titles
sreidthomas dfd4343
Merge branch 'dev' into feature.issue.294
sreidthomas cfeabd5
Added documentation for Profile Card, updated attribute names for Pro…
sreidthomas 9e551a2
Updated ProfileCard.js functions to work better with storybook tests.…
sreidthomas e9dd8d3
Fixed prettier issues in 3 files and removed unused variable in stori…
sreidthomas aa41b70
Changed reflect status in documentation
sreidthomas df34cea
Added Reflective JS properties for attributes
sreidthomas b17cadb
Fixed prettier issues in 1 file
sreidthomas 1e93d2f
Removed duplicate cod-gov-banner.js file
sreidthomas 0daceaa
Removed validate slot methods and sanity checks
sreidthomas aac6062
Removed validate slot test from stories file
sreidthomas b7394d3
Removed unused validationError function
sreidthomas 519f948
Added margin to the bottom of profile card text and removed blue colo…
sreidthomas 93527aa
Removed call to validateSlots function from connectedcallback, remove…
sreidthomas 224bdee
Added drop shadow to profile card image, removed parameter that allow…
sreidthomas 98741f1
Updated documentation to include Usage section
sreidthomas 907e8ab
Fixed prettier issues in 1 file
sreidthomas 402e0f6
Fixed Reflective JS issues
sreidthomas 21b5bd9
Fixed prettier issues in 1 file
sreidthomas 4281523
Updated slots for primary and secondary fields in multiple files
sreidthomas 4924f26
Updated if/else for updateLink function
sreidthomas f5e92a3
Removed the default img for the updateImage function
sreidthomas c6abe6c
Fixed prettier issues in 1 file
sreidthomas b2461d1
Added slot styles to the light-dom
sreidthomas 524bcac
Fixed prettier issues in 2 files
sreidthomas f8ac9c0
Added chevron as Bootstrap SVG. Added slight transform on hover for c…
sreidthomas 48901ba
Added alt attribute to component
sreidthomas 72abd05
Fixed prettier issues in 2 files
sreidthomas 90528ac
Updated the ProfileCard.mdx file
sreidthomas 1c0eb2d
Exposed target and rel attributes
sreidthomas c2a6c61
Fixed prettier issues in 1 file
sreidthomas 7de4119
Removed second name slot field
sreidthomas bcb40ec
Removed all fallback values
sreidthomas 6daf916
Updated scss so that chevron animation happens when on any part of th…
sreidthomas 8d2fe0a
Merge branch 'dev' into feature.issue.294
sreidthomas 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import styles from '!!raw-loader!./ProfileCard.css'; | ||
|
|
||
| const template = document.createElement('template'); | ||
| template.innerHTML = ` | ||
| <style> | ||
| ${styles} | ||
| </style> | ||
| <a class="profile-card"> | ||
| <img class="profile-image" alt="Profile Image"> | ||
| <div class="profile-details"> | ||
| <div class="name-container"> | ||
| <slot name="name"></slot> | ||
| <span class="chevron"></span> | ||
| </div> | ||
| <slot name="title"></slot> | ||
| </div> | ||
| </a> | ||
| `; | ||
|
|
||
| class ProfileCard extends HTMLElement { | ||
| constructor() { | ||
| super(); | ||
| const shadow = this.attachShadow({ mode: 'open' }); | ||
| shadow.appendChild(template.content.cloneNode(true)); | ||
|
|
||
| // Internal properties | ||
| this._href = this.getAttribute('href'); | ||
| this._src = this.getAttribute('src'); | ||
| this._alt = this.getAttribute('alt'); | ||
| this._target = this.getAttribute('target'); | ||
| this._rel = this.getAttribute('rel'); | ||
| } | ||
|
|
||
| static get observedAttributes() { | ||
| return ['src', 'href', 'alt', 'target', 'rel']; | ||
| } | ||
|
|
||
| get href() { | ||
| return this._href; | ||
| } | ||
| get src() { | ||
| return this._src; | ||
| } | ||
| get alt() { | ||
| return this._alt; | ||
| } | ||
| get target() { | ||
| return this._target; | ||
| } | ||
| get rel() { | ||
| return this._rel; | ||
| } | ||
|
|
||
| attributeChangedCallback(name, oldValue, newValue) { | ||
| if (name === 'src' && newValue !== oldValue) { | ||
| this._src = newValue; | ||
| this._updateImage(newValue); | ||
| } | ||
|
|
||
| if (name === 'href' && newValue !== oldValue) { | ||
| this._href = newValue; | ||
| this._updateLink(newValue); | ||
| } | ||
| if (name === 'alt' && newValue !== oldValue) { | ||
| this._alt = newValue; | ||
| this._updateImage(); | ||
| } | ||
| if (name === 'target' && newValue !== oldValue) { | ||
| this._target = newValue; | ||
| this._updateLink(); | ||
| } | ||
|
|
||
| if (name === 'rel' && newValue !== oldValue) { | ||
| this._rel = newValue; | ||
| this._updateLink(); | ||
| } | ||
| } | ||
|
|
||
| connectedCallback() { | ||
| this._updateImage(this.src); | ||
| this._updateLink(this.href); | ||
| } | ||
|
|
||
| _updateImage() { | ||
| const img = this.shadowRoot.querySelector('.profile-image'); | ||
| if (img) { | ||
| img.src = this._src || ''; | ||
| img.alt = this._alt || 'Profile Image'; | ||
| } | ||
| } | ||
|
|
||
| _updateLink() { | ||
| const card = this.shadowRoot.querySelector('.profile-card'); | ||
| if (card) { | ||
| if (this._href) { | ||
| card.href = this._href; | ||
| card.target = this._target || '_blank'; | ||
| card.rel = this._rel || 'noopener noreferrer'; | ||
| } else { | ||
| card.removeAttribute('href'); | ||
sreidthomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| card.removeAttribute('target'); | ||
| card.removeAttribute('rel'); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export { ProfileCard as default }; | ||
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,57 @@ | ||
| .profile-card { | ||
| display: flex; | ||
| align-items: center; | ||
| width: 100%; | ||
| max-width: 100%; | ||
| gap: 1.25rem; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| a.profile-card { | ||
| color: inherit; | ||
| text-decoration: none; | ||
|
|
||
| &:visited, | ||
| &:active, | ||
| &:hover { | ||
| color: inherit; | ||
| text-decoration: none; | ||
| } | ||
| } | ||
|
|
||
| .profile-image { | ||
| object-fit: cover; | ||
| width: 20%; | ||
| max-width: 120px; | ||
| height: auto; | ||
| border-radius: 50%; | ||
| box-shadow: | ||
| 0 4px 6px -1px rgba(0, 0, 0, 0.1), | ||
| 0 2px 4px -1px rgba(0, 0, 0, 0.06); | ||
| } | ||
|
|
||
| .profile-details { | ||
| display: flex; | ||
| flex-direction: column; | ||
| flex-grow: 1; | ||
| min-width: 0; | ||
| } | ||
| .name-container { | ||
| display: flex; | ||
| align-items: center; | ||
| margin-bottom: 5px; | ||
| } | ||
|
|
||
| .chevron { | ||
| background-image: url('data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20width=%2716%27%20height=%2716%27%20fill=%27currentColor%27%20class=%27bi%20bi-chevron-right%27%20viewBox=%270%200%2016%2016%27%3E%3Cpath%20fill-rule=%27evenodd%27%20d=%27M4.646%201.646a.5.5%200%200%201%20.708%200l6%206a.5.5%200%200%201%200%20.708l-6%206a.5.5%200%200%201-.708-.708L10.293%208%204.646%202.354a.5.5%200%200%201%200-.708%27/%3E%3C/svg%3E'); | ||
| display: inline-block; | ||
| width: 16px; | ||
| height: 16px; | ||
| background-size: contain; | ||
| background-repeat: no-repeat; | ||
| transition: transform 0.2s ease; | ||
| } | ||
|
|
||
| .profile-card:hover .chevron { | ||
| transform: translateX(4px); | ||
| } |
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,2 @@ | ||
| import ProfileCard from './ProfileCard'; | ||
| customElements.define('cod-profile-card', ProfileCard); |
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,92 @@ | ||
| import { | ||
| Meta, | ||
| Canvas, | ||
| Title, | ||
| Subtitle, | ||
| Description, | ||
| Primary, | ||
| Controls, | ||
| Stories, | ||
| Story, | ||
| Source, | ||
| } from '@storybook/blocks'; | ||
| import * as ProfileCardStories from '../stories/profilecard.stories'; | ||
|
|
||
| import '../../../.storybook/docs'; // Import all documentation components | ||
|
|
||
| <Meta of={ProfileCardStories} /> | ||
|
|
||
| # Profile Card | ||
|
|
||
| <div className="component-summary"> | ||
| Profile Cards are components used to display a user's profile information. | ||
| </div> | ||
|
|
||
| ## Usage | ||
|
|
||
| <Canvas of={ProfileCardStories.Default} /> | ||
|
|
||
| <Controls of={ProfileCardStories.Default} /> | ||
|
|
||
| # Examples | ||
|
|
||
| ### Default | ||
|
|
||
| <Description of={ProfileCardStories.Default} /> | ||
| <Story of={ProfileCardStories.Default} inline={true} /> | ||
| <Source of={ProfileCardStories.Default} /> | ||
|
|
||
| ## Slots | ||
|
|
||
| <doc-slots-table | ||
| data={JSON.stringify([ | ||
| {"name": "name", "description": "This slot is used to display the person's name in the profile card."}, | ||
| {"name": "Primary Title", "description": "This slot contains the person's primary title, like their job position or designation." }, | ||
| {"name": "Secondary Title", "description": "This slot contains additional information about the person, such as a secondary job title, a department name, or an affiliation."} | ||
| ])}> | ||
| </doc-slots-table> | ||
|
|
||
| ## HTML Attributes / JS Properties | ||
|
|
||
| Supported HTML attributes. If the attribute is reflected in a JS property, that attribute will have a 'reflects' tag next to the name. | ||
|
|
||
| <doc-js-properties-table | ||
| data={JSON.stringify([ | ||
| {"name": "href", "description": "A link to the page or site containing the person's information. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#href", "type": "string", "default": "-", "reflects": false}, | ||
| {"name": "src", "description": "The URL to an image asset representing the person's profile photo. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-src", "type": "string", "default": "-", "reflects": false} | ||
| ])}> | ||
| </doc-js-properties-table> | ||
|
|
||
| ## Events | ||
|
|
||
| <doc-events-table | ||
| data={JSON.stringify([])}> | ||
| </doc-events-table> | ||
|
|
||
| ## Methods | ||
|
|
||
| <doc-methods-table | ||
| data={JSON.stringify([])}> | ||
| </doc-methods-table> | ||
|
|
||
| ## Custom CSS Properties | ||
|
|
||
| <doc-css-custom-properties-table | ||
| data={JSON.stringify([])}> | ||
| </doc-css-custom-properties-table> | ||
|
|
||
| ## CSS Parts | ||
|
|
||
| <doc-css-parts-table | ||
| data={JSON.stringify([])}> | ||
| </doc-css-parts-table> | ||
|
|
||
| ## Dependencies | ||
|
|
||
| <doc-dependencies-list data={JSON.stringify([])}></doc-dependencies-list> | ||
|
|
||
| ## Accessibility | ||
|
|
||
| - **Images (`src`)**: When a profile image is included using the `src` attribute, it should be accompanied by an `alt` attribute describing the person (e.g., `alt="Photo of Jane Doe"`). This ensures screen readers can describe the image content. | ||
sreidthomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - **Links (`href`)**: When the card is made clickable with the `href` attribute, it becomes keyboard-accessible and can be navigated by screen readers. | ||
Oops, something went wrong.
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.