refactor: upgrade deps, setup tailwind4 and correct ci (#258)
* refresh * e2e test * Change debugger type from 'pwa-chrome' to 'chrome' * ci: align workflows with electron-vite-vue#540 * chore: update test, tsconfig and deps * chore: update deps and debug config * chore: refresh style * docs: update readme * docs: make linter happy * ci: bump versions * chore: refactor update handling and improve UI elements * 1.0.0
This commit is contained in:
39 files changed
+855
-916
No files matched your search
@@ -1,67 +0,0 @@
|
||||
import React, { ReactNode } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import './modal.css'
|
||||
|
||||
const ModalTemplate: React.FC<React.PropsWithChildren<{
|
||||
title?: ReactNode
|
||||
footer?: ReactNode
|
||||
cancelText?: string
|
||||
okText?: string
|
||||
onCancel?: () => void
|
||||
onOk?: () => void
|
||||
width?: number
|
||||
}>> = props => {
|
||||
const {
|
||||
title,
|
||||
children,
|
||||
footer,
|
||||
cancelText = 'Cancel',
|
||||
okText = 'OK',
|
||||
onCancel,
|
||||
onOk,
|
||||
width = 530,
|
||||
} = props
|
||||
|
||||
return (
|
||||
<div className='update-modal'>
|
||||
<div className='update-modal__mask' />
|
||||
<div className='update-modal__warp'>
|
||||
<div className='update-modal__content' style={{ width }}>
|
||||
<div className='content__header'>
|
||||
<div className='content__header-text'>{title}</div>
|
||||
<span
|
||||
className='update-modal--close'
|
||||
onClick={onCancel}
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 1024 1024"
|
||||
version="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path d="M557.312 513.248l265.28-263.904c12.544-12.48 12.608-32.704 0.128-45.248-12.512-12.576-32.704-12.608-45.248-0.128l-265.344 263.936-263.04-263.84C236.64 191.584 216.384 191.52 203.84 204 191.328 216.48 191.296 236.736 203.776 249.28l262.976 263.776L201.6 776.8c-12.544 12.48-12.608 32.704-0.128 45.248 6.24 6.272 14.464 9.44 22.688 9.44 8.16 0 16.32-3.104 22.56-9.312l265.216-263.808 265.44 266.24c6.24 6.272 14.432 9.408 22.656 9.408 8.192 0 16.352-3.136 22.592-9.344 12.512-12.48 12.544-32.704 0.064-45.248L557.312 513.248z" p-id="2764" fill="currentColor">
|
||||
</path>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div className='content__body'>{children}</div>
|
||||
{typeof footer !== 'undefined' ? (
|
||||
<div className='content__footer'>
|
||||
<button onClick={onCancel}>{cancelText}</button>
|
||||
<button onClick={onOk}>{okText}</button>
|
||||
</div>
|
||||
) : footer}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const Modal = (props: Parameters<typeof ModalTemplate>[0] & { open: boolean }) => {
|
||||
const { open, ...omit } = props
|
||||
|
||||
return createPortal(
|
||||
open ? ModalTemplate(omit) : null,
|
||||
document.body,
|
||||
)
|
||||
}
|
||||
|
||||
export default Modal
|
||||
@@ -1,87 +0,0 @@
|
||||
.update-modal {
|
||||
--primary-color: rgb(224, 30, 90);
|
||||
|
||||
.update-modal__mask {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 9;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
|
||||
.update-modal__warp {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 19;
|
||||
}
|
||||
|
||||
.update-modal__content {
|
||||
box-shadow: 0 0 10px -4px rgb(130, 86, 208);
|
||||
overflow: hidden;
|
||||
border-radius: 4px;
|
||||
|
||||
.content__header {
|
||||
display: flex;
|
||||
line-height: 38px;
|
||||
background-color: var(--primary-color);
|
||||
|
||||
.content__header-text {
|
||||
font-weight: bold;
|
||||
width: 0;
|
||||
flex-grow: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.update-modal--close {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
margin: 4px;
|
||||
line-height: 34px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
|
||||
svg {
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
}
|
||||
}
|
||||
|
||||
.content__body {
|
||||
padding: 10px;
|
||||
background-color: #fff;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.content__footer {
|
||||
padding: 10px;
|
||||
background-color: #fff;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
button {
|
||||
padding: 7px 11px;
|
||||
background-color: var(--primary-color);
|
||||
font-size: 14px;
|
||||
margin-left: 10px;
|
||||
|
||||
&:first-child {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.icon {
|
||||
padding: 0 15px;
|
||||
width: 20px;
|
||||
fill: currentColor;
|
||||
|
||||
&:hover {
|
||||
color: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import React from 'react'
|
||||
import './progress.css'
|
||||
|
||||
const Progress: React.FC<React.PropsWithChildren<{
|
||||
percent?: number
|
||||
}>> = props => {
|
||||
const { percent = 0 } = props
|
||||
|
||||
return (
|
||||
<div className='update-progress'>
|
||||
<div className='update-progress-pr'>
|
||||
<div
|
||||
className='update-progress-rate'
|
||||
style={{ width: `${3 * percent}px` }}
|
||||
/>
|
||||
</div>
|
||||
<span className='update-progress-num'>{(percent ?? 0).toString().substring(0, 4)}%</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Progress
|
||||
@@ -1,21 +0,0 @@
|
||||
.update-progress {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.update-progress-pr {
|
||||
border: 1px solid #000;
|
||||
border-radius: 3px;
|
||||
height: 6px;
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
.update-progress-rate {
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
background-image: linear-gradient(to right, rgb(130, 86, 208) 0%, var(--primary-color) 100%)
|
||||
}
|
||||
|
||||
.update-progress-num {
|
||||
margin: 0 10px;
|
||||
}
|
||||
}
|
||||
@@ -2,48 +2,54 @@
|
||||
|
||||
English | [简体中文](README.zh-CN.md)
|
||||
|
||||
> Use `electron-updater` to realize the update detection, download and installation of the electric program.
|
||||
> Use `electron-updater` to detect, download, and install Electron app updates.
|
||||
|
||||
```sh
|
||||
npm i electron-updater
|
||||
pnpm add electron-updater
|
||||
```
|
||||
|
||||
### Main logic
|
||||
## Main Flow
|
||||
|
||||
1. ##### Configuration of the update the service address and update information script:
|
||||
### 1. Configure the update server
|
||||
|
||||
Add a `publish` field to `electron-builder.json5` for configuring the update address and which strategy to use as the update service.
|
||||
Add a `publish` field to `electron-builder.json` to define the update source and provider.
|
||||
|
||||
``` json5
|
||||
{
|
||||
"publish": {
|
||||
"provider": "generic",
|
||||
"channel": "latest",
|
||||
"url": "https://foo.com/"
|
||||
}
|
||||
}
|
||||
```
|
||||
```json5
|
||||
{
|
||||
publish: {
|
||||
provider: 'generic',
|
||||
channel: 'latest',
|
||||
url: 'https://foo.com/',
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
For more information, please refer to : [electron-builder.json5...](https://github.com/electron-vite/electron-vite-react/blob/2f2880a9f19de50ff14a0785b32a4d5427477e55/electron-builder.json5#L38)
|
||||
For more information, please refer to [electron-builder.json](https://github.com/electron-vite/electron-vite-react/blob/main/electron-builder.json)
|
||||
|
||||
2. ##### The update logic of Electron:
|
||||
### 2. Main-process update logic
|
||||
|
||||
- Checking if an update is available;
|
||||
- Checking the version of the software on the server;
|
||||
- Checking if an update is available;
|
||||
- Downloading the new version of the software from the server (when an update is available);
|
||||
- Installation method;
|
||||
This project keeps `autoDownload` disabled, so users start downloads manually.
|
||||
|
||||
For more information, please refer to : [update...](https://github.com/electron-vite/electron-vite-react/blob/main/electron/main/update.ts)
|
||||
- `check-update` calls `autoUpdater.checkForUpdates()` after packaging.
|
||||
- The main process emits `update-can-available` when it receives `update-available` or `update-not-available`.
|
||||
- `start-download` begins downloading the update and forwards download progress to the renderer.
|
||||
- `cancel-download` stops the current download and resets the cancellation token.
|
||||
- `quit-and-install` installs the downloaded update and restarts the app.
|
||||
|
||||
3. ##### Updating UI pages in Electron:
|
||||
For more information, please refer to [update.ts](https://github.com/electron-vite/electron-vite-react/blob/main/electron/main/update.ts)
|
||||
|
||||
The main function is to provide a UI page for users to trigger the update logic mentioned in (2.) above. Users can click on the page to trigger different update functions in Electron.
|
||||
|
||||
For more information, please refer to : [components/update...](https://github.com/electron-vite/electron-vite-react/blob/main/src/components/update/index.tsx)
|
||||
### 3. Renderer UI
|
||||
|
||||
The update page is the user-facing entry point for the flow above. Users click the page button to trigger update actions in Electron.
|
||||
|
||||
- Click **Check update** to trigger `check-update`.
|
||||
- If an update is available, the page lets the user start or cancel the download.
|
||||
- After the download completes, the page switches to **Install now**.
|
||||
|
||||
For more information, please refer to [components/update/index.tsx](https://github.com/electron-vite/electron-vite-react/blob/main/src/components/update/index.tsx)
|
||||
|
||||
---
|
||||
|
||||
Here it is recommended to trigger updates through user actions (in this project, Electron update function is triggered after the user clicks on the "Check for updates" button).
|
||||
Updates should be triggered by user action. In this project, the flow starts after the user clicks **Check update**.
|
||||
|
||||
For more information on using `electron-updater` for Electron updates, please refer to the documentation : [auto-update](https://www.electron.build/.html)
|
||||
For more information on using `electron-updater` for Electron updates, please refer to the [documentation](https://www.electron.build)
|
||||
@@ -1,51 +1,55 @@
|
||||
# electron-auto-update
|
||||
# electron-updater
|
||||
|
||||
[English](README.md) | 简体中文
|
||||
|
||||
使用`electron-updater`实现electron程序的更新检测、下载和安装等功能。
|
||||
使用 `electron-updater` 检测、下载并安装 Electron 应用更新。
|
||||
|
||||
```sh
|
||||
npm i electron-updater
|
||||
pnpm add electron-updater
|
||||
```
|
||||
|
||||
### 主要逻辑
|
||||
## 主要流程
|
||||
|
||||
1. ##### 更新地址、更新信息脚本的配置
|
||||
### 1. 配置更新服务
|
||||
|
||||
在`electron-builder.json5`添加`publish`字段,用来配置更新地址和使用哪种策略作为更新服务
|
||||
在 `electron-builder.json` 中添加 `publish` 字段,用来配置更新地址和 provider。
|
||||
|
||||
``` json5
|
||||
{
|
||||
"publish": {
|
||||
"provider": "generic", // 提供者、提供商
|
||||
"channel": "latest", // 生成yml文件的名称
|
||||
"url": "https://foo.com/" //更新地址
|
||||
}
|
||||
}
|
||||
```
|
||||
```json5
|
||||
{
|
||||
publish: {
|
||||
provider: 'generic',
|
||||
channel: 'latest',
|
||||
url: 'https://foo.com/',
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
更多见 : [electron-builder.json5...](xxx)
|
||||
更多详情请见:[electron-builder.json](https://github.com/electron-vite/electron-vite-react/blob/main/electron-builder.json)
|
||||
|
||||
2. ##### Electron更新逻辑
|
||||
### 2. 主进程更新逻辑
|
||||
|
||||
- 检测更新是否可用;
|
||||
本项目保持 `autoDownload` 关闭,因此下载需要由用户手动触发。
|
||||
|
||||
- 检测服务端的软件版本;
|
||||
- `check-update` 会在打包后调用 `autoUpdater.checkForUpdates()`。
|
||||
- 主进程在收到 `update-available` 或 `update-not-available` 时,会向渲染进程发送 `update-can-available`。
|
||||
- `start-download` 会开始下载更新,并把下载进度转发到渲染进程。
|
||||
- `cancel-download` 会取消当前下载,并重置取消令牌。
|
||||
- `quit-and-install` 会安装已下载的更新并重启应用。
|
||||
|
||||
- 检测更新是否可用;
|
||||
更多详情请见:[update.ts](https://github.com/electron-vite/electron-vite-react/blob/main/electron/main/update.ts)
|
||||
|
||||
- 下载服务端新版软件(当更新可用);
|
||||
- 安装方式;
|
||||
### 3. 渲染进程 UI
|
||||
|
||||
更多见 : [update...](https://github.com/electron-vite/electron-vite-react/blob/main/electron/main/update.ts)
|
||||
更新页面是用户触发上述流程的入口,用户通过页面按钮触发 Electron 的更新动作。
|
||||
|
||||
3. ##### Electron更新UI页面
|
||||
- 点击 **Check update** 触发 `check-update`。
|
||||
- 如果发现新版本,页面会允许用户开始或取消下载。
|
||||
- 下载完成后,页面会切换为 **Install now**。
|
||||
|
||||
主要功能是:用户触发上述(2.)更新逻辑的UI页面。用户可以通过点击页面触发electron更新的不同功能。
|
||||
更多见 : [components/update.ts...](https://github.com/electron-vite/electron-vite-react/tree/main/src/components/update/index.tsx)
|
||||
更多详情请见:[components/update/index.tsx](https://github.com/electron-vite/electron-vite-react/blob/main/src/components/update/index.tsx)
|
||||
|
||||
---
|
||||
|
||||
这里建议更新触发以用户操作触发(本项目的以用户点击 **更新检测** 后触发electron更新功能)
|
||||
建议通过用户操作触发更新。在本项目中,流程从用户点击 **Check update** 开始。
|
||||
|
||||
关于更多使用`electron-updater`进行electron更新,见文档:[auto-update](https://www.electron.build/.html)
|
||||
更多使用 `electron-updater` 的信息请参考 [官方文档](https://www.electron.build)
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { ProgressInfo } from 'electron-updater'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import Modal from '@/components/update/Modal'
|
||||
import Progress from '@/components/update/Progress'
|
||||
import './update.css'
|
||||
import Modal from '@/components/update/modal'
|
||||
import Progress from '@/components/update/progress'
|
||||
|
||||
const Update = () => {
|
||||
const [checking, setChecking] = useState(false)
|
||||
@@ -36,35 +35,41 @@ const Update = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const onUpdateCanAvailable = useCallback((_event: Electron.IpcRendererEvent, arg1: VersionInfo) => {
|
||||
setVersionInfo(arg1)
|
||||
setUpdateError(undefined)
|
||||
// Can be update
|
||||
if (arg1.update) {
|
||||
setModalBtn(state => ({
|
||||
...state,
|
||||
cancelText: 'Cancel',
|
||||
okText: 'Update',
|
||||
onOk: () => window.ipcRenderer.invoke('start-download'),
|
||||
}))
|
||||
setUpdateAvailable(true)
|
||||
} else {
|
||||
setUpdateAvailable(false)
|
||||
}
|
||||
}, [])
|
||||
const onUpdateCanAvailable = useCallback(
|
||||
(_event: Electron.IpcRendererEvent, arg1: VersionInfo) => {
|
||||
setVersionInfo(arg1)
|
||||
setUpdateError(undefined)
|
||||
// Can be update
|
||||
if (arg1.update) {
|
||||
setModalBtn((state) => ({
|
||||
...state,
|
||||
cancelText: 'Cancel',
|
||||
okText: 'Update',
|
||||
onOk: () => window.ipcRenderer.invoke('start-download'),
|
||||
}))
|
||||
setUpdateAvailable(true)
|
||||
} else {
|
||||
setUpdateAvailable(false)
|
||||
}
|
||||
},
|
||||
[],
|
||||
)
|
||||
|
||||
const onUpdateError = useCallback((_event: Electron.IpcRendererEvent, arg1: ErrorType) => {
|
||||
setUpdateAvailable(false)
|
||||
setUpdateError(arg1)
|
||||
}, [])
|
||||
|
||||
const onDownloadProgress = useCallback((_event: Electron.IpcRendererEvent, arg1: ProgressInfo) => {
|
||||
setProgressInfo(arg1)
|
||||
}, [])
|
||||
const onDownloadProgress = useCallback(
|
||||
(_event: Electron.IpcRendererEvent, arg1: ProgressInfo) => {
|
||||
setProgressInfo(arg1)
|
||||
},
|
||||
[],
|
||||
)
|
||||
|
||||
const onUpdateDownloaded = useCallback((_event: Electron.IpcRendererEvent, ...args: any[]) => {
|
||||
setProgressInfo({ percent: 100 })
|
||||
setModalBtn(state => ({
|
||||
setModalBtn((state) => ({
|
||||
...state,
|
||||
cancelText: 'Later',
|
||||
okText: 'Install now',
|
||||
@@ -95,34 +100,42 @@ const Update = () => {
|
||||
okText={modalBtn?.okText}
|
||||
onCancel={modalBtn?.onCancel}
|
||||
onOk={modalBtn?.onOk}
|
||||
footer={updateAvailable ? /* hide footer */null : undefined}
|
||||
title="Updater"
|
||||
footer={updateAvailable ? /* hide footer */ null : undefined}
|
||||
>
|
||||
<div className='modal-slot'>
|
||||
{updateError
|
||||
? (
|
||||
<div>
|
||||
<p>Error downloading the latest version.</p>
|
||||
<p>{updateError.message}</p>
|
||||
<div className="space-y-3">
|
||||
{updateError ? (
|
||||
<div className="text-sm leading-6 text-rose-700">
|
||||
<p className="font-semibold text-rose-900">Error downloading the latest version.</p>
|
||||
<p className="mt-1 max-h-40 overflow-auto">{updateError.message}</p>
|
||||
</div>
|
||||
) : updateAvailable ? (
|
||||
<div className="space-y-3 text-sm text-slate-700">
|
||||
<div className="text-base font-semibold text-slate-900">
|
||||
The latest version is v{versionInfo?.newVersion}
|
||||
</div>
|
||||
) : updateAvailable
|
||||
? (
|
||||
<div>
|
||||
<div>The last version is: v{versionInfo?.newVersion}</div>
|
||||
<div className='new-version__target'>v{versionInfo?.version} -> v{versionInfo?.newVersion}</div>
|
||||
<div className='update__progress'>
|
||||
<div className='progress__title'>Update progress:</div>
|
||||
<div className='progress__bar'>
|
||||
<Progress percent={progressInfo?.percent} ></Progress>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-slate-600">
|
||||
v{versionInfo?.version} -> v{versionInfo?.newVersion}
|
||||
</div>
|
||||
<div className="flex items-center gap-3 pt-1">
|
||||
<div className="shrink-0 font-medium text-slate-700">Update progress:</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<Progress percent={progressInfo?.percent}></Progress>
|
||||
</div>
|
||||
)
|
||||
: (
|
||||
<div className='can-not-available'>{JSON.stringify(versionInfo ?? {}, null, 2)}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<pre className="overflow-auto text-left text-xs leading-6 text-slate-700">
|
||||
{JSON.stringify(versionInfo ?? {}, null, 2)}
|
||||
</pre>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
<button disabled={checking} onClick={checkUpdate}>
|
||||
<button
|
||||
disabled={checking}
|
||||
onClick={checkUpdate}
|
||||
className="inline-flex items-center justify-center rounded-2xl border border-cyan-700/15 bg-cyan-600 px-5 py-3 font-semibold text-white shadow-sm shadow-cyan-800/20 transition hover:bg-cyan-700 disabled:cursor-not-allowed disabled:bg-cyan-300 disabled:text-cyan-700"
|
||||
>
|
||||
{checking ? 'Checking...' : 'Check update'}
|
||||
</button>
|
||||
</>
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import React, { type ReactNode } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
|
||||
const ModalTemplate: React.FC<
|
||||
React.PropsWithChildren<{
|
||||
title?: ReactNode
|
||||
footer?: ReactNode
|
||||
cancelText?: string
|
||||
okText?: string
|
||||
onCancel?: () => void
|
||||
onOk?: () => void
|
||||
width?: number
|
||||
}>
|
||||
> = (props) => {
|
||||
const {
|
||||
title,
|
||||
children,
|
||||
footer,
|
||||
cancelText = 'Cancel',
|
||||
okText = 'OK',
|
||||
onCancel,
|
||||
onOk,
|
||||
width = 460,
|
||||
} = props
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50">
|
||||
<div className="absolute inset-0 bg-slate-900/14 backdrop-blur-sm" onClick={onCancel} />
|
||||
<div className="absolute left-1/2 top-1/2 w-[min(calc(100vw-2rem),_460px)] -translate-x-1/2 -translate-y-1/2">
|
||||
<div
|
||||
className="overflow-hidden rounded-[1.5rem] border border-slate-200 bg-white px-5 py-4 shadow-[0_24px_60px_-32px_rgba(15,23,42,0.28)]"
|
||||
style={{ width }}
|
||||
>
|
||||
<div className="flex items-start gap-3 text-slate-900">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="text-xs font-semibold uppercase tracking-[0.24em] text-cyan-700">System</div>
|
||||
<div className="mt-1 text-2xl font-semibold tracking-tight">{title}</div>
|
||||
</div>
|
||||
<span
|
||||
className="inline-flex h-10 w-10 cursor-pointer items-center justify-center rounded-full bg-slate-100 text-slate-700 transition hover:bg-slate-200"
|
||||
onClick={onCancel}
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 1024 1024"
|
||||
version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="h-4 w-4"
|
||||
>
|
||||
<path
|
||||
d="M557.312 513.248l265.28-263.904c12.544-12.48 12.608-32.704 0.128-45.248-12.512-12.576-32.704-12.608-45.248-0.128l-265.344 263.936-263.04-263.84C236.64 191.584 216.384 191.52 203.84 204 191.328 216.48 191.296 236.736 203.776 249.28l262.976 263.776L201.6 776.8c-12.544 12.48-12.608 32.704-0.128 45.248 6.24 6.272 14.464 9.44 22.688 9.44 8.16 0 16.32-3.104 22.56-9.312l265.216-263.808 265.44 266.24c6.24 6.272 14.432 9.408 22.656 9.408 8.192 0 16.352-3.136 22.592-9.344 12.512-12.48 12.544-32.704 0.064-45.248L557.312 513.248z"
|
||||
p-id="2764"
|
||||
fill="currentColor"
|
||||
></path>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div className="pt-4 text-slate-700">{children}</div>
|
||||
{footer !== undefined ? (
|
||||
<div className="flex justify-end gap-2 pt-4">
|
||||
<button
|
||||
onClick={onCancel}
|
||||
className="rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm font-medium text-slate-700 transition hover:bg-slate-50"
|
||||
>
|
||||
{cancelText}
|
||||
</button>
|
||||
<button
|
||||
onClick={onOk}
|
||||
className="rounded-xl bg-cyan-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-cyan-700"
|
||||
>
|
||||
{okText}
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
footer
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const Modal = (props: Parameters<typeof ModalTemplate>[0] & { open: boolean }) => {
|
||||
const { open, ...omit } = props
|
||||
|
||||
return createPortal(open ? <ModalTemplate {...omit} /> : null, document.body)
|
||||
}
|
||||
|
||||
export default Modal
|
||||
@@ -0,0 +1,26 @@
|
||||
import React from 'react'
|
||||
|
||||
const Progress: React.FC<
|
||||
React.PropsWithChildren<{
|
||||
percent?: number
|
||||
}>
|
||||
> = (props) => {
|
||||
const { percent = 0 } = props
|
||||
const normalizedPercent = Math.min(Math.max(percent ?? 0, 0), 100)
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="h-1.5 flex-1 overflow-hidden rounded-full bg-slate-200">
|
||||
<div
|
||||
className="h-full rounded-full bg-cyan-600 transition-[width] duration-300 ease-out"
|
||||
style={{ width: `${normalizedPercent}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="min-w-[3rem] text-right text-xs font-medium text-slate-600">
|
||||
{normalizedPercent.toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Progress
|
||||
@@ -1,24 +0,0 @@
|
||||
.modal-slot {
|
||||
.update-progress {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.new-version__target,
|
||||
.update__progress {
|
||||
margin-left: 40px;
|
||||
}
|
||||
|
||||
.progress__title {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.progress__bar {
|
||||
width: 0;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.can-not-available {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user