Skip to content

Commit af51774

Browse files
committed
refactor: remove casting
1 parent d430f62 commit af51774

2 files changed

Lines changed: 18 additions & 22 deletions

File tree

packages/main/src/ColorPalette.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ interface IColorPaletteItem extends UI5Element, ITabbable {
5454
selected?: boolean,
5555
}
5656

57-
type ColorPaletteNavigationItem = IColorPaletteItem | Button;
57+
type ColorPaletteNavigationItem = ColorPaletteItem | Button;
5858

5959
type ColorPaletteItemClickEventDetail = {
6060
color: string,
@@ -203,7 +203,7 @@ class ColorPalette extends UI5Element {
203203
invalidateOnChildChange: true,
204204
individualSlots: true,
205205
})
206-
colors!: DefaultSlot<IColorPaletteItem>;
206+
colors!: DefaultSlot<ColorPaletteItem>;
207207

208208
_itemNavigation: ItemNavigation;
209209
_itemNavigationRecentColors: ItemNavigation;
@@ -285,7 +285,7 @@ class ColorPalette extends UI5Element {
285285

286286
item.focus();
287287

288-
if (this.displayedColors.includes(item as unknown as IColorPaletteItem)) {
288+
if (this.displayedColors.includes(item)) {
289289
this._itemNavigation.setCurrentItem(item);
290290
}
291291

@@ -308,22 +308,19 @@ class ColorPalette extends UI5Element {
308308
});
309309
}
310310

