Add keyboard navigation for users, groups, branches, tags, sources, changesets and plugins (#2153)

Co-authored-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com>
This commit is contained in:
Konstantin Schaper
2022-11-10 11:44:53 +01:00
committed by GitHub
parent da71004dd0
commit eea60deadb
28 changed files with 819 additions and 373 deletions

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React, { FC, ReactNode } from "react";
import React, { ReactNode, useCallback } from "react";
import classNames from "classnames";
import styled from "styled-components";
import { Link } from "react-router-dom";
@@ -55,69 +55,72 @@ const InvisibleButton = styled.button`
cursor: pointer;
`;
const CardColumn: FC<Props> = ({
link,
avatar,
title,
description,
contentRight,
footerLeft,
footerRight,
action,
className,
}) => {
const renderAvatar = avatar ? <figure className="media-left mt-3 ml-4">{avatar}</figure> : null;
const renderDescription = description ? <p className="shorten-text">{description}</p> : null;
const renderContentRight = contentRight ? <div className="ml-auto">{contentRight}</div> : null;
const CardColumn = React.forwardRef<HTMLElement, Props>(
({ link, avatar, title, description, contentRight, footerLeft, footerRight, action, className }, ref) => {
const renderAvatar = avatar ? <figure className="media-left mt-3 ml-4">{avatar}</figure> : null;
const renderDescription = description ? <p className="shorten-text">{description}</p> : null;
const renderContentRight = contentRight ? <div className="ml-auto">{contentRight}</div> : null;
const executeRef = useCallback(
(el: HTMLButtonElement | HTMLAnchorElement | null) => {
if (typeof ref === "function") {
ref(el);
} else if (ref) {
ref.current = el;
}
},
[ref]
);
let createLink = null;
if (link) {
createLink = <Link className="overlay-column" to={link} />;
} else if (action) {
createLink = (
<InvisibleButton
className="overlay-column"
onClick={(e) => {
e.preventDefault();
action();
}}
tabIndex={0}
/>
let createLink = null;
if (link) {
createLink = <Link ref={executeRef} className="overlay-column" to={link} />;
} else if (action) {
createLink = (
<InvisibleButton
ref={executeRef}
className="overlay-column"
onClick={(e) => {
e.preventDefault();
action();
}}
tabIndex={0}
/>
);
}
return (
<>
{createLink}
<NoEventWrapper className={classNames("media", className)}>
{renderAvatar}
<div
className={classNames(
"media-content",
"text-box",
"is-flex",
"is-flex-direction-column",
"is-justify-content-space-around",
"is-align-self-stretch"
)}
>
<div className="is-flex">
<div className="is-clipped mb-0">
<p className="shorten-text m-0">{title}</p>
{renderDescription}
</div>
{renderContentRight}
</div>
<div className={classNames("level", "is-flex", "pb-4")}>
<div className={classNames("level-left", "is-hidden-mobile", "mr-2")}>{footerLeft}</div>
<InheritFlexShrinkDiv className="level-right is-block is-mobile m-0 shorten-text">
{footerRight}
</InheritFlexShrinkDiv>
</div>
</div>
</NoEventWrapper>
</>
);
}
return (
<>
{createLink}
<NoEventWrapper className={classNames("media", className)}>
{renderAvatar}
<div
className={classNames(
"media-content",
"text-box",
"is-flex",
"is-flex-direction-column",
"is-justify-content-space-around",
"is-align-self-stretch"
)}
>
<div className="is-flex">
<div className="is-clipped mb-0">
<p className="shorten-text m-0">{title}</p>
{renderDescription}
</div>
{renderContentRight}
</div>
<div className={classNames("level", "is-flex", "pb-4")}>
<div className={classNames("level-left", "is-hidden-mobile", "mr-2")}>{footerLeft}</div>
<InheritFlexShrinkDiv className="level-right is-block is-mobile m-0 shorten-text">
{footerRight}
</InheritFlexShrinkDiv>
</div>
</div>
</NoEventWrapper>
</>
);
};
);
export default CardColumn;