-
Notifications
You must be signed in to change notification settings - Fork 3
feature.LinkTray #344
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
SBBlee
wants to merge
4
commits into
dev
Choose a base branch
from
feature.linktray
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
feature.LinkTray #344
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,91 @@ | ||
| const template = document.createElement('template'); | ||
| template.innerHTML = ` | ||
| <style> | ||
| .linktray-container { | ||
| background: #f2f2f2; | ||
| border-left: 5px solid #feb70d; | ||
| padding: 20px 10px; | ||
|
|
||
| ul { | ||
| list-style-type: none; | ||
| display: grid; | ||
| margin: 0 auto; | ||
| gap: 1rem; | ||
| margin: 1rem -2rem; | ||
| @media (min-width: 600px) { | ||
| grid-template-columns: repeat(2, 1fr); | ||
| } | ||
| @media (min-width: 900px) { | ||
| grid-template-columns: repeat(3, 1fr); | ||
| } | ||
| a { | ||
| font-size: 18px; | ||
| font-weight: 600; | ||
| text-decoration: none !important; | ||
| color: #000 !important; | ||
| } | ||
|
|
||
| svg { | ||
| top: 3px; | ||
| position: relative; | ||
| } | ||
| } | ||
| #tray-links :hover svg { | ||
| transform: translate(3px, 0px); | ||
| } | ||
| } | ||
| </style> | ||
| <div class='linktray-container'> | ||
| <span class='tray-title'> | ||
| <slot name="tray-title"></slot> | ||
| </span> | ||
| <ul id="tray-links"> | ||
| <slot name="tray-link"></slot> | ||
| </span> | ||
| </ul> | ||
|
|
||
| `; | ||
|
|
||
| class Linktray extends HTMLElement { | ||
| constructor() { | ||
| super(); | ||
|
|
||
| // Create a shadow root | ||
| const shadow = this.attachShadow({ mode: 'open' }); | ||
| shadow.appendChild(template.content.cloneNode(true)); | ||
| } | ||
|
|
||
| connectedCallback() { | ||
| this._fetchLinks(); | ||
| } | ||
|
|
||
| _fetchLinks() { | ||
| const linkSlot = this.shadowRoot.querySelector('slot[name="tray-link"]'); | ||
|
|
||
| linkSlot.addEventListener('slotchange', () => { | ||
| const elements = linkSlot.assignedElements(); | ||
|
|
||
| elements.forEach((element) => { | ||
| const li = document.createElement('li'); | ||
|
|
||
| // append element to li | ||
| li.appendChild(element); | ||
|
|
||
| // append Chevron | ||
| const chevron = document.createElement('span'); | ||
| chevron.classList.add('chevron'); | ||
| chevron.innerHTML = ` | ||
| <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-right" viewBox="0 0 16 16"> | ||
| <path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708"/> | ||
| </svg> `; | ||
| li.appendChild(chevron); | ||
|
|
||
| // place li at the at the top of ul | ||
| const trayLinks = this.shadowRoot.querySelector('#tray-links'); | ||
| trayLinks.insertBefore(li, trayLinks.children[0]); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| export { Linktray 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,2 @@ | ||
| import Linktray from './Linktray'; | ||
| customElements.define('cod-linktray', Linktray); |
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,53 @@ | ||
| import '../../stable/components/Linktray/cod-linktray'; | ||
| import { html } from 'lit-html'; | ||
|
|
||
| export default { | ||
| tags: ['stable'], | ||
| title: 'Components/Linktray', | ||
| }; | ||
|
|
||
| export const Linktray = { | ||
| tags: ['autodocs'], | ||
| render: () => html` | ||
| <style> | ||
| .linktray [slot='tray-title'] { font-size: 20px; font-weight: 700;} | ||
|
|
||
| } | ||
| </style> | ||
| <cod-linktray class="linktray"> | ||
| <span slot="tray-title"> More from Mayor's Office </span> | ||
|
|
||
| <a slot="tray-link" href="https://www.example.com">State of the city</a> | ||
| <a slot="tray-link" href="https://www.example.com">Properties</a> | ||
| <a slot="tray-link" href="https://www.example.com">Special Events</a> | ||
| <a slot="tray-link" href="https://www.example.com">Correspondence</a> | ||
| <a slot="tray-link" href="https://www.example.com" | ||
| >Renew Detroit Home Repair Program</a | ||
| > | ||
| <a slot="tray-link" href="https://www.example.com" | ||
| >Michigan State Fair Grounds Development</a | ||
| > | ||
| <a slot="tray-link" href="https://www.example.com" | ||
| >Detroit Neighborhood Initiatve</a | ||
| > | ||
| <a slot="tray-link" href="https://www.example.com">LEAN</a> | ||
| <a slot="tray-link" href="https://www.example.com" | ||
| >Detroit Opportunities</a | ||
| > | ||
| <a slot="tray-link" href="https://www.example.com">Mayor's Help Desk</a> | ||
| <a slot="tray-link" href="https://www.example.com">Executive Orders</a> | ||
| </cod-linktray> | ||
| `, | ||
| }; | ||
|
|
||
| // Slots ----- tray title ---- links | ||
| // target tray body to resize ------ mobile 1 column ---- DT 3 col | ||
| // Grid 2 body size options - V or H | ||
| // child depts, related dept, More from this dept (Depts / More) | ||
| // Col, if more than 10? links | ||
| // grid-template-columns: repeat(auto-fit,minmax(132px, 1fr)); | ||
| // grid-template-columns: 1fr 1fr 1fr; | ||
| // grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); | ||
|
|
||
| // https://www.w3schools.com/css/css3_flexbox_responsive.asp | ||
| // https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite right. This is taking the slotted
aelements, moving them out of the light DOM slot, and moving them into the shadow DOM (and out of the slot).Notice how there's nothing inside the
<slot name=tray-link>slot:We want the slotted elements to remain in the light DOM slot, but wrapped in
lielements.To keep the elements in the light DOM, we need to add the
slot=link-trayattribute to thelitag created, and then append thelielements to the elementcod-linktrayinstead of appending to an element in the shadowRoot like'#tray-links.You can see an example of how this is done at lines 88-94 for the section navigation component:
COD-Design-System/src/stable/components/SectionNavigation/SectionNavigation.js
Lines 88 to 94 in d908d2e
Notice how the resulting HTML looks for the section navigation with the
lielements inside the<slot name=nav-items>: