Skip to content

Commit

Permalink
fix(external-sources): done button loading state behaviour (#770)
Browse files Browse the repository at this point in the history
Co-authored-by: nd0ut <[email protected]>
  • Loading branch information
nd0ut and nd0ut authored Jan 8, 2025
1 parent 8cbbdb3 commit 77b545e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
16 changes: 9 additions & 7 deletions blocks/ExternalSource/ExternalSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ export class ExternalSource extends UploaderBlock {
total: 0,

isSelectionReady: false,
isDoneBtnEnabled: false,
couldSelectAll: false,
couldDeselectAll: false,
showSelectionStatus: false,
counterText: '',
doneBtnTextClass: 'uc-hidden',

onDone: () => {
for (const message of this.$.selectedList) {
Expand Down Expand Up @@ -150,7 +152,9 @@ export class ExternalSource extends UploaderBlock {
);

this.set$({
doneBtnTextClass: message.isReady ? '' : 'uc-hidden',
isSelectionReady: message.isReady,
isDoneBtnEnabled: message.isReady && message.selectedFiles.length > 0,
showSelectionStatus: message.isMultipleMode && message.total > 0,
couldSelectAll: message.selectedCount < message.total,
couldDeselectAll: message.selectedCount === message.total,
Expand Down Expand Up @@ -256,7 +260,7 @@ export class ExternalSource extends UploaderBlock {
this.set$({
selectedList: [],
total: 0,
isSelectionReady: false,
isDoneBtnEnabled: false,
couldSelectAll: false,
couldDeselectAll: false,
showSelectionStatus: false,
Expand Down Expand Up @@ -284,12 +288,10 @@ ExternalSource.template = /* HTML */ `
<button type="button" set="onclick: onSelectAll; @hidden: !couldSelectAll" l10n="select-all"></button>
<button type="button" set="onclick: onDeselectAll; @hidden: !couldDeselectAll" l10n="deselect-all"></button>
</div>
<button
type="button"
class="uc-done-btn uc-primary-btn"
set="onclick: onDone; @disabled: !isSelectionReady"
l10n="done"
></button>
<button type="button" class="uc-done-btn uc-primary-btn" set="onclick: onDone; @disabled: !isDoneBtnEnabled;">
<uc-spinner set="@hidden: isSelectionReady"></uc-spinner>
<span l10n="done" set="@class: doneBtnTextClass"></span>
</button>
</div>
</div>
`;
14 changes: 14 additions & 0 deletions blocks/ExternalSource/external-source.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,17 @@ uc-external-source uc-activity-header {
uc-external-source uc-activity-header .uc-close-btn {
pointer-events: auto;
}

uc-external-source .uc-done-btn > span.uc-hidden {
visibility: hidden;
pointer-events: none;
}

uc-external-source .uc-done-btn > uc-spinner {
position: absolute;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
5 changes: 5 additions & 0 deletions blocks/Spinner/Spinner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { BaseComponent } from '@symbiotejs/symbiote';

export class Spinner extends BaseComponent {}

Spinner.template = /* HTML */ ` <div class="uc-spinner"></div> `;
18 changes: 18 additions & 0 deletions blocks/Spinner/spinner.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@keyframes uc-spinner-keyframes {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

.uc-spinner {
width: 1em;
height: 1em;
border: solid 2px transparent;
border-top-color: currentColor;
border-left-color: currentColor;
border-radius: 50%;
animation: uc-spinner-keyframes 400ms linear infinite;
}
1 change: 1 addition & 0 deletions blocks/themes/uc-basic/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
@import url('../../CloudImageEditor/index.css');
@import url('../../CloudImageEditorActivity/index.css');
@import url('../../Select/select.css');
@import url('../../Spinner/spinner.css');

/* POST RESET */
@import url('post-reset.css');
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export { FormInput } from './blocks/FormInput/FormInput.js';
export { ActivityHeader } from './blocks/ActivityHeader/ActivityHeader.js';
export { Select } from './blocks/Select/Select.js';
export { Copyright } from './blocks/Copyright/Copyright.js';
export { Spinner } from './blocks/Spinner/Spinner.js';

// Solutions:
export { FileUploaderRegular } from './solutions/file-uploader/regular/FileUploaderRegular.js';
Expand Down

0 comments on commit 77b545e

Please sign in to comment.