use binder from context to make extensions it testable

This commit is contained in:
Sebastian Sdorra
2020-02-19 09:48:46 +01:00
parent 041a999a01
commit f23b464524
3 changed files with 68 additions and 75 deletions

View File

@@ -1,25 +1,26 @@
import React, {FC} from "react";
import { binder } from "@scm-manager/ui-extensions";
import React, { FC } from "react";
import { Image } from "..";
import { Person } from "./Avatar";
import { EXTENSION_POINT } from "./Avatar";
import { useBinder } from "@scm-manager/ui-extensions";
type Props = {
person: Person;
representation?: "rounded" | "rounded-border";
};
const AvatarImage:FC<Props> = ({person, representation = "rounded-border"}) => {
const avatarFactory = binder.getExtension(EXTENSION_POINT);
if (avatarFactory) {
const avatar = avatarFactory(person);
const AvatarImage: FC<Props> = ({ person, representation = "rounded-border" }) => {
const binder = useBinder();
const avatarFactory = binder.getExtension(EXTENSION_POINT);
if (avatarFactory) {
const avatar = avatarFactory(person);
const className = representation === "rounded" ? "is-rounded" : "has-rounded-border";
const className = representation === "rounded" ? "is-rounded" : "has-rounded-border";
return <Image className={className} src={avatar} alt={person.name} />;
}
return <Image className={className} src={avatar} alt={person.name} />;
}
return null;
return null;
};
export default AvatarImage;