-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #611 from Neovici/feat/tweak-expand
Implement mini layout
- Loading branch information
Showing
16 changed files
with
252 additions
and
152 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
import { component, html } from '@pionjs/pion'; | ||
import { css, sheet } from '@neovici/cosmoz-utils'; | ||
|
||
const OmnitableItemExpandLine = ({ column }) => html` | ||
<style> | ||
:host { | ||
display: flex; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
} | ||
const style = css` | ||
:host { | ||
display: flex; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
} | ||
.item-expand-label { | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
flex: initial; | ||
align-self: start; | ||
} | ||
.label { | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
flex: initial; | ||
align-self: start; | ||
} | ||
.item-expand-value { | ||
text-align: right; | ||
flex-grow: 1 !important; | ||
flex-basis: 100px !important; | ||
white-space: nowrap; | ||
} | ||
.value { | ||
text-align: right; | ||
flex-grow: 1; | ||
flex-basis: 100px; | ||
white-space: nowrap; | ||
} | ||
`; | ||
|
||
</style> | ||
<div class="item-expand-label" title=${ column.title } part="item-expand-label">${ column.title }</div> | ||
<div class="item-expand-value" part="item-expand-value"> | ||
const ItemExpandLine = ({ column }) => html` | ||
<div class="label" title="${column.title}" part="item-expand-label"> | ||
${column.title} | ||
</div> | ||
<div class="value" part="item-expand-value"> | ||
<slot></slot> | ||
</div> | ||
`; | ||
|
||
customElements.define('cosmoz-omnitable-item-expand-line', component(OmnitableItemExpandLine)); | ||
customElements.define( | ||
'cosmoz-omnitable-item-expand-line', | ||
component(ItemExpandLine, {styleSheets: [sheet(style)]}), | ||
); |
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,48 +1,28 @@ | ||
/* eslint-disable object-curly-newline */ | ||
import { component, useEffect } from '@pionjs/pion'; | ||
import { html, nothing } from 'lit-html'; | ||
import { component } from '@pionjs/pion'; | ||
import { html } from 'lit-html'; | ||
import { map } from 'lit-html/directives/map.js'; | ||
import './cosmoz-omnitable-item-expand-line'; | ||
|
||
const renderExpandList = ({ | ||
const ItemExpand = ({ columns, item, selected, expanded, groupOnColumn }) => { | ||
return map( | ||
columns, | ||
item, | ||
selected, | ||
expanded, | ||
groupOnColumn, | ||
}) => | ||
columns.map( | ||
(column) => html`<cosmoz-omnitable-item-expand-line | ||
(column) => | ||
html`<cosmoz-omnitable-item-expand-line | ||
.column=${column} | ||
?hidden=${column === groupOnColumn} | ||
exportparts="item-expand-label,item-expand-value" | ||
exportparts="item-expand-label, item-expand-value" | ||
>${column.renderCell(column, { | ||
item, | ||
selected, | ||
expanded, | ||
})}</cosmoz-omnitable-item-expand-line | ||
>` | ||
), | ||
ExpandList = (host) => { | ||
const { columns } = host; | ||
|
||
useEffect(() => { | ||
if (columns?.length > 0) { | ||
return; | ||
} | ||
|
||
host.setAttribute('hidden', ''); | ||
return () => host.removeAttribute('hidden'); | ||
}, [columns?.length]); | ||
|
||
return Array.isArray(columns) && columns.length > 0 && host.expanded | ||
? renderExpandList(host) | ||
: nothing; | ||
}; | ||
>`, | ||
); | ||
}; | ||
|
||
customElements.define( | ||
'cosmoz-omnitable-item-expand', | ||
component(ExpandList, { | ||
component(ItemExpand, { | ||
useShadowDOM: false, | ||
observedAttributes: ['expanded'], | ||
}) | ||
}), | ||
); |
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,20 +1,37 @@ | ||
import { component, html } from '@pionjs/pion'; | ||
import { repeat } from 'lit-html/directives/repeat.js'; | ||
|
||
const | ||
renderCell = (column, data, onItemChange) => column.editable | ||
const renderCell = (column, data, onItemChange) => | ||
column.editable | ||
? column.renderEditCell(column, data, onItemChange(column, data.item)) | ||
: column.renderCell(column, data), | ||
ItemRow = ({ columns, groupOnColumn, item, index, selected, expanded, onItemChange }) => { | ||
return repeat(columns, column => column.name, column => { | ||
: column.renderCell(column, data); | ||
|
||
const ItemRow = ({ | ||
columns, | ||
groupOnColumn, | ||
item, | ||
index, | ||
selected, | ||
expanded, | ||
onItemChange, | ||
}) => | ||
repeat( | ||
columns, | ||
(column) => column.name, | ||
(column) => { | ||
return html`<div | ||
class="cell itemRow-cell ${ column.cellClass ?? '' }" | ||
?hidden=${ column === groupOnColumn } | ||
?editable=${ column.editable } | ||
title=${ column.cellTitleFn(column, item) } | ||
name=${ column.name } | ||
>${ renderCell(column, { item, index, selected, expanded }, onItemChange) }</div>`; | ||
}); | ||
}; | ||
class="cell itemRow-cell ${column.cellClass ?? ''}" | ||
?hidden="${column === groupOnColumn}" | ||
?editable="${column.editable}" | ||
title="${column.cellTitleFn(column, item)}" | ||
name="${column.name}" | ||
> | ||
${renderCell(column, { item, index, selected, expanded }, onItemChange)} | ||
</div>`; | ||
}, | ||
); | ||
|
||
customElements.define('cosmoz-omnitable-item-row', component(ItemRow, { useShadowDOM: false })); | ||
customElements.define( | ||
'cosmoz-omnitable-item-row', | ||
component(ItemRow, { useShadowDOM: false }), | ||
); |
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
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
Oops, something went wrong.