Skip to content
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

refactor: replace paper-icon-button with button #608

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions cosmoz-omnitable-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export default css`
.itemRow:hover .checkbox:not(:checked):not(:hover) {
box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.54) inset;
}
.groupRow:hover .fold:not(:hover),
.groupRow:hover .expand:not(:hover),
.itemRow:hover .expand:not(:hover) {
color: rgba(0, 0, 0, 0.54);
}
Expand All @@ -468,17 +468,30 @@ export default css`
height: 24px;
padding: 0;
flex: none;
}

.expand,
.fold {
border: none;
border-radius: 50%;
cursor: pointer;
background: none;
transition: 0.15s background ease-in;
outline: none;
color: rgba(0, 0, 0, 0.16);
}

.expand:hover,
.fold:hover {
}
.expand svg {
fill: currentColor;
}
.expand:not([aria-expanded]) svg {
transform: scaleY(-1);
}
.expand:active {
background: rgba(33,33,33,0.25)
}
.expand:hover {
color: #000;
}
.groupRow .expand {
margin: 8px;
}

.sg {
display: inline-flex;
Expand Down
1 change: 0 additions & 1 deletion cosmoz-omnitable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* eslint-disable max-lines */
import '@polymer/iron-icons/iron-icons';
import '@polymer/iron-icon/iron-icon';
import '@polymer/paper-icon-button/paper-icon-button';
import '@polymer/paper-spinner/paper-spinner-lite';

import '@neovici/cosmoz-grouped-list';
Expand Down
188 changes: 103 additions & 85 deletions lib/use-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,101 +4,119 @@ import { indexSymbol } from './utils';
import { isEmpty } from '@neovici/cosmoz-utils/template';
import { onItemChange as _onItemChange } from './utils-data';

const arrow = html`
<svg
viewBox="0 0 24 24"
preserveAspectRatio="xMidYMid meet"
focusable="false"
>
<g>
<path d="M12 8l-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z"></path>
</g>
</svg>
`;

const _getGroupRowClasses = (folded) =>
folded ? 'groupRow groupRow-folded' : 'groupRow',
_getFoldIcon = (expanded) => (expanded ? 'expand-less' : 'expand-more'),
renderItem =
({
columns,
collapsedColumns,
onItemClick,
onCheckboxChange,
dataIsValid,
groupOnColumn,
onItemChange,
rowPartFn,
}) =>
(item, index, { selected, expanded, toggleCollapse }) =>
html` <div class="item-row-wrapper">
<div
?selected=${selected}
part="${['itemRow', `itemRow-${item[indexSymbol]}`, rowPartFn?.(item, index)]
.filter(Boolean)
.join(' ')}"
.dataIndex=${item[indexSymbol]}
.dataItem=${item}
class="itemRow"
@click=${onItemClick}
>
<input
class="checkbox"
type="checkbox"
part="checkbox"
.checked=${selected}
.dataItem=${item}
@input=${onCheckboxChange}
?disabled=${!dataIsValid}
/>
<cosmoz-omnitable-item-row
.columns=${columns}
.index=${index}
.selected=${selected}
.expanded=${expanded}
.item=${item}
.groupOnColumn=${groupOnColumn}
.onItemChange=${onItemChange}
>
</cosmoz-omnitable-item-row>
<paper-icon-button
class="expand"
?hidden=${isEmpty(collapsedColumns.length)}
.icon=${_getFoldIcon(expanded)}
@click=${toggleCollapse}
></paper-icon-button>
</div>
<cosmoz-omnitable-item-expand
.columns=${collapsedColumns}
.item=${item}
.index=${index}
?selected=${selected}
?expanded=${expanded}
.groupOnColumn=${groupOnColumn}
part="item-expand"
>
</cosmoz-omnitable-item-expand>
</div>`,
renderGroup = ({ onCheckboxChange, dataIsValid, groupOnColumn }) => {
return (item, index, { selected, folded, toggleFold }) =>
html` <div
class="${_getGroupRowClasses(folded)}"
part="groupRow groupRow-${item[indexSymbol]}"
folded ? 'groupRow groupRow-folded' : 'groupRow';

const renderItem =
({
columns,
collapsedColumns,
onItemClick,
onCheckboxChange,
dataIsValid,
groupOnColumn,
onItemChange,
rowPartFn,
}) =>
(item, index, { selected, expanded, toggleCollapse }) =>
html` <div class="item-row-wrapper">
<div
?selected=${selected}
part="${[
'itemRow',
`itemRow-${item[indexSymbol]}`,
rowPartFn?.(item, index),
]
.filter(Boolean)
.join(' ')}"
.dataIndex=${item[indexSymbol]}
.dataItem=${item}
class="itemRow"
@click=${onItemClick}
>
<input
class="checkbox"
type="checkbox"
part="checkbox"
.checked=${selected}
.dataItem=${item}
@input=${onCheckboxChange}
?disabled=${!dataIsValid}
/>
<h3 class="groupRow-label">
<div><span>${groupOnColumn?.title}</span>: &nbsp;</div>
<cosmoz-omnitable-group-row
.column=${groupOnColumn}
.item=${item.items?.[0]}
.selected=${selected}
.folded=${folded}
.group=${item}
></cosmoz-omnitable-group-row>
</h3>
<div class="groupRow-badge">${item.items.length}</div>
<paper-icon-button
class="fold"
.icon=${_getFoldIcon(folded)}
@click=${toggleFold}
></paper-icon-button>
</div>`;
};
<cosmoz-omnitable-item-row
.columns=${columns}
.index=${index}
.selected=${selected}
.expanded=${expanded}
.item=${item}
.groupOnColumn=${groupOnColumn}
.onItemChange=${onItemChange}
>
</cosmoz-omnitable-item-row>

<button
class="expand"
?hidden="${isEmpty(collapsedColumns.length)}"
?aria-expanded="${expanded}"
@click="${toggleCollapse}"
>
${arrow}
</button>
</div>
<cosmoz-omnitable-item-expand
.columns=${collapsedColumns}
.item=${item}
.index=${index}
?selected=${selected}
?expanded=${expanded}
.groupOnColumn=${groupOnColumn}
part="item-expand"
>
</cosmoz-omnitable-item-expand>
</div>`;

const renderGroup =
({ onCheckboxChange, dataIsValid, groupOnColumn }) =>
(item, index, { selected, folded, toggleFold }) =>
html` <div
class="${_getGroupRowClasses(folded)}"
part="groupRow groupRow-${item[indexSymbol]}"
>
<input
class="checkbox"
type="checkbox"
.checked=${selected}
.dataItem=${item}
@input=${onCheckboxChange}
?disabled=${!dataIsValid}
/>
<h3 class="groupRow-label">
<div><span>${groupOnColumn?.title}</span>: &nbsp;</div>
<cosmoz-omnitable-group-row
.column=${groupOnColumn}
.item=${item.items?.[0]}
.selected=${selected}
.folded=${folded}
.group=${item}
></cosmoz-omnitable-group-row>
</h3>
<div class="groupRow-badge">${item.items.length}</div>
<button class="expand" ?aria-expanded="${folded}" @click=${toggleFold}>
${arrow}
</button>
</div>`;

export const useList = ({
host,
Expand Down
Loading