index
int64 0
0
| repo_id
stringlengths 16
181
| file_path
stringlengths 28
270
| content
stringlengths 1
11.6M
| __index_level_0__
int64 0
10k
|
|---|---|---|---|---|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/icon/Icon.test.js
|
import { render } from '@testing-library/react';
import Icon from './Icon';
describe('Icon component', () => {
it('should render the icon and the screen reader helper', () => {
const name = 'account';
const alt = 'Account';
const { container } = render(<Icon name={name} alt={alt} />);
const svgNode = container.querySelector(`[xlink:href="#ic-${name}"]`);
const srpNode = container.querySelector('.sr-only');
expect(svgNode).toBeDefined();
expect(srpNode).toBeDefined();
expect(srpNode.textContent).toBe(alt);
});
});
| 5,400
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/icon/Icon.tsx
|
import { forwardRef } from 'react';
import clsx from '@proton/utils/clsx';
export type IconSize =
| 6
| 8
| 10
| 11
| 12
| 14
| 16
| 18
| 20
| 22
| 24
| 28
| 32
| 36
| 40
| 42
| 48
| 56
| 60
| 70
| 100
| 110;
export type IconName =
| 'alias'
| 'app-switch'
| 'archive-box'
| 'arrow-down'
| 'arrow-down-arrow-up'
| 'arrow-down-circle'
| 'arrow-down-circle-filled'
| 'arrow-down-line'
| 'arrow-down-to-square'
| 'arrow-in-to-rectangle'
| 'arrow-left'
| 'arrow-left-and-up'
| 'arrow-out-from-rectangle'
| 'arrow-out-square'
| 'arrow-over-square'
| 'arrow-right'
| 'arrow-right-arrow-left'
| 'arrow-rotate-right'
| 'arrow-up'
| 'arrow-up-and-left'
| 'arrow-up-and-left-big'
| 'arrow-up-and-right-big'
| 'arrow-up-big-line'
| 'arrow-up-bounce-left'
| 'arrow-up-from-square'
| 'arrow-up-line'
| 'arrows-cross'
| 'arrows-from-center'
| 'arrows-left-right'
| 'arrows-rotate'
| 'arrows-swap-right'
| 'arrows-switch'
| 'arrows-to-center'
| 'arrows-up-and-left'
| 'arrows-up-and-left-big'
| 'at'
| 'backspace'
| 'bag-percent'
| 'bell'
| 'bolt'
| 'bookmark'
| 'brand-amex'
| 'brand-android'
| 'brand-apple'
| 'brand-bitcoin'
| 'brand-brave'
| 'brand-chrome'
| 'brand-discover'
| 'brand-edge'
| 'brand-firefox'
| 'brand-github'
| 'brand-linux'
| 'brand-mac'
| 'brand-mastercard'
| 'brand-paypal'
| 'brand-proton'
| 'brand-proton-calendar'
| 'brand-proton-drive'
| 'brand-proton-mail'
| 'brand-proton-mail-filled'
| 'brand-proton-mail-filled-plus'
| 'brand-proton-vpn'
| 'brand-reddit'
| 'brand-simple-login'
| 'brand-tor'
| 'brand-twitter'
| 'brand-visa'
| 'brand-windows'
| 'brand-wireguard'
| 'briefcase'
| 'broom'
| 'bug'
| 'buildings'
| 'calendar-cells'
| 'calendar-checkmark'
| 'calendar-grid'
| 'calendar-row'
| 'calendar-today'
| 'camera'
| 'candles-cake'
| 'card-identity'
| 'column-one'
| 'column-two'
| 'checkmark'
| 'checkmark-circle'
| 'checkmark-circle-filled'
| 'checkmark-triple'
| 'chevron-down'
| 'chevron-down-filled'
| 'chevron-left'
| 'chevron-left-filled'
| 'chevron-right'
| 'chevron-right-filled'
| 'chevron-up'
| 'chevron-up-filled'
| 'chevrons-left'
| 'chevrons-right'
| 'circle'
| 'circle-filled'
| 'circle-half-filled'
| 'circle-slash'
| 'clock'
| 'clock-paper-plane'
| 'clock-rotate-left'
| 'cloud'
| 'code'
| 'cog-wheel'
| 'cog-drawer'
| 'credit-card'
| 'credit-card-detailed'
| 'cross'
| 'cross-big'
| 'cross-circle'
| 'cross-circle-filled'
| 'cross-small'
| 'density-low'
| 'density-high'
| 'drive'
| 'earth'
| 'emoji'
| 'envelope'
| 'envelope-arrow-up-and-right'
| 'envelope-cross'
| 'envelope-dot'
| 'envelope-lock'
| 'envelope-magnifying-glass'
| 'envelope-open'
| 'envelope-open-text'
| 'envelopes'
| 'eraser'
| 'exclamation-circle'
| 'exclamation-circle-filled'
| 'exclamation-triangle-filled'
| 'eye'
| 'eye-slash'
| 'file'
| 'file-arrow-in'
| 'file-arrow-in-up'
| 'file-arrow-out'
| 'file-image'
| 'file-lines'
| 'file-pdf'
| 'file-shapes'
| 'filing-cabinet'
| 'filter'
| 'fingerprint'
| 'fire'
| 'fire-slash'
| 'flag-filled'
| 'folder'
| 'folder-arrow-in'
| 'folder-arrow-in-filled'
| 'folder-arrow-up'
| 'folder-filled'
| 'folder-open'
| 'folder-open-filled'
| 'folder-plus'
| 'folders'
| 'folders-filled'
| 'gift'
| 'globe'
| 'grid-2'
| 'grid-3'
| 'hamburger'
| 'heart'
| 'hook'
| 'hourglass'
| 'house'
| 'house-filled'
| 'image'
| 'inbox'
| 'info-circle'
| 'info-circle-filled'
| 'key'
| 'key-history'
| 'key-skeleton'
| 'language'
| 'life-ring'
| 'lightbulb'
| 'lines-long-to-small'
| 'lines-vertical'
| 'link'
| 'link-pen'
| 'link-slash'
| 'list-arrow-up'
| 'list-arrow-down'
| 'list-bullets'
| 'list-numbers'
| 'lock'
| 'lock-check-filled'
| 'lock-exclamation-filled'
| 'lock-filled'
| 'lock-open-check-filled'
| 'lock-open-exclamation-filled'
| 'lock-open-pen-filled'
| 'lock-pen-filled'
| 'locks'
| 'low-dash'
| 'magnifier'
| 'mailbox'
| 'map'
| 'map-pin'
| 'minus'
| 'minus-circle'
| 'mobile'
| 'mobile-plus'
| 'money-bills'
| 'moon'
| 'note'
| 'notepad-checklist'
| 'pass-all-vaults'
| 'pass-atom'
| 'pass-basketball'
| 'pass-bear'
| 'pass-book'
| 'pass-bookmark'
| 'pass-box'
| 'pass-cheque'
| 'pass-circles'
| 'pass-cream'
| 'pass-credit-card'
| 'pass-fire'
| 'pass-fish'
| 'pass-flower'
| 'pass-gift'
| 'pass-group'
| 'pass-heart'
| 'pass-home'
| 'pass-json'
| 'pass-laptop'
| 'pass-leaf'
| 'pass-lock'
| 'pass-mushroom'
| 'pass-pacman'
| 'pass-shield'
| 'pass-shop'
| 'pass-shopping-cart'
| 'pass-smile'
| 'pass-star'
| 'pass-trash'
| 'pass-vault'
| 'pass-wallet'
| 'pass-work'
| 'paint-roller'
| 'palette'
| 'paper-clip'
| 'paper-clip-vertical'
| 'paper-plane'
| 'paper-plane-horizontal'
| 'paper-plane-horizontal-clock'
| 'pause'
| 'pen'
| 'pen-square'
| 'pencil'
| 'phone'
| 'play'
| 'plus'
| 'plus-circle'
| 'plus-circle-filled'
| 'power-off'
| 'presentation-screen'
| 'printer'
| 'question-circle'
| 'question-circle-filled'
| 'robot'
| 'rocket'
| 'servers'
| 'shield'
| 'shield-2'
| 'shield-2-check-filled'
| 'shield-filled'
| 'shield-half-filled'
| 'size-arrow-up'
| 'size-arrow-down'
| 'speech-bubble'
| 'squares'
| 'squares-in-square'
| 'star'
| 'star-filled'
| 'star-slash'
| 'storage'
| 'sun'
| 'switch-off'
| 'switch-on'
| 'switch-on-lock'
| 'tag'
| 'tag-filled'
| 'tag-plus'
| 'tags'
| 'text-align-center'
| 'text-align-justify'
| 'text-align-left'
| 'text-align-right'
| 'text-bold'
| 'text-italic'
| 'text-quote'
| 'text-strikethrough'
| 'text-underline'
| 'three-dots-horizontal'
| 'three-dots-vertical'
| 'trash'
| 'trash-clock'
| 'trash-cross'
| 'trash-cross-filled'
| 'tv'
| 'upgrade'
| 'user'
| 'user-arrow-left'
| 'user-arrow-right'
| 'user-circle'
| 'user-filled'
| 'user-plus'
| 'users'
| 'users-filled'
| 'users-merge'
| 'users-plus'
| 'vault'
| 'wallet'
| 'window-image'
| 'window-maximised'
| 'window-small'
| 'window-terminal'
| 'wrench';
export interface IconProps extends Omit<React.SVGProps<SVGSVGElement>, 'ref'> {
/** Determines which icon to render based on its name */
name: IconName;
/** If specified, renders an sr-only element for screenreaders */
alt?: string;
/** If specified, renders an inline title element */
title?: string;
/** The size of the icon */
size?: IconSize;
/** How many degrees the icon should be rotated */
rotate?: number;
/** Applied as inline css 'color' attribute on the svg element */
color?: string;
/** Icon name prefix */
nameSpaceSvg?: string;
}
const Icon = forwardRef<SVGSVGElement, IconProps>(
({ name, alt, title, color, className = '', viewBox = '0 0 16 16', size = 16, rotate = 0, ...rest }, ref) => {
const style = {
...(color && { color }),
...(rotate && { transform: `rotate(${rotate}deg)` }),
};
return (
<>
<svg
style={style}
viewBox={viewBox}
className={clsx([`icon-${size}p`, className])}
role="img"
focusable="false"
ref={ref}
aria-hidden="true"
{...rest}
>
{title ? <title>{title}</title> : null}
<use xlinkHref={`#ic-${name}`} />
</svg>
{alt ? <span className="sr-only">{alt}</span> : null}
</>
);
}
);
export default Icon;
| 5,401
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/icon/Icons.tsx
|
import svgFiles from '@proton/styles/assets/img/icons/file-icons.svg';
import svg from '@proton/styles/assets/img/icons/sprite-icons.svg';
export const ICONS_ID = 'icons-root';
const Icons = () => <div id={ICONS_ID} dangerouslySetInnerHTML={{ __html: `${svg}${svgFiles}` }} />;
export default Icons;
| 5,402
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/icon/MimeIcon.tsx
|
import { ComponentPropsWithRef, forwardRef } from 'react';
import clsx from '@proton/utils/clsx';
import { IconSize } from './Icon';
export type MimeName =
| 'attachments'
| 'calendar'
| 'doc'
| 'folder'
| 'font'
| 'image'
| 'keynote'
| 'keytrust'
| 'numbers'
| 'pages'
| 'pdf'
| 'ppt'
| 'sound'
| 'text'
| 'unknown'
| 'video'
| 'xls'
| 'xml'
| 'zip';
const viewboxMap = {
sm: 16,
md: 24,
lg: 48,
};
const getIconAsset = (size: IconSize) => {
if (size < 20) {
return 'sm';
}
if (size < 40) {
return 'md';
}
return 'lg';
};
export interface MimeIconProps extends ComponentPropsWithRef<'svg'> {
name: MimeName;
size?: IconSize;
/** If specified, renders an sr-only element for screenreaders */
alt?: string;
/** If specified, renders an inline title element */
title?: string;
}
/**
* Component to render SVG file icons.
* Use it the same way as Icon, just without need to specify name space
* (automatically mime is used), and proper asset is chosen based on the
* passed size parameter: mime icons have three different shapes to fit
* any space the best way.
*/
const MimeIcon = forwardRef<SVGSVGElement, MimeIconProps>(
({ name, size = 16, alt, title, className, ...rest }, ref) => {
const iconAsset = getIconAsset(size);
const viewBox = `0 0 ${viewboxMap[iconAsset]} ${viewboxMap[iconAsset]}`;
return (
<>
<svg
role="img"
viewBox={viewBox}
focusable="false"
className={clsx([`icon-${size}p`, className])}
ref={ref}
{...rest}
>
{title && <title>{title}</title>}
<use xlinkHref={`#mime-${iconAsset}-${name}`} />
</svg>
{alt ? <span className="sr-only">{alt}</span> : null}
</>
);
}
);
export default MimeIcon;
| 5,403
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/icon/PersonalKeyWarningIcon.tsx
|
import { c } from 'ttag';
import { Href } from '@proton/atoms';
import { getKnowledgeBaseUrl } from '@proton/shared/lib/helpers/url';
import WarningIcon from './WarningIcon';
interface Props {
className?: string;
}
// Unlike ContactKeys, PersonalKeys can always encrypt and sign, and never trigger email mismatching warnings, since they are reformatted on import to match the user's address.
// However, if they were created or imported a while ago, they might be considered too weak security-wise.
const PersonalKeyWarningIcon = ({ className }: Props) => {
const warning = c('Weak personal key warning')
.t`This key no longer meets our security standards. We suggest you mark it as obsolete and generate a new key.`;
return (
<Href href={getKnowledgeBaseUrl('/openpgp-keys-security')} className={className}>
<WarningIcon warning={warning} />
</Href>
);
};
export default PersonalKeyWarningIcon;
| 5,404
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/icon/RoundedIcon.tsx
|
import { Ref, forwardRef } from 'react';
import clsx from '@proton/utils/clsx';
import Icon, { IconName } from './Icon';
const TYPES = {
success: 'bg-success',
warning: 'bg-warning',
error: 'bg-danger',
};
interface Props {
iconClassName?: string;
className?: string;
type?: 'success' | 'warning' | 'error';
title?: string;
padding?: string;
name: IconName;
}
const RoundedIcon = (
{ className = '', iconClassName, type = 'success', padding = 'p-2', title, name, ...rest }: Props,
ref: Ref<HTMLSpanElement>
) => {
return (
<span
className={clsx(['inline-flex rounded-50 flex-item-noshrink', className, padding, type && TYPES[type]])}
title={title}
ref={ref}
>
<Icon size={12} className={iconClassName} name={name} {...rest} />
</span>
);
};
export default forwardRef<HTMLSpanElement, Props>(RoundedIcon);
| 5,405
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/icon/TodayIcon.tsx
|
import clsx from '@proton/utils/clsx';
import './_today-icon.scss';
interface Props {
todayDate: number;
className?: string;
}
const TodayIcon = ({ todayDate, className }: Props) => {
return <span className={clsx(['today-icon', className])}>{todayDate}</span>;
};
export default TodayIcon;
| 5,406
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/icon/WarningIcon.tsx
|
import clsx from '@proton/utils/clsx';
import { Tooltip } from '../tooltip';
import Icon from './Icon';
interface Props {
warning: string;
className?: string;
}
const WarningIcon = ({ warning, className }: Props) => {
if (!warning.length) {
return null;
}
const icon = <Icon name="exclamation-circle" className={clsx([className, 'color-warning'])} />;
return <Tooltip title={warning}>{icon}</Tooltip>;
};
export default WarningIcon;
| 5,407
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/icon/_today-icon.scss
|
@import '~@proton/styles/scss/lib';
.today-icon {
font-weight: var(--font-weight-bold);
border: 1px solid currentcolor;
border-radius: var(--border-radius-sm);
display: inline-flex;
align-items: center;
justify-content: center;
font-size: rem(8);
inline-size: rem(16);
block-size: rem(16);
line-height: 1;
}
| 5,408
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/icon/index.ts
|
export { default as Icon } from './Icon';
export * from './Icon';
export { default as RoundedIcon } from './RoundedIcon';
export { default as Icons } from './Icons';
export { default as MimeIcon } from './MimeIcon';
export { default as ContactKeyWarningIcon } from './ContactKeyWarningIcon';
export { default as TodayIcon } from './TodayIcon';
| 5,409
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/iconRow/IconRow.tsx
|
import { ReactElement, ReactNode } from 'react';
import { Icon, IconName, Label } from '@proton/components';
import { Tooltip } from '../tooltip';
export interface IconRowProps {
className?: string;
children: ReactNode;
icon?: ReactElement | IconName;
iconColor?: string;
iconClassName?: string;
labelClassName?: string;
title?: string;
id?: string;
}
const IconRow = ({
children,
icon,
iconColor,
className,
title,
iconClassName,
labelClassName = 'pb-2',
id,
}: IconRowProps) => {
const getIcon = () => {
if (!title && !icon) {
return null;
}
if (!icon) {
return (
<>
<span className="sr-only">{title}</span>
</>
);
}
if (typeof icon === 'string') {
return <Icon name={icon} className={iconClassName} alt={title} color={iconColor} />;
}
return <span>{icon}</span>;
};
const iconResult = getIcon();
return (
<div className="flex flex-nowrap flex-align-items-start mb-4 form--icon-labels">
{!!iconResult && (
<Label className={labelClassName} htmlFor={id}>
<Tooltip title={title}>{iconResult}</Tooltip>
</Label>
)}
<div className={className || 'flex-item-fluid'}>{children}</div>
</div>
);
};
export default IconRow;
| 5,410
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/iconRow/MemoizedIconRow.tsx
|
import { memo } from 'react';
import IconRow, { IconRowProps } from './IconRow';
const MemoizedIconRow = (props: IconRowProps) => IconRow(props);
export default memo(MemoizedIconRow);
| 5,411
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/iconRow/index.ts
|
export { default as IconRow } from './IconRow';
export { default as MemoizedIconRow } from './MemoizedIconRow';
| 5,412
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/image/QRCode.tsx
|
import { ComponentPropsWithoutRef, forwardRef } from 'react';
import QRCodeReact from 'qrcode.react';
import clsx from '@proton/utils/clsx';
interface Props extends ComponentPropsWithoutRef<'svg'> {
size?: number;
value: string;
}
const QRCode = forwardRef<SVGElement, Props>(({ size = 200, className, ...rest }: Props, ref) => {
return (
<QRCodeReact
className={clsx(['qr-code', className])}
size={size}
includeMargin={false}
ref={ref as any}
{...rest}
renderAs="svg"
/>
);
});
export default QRCode;
| 5,413
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/image/RemoteImage.tsx
|
import { DetailedHTMLProps, ImgHTMLAttributes, useEffect } from 'react';
import { c } from 'ttag';
import { Button } from '@proton/atoms';
import { Icon, Tooltip } from '@proton/components/components';
import LoadRemoteImageBanner from '../../containers/banner/LoadRemoteImageBanner';
import useLoadContactImage from '../../hooks/useLoadContactImage';
import { Loader } from '../loader';
export interface Props extends DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement> {
src: string;
text?: string;
/**
* Force loading the image on component render
*/
autoLoad?: boolean;
}
const RemoteImage = ({ src, text = c('Action').t`Load image`, autoLoad = false, ...rest }: Props) => {
const { handleLoadImageDirect, image, setShowAnyway, display } = useLoadContactImage({
photo: src,
});
const handleClick = () => setShowAnyway(true);
/**
* Should be only used in ContactFieldImage, to show it directly
* In other cases, we want to rely on the auto show setting
*/
useEffect(() => {
if (autoLoad) {
handleClick();
}
}, [autoLoad]);
return (
<>
{display === 'loading' && <Loader />}
{display === 'loadDirectFailed' && (
<div className="border rounded bg-norm mb-0 flex flex-justify-center flex-align-items-center p-4">
<Tooltip title={c('Tooltip').t`The image could not be loaded`}>
<Icon name="cross-circle" size={24} className="color-danger" />
</Tooltip>
</div>
)}
{display === 'needsLoadDirect' && (
<LoadRemoteImageBanner
onClick={handleLoadImageDirect}
text={c('Action').t`Image could not be loaded with tracker protection.`}
tooltip={c('Action').t`Image will be loaded without a proxy`}
actionText={c('Action').t`Load`}
/>
)}
{display === 'loaded' && <img src={image?.src} alt="" referrerPolicy="no-referrer" {...rest} />}
{display === 'askLoading' && <Button onClick={handleClick}>{text}</Button>}
</>
);
};
export default RemoteImage;
| 5,414
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/image/index.ts
|
export { default as RemoteImage } from './RemoteImage';
export { default as QRCode } from './QRCode';
| 5,415
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/Checkbox.tsx
|
import { InputHTMLAttributes, LabelHTMLAttributes, Ref, forwardRef, useEffect, useRef } from 'react';
import { useCombinedRefs } from '@proton/hooks';
import clsx from '@proton/utils/clsx';
import Icon from '../icon/Icon';
export interface CheckboxProps extends InputHTMLAttributes<HTMLInputElement> {
/**
* Interactions will be blocked while loading is true
*/
loading?: boolean;
/**
* Background color can be set using a css color (e.g. #ff0000 or rgb(255, 0, 0))
*/
backgroundColor?: string;
/**
* Border color can be set using a css color (e.g. #ff0000 or rgb(255, 0, 0))
*/
borderColor?: string;
/**
* Color can be set using a css color (e.g. #ff0000 or rgb(255, 0, 0))
*/
color?: string;
indeterminate?: boolean;
labelOnClick?: (event: React.MouseEvent<HTMLLabelElement, MouseEvent>) => void;
labelProps?: LabelHTMLAttributes<HTMLLabelElement> & { 'data-testid': string };
}
const Checkbox = (
{
id,
className,
title,
loading,
disabled,
checked,
indeterminate = false,
color,
backgroundColor,
borderColor,
children,
labelOnClick,
labelProps,
...rest
}: CheckboxProps,
ref: Ref<HTMLInputElement>
) => {
const inputRef = useRef<HTMLInputElement>(null);
const combinedRef = useCombinedRefs(inputRef, ref);
useEffect(() => {
if (inputRef.current) {
inputRef.current.indeterminate = indeterminate;
}
}, [indeterminate]);
return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
<label
{...labelProps}
htmlFor={id}
className={clsx(
'checkbox-container',
!className?.includes('increase-click-surface') && 'relative',
className
)}
title={title}
onClick={labelOnClick}
>
<input
ref={combinedRef}
disabled={disabled || loading}
id={id}
type="checkbox"
className="checkbox-input"
checked={checked}
{...rest}
/>
<span
className={clsx('checkbox-fakecheck', children ? 'mr-2' : '')}
style={{ borderColor, background: backgroundColor, color }}
>
{indeterminate === false ? (
<Icon className="checkbox-fakecheck-img" size={16} name="checkmark" color={color} />
) : (
<Icon className="checkbox-fakecheck-img color-disabled" size={16} name="minus" />
)}
</span>
{children}
</label>
);
};
export default forwardRef<HTMLInputElement, CheckboxProps>(Checkbox);
| 5,416
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/ColorPicker.tsx
|
import { useState } from 'react';
import tinycolor from 'tinycolor2';
import { ACCENT_COLORS_MAP, getColorName } from '@proton/shared/lib/colors';
import { omit } from '@proton/shared/lib/helpers/object';
import clsx from '@proton/utils/clsx';
import { generateUID } from '../../helpers';
import ColorSelector from '../color/ColorSelector';
import { Dropdown, DropdownButton, DropdownSizeUnit } from '../dropdown';
import { DropdownButtonProps } from '../dropdown/DropdownButton';
import { Icon } from '../icon';
import { usePopperAnchor } from '../popper';
interface OwnProps {
color?: string;
onChange: (color: string) => void;
}
type ButtonProps = DropdownButtonProps<'button'>;
export type Props =
| ({ layout: 'inline' } & OwnProps)
| ({ layout?: 'dropdown' } & OwnProps & Omit<ButtonProps, 'onChange' | 'as'>);
const getOptions = () => {
return Object.values(ACCENT_COLORS_MAP).map(({ color, getName }) => ({ value: color, label: getName() }));
};
const ColorPicker = ({ color = '#5252CC', onChange, ...rest }: Props) => {
const options = getOptions();
const [uid] = useState(generateUID('dropdown'));
const { anchorRef, isOpen, toggle, close } = usePopperAnchor<HTMLButtonElement>();
if (rest.layout === 'inline') {
return <ColorSelector selected={color} onChange={onChange} colors={options} inline />;
}
const colorModel = tinycolor(color);
const iconColor = colorModel.isValid() ? colorModel.toHexString() : '';
const colorName = getColorName(color);
const { className, ...restDropdownProps } = omit(rest, ['layout']);
return (
<>
<DropdownButton
{...restDropdownProps}
as="button"
type="button"
className={clsx([className, 'field select w-1/2 flex flex-align-items-center py-0 pl-2'])}
hasCaret
ref={anchorRef}
isOpen={isOpen}
onClick={toggle}
aria-label={colorName}
>
<span className="flex-item-fluid text-left flex flex-nowrap flex-align-items-center gap-2">
<Icon className="flex-item-noshrink" name="circle-filled" size={28} color={iconColor} />
{colorName && <span className="text-capitalize text-ellipsis">{colorName}</span>}
</span>
</DropdownButton>
<Dropdown
id={uid}
isOpen={isOpen}
size={{ maxWidth: DropdownSizeUnit.Viewport, maxHeight: DropdownSizeUnit.Viewport }}
anchorRef={anchorRef}
onClose={close}
disableDefaultArrowNavigation
>
<ColorSelector selected={color} onChange={onChange} colors={options} className="p-4" />
</Dropdown>
</>
);
};
export default ColorPicker;
| 5,417
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/DateInput.tsx
|
import { ChangeEvent, FocusEvent, useEffect, useMemo, useState } from 'react';
import { Locale, addDays, format, parse } from 'date-fns';
import { c } from 'ttag';
import { dateLocale } from '@proton/shared/lib/i18n';
import { generateUID } from '../../helpers';
import { useHotkeys } from '../../hooks';
import Dropdown from '../dropdown/Dropdown';
import LocalizedMiniCalendar from '../miniCalendar/LocalizedMiniCalendar';
import { usePopperAnchor } from '../popper';
import Input, { Props as InputProps } from './Input';
const toFormatted = (value: Date, locale: Locale) => {
return format(value, 'PP', { locale });
};
const fromFormatted = (value: string, locale: Locale) => {
return parse(value, 'PP', new Date(), { locale });
};
const getTemporaryInputFromValue = (value: Date | undefined) => {
return value ? toFormatted(value, dateLocale) : '';
};
const DEFAULT_MIN = new Date(1900, 0, 1);
const DEFAULT_MAX = new Date(2200, 0, 1);
interface Props extends Omit<InputProps, 'min' | 'max' | 'value' | 'onChange'> {
displayWeekNumbers?: boolean;
weekStartsOn?: 0 | 2 | 1 | 6 | 5 | 4 | 3;
value?: Date;
placeholder?: string;
defaultDate?: Date;
min?: Date;
max?: Date;
onChange: (value: Date | undefined) => void;
// In some cases we want to prevent the 'reset' of the value, if value > max or < min
preventValueReset?: boolean;
fromFormatter?: (value: string, locale: Locale) => Date;
toFormatter?: (value: Date, locale: Locale) => string;
hasToday?: boolean;
}
const DateInput = ({
value,
defaultDate,
placeholder,
autoFocus,
onChange,
onFocus,
onBlur,
displayWeekNumbers,
weekStartsOn,
min = DEFAULT_MIN,
max = DEFAULT_MAX,
preventValueReset = false,
fromFormatter = fromFormatted,
toFormatter = toFormatted,
hasToday = true,
...rest
}: Props) => {
const [uid] = useState(generateUID('dropdown'));
const { anchorRef, isOpen, open, close } = usePopperAnchor<HTMLInputElement>();
const [temporaryInput, setTemporaryInput] = useState<string>('');
const [showTemporary, setShowTemporary] = useState<boolean>(false);
useEffect(() => {
setTemporaryInput(getTemporaryInputFromValue(value));
}, [value ? +value : undefined]);
const currentInput = useMemo(() => {
return value ? toFormatter(value, dateLocale) : '';
}, [value ? +value : undefined]);
const temporaryValue = useMemo(() => {
if (!temporaryInput) {
return;
}
try {
const newDate = fromFormatter(temporaryInput, dateLocale);
if (newDate < min || newDate > max) {
/* There are some cases where we do not want to reset the value so that we are able to tell the user
* he made a mistake, by displaying an error.
*/
if (preventValueReset) {
return newDate;
}
return;
}
if (Number.isNaN(+newDate)) {
return;
}
return newDate;
// eslint-disable-next-line no-empty
} catch (e: any) {}
}, [temporaryInput]);
const actualDefaultDate = useMemo(() => defaultDate || new Date(), [defaultDate]);
const actualValue = temporaryValue || value || actualDefaultDate;
const parseAndTriggerChange = () => {
const oldTemporaryInput = temporaryInput;
// Before the new date is set, the input is reset to the old date in case the onChange handler rejects the change,
// or it's an invalid date that couldn't be parsed
setTemporaryInput(getTemporaryInputFromValue(value));
// Allow a valid parsed date value, or undefined to reset.
if (temporaryValue || !oldTemporaryInput) {
onChange(temporaryValue);
}
};
const handleFocusInput = (event: FocusEvent<HTMLInputElement>) => {
onFocus?.(event);
open();
setShowTemporary(true);
setTemporaryInput(currentInput);
};
const handleBlurInput = (event: FocusEvent<HTMLInputElement>) => {
onBlur?.(event);
parseAndTriggerChange();
close();
setShowTemporary(false);
setTemporaryInput('');
};
useHotkeys(anchorRef, [
[
'Escape',
(e) => {
if (isOpen) {
e.preventDefault();
e.stopPropagation();
parseAndTriggerChange();
close();
}
},
],
[
'Enter',
(e) => {
parseAndTriggerChange();
if (isOpen) {
e.preventDefault();
e.stopPropagation();
close();
} else {
e.preventDefault();
e.stopPropagation();
open();
}
},
],
[
'ArrowDown',
(e) => {
if (isOpen) {
e.preventDefault();
e.stopPropagation();
setTemporaryInput(toFormatted(addDays(actualValue, -1), dateLocale));
}
},
],
[
'ArrowUp',
(e) => {
if (isOpen) {
e.preventDefault();
e.stopPropagation();
setTemporaryInput(toFormatted(addDays(actualValue, 1), dateLocale));
}
},
],
]);
const handleClickDate = (newDate: Date) => {
setTemporaryInput(toFormatted(newDate, dateLocale));
setTimeout(() => anchorRef.current?.blur());
};
const handleInputChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) => {
setTemporaryInput(value);
};
const placeholderInLocale = useMemo(() => {
return toFormatted(actualDefaultDate, dateLocale);
}, [dateLocale, defaultDate]);
return (
<>
<Input
type="text"
ref={anchorRef}
onFocus={handleFocusInput}
onBlur={handleBlurInput}
value={showTemporary ? temporaryInput : currentInput}
onChange={handleInputChange}
placeholder={
placeholder !== undefined ? placeholder : `${c('Placeholder').t`E.g., `}${placeholderInLocale}`
}
autoFocus={autoFocus}
{...rest}
/>
<Dropdown
disableFocusTrap
autoClose={false}
autoCloseOutside={false}
id={uid}
isOpen={isOpen}
anchorRef={anchorRef}
onClose={close}
disableDefaultArrowNavigation
>
<LocalizedMiniCalendar
date={actualValue}
min={min}
max={max}
onSelectDate={handleClickDate}
displayWeekNumbers={displayWeekNumbers}
weekStartsOn={weekStartsOn}
fixedSize
hasToday={hasToday}
preventLeaveFocus
/>
</Dropdown>
</>
);
};
export default DateInput;
| 5,418
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/EmailInput.tsx
|
import { c } from 'ttag';
import { EMAIL_PLACEHOLDER } from '@proton/shared/lib/constants';
import { validateEmailAddress } from '@proton/shared/lib/helpers/email';
import Input, { Props } from './Input';
const EmailInput = ({ value = '', ...rest }: Props) => {
const error = value ? (validateEmailAddress(value as string) ? '' : c('Error').t`Invalid email address`) : '';
return <Input type="email" error={error} placeholder={EMAIL_PLACEHOLDER} value={value} {...rest} />;
};
export default EmailInput;
| 5,419
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/EmojiScale.scss
|
@import '~@proton/styles/scss/lib';
.emoji-scale {
&_input-button {
&#{&} {
inline-size: em(52);
block-size: em(52);
padding: 0;
display: flex;
}
}
}
| 5,420
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/EmojiScale.tsx
|
import { ChangeEvent, ComponentPropsWithoutRef } from 'react';
import { c } from 'ttag';
import emojiAwful from '@proton/styles/assets/img/emojis/emoji-awful.svg';
import emojiBad from '@proton/styles/assets/img/emojis/emoji-bad.svg';
import emojiGood from '@proton/styles/assets/img/emojis/emoji-good.svg';
import emojiOk from '@proton/styles/assets/img/emojis/emoji-ok.svg';
import emojiWonderful from '@proton/styles/assets/img/emojis/emoji-wonderful.svg';
import clsx from '@proton/utils/clsx';
import { Tooltip } from '../tooltip';
import InputButton, { InputButtonProps } from './InputButton';
import ScaleLabel from './ScaleLabel';
import './EmojiScale.scss';
export interface EmojiScaleProps extends Omit<ComponentPropsWithoutRef<'div'>, 'onChange'> {
fromLabel: string;
toLabel: string;
value?: number;
InputButtonProps?: Partial<InputButtonProps>;
onChange: (value: number) => void;
}
const scale = [
{ value: 1, emoji: emojiAwful, label: () => c('Label').t`Awful` },
{ value: 2, emoji: emojiBad, label: () => c('Label').t`Bad` },
{ value: 3, emoji: emojiOk, label: () => c('Label').t`OK` },
{ value: 4, emoji: emojiGood, label: () => c('Label').t`Good` },
{ value: 5, emoji: emojiWonderful, label: () => c('Label').t`Wonderful` },
];
const EmojiScale = ({ fromLabel, toLabel, value, InputButtonProps, onChange, className, ...rest }: EmojiScaleProps) => {
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
onChange(Number(e.target.value));
};
return (
<div className={clsx([className, 'flex flex-column gap-4'])} {...rest}>
<div className="flex flex-justify-space-between flex-align-items-center">
{scale.map((option) => (
<Tooltip title={option.label()} key={option.value}>
<span>
<InputButton
id={`score-${option.value}`}
name="score"
type="radio"
value={option.value}
checked={value === option.value}
onChange={handleChange}
ButtonLikeProps={{ className: 'emoji-scale_input-button' }}
{...InputButtonProps}
>
<img src={option.emoji} alt={option.label()} aria-hidden="true" />
<span className="sr-only">{option.label()}</span>
</InputButton>
</span>
</Tooltip>
))}
</div>
<ScaleLabel fromLabel={fromLabel} toLabel={toLabel} />
</div>
);
};
export default EmojiScale;
| 5,421
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/FileInput.test.js
|
import { fireEvent, render } from '@testing-library/react';
import FileInput from './FileInput';
describe('FileInput component', () => {
const value = 'panda';
const file = new File(['(⌐□_□)'], 'chucknorris.png', { type: 'image/png' });
it('should render a file input and wrap children', () => {
const { container } = render(<FileInput>{value}</FileInput>);
const inputNode = container.querySelector('input');
expect(inputNode).not.toBe(null);
expect(inputNode.getAttribute('type')).toBe('file');
expect(container.textContent).toBe(value);
});
it('should upload a file', () => {
const mockOnChange = jest.fn(({ target }) => [...target.files]);
const { container } = render(<FileInput onChange={mockOnChange}>{value}</FileInput>);
const inputNode = container.querySelector('input');
Object.defineProperty(inputNode, 'files', { value: [file] });
fireEvent.change(inputNode);
expect(mockOnChange).toHaveBeenCalledTimes(1);
expect(mockOnChange.mock.results[0].value[0]).toBe(file);
});
});
| 5,422
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/FileInput.tsx
|
import { ChangeEvent, DetailedHTMLProps, InputHTMLAttributes, ReactNode, Ref, forwardRef, useRef } from 'react';
import { ButtonLike, ButtonLikeShape } from '@proton/atoms';
import { ThemeColorUnion } from '@proton/colors';
import { useCombinedRefs } from '@proton/hooks';
import clsx from '@proton/utils/clsx';
export interface Props extends DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
children: ReactNode;
id?: string;
className?: string;
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
disabled?: boolean;
shape?: ButtonLikeShape;
color?: ThemeColorUnion;
loading?: boolean;
}
const FileInput = (
{ children, id = 'fileInput', className, onChange, disabled, shape, color, loading, ...rest }: Props,
ref: Ref<HTMLInputElement>
) => {
const inputRef = useRef<HTMLInputElement>(null);
const combinedRef = useCombinedRefs(inputRef, ref);
return (
<ButtonLike
as="label"
htmlFor={id}
className={clsx(className, 'relative')}
disabled={disabled}
shape={shape}
color={color}
loading={loading}
>
<input
id={id}
type="file"
className="sr-only"
onChange={(e) => {
onChange(e);
if (inputRef.current) {
// Reset it to allow to select the same file again.
inputRef.current.value = '';
}
}}
{...rest}
ref={combinedRef}
/>
{children}
</ButtonLike>
);
};
export default forwardRef<HTMLInputElement, Props>(FileInput);
| 5,423
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/Input.test.js
|
import { fireEvent, render } from '@testing-library/react';
import Input from './Input';
describe('Input component', () => {
const value = 'panda';
const error = 'hahaha';
it('should display an input', () => {
const { container } = render(<Input value={value} />);
const inputNode = container.querySelector('input');
expect(inputNode).not.toBe(null);
expect(inputNode.value).toBe(value);
});
it('should display an error', () => {
const { container } = render(<Input value={value} error={error} isSubmitted />);
const inputNode = container.querySelector('input');
const errorZoneNode = container.querySelector('.error-zone');
const uid = inputNode.getAttribute('aria-describedby');
expect(uid).not.toBe(null);
expect(errorZoneNode).not.toBe(null);
fireEvent.change(inputNode, { target: { value: 'bar' } });
expect(errorZoneNode.textContent).toBe(error);
});
});
| 5,424
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/Input.tsx
|
import {
DetailedHTMLProps,
InputHTMLAttributes,
KeyboardEventHandler,
ReactElement,
ReactNode,
Ref,
cloneElement,
forwardRef,
useState,
} from 'react';
import { c } from 'ttag';
import clsx from '@proton/utils/clsx';
import { generateUID } from '../../helpers';
import Icon from '../icon/Icon';
import ErrorZone from '../text/ErrorZone';
import useInput from './useInput';
export interface Props extends DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
ref?: Ref<HTMLInputElement>; // override ref so that LegacyRef isn't used
containerRef?: Ref<HTMLDivElement>;
icon?: ReactElement;
iconSearchDisplayed?: boolean;
error?: string;
errorZoneClassName?: string;
autoComplete?: string;
className?: string;
onPressEnter?: KeyboardEventHandler<HTMLInputElement>;
isSubmitted?: boolean;
loading?: boolean;
}
/**
* @deprecated please use Input from @proton/atoms or InputFieldTwo instead
*/
const Input = forwardRef<HTMLInputElement, Props>(
(
{
containerRef,
icon,
error,
errorZoneClassName,
autoComplete = 'off',
className = '',
type = 'text',
iconSearchDisplayed = true,
onPressEnter,
isSubmitted,
loading = false,
required = false,
id,
placeholder,
value,
...rest
},
ref
) => {
const { handlers, statusClasses, status } = useInput<HTMLInputElement>({ onPressEnter, ...rest });
const [uid] = useState(generateUID('input'));
const errorZone = required && !value && value !== 0 && !error ? c('Error').t`This field is required` : error;
const hasError = !!(errorZone && (status.isDirty || isSubmitted));
const addIconWrapper = (child: ReactNode) => {
if (type === 'search' && iconSearchDisplayed) {
return (
<div
ref={containerRef}
className={clsx(['relative flex', hasError && 'field-icon-container--invalid'])}
>
<Icon name="magnifier" className="absolute no-pointer-events left-icon" />
{child}
</div>
);
}
if (!icon) {
return child;
}
return (
<div
ref={containerRef}
className={clsx([
'relative field-icon-container w-full',
hasError && 'field-icon-container--invalid',
])}
>
{child}
{cloneElement(icon, {
className: clsx([icon.props.className, 'right-icon absolute flex']),
})}
</div>
);
};
return (
<>
{id && placeholder ? (
<label className="sr-only" htmlFor={id}>
{placeholder}
</label>
) : null}
{addIconWrapper(
<input
className={clsx(['field w-full', className, statusClasses])}
aria-invalid={hasError}
aria-describedby={uid}
id={id}
ref={ref}
type={type}
value={value}
placeholder={placeholder}
autoComplete={autoComplete}
disabled={loading || rest.disabled}
required={required}
{...rest}
{...handlers}
/>
)}
{hasError && (
<ErrorZone className={errorZoneClassName} id={uid}>
{errorZone}
</ErrorZone>
)}
</>
);
}
);
export default Input;
| 5,425
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/InputButton.tsx
|
import { ComponentPropsWithoutRef } from 'react';
import { ButtonLike, ButtonLikeProps as TButtonLikeProps } from '@proton/atoms';
import clsx from '@proton/utils/clsx';
export interface InputButtonProps extends ComponentPropsWithoutRef<'input'> {
id?: string;
type?: 'checkbox' | 'radio';
title?: string;
checked?: boolean;
labelProps?: ComponentPropsWithoutRef<'label'>;
ButtonLikeProps?: TButtonLikeProps<'span'>;
}
const InputButton = ({
id,
title,
checked,
children,
type = 'checkbox',
labelProps = {},
ButtonLikeProps = {},
...rest
}: InputButtonProps) => {
const { className: labelClassNameProp, ...labelPropsRest } = labelProps;
const labelClassName = clsx(['inline-flex relative', labelClassNameProp]);
return (
<label htmlFor={id} title={title} className={labelClassName} {...labelPropsRest}>
<input id={id} type={type} className="input-button-input sr-only" checked={checked} {...rest} />
<ButtonLike
as="span"
{...ButtonLikeProps}
className={clsx([
'input-button flex flex-justify-center flex-item-noshrink rounded-50',
ButtonLikeProps.className,
])}
>
{children}
</ButtonLike>
</label>
);
};
export default InputButton;
| 5,426
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/IntegerInput.tsx
|
import { ChangeEvent } from 'react';
import Input, { Props as InputProps } from './Input';
interface Props extends Omit<InputProps, 'onChange' | 'value' | 'min' | 'max'> {
max?: number;
min?: number;
value: number | undefined;
onChange: (value: number | undefined) => void;
step?: number;
}
/**
* Small helper to transform a string or a number into a string
* For other type of arguments, return undefined
*/
const toString = (x: any) => (['number', 'string'].includes(typeof x) ? `${x}` : undefined);
const IntegerInput = ({ value, onChange, max, min, step, ...rest }: Props) => {
const minStr = toString(min);
const maxStr = toString(max);
const stepStr = toString(step) || '1';
const intValue = parseInt(`${value}`, 10);
return (
<Input
type="number"
step={stepStr}
min={minStr}
max={maxStr}
value={value === null || Number.isNaN(intValue) ? '' : intValue}
onInput={({ target, target: { value: newValue, validity } }: ChangeEvent<HTMLInputElement>) => {
const isClear = validity.valid;
// Prevent broken input on certain browsers since it allows to enter other characters than integer numbers
if (newValue === '') {
const emptyOrOldValue = isClear ? undefined : value;
target.value = `${emptyOrOldValue || ''}`;
return onChange(emptyOrOldValue);
}
const newIntValue = parseInt(newValue, 10);
if (
Number.isNaN(newIntValue) ||
(minStr && newIntValue < +minStr) ||
(maxStr && newIntValue > +maxStr)
) {
target.value = `${intValue}`;
return;
}
target.value = `${newIntValue}`;
onChange(newIntValue);
}}
{...rest}
/>
);
};
export default IntegerInput;
| 5,427
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/LayoutCard.scss
|
@import '~@proton/styles/scss/lib';
.layout-card {
&-button {
&#{&} {
background-color: transparent;
}
}
&-image {
inline-size: rem(149);
}
}
| 5,428
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/LayoutCard.tsx
|
import { c } from 'ttag';
import { Button } from '@proton/atoms';
import clsx from '@proton/utils/clsx';
import './LayoutCard.scss';
// just for proper sizing when zooming
export interface LayoutCardProps {
label: string;
src: string;
selected: boolean;
onChange: () => void;
disabled?: boolean;
describedByID: string;
}
const LayoutCard = ({ label, src, selected, onChange, disabled, describedByID }: LayoutCardProps) => {
return (
<Button
name="layoutCard"
shape="outline"
color={selected ? 'norm' : 'weak'}
className={clsx(['mr-4 mb-4 layout-card-button', selected && 'is-active no-pointer-events text-bold'])}
aria-pressed={selected}
onClick={onChange}
disabled={disabled}
type="button"
aria-label={c('Action').t`Use “${label}” setting`}
title={c('Action').t`Use “${label}” setting`}
aria-describedby={describedByID}
data-testid={`layout:${label}`}
>
<span className="flex flex-nowrap flex-column">
<img alt="" src={src} className="mb-2 layout-card-image on-rtl-mirror" width={122} height={78} />
<span>{label}</span>
</span>
</Button>
);
};
export default LayoutCard;
| 5,429
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/LayoutCards.tsx
|
import clsx from '@proton/utils/clsx';
import LayoutCard, { LayoutCardProps } from './LayoutCard';
interface Props {
list: LayoutCardProps[];
className?: string;
liClassName?: string;
describedByID: string;
}
const LayoutCards = ({ list = [], className, liClassName, describedByID }: Props) => {
return (
<ul className={clsx(['unstyled m-0 flex', className])}>
{list.map(({ selected, label, src, onChange, disabled }, index) => {
return (
<li className={liClassName} key={label}>
<LayoutCard
key={index.toString()}
selected={selected}
label={label}
src={src}
onChange={onChange}
disabled={disabled}
describedByID={describedByID}
/>
</li>
);
})}
</ul>
);
};
export default LayoutCards;
| 5,430
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/LegacyInputField.tsx
|
import { ReactNode } from 'react';
import clsx from '@proton/utils/clsx';
interface Props {
label: ReactNode;
input: ReactNode;
className?: string;
}
const LegacyInputField = ({ label, input, className }: Props) => {
return (
<div className={clsx(['flex on-mobile-flex-column signup-label-field-container mb-4', className])}>
{label}
<div className="flex-item-fluid">{input}</div>
</div>
);
};
export default LegacyInputField;
| 5,431
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/PasswordInput.test.js
|
import { fireEvent, render } from '@testing-library/react';
import PasswordInput from './PasswordInput';
describe('PasswordInput component', () => {
const value = 'panda';
it('should display a password input with a toggle button', () => {
const { container } = render(<PasswordInput value={value} />);
const inputNode = container.querySelector('input');
const buttonNode = container.querySelector('button');
expect(inputNode).not.toBe(null);
expect(buttonNode).not.toBe(null);
expect(inputNode.getAttribute('type')).toBe('password');
});
it('should display the password', () => {
const { container } = render(<PasswordInput value={value} />);
const inputNode = container.querySelector('input');
const buttonNode = container.querySelector('button');
fireEvent.click(buttonNode);
expect(inputNode.getAttribute('type')).toBe('text');
});
it('should disable input and button', () => {
const { container } = render(<PasswordInput disabled />);
const inputNode = container.querySelector('input');
const buttonNode = container.querySelector('button');
expect(inputNode).toHaveAttribute('disabled');
expect(buttonNode).toHaveAttribute('disabled');
});
});
| 5,432
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/PasswordInput.tsx
|
import { useState } from 'react';
import { c } from 'ttag';
import Icon from '../icon/Icon';
import Input, { Props } from './Input';
/**
* @deprecated please use PasswordInputTwo instead
*/
const PasswordInput = ({ disabled = false, ...rest }: Props) => {
const [type, setType] = useState('password');
const toggle = () => {
setType(type === 'password' ? 'text' : 'password');
};
return (
<Input
type={type}
disabled={disabled}
icon={
<button
title={type === 'password' ? c('Label').t`Reveal password` : c('Label').t`Hide password`}
className="inline-flex flex-item-noshrink"
tabIndex={-1}
disabled={disabled}
type="button"
onClick={toggle}
>
<Icon className="m-auto" name={type === 'password' ? 'eye' : 'eye-slash'} />
</button>
}
{...rest}
autoCapitalize="off"
autoCorrect="off"
spellCheck="false"
/>
);
};
export default PasswordInput;
| 5,433
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/Radio.tsx
|
import { InputHTMLAttributes } from 'react';
import clsx from '@proton/utils/clsx';
export interface Props extends InputHTMLAttributes<HTMLInputElement> {
id: string;
className?: string;
name: string;
disabled?: boolean;
}
const Radio = ({ id, children, className = 'inline-flex', name, disabled = false, ...rest }: Props) => (
<label
htmlFor={id}
className={clsx([
!className?.includes('increase-click-surface') && 'relative',
disabled && 'opacity-50 no-pointer-events',
className,
])}
>
<input id={id} type="radio" className="radio" name={name} disabled={disabled} {...rest} />
<span className={clsx('radio-fakeradio flex-item-noshrink', children ? 'mr-2' : '')} />
{children}
</label>
);
export default Radio;
| 5,434
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/RadioGroup.tsx
|
import { Key, ReactNode } from 'react';
import clsx from '@proton/utils/clsx';
import Radio from './Radio';
export interface Props<T> {
name: string;
options: {
key?: Key;
value: T;
label: ReactNode;
disabled?: boolean;
}[];
onChange: (value: T) => void;
value: T;
className?: string;
['aria-describedby']?: string;
}
const RadioGroup = <T,>({
name,
options,
onChange,
value,
className,
'aria-describedby': ariaDescribedBy,
}: Props<T>) => {
return (
<>
{options.map((option, i) => (
<Radio
key={option.key || `${i}`}
id={`radio_${i}`}
onChange={() => onChange(option.value)}
checked={value === option.value}
name={name}
className={clsx(['mr-8', 'mb-2', 'flex', 'inline-flex-vcenter', className])}
disabled={option.disabled}
aria-describedby={ariaDescribedBy}
>
{option.label}
</Radio>
))}
</>
);
};
export default RadioGroup;
| 5,435
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/Scale.tsx
|
import { ChangeEvent, ComponentPropsWithoutRef } from 'react';
import clsx from '@proton/utils/clsx';
import range from '@proton/utils/range';
import { concatStringProp } from '../../helpers';
import useUid from '../../hooks/useUid';
import InputButton, { InputButtonProps } from './InputButton';
import ScaleLabel from './ScaleLabel';
export interface ScaleProps extends Omit<ComponentPropsWithoutRef<'div'>, 'onChange'> {
from: number;
to: number;
fromLabel: string;
toLabel: string;
value?: number;
InputButtonProps?: Partial<InputButtonProps>;
onChange: (value: number) => void;
className?: string;
}
const Scale = ({ from, to, fromLabel, toLabel, value, InputButtonProps, onChange, className, ...rest }: ScaleProps) => {
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
onChange(Number(e.target.value));
};
const scale = range(from, to + 1);
const scaleId = useUid('scale');
const scaleFromToId = useUid('scale-from-to');
const ariaDescribedBy = concatStringProp([InputButtonProps?.['aria-describedby'], scaleFromToId]);
return (
<div className={clsx([className, 'inline-flex flex-column gap-4'])} {...rest}>
<div className="flex flex-justify-start flex-align-items-center gap-4">
{scale.map((n) => (
<InputButton
key={n}
id={`${scaleId}-${n}`}
name={scaleId}
type="radio"
value={n}
title={String(n)}
checked={value === n}
onChange={handleChange}
{...InputButtonProps}
aria-describedby={ariaDescribedBy}
>
{n}
</InputButton>
))}
</div>
<ScaleLabel id={scaleFromToId} fromLabel={fromLabel} toLabel={toLabel} />
</div>
);
};
export default Scale;
| 5,436
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/ScaleLabel.tsx
|
import { ComponentPropsWithRef } from 'react';
interface ScaleLabelProps extends ComponentPropsWithRef<'div'> {
fromLabel: string;
toLabel: string;
}
const ScaleLabel = ({ fromLabel, toLabel, ...rest }: ScaleLabelProps) => {
return (
<div className="flex flex-justify-space-between flex-align-items-start gap-4" {...rest}>
<span className="text-sm m-0">{fromLabel}</span>
<span className="text-sm m-0">{toLabel}</span>
</div>
);
};
export default ScaleLabel;
| 5,437
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/SearchInput.tsx
|
import { ChangeEvent, forwardRef, useEffect, useState } from 'react';
import noop from '@proton/utils/noop';
import Input, { Props as InputProps } from './Input';
import useDebounceInput from './useDebounceInput';
/**
* <SearchInput delay={500} onChange={handleChange} value={keywords} />
* @param delay used to debounce search value (default: 0)
* @param onChange returns directly the value and not the event
* @param value initial
*/
interface Props extends Omit<InputProps, 'onChange'> {
delay?: number;
onChange?: (value: string) => void;
value?: string;
}
const SearchInput = forwardRef<HTMLInputElement, Props>(
({ delay = 200, onChange = noop, value = '', ...rest }, ref) => {
const [keywords, setKeywords] = useState(value);
const words = useDebounceInput(keywords, delay);
const handleChange = ({ target }: ChangeEvent<HTMLInputElement>) => setKeywords(target.value);
useEffect(() => {
onChange(words);
}, [words]);
useEffect(() => {
setKeywords(value);
}, [value]);
return <Input ref={ref} value={keywords} onChange={handleChange} type="search" {...rest} />;
}
);
export default SearchInput;
| 5,438
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/TelInput.js
|
import Input from './Input';
const TelInput = (props) => {
return <Input type="tel" {...props} />;
};
export default TelInput;
| 5,439
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/TextArea.tsx
|
import { ChangeEvent, DetailedHTMLProps, Ref, TextareaHTMLAttributes, useEffect, useRef, useState } from 'react';
import clsx from '@proton/utils/clsx';
import { generateUID } from '../../helpers';
import useAutoGrow from '../../hooks/useAutoGrow';
import ErrorZone from '../text/ErrorZone';
import useInput from './useInput';
export interface Props extends DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement> {
ref?: Ref<HTMLTextAreaElement>; // override ref so that LegacyRef isn't used
error?: string;
isSubmitted?: boolean;
loading?: boolean;
rows?: number;
minRows?: number;
autoGrow?: boolean;
}
/**
* @deprecated please use TextAreaTwo instead
*/
const TextArea = ({
className = '',
error,
rows: maxRows = 5,
minRows = 1,
autoGrow = false,
onChange,
isSubmitted,
...rest
}: Props) => {
const textAreaRef = useRef<HTMLTextAreaElement>(null);
const { rows, updateTextArea } = useAutoGrow({ maxRows, minRows, autoGrow });
const { handlers, statusClasses, status } = useInput<HTMLTextAreaElement>({
...rest,
onChange(e: ChangeEvent<HTMLTextAreaElement>) {
if (updateTextArea) {
updateTextArea(e.target);
}
if (onChange) {
onChange(e);
}
},
});
useEffect(() => {
if (updateTextArea && textAreaRef.current) {
updateTextArea(textAreaRef.current);
}
}, [updateTextArea]);
const [uid] = useState(generateUID('textarea'));
const hasError = !!(error && (status.isDirty || isSubmitted));
return (
<>
<textarea
ref={textAreaRef}
rows={rows}
className={clsx(['field w-full', className, statusClasses])}
aria-invalid={hasError}
aria-describedby={uid}
{...rest}
{...handlers}
/>
{hasError && <ErrorZone id={uid}>{error}</ErrorZone>}
</>
);
};
export default TextArea;
| 5,440
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/TimeInput.test.tsx
|
import { fireEvent, render, screen } from '@testing-library/react';
import noop from '@proton/utils/noop';
import TimeInput from './TimeInput';
describe('TimeInput component', () => {
it('should display a time input of type text', () => {
const date = new Date(2023, 0, 11, 12);
const { container } = render(<TimeInput value={date} onChange={noop} />);
const inputNode = container.querySelector('input');
expect(inputNode).not.toBe(null);
expect(inputNode?.getAttribute('type')).toBe('text');
});
it('should display the time with duration', () => {
const date = new Date(2023, 0, 1, 12);
render(<TimeInput value={date} min={date} onChange={noop} displayDuration />);
const input = screen.getByDisplayValue(/12/);
expect(input).toHaveValue('12:00 PM');
fireEvent.click(input);
// display duration options
screen.getByText('0 min');
screen.getByText('30 min');
screen.getByText('30 min');
screen.getByText('1 h');
screen.getByText('1.5 h');
screen.getByText('2 h');
screen.getByText('2.5 h');
});
});
| 5,441
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/TimeInput.tsx
|
import { ChangeEvent, MouseEvent, useEffect, useMemo, useRef, useState } from 'react';
import { Locale, addMinutes, format, parse, startOfDay } from 'date-fns';
import { c, msgid } from 'ttag';
import { Input, InputProps } from '@proton/atoms';
import { findLongestMatchingIndex } from '@proton/shared/lib/helpers/string';
import { dateLocale } from '@proton/shared/lib/i18n';
import withDecimalPrecision from '@proton/utils/withDecimalPrecision';
import { generateUID } from '../../helpers';
import { useHotkeys } from '../../hooks';
import Dropdown from '../dropdown/Dropdown';
import DropdownMenu from '../dropdown/DropdownMenu';
import DropdownMenuButton from '../dropdown/DropdownMenuButton';
import { usePopperAnchor } from '../popper';
const toFormatted = (value: Date, locale: Locale) => {
return format(value, 'p', { locale });
};
const fromFormatted = (value: string, locale: Locale) => {
return parse(value, 'p', new Date(), { locale });
};
export const formatDuration = (label: string, minutes: number) => {
const hours = withDecimalPrecision(minutes / 60, 1);
const hoursInt = Math.floor(hours);
if (hours >= 1) {
if (hours === hoursInt) {
// hours is an integer
return {
// translator: 'h' stands for hour and the rendered string is a duration, e.g.: 1 h, 3 h. Please translate with the shortest possible version in your language.
shortText: c('Time unit for duration; displayed in the time picker').ngettext(
msgid`${hours} h`,
`${hours} h`,
hours
),
longText: c('Time unit for duration; vocalized in the time picker').ngettext(
msgid`${hours} hour`,
`${hours} hours`,
hours
),
};
}
// else hours is a half-integer
return {
// translator: 'h' stands for hour and the rendered string is a duration, with the variable hoursInt being an integer but the duration being a half-integer, e.g.: 1.5 h, 3.5 h. Please translate with the shortest possible version in your language.
shortText: c('Time unit for duration; displayed in the time picker').ngettext(
msgid`${hoursInt}.5 h`,
`${hoursInt}.5 h`,
hoursInt
),
// translator: The variable hoursInt is an integer but the duration is a half-integer bigger than 1, e.g.: 1.5 hours, 3.5 hours.
longText: c('Time unit for duration; vocalized in the time picker').ngettext(
msgid`${hoursInt}.5 hour`,
`${hoursInt}.5 hours`,
hoursInt
),
};
}
return {
// translator: 'min' stands for minute and the rendered string is a duration, e.g.: 15 min, 30 min. Please translate with the shortest possible version in your language.
shortText: c('Time unit for duration; displayed in the time picker').ngettext(
msgid`${minutes} min`,
`${minutes} min`,
minutes
),
longText: c('Time unit for duration; vocalized in the time picker').ngettext(
msgid`${minutes} minute`,
`${minutes} minutes`,
minutes
),
};
};
const getDurationOptionDisplay = (label: string, minutes: number) => {
const { shortText, longText } = formatDuration(label, minutes);
return (
<>
<span aria-hidden="true">{shortText}</span>
<span className="sr-only">{longText}</span>
</>
);
};
const getMinutes = (date: Date) => date.getHours() * 60 + date.getMinutes();
// Get minutes from midnight to prevent having options going further than 11:30 PM (when prevent preventNextDayOverflow prop is active)
const getBaseDateMinutes = (baseDate: Date, interval: number) => {
const baseMinutes = baseDate.getMinutes();
let minutes = 0;
if (baseMinutes > interval) {
// calculate minutes to remove depending on the interval
minutes = Math.floor(baseMinutes / interval) * interval;
}
return (24 - baseDate.getHours()) * 60 - minutes;
};
const MAX_MINUTES = 24 * 60;
interface Props extends Omit<InputProps, 'onChange' | 'min' | 'max' | 'value'> {
value: Date;
min?: Date;
max?: Date;
onChange: (date: Date) => void;
displayDuration?: boolean;
base?: Date;
interval?: number;
preventNextDayOverflow?: boolean; // If we have a min hour, we may want to avoid having calculated options overflowing on the next day
}
const TimeInput = ({
onChange,
value,
interval = 30,
min,
displayDuration = false,
max,
preventNextDayOverflow = false,
...rest
}: Props) => {
const [uid] = useState(generateUID('dropdown'));
const { anchorRef, isOpen, open, close } = usePopperAnchor<HTMLInputElement>();
const [temporaryInput, setTemporaryInput] = useState(() => toFormatted(value, dateLocale));
useEffect(() => {
setTemporaryInput(toFormatted(value, dateLocale));
}, [value]);
const base = useMemo(() => min || startOfDay(value), [min, value]);
const minMinutes = getMinutes(base);
const valueMinutes = getMinutes(value);
const normalizedMinutes = valueMinutes - minMinutes;
const handleSelectDate = (newDate: Date) => {
const newMinutes = getMinutes(newDate);
if (valueMinutes === newMinutes) {
return;
}
const diffMinutes = newMinutes - minMinutes;
const normalizedDate = new Date(
base.getFullYear(),
base.getMonth(),
base.getDate(),
0,
minMinutes + (diffMinutes < 0 && !preventNextDayOverflow ? diffMinutes + MAX_MINUTES : diffMinutes)
);
onChange(normalizedDate);
};
const parseAndSetDate = (temporaryInput: string) => {
try {
const newDate = fromFormatted(temporaryInput, dateLocale);
const newDateTime = +newDate;
if (!Number.isNaN(newDateTime)) {
handleSelectDate(newDate);
}
// eslint-disable-next-line no-empty
} catch (e: any) {}
setTemporaryInput(toFormatted(value, dateLocale));
};
const handleBlur = () => {
parseAndSetDate(temporaryInput);
close();
};
useHotkeys(anchorRef, [
[
'Escape',
(e) => {
if (isOpen) {
e.preventDefault();
e.stopPropagation();
parseAndSetDate(temporaryInput);
close();
}
},
],
[
'Enter',
(e) => {
parseAndSetDate(temporaryInput);
if (isOpen) {
e.preventDefault();
e.stopPropagation();
close();
} else {
e.preventDefault();
e.stopPropagation();
open();
}
},
],
[
'ArrowDown',
(e) => {
if (isOpen) {
e.preventDefault();
e.stopPropagation();
handleSelectDate(addMinutes(value, interval));
}
},
],
[
'ArrowUp',
(e) => {
if (isOpen) {
e.preventDefault();
e.stopPropagation();
handleSelectDate(addMinutes(value, -1 * interval));
}
},
],
]);
const scrollRef = useRef<HTMLDivElement>(null);
const listRef = useRef<HTMLUListElement>(null);
const options = useMemo(() => {
const totalMinutes = preventNextDayOverflow ? getBaseDateMinutes(base, interval) : MAX_MINUTES;
const length = Math.floor(totalMinutes / interval);
const minutes = Array.from({ length }, (a, i) => i * interval);
return minutes.map((minutes) => {
const value = addMinutes(base, minutes);
const label = toFormatted(value, dateLocale);
return {
minutes,
value,
label,
display: displayDuration ? (
<>
{label} ({getDurationOptionDisplay(label, minutes)})
</>
) : (
label
),
};
});
}, [normalizedMinutes, base]);
const filteredOptions = useMemo(() => {
return options.filter(({ value }) => {
const minCondition = min ? value >= min : true;
const maxCondition = max ? value <= max : true;
return minCondition && maxCondition;
});
}, [options, min, max]);
const matchingIndex = useMemo(() => {
const idx = findLongestMatchingIndex(
filteredOptions.map(({ label }) => label),
temporaryInput
);
return idx === -1 ? undefined : idx;
}, [filteredOptions, temporaryInput]);
const scrollToSelection = () => {
if (!isOpen) {
return;
}
if (!listRef.current || !scrollRef.current || matchingIndex === undefined) {
return;
}
const matchingEl = listRef.current.children[matchingIndex] as HTMLLIElement;
if (matchingEl) {
scrollRef.current.scrollTop =
matchingEl.offsetTop - (scrollRef.current.clientHeight - matchingEl.clientHeight) / 2;
}
};
useEffect(() => {
// RAF needed due to our portal behavior in dropdown
requestAnimationFrame(scrollToSelection);
}, [isOpen]);
useEffect(() => {
scrollToSelection();
}, [matchingIndex]);
return (
<>
<Input
type="text"
ref={anchorRef}
onFocus={() => open()}
onBlur={handleBlur}
onClick={() => open()}
value={temporaryInput}
onChange={({ target: { value } }: ChangeEvent<HTMLInputElement>) => setTemporaryInput(value)}
{...rest}
/>
<Dropdown
id={uid}
isOpen={isOpen}
anchorRef={anchorRef}
onClose={close}
disableFocusTrap
autoClose={false}
autoCloseOutside={false}
contentProps={{
onMouseDown: (event: MouseEvent<HTMLDivElement>) => {
// Prevent default to stop the input getting blurred.
event.preventDefault();
},
ref: scrollRef,
}}
disableDefaultArrowNavigation
>
<DropdownMenu listRef={listRef}>
{filteredOptions.map(({ label, display, value: otherValue }, i) => {
// Only highlight if the text includes the input (where 13:05 is centered but not highlighted)
const isSelected = i === matchingIndex && label.includes(temporaryInput);
return (
<DropdownMenuButton
key={i}
className="text-left text-nowrap"
isSelected={isSelected}
style={{ pointerEvents: 'auto' }} // Lets the user select the time during typing
onClick={() => {
handleSelectDate(otherValue);
close();
}}
>
{display}
</DropdownMenuButton>
);
})}
</DropdownMenu>
</Dropdown>
</>
);
};
export default TimeInput;
| 5,442
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/TwoFactorInput.tsx
|
import Input, { Props } from './Input';
/**
* The two-factor input needs to support recovery codes and totp codes.
* e.g. 0fac27c3 and 505037.
*/
const TwoFactorInput = ({ value, onChange, maxLength = 8, ...rest }: Props) => {
return (
<Input
value={value}
autoComplete="one-time-code"
inputMode="numeric"
onChange={onChange}
maxLength={maxLength}
{...rest}
/>
);
};
export default TwoFactorInput;
| 5,443
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/index.ts
|
export { default as Checkbox } from './Checkbox';
export * from './Checkbox';
export { default as ColorPicker } from './ColorPicker';
export { default as DateInput } from './DateInput';
export { default as EmailInput } from './EmailInput';
export { default as FileInput } from './FileInput';
export { default as Input } from './Input';
export { default as InputButton } from './InputButton';
export * from './InputButton';
export { default as LegacyInputField } from './LegacyInputField';
export { default as IntegerInput } from './IntegerInput';
export { default as PasswordInput } from './PasswordInput';
export { default as Radio } from './Radio';
export { default as LayoutCard } from './LayoutCard';
export { default as LayoutCards } from './LayoutCards';
export { default as RadioGroup } from './RadioGroup';
export { default as SearchInput } from './SearchInput';
export { default as Scale } from './Scale';
export * from './Scale';
export { default as EmojiScale } from './EmojiScale';
export * from './EmojiScale';
export { default as TelInput } from './TelInput';
export { default as TextArea } from './TextArea';
export { default as TimeInput } from './TimeInput';
export { default as TwoFactorInput } from './TwoFactorInput';
export { default as useDebounceInput } from './useDebounceInput';
export { default as useInput } from './useInput';
| 5,444
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/useDebounceInput.ts
|
import { useCallback, useEffect, useRef, useState } from 'react';
export default function useDebounceInput<T>(value: T, delay = 500) {
const [currentValue, setCurrentValue] = useState<T>(value);
const interval = useRef(0);
const clean = useCallback(() => {
window.clearInterval(interval.current);
}, []);
useEffect(() => {
if (!delay) {
return setCurrentValue(value);
}
interval.current = window.setTimeout(() => {
setCurrentValue(value);
}, delay);
return clean;
}, [value, delay]);
useEffect(() => clean, []);
return !delay ? value : currentValue;
}
| 5,445
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/input/useInput.tsx
|
import {
ChangeEvent,
ChangeEventHandler,
FocusEvent,
FocusEventHandler,
KeyboardEvent,
KeyboardEventHandler,
useMemo,
useState,
} from 'react';
const FOCUSED_CLASS = 'focused';
const BLURRED_CLASS = 'blurred';
const DIRTY_CLASS = 'dirty';
const PRISTINE_CLASS = 'pristine';
const DEFAULT_STATE = {
isFocused: false,
isBlurred: false,
isDirty: false,
isPristine: true,
};
interface Arguments<T> {
onFocus?: FocusEventHandler<T>;
onBlur?: FocusEventHandler<T>;
onChange?: ChangeEventHandler<T>;
onPressEnter?: KeyboardEventHandler<T>;
onKeyDown?: KeyboardEventHandler<T>;
disabled?: boolean;
}
function useInput<T>(
{ onFocus, onBlur, onChange, onPressEnter, onKeyDown, disabled }: Arguments<T>,
initialState = DEFAULT_STATE,
prefix = 'field'
) {
const [status, changeStatus] = useState(initialState);
const { isFocused, isBlurred, isPristine, isDirty } = status;
const reset = () => {
changeStatus({ ...DEFAULT_STATE });
};
const statusClasses = useMemo(() => {
return [
isPristine && PRISTINE_CLASS,
isFocused && FOCUSED_CLASS,
isBlurred && BLURRED_CLASS,
isDirty && DIRTY_CLASS,
]
.filter(Boolean)
.map((className) => `${prefix}-${className}`)
.join(' ');
}, [status, prefix]);
return {
status,
statusClasses,
reset,
handlers: {
onFocus: (event: FocusEvent<T>) => {
if (disabled) {
return;
}
if (!isFocused) {
changeStatus({
...status,
isBlurred: false,
isFocused: true,
isPristine: false,
});
}
if (onFocus) {
onFocus(event);
}
},
onBlur: (event: FocusEvent<T>) => {
if (!isBlurred) {
changeStatus({
...status,
isBlurred: true,
isFocused: false,
isPristine: false,
});
}
if (onBlur) {
onBlur(event);
}
},
onChange: (event: ChangeEvent<T>) => {
if (!isDirty) {
changeStatus({
...status,
isDirty: true,
isPristine: false,
});
}
if (onChange) {
onChange(event);
}
},
onKeyDown: (event: KeyboardEvent<T>) => {
if (event.key === 'Enter' && onPressEnter) {
onPressEnter(event);
}
if (onKeyDown) {
onKeyDown(event);
}
},
},
};
}
export default useInput;
| 5,446
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/keyTransparency/KeyTransparencyDetailsModal.tsx
|
import { formatDistanceToNow } from 'date-fns';
import { c } from 'ttag';
import { Button, Href } from '@proton/atoms';
import {
AppLink,
Icon,
ModalProps,
ModalTwo,
ModalTwoContent,
ModalTwoFooter,
ModalTwoHeader,
useConfig,
useKeyTransparencyContext,
} from '@proton/components';
import {
AddressAuditStatus,
AddressAuditWarningDetails,
AddressAuditWarningReason,
LocalStorageAuditResult,
SelfAuditResult,
} from '@proton/key-transparency/lib';
import { getAppName } from '@proton/shared/lib/apps/helper';
import { APPS, BRAND_NAME } from '@proton/shared/lib/constants';
import { canonicalizeInternalEmail } from '@proton/shared/lib/helpers/email';
import { getKnowledgeBaseUrl } from '@proton/shared/lib/helpers/url';
import { dateLocale } from '@proton/shared/lib/i18n';
const uniqueByEmail = (failedAudits: LocalStorageAuditResult[]): LocalStorageAuditResult[] => {
const seen = new Set<string>();
return failedAudits.filter(({ email }) => {
const canonicalEmail = canonicalizeInternalEmail(email);
if (seen.has(canonicalEmail)) {
return false;
}
seen.add(canonicalEmail);
return true;
});
};
const SelfAuditResults = ({ selfAuditResult }: { selfAuditResult: SelfAuditResult }) => {
const { APP_NAME } = useConfig();
const appName = getAppName(APP_NAME);
if (selfAuditResult?.error) {
if (selfAuditResult.error.tooManyRetries) {
return (
<div className="flex flex-nowrap">
<Icon name="exclamation-circle" className="flex-item-noshrink mr-2 mt-0.5 color-warning" />
<span className="flex-item-fluid text-break">{c('loc_nightly: Key transparency details')
.t`Key verification was interrupted too many times, there might be a technical issue preventing ${appName} from verifying your keys.`}</span>
</div>
);
} else {
return (
<span>{c('loc_nightly: Key transparency details')
.t`Key verification was interrupted, it will be restarted automatically.`}</span>
);
}
}
const addressAuditWarningMessage = (details: AddressAuditWarningDetails) => {
switch (details.reason) {
case AddressAuditWarningReason.UnverifiableHistory:
if (details.addressWasDisabled) {
return (
<span>{c('loc_nightly: Key transparency details')
.t`${appName} detected that this address has been disabled and re-enabled recently. During that period, data shared to that address might not have been encrypted with your keys.`}</span>
);
} else {
return (
<span>{c('loc_nightly: Key transparency details')
.t`${appName} could not verify some changes made to this address' keys in the past. This might be due to a recent key deletion or a password reset.`}</span>
);
}
case AddressAuditWarningReason.AddressWithNoKeys: {
return (
<span>{c('loc_nightly: Key transparency details')
.t`${appName} detected that this address has no encryption keys. Please re-login to generate keys for this address.`}</span>
);
}
}
};
const verifyYourKeysLink = (
<AppLink to="/encryption-keys" toApp={APPS.PROTONACCOUNT} target="_self">{c(
'loc_nightly: Key transparency details'
).t`Verify your keys.`}</AppLink>
);
const getMessageWithFingerprint = (primaryKeyFingerprint: string | undefined) => {
if (!primaryKeyFingerprint) {
return;
}
const fingerprintMessage = c('loc_nightly: Key transparency details')
.t`To verify the security of your end-to-end encryption with this contact, compare the following fingerprint with the one the recipient sees in their Account (Settings > Encryption & Keys).`;
return (
<>
<div className="flex flex-column gap-1">
<p>{fingerprintMessage}</p>
<code className="bg-weak p-1 rounded user-select text-sm text-break">{primaryKeyFingerprint}</code>
</div>
</>
);
};
const getAddressAuditFailures = () => {
const failedAddressAuditMessage = c('loc_nightly: Key transparency details')
.t`${appName} failed to verify that the keys of this address are consistent with Key Transparency.`;
const failedAddressAudits = selfAuditResult.addressAuditResults.filter(
({ status }) => status === AddressAuditStatus.Failure
);
return failedAddressAudits.map(({ email }) => {
return (
<div>
<p>{failedAddressAuditMessage}</p>
<ul className="unstyled">
<li className="flex flex-nowrap" key={email}>
<Icon name="exclamation-circle" className="flex-item-noshrink mr-2 mt-0.5 color-danger" />
<strong className="flex-item-fluid text-break">{email}</strong>
</li>
</ul>
</div>
);
});
};
const getAddressAuditWarnings = () => {
const warningAddressAudits = selfAuditResult.addressAuditResults
.filter(({ status }) => status === AddressAuditStatus.Warning)
.filter(
({ warningDetails }) =>
!(
warningDetails?.reason === AddressAuditWarningReason.UnverifiableHistory &&
!warningDetails.addressWasDisabled
)
);
return warningAddressAudits.map(({ email, warningDetails }) => {
return (
<div>
<p>{addressAuditWarningMessage(warningDetails!)}</p>
<ul className="unstyled">
<li className="flex flex-nowrap" key={email}>
<Icon name="exclamation-circle" className="flex-item-noshrink mr-2 mt-0.5 color-warning" />
<strong className="flex-item-fluid text-break">{email}</strong>
</li>
</ul>
</div>
);
});
};
const getLSAuditFailuresOwn = () => {
const failedLSAudits = selfAuditResult.localStorageAuditResultsOwnAddress.filter((audit) => !audit.success);
const failedLSAuditsDeduplicated = uniqueByEmail(failedLSAudits);
const failedLSAuditMessage = (
<div>
<span className="mr-1">{c('loc_nightly: Key transparency details')
.t`${appName} detected that changes you made recently to the keys of this address have not been properly applied.`}</span>
{verifyYourKeysLink}
</div>
);
return failedLSAuditsDeduplicated.map(({ email }) => {
return (
<div>
<p>{failedLSAuditMessage}</p>
<ul className="unstyled">
<li className="flex flex-nowrap" key={email}>
<Icon name="exclamation-circle" className="flex-item-noshrink mr-2 mt-0.5 color-danger" />
<strong className="flex-item-fluid text-break">{email}</strong>
</li>
</ul>
</div>
);
});
};
const getLSAuditFailuresOther = () => {
const failedLSAuditsOther = selfAuditResult.localStorageAuditResultsOtherAddress.filter(
(audit) => !audit.success
);
const failedLSAuditsOtherDeduplicated = uniqueByEmail(failedLSAuditsOther);
const message = c('loc_nightly: Key transparency details')
.t`${appName} detected that the keys used in the past for this address may not be authentic.`;
return failedLSAuditsOtherDeduplicated.map(({ email, primaryKeyFingerprint }) => {
return (
<div>
<p>{message}</p>
<ul className="unstyled">
<li className="flex flex-nowrap" key={email}>
<Icon name="exclamation-circle" className="flex-item-noshrink mr-2 mt-0.5 color-danger" />
<strong className="flex-item-fluid text-break">{email}</strong>
</li>
</ul>
<p>{getMessageWithFingerprint(primaryKeyFingerprint)}</p>
</div>
);
});
};
const getAuditSuccess = () => {
const successEmails = selfAuditResult.addressAuditResults
.filter(
({ status, warningDetails }) =>
status === AddressAuditStatus.Success ||
(status === AddressAuditStatus.Warning &&
warningDetails?.reason === AddressAuditWarningReason.UnverifiableHistory &&
!warningDetails.addressWasDisabled)
)
.map(({ email }) => email);
if (!successEmails.length) {
return <></>;
}
return (
<div>
<p>{c('loc_nightly').t`The following addresses were successfully audited with Key Transparency:`}</p>
<ul className="unstyled">
{successEmails.map((email) => (
<li className="flex flex-nowrap" key={email}>
<Icon name="checkmark" className="flex-item-noshrink mr-2 mt-0.5 color-success" />
<strong className="flex-item-fluid text-break">{email}</strong>
</li>
))}
</ul>
</div>
);
};
const alerts = [
...getAddressAuditFailures(),
...getLSAuditFailuresOwn(),
...getLSAuditFailuresOther(),
...getAddressAuditWarnings(),
getAuditSuccess(),
];
return (
<>
{alerts.map((alert, index) => (
<>
{alert}
{index !== alerts.length - 1 && <hr />}
</>
))}
</>
);
};
const NoResultFallback = () => {
return <span>{c('loc_nightly: Key transparency details').t`Key verification is pending`}</span>;
};
const KeyTransparencyDetailsModal = (props: ModalProps) => {
const {
ktState: { selfAuditResult },
} = useKeyTransparencyContext();
const { onClose } = props;
const auditTime = selfAuditResult
? formatDistanceToNow(new Date(selfAuditResult.auditTime), {
locale: dateLocale,
addSuffix: true,
})
: undefined;
const introductionText = c('loc_nightly: Key transparency details')
.t`${BRAND_NAME} automatically verifies your and your contacts’ encryption keys to ensure their authenticity. This ensures that only the owner of the email address can read messages sent to it.`;
return (
<ModalTwo size="medium" data-testid="key-transparency-details:modal" {...props}>
<ModalTwoHeader title={c('loc_nightly: Key transparency details').t`Key verification (Beta)`} />
<ModalTwoContent>
{auditTime && (
<div className="bg-weak p-3 rounded color-weak">{
// translator: the variable auditTime is a string that indicates how long ago last verification happened. E.g.: less than a minute ago, 14 minutes ago, about 2 hours ago
c('loc_nightly: Key transparency details').t`Last verified: ${auditTime}`
}</div>
)}
<p>
<span className="mr-1">{introductionText}</span>
<Href href={getKnowledgeBaseUrl('/key-transparency')}>{c('Link').t`Learn more`}</Href>
</p>
<hr />
{!!selfAuditResult && <SelfAuditResults selfAuditResult={selfAuditResult} />}
{!selfAuditResult && <NoResultFallback />}
</ModalTwoContent>
<ModalTwoFooter>
<Button className="ml-auto" color="norm" onClick={onClose}>{c('Action').t`Close`}</Button>
</ModalTwoFooter>
</ModalTwo>
);
};
export default KeyTransparencyDetailsModal;
| 5,447
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/keyTransparency/index.ts
|
export { default as KeyTransparencyDetailsModal } from './KeyTransparencyDetailsModal';
| 5,448
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/label/Label.tsx
|
import { LabelHTMLAttributes } from 'react';
import clsx from '@proton/utils/clsx';
type Props = LabelHTMLAttributes<HTMLLabelElement>;
const Label = ({ htmlFor, className, children, ...rest }: Props) => {
return (
<label htmlFor={htmlFor} className={clsx(['label', className])} {...rest}>
{children}
</label>
);
};
export default Label;
| 5,449
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/label/index.ts
|
export { default as Label } from './Label';
| 5,450
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/labelStack/LabelStack.tsx
|
import { MouseEvent } from 'react';
import { c } from 'ttag';
import clsx from '@proton/utils/clsx';
import Tooltip from '../tooltip/Tooltip';
import LabelStackItem from './LabelStackItem';
export interface LabelDescription {
name: string;
color?: string;
title?: string;
onClick?: (event: MouseEvent) => void;
onDelete?: (event: MouseEvent) => void;
}
interface Props {
labels: LabelDescription[];
showDelete?: boolean;
isStacked?: boolean;
/**
* Reverses stacking order when isStacked is true.
* Has no effect when isStacked is false.
*/
leftToRight?: boolean;
maxNumber?: number;
className?: string;
showDropDown?: boolean;
}
const LabelStack = ({
labels,
showDelete = false,
isStacked = false,
leftToRight = false,
maxNumber,
showDropDown,
className,
}: Props) => {
const labelsToShow = labels.slice(0, maxNumber);
const labelsOverflow = labels.slice(maxNumber || labels.length);
// translator: this text is not visible in the interface, it will be vocalized for blind people, to give them context of label buttons, like "Labels: <vocalisation of labels buttons>"
const labelsContext = c('Info').t`Labels:`;
return (
<ul
className={clsx([
'label-stack unstyled m-0 inline-flex flex-align-items-center stop-propagation rounded-full',
isStacked ? `is-stacked ${leftToRight ? 'flex-row-reverse' : 'flex-row'}` : 'flex-row',
className,
])}
aria-label={labelsContext}
>
{labelsToShow.map((label: LabelDescription) => (
<LabelStackItem label={label} key={label.name} showDropdown={showDropDown} showDelete={showDelete} />
))}
{labelsOverflow.length > 0 && (
<li className="label-stack-overflow-count flex">
<Tooltip title={labelsOverflow.map((label) => label.name).join(', ')}>
<span data-testid="label-stack:labels-overflow">+{labelsOverflow.length}</span>
</Tooltip>
</li>
)}
</ul>
);
};
export default LabelStack;
| 5,451
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/labelStack/LabelStackItem.tsx
|
import { MouseEvent } from 'react';
import tinycolor from 'tinycolor2';
import { c } from 'ttag';
import { genAccentShades } from '@proton/colors';
import clsx from '@proton/utils/clsx';
import { Dropdown, DropdownMenu, DropdownMenuButton } from '../dropdown';
import { Icon } from '../icon';
import { usePopperAnchor } from '../popper';
import { LabelDescription } from './LabelStack';
interface Props {
label: LabelDescription;
showDropdown?: boolean;
showDelete?: boolean;
}
const LabelStackItem = ({ label, showDelete = false, showDropdown = false }: Props) => {
const { anchorRef, isOpen, toggle, close } = usePopperAnchor<HTMLButtonElement>();
const handleLabelClick = (e: MouseEvent<HTMLButtonElement>) => {
if (showDropdown) {
toggle();
} else if (label.onClick) {
label.onClick(e);
}
};
const handleLabelOpen = (e: MouseEvent<HTMLButtonElement>) => {
if (label.onClick) {
e.stopPropagation();
label.onClick(e);
close();
}
};
const handleLabelRemove = (e: MouseEvent<HTMLButtonElement>) => {
if (label.onDelete) {
e.stopPropagation();
label.onDelete(e);
close();
}
};
const [base, hover, active] = genAccentShades(tinycolor(label.color)).map((c) => c.toHexString());
return (
<li
className="label-stack-item flex flex-row flex-align-items-stretch flex-justify-start flex-nowrap"
style={
label.color
? {
'--label-bg': base,
'--label-bg-hover': hover,
'--label-bg-active': active,
}
: undefined
}
data-testid={`label-item:container-${label.name}`}
>
{label.onClick ? (
<button
type="button"
className={clsx([
'label-stack-item-inner label-stack-item-button text-ellipsis',
showDelete && 'with-delete',
])}
onClick={(e) => handleLabelClick(e)}
title={label.title}
ref={anchorRef}
data-testid="label-item:body-button"
>
<span className="label-stack-item-text">{label.name}</span>
</button>
) : (
<span className="label-stack-item-inner text-ellipsis" title={label.title}>
<span className="label-stack-item-text">{label.name}</span>
</span>
)}
{showDelete && (
<button
type="button"
className="label-stack-item-delete label-stack-item-button flex-item-noshrink"
onClick={label.onDelete}
title={`${c('Action').t`Remove`} ${label.title}`}
data-testid="label-item:close-button"
>
<Icon name="cross-small" className="label-stack-item-delete-icon" alt={c('Action').t`Remove`} />
</button>
)}
{showDropdown && (
<Dropdown
anchorRef={anchorRef}
isOpen={isOpen}
originalPlacement="bottom"
onClose={close}
data-testid="label-item:dropdown-button"
>
<DropdownMenu>
<DropdownMenuButton
className="text-left "
onClick={(e) => handleLabelOpen(e)}
title={`${c('Action').t`Go to label`} ${label.title}`}
data-testid="label-item:dropdown--open-label"
>
{c('Action').t`Go to label`}
</DropdownMenuButton>
{label.onDelete && <hr className="my-1" aria-hidden="true" />}
{label.onDelete && (
<DropdownMenuButton
className="text-left"
onClick={(e) => handleLabelRemove(e)}
title={`${c('Action').t`Remove`} ${label.title}`}
data-testid="label-item:dropdown--remove-label"
>
{c('Action').t`Remove`}
</DropdownMenuButton>
)}
</DropdownMenu>
</Dropdown>
)}
</li>
);
};
export default LabelStackItem;
| 5,452
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/labelStack/index.ts
|
export { default as LabelStack } from './LabelStack';
| 5,453
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/link/AppLink.tsx
|
import { AnchorHTMLAttributes, Ref, forwardRef } from 'react';
import { Link as ReactRouterLink } from 'react-router-dom';
import { getAppHref, getAppHrefBundle } from '@proton/shared/lib/apps/helper';
import { APPS, APP_NAMES, VPN_HOSTNAME, isSSOMode, isStandaloneMode } from '@proton/shared/lib/constants';
import { stripLeadingAndTrailingSlash } from '@proton/shared/lib/helpers/string';
import { useAuthentication, useConfig } from '../../hooks';
import Tooltip from '../tooltip/Tooltip';
export interface AppLinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'color'> {
to: string;
toApp?: APP_NAMES;
selfOpening?: boolean;
}
const AppLink = ({ to, toApp, selfOpening = false, children, ...rest }: AppLinkProps, ref: Ref<HTMLAnchorElement>) => {
const { APP_NAME } = useConfig();
const authentication = useAuthentication();
const targetApp = selfOpening ? APP_NAME : toApp;
if (targetApp && (targetApp !== APP_NAME || selfOpening)) {
if (isSSOMode) {
// If in vpn-level account settings and want to visit the proton vpn app
if (targetApp === APPS.PROTONVPN_SETTINGS) {
const href = `https://${VPN_HOSTNAME}/${stripLeadingAndTrailingSlash(to)}`;
return (
// internal link, trusted
<a ref={ref} {...rest} target="_blank" href={href}>
{children}
</a>
);
}
const localID = authentication.getLocalID?.();
const href = getAppHref(to, targetApp, localID);
return (
// internal link, trusted
<a ref={ref} target="_blank" {...rest} href={href}>
{children}
</a>
);
}
if (APP_NAME === APPS.PROTONVPN_SETTINGS) {
const href = getAppHref(to, targetApp);
return (
// internal link, trusted
<a ref={ref} target="_blank" {...rest} href={href}>
{children}
</a>
);
}
if (isStandaloneMode) {
return (
<Tooltip title="Disabled in standalone mode">
<a ref={ref} {...rest} onClick={(e) => e.preventDefault()} href="#">
{children}
</a>
</Tooltip>
);
}
const href = getAppHrefBundle(to, targetApp);
return (
<a ref={ref} target="_self" {...rest} href={href}>
{children}
</a>
);
}
return (
<ReactRouterLink ref={ref} to={to} {...rest}>
{children}
</ReactRouterLink>
);
};
export default forwardRef<HTMLAnchorElement, AppLinkProps>(AppLink);
| 5,454
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/link/Info.scss
|
@import '~@proton/styles/scss/lib';
.info-button.info-button {
&::after {
inset-inline-start: 1px;
inset-block-start: 1px;
border: 0;
}
}
| 5,455
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/link/Info.tsx
|
import { ComponentPropsWithoutRef, MouseEvent, ReactNode, useState } from 'react';
import { c } from 'ttag';
import clsx from '@proton/utils/clsx';
import { generateUID } from '../../helpers';
import Icon, { IconProps } from '../icon/Icon';
import Tooltip from '../tooltip/Tooltip';
import './Info.scss';
interface Props extends Omit<IconProps, 'title' | 'name'> {
originalPlacement?: ComponentPropsWithoutRef<typeof Tooltip>['originalPlacement'];
url?: string;
title?: ReactNode;
buttonClass?: string;
buttonTabIndex?: number;
className?: string;
questionMark?: boolean;
filled?: boolean;
colorPrimary?: boolean;
}
const Info = ({
originalPlacement = 'top',
url,
title = undefined,
buttonClass,
buttonTabIndex,
className = '',
questionMark = false,
filled = false,
colorPrimary = true,
...rest
}: Props) => {
const [uid] = useState(generateUID('tooltip'));
const handleClick = (event: MouseEvent) => {
event.preventDefault();
if (url) {
window.open(url);
}
};
const safeTitle = title || '';
const icon = () => {
if (questionMark && !filled) {
return 'question-circle';
} else if (questionMark && filled) {
return 'question-circle-filled';
} else if (!questionMark && filled) {
return 'info-circle-filled';
}
return 'info-circle';
};
return (
<Tooltip
title={safeTitle}
openDelay={0}
closeDelay={250}
longTapDelay={0}
originalPlacement={originalPlacement}
>
<button
tabIndex={buttonTabIndex}
className={clsx(
'info-button inline-flex color-inherit relative interactive-pseudo interactive--no-background rounded-full',
buttonClass
)}
onClick={handleClick}
aria-describedby={uid}
type="button"
role={url ? 'link' : undefined}
>
<Icon
className={clsx(['icon-16p', colorPrimary && 'color-primary', className])}
name={icon()}
alt={c('Action').t`More info: ${safeTitle}`}
{...rest}
/>
</button>
</Tooltip>
);
};
export default Info;
| 5,456
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/link/LearnMore.test.js
|
import { render } from '@testing-library/react';
import LearnMore from './LearnMore';
describe('LearnMore component', () => {
const url = 'https://protonmail.com';
it('should contain "Learn more" and be a link', () => {
const { getByText } = render(<LearnMore url={url} />);
const linkNode = getByText('Learn more');
expect(linkNode.getAttribute('href')).toBe(url);
expect(linkNode.getAttribute('target')).toBe('_blank');
expect(linkNode.getAttribute('rel')).toBe('noopener noreferrer nofollow');
});
});
| 5,457
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/link/LearnMore.tsx
|
import { c } from 'ttag';
import { Href } from '@proton/atoms';
export interface LearnMoreProps {
url: string;
className?: string;
}
/**
* @deprecated please use Href
*/
const LearnMore = ({ url, className }: LearnMoreProps) => (
<Href href={url} className={className}>{c('Link').t`Learn more`}</Href>
);
export default LearnMore;
| 5,458
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/link/SettingsLink.tsx
|
import { Ref, forwardRef } from 'react';
import { useLocation } from 'react-router-dom';
import { DEFAULT_APP, getAppFromPathnameSafe, getSlugFromApp } from '@proton/shared/lib/apps/slugHelper';
import { APPS, APP_NAMES } from '@proton/shared/lib/constants';
import { getIsIframe } from '@proton/shared/lib/helpers/browser';
import { useConfig } from '../../hooks';
import AppLink, { AppLinkProps } from './AppLink';
const canOpenInSameTab = (APP_NAME: APP_NAMES, settingsApp: APP_NAMES | undefined, toSettingsForApp: APP_NAMES) => {
const isIframe = getIsIframe();
// If app is displayed inside an iframe, open settings in another tab
if (isIframe) {
return false;
}
// If in the "settings app", otherwise if any other app
return settingsApp ? settingsApp === toSettingsForApp : APP_NAME === toSettingsForApp;
};
export interface Props extends Omit<AppLinkProps, 'to' | 'toApp'> {
path: string;
app?: APP_NAMES;
}
const SettingsLink = ({ path, app, children, ...rest }: Props, ref: Ref<HTMLAnchorElement>) => {
const location = useLocation();
const { APP_NAME } = useConfig();
if (APP_NAME === APPS.PROTONVPN_SETTINGS) {
return (
<AppLink to={path} ref={ref} {...rest}>
{children}
</AppLink>
);
}
const settingsApp =
APP_NAME === APPS.PROTONACCOUNT ? getAppFromPathnameSafe(location.pathname) || DEFAULT_APP : undefined;
// Don't allow to go for settings to proton account
const toSettingsForApp = (app !== APPS.PROTONACCOUNT ? app : undefined) || settingsApp || APP_NAME;
const slug = getSlugFromApp(toSettingsForApp);
return (
<AppLink
to={`/${slug}${path}`}
ref={ref}
toApp={APPS.PROTONACCOUNT}
// If going to settings for the same app
target={canOpenInSameTab(APP_NAME, settingsApp, toSettingsForApp) ? '_self' : '_blank'}
{...rest}
>
{children}
</AppLink>
);
};
export default forwardRef<HTMLAnchorElement, Props>(SettingsLink);
| 5,459
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/link/index.ts
|
export { default as Info } from './Info';
export { default as useAppLink } from './useAppLink';
export { default as useSettingsLink } from './useSettingsLink';
export { default as AppLink } from './AppLink';
export * from './AppLink';
export { default as SettingsLink } from './SettingsLink';
export { default as LearnMore } from './LearnMore';
export * from './LearnMore';
| 5,460
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/link/useAppLink.ts
|
import { useCallback } from 'react';
import { useHistory } from 'react-router-dom';
import { getAppHref, getAppHrefBundle } from '@proton/shared/lib/apps/helper';
import { APPS, APP_NAMES, isSSOMode, isStandaloneMode } from '@proton/shared/lib/constants';
import { useAuthentication, useConfig } from '../../hooks';
const safeOpenNewTab = (href: string) => {
const otherWindow = window.open();
if (otherWindow) {
otherWindow.location.href = href;
}
};
const useAppLink = () => {
const { APP_NAME } = useConfig();
const authentication = useAuthentication();
const history = useHistory();
return useCallback(
(to: string, toApp?: APP_NAMES, newTab?: boolean) => {
if (toApp && toApp !== APP_NAME) {
if (isSSOMode) {
const localID = authentication.getLocalID?.();
const href = getAppHref(to, toApp, localID);
if (newTab) {
return safeOpenNewTab(href);
}
return document.location.assign(href);
}
if (APP_NAME === APPS.PROTONVPN_SETTINGS) {
const href = getAppHref(to, toApp);
return safeOpenNewTab(href);
}
if (isStandaloneMode) {
return;
}
return document.location.assign(getAppHrefBundle(to, toApp));
}
return history.push(to);
},
[authentication]
);
};
export default useAppLink;
| 5,461
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/link/useSettingsLink.ts
|
import { useCallback } from 'react';
import { useLocation } from 'react-router-dom';
import { getAppFromPathnameSafe, getSlugFromApp } from '@proton/shared/lib/apps/slugHelper';
import { APPS, APP_NAMES } from '@proton/shared/lib/constants';
import { useConfig } from '../../hooks';
import useAppLink from './useAppLink';
const useSettingsLink = () => {
const goToApp = useAppLink();
const location = useLocation();
const { APP_NAME } = useConfig();
return useCallback(
(path: string, app?: APP_NAMES, newTab?: boolean) => {
if (APP_NAME === APPS.PROTONVPN_SETTINGS) {
return goToApp(path, APP_NAME, newTab);
}
const settingsApp = APP_NAME === APPS.PROTONACCOUNT ? getAppFromPathnameSafe(location.pathname) : undefined;
const slug = getSlugFromApp(settingsApp || app || APP_NAME);
return goToApp(`/${slug}${path}`, APPS.PROTONACCOUNT, newTab);
},
[location, goToApp]
);
};
export default useSettingsLink;
| 5,462
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/loader/EllipsisLoader.tsx
|
import { HTMLAttributes } from 'react';
import { c } from 'ttag';
import clsx from '@proton/utils/clsx';
export interface Props extends HTMLAttributes<HTMLSpanElement> {
className?: string;
}
const EllipsisLoader = ({ className, ...rest }: Props) => {
return (
<span className={clsx(['ellipsis-loader', className])} {...rest}>
<span className="sr-only">{c('Info').t`Loading`}</span>
</span>
);
};
export default EllipsisLoader;
| 5,463
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/loader/Loader.tsx
|
import { CircleLoader, CircleLoaderSize } from '@proton/atoms';
interface Props {
size?: CircleLoaderSize;
className?: string;
}
const Loader = ({ size = 'small', className = 'mx-auto flex my-8' }: Props) => {
return (
<div className={className}>
<CircleLoader className="m-auto" size={size} />
</div>
);
};
export default Loader;
| 5,464
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/loader/LoaderIcon.tsx
|
import { CircleLoader } from '@proton/atoms';
const LoaderIcon = () => (
<div className="p-4" aria-busy="true">
<CircleLoader />
</div>
);
export default LoaderIcon;
| 5,465
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/loader/TextLoader.tsx
|
import { ReactNode } from 'react';
import EllipsisLoader from './EllipsisLoader';
interface Props {
children?: ReactNode;
className?: string;
}
const TextLoader = ({ children, className }: Props) => {
return (
<p className={className}>
{children}
<EllipsisLoader />
</p>
);
};
export default TextLoader;
| 5,466
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/loader/index.ts
|
export { default as Loader } from './Loader';
export { default as EllipsisLoader } from './EllipsisLoader';
export { default as TextLoader } from './TextLoader';
export { default as LoaderIcon } from './LoaderIcon';
| 5,467
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/CalendarLogo.tsx
|
import { ComponentPropsWithoutRef, useState } from 'react';
import { generateUID } from '@proton/components';
import { CALENDAR_APP_NAME } from '@proton/shared/lib/constants';
import clsx from '@proton/utils/clsx';
import { LogoProps } from './Logo';
type Props = ComponentPropsWithoutRef<'svg'> & Pick<LogoProps, 'variant' | 'size' | 'hasTitle'>;
const CalendarLogo = ({ variant = 'with-wordmark', size, className, hasTitle = true, ...rest }: Props) => {
// This logo can be several times in the view, ids has to be different each time
const [uid] = useState(generateUID('logo'));
const logoWidth = variant === 'with-wordmark' ? 178 : 36;
return (
<svg
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
viewBox={`0 0 ${logoWidth} 36`}
width={logoWidth}
height="36"
fill="none"
role="img"
className={clsx('logo', size && variant === 'glyph-only' && `icon-${size}p`, variant, className)}
aria-labelledby={`${uid}-title`}
{...rest}
>
{hasTitle && <title id={`${uid}-title`}>{CALENDAR_APP_NAME}</title>}
{variant === 'glyph-only' && (
<>
<path fill={`url(#${uid}-a)`} d="M7 6a3 3 0 0 0-3 3v1l1 1v17l20-10 1 1h6V9a3 3 0 0 0-3-3H7Z" />
<path
fill={`url(#${uid}-b)`}
d="M23.643 10H4v16.119A2.88 2.88 0 0 0 6.881 29H17l5.251-7.877A3.411 3.411 0 0 1 25.41 19H26v-6.643A2.357 2.357 0 0 0 23.643 10Z"
/>
<path
fill="#B8D7FF"
d="M17 29v-1.075a2.5 2.5 0 0 1 .602-1.627l5.053-5.897a3.43 3.43 0 0 1 .345-.404l-.345.404A3.394 3.394 0 0 0 22 22.41V29h-5Z"
/>
<path
fill="#8F69FF"
d="M24.6 25.386h1.02a.787.787 0 0 0 .802.596c.462-.001.766-.253.766-.623s-.316-.575-.943-.575h-.405v-.833h.352c.606 0 .854-.223.854-.555 0-.331-.269-.56-.642-.56a.642.642 0 0 0-.455.153.631.631 0 0 0-.219.425h-.985c.035-.58.497-1.414 1.654-1.414.928 0 1.57.525 1.57 1.264a1.1 1.1 0 0 1-.216.66c-.142.191-.34.335-.567.405v.015a1.117 1.117 0 0 1 .922 1.135c0 .801-.74 1.33-1.695 1.33-1.014.005-1.74-.567-1.813-1.424Zm5.292-3.306h.743v4.661h-.959v-3.576l-.923.622v-.942l1.14-.765Z"
/>
<defs>
<radialGradient
id={`${uid}-b`}
cx="0"
cy="0"
r="1"
gradientTransform="matrix(44.9183 0 0 40.1408 25.159 -5.851)"
gradientUnits="userSpaceOnUse"
>
<stop offset=".503" stopColor="#6D4AFF" />
<stop offset=".994" stopColor="#06B8FF" />
</radialGradient>
<linearGradient
id={`${uid}-a`}
x1="27.523"
x2="11.191"
y1="21.036"
y2="-2.692"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#BFE8FF" />
<stop offset=".307" stopColor="#BFABFF" />
<stop offset="1" stopColor="#7341FF" />
</linearGradient>
</defs>
</>
)}
{variant === 'with-wordmark' && (
<>
<path fill={`url(#${uid}-a)`} d="M3 6a3 3 0 0 0-3 3v1l1 1v17l20-10 1 1h6V9a3 3 0 0 0-3-3H3Z" />
<path
fill={`url(#${uid}-b)`}
d="M19.643 10H0v16.119A2.88 2.88 0 0 0 2.881 29H13l5.251-7.877A3.411 3.411 0 0 1 21.41 19H22v-6.643A2.357 2.357 0 0 0 19.643 10Z"
/>
<path
fill="#B8D7FF"
d="M13 29v-1.075a2.5 2.5 0 0 1 .602-1.627l5.053-5.897a3.42 3.42 0 0 1 .345-.403l-.345.403A3.394 3.394 0 0 0 18 22.41V29h-5Z"
/>
<path
fill="#8F69FF"
d="M20.6 25.386h1.02a.787.787 0 0 0 .802.596c.462-.001.766-.253.766-.623s-.316-.575-.943-.575h-.405v-.833h.352c.606 0 .854-.223.854-.555 0-.331-.269-.56-.642-.56a.642.642 0 0 0-.455.153.631.631 0 0 0-.219.425h-.985c.035-.58.497-1.414 1.654-1.414.928 0 1.57.525 1.57 1.264a1.1 1.1 0 0 1-.216.66c-.142.191-.34.335-.567.405v.015a1.117 1.117 0 0 1 .922 1.135c0 .801-.74 1.33-1.695 1.33-1.014.005-1.74-.567-1.813-1.424Zm5.292-3.306h.743v4.661h-.959v-3.576l-.923.622v-.942l1.14-.765Z"
/>
<path
fill="var(--logo-text-proton-color)"
d="M38 21.26v3.664h2.56V21.42a1.282 1.282 0 0 1 1.279-1.286h2.624a4.593 4.593 0 0 0 3.261-1.36 4.652 4.652 0 0 0 1.351-3.28c0-1.23-.486-2.41-1.35-3.282a4.603 4.603 0 0 0-3.265-1.358H38v4.58h2.56v-2.159h3.73c.58 0 1.134.232 1.544.644a2.2 2.2 0 0 1 0 3.105 2.18 2.18 0 0 1-1.544.643h-2.71a3.55 3.55 0 0 0-2.528 1.055 3.651 3.651 0 0 0-.776 1.166A3.54 3.54 0 0 0 38 21.26Zm11.473 3.664v-5.583c0-2.279 1.322-4.091 3.97-4.091a5.09 5.09 0 0 1 1.262.14v2.296c-.301-.02-.56-.02-.682-.02-1.402 0-2.005.646-2.005 1.955v5.303h-2.545Zm5.994-4.734c0-2.802 2.104-4.937 5.033-4.937 2.929 0 5.033 2.135 5.033 4.937 0 2.802-2.104 4.957-5.033 4.957-2.929 0-5.033-2.158-5.033-4.957Zm7.558 0c0-1.593-1.064-2.722-2.525-2.722-1.465 0-2.525 1.127-2.525 2.722 0 1.612 1.063 2.721 2.525 2.721 1.461 0 2.525-1.112 2.525-2.721Zm10.643 0c0-2.802 2.104-4.937 5.032-4.937 2.926 0 5.03 2.135 5.03 4.937 0 2.802-2.104 4.957-5.03 4.957-2.928 0-5.032-2.158-5.032-4.957Zm7.557 0c0-1.593-1.063-2.722-2.524-2.722-1.462 0-2.525 1.127-2.525 2.722 0 1.612 1.063 2.721 2.525 2.721 1.461 0 2.524-1.112 2.524-2.721Zm3.828 4.734v-5.38c0-2.499 1.583-4.294 4.41-4.294 2.806 0 4.39 1.793 4.39 4.294v5.38h-2.525v-5.18c0-1.39-.623-2.258-1.865-2.258-1.243 0-1.865.866-1.865 2.258v5.18h-2.545Zm-12.147-7.436h-2.747v3.528c0 1.23.44 1.793 1.703 1.793.12 0 .42 0 .802-.02v2.075c-.52.14-.981.223-1.484.223-2.124 0-3.569-1.29-3.569-3.728v-3.87h-1.706v-2.036h.424c.168 0 .335-.034.489-.097a1.284 1.284 0 0 0 .694-.698 1.28 1.28 0 0 0 .096-.492v-1.918h2.545v3.205H72.9v2.035h.006Z"
/>
<path
fill="var(--logo-text-product-color)"
d="M102.372 24.208a6.762 6.762 0 0 1-2.562-2.567 7.615 7.615 0 0 1 0-7.285 6.762 6.762 0 0 1 2.562-2.567 7.225 7.225 0 0 1 3.654-.935 7.446 7.446 0 0 1 3.03.614c.874.375 1.646.95 2.255 1.676a5.903 5.903 0 0 1 1.227 2.499h-2.695a3.808 3.808 0 0 0-1.433-1.664 4.657 4.657 0 0 0-4.642-.02 4.381 4.381 0 0 0-1.611 1.672 5.07 5.07 0 0 0 0 4.752c.376.692.936 1.27 1.62 1.67.684.4 1.462.603 2.255.594a4.273 4.273 0 0 0 2.378-.626 3.83 3.83 0 0 0 1.433-1.667h2.695a5.932 5.932 0 0 1-1.233 2.516 5.989 5.989 0 0 1-2.249 1.679 7.404 7.404 0 0 1-3.03.597 7.171 7.171 0 0 1-3.654-.938Zm18.438-8.428a4.4 4.4 0 0 1 1.804 1.744c.448.806.672 1.718.652 2.642v4.752h-2.289l-.164-1.427a3.195 3.195 0 0 1-1.264 1.22 3.857 3.857 0 0 1-1.835.427 4.438 4.438 0 0 1-2.318-.626 4.48 4.48 0 0 1-1.661-1.767 5.387 5.387 0 0 1-.611-2.602 4.953 4.953 0 0 1 .663-2.539 4.734 4.734 0 0 1 1.824-1.787 5.217 5.217 0 0 1 2.6-.634 5.437 5.437 0 0 1 2.599.597Zm-.839 6.396c.497-.475.744-1.15.744-2.03a2.758 2.758 0 0 0-.715-1.979 2.346 2.346 0 0 0-1.792-.76 2.35 2.35 0 0 0-.988.192 2.376 2.376 0 0 0-.822.58 3.079 3.079 0 0 0-.721 1.976c0 .72.256 1.42.721 1.975a2.385 2.385 0 0 0 1.813.752 2.4 2.4 0 0 0 .95-.177 2.53 2.53 0 0 0 .81-.53Zm7.561 2.742h-2.58V11.066h2.58v13.852Zm11.038-3.9h-7.244a2.57 2.57 0 0 0 .879 1.475 2.498 2.498 0 0 0 1.591.52c.46.018.92-.063 1.348-.234.339-.154.617-.415.795-.74h2.39a3.93 3.93 0 0 1-1.672 2.304 5.04 5.04 0 0 1-2.795.8c-.907.02-1.806-.2-2.599-.637a4.45 4.45 0 0 1-1.755-1.776 5.268 5.268 0 0 1-.621-2.567 5.21 5.21 0 0 1 .63-2.567 4.552 4.552 0 0 1 1.755-1.776 4.981 4.981 0 0 1 2.53-.635 4.795 4.795 0 0 1 2.47.65 4.59 4.59 0 0 1 1.718 1.786c.419.78.635 1.653.623 2.54a9.17 9.17 0 0 1-.043.857Zm-6.385-3.188c-.439.357-.75.852-.879 1.404h4.869a2.152 2.152 0 0 0-.787-1.384 2.42 2.42 0 0 0-1.603-.546 2.478 2.478 0 0 0-1.6.526Zm7.365 1.664a4.297 4.297 0 0 1 .273-1.69c.204-.54.517-1.032.919-1.446.796-.787 1.893-1.178 3.292-1.178 1.398 0 2.493.4 3.286 1.198a4.287 4.287 0 0 1 1.183 3.139v5.418h-2.579v-5.238a2.599 2.599 0 0 0-.46-1.664 1.97 1.97 0 0 0-2.835 0 2.618 2.618 0 0 0-.483 1.673v5.22h-2.579l-.017-5.432Zm17.375-8.428h2.579v13.852h-2.346l-.181-1.47a3.09 3.09 0 0 1-1.235 1.24 3.92 3.92 0 0 1-1.908.447 4.23 4.23 0 0 1-2.134-.569 4.254 4.254 0 0 1-1.631-1.71 5.508 5.508 0 0 1-.624-2.699 5.475 5.475 0 0 1 .624-2.69 4.254 4.254 0 0 1 1.631-1.71 4.239 4.239 0 0 1 2.134-.569 4.01 4.01 0 0 1 1.856.41c.517.248.948.648 1.235 1.146v-5.678Zm-.715 11.101a2.726 2.726 0 0 0 .712-2.021c0-.866-.241-1.533-.721-1.996a2.406 2.406 0 0 0-.807-.529 2.455 2.455 0 0 0-.951-.18 2.46 2.46 0 0 0-.948.198 2.462 2.462 0 0 0-.798.543 2.723 2.723 0 0 0-.713 1.978c-.037.732.219 1.45.713 1.996a2.394 2.394 0 0 0 1.795.74 2.348 2.348 0 0 0 1.718-.729Zm12.222-6.387a4.41 4.41 0 0 1 1.804 1.744c.448.806.672 1.718.652 2.642v4.752h-2.293l-.163-1.427a3.243 3.243 0 0 1-1.267 1.22 3.857 3.857 0 0 1-1.835.427 4.423 4.423 0 0 1-3.979-2.393 5.4 5.4 0 0 1-.612-2.602 4.964 4.964 0 0 1 .664-2.539 4.76 4.76 0 0 1 1.821-1.784 5.242 5.242 0 0 1 2.605-.637 5.445 5.445 0 0 1 2.603.597Zm-.836 6.396c.497-.475.744-1.15.744-2.03a2.777 2.777 0 0 0-.712-1.979 2.508 2.508 0 0 0-2.781-.566c-.31.132-.589.323-.821.566a3.072 3.072 0 0 0 0 3.952 2.365 2.365 0 0 0 1.803.76 2.474 2.474 0 0 0 1.767-.703Zm4.579-2.886a4.23 4.23 0 0 1 1.051-2.97c.698-.76 1.695-1.14 2.987-1.14.434-.004.865.045 1.287.142v2.316c-.204 0-.437-.02-.692-.02-.707 0-1.224.163-1.551.489a2.065 2.065 0 0 0-.397.692 2.052 2.052 0 0 0-.095.789v5.34h-2.579l-.011-5.637Z"
/>
<defs>
<radialGradient
id={`${uid}-b`}
cx="0"
cy="0"
r="1"
gradientTransform="matrix(44.9183 0 0 40.1408 21.159 -5.851)"
gradientUnits="userSpaceOnUse"
>
<stop offset=".503" stopColor="#6D4AFF" />
<stop offset=".994" stopColor="#06B8FF" />
</radialGradient>
<linearGradient
id={`${uid}-a`}
x1="23.523"
x2="7.191"
y1="21.036"
y2="-2.692"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#BFE8FF" />
<stop offset=".307" stopColor="#BFABFF" />
<stop offset="1" stopColor="#7341FF" />
</linearGradient>
</defs>
</>
)}
</svg>
);
};
export default CalendarLogo;
| 5,468
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/DriveLogo.tsx
|
import { ComponentPropsWithoutRef, useState } from 'react';
import { generateUID } from '@proton/components';
import { DRIVE_APP_NAME } from '@proton/shared/lib/constants';
import clsx from '@proton/utils/clsx';
import { LogoProps } from './Logo';
type Props = ComponentPropsWithoutRef<'svg'> & Pick<LogoProps, 'variant' | 'size' | 'hasTitle'>;
const DriveLogo = ({ variant = 'with-wordmark', size, className, hasTitle = true, ...rest }: Props) => {
// This logo can be several times in the view, ids has to be different each time
const [uid] = useState(generateUID('logo'));
const logoWidth = variant === 'with-wordmark' ? 140 : 36;
return (
<svg
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
viewBox={`0 0 ${logoWidth} 36`}
width={logoWidth}
height="36"
fill="none"
role="img"
className={clsx('logo', size && variant === 'glyph-only' && `icon-${size}p`, variant, className)}
aria-labelledby={`${uid}-title`}
{...rest}
>
{hasTitle && <title id={`${uid}-title`}>{DRIVE_APP_NAME}</title>}
{variant === 'glyph-only' && (
<>
<path fill={`url(#${uid}-a)`} d="m4 9 4-2 7 4h12v17l-1 1H7a3 3 0 0 1-3-3V9Z" />
<path
fill={`url(#${uid}-b)`}
fillRule="evenodd"
d="M14.961 7.426A3 3 0 0 0 16.726 8H29a3 3 0 0 1 3 3v15a3 3 0 0 1-3 3h-3V14.5a2.5 2.5 0 0 0-2.5-2.5H13a3 3 0 0 1-1.8-.6L8.8 9.6A3 3 0 0 0 7 9H4a3 3 0 0 1 3-3h5.024a3 3 0 0 1 1.765.574l1.172.852Z"
clipRule="evenodd"
/>
<defs>
<radialGradient
id={`${uid}-a`}
cx="0"
cy="0"
r="1"
gradientTransform="matrix(42.9176 0 0 45.5519 28.926 -8.114)"
gradientUnits="userSpaceOnUse"
>
<stop offset=".556" stopColor="#6D4AFF" />
<stop offset="1" stopColor="#FF50C3" />
</radialGradient>
<linearGradient
id={`${uid}-b`}
x1="3.631"
x2="38.345"
y1="-6.003"
y2="32.431"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#7341FF" />
<stop offset=".359" stopColor="#B487FF" />
<stop offset="1" stopColor="#FFC8FF" />
</linearGradient>
</defs>
</>
)}
{variant === 'with-wordmark' && (
<>
<path fill={`url(#${uid}-a)`} d="m0 9 4-2 7 4h12v17l-1 1H3a3 3 0 0 1-3-3V9Z" />
<path
fill={`url(#${uid}-b)`}
fillRule="evenodd"
d="M10.961 7.426A3 3 0 0 0 12.726 8H25a3 3 0 0 1 3 3v15a3 3 0 0 1-3 3h-3V14.5a2.5 2.5 0 0 0-2.5-2.5H9a3 3 0 0 1-1.8-.6L4.8 9.6A3 3 0 0 0 3 9H0a3 3 0 0 1 3-3h5.024a3 3 0 0 1 1.765.574l1.172.852Z"
clipRule="evenodd"
/>
<path
fill="var(--logo-text-product-color)"
d="M107.045 12.12a6.552 6.552 0 0 1 2.508 2.476 7.186 7.186 0 0 1 0 6.959 6.55 6.55 0 0 1-2.508 2.49 7.27 7.27 0 0 1-3.658.904h-4.505V11.213h4.505a7.274 7.274 0 0 1 3.658.907Zm-3.507 10.38a4.163 4.163 0 0 0 2.177-.569 4.18 4.18 0 0 0 1.561-1.62 4.803 4.803 0 0 0 .553-2.234c0-.777-.188-1.544-.553-2.233a4.138 4.138 0 0 0-1.524-1.59 4.218 4.218 0 0 0-2.217-.586h-2.086v8.815l2.089.017Zm8.04-3.138a4.213 4.213 0 0 1 1.035-2.945c.695-.752 1.672-1.13 2.937-1.13.425-.002.849.046 1.265.14v2.294c-.199 0-.427-.02-.681-.02-.695 0-1.205.16-1.527.483a2.015 2.015 0 0 0-.481 1.47v5.292h-2.533l-.015-5.584Zm6.266-5.844a1.443 1.443 0 0 1-.473-1.095 1.495 1.495 0 0 1 .473-1.106 1.544 1.544 0 0 1 1.125-.463c.208-.004.413.036.604.116.191.08.365.198.51.346a1.495 1.495 0 0 1 .473 1.107 1.443 1.443 0 0 1-.473 1.095 1.55 1.55 0 0 1-1.111.452 1.566 1.566 0 0 1-1.128-.452Zm2.396 11.416h-2.533v-9.458h2.533v9.458Zm4.071 0-3.59-9.458h2.667l1.644 4.832c.254.847.402 1.353.442 1.53h.04c.119-.455.282-.966.461-1.53l1.644-4.832h2.687l-3.59 9.458h-2.405Zm15.298-3.862h-7.118c.112.571.419 1.089.867 1.46.447.35 1 .532 1.564.515.453.017.903-.063 1.322-.231.33-.16.598-.42.772-.746h2.345a3.885 3.885 0 0 1-1.644 2.281 4.927 4.927 0 0 1-2.747.795c-.892.02-1.775-.2-2.555-.632a4.416 4.416 0 0 1-1.727-1.761 5.268 5.268 0 0 1-.61-2.542c-.014-.886.2-1.764.621-2.542a4.491 4.491 0 0 1 1.724-1.761 4.885 4.885 0 0 1 2.493-.618 4.675 4.675 0 0 1 2.428.644 4.515 4.515 0 0 1 1.689 1.77 5.19 5.19 0 0 1 .613 2.513c.005.286-.009.572-.037.855Zm-6.277-3.16a2.522 2.522 0 0 0-.86 1.39h4.786a2.134 2.134 0 0 0-.772-1.37c-.442-.363-1-.557-1.573-.543a2.436 2.436 0 0 0-1.581.523Z"
/>
<path
fill="var(--logo-text-proton-color)"
d="M38 21.26v3.664h2.56V21.42a1.282 1.282 0 0 1 1.279-1.286h2.624a4.592 4.592 0 0 0 3.261-1.361 4.652 4.652 0 0 0 1.351-3.28c0-1.228-.486-2.41-1.35-3.281a4.603 4.603 0 0 0-3.265-1.358H38v4.58h2.56v-2.159h3.73c.58 0 1.134.232 1.544.644a2.2 2.2 0 0 1 0 3.104c-.41.412-.964.644-1.544.644h-2.71a3.551 3.551 0 0 0-2.528 1.055 3.65 3.65 0 0 0-.776 1.166A3.54 3.54 0 0 0 38 21.259Zm11.47 3.664v-5.583c0-2.279 1.322-4.091 3.97-4.091a5.09 5.09 0 0 1 1.262.14v2.296c-.301-.02-.56-.02-.682-.02-1.402 0-2.005.646-2.005 1.955v5.303H49.47Zm5.994-4.734c0-2.802 2.104-4.937 5.033-4.937 2.929 0 5.033 2.135 5.033 4.937 0 2.802-2.104 4.957-5.033 4.957-2.929 0-5.033-2.158-5.033-4.957Zm7.558 0c0-1.592-1.064-2.722-2.525-2.722-1.465 0-2.525 1.127-2.525 2.722 0 1.612 1.063 2.722 2.525 2.722 1.464 0 2.525-1.113 2.525-2.722Zm10.646 0c0-2.802 2.104-4.937 5.032-4.937 2.926 0 5.03 2.135 5.03 4.937 0 2.802-2.104 4.957-5.03 4.957-2.928 0-5.032-2.158-5.032-4.957Zm7.554 0c0-1.592-1.063-2.722-2.524-2.722-1.462 0-2.525 1.127-2.525 2.722 0 1.612 1.063 2.722 2.525 2.722 1.461 0 2.525-1.113 2.525-2.722Zm3.831 4.734v-5.38c0-2.499 1.583-4.294 4.41-4.294 2.806 0 4.39 1.792 4.39 4.294v5.38h-2.525v-5.18c0-1.39-.623-2.259-1.865-2.259-1.243 0-1.865.867-1.865 2.259v5.18h-2.545Zm-12.147-7.436h-2.747v3.528c0 1.23.44 1.793 1.703 1.793.12 0 .42 0 .802-.02v2.075c-.52.14-.981.223-1.484.223-2.124 0-3.569-1.29-3.569-3.728v-3.87h-1.706v-2.036h.427a1.3 1.3 0 0 0 .489-.097 1.285 1.285 0 0 0 .694-.698 1.28 1.28 0 0 0 .096-.492v-1.918h2.545v3.205h2.747v2.035h.003Z"
/>
<defs>
<radialGradient
id={`${uid}-a`}
cx="0"
cy="0"
r="1"
gradientTransform="matrix(42.9176 0 0 45.5519 24.926 -8.114)"
gradientUnits="userSpaceOnUse"
>
<stop offset=".556" stopColor="#6D4AFF" />
<stop offset="1" stopColor="#FF50C3" />
</radialGradient>
<linearGradient
id={`${uid}-b`}
x1="-.369"
x2="34.345"
y1="-6.003"
y2="32.431"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#7341FF" />
<stop offset=".359" stopColor="#B487FF" />
<stop offset="1" stopColor="#FFC8FF" />
</linearGradient>
</defs>
</>
)}
</svg>
);
};
export default DriveLogo;
| 5,469
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/Logo.tsx
|
import { ComponentPropsWithoutRef } from 'react';
import { APPS, APP_NAMES } from '@proton/shared/lib/constants';
import { IconSize } from '../icon';
import CalendarLogo from './CalendarLogo';
import DriveLogo from './DriveLogo';
import MailLogo from './MailLogo';
import PassLogo from './PassLogo';
import VpnLogo from './VpnLogo';
export type LogoVariant = 'with-wordmark' | 'glyph-only';
const { PROTONCALENDAR, PROTONDRIVE, PROTONMAIL, PROTONVPN_SETTINGS, PROTONPASS } = APPS;
export interface LogoProps extends Omit<ComponentPropsWithoutRef<'svg'>, 'size'> {
appName: APP_NAMES;
size?: IconSize;
variant?: LogoVariant;
hasTitle?: boolean;
}
const Logo = ({ appName, variant, ...rest }: LogoProps) => {
if (appName === PROTONMAIL) {
return <MailLogo variant={variant} {...rest} />;
}
if (appName === PROTONCALENDAR) {
return <CalendarLogo variant={variant} {...rest} />;
}
if (appName === PROTONVPN_SETTINGS) {
return <VpnLogo variant={variant} {...rest} />;
}
if (appName === PROTONDRIVE) {
return <DriveLogo variant={variant} {...rest} />;
}
if (appName === PROTONPASS) {
return <PassLogo variant={variant} {...rest} />;
}
return null;
};
export default Logo;
| 5,470
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/MailLogo.tsx
|
import { ComponentPropsWithoutRef, useState } from 'react';
import { generateUID } from '@proton/components';
import { MAIL_APP_NAME } from '@proton/shared/lib/constants';
import clsx from '@proton/utils/clsx';
import { LogoProps } from './Logo';
type Props = ComponentPropsWithoutRef<'svg'> & Pick<LogoProps, 'variant' | 'size' | 'hasTitle'>;
const MailLogo = ({ variant = 'with-wordmark', className, size, hasTitle = true, ...rest }: Props) => {
// This logo can be several times in the view, ids has to be different each time
const [uid] = useState(generateUID('logo'));
const logoWidth = variant === 'with-wordmark' ? 134 : 36;
return (
<svg
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
viewBox={`0 0 ${logoWidth} 36`}
width={logoWidth}
height="36"
fill="none"
role="img"
className={clsx('logo', size && variant === 'glyph-only' && `icon-${size}p`, variant, className)}
aria-labelledby={`${uid}-title`}
{...rest}
>
{hasTitle && <title id={`${uid}-title`}>{MAIL_APP_NAME}</title>}
{variant === 'glyph-only' && (
<>
<path
fill={`url(#${uid}-a)`}
fillRule="evenodd"
d="m21.78 14.36.002.002L14 23 4 11.993V7.245a.644.644 0 0 1 1.055-.495l11.095 9.213a2.896 2.896 0 0 0 3.7 0l1.93-1.602Z"
clipRule="evenodd"
/>
<path
fill={`url(#${uid}-b)`}
d="m26 10.857-4.22 3.504.002.001-5.588 4.936a2.575 2.575 0 0 1-3.35.05L4 11.993v14.11A2.896 2.896 0 0 0 6.897 29H26l2-9.072-2-9.072Z"
/>
<path
fill={`url(#${uid}-c)`}
fillRule="evenodd"
d="M26 10.86V29h3.103c1.6 0 2.897-1.297 2.897-2.896V7.244a.644.644 0 0 0-1.055-.494L26 10.86Z"
clipRule="evenodd"
/>
<defs>
<linearGradient
id={`${uid}-a`}
x1="14.507"
x2="5.116"
y1="23.152"
y2="-9.469"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#E3D9FF" />
<stop offset="1" stopColor="#7341FF" />
</linearGradient>
<linearGradient
id={`${uid}-c`}
x1="41.055"
x2="19.455"
y1="43.522"
y2="-3.075"
gradientUnits="userSpaceOnUse"
>
<stop offset=".271" stopColor="#E3D9FF" />
<stop offset="1" stopColor="#7341FF" />
</linearGradient>
<radialGradient
id={`${uid}-b`}
cx="0"
cy="0"
r="1"
gradientTransform="matrix(27.9882 0 0 26.381 27.895 13.077)"
gradientUnits="userSpaceOnUse"
>
<stop offset=".556" stopColor="#6D4AFF" />
<stop offset=".994" stopColor="#AA8EFF" />
</radialGradient>
</defs>
</>
)}
{variant === 'with-wordmark' && (
<>
<path
fill={`url(#${uid}-a)`}
fillRule="evenodd"
d="m17.78 14.361.002.001L10 23 0 11.993V7.245a.644.644 0 0 1 1.055-.495l11.095 9.213a2.895 2.895 0 0 0 3.7 0l1.93-1.602Z"
clipRule="evenodd"
/>
<path
fill={`url(#${uid}-b)`}
d="m22 10.856-4.22 3.505.002.001-5.588 4.936a2.575 2.575 0 0 1-3.35.05L0 11.993v14.11A2.896 2.896 0 0 0 2.897 29H22l2-9.072-2-9.072Z"
/>
<path
fill={`url(#${uid}-c)`}
fillRule="evenodd"
d="M22 10.86V29h3.103c1.6 0 2.897-1.297 2.897-2.896V7.245a.644.644 0 0 0-1.055-.495L22 10.86Z"
clipRule="evenodd"
/>
<path
fill="var(--logo-text-proton-color)"
d="M38 21.26v3.664h2.56V21.42a1.282 1.282 0 0 1 1.279-1.286h2.624a4.592 4.592 0 0 0 3.261-1.361 4.652 4.652 0 0 0 1.351-3.28c0-1.228-.486-2.41-1.35-3.281a4.603 4.603 0 0 0-3.265-1.358H38v4.58h2.56v-2.159h3.73c.58 0 1.134.232 1.544.644a2.2 2.2 0 0 1 0 3.104c-.41.412-.964.644-1.544.644h-2.71a3.551 3.551 0 0 0-2.528 1.055 3.65 3.65 0 0 0-.776 1.166A3.54 3.54 0 0 0 38 21.259Zm11.47 3.664v-5.583c0-2.279 1.322-4.091 3.97-4.091a5.09 5.09 0 0 1 1.262.14v2.296c-.301-.02-.56-.02-.682-.02-1.402 0-2.005.646-2.005 1.955v5.303H49.47Zm5.994-4.734c0-2.802 2.104-4.937 5.033-4.937 2.929 0 5.033 2.135 5.033 4.937 0 2.802-2.104 4.957-5.033 4.957-2.929 0-5.033-2.158-5.033-4.957Zm7.558 0c0-1.592-1.064-2.722-2.525-2.722-1.465 0-2.525 1.127-2.525 2.722 0 1.612 1.063 2.722 2.525 2.722 1.464 0 2.525-1.113 2.525-2.722Zm10.646 0c0-2.802 2.104-4.937 5.032-4.937 2.926 0 5.03 2.135 5.03 4.937 0 2.802-2.104 4.957-5.03 4.957-2.928 0-5.032-2.158-5.032-4.957Zm7.554 0c0-1.592-1.063-2.722-2.524-2.722-1.462 0-2.525 1.127-2.525 2.722 0 1.612 1.063 2.722 2.525 2.722 1.461 0 2.525-1.113 2.525-2.722Zm3.831 4.734v-5.38c0-2.499 1.583-4.294 4.41-4.294 2.806 0 4.39 1.792 4.39 4.294v5.38h-2.525v-5.18c0-1.39-.623-2.259-1.865-2.259-1.243 0-1.865.867-1.865 2.259v5.18h-2.545Zm-12.147-7.436h-2.747v3.528c0 1.23.44 1.793 1.703 1.793.12 0 .42 0 .802-.02v2.075c-.52.14-.981.223-1.484.223-2.124 0-3.569-1.29-3.569-3.728v-3.87h-1.706v-2.036h.427a1.3 1.3 0 0 0 .489-.097 1.285 1.285 0 0 0 .694-.698 1.28 1.28 0 0 0 .096-.492v-1.918h2.545v3.205h2.747v2.035h.003Z"
/>
<path
fill="var(--logo-text-product-color)"
d="M98.882 11.216h3.575l3.351 8.223c.299.69.554 1.393.769 2.11h.035c.215-.717.471-1.424.769-2.11l3.351-8.223h3.575V24.93h-2.59v-9.187a8.055 8.055 0 0 1 .043-.906h-.043c-.08.323-.186.64-.321.946l-3.713 8.987h-2.148l-3.724-8.987a7.46 7.46 0 0 1-.342-.946h-.04c.029.3.043.603.04.906v9.19h-2.587V11.216Zm24.283 4.666c.75.392 1.37.993 1.786 1.727a5.17 5.17 0 0 1 .652 2.614v4.706h-2.268l-.161-1.413a3.18 3.18 0 0 1-1.252 1.21 3.784 3.784 0 0 1-1.818.42 4.364 4.364 0 0 1-2.291-.62 4.476 4.476 0 0 1-1.648-1.75 5.345 5.345 0 0 1-.603-2.573 4.91 4.91 0 0 1 .655-2.514 4.702 4.702 0 0 1 1.808-1.77 5.141 5.141 0 0 1 2.553-.643 5.391 5.391 0 0 1 2.587.606Zm-.83 6.33c.494-.468.738-1.129.738-2.01a2.746 2.746 0 0 0-.706-1.958 2.455 2.455 0 0 0-.813-.56 2.446 2.446 0 0 0-.967-.198 2.465 2.465 0 0 0-1.781.758 3.05 3.05 0 0 0-.712 1.956c0 .715.253 1.407.712 1.956a2.367 2.367 0 0 0 1.786.755 2.438 2.438 0 0 0 1.743-.698Zm4.666-8.692a1.494 1.494 0 0 1-.356-.497 1.429 1.429 0 0 1-.12-.597 1.488 1.488 0 0 1 .476-1.106 1.617 1.617 0 0 1 2.269 0 1.5 1.5 0 0 1 .353.502c.08.192.123.395.12.604a1.458 1.458 0 0 1-.473 1.095 1.645 1.645 0 0 1-2.269 0Zm2.412 11.409h-2.55v-9.45h2.55v9.45Zm4.411 0h-2.553V11.216h2.553V24.93Z"
/>
<defs>
<linearGradient
id={`${uid}-a`}
x1="10.507"
x2="1.116"
y1="23.152"
y2="-9.469"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#E3D9FF" />
<stop offset="1" stopColor="#7341FF" />
</linearGradient>
<linearGradient
id={`${uid}-c`}
x1="37.055"
x2="15.455"
y1="43.522"
y2="-3.075"
gradientUnits="userSpaceOnUse"
>
<stop offset=".271" stopColor="#E3D9FF" />
<stop offset="1" stopColor="#7341FF" />
</linearGradient>
<radialGradient
id={`${uid}-b`}
cx="0"
cy="0"
r="1"
gradientTransform="matrix(27.9882 0 0 26.381 23.895 13.077)"
gradientUnits="userSpaceOnUse"
>
<stop offset=".556" stopColor="#6D4AFF" />
<stop offset=".994" stopColor="#AA8EFF" />
</radialGradient>
</defs>
</>
)}
</svg>
);
};
export default MailLogo;
| 5,471
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/MainLogo.tsx
|
import { AppLink, AppLinkProps } from '@proton/components';
import { useConfig } from '../../hooks';
import Logo from './Logo';
const MainLogo = (props: AppLinkProps) => {
const { APP_NAME } = useConfig();
return (
<AppLink
toApp={APP_NAME}
target="_self"
className="relative interactive-pseudo-protrude interactive--no-background"
{...props}
>
<Logo appName={APP_NAME} />
</AppLink>
);
};
export default MainLogo;
| 5,472
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/PassLogo.tsx
|
import { ComponentPropsWithoutRef, useState } from 'react';
import { generateUID } from '@proton/components';
import { PASS_APP_NAME } from '@proton/shared/lib/constants';
import clsx from '@proton/utils/clsx';
import { LogoProps } from './Logo';
type Props = ComponentPropsWithoutRef<'svg'> & Pick<LogoProps, 'variant' | 'size' | 'hasTitle'>;
const PassLogo = ({ variant = 'with-wordmark', size, className, hasTitle = true, ...rest }: Props) => {
// This logo can be several times in the view, ids has to be different each time
const [uid] = useState(generateUID('logo'));
const logoWidth = variant === 'with-wordmark' ? 142 : 36;
return (
<svg
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
viewBox={`0 0 ${logoWidth} 36`}
width={logoWidth}
height="36"
fill="none"
role="img"
className={clsx('logo', size && variant === 'glyph-only' && `icon-${size}p`, variant, className)}
aria-labelledby={`${uid}-title`}
{...rest}
>
{hasTitle && <title id={`${uid}-title`}>{PASS_APP_NAME}</title>}
{variant === 'glyph-only' && (
<>
<path
fill={`url(#${uid}-a)`}
d="M12.42 7.54c1.95-1.96 2.93-2.93 4.06-3.3a4.93 4.93 0 0 1 3.04 0c1.13.37 2.1 1.34 4.06 3.3l4.88 4.88c1.96 1.95 2.93 2.93 3.3 4.06.32.99.32 2.05 0 3.04-.37 1.13-1.34 2.1-3.3 4.06l-4.88 4.88c-1.95 1.96-2.93 2.93-4.06 3.3-.99.32-2.05.32-3.04 0-1.13-.37-2.1-1.34-4.06-3.3l-.92-1.03a7.87 7.87 0 0 1-1.03-1.28 3.7 3.7 0 0 1-.38-1c-.09-.4-.09-.82-.09-1.66V12.51c0-.84 0-1.26.09-1.65.08-.35.2-.7.38-1 .2-.36.48-.67 1.03-1.3l.92-1.02Z"
/>
<path
fill={`url(#${uid}-b)`}
d="M12.42 7.54c1.95-1.96 2.93-2.93 4.06-3.3a4.93 4.93 0 0 1 3.04 0c1.13.37 2.1 1.34 4.06 3.3l4.88 4.88c1.96 1.95 2.93 2.93 3.3 4.06.32.99.32 2.05 0 3.04-.37 1.13-1.34 2.1-3.3 4.06l-4.88 4.88c-1.95 1.96-2.93 2.93-4.06 3.3-.99.32-2.05.32-3.04 0-1.13-.37-2.1-1.34-4.06-3.3l-.92-1.03a7.87 7.87 0 0 1-1.03-1.28 3.7 3.7 0 0 1-.38-1c-.09-.4-.09-.82-.09-1.66V12.51c0-.84 0-1.26.09-1.65.08-.35.2-.7.38-1 .2-.36.48-.67 1.03-1.3l.92-1.02Z"
/>
<path
fill={`url(#${uid}-c)`}
d="M12.07 7.89c.98-.98 1.47-1.47 2.03-1.65.5-.16 1.03-.16 1.52 0 .57.18 1.05.67 2.03 1.65l7.33 7.32c.97.98 1.46 1.46 1.64 2.03.16.5.16 1.03 0 1.52-.18.56-.67 1.05-1.64 2.03l-7.33 7.32c-.98.98-1.46 1.47-2.03 1.65-.5.16-1.03.16-1.52 0-.56-.18-1.05-.67-2.03-1.65l-4.53-4.53c-1.96-1.95-2.93-2.93-3.3-4.06a4.93 4.93 0 0 1 0-3.04c.37-1.13 1.34-2.1 3.3-4.06l4.53-4.53Z"
/>
<defs>
<radialGradient
id={`${uid}-a`}
cx="0"
cy="0"
r="1"
gradientTransform="rotate(-58.14 35.5 5.08) scale(23.3731 36.5508)"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#FFD580" />
<stop offset=".09" stopColor="#F6C592" />
<stop offset=".2" stopColor="#EBB6A2" />
<stop offset=".32" stopColor="#DFA5AF" />
<stop offset=".43" stopColor="#D397BE" />
<stop offset=".53" stopColor="#C486CB" />
<stop offset=".65" stopColor="#B578D9" />
<stop offset=".77" stopColor="#A166E5" />
<stop offset=".89" stopColor="#8B57F2" />
<stop offset="1" stopColor="#704CFF" />
</radialGradient>
<linearGradient
id={`${uid}-b`}
x1="11.49"
x2="16.93"
y1="-1.56"
y2="31.68"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#6D4AFF" />
<stop offset=".39" stopColor="#B39FFB" stopOpacity=".98" />
<stop offset="1" stopColor="#FFE8DB" stopOpacity=".8" />
</linearGradient>
<radialGradient
id={`${uid}-c`}
cx="0"
cy="0"
r="1"
gradientTransform="matrix(9.923 -15.96803 24.97081 15.51758 10.4 29.7)"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#FFD580" />
<stop offset=".09" stopColor="#F6C592" />
<stop offset=".2" stopColor="#EBB6A2" />
<stop offset=".32" stopColor="#DFA5AF" />
<stop offset=".43" stopColor="#D397BE" />
<stop offset=".53" stopColor="#C486CB" />
<stop offset=".65" stopColor="#B578D9" />
<stop offset=".77" stopColor="#A166E5" />
<stop offset=".89" stopColor="#8B57F2" />
<stop offset="1" stopColor="#704CFF" />
</radialGradient>
</defs>
</>
)}
{variant === 'with-wordmark' && (
<>
<path
fill={`url(#${uid}-a)`}
d="M12.42 7.54c1.95-1.96 2.93-2.93 4.06-3.3a4.93 4.93 0 0 1 3.04 0c1.13.37 2.1 1.34 4.06 3.3l4.88 4.88c1.96 1.95 2.93 2.93 3.3 4.06.32.99.32 2.05 0 3.04-.37 1.13-1.34 2.1-3.3 4.06l-4.88 4.88c-1.95 1.96-2.93 2.93-4.06 3.3-.99.32-2.05.32-3.04 0-1.13-.37-2.1-1.34-4.06-3.3l-.92-1.03a7.87 7.87 0 0 1-1.03-1.28 3.7 3.7 0 0 1-.38-1c-.09-.4-.09-.82-.09-1.66V12.51c0-.84 0-1.26.09-1.65.08-.35.2-.7.38-1 .2-.36.48-.67 1.03-1.3l.92-1.02Z"
/>
<path
fill={`url(#${uid}-b)`}
d="M12.42 7.54c1.95-1.96 2.93-2.93 4.06-3.3a4.93 4.93 0 0 1 3.04 0c1.13.37 2.1 1.34 4.06 3.3l4.88 4.88c1.96 1.95 2.93 2.93 3.3 4.06.32.99.32 2.05 0 3.04-.37 1.13-1.34 2.1-3.3 4.06l-4.88 4.88c-1.95 1.96-2.93 2.93-4.06 3.3-.99.32-2.05.32-3.04 0-1.13-.37-2.1-1.34-4.06-3.3l-.92-1.03a7.87 7.87 0 0 1-1.03-1.28 3.7 3.7 0 0 1-.38-1c-.09-.4-.09-.82-.09-1.66V12.51c0-.84 0-1.26.09-1.65.08-.35.2-.7.38-1 .2-.36.48-.67 1.03-1.3l.92-1.02Z"
/>
<path
fill={`url(#${uid}-c)`}
d="M12.07 7.89c.98-.98 1.47-1.47 2.03-1.65.5-.16 1.03-.16 1.52 0 .57.18 1.05.67 2.03 1.65l7.33 7.32c.97.98 1.46 1.46 1.64 2.03.16.5.16 1.03 0 1.52-.18.56-.67 1.05-1.64 2.03l-7.33 7.32c-.98.98-1.46 1.47-2.03 1.65-.5.16-1.03.16-1.52 0-.56-.18-1.05-.67-2.03-1.65l-4.53-4.53c-1.96-1.95-2.93-2.93-3.3-4.06a4.93 4.93 0 0 1 0-3.04c.37-1.13 1.34-2.1 3.3-4.06l4.53-4.53Z"
/>
<path
fill="var(--logo-text-product-color)"
d="M119.02 15.65a4.82 4.82 0 0 0-4.98 4.9c0 2.96 2.04 4.92 4.5 4.92 1.36 0 2.44-.6 3.04-1.62l.16 1.4h2.24v-4.68c0-3.04-2.12-4.92-4.96-4.92Zm0 7.6c-1.42 0-2.48-1.1-2.48-2.7s1.08-2.7 2.48-2.7c1.38 0 2.46 1.06 2.46 2.7 0 1.84-1.24 2.7-2.46 2.7Zm9.87 2.22c1.92 0 3.56-1.1 3.56-2.78 0-3.6-4.86-2.76-4.86-4.22 0-.48.42-.84 1.08-.84.68 0 1.12.38 1.22.94h2.38c-.14-1.84-1.54-2.94-3.6-2.92-2.12 0-3.42 1.26-3.42 2.82 0 3.64 4.8 2.7 4.8 4.22 0 .46-.44.8-1.16.8-.7 0-1.34-.34-1.46-1.06H125c.14 1.78 1.7 3.04 3.88 3.04Zm8.41 0c1.92 0 3.56-1.1 3.56-2.78 0-3.6-4.86-2.76-4.86-4.22 0-.48.42-.84 1.08-.84.68 0 1.12.38 1.22.94h2.38c-.14-1.84-1.54-2.94-3.6-2.92-2.12 0-3.42 1.26-3.42 2.82 0 3.64 4.8 2.7 4.8 4.22 0 .46-.44.8-1.16.8-.7 0-1.34-.34-1.46-1.06h-2.42c.14 1.78 1.7 3.04 3.88 3.04ZM109.47 11h-6.57v14.25h2.6V21.7a1.3 1.3 0 0 1 1.3-1.3h2.67a4.68 4.68 0 0 0 4.34-6.49 4.67 4.67 0 0 0-4.34-2.91Zm2.05 4.67a2.2 2.2 0 0 1-.65 1.58 2.2 2.2 0 0 1-1.57.64h-3.8v-4.43h3.8a2.22 2.22 0 0 1 2.22 2.23v-.02Z"
/>
<path
fill="var(--logo-text-proton-color)"
d="M42 21.26v3.66h2.56v-3.5a1.28 1.28 0 0 1 1.28-1.29h2.62a4.6 4.6 0 0 0 4.62-4.64 4.66 4.66 0 0 0-4.62-4.64H42v4.58h2.56v-2.16h3.73a2.18 2.18 0 0 1 2.18 2.2 2.2 2.2 0 0 1-2.18 2.2h-2.71a3.51 3.51 0 0 0-2.53 1.05A3.65 3.65 0 0 0 42 21.26Zm11.47 3.66v-5.58c0-2.28 1.32-4.09 3.97-4.09.42 0 .85.04 1.26.14v2.3c-.3-.02-.56-.02-.68-.02-1.4 0-2 .64-2 1.95v5.3h-2.55Zm5.99-4.73c0-2.8 2.1-4.94 5.04-4.94a4.85 4.85 0 0 1 5.03 4.94c0 2.8-2.1 4.96-5.03 4.96a4.87 4.87 0 0 1-5.04-4.96Zm7.56 0c0-1.6-1.06-2.72-2.52-2.72-1.47 0-2.53 1.12-2.53 2.72 0 1.61 1.07 2.72 2.53 2.72 1.46 0 2.52-1.11 2.52-2.72Zm10.65 0c0-2.8 2.1-4.94 5.03-4.94a4.85 4.85 0 0 1 5.03 4.94c0 2.8-2.1 4.96-5.03 4.96a4.87 4.87 0 0 1-5.03-4.96Zm7.55 0c0-1.6-1.06-2.72-2.52-2.72s-2.53 1.12-2.53 2.72c0 1.61 1.07 2.72 2.53 2.72 1.46 0 2.52-1.11 2.52-2.72Zm3.83 4.73v-5.38c0-2.5 1.59-4.29 4.41-4.29 2.8 0 4.4 1.8 4.4 4.3v5.37h-2.53v-5.18c0-1.39-.62-2.25-1.87-2.25-1.24 0-1.86.86-1.86 2.25v5.18h-2.55ZM76.9 17.49h-2.74v3.53c0 1.23.44 1.79 1.7 1.79.12 0 .42 0 .8-.02v2.07c-.52.14-.98.23-1.48.23-2.12 0-3.57-1.3-3.57-3.73v-3.87h-1.7v-2.04h.42a1.3 1.3 0 0 0 .9-.37 1.3 1.3 0 0 0 .38-.91v-1.92h2.55v3.2h2.74v2.04Z"
/>
<defs>
<radialGradient
id={`${uid}-a`}
cx="0"
cy="0"
r="1"
gradientTransform="rotate(-58.14 35.5 5.08) scale(23.3731 36.5508)"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#FFD580" />
<stop offset=".09" stopColor="#F6C592" />
<stop offset=".2" stopColor="#EBB6A2" />
<stop offset=".32" stopColor="#DFA5AF" />
<stop offset=".43" stopColor="#D397BE" />
<stop offset=".53" stopColor="#C486CB" />
<stop offset=".65" stopColor="#B578D9" />
<stop offset=".77" stopColor="#A166E5" />
<stop offset=".89" stopColor="#8B57F2" />
<stop offset="1" stopColor="#704CFF" />
</radialGradient>
<linearGradient
id={`${uid}-b`}
x1="11.49"
x2="16.93"
y1="-1.56"
y2="31.68"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#6D4AFF" />
<stop offset=".39" stopColor="#B39FFB" stopOpacity=".98" />
<stop offset="1" stopColor="#FFE8DB" stopOpacity=".8" />
</linearGradient>
<radialGradient
id={`${uid}-c`}
cx="0"
cy="0"
r="1"
gradientTransform="matrix(9.923 -15.96803 24.97081 15.51758 10.4 29.7)"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#FFD580" />
<stop offset=".09" stopColor="#F6C592" />
<stop offset=".2" stopColor="#EBB6A2" />
<stop offset=".32" stopColor="#DFA5AF" />
<stop offset=".43" stopColor="#D397BE" />
<stop offset=".53" stopColor="#C486CB" />
<stop offset=".65" stopColor="#B578D9" />
<stop offset=".77" stopColor="#A166E5" />
<stop offset=".89" stopColor="#8B57F2" />
<stop offset="1" stopColor="#704CFF" />
</radialGradient>
</defs>
</>
)}
</svg>
);
};
export default PassLogo;
| 5,473
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/ProtonForBusinessLogo.tsx
|
import { ComponentPropsWithoutRef, useState } from 'react';
import { generateUID } from '@proton/components';
import { LogoProps } from './Logo';
type Props = ComponentPropsWithoutRef<'svg'> & Pick<LogoProps, 'variant' | 'size' | 'hasTitle'>;
const ProtonForBusinessLogo = ({ ...rest }: Props) => {
// This logo can be several times in the view, ids has to be different each time
const [uid] = useState(generateUID('logo'));
return (
<svg
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
width="146"
height="36"
viewBox="0 0 146 36"
fill="none"
role="img"
aria-labelledby={`${uid}-title`}
{...rest}
>
<rect width="146" height="36" fill="white" />
<path
d="M69.2681 24.7433V14.0742H75.3465V15.4235H70.6788V18.7812H75.1363V20.1305H70.6788V24.7433H69.2681Z"
fill="currentColor"
/>
<path
d="M81.988 23.8025C81.297 24.5347 80.4367 24.9008 79.4061 24.9008C78.3756 24.9008 77.5102 24.5347 76.8098 23.8025C76.1196 23.0599 75.7742 22.1499 75.7742 21.0725C75.7742 19.9951 76.1196 19.0903 76.8098 18.3582C77.5102 17.6155 78.3756 17.2441 79.4061 17.2441C80.4367 17.2441 81.297 17.6155 81.988 18.3582C82.6883 19.0903 83.0381 19.9951 83.0381 21.0725C83.0381 22.1499 82.6883 23.0599 81.988 23.8025ZM77.7858 19.2681C77.3654 19.7388 77.1552 20.3403 77.1552 21.0725C77.1552 21.8047 77.3654 22.4061 77.7858 22.8768C78.2156 23.3475 78.756 23.5829 79.4061 23.5829C80.0563 23.5829 80.5916 23.3475 81.012 22.8768C81.4425 22.4061 81.6578 21.8047 81.6578 21.0725C81.6578 20.3403 81.4425 19.7388 81.012 19.2681C80.5916 18.7974 80.0563 18.5621 79.4061 18.5621C78.756 18.5621 78.2156 18.7974 77.7858 19.2681Z"
fill="currentColor"
/>
<path
d="M84.3878 20.0997C84.3878 19.2106 84.6285 18.515 85.1085 18.0129C85.5885 17.5004 86.2191 17.2441 86.9994 17.2441C87.2496 17.2441 87.5049 17.2808 87.7645 17.354V18.6719C87.6751 18.6615 87.4947 18.6563 87.2249 18.6563C86.7544 18.6563 86.3944 18.7922 86.1442 19.0642C85.894 19.3361 85.7689 19.7963 85.7689 20.4449V24.7439H84.3878V20.0997Z"
fill="currentColor"
/>
<path
d="M92.7327 24.7433V14.0742H95.9145C97.065 14.0742 97.9159 14.3357 98.4657 14.8587C99.0265 15.3817 99.3064 16.0982 99.3064 17.0082C99.3064 17.6044 99.1363 18.1013 98.7959 18.4987C98.4657 18.8963 98.0759 19.1368 97.6257 19.2205V19.2519C98.2563 19.3355 98.7763 19.5866 99.1865 20.005C99.6068 20.4234 99.817 20.9778 99.817 21.6681C99.817 22.6199 99.5115 23.373 98.9014 23.9274C98.2912 24.4714 97.4054 24.7433 96.2446 24.7433H92.7327ZM94.1436 23.394H96.1399C97.6308 23.394 98.3763 22.8187 98.3763 21.6681C98.3763 21.0824 98.1661 20.6482 97.7457 20.3659C97.3355 20.0835 96.6897 19.9422 95.8097 19.9422H94.1436V23.394ZM94.1436 18.5929H95.8097C96.5297 18.5929 97.0505 18.4674 97.3705 18.2163C97.7006 17.9653 97.8657 17.5626 97.8657 17.0082C97.8657 15.9518 97.1806 15.4235 95.8097 15.4235H94.1436V18.5929Z"
fill="currentColor"
/>
<path
d="M106.362 24.0214C105.821 24.6073 105.096 24.9001 104.186 24.9001C103.275 24.9001 102.55 24.6073 102.01 24.0214C101.469 23.4357 101.199 22.6774 101.199 21.7465V17.4004H102.58V21.6367C102.58 22.2433 102.715 22.714 102.985 23.0487C103.255 23.3834 103.656 23.5508 104.186 23.5508C104.716 23.5508 105.116 23.3834 105.386 23.0487C105.656 22.714 105.792 22.2433 105.792 21.6367V17.4004H107.173V21.7465C107.173 22.6774 106.902 23.4357 106.362 24.0214Z"
fill="currentColor"
/>
<path
d="M111.413 24.9008C110.633 24.9008 109.987 24.6811 109.477 24.2418C108.977 23.8025 108.706 23.2115 108.666 22.4689H110.047C110.087 22.8349 110.232 23.1279 110.482 23.3475C110.743 23.5672 111.053 23.677 111.413 23.677C111.783 23.677 112.069 23.5933 112.269 23.4259C112.469 23.2586 112.569 23.0547 112.569 22.8141C112.569 22.5316 112.439 22.3067 112.178 22.1394C111.919 21.9616 111.603 21.8203 111.233 21.7158C110.873 21.6112 110.508 21.4856 110.138 21.3392C109.778 21.1928 109.467 20.9574 109.207 20.6331C108.947 20.3089 108.817 19.8958 108.817 19.3937C108.817 18.8184 109.032 18.3163 109.462 17.8875C109.893 17.4586 110.487 17.2441 111.248 17.2441C111.968 17.2441 112.559 17.4481 113.019 17.8561C113.479 18.264 113.744 18.8341 113.815 19.5662H112.434C112.324 18.8341 111.928 18.468 111.248 18.468C110.948 18.468 110.698 18.5516 110.498 18.719C110.298 18.8864 110.197 19.1113 110.197 19.3937C110.197 19.6761 110.327 19.901 110.588 20.0683C110.848 20.2357 111.158 20.3717 111.518 20.4763C111.888 20.5808 112.253 20.7064 112.614 20.8528C112.984 20.9888 113.299 21.2241 113.559 21.5589C113.82 21.8831 113.949 22.3015 113.949 22.8141C113.949 23.4208 113.709 23.9228 113.229 24.3202C112.749 24.7073 112.143 24.9008 111.413 24.9008Z"
fill="currentColor"
/>
<path
d="M115.284 24.7431V17.4003H116.665V24.7431H115.284ZM115.329 15.7215C115.159 15.5436 115.074 15.324 115.074 15.0625C115.074 14.801 115.159 14.5813 115.329 14.4035C115.509 14.2152 115.725 14.1211 115.975 14.1211C116.225 14.1211 116.435 14.2152 116.605 14.4035C116.785 14.5813 116.875 14.801 116.875 15.0625C116.875 15.324 116.785 15.5436 116.605 15.7215C116.435 15.8993 116.225 15.9882 115.975 15.9882C115.725 15.9882 115.509 15.8993 115.329 15.7215Z"
fill="currentColor"
/>
<path
d="M118.479 20.3978C118.479 19.4669 118.754 18.7086 119.304 18.1228C119.855 17.537 120.595 17.2441 121.525 17.2441C122.456 17.2441 123.196 17.537 123.746 18.1228C124.297 18.7086 124.572 19.4669 124.572 20.3978V24.7439H123.191V20.5077C123.191 19.8905 123.051 19.4146 122.771 19.0798C122.491 18.7347 122.076 18.5621 121.525 18.5621C120.975 18.5621 120.56 18.7347 120.28 19.0798C119.999 19.4146 119.86 19.8905 119.86 20.5077V24.7439H118.479V20.3978Z"
fill="currentColor"
/>
<path
d="M129.47 24.9008C128.439 24.9008 127.589 24.5452 126.919 23.8339C126.258 23.1227 125.928 22.2021 125.928 21.0725C125.928 19.9428 126.258 19.0223 126.919 18.311C127.579 17.5998 128.43 17.2441 129.47 17.2441C130.401 17.2441 131.191 17.6155 131.841 18.3582C132.502 19.0903 132.832 19.9951 132.832 21.0725C132.832 21.3026 132.822 21.4909 132.802 21.6374H127.354C127.454 22.2336 127.694 22.7095 128.074 23.0651C128.465 23.4103 128.93 23.5829 129.47 23.5829C130.34 23.5829 130.931 23.2377 131.241 22.5473H132.652C132.441 23.2586 132.046 23.8287 131.466 24.2576C130.896 24.6864 130.231 24.9008 129.47 24.9008ZM127.369 20.4449H131.406C131.356 19.9323 131.151 19.4931 130.791 19.127C130.431 18.7504 129.991 18.5621 129.47 18.5621C128.93 18.5621 128.47 18.7347 128.089 19.0798C127.719 19.4146 127.479 19.8696 127.369 20.4449Z"
fill="currentColor"
/>
<path
d="M136.622 24.9008C135.842 24.9008 135.196 24.6811 134.686 24.2418C134.186 23.8025 133.916 23.2115 133.876 22.4689H135.256C135.296 22.8349 135.442 23.1279 135.692 23.3475C135.952 23.5672 136.262 23.677 136.622 23.677C136.992 23.677 137.277 23.5933 137.478 23.4259C137.678 23.2586 137.778 23.0547 137.778 22.8141C137.778 22.5316 137.647 22.3067 137.388 22.1394C137.127 21.9616 136.812 21.8203 136.442 21.7158C136.082 21.6112 135.716 21.4856 135.346 21.3392C134.986 21.1928 134.676 20.9574 134.416 20.6331C134.156 20.3089 134.026 19.8958 134.026 19.3937C134.026 18.8184 134.241 18.3163 134.671 17.8875C135.101 17.4586 135.697 17.2441 136.457 17.2441C137.178 17.2441 137.767 17.4481 138.228 17.8561C138.688 18.264 138.954 18.8341 139.023 19.5662H137.643C137.532 18.8341 137.138 18.468 136.457 18.468C136.157 18.468 135.907 18.5516 135.706 18.719C135.506 18.8864 135.407 19.1113 135.407 19.3937C135.407 19.6761 135.537 19.901 135.796 20.0683C136.057 20.2357 136.367 20.3717 136.727 20.4763C137.098 20.5808 137.463 20.7064 137.823 20.8528C138.193 20.9888 138.508 21.2241 138.768 21.5589C139.028 21.8831 139.159 22.3015 139.159 22.8141C139.159 23.4208 138.919 23.9228 138.438 24.3202C137.958 24.7073 137.353 24.9008 136.622 24.9008Z"
fill="currentColor"
/>
<path
d="M142.924 24.9008C142.144 24.9008 141.498 24.6811 140.988 24.2418C140.488 23.8025 140.217 23.2115 140.177 22.4689H141.558C141.598 22.8349 141.743 23.1279 141.993 23.3475C142.254 23.5672 142.564 23.677 142.924 23.677C143.294 23.677 143.58 23.5933 143.78 23.4259C143.98 23.2586 144.08 23.0547 144.08 22.8141C144.08 22.5316 143.95 22.3067 143.689 22.1394C143.43 21.9616 143.114 21.8203 142.744 21.7158C142.384 21.6112 142.019 21.4856 141.649 21.3392C141.289 21.1928 140.978 20.9574 140.718 20.6331C140.458 20.3089 140.328 19.8958 140.328 19.3937C140.328 18.8184 140.543 18.3163 140.973 17.8875C141.404 17.4586 141.998 17.2441 142.759 17.2441C143.479 17.2441 144.07 17.4481 144.53 17.8561C144.99 18.264 145.255 18.8341 145.326 19.5662H143.945C143.835 18.8341 143.439 18.468 142.759 18.468C142.459 18.468 142.209 18.5516 142.009 18.719C141.809 18.8864 141.708 19.1113 141.708 19.3937C141.708 19.6761 141.838 19.901 142.099 20.0683C142.359 20.2357 142.669 20.3717 143.029 20.4763C143.399 20.5808 143.764 20.7064 144.125 20.8528C144.495 20.9888 144.81 21.2241 145.07 21.5589C145.331 21.8831 145.46 22.3015 145.46 22.8141C145.46 23.4208 145.22 23.9228 144.74 24.3202C144.26 24.7073 143.654 24.9008 142.924 24.9008Z"
fill="currentColor"
/>
<path
d="M12.4133 24.6506V18.4023C12.4133 15.8531 13.842 13.8229 16.6998 13.8229C17.1585 13.8159 17.6162 13.8689 18.0622 13.9806V16.5511C17.7375 16.5286 17.4566 16.5286 17.3265 16.5286C15.8127 16.5286 15.1617 17.2503 15.1617 18.7166V24.6506H12.4133Z"
fill="currentColor"
/>
<path
d="M18.8848 19.3509C18.8848 16.2153 21.1578 13.8242 24.3187 13.8242C27.4796 13.8242 29.7519 16.2137 29.7519 19.3509C29.7519 22.488 27.4789 24.8984 24.3183 24.8984C21.1578 24.8984 18.8848 22.4849 18.8848 19.3509ZM27.0463 19.3509C27.0463 17.5687 25.8988 16.3056 24.3187 16.3056C22.7386 16.3056 21.5908 17.5675 21.5908 19.3509C21.5908 21.1554 22.7383 22.3961 24.3187 22.3961C25.8992 22.3961 27.0463 21.1538 27.0463 19.3509Z"
fill="currentColor"
/>
<path
d="M37.7184 16.3269H34.7529V20.2745C34.7529 21.6505 35.2289 22.2822 36.5929 22.2822C36.7227 22.2822 37.047 22.2822 37.4588 22.2598V24.5833C36.896 24.7411 36.3991 24.8314 35.8568 24.8314C33.5622 24.8314 32.0033 23.3876 32.0033 20.6582V16.3269H30.1632V14.0487H30.6219C30.8034 14.0487 30.9832 14.0114 31.1509 13.9389C31.3186 13.8665 31.4709 13.7603 31.5992 13.6265C31.7275 13.4927 31.8292 13.3338 31.8985 13.159C31.9679 12.9842 32.0035 12.7968 32.0033 12.6077V10.4619H34.7529V14.0487H37.7184V16.3269Z"
fill="currentColor"
/>
<path
d="M38.5409 19.3509C38.5409 16.2153 40.814 13.8242 43.9749 13.8242C47.1358 13.8242 49.4085 16.2137 49.4085 19.3509C49.4085 22.488 47.1354 24.8999 43.9749 24.8999C40.8143 24.8999 38.5409 22.4849 38.5409 19.3509ZM46.7021 19.3509C46.7021 17.5687 45.5546 16.3056 43.9745 16.3056C42.3944 16.3056 41.2466 17.5675 41.2466 19.3509C41.2466 21.1554 42.394 22.3961 43.9745 22.3961C45.555 22.3961 46.7021 21.1538 46.7021 19.3509Z"
fill="currentColor"
/>
<path
d="M50.8378 24.6509V18.6282C50.8378 15.831 52.5481 13.8232 55.6004 13.8232C58.6311 13.8232 60.3414 15.831 60.3414 18.6282V24.6509H57.6138V18.8538C57.6138 17.2976 56.9424 16.3275 55.6004 16.3275C54.2583 16.3275 53.5869 17.2976 53.5869 18.8538V24.6509H50.8378Z"
fill="currentColor"
/>
<path
d="M6.68209e-07 20.5488V24.6501H2.76277V20.7262C2.76277 20.3445 2.90831 19.9783 3.16737 19.7084C3.42643 19.4384 3.77779 19.2868 4.14416 19.2868H6.97695C8.29843 19.2864 9.5657 18.7391 10.5 17.7652C11.4343 16.7914 11.9593 15.4708 11.9594 14.0938C11.9594 12.7165 11.4344 11.3957 10.4999 10.4218C9.5654 9.44785 8.29792 8.9006 6.97619 8.90039H6.68209e-07V14.0271H2.76277V11.6101H6.78999C7.41531 11.6101 8.01501 11.8689 8.45719 12.3295C8.89944 12.7902 9.14795 13.415 9.14817 14.0666C9.14817 14.7183 8.89974 15.3433 8.45748 15.8041C8.01523 16.2649 7.41545 16.5238 6.78999 16.5238H3.86221C3.35491 16.5236 2.85255 16.6276 2.38382 16.8297C1.9151 17.0319 1.48922 17.3283 1.13052 17.7022C0.771829 18.076 0.487362 18.5198 0.293378 19.0082C0.0993944 19.4966 -0.000297801 20.0201 6.68209e-07 20.5488Z"
fill="currentColor"
/>
</svg>
);
};
export default ProtonForBusinessLogo;
| 5,474
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/ProtonLogo.tsx
|
import { ComponentPropsWithoutRef, useState } from 'react';
import { LogoProps, generateUID } from '@proton/components';
import { BRAND_NAME } from '@proton/shared/lib/constants';
import clsx from '@proton/utils/clsx';
type Version = 'full' | 'glyph-only';
type Color = 'brand' | 'invert';
interface Props extends ComponentPropsWithoutRef<'svg'>, Pick<LogoProps, 'size'> {
variant?: Version;
color?: Color;
}
const ProtonLogo = ({ variant = 'full', size, color = 'brand', className, ...rest }: Props) => {
// This logo can be several times in the view, ids has to be different each time
const [uid] = useState(generateUID('logo'));
const brandColor = '#6351E1';
const invertColor = 'white';
return variant === 'full' ? (
<svg
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
viewBox="0 0 96 36"
width="96"
height="36"
fill="none"
role="img"
className={clsx('logo', size && `icon-${size}p`, variant, className)}
aria-labelledby={`${uid}-title`}
{...rest}
>
<title id={`${uid}-title`}>{BRAND_NAME}</title>
<path
fill={color === 'brand' ? brandColor : invertColor}
d="M0 23.793v6.265h4.397v-5.993a2.199 2.199 0 0 1 2.199-2.199h4.509a7.933 7.933 0 0 0 7.932-7.932A7.932 7.932 0 0 0 11.105 6H0v7.83h4.397v-3.69h6.41a3.754 3.754 0 0 1 3.753 3.753 3.754 3.754 0 0 1-3.753 3.753h-4.66A6.146 6.146 0 0 0 0 23.793z"
/>
<path
fill={color === 'brand' ? `url(#${uid}-a)` : undefined}
d="M6.595 21.865A6.594 6.594 0 0 0 0 28.46v1.597h4.397v-5.993a2.199 2.199 0 0 1 2.198-2.199z"
/>
<path
fill={color === 'brand' ? brandColor : invertColor}
d="M19.717 30.058v-9.544c0-3.894 2.274-6.995 6.822-6.995.73-.01 1.459.07 2.169.24v3.928c-.518-.034-.964-.034-1.172-.034-2.41 0-3.445 1.103-3.445 3.343v9.06l-4.374.002zm10.301-8.098c0-4.789 3.617-8.441 8.648-8.441s8.649 3.652 8.649 8.442c0 4.789-3.618 8.476-8.649 8.476-5.03 0-8.648-3.688-8.648-8.476zm12.99 0c0-2.722-1.827-4.65-4.342-4.65-2.514 0-4.341 1.927-4.341 4.65 0 2.757 1.826 4.652 4.341 4.652 2.516 0 4.342-1.895 4.342-4.651zm18.295 0c0-4.789 3.618-8.441 8.648-8.441 5.031 0 8.649 3.652 8.649 8.442 0 4.789-3.618 8.476-8.648 8.476-5.03 0-8.65-3.688-8.65-8.476zm12.99 0c0-2.722-1.827-4.65-4.342-4.65-2.514 0-4.341 1.927-4.341 4.65 0 2.757 1.826 4.652 4.341 4.652 2.516 0 4.343-1.895 4.343-4.651h-.001zm6.58 8.098v-9.2c0-4.272 2.722-7.339 7.58-7.339 4.824 0 7.546 3.067 7.546 7.34v9.199H91.66v-8.855c0-2.378-1.068-3.86-3.204-3.86s-3.205 1.482-3.205 3.86v8.855h-4.378zM59.994 17.343h-4.72v6.032c0 2.102.757 3.066 2.928 3.066.207 0 .723 0 1.379-.034v3.549c-.896.241-1.687.379-2.55.379-3.652 0-6.134-2.205-6.134-6.374v-6.618H47.97v-3.48h.73a2.199 2.199 0 0 0 2.198-2.198v-3.28h4.377v5.481h4.72v3.477z"
/>
{color === 'brand' && (
<defs>
<linearGradient
id={`${uid}-a`}
x1="3.297"
x2="3.297"
y1="28.872"
y2="19.667"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#6D4BFD" />
<stop offset="1" stopColor="#1C0554" />
</linearGradient>
</defs>
)}
</svg>
) : (
<svg
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
viewBox="0 0 36 36"
width="36"
height="36"
fill="none"
className={clsx(['logo', size && `icon-${size}p`, variant, className])}
aria-labelledby={`${uid}-title`}
{...rest}
>
<title id={`${uid}-title`}>{BRAND_NAME}</title>
<path
fill={`url(#${uid}-a)`}
d="M3.78 26.584v9.36h6.57V26.99a3.285 3.285 0 0 1 3.284-3.285h6.737a11.852 11.852 0 0 0 11.851-11.852A11.851 11.851 0 0 0 20.371 0H3.779v11.7h6.57V6.183h9.577a5.608 5.608 0 1 1 0 11.215h-6.963a9.18 9.18 0 0 0-9.184 9.186z"
/>
<path
fill={`url(#${uid}-b)`}
d="M13.633 23.704a9.853 9.853 0 0 0-9.854 9.853v2.386h6.57V26.99a3.285 3.285 0 0 1 3.284-3.285z"
/>
<defs>
<radialGradient
id={`${uid}-a`}
cx="0"
cy="0"
r="1"
gradientTransform="translate(32.323 -4.99) scale(36.1773)"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#A995FF" />
<stop offset="1" stopColor="#6652F5" />
</radialGradient>
<linearGradient
id={`${uid}-b`}
x1="8.706"
x2="8.706"
y1="34.173"
y2="20.419"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#6D4BFD" />
<stop offset="1" stopColor="#1C0554" />
</linearGradient>
</defs>
</svg>
);
};
export default ProtonLogo;
| 5,475
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/VpnForBusinessLogo.tsx
|
import { ComponentPropsWithoutRef, useState } from 'react';
import { generateUID } from '@proton/components';
import { LogoProps } from './Logo';
type Props = ComponentPropsWithoutRef<'svg'> & Pick<LogoProps, 'variant' | 'size' | 'hasTitle'>;
const VpnForBusinessLogo = ({ ...rest }: Props) => {
// This logo can be several times in the view, ids has to be different each time
const [uid] = useState(generateUID('logo'));
return (
<svg
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
width="249"
height="48"
viewBox="0 0 249 48"
fill="none"
role="img"
aria-labelledby={`${uid}-title`}
{...rest}
>
<g clipPath="url(#clip0_631_54368)">
<path
d="M0 28.0379V32.9245H3.41208V28.2513C3.41208 27.7977 3.59027 27.3594 3.91252 27.0392C4.23098 26.719 4.66697 26.536 5.11812 26.536H8.6174C10.2476 26.536 11.8134 25.8842 12.9659 24.7216C14.1184 23.5629 14.7667 21.9886 14.7667 20.3496C14.7667 18.7105 14.1184 17.1363 12.9659 15.9737C11.8134 14.8149 10.2476 14.1631 8.61361 14.1631H0V20.2695H3.41208V17.3916H8.38613C9.15954 17.3916 9.89882 17.7004 10.4448 18.2493C10.9907 18.7982 11.2978 19.5415 11.2978 20.3191C11.2978 21.0967 10.9907 21.84 10.4448 22.3889C9.89882 22.9377 9.15954 23.2465 8.38613 23.2465H4.77312C4.14757 23.2465 3.52582 23.3685 2.94955 23.6124C2.3695 23.8526 1.84631 24.2071 1.40274 24.653C0.959173 25.099 0.610386 25.6288 0.367749 26.2082C0.125112 26.7838 0 27.4089 0 28.0379Z"
fill="currentColor"
/>
<path
d="M15.2937 32.9245V25.4802C15.2937 22.4422 17.0566 20.0256 20.5862 20.0256C21.1511 20.0179 21.716 20.0789 22.2695 20.2123V23.2732C21.8677 23.2465 21.5227 23.2465 21.3596 23.2465C19.4906 23.2465 18.6868 24.1079 18.6868 25.8537V32.9245H15.2937Z"
fill="currentColor"
/>
<path
d="M23.2854 26.6123C23.2854 22.8768 26.0909 20.0294 29.9959 20.0294C33.9008 20.0294 36.7063 22.8768 36.7063 26.6123C36.7063 30.3478 33.9008 33.2219 29.9959 33.2219C26.0909 33.2219 23.2854 30.344 23.2854 26.6123ZM33.3625 26.6123C33.3625 24.4892 31.9445 22.9835 29.9959 22.9835C28.0434 22.9835 26.6293 24.4854 26.6293 26.6123C26.6293 28.7622 28.0472 30.2411 29.9959 30.2411C31.9483 30.2411 33.3625 28.7583 33.3625 26.6123Z"
fill="currentColor"
/>
<path
d="M47.5568 26.6123C47.5568 22.8768 50.3623 20.0294 54.2672 20.0294C58.1684 20.0294 60.9738 22.8768 60.9738 26.6123C60.9738 30.3478 58.1684 33.2219 54.2672 33.2219C50.3623 33.2219 47.5568 30.344 47.5568 26.6123ZM57.63 26.6123C57.63 24.4892 56.2121 22.9835 54.2634 22.9835C52.3148 22.9835 50.8969 24.4854 50.8969 26.6123C50.8969 28.7622 52.3148 30.2411 54.2634 30.2411C56.2121 30.2411 57.63 28.7583 57.63 26.6123Z"
fill="currentColor"
/>
<path
d="M62.7368 32.9246V25.7509C62.7368 22.4194 64.8485 20.0256 68.617 20.0256C72.3589 20.0256 74.4706 22.4156 74.4706 25.7509V32.9246H71.104V26.0177C71.104 24.1652 70.2737 23.0064 68.617 23.0064C66.9602 23.0064 66.1299 24.1614 66.1299 26.0177V32.9246H62.7368Z"
fill="currentColor"
/>
<path
d="M46.5408 23.01H42.8785V27.7137C42.8785 29.3528 43.4661 30.1037 45.1494 30.1037C45.3086 30.1037 45.7105 30.1037 46.2185 30.077V32.8444C45.5247 33.0311 44.9105 33.1417 44.2395 33.1417C41.4075 33.1417 39.4815 31.4226 39.4815 28.1711V23.01H37.2068V20.2961H37.7755C37.9992 20.2961 38.2229 20.2503 38.4276 20.1665C38.6361 20.0788 38.8219 19.953 38.9811 19.7929C39.1403 19.6328 39.2654 19.446 39.3526 19.2364C39.4398 19.0267 39.4815 18.8057 39.4815 18.5808V16.0231H42.8747V20.2961H46.537V23.01H46.5408Z"
fill="currentColor"
/>
<path
d="M109.417 14.2213H100.655V33.2219H104.126V28.492C104.126 28.0326 104.307 27.5885 104.635 27.2642C104.959 26.9399 105.402 26.7545 105.861 26.7545H109.417C111.076 26.7545 112.665 26.0943 113.833 24.9243C115.006 23.7506 115.662 22.1598 115.662 20.5034C115.665 19.6809 115.507 18.8624 115.195 18.1017C114.882 17.3411 114.424 16.6461 113.841 16.0631C113.259 15.48 112.572 15.0167 111.812 14.7001C111.056 14.3835 110.243 14.2213 109.417 14.2213ZM112.152 20.4532C112.152 20.8431 112.075 21.2293 111.924 21.5883C111.774 21.9474 111.558 22.2756 111.28 22.5498C111.006 22.8239 110.679 23.044 110.32 23.1907C109.961 23.3413 109.575 23.4146 109.186 23.4146H104.11V17.4955H109.186C109.575 17.4955 109.961 17.5728 110.324 17.7233C110.682 17.8739 111.01 18.094 111.284 18.3682C111.558 18.6462 111.778 18.9744 111.924 19.3334C112.071 19.6964 112.148 20.0825 112.144 20.4725L112.152 20.4532Z"
fill="currentColor"
/>
<path
d="M88.463 33.1525L81.4706 14.1673H85.42L90.0212 27.7546C90.2025 28.2411 90.3336 28.743 90.4108 29.2566H90.4493C90.5072 28.7392 90.6383 28.2334 90.8389 27.7546L95.4555 14.1673H99.4319L92.4048 33.1525H88.463Z"
fill="currentColor"
/>
<path
d="M116.961 33.1521V14.1631H120.004L128.96 25.9395C129.284 26.3449 129.562 26.7812 129.797 27.2446H129.851C129.789 26.6731 129.762 26.0978 129.766 25.5225V14.1631H133.353V33.1482H130.31L121.327 21.3718C121.011 20.9625 120.733 20.5262 120.494 20.0667H120.463C120.513 20.6382 120.533 21.2135 120.521 21.7888V33.1482H116.961V33.1521Z"
fill="currentColor"
/>
<path
d="M144.353 33.1701V18.5H152.711V20.3553H146.293V24.9721H152.422V26.8274H146.293V33.1701H144.353Z"
fill="currentColor"
/>
<path
d="M161.842 31.8757C160.893 32.8824 159.71 33.3858 158.293 33.3858C156.876 33.3858 155.686 32.8824 154.723 31.8757C153.774 30.8545 153.299 29.6032 153.299 28.1218C153.299 26.6405 153.774 25.3964 154.723 24.3896C155.686 23.3685 156.876 22.8579 158.293 22.8579C159.71 22.8579 160.893 23.3685 161.842 24.3896C162.805 25.3964 163.287 26.6405 163.287 28.1218C163.287 29.6032 162.805 30.8545 161.842 31.8757ZM156.064 25.6409C155.486 26.2881 155.198 27.1151 155.198 28.1218C155.198 29.1286 155.486 29.9556 156.064 30.6028C156.656 31.25 157.399 31.5736 158.293 31.5736C159.187 31.5736 159.923 31.25 160.501 30.6028C161.093 29.9556 161.388 29.1286 161.388 28.1218C161.388 27.1151 161.093 26.2881 160.501 25.6409C159.923 24.9937 159.187 24.6701 158.293 24.6701C157.399 24.6701 156.656 24.9937 156.064 25.6409Z"
fill="currentColor"
/>
<path
d="M165.143 26.7843C165.143 25.5618 165.473 24.6053 166.134 23.915C166.794 23.2102 167.661 22.8579 168.734 22.8579C169.078 22.8579 169.429 22.9082 169.786 23.0089V24.8211C169.662 24.8067 169.415 24.7995 169.043 24.7995C168.397 24.7995 167.901 24.9865 167.558 25.3604C167.214 25.7344 167.042 26.3672 167.042 27.2589V33.1701H165.143V26.7843Z"
fill="currentColor"
/>
<path
d="M176.617 33.1701V18.5H180.992C182.574 18.5 183.744 18.8596 184.5 19.5787C185.271 20.2978 185.656 21.283 185.656 22.5343C185.656 23.3541 185.422 24.0372 184.954 24.5838C184.5 25.1303 183.964 25.4611 183.345 25.5762V25.6193C184.211 25.7344 184.927 26.0795 185.491 26.6548C186.069 27.2301 186.357 27.9924 186.357 28.9416C186.357 30.2504 185.938 31.286 185.099 32.0482C184.259 32.7961 183.042 33.1701 181.446 33.1701H176.617ZM178.557 31.3147H181.302C183.351 31.3147 184.376 30.5237 184.376 28.9416C184.376 28.1362 184.087 27.5394 183.51 27.151C182.946 26.7627 182.058 26.5685 180.848 26.5685H178.557V31.3147ZM178.557 24.7132H180.848C181.838 24.7132 182.553 24.5406 182.994 24.1954C183.448 23.8503 183.675 23.2965 183.675 22.5343C183.675 21.0816 182.732 20.3553 180.848 20.3553H178.557V24.7132Z"
fill="currentColor"
/>
<path
d="M195.357 32.1777C194.614 32.9831 193.617 33.3858 192.365 33.3858C191.113 33.3858 190.115 32.9831 189.372 32.1777C188.63 31.3723 188.258 30.3295 188.258 29.0495V23.0736H190.157V28.8985C190.157 29.7327 190.342 30.3799 190.714 30.8401C191.085 31.3004 191.636 31.5305 192.365 31.5305C193.094 31.5305 193.644 31.3004 194.016 30.8401C194.387 30.3799 194.573 29.7327 194.573 28.8985V23.0736H196.471V29.0495C196.471 30.3295 196.1 31.3723 195.357 32.1777Z"
fill="currentColor"
/>
<path
d="M202.303 33.3858C201.23 33.3858 200.342 33.0838 199.641 32.4797C198.953 31.8757 198.581 31.0631 198.526 30.0419H200.425C200.48 30.5453 200.679 30.948 201.023 31.25C201.381 31.5521 201.807 31.7031 202.303 31.7031C202.812 31.7031 203.204 31.588 203.479 31.3579C203.754 31.1278 203.892 30.8473 203.892 30.5165C203.892 30.1282 203.713 29.819 203.355 29.5889C202.997 29.3444 202.564 29.1502 202.055 29.0064C201.56 28.8625 201.058 28.6899 200.549 28.4886C200.053 28.2872 199.627 27.9636 199.269 27.5178C198.911 27.0719 198.733 26.5038 198.733 25.8135C198.733 25.0224 199.028 24.3321 199.62 23.7424C200.211 23.1527 201.03 22.8579 202.076 22.8579C203.066 22.8579 203.878 23.1383 204.511 23.6992C205.144 24.2602 205.508 25.044 205.604 26.0508H203.706C203.555 25.044 203.011 24.5406 202.076 24.5406C201.663 24.5406 201.319 24.6557 201.044 24.8858C200.769 25.1159 200.631 25.4251 200.631 25.8135C200.631 26.2018 200.81 26.511 201.168 26.7411C201.525 26.9713 201.952 27.1582 202.447 27.302C202.956 27.4459 203.458 27.6185 203.954 27.8198C204.463 28.0068 204.896 28.3304 205.254 28.7906C205.611 29.2365 205.79 29.8118 205.79 30.5165C205.79 31.3507 205.46 32.0411 204.8 32.5876C204.139 33.1197 203.307 33.3858 202.303 33.3858Z"
fill="currentColor"
/>
<path
d="M207.625 33.1701V23.0736H209.524V33.1701H207.625ZM207.687 20.7652C207.453 20.5207 207.336 20.2187 207.336 19.8591C207.336 19.4996 207.453 19.1975 207.687 18.953C207.935 18.6942 208.23 18.5647 208.574 18.5647C208.918 18.5647 209.207 18.6942 209.441 18.953C209.689 19.1975 209.813 19.4996 209.813 19.8591C209.813 20.2187 209.689 20.5207 209.441 20.7652C209.207 21.0097 208.918 21.132 208.574 21.132C208.23 21.132 207.935 21.0097 207.687 20.7652Z"
fill="currentColor"
/>
<path
d="M212.018 27.1942C212.018 25.9141 212.396 24.8714 213.153 24.066C213.91 23.2606 214.928 22.8579 216.207 22.8579C217.487 22.8579 218.505 23.2606 219.261 24.066C220.018 24.8714 220.396 25.9141 220.396 27.1942V33.1701H218.498V27.3452C218.498 26.4966 218.305 25.8422 217.92 25.382C217.535 24.9074 216.964 24.6701 216.207 24.6701C215.45 24.6701 214.879 24.9074 214.494 25.382C214.109 25.8422 213.916 26.4966 213.916 27.3452V33.1701H212.018V27.1942Z"
fill="currentColor"
/>
<path
d="M227.131 33.3858C225.714 33.3858 224.545 32.8968 223.623 31.9188C222.715 30.9408 222.261 29.6751 222.261 28.1218C222.261 26.5685 222.715 25.3029 223.623 24.3249C224.531 23.3469 225.7 22.8579 227.131 22.8579C228.411 22.8579 229.497 23.3685 230.392 24.3896C231.3 25.3964 231.754 26.6405 231.754 28.1218C231.754 28.4383 231.74 28.6971 231.712 28.8985H224.222C224.359 29.7183 224.689 30.3727 225.212 30.8617C225.749 31.3363 226.388 31.5736 227.131 31.5736C228.328 31.5736 229.14 31.099 229.566 30.1498H231.506C231.217 31.1278 230.674 31.9116 229.876 32.5013C229.092 33.091 228.177 33.3858 227.131 33.3858ZM224.242 27.2589H229.793C229.725 26.5542 229.442 25.9501 228.947 25.4467C228.452 24.9289 227.847 24.6701 227.131 24.6701C226.388 24.6701 225.755 24.9074 225.233 25.382C224.724 25.8422 224.393 26.4679 224.242 27.2589Z"
fill="currentColor"
/>
<path
d="M236.965 33.3858C235.892 33.3858 235.005 33.0838 234.303 32.4797C233.615 31.8757 233.244 31.0631 233.189 30.0419H235.087C235.142 30.5453 235.342 30.948 235.686 31.25C236.043 31.5521 236.47 31.7031 236.965 31.7031C237.474 31.7031 237.866 31.588 238.141 31.3579C238.416 31.1278 238.554 30.8473 238.554 30.5165C238.554 30.1282 238.375 29.819 238.017 29.5889C237.66 29.3444 237.226 29.1502 236.717 29.0064C236.222 28.8625 235.72 28.6899 235.211 28.4886C234.716 28.2872 234.289 27.9636 233.931 27.5178C233.574 27.0719 233.395 26.5038 233.395 25.8135C233.395 25.0224 233.691 24.3321 234.282 23.7424C234.874 23.1527 235.692 22.8579 236.738 22.8579C237.729 22.8579 238.54 23.1383 239.173 23.6992C239.806 24.2602 240.171 25.044 240.267 26.0508H238.368C238.217 25.044 237.674 24.5406 236.738 24.5406C236.325 24.5406 235.981 24.6557 235.706 24.8858C235.431 25.1159 235.293 25.4251 235.293 25.8135C235.293 26.2018 235.472 26.511 235.83 26.7411C236.188 26.9713 236.614 27.1582 237.109 27.302C237.618 27.4459 238.121 27.6185 238.616 27.8198C239.125 28.0068 239.558 28.3304 239.916 28.7906C240.274 29.2365 240.453 29.8118 240.453 30.5165C240.453 31.3507 240.122 32.0411 239.462 32.5876C238.802 33.1197 237.969 33.3858 236.965 33.3858Z"
fill="currentColor"
/>
<path
d="M245.631 33.3858C244.558 33.3858 243.67 33.0838 242.969 32.4797C242.281 31.8757 241.909 31.0631 241.854 30.0419H243.753C243.808 30.5453 244.007 30.948 244.351 31.25C244.709 31.5521 245.135 31.7031 245.631 31.7031C246.14 31.7031 246.532 31.588 246.807 31.3579C247.082 31.1278 247.22 30.8473 247.22 30.5165C247.22 30.1282 247.041 29.819 246.683 29.5889C246.325 29.3444 245.892 29.1502 245.383 29.0064C244.888 28.8625 244.386 28.6899 243.877 28.4886C243.381 28.2872 242.955 27.9636 242.597 27.5178C242.239 27.0719 242.061 26.5038 242.061 25.8135C242.061 25.0224 242.356 24.3321 242.948 23.7424C243.539 23.1527 244.358 22.8579 245.404 22.8579C246.394 22.8579 247.206 23.1383 247.839 23.6992C248.472 24.2602 248.836 25.044 248.932 26.0508H247.034C246.883 25.044 246.339 24.5406 245.404 24.5406C244.991 24.5406 244.647 24.6557 244.372 24.8858C244.097 25.1159 243.959 25.4251 243.959 25.8135C243.959 26.2018 244.138 26.511 244.496 26.7411C244.853 26.9713 245.28 27.1582 245.775 27.302C246.284 27.4459 246.786 27.6185 247.282 27.8198C247.791 28.0068 248.224 28.3304 248.582 28.7906C248.939 29.2365 249.118 29.8118 249.118 30.5165C249.118 31.3507 248.788 32.0411 248.128 32.5876C247.467 33.1197 246.635 33.3858 245.631 33.3858Z"
fill="currentColor"
/>
</g>
<defs>
<clipPath id="clip0_631_54368">
<rect width="249" height="48" fill="currentColor" />
</clipPath>
</defs>
</svg>
);
};
export default VpnForBusinessLogo;
| 5,476
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/VpnLogo.tsx
|
import { ComponentPropsWithoutRef, useState } from 'react';
import { generateUID } from '@proton/components';
import { VPN_APP_NAME } from '@proton/shared/lib/constants';
import clsx from '@proton/utils/clsx';
import { LogoProps } from './Logo';
type Props = ComponentPropsWithoutRef<'svg'> & Pick<LogoProps, 'variant' | 'size' | 'hasTitle'>;
const VpnLogo = ({ variant = 'with-wordmark', size, className, hasTitle = true, ...rest }: Props) => {
// This logo can be several times in the view, ids has to be different each time
const [uid] = useState(generateUID('logo'));
const logoWidth = variant === 'with-wordmark' ? 138 : 36;
return (
<svg
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
viewBox={`0 0 ${logoWidth} 36`}
width={logoWidth}
height="36"
fill="none"
role="img"
className={clsx('logo', size && variant === 'glyph-only' && `icon-${size}p`, variant, className)}
aria-labelledby={`${uid}-title`}
{...rest}
>
{hasTitle && <title id={`${uid}-title`}>{VPN_APP_NAME}</title>}
{variant === 'glyph-only' && (
<>
<path
fill={`url(#${uid}-a)`}
fillRule="evenodd"
d="M15.247 29.149c1.064 1.913 3.797 2.017 5.005.19l11.265-17.035c1.195-1.806.052-4.228-2.111-4.475L7.263 5.31c-2.36-.269-4.041 2.22-2.893 4.285l.09.16 9.88 6.77-.12 10.77 1.027 1.854Z"
clipRule="evenodd"
/>
<path
fill={`url(#${uid}-b)`}
d="m15.881 27.364 1-1.49 7.594-11.472c.664-1.003.03-2.349-1.17-2.487L4.456 9.752l9.764 17.552a.979.979 0 0 0 1.66.06Z"
/>
<defs>
<linearGradient
id={`${uid}-a`}
x1="29.32"
x2="11.303"
y1="29.148"
y2="-1.922"
gradientUnits="userSpaceOnUse"
>
<stop offset=".066" stopColor="#8EFFEE" />
<stop offset=".45" stopColor="#C9C7FF" />
<stop offset="1" stopColor="#7341FF" />
</linearGradient>
<linearGradient
id={`${uid}-b`}
x1="30.967"
x2="5.738"
y1="-22.452"
y2="31.512"
gradientUnits="userSpaceOnUse"
>
<stop offset=".48" stopColor="#6D4AFF" />
<stop offset=".994" stopColor="#00F0C3" />
</linearGradient>
</defs>
</>
)}
{variant === 'with-wordmark' && (
<>
<path
fill={`url(#${uid}-a)`}
fillRule="evenodd"
d="M11.247 29.149c1.064 1.913 3.797 2.017 5.005.19l11.265-17.035c1.195-1.806.052-4.228-2.111-4.475L3.263 5.31C.903 5.041-.778 7.53.37 9.595l.09.16 9.88 6.77-.12 10.77 1.027 1.854Z"
clipRule="evenodd"
/>
<path
fill={`url(#${uid}-b)`}
d="m11.881 27.364 1-1.49 7.594-11.472c.664-1.003.03-2.349-1.17-2.486L.456 9.752l9.764 17.552a.979.979 0 0 0 1.66.06Z"
/>
<path
fill="var(--logo-text-product-color)"
d="M119.842 10.897h-6.572v14.25h2.604V21.6a1.303 1.303 0 0 1 1.301-1.303h2.667a4.682 4.682 0 0 0 4.684-4.689 4.688 4.688 0 0 0-2.887-4.352 4.65 4.65 0 0 0-1.797-.36Zm2.051 4.674a2.218 2.218 0 0 1-1.374 2.053 2.192 2.192 0 0 1-.85.168h-3.807v-4.44h3.807a2.222 2.222 0 0 1 2.219 2.233l.005-.014Zm-17.766 9.524-5.245-14.239h2.962l3.451 10.19c.136.366.235.742.292 1.127h.029c.044-.388.142-.767.293-1.126l3.462-10.19h2.982l-5.27 14.238h-2.956Zm21.373 0V10.853h2.283l6.716 8.832c.243.304.452.632.628.98h.041a11.14 11.14 0 0 1-.064-1.292v-8.52h2.69v14.239h-2.282l-6.737-8.832a6.517 6.517 0 0 1-.625-.98h-.023c.038.43.052.86.043 1.292v8.52h-2.67v.003Z"
/>
<path
fill="var(--logo-text-proton-color)"
d="M38 21.26v3.664h2.56V21.42a1.282 1.282 0 0 1 1.279-1.286h2.624a4.592 4.592 0 0 0 3.261-1.361 4.652 4.652 0 0 0 1.351-3.28c0-1.228-.486-2.41-1.35-3.281a4.603 4.603 0 0 0-3.265-1.358H38v4.58h2.56v-2.159h3.73c.58 0 1.134.232 1.544.644a2.2 2.2 0 0 1 0 3.104c-.41.412-.964.644-1.544.644h-2.71a3.551 3.551 0 0 0-2.528 1.055 3.65 3.65 0 0 0-.776 1.166A3.54 3.54 0 0 0 38 21.259Zm11.47 3.664v-5.583c0-2.279 1.322-4.091 3.97-4.091a5.09 5.09 0 0 1 1.262.14v2.296c-.301-.02-.56-.02-.682-.02-1.402 0-2.005.646-2.005 1.955v5.303H49.47Zm5.994-4.734c0-2.802 2.104-4.937 5.033-4.937 2.929 0 5.033 2.135 5.033 4.937 0 2.802-2.104 4.957-5.033 4.957-2.929 0-5.033-2.158-5.033-4.957Zm7.558 0c0-1.592-1.064-2.722-2.525-2.722-1.465 0-2.525 1.127-2.525 2.722 0 1.612 1.063 2.722 2.525 2.722 1.464 0 2.525-1.113 2.525-2.722Zm10.646 0c0-2.802 2.104-4.937 5.032-4.937 2.926 0 5.03 2.135 5.03 4.937 0 2.802-2.104 4.957-5.03 4.957-2.928 0-5.032-2.158-5.032-4.957Zm7.554 0c0-1.592-1.063-2.722-2.524-2.722-1.462 0-2.525 1.127-2.525 2.722 0 1.612 1.063 2.722 2.525 2.722 1.461 0 2.525-1.113 2.525-2.722Zm3.831 4.734v-5.38c0-2.499 1.583-4.294 4.41-4.294 2.806 0 4.39 1.792 4.39 4.294v5.38h-2.525v-5.18c0-1.39-.623-2.259-1.865-2.259-1.243 0-1.865.867-1.865 2.259v5.18h-2.545Zm-12.147-7.436h-2.747v3.528c0 1.23.44 1.793 1.703 1.793.12 0 .42 0 .802-.02v2.075c-.52.14-.981.223-1.484.223-2.124 0-3.569-1.29-3.569-3.728v-3.87h-1.706v-2.036h.427a1.3 1.3 0 0 0 .489-.097 1.285 1.285 0 0 0 .694-.698 1.28 1.28 0 0 0 .096-.492v-1.918h2.545v3.205h2.747v2.035h.003Z"
/>
<defs>
<linearGradient
id={`${uid}-a`}
x1="25.32"
x2="7.303"
y1="29.148"
y2="-1.922"
gradientUnits="userSpaceOnUse"
>
<stop offset=".066" stopColor="#8EFFEE" />
<stop offset=".45" stopColor="#C9C7FF" />
<stop offset="1" stopColor="#7341FF" />
</linearGradient>
<linearGradient
id={`${uid}-b`}
x1="26.967"
x2="1.738"
y1="-22.452"
y2="31.512"
gradientUnits="userSpaceOnUse"
>
<stop offset=".48" stopColor="#6D4AFF" />
<stop offset=".994" stopColor="#00F0C3" />
</linearGradient>
</defs>
</>
)}
</svg>
);
};
export default VpnLogo;
| 5,477
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/logo/index.ts
|
export { default as CalendarLogo } from './CalendarLogo';
export { default as DriveLogo } from './DriveLogo';
export { default as MailLogo } from './MailLogo';
export { default as MainLogo } from './MainLogo';
export { default as Logo } from './Logo';
export * from './Logo';
export { default as ProtonLogo } from './ProtonLogo';
export { default as VpnLogo } from './VpnLogo';
export { default as VpnForBusinessLogo } from './VpnForBusinessLogo';
export { default as ProtonForBusinessLogo } from './ProtonForBusinessLogo';
export { default as PassLogo } from './PassLogo';
| 5,478
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/maintenanceLayout/SettingsMaintenanceLayoutWrapper.test.tsx
|
import { render } from '@testing-library/react';
import { SettingsAreaConfig, useFlag } from '../..';
import SettingsMaintenanceLayoutWrapper from './SettingsMaintenanceLayoutWrapper';
const config: SettingsAreaConfig = {
text: 'text',
subsections: [
{
text: 'text',
id: 'id',
},
],
};
jest.mock('../..');
const mockUseFlag = useFlag as unknown as jest.MockedFunction<any>;
jest.mock('@proton/components/hooks/useAppTitle');
jest.mock('react-router', () => ({
__esModule: true,
useLocation: jest.fn().mockReturnValue({ location: { pathname: '/' } }),
}));
describe('SettingsMaintenanceLayoutWrapper', () => {
it('should handle is in Maintenance', () => {
mockUseFlag.mockReturnValue(true);
const { getByText, queryByText } = render(
<SettingsMaintenanceLayoutWrapper config={config} maintenanceFlag="MaintenanceImporter">
<div>children</div>
</SettingsMaintenanceLayoutWrapper>
);
expect(queryByText(config.text)).toBeTruthy();
expect(getByText('This feature is temporarily unavailable')).toBeInTheDocument();
});
it('should handle is not in maintenance', () => {
mockUseFlag.mockReturnValue(false);
const { getByText, queryByText } = render(
<SettingsMaintenanceLayoutWrapper config={config} maintenanceFlag="MaintenanceImporter">
<div>children</div>
</SettingsMaintenanceLayoutWrapper>
);
expect(queryByText(config.text)).toBeNull();
expect(getByText('children')).toBeInTheDocument();
});
it('should handle is in maintenance and is subsection', () => {
mockUseFlag.mockReturnValue(true);
const { getByText, queryByText } = render(
<SettingsMaintenanceLayoutWrapper config={config} maintenanceFlag="MaintenanceImporter" isSubsection>
<div>children</div>
</SettingsMaintenanceLayoutWrapper>
);
expect(queryByText(config.text)).toBeNull();
expect(getByText('This feature is temporarily unavailable')).toBeInTheDocument();
});
it('should handle is not in maintenance and is subsection', () => {
mockUseFlag.mockReturnValue(false);
const { getByText, queryByText } = render(
<SettingsMaintenanceLayoutWrapper config={config} maintenanceFlag="MaintenanceImporter" isSubsection>
<div>children</div>
</SettingsMaintenanceLayoutWrapper>
);
expect(queryByText(config.text)).toBeNull();
expect(getByText('children')).toBeInTheDocument();
});
});
| 5,479
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/maintenanceLayout/SettingsMaintenanceLayoutWrapper.tsx
|
import { ReactNode } from 'react';
import { c } from 'ttag';
import { PrivateMainSettingsAreaBase } from '@proton/components/containers/layout/PrivateMainSettingsArea';
import errorImg from '@proton/styles/assets/img/errors/error-generic.svg';
import { FeatureFlag, SettingsAreaConfig, useFlag } from '../..';
interface Props {
config: SettingsAreaConfig;
maintenanceFlag: FeatureFlag;
isSubsection?: boolean;
children: ReactNode;
}
const MaintenanceLayout = () => {
return (
<div className="max-w-custom border rounded-xl p-8 rounded-xl text-center" style={{ '--max-w-custom': '24em' }}>
<img
src={errorImg}
alt={c('Maintenance mode').t`This feature is temporarily unavailable`}
className="mb-4"
/>
<h2 className="text-semibold text-rg m-0 mb-2">{c('Maintenance mode')
.t`This feature is temporarily unavailable`}</h2>
<p className="m-0">{c('Maintenance mode').t`Please check back in a few minutes.`}</p>
</div>
);
};
const SettingsMaintenanceLayoutWrapper = ({ config, isSubsection, children, maintenanceFlag }: Props) => {
const isInMaintenance = useFlag(maintenanceFlag);
if (isInMaintenance) {
return (
<>
{isSubsection ? (
<MaintenanceLayout />
) : (
<PrivateMainSettingsAreaBase title={config.text} description={config.description}>
<MaintenanceLayout />
</PrivateMainSettingsAreaBase>
)}
</>
);
}
return <>{children}</>;
};
export default SettingsMaintenanceLayoutWrapper;
| 5,480
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/maintenanceLayout/index.ts
|
export { default as SettingsMaintenanceLayoutWrapper } from './SettingsMaintenanceLayoutWrapper';
| 5,481
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/miniCalendar/LocalizedMiniCalendar.tsx
|
import { useCallback, useMemo } from 'react';
import { format } from 'date-fns';
import { c } from 'ttag';
import { getFormattedMonths, getFormattedWeekdays, getWeekStartsOn } from '@proton/shared/lib/date/date';
import { dateLocale } from '@proton/shared/lib/i18n';
import MiniCalendar, { Props as MiniCalProps } from './MiniCalendar';
export type Props = MiniCalProps;
const LocalizedMiniCalendar = ({ weekStartsOn, now, todayTitle: todayTitleProp, ...rest }: Props) => {
const weekdaysLong = useMemo(() => {
return getFormattedWeekdays('cccc', { locale: dateLocale });
}, [dateLocale]);
const weekdaysShort = useMemo(() => {
return getFormattedWeekdays('ccccc', { locale: dateLocale });
}, [dateLocale]);
const months = useMemo(() => {
return getFormattedMonths('LLLL', { locale: dateLocale });
}, [dateLocale]);
const formatDay = useCallback(
(date) => {
return format(date, 'PPPP', { locale: dateLocale });
},
[dateLocale]
);
const todayTitle = useMemo(() => {
if (todayTitleProp !== undefined) {
return todayTitleProp;
}
if (!now) {
return c('Today icon tooltip in mini calendar').t`Today`;
}
return format(now, 'PP', { locale: dateLocale });
}, [now, dateLocale]);
return (
<MiniCalendar
nextMonth={c('Action').t`Next month`}
prevMonth={c('Action').t`Previous month`}
weekdaysLong={weekdaysLong}
weekdaysShort={weekdaysShort}
months={months}
weekStartsOn={weekStartsOn !== undefined ? weekStartsOn : getWeekStartsOn(dateLocale)}
formatDay={formatDay}
todayTitle={todayTitle}
{...rest}
/>
);
};
export default LocalizedMiniCalendar;
| 5,482
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/miniCalendar/MiniCalendar.test.tsx
|
import { fireEvent, render, screen } from '@testing-library/react';
import MiniCalendar from './MiniCalendar';
describe('MiniCalendar', () => {
const getFakeNow = () => new Date(Date.UTC(2021, 0, 1, 0, 0, 0));
beforeAll(() => {
jest.useFakeTimers().setSystemTime(getFakeNow().getTime());
});
it('disables today button when out of range', async () => {
const { rerender } = render(<MiniCalendar date={getFakeNow()} hasToday min={getFakeNow()} />);
const getTodayButton = () => screen.getByTestId(/minicalendar:today/);
expect(getTodayButton()).not.toBeDisabled();
const fakeTomorrow = getFakeNow();
fakeTomorrow.setUTCDate(getFakeNow().getUTCDate() + 1);
rerender(<MiniCalendar date={getFakeNow()} hasToday min={fakeTomorrow} />);
expect(getTodayButton()).toBeDisabled();
const fakeYesterday = getFakeNow();
fakeYesterday.setUTCDate(getFakeNow().getUTCDate() - 1);
rerender(<MiniCalendar date={getFakeNow()} hasToday max={fakeYesterday} />);
expect(getTodayButton()).toBeDisabled();
});
it('disables month navigation when out of range', async () => {
const { rerender } = render(<MiniCalendar date={getFakeNow()} min={getFakeNow()} max={getFakeNow()} />);
const getPrevMonthButton = () => screen.getByTestId(/minicalendar:previous-month/);
const getNextMonthButton = () => screen.getByTestId(/minicalendar:next-month/);
expect(getPrevMonthButton()).toBeDisabled();
expect(getNextMonthButton()).toBeDisabled();
const fakeNextMonth = getFakeNow();
const fakePrevMonth = getFakeNow();
fakePrevMonth.setUTCMonth(getFakeNow().getUTCMonth() - 1);
fakeNextMonth.setUTCMonth(getFakeNow().getUTCMonth() + 1);
rerender(<MiniCalendar date={getFakeNow()} hasToday min={fakePrevMonth} max={fakeNextMonth} />);
expect(getPrevMonthButton()).not.toBeDisabled();
expect(getNextMonthButton()).not.toBeDisabled();
fireEvent.click(getNextMonthButton());
expect(getNextMonthButton()).toBeDisabled();
fireEvent.click(getPrevMonthButton());
fireEvent.click(getPrevMonthButton());
expect(getPrevMonthButton()).toBeDisabled();
});
});
| 5,483
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/miniCalendar/MiniCalendar.tsx
|
import { FormEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { addMonths, endOfMonth, isSameMonth, startOfMonth } from 'date-fns';
import { c } from 'ttag';
import { Vr } from '@proton/atoms';
import { Button } from '@proton/atoms';
import clsx from '@proton/utils/clsx';
import { createObserver } from '../../hooks/useElementRect';
import { TodayIcon } from '../icon';
import Icon from '../icon/Icon';
import { Tooltip } from '../tooltip';
import MonthDays from './MonthDays';
import WeekDays from './WeekDays';
import WeekNumbers from './WeekNumbers';
import { getDateTupleFromMonday, getDaysInMonth } from './helper';
import { DateTuple, WeekStartsOn } from './index.d';
export interface Props {
hasCursors?: boolean;
hasToday?: boolean;
now?: Date;
date: Date;
dateRange?: DateTuple;
min?: Date;
max?: Date;
displayWeekNumbers?: boolean;
months?: string[];
nextMonth?: string;
prevMonth?: string;
numberOfWeeks?: number;
weekdaysLong?: string[];
weekdaysShort?: string[];
onSelectDate?: (a1: Date) => void;
onSelectDateRange?: (a1: DateTuple, resetRange?: boolean) => void;
formatDay?: (a1: Date) => string;
weekStartsOn?: WeekStartsOn;
numberOfDays?: number;
fixedSize?: boolean;
preventLeaveFocus?: boolean;
todayTitle?: string;
}
const MiniCalendar = ({
hasCursors = true,
hasToday = false,
now = new Date(),
date: selectedDate,
min,
max,
dateRange,
onSelectDate,
onSelectDateRange,
formatDay = (date) => date.toString(),
weekStartsOn = 1,
weekdaysLong = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
weekdaysShort = ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
nextMonth = 'Next month',
prevMonth = 'Previous month',
months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
],
numberOfDays = 7,
numberOfWeeks = 6,
displayWeekNumbers = false,
fixedSize = false,
preventLeaveFocus = false,
todayTitle,
}: Props) => {
const [temporaryDate, setTemporaryDate] = useState<Date | undefined>();
const [cellWidth, setCellWidth] = useState(0);
const unsubscribeRef = useRef<() => void | undefined>();
useEffect(() => {
return () => {
unsubscribeRef.current?.();
};
}, []);
const cb = useCallback((node: HTMLElement | null) => {
unsubscribeRef.current?.();
if (!node) {
return null;
}
const sizeCache: number[] = [];
unsubscribeRef.current = createObserver(node, (rect) => {
const [prevOld, prevNew] = sizeCache;
const newWidth = rect.width;
// If it's flipping back and forth, settle on the previous value. This is
// to prevent a scenario where the new height of the node causes an overflow scroll to
// appear/disappear indefinitely.
if (prevOld === newWidth) {
return;
}
setCellWidth(newWidth);
sizeCache[0] = prevNew;
sizeCache[1] = newWidth;
});
}, []);
const activeDate = temporaryDate || selectedDate;
const activeDateDay = isSameMonth(now, activeDate) ? now.getDay() : undefined;
const days = useMemo(() => {
return getDaysInMonth(activeDate, { weekStartsOn, weeks: numberOfWeeks - 1 });
}, [activeDate, weekStartsOn, numberOfWeeks]);
const monthLabel = useMemo(() => {
return `${months[activeDate.getMonth()]} ${activeDate.getFullYear()}`;
}, [activeDate, months]);
const handleSwitchMonth = (direction: -1 | 1) => {
const newDate = addMonths(activeDate, direction);
// Don't allow to go outside of bounds.
const isBeforeMin = min && startOfMonth(newDate) < startOfMonth(min);
const isAfterMax = max && endOfMonth(newDate) > endOfMonth(max);
if (isBeforeMin || isAfterMax) {
return;
}
setTemporaryDate(newDate);
};
const handleClickWeekNumber =
onSelectDateRange &&
((monday: Date) => {
onSelectDateRange(getDateTupleFromMonday(monday, weekStartsOn), true);
});
const handleSelectWeekRange =
onSelectDateRange &&
(([startWeekMonday, endWeekMonday]: [Date, Date]) => {
const [start] = getDateTupleFromMonday(startWeekMonday, weekStartsOn);
const [, end] = getDateTupleFromMonday(endWeekMonday, weekStartsOn);
onSelectDateRange([start, end]);
});
useEffect(() => {
setTemporaryDate(undefined);
}, [selectedDate]);
const handleMouseDown = preventLeaveFocus ? (e: FormEvent<HTMLElement>) => e.preventDefault() : undefined;
return (
<div className="minicalendar" onMouseDown={handleMouseDown} aria-label={monthLabel}>
<h2 className="sr-only">{c('Title').t`Minicalendar`}</h2>
<div className="flex flex-align-items-center flex-nowrap p-3 pt-1">
<span className="text-bold flex-item-fluid text-ellipsis">{monthLabel}</span>
{hasToday ? (
<Tooltip title={todayTitle}>
<Button
icon
shape="ghost"
color="weak"
size="small"
onClick={() => onSelectDate?.(now)}
disabled={(min && +now < +min) || (max && +now > +max)}
data-testid="minicalendar:today"
className="flex"
>
<TodayIcon todayDate={now.getDate()} />
</Button>
</Tooltip>
) : null}
{hasCursors ? (
<>
<Tooltip title={prevMonth}>
<Button
icon
shape="ghost"
className="on-rtl-mirror"
color="weak"
size="small"
disabled={min && startOfMonth(addMonths(activeDate, -1)) < startOfMonth(min)}
onClick={() => handleSwitchMonth(-1)}
data-testid="minicalendar:previous-month"
>
<Icon name="chevron-left" className="minicalendar-icon" alt={prevMonth} />
</Button>
</Tooltip>
<Tooltip title={nextMonth}>
<Button
icon
shape="ghost"
className="on-rtl-mirror"
color="weak"
size="small"
disabled={max && endOfMonth(addMonths(activeDate, 1)) > endOfMonth(max)}
onClick={() => handleSwitchMonth(1)}
data-testid="minicalendar:next-month"
>
<Icon name="chevron-right" className="minicalendar-icon" alt={nextMonth} />
</Button>
</Tooltip>
</>
) : null}
</div>
<div
style={
!fixedSize && cellWidth && cellWidth > 0 ? { '--computed-cell-width': `${cellWidth}px` } : undefined
}
className={clsx([
'minicalendar-grid px-3 pb-7',
displayWeekNumbers && 'with-weeknumbers',
fixedSize && 'is-fixed-size',
])}
>
{displayWeekNumbers ? (
<>
<WeekNumbers
numberOfWeeks={numberOfWeeks}
days={days}
onClickWeekNumber={handleClickWeekNumber}
onSelectWeekRange={handleSelectWeekRange}
/>
<Vr className="minicalendar-vr" aria-hidden="true" />
</>
) : null}
<WeekDays
numberOfDays={numberOfDays}
weekdaysShort={weekdaysShort}
weekdaysLong={weekdaysLong}
weekStartsOn={weekStartsOn}
activeDateDay={activeDateDay}
cellRef={cb}
/>
<MonthDays
min={min}
max={max}
numberOfWeeks={numberOfWeeks}
numberOfDays={numberOfDays}
days={days}
formatDay={formatDay}
dateRange={dateRange}
onSelectDate={onSelectDate}
onSelectDateRange={onSelectDateRange}
now={now}
activeDate={activeDate}
selectedDate={selectedDate}
/>
</div>
</div>
);
};
export default MiniCalendar;
| 5,484
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/miniCalendar/MonthDays.tsx
|
import { MouseEvent, Ref, memo, useRef, useState } from 'react';
import { isAfter, isBefore, isSameDay, isSameMonth, isWithinInterval } from 'date-fns';
import clsx from '@proton/utils/clsx';
import { DateTuple } from './index.d';
const getTargetDate = (target: any, days: Date[]) => {
const idx = parseInt(target?.dataset?.i || '', 10);
if (idx >= 0 && idx < days.length) {
return days[idx];
}
};
export interface Props {
days: Date[];
onSelectDate?: (a1: Date) => void;
onSelectDateRange?: (a1: DateTuple) => void;
now: Date;
selectedDate?: Date;
activeDate: Date;
dateRange?: DateTuple;
min?: Date;
max?: Date;
formatDay: (a1: Date) => string;
numberOfDays: number;
numberOfWeeks: number;
cellRef?: Ref<HTMLLIElement>;
}
const MonthDays = ({
days,
onSelectDate,
onSelectDateRange,
dateRange,
formatDay,
now,
min,
max,
selectedDate,
activeDate,
numberOfDays,
numberOfWeeks,
cellRef,
}: Props) => {
const [temporaryDateRange, setTemporaryDateRange] = useState<[Date, Date | undefined] | undefined>(undefined);
const rangeStartRef = useRef<Date | undefined>(undefined);
const rangeEndRef = useRef<Date | undefined>(undefined);
const style = {
'--cols': numberOfDays,
'--rows': numberOfWeeks,
};
const handleMouseDown = ({ target }: MouseEvent<HTMLUListElement>) => {
const targetDate = getTargetDate(target, days);
if (rangeStartRef.current || !targetDate || !onSelectDateRange) {
return;
}
setTemporaryDateRange([targetDate, undefined]);
rangeStartRef.current = targetDate;
const handleMouseUp = () => {
if (rangeEndRef.current && rangeStartRef.current) {
onSelectDateRange(
isAfter(rangeEndRef.current, rangeStartRef.current)
? [rangeStartRef.current, rangeEndRef.current]
: [rangeEndRef.current, rangeStartRef.current]
);
}
setTemporaryDateRange(undefined);
rangeStartRef.current = undefined;
rangeEndRef.current = undefined;
document.removeEventListener('mouseup', handleMouseUp);
};
document.addEventListener('mouseup', handleMouseUp);
};
const handleMouseOver = ({ target }: MouseEvent<HTMLUListElement>) => {
const overDate = getTargetDate(target, days);
if (!rangeStartRef.current || !overDate || !onSelectDateRange) {
return;
}
rangeEndRef.current = overDate;
setTemporaryDateRange(
isAfter(overDate, rangeStartRef.current)
? [rangeStartRef.current, overDate]
: [overDate, rangeStartRef.current]
);
};
const handleFocus = () => {};
const handleClick = ({ target }: MouseEvent<HTMLUListElement>) => {
const value = getTargetDate(target, days);
if (value) {
onSelectDate?.(value);
}
};
const [rangeStart, rangeEnd] = temporaryDateRange || dateRange || [];
return (
<ul
className="minicalendar-monthdays unstyled m-0 text-center"
style={style}
onClick={handleClick}
onMouseDown={handleMouseDown}
onMouseOver={handleMouseOver}
onFocus={handleFocus}
>
{days.map((dayDate, i) => {
const isBeforeMin = min ? isBefore(dayDate, min) : false;
const isAfterMax = max ? isAfter(dayDate, max) : false;
const isOutsideMinMax = isBeforeMin || isAfterMax;
const isActiveMonth = isOutsideMinMax ? false : isSameMonth(dayDate, activeDate);
const isCurrent = isSameDay(now, dayDate);
const isInterval =
(rangeStart && rangeEnd && isWithinInterval(dayDate, { start: rangeStart, end: rangeEnd })) ||
(rangeStart && isSameDay(rangeStart, dayDate));
const isPressed = selectedDate ? isSameDay(selectedDate, dayDate) || isInterval : false;
// only for CSS layout: start/end of week OR start/end of interval in week
const isIntervalBoundStart =
(isInterval && i % numberOfDays === 0) ||
(isInterval && rangeStart && isSameDay(rangeStart, dayDate));
const isIntervalBoundEnd =
(isInterval && i % numberOfDays === numberOfDays - 1) ||
(isInterval && rangeEnd && isSameDay(rangeEnd, dayDate)) ||
(!rangeEnd && isIntervalBoundStart);
const className = clsx([
'minicalendar-day no-pointer-events-children',
!isActiveMonth && 'minicalendar-day--out-of-month',
isInterval && 'minicalendar-day--range',
isIntervalBoundStart && 'minicalendar-day--range-bound-start',
isIntervalBoundEnd && 'minicalendar-day--range-bound-end',
selectedDate && isSameDay(selectedDate, dayDate) && 'minicalendar-day--selected',
]);
return (
<li key={dayDate.toString()} ref={i === 0 ? cellRef : undefined}>
<button
disabled={isOutsideMinMax}
aria-label={formatDay(dayDate)}
aria-current={isCurrent ? 'date' : undefined}
aria-pressed={isPressed ? true : undefined}
className={className}
data-i={i}
type="button"
>
<span className="minicalendar-day-number">{dayDate.getDate()}</span>
</button>
</li>
);
})}
</ul>
);
};
export default memo(MonthDays);
| 5,485
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/miniCalendar/WeekDays.tsx
|
import { Ref, memo } from 'react';
import clsx from '@proton/utils/clsx';
import Tooltip from '../tooltip/Tooltip';
import { WeekStartsOn } from './index.d';
export interface Props {
weekStartsOn: WeekStartsOn;
numberOfDays?: number;
weekdaysLong: string[];
weekdaysShort: string[];
activeDateDay?: number;
cellRef?: Ref<HTMLSpanElement>;
}
const WeekDays = ({ cellRef, weekdaysShort, weekdaysLong, weekStartsOn = 1, numberOfDays, activeDateDay }: Props) => {
const style = {
'--weekdays-count': numberOfDays,
};
return (
<div className="text-center minicalendar-weekdays" style={style}>
{weekdaysShort.map((el, i) => {
const idx = (i + weekStartsOn) % 7;
const label = weekdaysShort[idx];
const tooltip = weekdaysLong[idx];
const isCurrentDay = idx === activeDateDay;
return (
<Tooltip key={label + i} title={tooltip}>
<span
ref={i === 0 ? cellRef : undefined}
aria-hidden="true"
className={clsx(['text-strong', isCurrentDay && 'current-weekday'])}
>
{label}
<span className="sr-only">{tooltip}</span>
</span>
</Tooltip>
);
})}
</div>
);
};
export default memo(WeekDays);
| 5,486
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/miniCalendar/WeekNumbers.tsx
|
import { MouseEvent, useMemo, useRef, useState } from 'react';
import { getISOWeek } from 'date-fns';
import { c } from 'ttag';
import clsx from '@proton/utils/clsx';
import { Tooltip } from '../tooltip';
/*
ISO weeks always start on Monday, and they won't match user custom weeks starting on Saturday/Sunday.
A custom week with number N is defined as the one which has the same Monday as ISO week N.
*/
const getWeekNumberToMondayMap = (days: Date[]) => {
const firstMondayIndex = days.findIndex((day) => day.getDay() === 1);
const result: { [weekNumber: number]: Date } = {};
if (firstMondayIndex === -1) {
return result;
}
for (let i = 0; i < Math.floor(days.length / 7); i++) {
const day = days[firstMondayIndex + 7 * i];
result[getISOWeek(day)] = day;
}
return result;
};
const getTargetMonday = (target: any, weekNumberToMondayMap: { [weekNumber: number]: Date }) => {
const idx = parseInt(target?.dataset?.i || '', 10);
if (idx >= 0 && idx <= 53) {
return weekNumberToMondayMap[idx];
}
};
const getMonday = (days: Date[], start: number, end: number) => {
for (let i = start; i < end; ++i) {
const day = days[i];
if (day && day.getDay() === 1) {
return day;
}
}
};
export interface Props {
days: Date[];
numberOfWeeks: number;
onClickWeekNumber?: (monday: Date) => void;
onSelectWeekRange?: (arg: [Date, Date]) => void;
}
const WeekNumbers = ({ days, numberOfWeeks, onClickWeekNumber, onSelectWeekRange }: Props) => {
const style = {
'--week-count': numberOfWeeks + 1,
};
const weekNumberToMondayMap = useMemo(() => getWeekNumberToMondayMap(days), days);
const [temporaryWeekRange, setTemporaryWeekRange] = useState<[Date, Date | undefined] | undefined>(undefined);
const rangeStartRef = useRef<Date | undefined>(undefined);
const rangeEndRef = useRef<Date | undefined>(undefined);
const handleMouseDown = ({ target }: MouseEvent<HTMLUListElement>) => {
const targetMonday = getTargetMonday(target, weekNumberToMondayMap);
if (rangeStartRef.current || !targetMonday || !onSelectWeekRange) {
return;
}
setTemporaryWeekRange([targetMonday, undefined]);
rangeStartRef.current = targetMonday;
const handleMouseUp = () => {
if (rangeEndRef.current && rangeStartRef.current) {
onSelectWeekRange(
rangeEndRef.current > rangeStartRef.current
? [rangeStartRef.current, rangeEndRef.current]
: [rangeEndRef.current, rangeStartRef.current]
);
}
setTemporaryWeekRange(undefined);
rangeStartRef.current = undefined;
rangeEndRef.current = undefined;
document.removeEventListener('mouseup', handleMouseUp);
};
document.addEventListener('mouseup', handleMouseUp);
};
const handleMouseOver = ({ target }: MouseEvent<HTMLUListElement>) => {
const targetMonday = getTargetMonday(target, weekNumberToMondayMap);
if (!rangeStartRef.current || !targetMonday || !onSelectWeekRange) {
return;
}
rangeEndRef.current = targetMonday;
setTemporaryWeekRange(
targetMonday > rangeStartRef.current
? [rangeStartRef.current, targetMonday]
: [targetMonday, rangeStartRef.current]
);
};
const handleFocus = () => {};
const weekNumberLabels = useMemo(() => {
return Array.from({ length: numberOfWeeks }, (a, i) => {
const idx = i * 7;
const monday = getMonday(days, idx, idx + 7) || days[idx];
const weekNumber = getISOWeek(monday);
return {
monday,
weekNumber,
};
});
}, [days]);
return (
<ul
className={clsx([
'minicalendar-weeknumbers unstyled m-0 text-center',
!onSelectWeekRange && 'no-pointer-events-children',
])}
style={style}
onMouseDown={handleMouseDown}
onMouseOver={handleMouseOver}
onFocus={handleFocus}
>
<li>
<span className="sr-only">{c('Info').t`Week`}</span>
</li>
{weekNumberLabels.map(({ monday, weekNumber }) => {
const isPressed = !temporaryWeekRange
? false
: monday >= temporaryWeekRange[0] && monday <= (temporaryWeekRange[1] || temporaryWeekRange[0]);
return (
<li key={+monday}>
<Tooltip title={`${c('Info').t`Week`} ${weekNumber}`} originalPlacement="bottom">
<button
data-i={weekNumber}
aria-pressed={isPressed}
type="button"
className={clsx(['minicalendar-weeknumber', !onClickWeekNumber && 'no-pointer-events'])}
onClick={() => onClickWeekNumber?.(monday)}
>
<span className="no-pointer-events">{weekNumber}</span>
</button>
</Tooltip>
</li>
);
})}
</ul>
);
};
export default WeekNumbers;
| 5,487
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/miniCalendar/helper.ts
|
import { addWeeks, eachDayOfInterval, endOfWeek, isSameDay, startOfMonth, startOfWeek, subWeeks } from 'date-fns';
import { DateTuple, WeekStartsOn } from './index.d';
/**
* Get all days to display in the mini calendar for a given date.
*/
export const getDaysInMonth = (
currentDate: Date,
{ weekStartsOn, weeks }: { weeks: number; weekStartsOn: WeekStartsOn }
) => {
const startOfMonthDate = startOfMonth(currentDate);
const startOfWeekDate = startOfWeek(startOfMonthDate, { weekStartsOn });
// in case of displaying 6 weeks for a month starting on weekStartsOn day,
// display last week of previous month so that trailing days are displayed both at the beginning and the end
const adjust = isSameDay(startOfMonthDate, startOfWeekDate) && weeks === 5;
const start = adjust ? subWeeks(startOfWeekDate, 1) : startOfWeekDate;
const end = endOfWeek(addWeeks(start, weeks), { weekStartsOn });
return eachDayOfInterval({ start, end });
};
export const getDateTupleFromMonday = (monday: Date, weekStartsOn?: WeekStartsOn): DateTuple => {
const startDateInWeek = startOfWeek(monday, { weekStartsOn });
const endDateInWeek = endOfWeek(monday, { weekStartsOn });
return [startDateInWeek, endDateInWeek];
};
| 5,488
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/miniCalendar/index.d.ts
|
export type WeekStartsOn = 0 | 1 | 2 | 3 | 4 | 5 | 6;
export type DateTuple = [Date, Date];
| 5,489
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/miniCalendar/index.ts
|
export { default as MiniCalendar } from './MiniCalendar';
export { default as LocalizedMiniCalendar } from './LocalizedMiniCalendar';
| 5,490
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/modal/Confirm.tsx
|
import { ReactNode } from 'react';
import { c } from 'ttag';
import FormModal from './FormModal';
export interface ConfirmModalProps {
onClose?: () => void;
onConfirm?: () => void;
title?: string;
children?: ReactNode;
cancel?: ReactNode;
confirm?: ReactNode;
loading?: boolean;
className?: string;
small?: boolean;
tiny?: boolean;
noTitleEllipsis?: boolean;
mode?: 'alert';
submitProps?: any;
closeProps?: any;
}
/**
* @deprecated please use `Prompt` instead
*/
const Confirm = ({
onClose,
onConfirm,
children,
title = c('Action').t`Confirm`,
cancel = c('Action').t`Cancel`,
confirm = c('Action').t`Confirm`,
small = true,
noTitleEllipsis = true,
...rest
}: ConfirmModalProps) => {
return (
<FormModal
onClose={onClose}
onSubmit={() => {
onConfirm?.();
onClose?.();
}}
title={title}
close={cancel}
submit={confirm}
small={small}
noTitleEllipsis={noTitleEllipsis}
{...rest}
>
{children}
</FormModal>
);
};
export default Confirm;
| 5,491
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/modal/Content.tsx
|
import { FormEvent, ReactNode } from 'react';
import clsx from '@proton/utils/clsx';
import noop from '@proton/utils/noop';
interface Props {
children: ReactNode;
className?: string;
onSubmit: (event: FormEvent<HTMLFormElement>) => void;
onReset: (event: FormEvent<HTMLFormElement>) => void;
autoComplete?: string;
noValidate?: boolean;
}
/**
* @deprecated Please use ModalTwo instead
*/
const Content = ({
children,
className = '',
onSubmit = noop,
onReset = noop,
autoComplete = 'off',
noValidate = false,
...rest
}: Props) => {
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
onSubmit(event);
};
return (
<form
onSubmit={handleSubmit}
onReset={onReset}
autoComplete={autoComplete}
className={clsx(['modal-content', className])}
noValidate={noValidate}
method="post"
{...rest}
>
{children}
</form>
);
};
export default Content;
| 5,492
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/modal/Dialog.js
|
import { useEffect, useLayoutEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { dialogRootClassName } from '@proton/shared/lib/busy';
import clsx from '@proton/utils/clsx';
import { useHotkeys } from '../../hooks';
import { useFocusTrap } from '../focus';
import { useModalPosition } from '../modalTwo/modalPositions';
import Portal from '../portal/Portal';
const CLASSES = {
MODAL: 'modal',
MODAL_IN: 'modal--in',
MODAL_OUT: 'modal--out',
MODAL_INTERMEDIATE: 'modal--intermediate',
MODAL_SMALL: 'modal--smaller',
MODAL_TINY: 'modal--tiny',
};
const ANIMATIONS = {
MODAL_IN: 'anime-modal-in',
MODAL_OUT: 'anime-modal-out',
};
/**
* @deprecated Please use ModalTwo instead
* @type any
*/
const Dialog = ({
onClose,
onEnter,
onExit,
intermediate: isIntermediate = false,
small: isSmall = false,
tiny: isTiny = false,
isClosing = false,
modalTitleID,
children,
className: extraClassNames = '',
disableCloseOnOnEscape,
open, // To prevent it being passed in rest
...rest
}) => {
const rootRef = useRef(null);
const hasCalledExit = useRef(false);
const hasCalledClose = useRef(false);
const focusTrapProps = useFocusTrap({ rootRef });
const last = useModalPosition(true);
useLayoutEffect(() => {
hasCalledClose.current = isClosing;
}, [isClosing]);
useEffect(() => {
return () => {
// Safety measure to make sure cleanup functions always get called, even if the component gets forcefully removed
if (!hasCalledClose.current) {
onClose?.();
}
if (!hasCalledExit.current) {
onExit?.();
}
};
}, []);
useHotkeys(rootRef, [
[
'Escape',
(e) => {
if (!disableCloseOnOnEscape) {
e.stopPropagation();
onClose?.();
}
},
],
]);
return (
<Portal>
<div className={clsx([dialogRootClassName, !last && 'is-behind-backdrop'])}>
<dialog
aria-labelledby={modalTitleID}
aria-modal="true"
open
className={clsx([
CLASSES.MODAL,
isSmall && CLASSES.MODAL_SMALL,
isTiny && CLASSES.MODAL_TINY,
isIntermediate && CLASSES.MODAL_INTERMEDIATE,
(isSmall || isTiny || isIntermediate) && 'modal--shorter-labels',
isClosing && CLASSES.MODAL_OUT,
extraClassNames,
'outline-none',
])}
onAnimationEnd={({ animationName }) => {
if (animationName === ANIMATIONS.MODAL_OUT && isClosing) {
hasCalledExit.current = true;
onExit?.();
}
if (animationName === ANIMATIONS.MODAL_IN && !isClosing) {
onEnter?.();
}
}}
{...rest}
ref={rootRef}
{...focusTrapProps}
>
{children}
</dialog>
</div>
</Portal>
);
};
Dialog.propTypes = {
onEnter: PropTypes.func,
open: PropTypes.bool,
onExit: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
children: PropTypes.node.isRequired,
modalTitleID: PropTypes.string.isRequired,
className: PropTypes.string,
small: PropTypes.bool,
isClosing: PropTypes.bool,
disableCloseOnOnEscape: PropTypes.bool,
};
export default Dialog;
| 5,493
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/modal/Footer.tsx
|
import { ComponentPropsWithoutRef, ReactNode } from 'react';
import clsx from '@proton/utils/clsx';
interface Props extends ComponentPropsWithoutRef<'footer'> {
children?: ReactNode;
isColumn?: boolean;
}
/**
* @deprecated Please use ModalTwo instead
*/
const Footer = ({
children,
isColumn,
className = clsx([
'flex flex-nowrap',
isColumn ? 'flex-column' : 'flex-justify-space-between flex-align-items-center',
]),
...rest
}: Props) => {
return (
<footer className={clsx(['modal-footer', className])} {...rest}>
{children}
</footer>
);
};
export default Footer;
| 5,494
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/modal/FormModal.js
|
import PropTypes from 'prop-types';
import { c } from 'ttag';
import { Button } from '@proton/atoms';
import noop from '@proton/utils/noop';
import ContentModal from './Content';
import DialogModal from './Dialog';
import FooterModal from './Footer';
import HeaderModal from './Header';
import InnerModal from './Inner';
/**
* @deprecated Please use ModalTwo instead
* @type any
*/
const Modal = ({
onClose,
onSubmit,
title,
close = c('Action').t`Cancel`,
submit = c('Action').t`Submit`,
loading = false,
children,
modalTitleID = 'modalTitle',
footer,
innerRef,
hasSubmit = true,
hasClose = true,
displayTitle = true,
noTitleEllipsis = false,
noValidate = false,
mode = '',
// Destructure these options so they are not passed to the DOM.
// eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
disableCloseOnLocation,
disableCloseOnOnEscape,
submitProps,
closeProps,
...rest
}) => {
const isAlertMode = mode === 'alert';
const getFooter = () => {
if (footer === null) {
return null;
}
if (footer) {
return <FooterModal isColumn={isAlertMode}>{footer}</FooterModal>;
}
if (isAlertMode) {
return (
<FooterModal isColumn>
<Button
size="large"
color="norm"
type="button"
fullWidth
loading={loading}
onClick={onSubmit}
{...submitProps}
>
{submit}
</Button>
{close ? (
<Button
size="large"
color="weak"
type="button"
onClick={onClose}
disabled={loading}
fullWidth
{...closeProps}
>
{close}
</Button>
) : null}
</FooterModal>
);
}
const nodeSubmit =
typeof submit === 'string' ? (
<Button color="norm" loading={loading} type="submit" {...submitProps}>
{submit}
</Button>
) : (
submit
);
const submitBtn = hasSubmit ? nodeSubmit : null;
return (
<FooterModal>
{typeof close === 'string' ? (
<Button type="reset" disabled={loading}>
{close}
</Button>
) : (
close
)}
{submitBtn}
</FooterModal>
);
};
return (
<DialogModal
onClose={onClose}
modalTitleID={modalTitleID}
disableCloseOnOnEscape={disableCloseOnOnEscape || loading}
{...rest}
{...(isAlertMode ? { small: false, tiny: true } : {})}
>
<HeaderModal
hasClose={hasClose}
displayTitle={displayTitle}
noEllipsis={noTitleEllipsis}
modalTitleID={modalTitleID}
onClose={onClose}
{...(isAlertMode ? { hasClose: false } : {})}
>
{title}
</HeaderModal>
<ContentModal
onSubmit={rest.isClosing || loading ? noop : onSubmit}
onReset={onClose}
noValidate={noValidate}
>
<InnerModal ref={innerRef}>{children}</InnerModal>
{getFooter()}
</ContentModal>
</DialogModal>
);
};
Modal.propTypes = {
...DialogModal.propTypes,
modalTitleID: PropTypes.string,
onClose: PropTypes.func.isRequired,
onSubmit: PropTypes.func,
title: PropTypes.node,
children: PropTypes.node.isRequired,
innerRef: PropTypes.object,
loading: PropTypes.bool,
submit: PropTypes.node,
close: PropTypes.node,
noValidate: PropTypes.bool,
mode: PropTypes.string,
small: PropTypes.bool,
background: PropTypes.bool,
hasSubmit: PropTypes.bool,
hasClose: PropTypes.bool,
disableCloseOnLocation: PropTypes.bool,
disableCloseOnOnEscape: PropTypes.bool,
};
export default Modal;
| 5,495
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/modal/FormModal.test.js
|
import { render } from '@testing-library/react';
import FormModal from './FormModal';
describe('Modal component', () => {
const mockOnClose = jest.fn();
const content = <div>panda</div>;
it('should render the modal content', () => {
const { container } = render(
<FormModal title="Title" onClose={mockOnClose}>
{content}
</FormModal>
);
expect(container.firstChild).toBeDefined();
});
});
| 5,496
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/modal/Header.tsx
|
import { DetailedHTMLProps, HTMLAttributes, ReactNode } from 'react';
import clsx from '@proton/utils/clsx';
import ModalCloseButton from './ModalCloseButton';
import Title from './Title';
interface Props extends Omit<DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>, 'children'> {
modalTitleID?: string;
children?: ReactNode;
onClose?: () => void;
displayTitle?: boolean;
hasClose?: boolean;
closeTextModal?: string;
noEllipsis?: boolean;
}
/**
* @deprecated Please use ModalTwo instead
*/
const Header = ({
children,
modalTitleID = 'modalTitle',
className,
closeTextModal,
hasClose = true,
displayTitle = true,
onClose,
noEllipsis = false,
...rest
}: Props) => {
return (
<header className={clsx(['modal-header', !displayTitle && 'modal-header--no-title', className])} {...rest}>
{hasClose ? <ModalCloseButton closeTextModal={closeTextModal} onClose={onClose} /> : null}
{typeof children === 'string' ? (
<Title
id={modalTitleID}
className={!displayTitle ? 'sr-only' : noEllipsis ? undefined : 'text-ellipsis'}
>
{children}
</Title>
) : (
children
)}
</header>
);
};
export default Header;
| 5,497
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/modal/Inner.tsx
|
import { ReactNode, Ref, forwardRef } from 'react';
import { ScrollShadows } from '@proton/atoms';
import clsx from '@proton/utils/clsx';
interface Props {
children: ReactNode;
className?: string;
}
/**
* @deprecated Please use ModalTwo instead
*/
const Inner = forwardRef<HTMLDivElement, Props>(({ children, className = '' }: Props, ref: Ref<HTMLDivElement>) => {
return (
<div ref={ref} className={clsx(['modal-content-inner', className])}>
<ScrollShadows>{children}</ScrollShadows>
</div>
);
});
export default Inner;
| 5,498
|
0
|
petrpan-code/ProtonMail/WebClients/packages/components/components
|
petrpan-code/ProtonMail/WebClients/packages/components/components/modal/ModalCloseButton.tsx
|
import * as React from 'react';
import { c } from 'ttag';
import { Button } from '@proton/atoms';
import { Icon } from '../icon';
interface ModalCloseButtonProps {
onClose?: () => void;
closeTextModal?: string;
}
/**
* @deprecated Please use ModalTwo instead
*/
const ModalCloseButton = ({ closeTextModal, onClose }: ModalCloseButtonProps) => {
const closeText = closeTextModal || c('Action').t`Close`;
return (
<Button icon shape="ghost" size="small" className="modal-close" title={closeText} onClick={onClose}>
<Icon className="modal-close-icon" name="cross" alt={closeText} />
</Button>
);
};
export default ModalCloseButton;
| 5,499
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.