mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
Closes: [BS-3555](https://linear.app/affine-design/issue/BS-3555/ui-attachment-loading-变量更新) Closes: [BS-3559](https://linear.app/affine-design/issue/BS-3559/ui-图片-loading-变量更新) ### Dark <img width="625" alt="Screenshot 2025-05-26 at 20 32 36" src="https://github.com/user-attachments/assets/93501e3d-8fc6-45f9-84a0-ac147e5c5f9f" /> ### Light <img width="623" alt="Screenshot 2025-05-26 at 20 32 25" src="https://github.com/user-attachments/assets/7d5bc128-6667-45b5-982d-dab3a22706a7" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Loading icons are now invoked as functions, allowing for more flexible and customizable rendering with parameters like size and progress. - **Refactor** - Replaced theme-dependent and static loading icon references with a unified `LoadingIcon()` component across multiple components and blocks. - Removed legacy icon variants and simplified icon import statements, centralizing icon rendering logic. - **Style** - Updated styles for loading and reload buttons to use theme-aware CSS variables. - Enlarged and repositioned loading indicators in image blocks for better visibility. - **Bug Fixes** - Achieved consistent loading icon rendering across various blocks and components by standardizing icon invocation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
194 lines
4.8 KiB
TypeScript
194 lines
4.8 KiB
TypeScript
import { LoadingIcon } from '@blocksuite/affine-components/icons';
|
|
import { unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme';
|
|
import { EmbedIcon } from '@blocksuite/icons/lit';
|
|
import { type BlockStdScope } from '@blocksuite/std';
|
|
import { css, html, LitElement } from 'lit';
|
|
import { property } from 'lit/decorators.js';
|
|
import { classMap } from 'lit/directives/class-map.js';
|
|
import { styleMap } from 'lit/directives/style-map.js';
|
|
|
|
import { LOADING_CARD_DEFAULT_HEIGHT } from '../consts';
|
|
import type { EmbedIframeStatusCardOptions } from '../types';
|
|
|
|
export class EmbedIframeLoadingCard extends LitElement {
|
|
static override styles = css`
|
|
:host {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.affine-embed-iframe-loading-card {
|
|
container: affine-embed-iframe-loading-card / size;
|
|
display: flex;
|
|
box-sizing: border-box;
|
|
border-radius: 8px;
|
|
user-select: none;
|
|
padding: 12px;
|
|
gap: 12px;
|
|
overflow: hidden;
|
|
border: 1px solid ${unsafeCSSVarV2('layer/insideBorder/border')};
|
|
background: ${unsafeCSSVarV2('layer/white')};
|
|
|
|
.loading-content {
|
|
display: flex;
|
|
gap: 8px;
|
|
align-self: stretch;
|
|
|
|
.loading-spinner {
|
|
display: flex;
|
|
width: 24px;
|
|
height: 24px;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
.loading-text {
|
|
display: -webkit-box;
|
|
-webkit-box-orient: vertical;
|
|
-webkit-line-clamp: 1;
|
|
overflow: hidden;
|
|
color: ${unsafeCSSVarV2('text/primary')};
|
|
text-overflow: ellipsis;
|
|
/* Client/smMedium */
|
|
font-family: Inter;
|
|
font-size: var(--affine-font-sm);
|
|
font-style: normal;
|
|
font-weight: 500;
|
|
line-height: 22px; /* 157.143% */
|
|
}
|
|
}
|
|
|
|
.loading-banner {
|
|
display: flex;
|
|
box-sizing: border-box;
|
|
justify-content: center;
|
|
align-items: center;
|
|
flex-shrink: 0;
|
|
|
|
.icon-box {
|
|
display: flex;
|
|
transform: rotate(8deg);
|
|
justify-content: center;
|
|
align-items: center;
|
|
flex-shrink: 0;
|
|
border-radius: 4px 4px 0px 0px;
|
|
background: ${unsafeCSSVarV2('slashMenu/background')};
|
|
box-shadow: 0px 0px 5px 0px rgba(66, 65, 73, 0.17);
|
|
|
|
svg {
|
|
fill: black;
|
|
fill-opacity: 0.07;
|
|
}
|
|
}
|
|
}
|
|
|
|
@container affine-embed-iframe-loading-card (width < 360px) {
|
|
.loading-banner {
|
|
display: none;
|
|
}
|
|
}
|
|
}
|
|
|
|
.affine-embed-iframe-loading-card.horizontal {
|
|
flex-direction: row;
|
|
align-items: flex-start;
|
|
|
|
.loading-content {
|
|
flex: 1 0 0;
|
|
align-items: flex-start;
|
|
|
|
.loading-text {
|
|
flex: 1 0 0;
|
|
}
|
|
}
|
|
|
|
.loading-banner {
|
|
width: 204px;
|
|
padding: 3.139px 42.14px 0px 42.14px;
|
|
|
|
.icon-box {
|
|
width: 106px;
|
|
height: 106px;
|
|
|
|
svg {
|
|
width: 66px;
|
|
height: 66px;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
.affine-embed-iframe-loading-card.vertical {
|
|
flex-direction: column-reverse;
|
|
align-items: center;
|
|
justify-content: center;
|
|
|
|
.loading-content {
|
|
justify-content: center;
|
|
font-size: 14px;
|
|
transform: translateX(-2%);
|
|
}
|
|
|
|
.loading-banner {
|
|
width: 340px;
|
|
padding: 5.23px 70.234px 0px 70.232px;
|
|
overflow-y: hidden;
|
|
|
|
.icon-box {
|
|
width: 176px;
|
|
height: 176px;
|
|
transform: rotate(8deg) translateY(15%);
|
|
|
|
svg {
|
|
width: 112px;
|
|
height: 112px;
|
|
}
|
|
}
|
|
}
|
|
|
|
@container affine-embed-iframe-loading-card (height < 240px) {
|
|
.loading-banner {
|
|
display: none;
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
override render() {
|
|
const { layout, width, height } = this.options;
|
|
const cardClasses = classMap({
|
|
'affine-embed-iframe-loading-card': true,
|
|
horizontal: layout === 'horizontal',
|
|
vertical: layout === 'vertical',
|
|
});
|
|
|
|
const cardWidth = width ? `${width}px` : '100%';
|
|
const cardHeight = height ? `${height}px` : '100%';
|
|
const cardStyle = styleMap({
|
|
width: cardWidth,
|
|
height: cardHeight,
|
|
});
|
|
|
|
return html`
|
|
<div class=${cardClasses} style=${cardStyle}>
|
|
<div class="loading-content">
|
|
<div class="loading-spinner">${LoadingIcon()}</div>
|
|
<div class="loading-text">Loading...</div>
|
|
</div>
|
|
<div class="loading-banner">
|
|
<div class="icon-box">${EmbedIcon()}</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
@property({ attribute: false })
|
|
accessor std!: BlockStdScope;
|
|
|
|
@property({ attribute: false })
|
|
accessor options: EmbedIframeStatusCardOptions = {
|
|
layout: 'horizontal',
|
|
height: LOADING_CARD_DEFAULT_HEIGHT,
|
|
};
|
|
}
|