From cfa6ea51aed5e1f6fd06f89ef26225f84c8a72ea Mon Sep 17 00:00:00 2001 From: Nayden Naydenov Date: Wed, 7 Aug 2024 13:40:52 +0300 Subject: [PATCH] chore: cleanup --- package.json | 6 +-- src/App.tsx | 98 ++++++++++++++++++++++++------------------------ src/TodoItem.tsx | 2 +- src/TodoList.tsx | 4 +- src/custom.d.ts | 4 +- 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/package.json b/package.json index ebecd15..5417abd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "my-react-ts2", - "private": true, - "version": "0.0.0", + "name": "ui5-webcomponents-sample-react", + "version": "0.7.0", + "homepage": "./", "type": "module", "scripts": { "dev": "vite", diff --git a/src/App.tsx b/src/App.tsx index 404c272..d3aae95 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,28 +1,28 @@ -import React, { useState, useRef, useEffect, useCallback } from "react"; +import { useState, useRef, useEffect, useCallback } from "react"; import logo from "./logo.png"; import "./App.css"; import TodoList from "./TodoList"; import applyDirection from "@ui5/webcomponents-base/dist/locale/applyDirection.js"; -import { setTheme } from "@ui5/webcomponents-base/dist/config/Theme"; -import "@ui5/webcomponents-base/dist/features/F6Navigation"; -import "@ui5/webcomponents/dist/Button"; -import "@ui5/webcomponents/dist/Title"; -import "@ui5/webcomponents/dist/Input"; -import "@ui5/webcomponents/dist/DatePicker"; -import "@ui5/webcomponents/dist/List"; -import "@ui5/webcomponents/dist/Label"; -import "@ui5/webcomponents/dist/ListItemCustom"; -import "@ui5/webcomponents/dist/Panel"; -import "@ui5/webcomponents/dist/Dialog"; -import "@ui5/webcomponents/dist/Popover"; -import "@ui5/webcomponents/dist/Tab"; -import "@ui5/webcomponents/dist/TabContainer"; -import "@ui5/webcomponents/dist/TextArea"; -import "@ui5/webcomponents/dist/Switch"; -import "@ui5/webcomponents-fiori/dist/ShellBar"; -import "@ui5/webcomponents-fiori/dist/ShellBarItem"; -import "@ui5/webcomponents-fiori/dist/Assets"; +import { setTheme } from "@ui5/webcomponents-base/dist/config/Theme.js"; +import "@ui5/webcomponents-base/dist/features/F6Navigation.js"; +import "@ui5/webcomponents/dist/Button.js"; +import "@ui5/webcomponents/dist/Title.js"; +import "@ui5/webcomponents/dist/Input.js"; +import "@ui5/webcomponents/dist/DatePicker.js"; +import "@ui5/webcomponents/dist/List.js"; +import "@ui5/webcomponents/dist/Label.js"; +import "@ui5/webcomponents/dist/ListItemCustom.js"; +import "@ui5/webcomponents/dist/Panel.js"; +import "@ui5/webcomponents/dist/Dialog.js"; +import "@ui5/webcomponents/dist/Popover.js"; +import "@ui5/webcomponents/dist/Tab.js"; +import "@ui5/webcomponents/dist/TabContainer.js"; +import "@ui5/webcomponents/dist/TextArea.js"; +import "@ui5/webcomponents/dist/Switch.js"; +import "@ui5/webcomponents-fiori/dist/ShellBar.js"; +import "@ui5/webcomponents-fiori/dist/ShellBarItem.js"; +import "@ui5/webcomponents-fiori/dist/Assets.js"; import "@ui5/webcomponents-icons/dist/palette.js"; import "@ui5/webcomponents-icons/dist/settings.js"; import "@ui5/webcomponents-icons/dist/sys-help.js"; @@ -119,9 +119,9 @@ function App() { } }, [editDialog]); - const handleProfileClick = useCallback((event: CustomEvent) => { + const handleProfileClick = useCallback((event: Event) => { if (profilePopover.current) { - profilePopover.current.opener = event.detail.targetRef; + profilePopover.current.opener = (event as CustomEvent).detail.targetRef; profilePopover.current.open = true; } }, []); @@ -138,12 +138,12 @@ function App() { } }, []); - const handleRtlSwitchChange = useCallback((event: CustomEvent) => { + const handleRtlSwitchChange = useCallback((event: Event) => { document.body.dir = (event.target as Switch).checked ? "rtl" : "ltr"; applyDirection(); }, []); - const handleContentDensitySwitchChange = useCallback((event: CustomEvent) => { + const handleContentDensitySwitchChange = useCallback((event: Event) => { if ((event.target as Switch).checked) { document.body.classList.add("ui5-content-density-compact"); } else { @@ -151,8 +151,8 @@ function App() { } }, []); - const handleProfileSettingsSelect = useCallback((event: CustomEvent) => { - const selectedKey = event.detail.item.getAttribute("data-key"); + const handleProfileSettingsSelect = useCallback((event: Event) => { + const selectedKey = (event as CustomEvent).detail.item.getAttribute("data-key"); if (selectedKey === "settings") { if (settingsDialog.current) { settingsDialog.current.open = true; @@ -164,15 +164,15 @@ function App() { } }, []); - const handleThemeSettingsToggle = useCallback((event: CustomEvent) => { + const handleThemeSettingsToggle = useCallback((event: Event) => { if (themeSettingsPopover.current) { - themeSettingsPopover.current.opener = event.detail.targetRef; + themeSettingsPopover.current.opener = (event as CustomEvent).detail.targetRef; themeSettingsPopover.current.open = true; } }, []); - const handleThemeChange = useCallback((event: CustomEvent) => { - const selectedTheme = event.detail.selectedItems[0].getAttribute("data-theme"); + const handleThemeChange = useCallback((event: Event) => { + const selectedTheme = (event as CustomEvent).detail.selectedItems[0].getAttribute("data-theme")!; setTheme(selectedTheme); }, []); @@ -196,8 +196,8 @@ function App() { }, [todoBeingEditted, setTodos]); const handleDone = useCallback( - (event: CustomEvent) => { - const selectedItem = event.detail.selectedItems[0]; + (event: Event) => { + const selectedItem = (event as CustomEvent).detail.selectedItems[0]; const selectedId = selectedItem.getAttribute("data-key"); setTodos((todos) => @@ -210,8 +210,8 @@ function App() { ); const handleUnDone = useCallback( - (event: CustomEvent) => { - const selectedItems = event.detail.selectedItems; + (event: Event) => { + const selectedItems = (event as CustomEvent).detail.selectedItems; setTodos((todos) => todos.map((todo) => { @@ -379,25 +379,25 @@ function App() { - +
- - - + + + Add Todo
- !todo.done).length || undefined} className="list-todos-panel"> + !todo.done).length || undefined} class="list-todos-panel"> !todo.done)} selectionChange={handleDone} remove={handleRemove} edit={handleEdit}> - todo.done).length || undefined} className="list-todos-panel" id="completed-tasks"> + todo.done).length || undefined} class="list-todos-panel" id="completed-tasks"> todo.done)} selectionChange={handleUnDone} remove={handleRemove} edit={handleEdit}>
@@ -407,7 +407,7 @@ function App() {
Title: - +
@@ -417,19 +417,19 @@ function App() {
- + Cancel {/*close dialog*/} - + Save {/*save dialog info*/}
- - + + SAP Horizon Morning @@ -457,7 +457,7 @@ function App() { - +
@@ -467,7 +467,7 @@ function App() {
- + Settings @@ -485,7 +485,7 @@ function App() {
- RTL + RTL
@@ -493,7 +493,7 @@ function App() {
- Compact + Compact
diff --git a/src/TodoItem.tsx b/src/TodoItem.tsx index 7f2d5f7..35efc30 100644 --- a/src/TodoItem.tsx +++ b/src/TodoItem.tsx @@ -1,5 +1,5 @@ import type Button from "@ui5/webcomponents/dist/Button.js"; -import React, { useEffect, useRef } from "react"; +import { useEffect, useRef } from "react"; type TODOItem = { text: string; diff --git a/src/TodoList.tsx b/src/TodoList.tsx index 65f1c98..1121f20 100644 --- a/src/TodoList.tsx +++ b/src/TodoList.tsx @@ -5,7 +5,7 @@ import type { TODOItem } from "./App"; type TodoList = { items: Array; - selectionChange: () => void; + selectionChange: (event: Event) => void; remove: (id: number) => void; edit: (id: number) => void; }; @@ -23,7 +23,7 @@ function TodoList({ items, selectionChange, remove, edit }: TodoList) { }, [selectionChange]); return ( - + {items.map((todo) => { return ; })} diff --git a/src/custom.d.ts b/src/custom.d.ts index a2aab12..95c7eea 100644 --- a/src/custom.d.ts +++ b/src/custom.d.ts @@ -19,11 +19,11 @@ import type Switch from "@ui5/webcomponents/dist/Switch.js"; import type Icon from "@ui5/webcomponents/dist/Icon.js"; import ListItemCustom from "@ui5/webcomponents/dist/ListItemCustom.js"; -import { DOMAttributes } from "react"; +import { DOMAttributes, useRef, Key } from "react"; -type CustomElementAttrs = DOMAttributes & { key: string | number; ref: React.RefObject; class: string }; // eslint-disable-next-line @typescript-eslint/no-explicit-any type CustomElement = Partial & { children: any }>; +type CustomElementAttrs = DOMAttributes & { key: Key; ref: ReturnType>; class: string }; declare global { namespace JSX {