mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-07-24 04:31:52 +00:00
Move more components to shlink-web-component when applicable
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
.copy-to-clipboard-icon {
|
||||
cursor: pointer;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { faClone as copyIcon } from '@fortawesome/free-regular-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import type { FC } from 'react';
|
||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||
import './CopyToClipboardIcon.scss';
|
||||
|
||||
interface CopyToClipboardIconProps {
|
||||
text: string;
|
||||
onCopy?: (text: string, result: boolean) => void;
|
||||
}
|
||||
|
||||
export const CopyToClipboardIcon: FC<CopyToClipboardIconProps> = ({ text, onCopy }) => (
|
||||
<CopyToClipboard text={text} onCopy={onCopy}>
|
||||
<FontAwesomeIcon icon={copyIcon} className="ms-2 copy-to-clipboard-icon" />
|
||||
</CopyToClipboard>
|
||||
);
|
||||
17
shlink-web-component/utils/components/ExportBtn.tsx
Normal file
17
shlink-web-component/utils/components/ExportBtn.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { faFileCsv } from '@fortawesome/free-solid-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import type { FC } from 'react';
|
||||
import type { ButtonProps } from 'reactstrap';
|
||||
import { Button } from 'reactstrap';
|
||||
import { prettify } from '../helpers/numbers';
|
||||
|
||||
type ExportBtnProps = Omit<ButtonProps, 'outline' | 'color' | 'disabled'> & {
|
||||
amount?: number;
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
export const ExportBtn: FC<ExportBtnProps> = ({ amount = 0, loading = false, ...rest }) => (
|
||||
<Button {...rest} outline color="primary" disabled={loading}>
|
||||
<FontAwesomeIcon icon={faFileCsv} /> {loading ? 'Exporting...' : <>Export ({prettify(amount)})</>}
|
||||
</Button>
|
||||
);
|
||||
24
shlink-web-component/utils/components/InfoTooltip.tsx
Normal file
24
shlink-web-component/utils/components/InfoTooltip.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { faInfoCircle as infoIcon } from '@fortawesome/free-solid-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import type { Placement } from '@popperjs/core';
|
||||
import type { FC, PropsWithChildren } from 'react';
|
||||
import { UncontrolledTooltip } from 'reactstrap';
|
||||
import { useElementRef } from '../helpers/hooks';
|
||||
|
||||
export type InfoTooltipProps = PropsWithChildren<{
|
||||
className?: string;
|
||||
placement: Placement;
|
||||
}>;
|
||||
|
||||
export const InfoTooltip: FC<InfoTooltipProps> = ({ className = '', placement, children }) => {
|
||||
const ref = useElementRef<HTMLSpanElement>();
|
||||
|
||||
return (
|
||||
<>
|
||||
<span className={className} ref={ref}>
|
||||
<FontAwesomeIcon icon={infoIcon} />
|
||||
</span>
|
||||
<UncontrolledTooltip target={ref} placement={placement}>{children}</UncontrolledTooltip>
|
||||
</>
|
||||
);
|
||||
};
|
||||
25
shlink-web-component/utils/components/PaginationDropdown.tsx
Normal file
25
shlink-web-component/utils/components/PaginationDropdown.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { DropdownItem, DropdownMenu, DropdownToggle, UncontrolledDropdown } from 'reactstrap';
|
||||
|
||||
interface PaginationDropdownProps {
|
||||
ranges: number[];
|
||||
value: number;
|
||||
setValue: (newValue: number) => void;
|
||||
toggleClassName?: string;
|
||||
}
|
||||
|
||||
export const PaginationDropdown = ({ toggleClassName, ranges, value, setValue }: PaginationDropdownProps) => (
|
||||
<UncontrolledDropdown>
|
||||
<DropdownToggle caret color="link" className={toggleClassName}>Paginate</DropdownToggle>
|
||||
<DropdownMenu end>
|
||||
{ranges.map((itemsPerPage) => (
|
||||
<DropdownItem key={itemsPerPage} active={itemsPerPage === value} onClick={() => setValue(itemsPerPage)}>
|
||||
<b>{itemsPerPage}</b> items per page
|
||||
</DropdownItem>
|
||||
))}
|
||||
<DropdownItem divider />
|
||||
<DropdownItem disabled={value === Infinity} onClick={() => setValue(Infinity)}>
|
||||
<i>Clear pagination</i>
|
||||
</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</UncontrolledDropdown>
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
.simple-paginator {
|
||||
user-select: none;
|
||||
}
|
||||
50
shlink-web-component/utils/components/SimplePaginator.tsx
Normal file
50
shlink-web-component/utils/components/SimplePaginator.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import classNames from 'classnames';
|
||||
import type { FC } from 'react';
|
||||
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap';
|
||||
import type { NumberOrEllipsis } from '../helpers/pagination';
|
||||
import {
|
||||
keyForPage,
|
||||
pageIsEllipsis,
|
||||
prettifyPageNumber,
|
||||
progressivePagination,
|
||||
} from '../helpers/pagination';
|
||||
import './SimplePaginator.scss';
|
||||
|
||||
interface SimplePaginatorProps {
|
||||
pagesCount: number;
|
||||
currentPage: number;
|
||||
setCurrentPage: (currentPage: number) => void;
|
||||
centered?: boolean;
|
||||
}
|
||||
|
||||
export const SimplePaginator: FC<SimplePaginatorProps> = (
|
||||
{ pagesCount, currentPage, setCurrentPage, centered = true },
|
||||
) => {
|
||||
if (pagesCount < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const onClick = (page: NumberOrEllipsis) => () => !pageIsEllipsis(page) && setCurrentPage(page);
|
||||
|
||||
return (
|
||||
<Pagination listClassName={classNames('flex-wrap mb-0 simple-paginator', { 'justify-content-center': centered })}>
|
||||
<PaginationItem disabled={currentPage <= 1}>
|
||||
<PaginationLink previous tag="span" onClick={onClick(currentPage - 1)} />
|
||||
</PaginationItem>
|
||||
{progressivePagination(currentPage, pagesCount).map((pageNumber, index) => (
|
||||
<PaginationItem
|
||||
key={keyForPage(pageNumber, index)}
|
||||
disabled={pageIsEllipsis(pageNumber)}
|
||||
active={currentPage === pageNumber}
|
||||
>
|
||||
<PaginationLink role="link" tag="span" onClick={onClick(pageNumber)}>
|
||||
{prettifyPageNumber(pageNumber)}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
))}
|
||||
<PaginationItem disabled={currentPage >= pagesCount}>
|
||||
<PaginationLink next tag="span" onClick={onClick(currentPage + 1)} />
|
||||
</PaginationItem>
|
||||
</Pagination>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user