-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(widget): extract detail view and font into separate files (#184)
* extract detail view and font * update readme dev instructions * various other refactors
- Loading branch information
1 parent
069434d
commit 543ea22
Showing
7 changed files
with
190 additions
and
140 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { svg } from 'lit'; | ||
|
||
export const closeDetailsButton = (color: string) => svg` | ||
<svg width='30' height='30' viewBox='0 0 30 30' fill='none' xmlns='http://www.w3.org/2000/svg'> | ||
<circle stroke='${color}' cx='15' cy='15' r='14.5'/> | ||
<path fill='${color}' fill-rule='evenodd' clip-rule='evenodd' d='M16.41 15L20.7 10.71C20.89 10.53 21 10.28 21 10C21 9.45 20.55 9 20 9C19.72 9 19.47 9.11 19.29 9.29L15 13.59L10.71 9.29C10.53 9.11 10.28 9 10 9C9.45 9 9 9.45 9 10C9 10.28 9.11 10.53 9.29 10.71L13.59 15L9.3 19.29C9.11 19.47 9 19.72 9 20C9 20.55 9.45 21 10 21C10.28 21 10.53 20.89 10.71 20.71L15 16.41L19.29 20.7C19.47 20.89 19.72 21 20 21C20.55 21 21 20.55 21 20C21 19.72 20.89 19.47 20.71 19.29L16.41 15Z'/> | ||
</svg> | ||
<svg width='30' height='30' viewBox='0 0 30 30' fill='none' xmlns='http://www.w3.org/2000/svg'> | ||
<circle stroke='${color}' cx='15' cy='15' r='14.5'/> | ||
<path fill='${color}' fill-rule='evenodd' clip-rule='evenodd' d='M16.41 15L20.7 10.71C20.89 10.53 21 10.28 21 10C21 9.45 20.55 9 20 9C19.72 9 19.47 9.11 19.29 9.29L15 13.59L10.71 9.29C10.53 9.11 10.28 9 10 9C9.45 9 9 9.45 9 10C9 10.28 9.11 10.53 9.29 10.71L13.59 15L9.3 19.29C9.11 19.47 9 19.72 9 20C9 20.55 9.45 21 10 21C10.28 21 10.53 20.89 10.71 20.71L15 16.41L19.29 20.7C19.47 20.89 19.72 21 20 21C20.55 21 21 20.55 21 20C21 19.72 20.89 19.47 20.71 19.29L16.41 15Z'/> | ||
</svg> | ||
`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { html, HTMLTemplateResult } from 'lit'; | ||
import { DisplayObject, filterMetadataEntries, TYPE_DISPLAY_OPTIONS } from './util'; | ||
import { renderDetailNavigationHeader } from './detail-navigation-header'; | ||
import { closeDetailsButton } from './assets'; | ||
|
||
export function renderDetailsView( | ||
selectedNode: DisplayObject, | ||
allNodes: DisplayObject[], | ||
updateSelectedNode: (node: DisplayObject) => void, | ||
closeDetailsView: () => void, | ||
) { | ||
const opts = TYPE_DISPLAY_OPTIONS[selectedNode.type]; | ||
const metadataEntries: [string, any][] = filterMetadataEntries(selectedNode); | ||
|
||
const metadataBody: HTMLTemplateResult = | ||
metadataEntries.length > 0 ? createMetadataGrid(metadataEntries) : emptyMetadataMessage(); | ||
|
||
const backgroundColor = opts.detailBackgroundColor || opts.backgroundColor; | ||
const textColor = opts.detailTextColor || opts.textColor; | ||
|
||
return html` | ||
<div class="detail-timeline"> | ||
${renderDetailNavigationHeader(allNodes, selectedNode, updateSelectedNode)} | ||
</div> | ||
<div class="detail-header" style="background: ${backgroundColor};"> | ||
<span style="color: ${textColor};"> ${opts.longLabel} </span> | ||
<div class="close-button clickable" @click="${closeDetailsView}"> | ||
${closeDetailsButton(textColor)} | ||
</div> | ||
</div> | ||
<div class="detail-body">${metadataBody}</div> | ||
`; | ||
} | ||
|
||
const createMetadataGrid = (metadataEntries: [string, any][]): HTMLTemplateResult => { | ||
const gridItems: HTMLTemplateResult[] = metadataEntries.map((entry, index) => | ||
createGridItem(entry, index), | ||
); | ||
return html` <div class="metadata-grid">${gridItems}</div>`; | ||
}; | ||
|
||
const createGridItem = ([key, value]: [string, any], index: number): HTMLTemplateResult => { | ||
if (Array.isArray(value)) { | ||
const values: any[] = value; // rename since it's actually plural | ||
return html` | ||
<div | ||
class="metadata-grid-item key" | ||
style="grid-row-start: ${index + 1}; grid-row-end: ${index + values.length + 1};" | ||
> | ||
${key} | ||
</div> | ||
${values.map((val) => html` <div class="metadata-grid-item value content">${val}</div>`)} | ||
`; | ||
} | ||
|
||
return html` | ||
<div class="metadata-grid-item key">${key}</div> | ||
<div class="metadata-grid-item value">${value}</div> | ||
`; | ||
}; | ||
|
||
const emptyMetadataMessage = (): HTMLTemplateResult => { | ||
return html` <div class="metadata-item"> | ||
<div class="metadata-key">no metadata found</div> | ||
</div>`; | ||
}; |
Oops, something went wrong.