Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions res/css/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
@import "./views/elements/_InlineSpinner.scss";
@import "./views/elements/_InteractiveTooltip.scss";
@import "./views/elements/_ManageIntegsButton.scss";
@import "./views/elements/_OverlaySpinner.scss";
@import "./views/elements/_PowerSelector.scss";
@import "./views/elements/_ProgressBar.scss";
@import "./views/elements/_ReplyThread.scss";
Expand Down
31 changes: 31 additions & 0 deletions res/css/views/elements/_OverlaySpinner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2020 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_OverlaySpinner {
background-color: white;
z-index: 2;
}

.mx_OverlaySpinner_visible {
opacity: 0.9;
transition: opacity 0.5s ease-in;
}

.mx_OverlaySpinner_hidden {
opacity: 0;
transition: opacity 0.2s ease-in;
pointer-events: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,46 @@ import {_t} from '../../../languageHandler.js';
import Field from "./Field";
import AccessibleButton from "./AccessibleButton";

export class EditableItem extends React.Component {
interface IEditableItemProps {
index: number,
value: string,
onRemove: (index: number) => void,
}

interface IEditableItemState {
verifyRemove: boolean,
}

export class EditableItem extends React.Component<IEditableItemProps, IEditableItemState> {
static propTypes = {
index: PropTypes.number,
value: PropTypes.string,
onRemove: PropTypes.func,
};

constructor() {
super();
constructor(props) {
super(props);

this.state = {
verifyRemove: false,
};
}

_onRemove = (e) => {
_onRemove = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
e.stopPropagation();
e.preventDefault();

this.setState({verifyRemove: true});
};

_onDontRemove = (e) => {
_onDontRemove = (e: Event) => {
e.stopPropagation();
e.preventDefault();

this.setState({verifyRemove: false});
};

_onActuallyRemove = (e) => {
_onActuallyRemove = (e: Event) => {
e.stopPropagation();
e.preventDefault();

Expand Down Expand Up @@ -85,7 +95,26 @@ export class EditableItem extends React.Component {
}
}

export default class EditableItemList extends React.Component {
interface IProps {
id: string,
items: string[],
itemsLabel?: string,
noItemsLabel?: string,
placeholder?: string,
newItem?: string,
suggestionsListId?: string,

onItemAdded?: (item: string) => void,
onItemRemoved?: (index: number) => void,
onNewItemChanged?: (item: string) => void,

canEdit?: boolean,
canRemove?: boolean,

error?: string, // for the benefit of PublishedAliases
}

export default class EditableItemList extends React.Component<IProps> {
static propTypes = {
id: PropTypes.string.isRequired,
items: PropTypes.arrayOf(PropTypes.string).isRequired,
Expand All @@ -102,18 +131,18 @@ export default class EditableItemList extends React.Component {
canRemove: PropTypes.bool,
};

_onItemAdded = (e) => {
_onItemAdded = (e: React.FormEvent<HTMLFormElement>) => {
e.stopPropagation();
e.preventDefault();

if (this.props.onItemAdded) this.props.onItemAdded(this.props.newItem);
};

_onItemRemoved = (index) => {
_onItemRemoved = (index: number) => {
if (this.props.onItemRemoved) this.props.onItemRemoved(index);
};

_onNewItemChanged = (e) => {
_onNewItemChanged = (e: any) => {
if (this.props.onNewItemChanged) this.props.onNewItemChanged(e.target.value);
};

Expand Down
92 changes: 92 additions & 0 deletions src/components/views/elements/OverlaySpinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright 2020 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React, {useEffect, useRef, useState, FunctionComponent} from "react";
import Spinner from "./Spinner";

/*
* A component which measures its children, and places a spinner over them
* while 'active' is true.
* We use 'holdOff' and 'holdOver' to shift the animations in time:
* We don't animate instantly to avoid a quick 'ghost' spinner for fast round trips.
* We have a short holdOver to allow the fade out to occur.
*/

interface IProps {
active: boolean,
className?: string,
};

export const OverlaySpinner: FunctionComponent<IProps> = ({active, className, children}) => {
const measured = useRef(null);
const [state, setState] = useState({w: 0, h: 0});

const firstMount = useRef(true);
const [holdOver, setHoldOver] = useState(false);
const [holdOff, setHoldOff] = useState(false);

/* Follow the size of the element we're meant to cover */
useEffect(() => {
const interval = requestAnimationFrame(() => {
if (!measured.current) return;
setState({
w: measured.current.clientWidth,
h: measured.current.clientHeight,
});
});
return () => cancelAnimationFrame(interval);
});

/* If it's not the first mount and the state changes to inactive,
* set 'holdOver' to true so the exit animation can play */
useEffect(() => {
if (firstMount.current) {
firstMount.current = false;
return;
}
if (!active) {
const handle = setTimeout(setHoldOver, 200, false);
setHoldOver(true);
return () => {
setHoldOver(false);
clearTimeout(handle);
};
} else {
const handle = setTimeout(setHoldOff, 200, false);
setHoldOff(true);
return () => {
setHoldOff(false);
clearTimeout(handle);
};
}
}, [active]);

const visibility = !holdOff && active ? "visible" : "hidden";

return (<div className={className} style={{ position: "relative" }}>
<div className={`mx_OverlaySpinner mx_OverlaySpinner_${visibility}`} style={{
position: "absolute",
width: state.w,
height: state.h,
visibility: active || holdOver ? "visible" : "hidden",
}}><Spinner /></div>
<div ref={measured}>
{children}
</div>
</div>);
}

export default OverlaySpinner;
Loading