Skip to content

Commit 976b568

Browse files
committed
align table row selection
1 parent b9609f6 commit 976b568

File tree

1 file changed

+120
-15
lines changed

1 file changed

+120
-15
lines changed

packages/uui-table/lib/uui-table-row.element.ts

Lines changed: 120 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from '@umbraco-ui/uui-base/lib/mixins';
55
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
66
import { css, html, LitElement } from 'lit';
7+
import { ref } from 'lit/directives/ref.js';
78
import { queryAssignedElements } from 'lit/decorators.js';
89

910
import { UUITableCellElement } from './uui-table-cell.element';
@@ -54,21 +55,30 @@ export class UUITableRowElement extends SelectOnlyMixin(
5455
}
5556

5657
private updateChildSelectOnly() {
57-
if (this.slotCellNodes) {
58-
this.slotCellNodes.forEach(el => {
59-
if (this.elementIsTableCell(el)) {
58+
const slotCellNodes = this.slotCellNodes;
59+
if (slotCellNodes) {
60+
slotCellNodes.forEach(el => {
61+
if (el instanceof UUITableCellElement) {
6062
el.disableChildInteraction = this.selectOnly;
6163
}
6264
});
6365
}
6466
}
6567

66-
private elementIsTableCell(element: unknown): element is UUITableCellElement {
67-
return element instanceof UUITableCellElement;
68+
#selectAreaChanged(selectArea?: Element | undefined) {
69+
this.selectableTarget = selectArea || this;
6870
}
6971

7072
render() {
71-
return html` <slot @slotchanged=${this.updateChildSelectOnly}></slot> `;
73+
return html`
74+
<slot @slotchanged=${this.updateChildSelectOnly}></slot>
75+
<div id="select-border" ${ref(this.#selectAreaChanged)}>
76+
<div id="select-top"></div>
77+
<div id="select-right"></div>
78+
<div id="select-bottom"></div>
79+
<div id="select-left"></div>
80+
</div>
81+
`;
7282
}
7383

7484
static styles = [
@@ -79,20 +89,115 @@ export class UUITableRowElement extends SelectOnlyMixin(
7989
outline-offset: -3px;
8090
}
8191
82-
:host([selectable]) {
83-
cursor: pointer;
84-
}
85-
8692
:host(:focus) {
8793
outline: calc(2px * var(--uui-show-focus-outline, 1)) solid
8894
var(--uui-color-focus);
8995
}
90-
:host([selected]) {
91-
outline: 2px solid
92-
var(--uui-table-row-color-selected, var(--uui-color-selected));
96+
97+
:host([selectable]) #select-border {
98+
position: absolute;
99+
top: -1px;
100+
left: -1px;
101+
right: -1px;
102+
bottom: -1px;
103+
pointer-events: none;
104+
opacity: 0;
105+
transition: opacity 120ms;
106+
}
107+
:host([selectable]) #select-border::after {
108+
content: '';
109+
position: absolute;
110+
z-index: 20;
111+
width: 100%;
112+
height: 100%;
113+
box-sizing: border-box;
114+
border: 2px solid var(--uui-color-selected);
115+
border-radius: calc(var(--uui-border-radius) + 2px);
116+
pointer-events: none;
117+
box-shadow:
118+
0 0 4px 0 var(--uui-color-selected),
119+
inset 0 0 2px 0 var(--uui-color-selected);
120+
}
121+
122+
:host([selectable]) #select-border #select-top,
123+
:host([selectable]) #select-border #select-right,
124+
:host([selectable]) #select-border #select-bottom,
125+
:host([selectable]) #select-border #select-left {
126+
position: absolute;
127+
z-index: 2;
128+
top: 1px;
129+
left: 1px;
130+
right: 1px;
131+
bottom: 1px;
132+
cursor: pointer;
133+
pointer-events: auto;
134+
}
135+
:host([selectable]) #select-border #select-top {
136+
height: var(--uui-size-space-3);
137+
bottom: unset;
138+
}
139+
:host([selectable]) #select-border #select-right {
140+
width: var(--uui-size-space-3);
141+
left: unset;
142+
}
143+
:host([selectable]) #select-border #select-bottom {
144+
height: var(--uui-size-space-3);
145+
top: unset;
146+
}
147+
:host([selectable]) #select-border #select-left {
148+
width: var(--uui-size-space-3);
149+
right: unset;
150+
}
151+
152+
:host([selected]) #select-border {
153+
opacity: 1;
154+
}
155+
:host([selectable]:not([selected]):hover) #select-border {
156+
opacity: 0.33;
157+
}
158+
:host([selectable][selected]:hover) #select-border {
159+
opacity: 0.8;
93160
}
94-
:host([selected]:focus) {
95-
outline-color: var(--uui-color-focus);
161+
162+
:host([selectable]:not([selected])) #open-part:hover + #select-border {
163+
opacity: 0;
164+
}
165+
:host([selectable][selected]) #open-part:hover + #select-border {
166+
opacity: 1;
167+
}
168+
169+
:host([selectable]:not([selected]):hover) #select-border::after {
170+
animation: not-selected--hover 1.2s infinite;
171+
}
172+
@keyframes not-selected--hover {
173+
0%,
174+
100% {
175+
opacity: 0.66;
176+
}
177+
50% {
178+
opacity: 1;
179+
}
180+
}
181+
182+
:host([selectable][selected]:hover) #select-border::after {
183+
animation: selected--hover 1.4s infinite;
184+
}
185+
@keyframes selected--hover {
186+
0%,
187+
100% {
188+
opacity: 1;
189+
}
190+
50% {
191+
opacity: 0.66;
192+
}
193+
}
194+
:host([selectable]) #open-part:hover + #select-border::after {
195+
animation: none;
196+
}
197+
198+
:host([select-only]) *,
199+
:host([select-only]) ::slotted(*) {
200+
pointer-events: none;
96201
}
97202
`,
98203
];

0 commit comments

Comments
 (0)