311-
get effectiveColorItems() {
312-
let colorItems: IColorPaletteItem[] = this.colors;
313-
311+
get effectiveColorItems(): ColorPaletteItem[] {
314312
if (this.popupMode) {
315-
colorItems = this.getSlottedNodes<ColorPaletteItem>("colors") as unknown as IColorPaletteItem[];
313+
return this.getSlottedNodes<ColorPaletteItem>("colors");
316314
}
317-
318-
return colorItems;
315+
return this.colors;
319316
}
320317

321318
/**
322319
* Ensures that only one item is selected or only the last selected item remains active if more than one are explicitly set as 'selected'.
323320
* @private
324321
*/
325322
_ensureSingleSelectionOrDeselectAll() {
326-
let lastSelectedItem: IColorPaletteItem | ColorPaletteItem | undefined;
323+
let lastSelectedItem: ColorPaletteItem | undefined;
327324

328325
this.allColorsInPalette.forEach(item => {
329326
if (item.selected) {
@@ -337,7 +334,6 @@ class ColorPalette extends UI5Element {
337334

338335
_onclick(e: MouseEvent) {
339336
if (e.defaultPrevented) {
340-
e.preventDefault();
341337
return;
342338
}
343339

@@ -353,7 +349,7 @@ class ColorPalette extends UI5Element {
353349

354350
const colorItem = target as ColorPaletteItem;
355351

356-
if (this.displayedColors.includes(colorItem as unknown as IColorPaletteItem)) {
352+
if (this.displayedColors.includes(colorItem)) {
357353
this._itemNavigation.setCurrentItem(colorItem);
358354
} else if (this.recentColorsElements.includes(colorItem)) {
359355
this._itemNavigationRecentColors.setCurrentItem(colorItem);
@@ -621,7 +617,7 @@ class ColorPalette extends UI5Element {
621617
return false;
622618
}
623619

624-
return this.displayedColors.includes(this._currentlySelected as unknown as IColorPaletteItem)
620+
return this.displayedColors.includes(this._currentlySelected)
625621
|| this.recentColorsElements.includes(this._currentlySelected);
626622
}
627623

@@ -646,7 +642,7 @@ class ColorPalette extends UI5Element {
646642
* @private
647643
*/
648644
_isFirstSwatchInRow(target: ColorPaletteItem): boolean {
649-
const index = this.displayedColors.indexOf(target as unknown as IColorPaletteItem);
645+
const index = this.displayedColors.indexOf(target);
650646
return index >= 0 ? index % this.rowSize === 0 : false;
651647
}
652648

@@ -655,7 +651,7 @@ class ColorPalette extends UI5Element {
655651
* @private
656652
*/
657653
_isLastSwatchInRow(target: ColorPaletteItem): boolean {
658-
const index = this.displayedColors.indexOf(target as unknown as IColorPaletteItem);
654+
const index = this.displayedColors.indexOf(target);
659655
return index >= 0 ? (index + 1) % this.rowSize === 0 || index === this.displayedColors.length - 1 : false;
660656
}
661657

@@ -671,15 +667,15 @@ class ColorPalette extends UI5Element {
671667
* @returns True if the swatch is the last of the last full row, false otherwise.
672668
*/
673669
_isLastSwatchOfLastFullRow(target: ColorPaletteItem): boolean {
674-
const index = this.displayedColors.indexOf(target as unknown as IColorPaletteItem);
670+
const index = this.displayedColors.indexOf(target);
675671
const rowSize = this.rowSize;
676672
const total = this.displayedColors.length;
677673
const lastCompleteRowEndIndex = this._getLastCompleteRowEndIndex(total, rowSize);
678674
return index >= 0 && index === lastCompleteRowEndIndex;
679675
}
680676

681677
_isSwatchInLastRow(target: ColorPaletteItem): boolean {
682-
const index = this.displayedColors.indexOf(target as unknown as IColorPaletteItem);
678+
const index = this.displayedColors.indexOf(target);
683679
const lastRowSwatchesCount = this.displayedColors.length % this.rowSize;
684680
return index >= 0 && index >= this.displayedColors.length - lastRowSwatchesCount;
685681
}
@@ -804,7 +800,7 @@ class ColorPalette extends UI5Element {
804800
*/
805801
_focusFirstRecentColor(): boolean {
806802
if (this.hasRecentColors && this.recentColorsElements.length) {
807-
this.focusColorElement(this.recentColorsElements[0] as unknown as IColorPaletteItem, this._itemNavigationRecentColors);
803+
this.focusColorElement(this.recentColorsElements[0], this._itemNavigationRecentColors);
808804
return true;
809805
}
810806
return false;
@@ -816,7 +812,7 @@ class ColorPalette extends UI5Element {
816812
*/
817813
_focusLastRecentColor(): boolean {
818814
if (this.hasRecentColors && this.recentColorsElements.length) {
819-
this.focusColorElement(this.recentColorsElements[this.recentColorsElements.length - 1] as unknown as IColorPaletteItem, this._itemNavigationRecentColors);
815+
this.focusColorElement(this.recentColorsElements[this.recentColorsElements.length - 1], this._itemNavigationRecentColors);
820816
return true;
821817
}
822818
return false;
@@ -901,8 +897,8 @@ class ColorPalette extends UI5Element {
901897
return this._selectedColor;
902898
}
903899

904-
get displayedColors(): Array<IColorPaletteItem> {
905-
const colors = this.getSlottedNodes<IColorPaletteItem>("colors");
900+
get displayedColors(): Array<ColorPaletteItem> {
901+
const colors = this.getSlottedNodes<ColorPaletteItem>("colors");
906902
return colors.filter(item => item.value).slice(0, 15);
907903
}
908904

packages/main/src/ColorPalettePopover.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class ColorPalettePopover extends UI5Element {
204204
}
205205

206206
// since height is dynamically determined by padding-block-start
207-
(colorPalette.allColorsInPalette as unknown as Array<IColorPaletteItem>).forEach((item: IColorPaletteItem) => {
207+
(colorPalette.allColorsInPalette).forEach((item: ColorPaletteItem) => {
208208
const itemHeight = item.offsetHeight + 4; // adding 4px for the offsets on top and bottom
209209
item.style.setProperty("--_ui5_color_palette_item_height", `${itemHeight}px`);
210210
});

0 commit comments

Comments
 (0)