mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Convert emby-button and emby-scroller to react
This commit is contained in:
parent
90c08d856c
commit
62a9034f5b
5 changed files with 484 additions and 0 deletions
65
src/elements/emby-button/LinkButton.tsx
Normal file
65
src/elements/emby-button/LinkButton.tsx
Normal file
|
@ -0,0 +1,65 @@
|
|||
import React, { AnchorHTMLAttributes, DetailedHTMLProps, MouseEvent } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import layoutManager from '../../components/layoutManager';
|
||||
import shell from '../../scripts/shell';
|
||||
import { appRouter } from '../../components/appRouter';
|
||||
import { appHost } from '../../components/apphost';
|
||||
import './emby-button.scss';
|
||||
|
||||
interface LinkButtonProps extends DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>,
|
||||
HTMLAnchorElement
|
||||
> {
|
||||
className?: string;
|
||||
isAutoHideEnabled?: boolean;
|
||||
href?: string;
|
||||
target?: string;
|
||||
}
|
||||
|
||||
const LinkButton: React.FC<LinkButtonProps> = ({
|
||||
className,
|
||||
isAutoHideEnabled,
|
||||
href,
|
||||
target,
|
||||
children,
|
||||
...rest
|
||||
}) => {
|
||||
const onAnchorClick = (e: MouseEvent<HTMLAnchorElement>) => {
|
||||
const url = href || '';
|
||||
if (url !== '#') {
|
||||
if (target) {
|
||||
if (!appHost.supports('targetblank')) {
|
||||
e.preventDefault();
|
||||
shell.openUrl(url);
|
||||
}
|
||||
} else {
|
||||
e.preventDefault();
|
||||
appRouter.show(url);
|
||||
}
|
||||
} else {
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
if (isAutoHideEnabled === true && !appHost.supports('externallinks')) {
|
||||
return null;
|
||||
}
|
||||
let cssClass = classNames('emby-button', className);
|
||||
|
||||
if (layoutManager.tv) {
|
||||
cssClass += ' show-focus';
|
||||
}
|
||||
|
||||
return (
|
||||
<a
|
||||
className={cssClass}
|
||||
href={href}
|
||||
target={target}
|
||||
onClick={onAnchorClick}
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
};
|
||||
|
||||
export default LinkButton;
|
Loading…
Add table
Add a link
Reference in a new issue