Correct the GenericToast props to show the two modes of operation

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/21833/head
Michael Telatynski 2020-05-29 19:13:59 +01:00
parent efd0da44a1
commit f45c584c8a
2 changed files with 26 additions and 3 deletions

19
src/@types/common.ts Normal file
View File

@ -0,0 +1,19 @@
/*
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.
*/
// Based on https://stackoverflow.com/a/53229857/3532235
export type Without<T, U> = {[P in Exclude<keyof T, keyof U>] ? : never}
export type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;

View File

@ -17,17 +17,21 @@ limitations under the License.
import React, {ReactChild} from "react"; import React, {ReactChild} from "react";
import FormButton from "../elements/FormButton"; import FormButton from "../elements/FormButton";
import {XOR} from "../../../@types/common";
interface IProps { interface IProps {
description: ReactChild; description: ReactChild;
acceptLabel: string; acceptLabel: string;
rejectLabel?: string;
onAccept(); onAccept();
onReject?();
} }
const GenericToast: React.FC<IProps> = ({description, acceptLabel, rejectLabel, onAccept, onReject}) => { interface IPropsExtended extends IProps {
rejectLabel: string;
onReject();
}
const GenericToast: React.FC<XOR<IPropsExtended, IProps>> = ({description, acceptLabel, rejectLabel, onAccept, onReject}) => {
return <div> return <div>
<div className="mx_Toast_description"> <div className="mx_Toast_description">
{ description } { description }