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/pass/components/Item
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item/Login/Login.view.tsx
import { type VFC } from 'react'; import { useSelector } from 'react-redux'; import { c, msgid } from 'ttag'; import { Href } from '@proton/atoms'; import { ExtraFieldsControl } from '@proton/pass/components/Form/Field/Control/ExtraFieldsControl'; import { OTPValueControl } from '@proton/pass/components/Form/Field/Control/OTPValueControl'; import { ValueControl } from '@proton/pass/components/Form/Field/Control/ValueControl'; import { FieldsetCluster } from '@proton/pass/components/Form/Field/Layout/FieldsetCluster'; import { TextAreaReadonly } from '@proton/pass/components/Form/legacy/TextAreaReadonly'; import { UpgradeButton } from '@proton/pass/components/Layout/Button/UpgradeButton'; import { MoreInfoDropdown } from '@proton/pass/components/Layout/Dropdown/MoreInfoDropdown'; import { ItemViewPanel } from '@proton/pass/components/Layout/Panel/ItemViewPanel'; import type { ItemViewProps } from '@proton/pass/components/Views/types'; import { useDeobfuscatedItem } from '@proton/pass/hooks/useDeobfuscatedItem'; import { getCharsGroupedByColor } from '@proton/pass/hooks/usePasswordGenerator'; import { selectAliasByAliasEmail, selectTOTPLimits } from '@proton/pass/store/selectors'; import { getFormattedDateFromTimestamp } from '@proton/pass/utils/time/format'; export const LoginView: VFC<ItemViewProps<'login'>> = ({ vault, revision, ...itemViewProps }) => { const { data: item, createTime, lastUseTime, modifyTime, revision: revisionNumber, shareId, itemId } = revision; const { metadata: { name, note }, content: { username, password, urls, totpUri }, extraFields, } = useDeobfuscatedItem(item); const relatedAlias = useSelector(selectAliasByAliasEmail(username)); const totpAllowed = useSelector(selectTOTPLimits).totpAllowed(itemId); return ( <ItemViewPanel type="login" name={name} vault={vault} {...itemViewProps}> <FieldsetCluster mode="read" as="div"> <ValueControl clickToCopy icon={relatedAlias ? 'alias' : 'user'} label={relatedAlias ? c('Label').t`Username (alias)` : c('Label').t`Username`} value={username} /> <ValueControl clickToCopy hidden icon="key" label={c('Label').t`Password`} value={password} ellipsis={false} valueClassName="text-monospace text-break-all" > {password.length ? getCharsGroupedByColor(password) : undefined} </ValueControl> {totpUri && totpAllowed && ( <OTPValueControl payload={{ itemId, shareId, totpUri, type: 'item', }} /> )} {totpUri && !totpAllowed && ( <ValueControl icon="lock" label={c('Label').t`2FA secret key (TOTP)`}> <UpgradeButton inline /> </ValueControl> )} </FieldsetCluster> {urls.length > 0 && ( <FieldsetCluster mode="read" as="div"> <ValueControl icon="earth" label={c('Label').t`Websites`}> {urls.map((url) => ( <Href className="block text-ellipsis" href={url} key={url}> {url} </Href> ))} </ValueControl> </FieldsetCluster> )} {note && ( <FieldsetCluster mode="read" as="div"> <ValueControl clickToCopy as={TextAreaReadonly} icon="note" label={c('Label').t`Note`} value={note} /> </FieldsetCluster> )} {Boolean(extraFields.length) && ( <ExtraFieldsControl extraFields={extraFields} itemId={itemId} shareId={shareId} /> )} <MoreInfoDropdown info={[ { label: c('Label').t`Last autofill`, // translator: when this login was last used values: [lastUseTime ? getFormattedDateFromTimestamp(lastUseTime) : c('Info').t`Never`], }, { label: c('Label').t`Modified`, values: [ c('Info').ngettext( msgid`${revisionNumber} time`, `${revisionNumber} times`, revisionNumber ), getFormattedDateFromTimestamp(modifyTime), ], }, { label: c('Label').t`Created`, values: [getFormattedDateFromTimestamp(createTime)] }, ]} /> </ItemViewPanel> ); };
7,600
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item/Note/Note.edit.tsx
import type { VFC } from 'react'; import { Form, FormikProvider, useFormik } from 'formik'; import { c } from 'ttag'; import { Field } from '@proton/pass/components/Form/Field/Field'; import { BaseTextAreaField } from '@proton/pass/components/Form/Field/TextareaField'; import { BaseTitleField } from '@proton/pass/components/Form/Field/TitleField'; import { ItemEditPanel } from '@proton/pass/components/Layout/Panel/ItemEditPanel'; import type { ItemEditViewProps } from '@proton/pass/components/Views/types'; import { MAX_ITEM_NAME_LENGTH, MAX_ITEM_NOTE_LENGTH } from '@proton/pass/constants'; import { useDeobfuscatedValue } from '@proton/pass/hooks/useDeobfuscatedValue'; import { useDraftSync } from '@proton/pass/hooks/useItemDraft'; import { validateNoteForm } from '@proton/pass/lib/validation/note'; import type { NoteFormValues } from '@proton/pass/types'; import { obfuscate } from '@proton/pass/utils/obfuscate/xor'; const FORM_ID = 'edit-note'; export const NoteEdit: VFC<ItemEditViewProps<'note'>> = ({ vault: { shareId }, revision, onSubmit, onCancel }) => { const { data: item, itemId, revision: lastRevision } = revision; const { metadata, extraFields } = item; const { name, itemUuid } = metadata; const note = useDeobfuscatedValue(metadata.note); const form = useFormik<NoteFormValues>({ initialValues: { name, note, shareId }, onSubmit: ({ name, note }) => { onSubmit({ type: 'note', itemId, shareId, lastRevision, metadata: { note: obfuscate(note), name, itemUuid }, content: {}, extraFields, }); }, validate: validateNoteForm, validateOnChange: true, }); useDraftSync<NoteFormValues>(form, { type: 'note', mode: 'edit', itemId: itemId, shareId: form.values.shareId, }); return ( <ItemEditPanel type="note" formId={FORM_ID} valid={form.isValid && form.dirty} discardable={!form.dirty} handleCancelClick={onCancel} > {() => ( <FormikProvider value={form}> <Form id={FORM_ID}> <Field dense className="mb-4" component={BaseTitleField} label={c('Label').t`Name`} labelContainerClassName="sr-only" name="name" placeholder={c('Placeholder').t`Untitled`} maxLength={MAX_ITEM_NAME_LENGTH} /> <Field component={BaseTextAreaField} label={c('Label').t`Note`} labelContainerClassName="sr-only" name="note" placeholder={c('Placeholder').t`Write your note`} maxLength={MAX_ITEM_NOTE_LENGTH} minRows={5} rows={Number.MAX_SAFE_INTEGER} /> </Form> </FormikProvider> )} </ItemEditPanel> ); };
7,601
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item/Note/Note.new.tsx
import type { VFC } from 'react'; import { useSelector } from 'react-redux'; import { Form, FormikProvider, useFormik } from 'formik'; import { c } from 'ttag'; import { Field } from '@proton/pass/components/Form/Field/Field'; import { FieldsetCluster } from '@proton/pass/components/Form/Field/Layout/FieldsetCluster'; import { BaseTextAreaField } from '@proton/pass/components/Form/Field/TextareaField'; import { BaseTitleField } from '@proton/pass/components/Form/Field/TitleField'; import { VaultSelectField } from '@proton/pass/components/Form/Field/VaultSelectField'; import { ItemCreatePanel } from '@proton/pass/components/Layout/Panel/ItemCreatePanel'; import type { ItemNewViewProps } from '@proton/pass/components/Views/types'; import { MAX_ITEM_NAME_LENGTH, MAX_ITEM_NOTE_LENGTH } from '@proton/pass/constants'; import { useDraftSync } from '@proton/pass/hooks/useItemDraft'; import { validateNoteForm } from '@proton/pass/lib/validation/note'; import { selectVaultLimits } from '@proton/pass/store/selectors'; import type { NoteFormValues } from '@proton/pass/types'; import { obfuscate } from '@proton/pass/utils/obfuscate/xor'; import { uniqueId } from '@proton/pass/utils/string/unique-id'; import { getEpoch } from '@proton/pass/utils/time/get-epoch'; const FORM_ID = 'new-note'; export const NoteNew: VFC<ItemNewViewProps<'note'>> = ({ shareId, onSubmit, onCancel }) => { const initialValues: NoteFormValues = { name: '', note: '', shareId }; const { vaultTotalCount } = useSelector(selectVaultLimits); const form = useFormik<NoteFormValues>({ initialValues, initialErrors: validateNoteForm(initialValues), onSubmit: ({ shareId, name, note }) => { const optimisticId = uniqueId(); onSubmit({ type: 'note', optimisticId, shareId: shareId, createTime: getEpoch(), metadata: { name, note: obfuscate(note), itemUuid: optimisticId }, content: {}, extraFields: [], }); }, validate: validateNoteForm, validateOnChange: true, }); const draft = useDraftSync<NoteFormValues>(form, { type: 'note', mode: 'new', itemId: 'draft-note', shareId: form.values.shareId, }); return ( <ItemCreatePanel type="note" formId={FORM_ID} valid={form.isValid} discardable={!form.dirty} handleCancelClick={onCancel} > {({ didEnter }) => ( <FormikProvider value={form}> <Form id={FORM_ID}> {vaultTotalCount > 1 && ( <FieldsetCluster className="mb-4"> <Field component={VaultSelectField} label={c('Label').t`Vault`} name="shareId" /> </FieldsetCluster> )} <Field dense name="name" className="mb-4" component={BaseTitleField} label={c('Label').t`Name`} labelContainerClassName="sr-only" placeholder={c('Placeholder').t`Untitled`} autoFocus={!draft && didEnter} key={`note-name-${didEnter}`} maxLength={MAX_ITEM_NAME_LENGTH} /> <Field component={BaseTextAreaField} label={c('Label').t`Note`} labelContainerClassName="sr-only" name="note" placeholder={c('Placeholder').t`Write your note`} maxLength={MAX_ITEM_NOTE_LENGTH} minRows={5} rows={Number.MAX_SAFE_INTEGER} /> </Form> </FormikProvider> )} </ItemCreatePanel> ); };
7,602
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item/Note/Note.view.tsx
import { type VFC } from 'react'; import { c } from 'ttag'; import { Button } from '@proton/atoms'; import { Icon } from '@proton/components'; import { TextAreaReadonly } from '@proton/pass/components/Form/legacy/TextAreaReadonly'; import type { ItemViewProps } from '@proton/pass/components/Views/types'; import { useCopyToClipboard } from '../../../hooks/useCopyToClipboard'; import { useDeobfuscatedValue } from '../../../hooks/useDeobfuscatedValue'; import { ItemViewPanel } from '../../Layout/Panel/ItemViewPanel'; export const NoteView: VFC<ItemViewProps<'note'>> = ({ vault, revision, ...itemViewProps }) => { const { name } = revision.data.metadata; const note = useDeobfuscatedValue(revision.data.metadata.note); const copyToClipboard = useCopyToClipboard(); return ( <ItemViewPanel type="note" name={name} vault={vault} actions={ Boolean(note.length) ? [ <Button icon pill color="weak" key="copy-to-clipboard-button" shape="solid" size="medium" onClick={() => copyToClipboard(note)} disabled={itemViewProps.optimistic} title={c('Action').t`Copy to clipboard`} > <Icon name="squares" alt={c('Action').t`Copy to clipboard`} size={20} /> </Button>, ] : [] } {...itemViewProps} > <TextAreaReadonly>{note}</TextAreaReadonly> </ItemViewPanel> ); };
7,603
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item/Search/SearchBar.scss
.pass-searchbar { --field-background-color: var(--background-strong); --field-hover-background-color: var(--field-background-color); --field-focus-background-color: var(--search-field-focus-background); --field-norm: var(--border-norm); --field-hover: var(--border-norm); --field-focus: var(--focus-outline); input { padding-block: 0.375rem; } .field-two-input-adornment { color: var(--text-norm); } }
7,604
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item
petrpan-code/ProtonMail/WebClients/packages/pass/components/Item/Search/SearchBar.tsx
import { type VFC, memo, useEffect, useMemo, useRef, useState } from 'react'; import { useSelector } from 'react-redux'; import { c } from 'ttag'; import { Button, Input } from '@proton/atoms'; import { Icon } from '@proton/components/components'; import usePrevious from '@proton/hooks/usePrevious'; import { usePassCore } from '@proton/pass/components/Core/PassCoreProvider'; import { getItemTypeOptions } from '@proton/pass/components/Item/Filters/Type'; import { useDebouncedValue } from '@proton/pass/hooks/useDebouncedValue'; import { createTelemetryEvent } from '@proton/pass/lib/telemetry/event'; import { selectShare } from '@proton/pass/store/selectors'; import type { ItemFilters, ShareType } from '@proton/pass/types'; import { TelemetryEventName } from '@proton/pass/types/data/telemetry'; import { isEmptyString } from '@proton/pass/utils/string/is-empty-string'; import './SearchBar.scss'; type Props = { disabled?: boolean; filters: ItemFilters; trash?: boolean; onChange: (value: string) => void; }; const SEARCH_DEBOUNCE_TIME = 150; const SearchBarRaw: VFC<Props> = ({ disabled, filters, trash, onChange }) => { const { onTelemetry } = usePassCore(); const [search, setSearch] = useState<string>(filters.search ?? ''); const searchRef = usePrevious(search); const debouncedSearch = useDebouncedValue(search, SEARCH_DEBOUNCE_TIME); const inputRef = useRef<HTMLInputElement>(null); const { selectedShareId, type = '*' } = filters; const vault = useSelector(selectShare<ShareType.Vault>(selectedShareId)); const placeholder = useMemo(() => { const ITEM_TYPE_TO_LABEL_MAP = getItemTypeOptions(); const pluralItemType = ITEM_TYPE_TO_LABEL_MAP[type].label.toLowerCase(); switch (type) { case '*': return vault ? c('Placeholder').t`Search in ${vault.content.name}` : c('Placeholder').t`Search in all vaults`; default: { // translator: ${pluralItemType} can be either "logins", "notes", "aliases", or "cards". Full sentence example: "Search notes in all vaults" return vault ? c('Placeholder').t`Search ${pluralItemType} in ${vault.content.name}` : c('Placeholder').t`Search ${pluralItemType} in all vaults`; } } }, [vault, type]); const handleClear = () => { setSearch(''); onChange(''); inputRef.current?.focus(); }; const handleFocus = () => inputRef.current?.select(); const handleBlur = () => { if (isEmptyString(search)) return; void onTelemetry(createTelemetryEvent(TelemetryEventName.SearchTriggered, {}, {})); }; useEffect(() => handleFocus(), []); useEffect(() => onChange(debouncedSearch), [debouncedSearch]); useEffect(() => { if (!filters.search) setSearch(''); if (filters.search !== searchRef) onChange(search); }, [filters.search]); return ( <Input autoFocus className="pass-searchbar" disabled={disabled} onBlur={handleBlur} onFocus={handleFocus} onValue={setSearch} placeholder={`${trash ? c('Placeholder').t`Search in Trash` : placeholder}…`} prefix={<Icon name="magnifier" />} ref={inputRef} suffix={ search !== '' && ( <Button shape="ghost" size="small" color="weak" icon pill onClick={handleClear} title={c('Action').t`Clear search`} > <Icon name="cross" /> </Button> ) } value={search} /> ); }; export const SearchBar = memo(SearchBarRaw);
7,605
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Button/UpgradeButton.tsx
import { type VFC } from 'react'; import { c } from 'ttag'; import { Button } from '@proton/atoms'; import { Icon, InlineLinkButton } from '@proton/components/components'; import { useNavigateToUpgrade } from '@proton/pass/hooks/useNavigateToUpgrade'; import clsx from '@proton/utils/clsx'; type UpgradeButtonProps = { className?: string; inline?: boolean; label?: string; }; export const UpgradeButton: VFC<UpgradeButtonProps> = ({ className, inline = false, label }) => { const navigateToUpgrade = useNavigateToUpgrade(); const ButtonComponent = inline ? InlineLinkButton : Button; const buttonProps = { pill: true, shape: 'solid' } as const; return ( <ButtonComponent className={clsx( 'flex-align-items-center flex-nowrap flex-item-noshrink', inline ? 'inline-flex' : 'flex text-sm', className )} color="norm" onClick={navigateToUpgrade} {...(!inline && buttonProps)} > {label || c('Action').t`Upgrade`} <Icon className="ml-2" name="arrow-out-square" /> </ButtonComponent> ); };
7,606
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Card/Card.scss
.pass-card { background: var(--interaction-weak); }
7,607
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Card/Card.tsx
import type { FC } from 'react'; import { Card as CoreCard } from '@proton/atoms/Card'; import clsx from '@proton/utils/clsx'; import './Card.scss'; type ItemCardProps = { className?: string }; export const Card: FC<ItemCardProps> = ({ children, className }) => ( <CoreCard rounded background={false} bordered={false} className={clsx('pass-card text-sm', className)}> {children} </CoreCard> );
7,608
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Dropdown/CountLabel.tsx
import type { VFC } from 'react'; type Props = { label: string; count: number }; export const CountLabel: VFC<Props> = ({ label, count }) => ( <> <span className="block text-ellipsis">{label}</span> <span className="flex-item-noshrink color-weak">({count})</span> </> );
7,609
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Dropdown/DropdownMenuButton.tsx
import { Children, type FC, type MouseEvent, type ReactElement, type ReactNode, cloneElement, isValidElement, } from 'react'; import { c } from 'ttag'; import { Button } from '@proton/atoms/Button'; import { Dropdown, DropdownMenu, Icon, usePopperAnchor } from '@proton/components'; import type { IconName } from '@proton/components/components'; import type { Props as DropdownMenuButtonCoreProps } from '@proton/components/components/dropdown/DropdownMenuButton'; import { default as DropdownMenuButtonCore } from '@proton/components/components/dropdown/DropdownMenuButton'; import clsx from '@proton/utils/clsx'; type QuickActionChildProp = { onClick: (evt: MouseEvent) => void }; type QuickActionChild = ReactElement<QuickActionChildProp>; const QuickActionsDropdown: FC<{ children: QuickActionChild[] }> = ({ children }) => { const { anchorRef, isOpen, toggle, close } = usePopperAnchor<HTMLButtonElement>(); const handleClick = (evt: MouseEvent) => { evt.stopPropagation(); toggle(); }; return ( <> <Button icon pill size="small" color="weak" onClick={handleClick} ref={anchorRef} shape="ghost" title={c('Action').t`More options`} > <Icon name="three-dots-vertical" alt={c('Action').t`More options`} color="var(--text-weak)" /> </Button> <Dropdown isOpen={isOpen} anchorRef={anchorRef} onClose={close}> <DropdownMenu> {Children.toArray(children).map((child) => isValidElement<QuickActionChildProp>(child) ? cloneElement<QuickActionChildProp>(child, { onClick: (evt: MouseEvent) => { child.props.onClick?.(evt); close(); }, }) : null )} </DropdownMenu> </Dropdown> </> ); }; type DropdownMenuButtonLabelProps = { label: ReactNode; labelClassname?: string; icon?: IconName | ReactElement; extra?: ReactNode; ellipsis?: boolean; danger?: boolean; }; export const DropdownMenuButtonLabel: FC<DropdownMenuButtonLabelProps> = ({ label, labelClassname, icon, extra, ellipsis = true, danger = false, }) => { return ( <div className="flex flex-justify-space-between flex-align-items-center flex-nowrap gap-2 max-h-custom" style={{ '--max-h-custom': '1.25rem' }} > <div className={clsx(labelClassname, 'flex flex-align-items-center flex-nowrap gap-2')}> {typeof icon === 'string' ? ( <Icon name={icon} className={clsx(danger ? 'color-danger' : 'color-weak', 'flex-item-noshrink')} /> ) : ( icon )} <div className={clsx( 'flex flex-nowrap flex-item-fluid-auto gap-1', ellipsis && 'text-ellipsis', danger && 'color-danger' )} > {label} </div> </div> {extra} </div> ); }; interface DropdownMenuButtonProps extends DropdownMenuButtonCoreProps, DropdownMenuButtonLabelProps { children?: ReactNode; className?: string; parentClassName?: string; isSelected?: boolean; quickActions?: QuickActionChild[]; size?: 'small' | 'medium'; } export const DropdownMenuButton: FC<DropdownMenuButtonProps> = ({ children, className, parentClassName, isSelected, quickActions, size = 'medium', icon, danger, label, labelClassname, extra, ellipsis = true, style, ...rest }) => { const extraPadding = quickActions !== undefined ? 'pr-3' : ''; return ( <div className={clsx('relative flex-item-noshrink', parentClassName)} style={style}> <DropdownMenuButtonCore className={clsx(size === 'small' && 'text-sm', className)} // translator : "Selected" is singular only title={isSelected ? c('Label').t`Selected` : undefined} {...rest} > <DropdownMenuButtonLabel icon={icon} ellipsis={ellipsis} danger={danger} label={label} labelClassname={labelClassname} extra={ <div className={clsx( 'flex flex-align-items-center flex-item-noshrink flex-nowrap color-weak', extraPadding )} > {isSelected && ( <div className={clsx('ml-auto')}> <Icon name="checkmark" color="var(--interaction-norm-major-1)" /> </div> )} {extra} </div> } /> </DropdownMenuButtonCore> <div className="absolute flex flex-align-items-center h-full right top"> {quickActions && <QuickActionsDropdown>{quickActions}</QuickActionsDropdown>} </div> </div> ); };
7,610
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Dropdown/MoreInfoDropdown.tsx
import { type VFC, useRef } from 'react'; import { c } from 'ttag'; import { Collapsible, CollapsibleContent, CollapsibleHeader, CollapsibleHeaderIconButton, Icon, } from '@proton/components'; type Props = { info: { label: string; values: string[] }[] }; export const MoreInfoDropdown: VFC<Props> = ({ info }) => { const anchorRef = useRef<HTMLDivElement>(null); const handleClick = () => setTimeout(() => anchorRef?.current?.scrollIntoView({ behavior: 'smooth' }), 50); return ( <Collapsible> <CollapsibleHeader disableFullWidth onClick={handleClick} className="pt-2 text-sm" suffix={ <CollapsibleHeaderIconButton className="p-0" onClick={handleClick}> <Icon name="chevron-down" className="color-weak" /> </CollapsibleHeaderIconButton> } > <span className="flex flex-align-items-center color-weak text-semibold"> <Icon className="mr-2" name="info-circle" /> <span>{c('Button').t`More info`}</span> </span> </CollapsibleHeader> <CollapsibleContent className="color-weak pt-4 text-sm"> {info.map(({ label, values }, idx) => ( <div className="flex mb-2" key={`${label}-${idx}`} {...(idx === info.length - 1 ? { ref: anchorRef } : {})} > <div className="mr-6 text-right w-custom" style={{ '--w-custom': '5rem' }}>{`${label}:`}</div> <div> {values.map((value) => ( <div key={value}>{value}</div> ))} </div> </div> ))} </CollapsibleContent> </Collapsible> ); };
7,611
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Dropdown/QuickActionsDropdown.tsx
import type { CSSProperties, FC } from 'react'; import { c } from 'ttag'; import type { ButtonLikeShape, ButtonLikeSize } from '@proton/atoms/Button'; import { Button } from '@proton/atoms/Button'; import { Dropdown, DropdownMenu, Icon, type IconSize, type PopperPlacement, usePopperAnchor, } from '@proton/components/index'; export type QuickActionsDropdownProps = { className?: string; color?: 'weak' | 'norm'; disabled?: boolean; iconSize?: IconSize; menuClassName?: string; offset?: number; originalPlacement?: PopperPlacement; shape?: ButtonLikeShape; size?: ButtonLikeSize; style?: CSSProperties; }; export const QuickActionsDropdown: FC<QuickActionsDropdownProps> = ({ children, className, color, disabled, iconSize = 20, menuClassName, offset, originalPlacement, shape, size = 'medium', style, }) => { const { anchorRef, isOpen, toggle, close } = usePopperAnchor<HTMLButtonElement>(); return ( <> <Button icon pill color={color} shape={shape} size={size} className={className} ref={anchorRef} onClick={toggle} disabled={disabled} title={c('Action').t`More options`} style={style} > <Icon name="three-dots-vertical" alt={c('Action').t`More options`} size={iconSize} /> </Button> <Dropdown isOpen={isOpen} anchorRef={anchorRef} onClose={close} originalPlacement={originalPlacement} offset={offset} > <DropdownMenu className={menuClassName}>{children}</DropdownMenu> </Dropdown> </> ); };
7,612
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Icon/IconBox.scss
.pass-item-icon { background: var(--interaction-weak); &--has-image { background: white; } }
7,613
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Icon/IconBox.tsx
import type { ReactNode, VFC } from 'react'; import type { IconSize } from '@proton/components/components'; import clsx from '@proton/utils/clsx'; import './IconBox.scss'; type Props = { children: ReactNode; className?: string; size: IconSize; mode: 'image' | 'icon' | 'transparent' }; const getOuterSize = (size: IconSize) => Math.round(size * 1.8); export const IconBox: VFC<Props> = ({ size, mode, className, children }) => { const outerSize = getOuterSize(size); return ( <div className={clsx( 'w-custom h-custom rounded-xl overflow-hidden relative', mode === 'icon' && 'pass-item-icon', mode === 'image' && 'pass-item-icon pass-item-icon--has-image', className )} style={{ '--w-custom': `${outerSize}px`, '--h-custom': `${outerSize}px` }} > {children} </div> ); };
7,614
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Icon/ItemIcon.tsx
import type { ReactNode } from 'react'; import { type VFC, useCallback, useState } from 'react'; import { useSelector } from 'react-redux'; import { CircleLoader } from '@proton/atoms/CircleLoader'; import type { IconName, IconSize } from '@proton/components'; import { Icon } from '@proton/components'; import { selectCanLoadDomainImages } from '@proton/pass/store/selectors'; import type { Item, ItemMap, ItemRevisionWithOptimistic, MaybeNull } from '@proton/pass/types'; import clsx from '@proton/utils/clsx'; import { IconBox } from './IconBox'; import { ImageStatus, ProxiedDomainImage } from './ProxiedDomainImage'; export const itemTypeToIconName: ItemMap<IconName> = { login: 'user', note: 'file-lines', alias: 'alias', creditCard: 'credit-card', }; export const presentItemIcon = (item: Item) => itemTypeToIconName[item.type]; type BaseItemIconProps = { icon: IconName; url?: MaybeNull<string>; size: IconSize; loadImage?: boolean; alt: string; className?: string; iconClassName?: string; renderIndicators?: () => ReactNode; }; type ItemIconProps = { item: ItemRevisionWithOptimistic; size: IconSize; className: string }; export const BaseItemIcon: VFC<BaseItemIconProps> = ({ icon, url, size, loadImage = true, alt, className, iconClassName, renderIndicators, }) => { const [imageStatus, setImageStatus] = useState<ImageStatus>(ImageStatus.LOADING); const handleStatusChange = useCallback((status: ImageStatus) => setImageStatus(status), []); return ( <IconBox size={size} className={className} mode={url && imageStatus === ImageStatus.READY ? 'image' : 'icon'}> <span className="sr-only">{alt}</span> {loadImage && ( <ProxiedDomainImage className={clsx('w-custom h-custom absolute-center', iconClassName)} style={{ '--w-custom': `${size}px`, '--h-custom': `${size}px` }} onStatusChange={handleStatusChange} status={imageStatus} url={url ?? ''} /> )} {imageStatus !== ImageStatus.READY && ( <Icon className={clsx('absolute-center', iconClassName)} color="var(--interaction-norm)" name={icon} size={size} /> )} {renderIndicators?.()} </IconBox> ); }; export const ItemIcon: VFC<ItemIconProps> = ({ item, size, className }) => { const { data, optimistic, failed } = item; const loadDomainImages = useSelector(selectCanLoadDomainImages); const domainURL = data.type === 'login' ? data.content.urls?.[0] : null; const renderIndicators = () => { if (failed) { return ( <Icon className="absolute-center" color="var(--signal-warning)" name="exclamation-circle-filled" size={size} /> ); } if (optimistic) { return <CircleLoader size="small" className="upper-layer color-primary absolute-center opacity-60" />; } }; return ( <BaseItemIcon icon={presentItemIcon(data)} url={domainURL} size={size} alt={data.type} className={className} iconClassName={clsx(optimistic && 'opacity-30', failed && 'hidden')} renderIndicators={renderIndicators} loadImage={loadDomainImages} /> ); };
7,615
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Icon/PassIcon.tsx
import type { VFC } from 'react'; import type { IconSize } from '@proton/components/components'; import type { PassIconStatus } from '@proton/pass/types/data/pass-icon'; type Props = { status: PassIconStatus; size: IconSize; className?: string }; export const PassIcon: VFC<Props> = ({ status, size, className }) => ( <img src={`/assets/${status}.svg`} width={size} height={size} alt={''} className={className} /> );
7,616
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Icon/ProxiedDomainImage.tsx
import { type CSSProperties, type VFC, useEffect, useMemo } from 'react'; import { usePassCore } from '@proton/pass/components/Core/PassCoreProvider'; import { safeCall } from '@proton/pass/utils/fp/safe-call'; import { isValidURL } from '@proton/pass/utils/url/is-valid-url'; export enum ImageStatus { LOADING, READY, ERROR, } type Props = { className?: string; status: ImageStatus; style?: CSSProperties; url: string; onStatusChange: (status: ImageStatus) => void; }; export const ProxiedDomainImage: VFC<Props> = ({ className, status, style = {}, url, onStatusChange }) => { const { getDomainImageURL } = usePassCore(); const domain = useMemo(() => safeCall(() => new URL(isValidURL(url).url).host)(), [url]); useEffect(() => onStatusChange(domain ? ImageStatus.LOADING : ImageStatus.ERROR), [domain, onStatusChange]); const styles = { visibility: status === ImageStatus.READY ? 'visible' : 'hidden', ...style }; return ( <img alt="" className={className} onError={() => onStatusChange(ImageStatus.ERROR)} onLoad={() => onStatusChange(ImageStatus.READY)} src={getDomainImageURL(domain)} style={styles} /> ); };
7,617
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/List/VirtualList.scss
.ReactVirtualized__List { &:focus-visible { outline: 1px solid var(--focus-outline); } }
7,618
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/List/VirtualList.tsx
import { type ForwardRefRenderFunction, type RefObject, forwardRef, useCallback, useEffect, useState } from 'react'; import type { ListRowRenderer, ScrollParams } from 'react-virtualized'; import { AutoSizer, List } from 'react-virtualized'; import clsx from '@proton/utils/clsx'; import './VirtualList.scss'; type Props = { rowRenderer: ListRowRenderer; rowCount: number; interpolationIndexes?: number[]; }; const VirtualListRender: ForwardRefRenderFunction<List, Props> = ( { rowRenderer, rowCount, interpolationIndexes = [] }, virtualListRef ) => { const [shadows, setShadows] = useState({ top: false, bottom: false }); const handleScroll = useCallback(({ scrollTop, clientHeight, scrollHeight }: ScrollParams) => { const scrollable = clientHeight > 0 && scrollHeight > clientHeight; setShadows({ top: scrollable && scrollTop > 0 && scrollHeight > clientHeight, bottom: scrollable && scrollTop + clientHeight < scrollHeight, }); }, []); useEffect(() => { (virtualListRef as RefObject<List>).current?.recomputeRowHeights(); }, [interpolationIndexes]); return ( <div className="h-full scroll-outer-vertical"> <div className={clsx('scroll-start-shadow no-pointer-events', shadows.top && 'scroll-start-shadow-visible')} aria-hidden="true" /> <div className={clsx('scroll-end-shadow no-pointer-events', shadows.bottom && 'scroll-end-shadow-visible')} aria-hidden="true" /> <AutoSizer> {({ height, width }) => ( <List className="unstyled m-0" style={{ overflowY: 'overlay' }} ref={virtualListRef} onScroll={handleScroll} onScrollbarPresenceChange={({ vertical }) => setShadows({ top: false, bottom: vertical })} rowRenderer={rowRenderer} rowCount={rowCount} height={height} width={width - 1} /* account for react-virtualized ceiling */ rowHeight={({ index }) => (interpolationIndexes.includes(index) ? 28 : 54)} /> )} </AutoSizer> </div> ); }; export const VirtualList = forwardRef(VirtualListRender);
7,619
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Lobby/LobbyContent.scss
@import '~@proton/styles/scss/lib'; .pass-lobby--heading { font-size: rem(24); line-height: 0.9; } .pass-lobby--brand-text { opacity: 0.8; }
7,620
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Lobby/LobbyContent.tsx
import { type ReactNode, type VFC, useEffect, useState } from 'react'; import { c } from 'ttag'; import { Button, CircleLoader } from '@proton/atoms'; import passBrandText from '@proton/pass/assets/protonpass-brand.svg'; import { Unlock } from '@proton/pass/components/Lock/Unlock'; import { clientBusy, clientErrored, clientLocked, clientStale } from '@proton/pass/lib/client'; import { AppStatus, type Maybe } from '@proton/pass/types'; import { BRAND_NAME, PASS_APP_NAME } from '@proton/shared/lib/constants'; import './LobbyContent.scss'; const ERROR_TIMEOUT = 15_000; type Props = { status: AppStatus; onLogin: () => void; onLogout: (options: { soft: boolean }) => void; onRegister: () => void; renderError: () => ReactNode; }; export const LobbyContent: VFC<Props> = ({ status, onLogin, onLogout, onRegister, renderError }) => { const [timeoutError, setTimeoutError] = useState(false); const stale = clientStale(status); const busy = clientBusy(status); const locked = clientLocked(status); const canSignOut = clientErrored(status) || locked; useEffect(() => { setTimeoutError(false); let timer: Maybe<NodeJS.Timeout> = stale ? setTimeout(() => setTimeoutError(true), ERROR_TIMEOUT) : undefined; return () => clearTimeout(timer); }, [stale]); const brandNameJSX = ( <img src={passBrandText} className="pass-lobby--brand-text ml-2 h-custom" style={{ '--h-custom': '1.5rem' }} key="brand" alt="" /> ); if (busy) { return timeoutError ? ( <>{renderError()}</> ) : ( <div key="lobby-loading" className="flex flex-column flex-align-items-center gap-3 mt-12 w-full anime-fade-in" style={{ '--anime-delay': '250ms' }} > <CircleLoader size="medium" /> <span className="block text-sm text-weak"> {(() => { switch (status) { case AppStatus.AUTHORIZED: case AppStatus.AUTHORIZING: // translator: status message displayed when loading return c('Info').t`Signing you in`; case AppStatus.BOOTING: return c('Info').t`Decrypting your data`; default: return c('Info').t`Loading ${PASS_APP_NAME}`; } })()} </span> </div> ); } return ( <div key="lobby" className="anime-fade-in" style={{ '--anime-delay': '250ms' }}> <div className="flex flex-column flex-align-items-center gap-3"> <span className="pass-lobby--heading text-bold text-norm flex flex-align-items-end flex-justify-center user-select-none"> {locked ? c('Title').jt`Unlock ${brandNameJSX}` : c('Title').jt`Welcome to ${brandNameJSX}`} </span> <span className="text-norm"> {locked ? c('Info').jt`Enter your PIN code` : c('Info').jt`Sign in to your account`} </span> </div> <div className="flex-item-fluid mt-8 flex flex-column gap-2"> {!locked && ( <Button pill shape="solid" color="norm" className="w-full" onClick={onLogin}> {clientErrored(status) ? c('Action').t`Sign back in` : c('Action').t`Sign in with ${BRAND_NAME}`} </Button> )} {!(locked || canSignOut) && ( <Button pill shape="solid" color="weak" className="w-full" onClick={onRegister}> {c('Action').t`Create a ${BRAND_NAME} account`} </Button> )} {locked && ( <div className="mb-8"> <Unlock /> </div> )} {canSignOut && ( <Button pill shape="outline" color="danger" className="w-full" onClick={() => onLogout({ soft: true })} > {c('Action').t`Sign out`} </Button> )} </div> </div> ); };
7,621
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Lobby/LobbyLayout.scss
@import '~@proton/styles/scss/lib'; @import '~@proton/pass/styles/lobby'; .pass-lobby--content::before { content: ''; display: block; block-size: rem(100); }
7,622
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Lobby/LobbyLayout.tsx
import type { FC } from 'react'; import protonPassIcon from '@proton/pass/assets/protonpass-icon.svg'; import clsx from '@proton/utils/clsx'; import './LobbyLayout.scss'; export const LobbyLayout: FC<{ overlay: boolean }> = ({ overlay, children }) => { return ( <div className="pass-lobby relative p-7 anime-fade-in" style={{ '--anime-duration': '450ms', '--anime-delay': '100ms' }} > <div className="absolute absolute-center-x top-custom anime-fade-in" style={{ '--top-custom': '-200px', '--anime-duration': '550ms', '--anime-delay': '150ms' }} > <img src={protonPassIcon} className={clsx('pass-lobby--logo w-custom max-w-custom', !overlay && 'pass-lobby--logo-hidden')} style={{ '--w-custom': '18.25rem' }} alt="" /> </div> <div className="pass-lobby--content flex flex-column h-full w-custom mx-auto text-center gap-2" style={{ '--w-custom': '18.75rem' }} > {children} </div> </div> ); };
7,623
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Modal/SidebarModal.scss
.pass-modal-two--sidebar, .pass-modal-two--sidebar-content { &.modal-two { inline-size: var(--popup-width, 100%); block-size: var(--popup-height, 100%); padding: 0; align-content: flex-end; flex-wrap: wrap; } .modal-two-dialog { animation-name: anime-modal-two-sidebar-dialog-in; border-radius: 0; block-size: var(--popup-height, 100%); } &.modal-two--out .modal-two-dialog { animation-name: anime-modal-two-sidebar-dialog-out; } } .pass-modal-two--sidebar .modal-two-dialog { --size: 55%; } .pass-modal-two--sidebar-content .modal-two-dialog { --size: 59.67%; } @keyframes anime-modal-two-sidebar-dialog-in { 0% { transform: translateX(100%); } 100% { transform: translateX(0); } } @keyframes anime-modal-two-sidebar-dialog-out { 0% { transform: translateX(0); } 100% { transform: translateX(100%); } }
7,624
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Modal/SidebarModal.tsx
import { type FC, type ReactNode, useCallback, useEffect, useRef, useState } from 'react'; import type { ModalProps } from '@proton/components'; import { ModalTwo } from '@proton/components'; import './SidebarModal.scss'; type Props = Omit<ModalProps, 'children'> & { children: ReactNode | ((didEnter: boolean) => ReactNode) }; export const SidebarModal: FC<Props> = ({ children, className, ...props }) => { const [didEnter, setDidEnter] = useState(false); const timer = useRef<NodeJS.Timeout>(); useEffect(() => { if (!props.open) setDidEnter(false); }, [props.open]); useEffect(() => () => clearTimeout(timer.current), []); const onEnter = useCallback(() => { props.onEnter?.(); timer.current = setTimeout(() => setDidEnter(true), 250); }, [props.onEnter]); return ( <ModalTwo rootClassName="pass-modal-two--sidebar" className={className} onBackdropClick={props.onClose} {...props} onEnter={onEnter} > <div className="h-full">{typeof children === 'function' ? children(didEnter) : children}</div> </ModalTwo> ); };
7,625
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Panel/DiscardableModalPanel.tsx
import { type FC, type ReactNode, useCallback, useState } from 'react'; import { c } from 'ttag'; import { ConfirmationModal } from '@proton/pass/components/Confirmation/ConfirmationModal'; import type { Callback } from '@proton/pass/types'; import { useEnsureMounted } from '../../../hooks/useEnsureMounted'; import { SidebarModal } from '../Modal/SidebarModal'; export type DiscardableModalRenderProps = { confirm: (effect?: Callback) => void; didEnter: boolean }; export type DiscardableModalProps = { discardable: boolean; onDiscard: () => void; children: (props: DiscardableModalRenderProps) => ReactNode; }; /* The didMount state is passed as a render prop to the children so * that they are informed when the modal has appeared on the screen * and completed its reveal animation. This is particularly useful * when the children contain input elements that need to be autofocused * after the modal has finished appearing. By doing this, we can avoid * animation glitches related to the "flickering caret" problem that * can occur with CSS animations. The "flickering caret" problem refers * to the flickering effect that can happen when the input's text cursor * rapidly gains and loses focus, leading to visual inconsistencies. */ export const DiscardableModalPanel: FC<DiscardableModalProps> = ({ discardable, onDiscard, children }) => { const ensureMounted = useEnsureMounted(); const [confirm, setConfirm] = useState<{ opened: boolean }>({ opened: false }); const doConfirm = useCallback(() => setConfirm({ opened: true }), []); const onBackdropClick = useCallback(discardable ? onDiscard : () => setConfirm({ opened: true }), [discardable]); return ( <div> <SidebarModal open onBackdropClick={onBackdropClick} rootClassName="pass-modal-two--sidebar-content"> {(didEnter) => children({ confirm: doConfirm, didEnter })} </SidebarModal> <ConfirmationModal title={c('Title').t`Discard changes?`} open={confirm.opened} onClose={() => ensureMounted(setConfirm)({ opened: false }) /* view may have been unmounted */} onSubmit={onDiscard} alertText={c('Warning').t`You have unsaved changes.`} submitText={c('Action').t`Discard`} /> </div> ); };
7,626
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Panel/ItemCreatePanel.tsx
import type { FC, ReactElement } from 'react'; import { c } from 'ttag'; import { Button } from '@proton/atoms'; import { Icon } from '@proton/components'; import { itemTypeToSubThemeClassName } from '@proton/pass/components/Layout/Theme/types'; import type { ItemType } from '@proton/pass/types'; import { DiscardableModalPanel, type DiscardableModalProps } from './DiscardableModalPanel'; import { Panel } from './Panel'; import { PanelHeader } from './PanelHeader'; type Props = { type: ItemType; formId: string; valid: boolean; handleCancelClick: () => void; renderSubmitButton?: ReactElement; } & Omit<DiscardableModalProps, 'onDiscard'>; function getItemTypeSubmitButtonLabel(type: ItemType) { switch (type) { case 'login': return c('Action').t`Create login`; case 'alias': return c('Action').t`Create alias`; case 'note': return c('Action').t`Create note`; case 'creditCard': return c('Action').t`Create card`; default: return c('Action').t`Create`; } } export const ItemCreatePanel: FC<Props> = ({ type, formId, valid, discardable, handleCancelClick, renderSubmitButton, children, }) => ( <DiscardableModalPanel onDiscard={handleCancelClick} discardable={discardable}> {(props) => ( <Panel className={itemTypeToSubThemeClassName[type]} header={ <PanelHeader actions={[ <Button key="cancel-button" icon pill shape="solid" color="weak" onClick={() => (discardable ? handleCancelClick() : props.confirm())} title={c('Action').t`Cancel`} > <Icon name="cross" alt={c('Action').t`Cancel`} /> </Button>, renderSubmitButton || ( <Button className="text-sm" key="submit-button" pill shape="solid" color="norm" type="submit" form={formId} disabled={!valid} > {getItemTypeSubmitButtonLabel(type)} </Button> ), ]} /> } > {children(props)} </Panel> )} </DiscardableModalPanel> );
7,627
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Panel/ItemEditPanel.tsx
import type { FC } from 'react'; import { c } from 'ttag'; import { Button } from '@proton/atoms'; import { Icon } from '@proton/components'; import { itemTypeToSubThemeClassName } from '@proton/pass/components/Layout/Theme/types'; import type { ItemType } from '@proton/pass/types'; import { DiscardableModalPanel, type DiscardableModalProps } from './DiscardableModalPanel'; import { Panel } from './Panel'; import { PanelHeader } from './PanelHeader'; type Props = { type: ItemType; formId: string; valid: boolean; handleCancelClick: () => void; } & Omit<DiscardableModalProps, 'onDiscard'>; export const ItemEditPanel: FC<Props> = ({ type, formId, valid, discardable, handleCancelClick, children }) => ( <DiscardableModalPanel onDiscard={handleCancelClick} discardable={discardable}> {(props) => ( <Panel className={itemTypeToSubThemeClassName[type]} header={ <PanelHeader actions={[ <Button key="cancel-button" icon pill shape="solid" color="weak" onClick={() => (discardable ? handleCancelClick() : props.confirm())} title={c('Action').t`Cancel`} > <Icon name="cross" alt={c('Action').t`Cancel`} /> </Button>, <Button className="text-sm" key="submit-button" pill shape="solid" color="norm" type="submit" form={formId} disabled={!valid} > {c('Action').t`Save`} </Button>, ]} /> } > {children(props)} </Panel> )} </DiscardableModalPanel> );
7,628
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Panel/ItemViewPanel.tsx
import { type FC, type ReactElement } from 'react'; import { useSelector } from 'react-redux'; import { c } from 'ttag'; import { Button } from '@proton/atoms'; import { Icon } from '@proton/components'; import { DropdownMenuButton } from '@proton/pass/components/Layout/Dropdown/DropdownMenuButton'; import { QuickActionsDropdown } from '@proton/pass/components/Layout/Dropdown/QuickActionsDropdown'; import { itemTypeToSubThemeClassName } from '@proton/pass/components/Layout/Theme/types'; import { useSpotlightContext } from '@proton/pass/components/Spotlight/SpotlightContext'; import { VaultTag } from '@proton/pass/components/Vault/VaultTag'; import { VAULT_ICON_MAP } from '@proton/pass/components/Vault/constants'; import type { ItemViewProps } from '@proton/pass/components/Views/types'; import { useFeatureFlag } from '@proton/pass/hooks/useFeatureFlag'; import { isVaultMemberLimitReached } from '@proton/pass/lib/vaults/vault.predicates'; import type { VaultShareItem } from '@proton/pass/store/reducers'; import { selectAllVaults, selectPassPlan } from '@proton/pass/store/selectors'; import { type ItemType, ShareRole } from '@proton/pass/types'; import { PassFeature } from '@proton/pass/types/api/features'; import { UserPassPlan } from '@proton/pass/types/api/plan'; import { Panel } from './Panel'; import { PanelHeader } from './PanelHeader'; type Props = { type: ItemType; name: string; vault: VaultShareItem; actions?: ReactElement[]; quickActions?: ReactElement[]; } & Omit<ItemViewProps, 'revision' | 'vault'>; export const ItemViewPanel: FC<Props> = ({ type, name, vault, optimistic, failed, trashed, actions = [], quickActions = [], handleEditClick, handleRetryClick, handleDismissClick, handleMoveToTrashClick, handleMoveToVaultClick, handleRestoreClick, handleDeleteClick, handleInviteClick, handleManageClick, children, }) => { const vaults = useSelector(selectAllVaults); const plan = useSelector(selectPassPlan); const sharingEnabled = useFeatureFlag(PassFeature.PassSharingV1); const hasMultipleVaults = vaults.length > 1; const { shareRoleId, shared } = vault; const showVaultTag = hasMultipleVaults || shared; const readOnly = shareRoleId === ShareRole.READ; const sharedReadOnly = shared && readOnly; const spotlight = useSpotlightContext(); return ( <Panel className={itemTypeToSubThemeClassName[type]} header={ <PanelHeader title={name} actions={(() => { if (failed) { return [ <Button key="dismiss-item-button" pill className="mr-1" color="danger" shape="outline" onClick={handleDismissClick} > {c('Action').t`Dismiss`} </Button>, <Button key="retry-item-button" pill color="norm" onClick={handleRetryClick}> {c('Action').t`Retry`} </Button>, ]; } if (trashed) { return [ <QuickActionsDropdown key="item-quick-actions-dropdown" color="weak" shape="solid" disabled={optimistic} > <DropdownMenuButton onClick={handleRestoreClick} label={c('Action').t`Restore item`} icon="arrows-rotate" disabled={sharedReadOnly} /> <DropdownMenuButton onClick={handleDeleteClick} label={c('Action').t`Delete permanently`} icon="trash-cross" disabled={sharedReadOnly} /> </QuickActionsDropdown>, ]; } return [ <Button className="flex flex-align-center text-sm" key="edit-item-button" pill shape="solid" color="norm" onClick={handleEditClick} disabled={optimistic || readOnly} > <Icon name="pencil" className="mr-1" /> <span>{c('Action').t`Edit`}</span> </Button>, ...actions, sharingEnabled && !shared && ( <Button key="share-item-button" icon pill color="weak" shape="solid" size="medium" title={c('Action').t`Share`} disabled={readOnly} onClick={ plan === UserPassPlan.FREE && isVaultMemberLimitReached(vault) ? () => spotlight.setUpselling('pass-plus') : handleInviteClick } > <Icon name="users-plus" alt={c('Action').t`Share`} size={20} /> </Button> ), shared && ( <Button key="manage-item-button" icon pill color="weak" shape="solid" size="medium" title={c('Action').t`See members`} onClick={handleManageClick} > <Icon name="users-plus" alt={c('Action').t`See members`} size={20} /> </Button> ), <QuickActionsDropdown key="item-quick-actions-dropdown" color="weak" disabled={optimistic} shape="solid" > {hasMultipleVaults && ( <DropdownMenuButton onClick={handleMoveToVaultClick} label={c('Action').t`Move to another vault`} icon="folder-arrow-in" disabled={sharedReadOnly} /> )} {quickActions} <DropdownMenuButton onClick={handleMoveToTrashClick} label={c('Action').t`Move to Trash`} icon="trash" disabled={sharedReadOnly} /> </QuickActionsDropdown>, ]; })()} subtitle={ showVaultTag ? ( <VaultTag title={vault.content.name} color={vault.content.display.color} count={vault.targetMembers} shared={vault.shared} icon={ vault.content.display.icon ? VAULT_ICON_MAP[vault.content.display.icon] : 'pass-all-vaults' } /> ) : undefined } /> } > {children} </Panel> ); };
7,629
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Panel/Panel.scss
.pass-panel { min-block-size: 100%; max-block-size: 100%; overflow: hidden; &--content { transition: opacity 250ms ease-in-out; } }
7,630
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Panel/Panel.tsx
import type { ReactNode, VFC } from 'react'; import { CircleLoader } from '@proton/atoms/CircleLoader'; import { Scroll } from '@proton/atoms/Scroll'; import clsx from '@proton/utils/clsx'; import './Panel.scss'; type Props = { header?: ReactNode; children?: ReactNode; className?: string; loading?: boolean; }; export const Panel: VFC<Props> = ({ header, children, className, loading }) => { return ( <article className={clsx('pass-panel flex flex-column flex-nowrap', className)}> {header && <div className="flex-item-noshrink px-4 py-3">{header}</div>} <div className="flex-item-fluid-auto h-full overflow-hidden relative"> {loading && <CircleLoader size="small" className="upper-layer absolute-center" />} <Scroll className={clsx( 'pass-panel--content absolute w-full h-full', loading && 'opacity-30 no-pointer-events' )} > <div className="px-4 pt-1 pb-3">{children}</div> </Scroll> </div> </article> ); };
7,631
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Panel/PanelHeader.tsx
import type { ReactNode, VFC } from 'react'; import clsx from '@proton/utils/clsx'; type Props = { className?: string; title?: string; subtitle?: ReactNode; actions?: ReactNode[]; }; export const PanelHeader: VFC<Props> = ({ className, actions, ...props }) => { const title = 'title' in props ? props.title : undefined; const subtitle = 'subtitle' in props ? props.subtitle : undefined; const withActions = Array.isArray(actions) && actions.length > 0; const onlyActions = withActions && [title, subtitle].every((prop) => prop === undefined); return ( <header className={clsx( 'pass-panel-header flex flex-nowrap flex-justify-space-between flex-align-items-center gap-2', className )} > {title !== undefined && ( <div> <h2 className="text-2xl text-bold text-ellipsis lh-full mb-0-5">{title}</h2> {subtitle} </div> )} {withActions && ( <div className={clsx( 'flex flex-nowrap flex-justify-space-between flex-align-items-center flex-item-noshrink gap-1', onlyActions && 'w-full' )} > {actions} </div> )} </header> ); };
7,632
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Section/Content.scss
#content { inline-size: 59.67%; block-size: 100%; flex-shrink: 0; background-color: var(--background-norm); border-inline-start: 1px solid var(--border-norm); box-shadow: 0 0.5rem 1.5rem rgb(14 14 14 / 0.8); // When the Content is empty, hide it completely // let the sidebar take full-width. &:empty { display: none; } }
7,633
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Section/Content.tsx
import type { FC } from 'react'; import './Content.scss'; export const Content: FC = ({ children }) => { return <div id="content">{children}</div>; };
7,634
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Section/Sidebar.scss
#pass-sidebar { min-inline-size: 20em; }
7,635
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Section/Sidebar.tsx
import { type FC } from 'react'; import { Logo } from '@proton/components/components'; import { getAppName } from '@proton/shared/lib/apps/helper'; import { APPS } from '@proton/shared/lib/constants'; import './Sidebar.scss'; type Props = { expanded: boolean; onToggle: () => void }; export const Sidebar: FC<Props> = ({ children, expanded = false, onToggle }) => ( <> <div id="pass-sidebar" className="sidebar flex flex-nowrap flex-column outline-none bg-strong" data-expanded={expanded} > <h1 className="sr-only">{getAppName(APPS.PROTONPASS)}</h1> <div className="logo-container hidden md:flex flex-item-noshrink flex-justify-space-between flex-align-items-center flex-nowrap"> <Logo appName={APPS.PROTONPASS} /> </div> <div className="mt-1 md:mt-0" aria-hidden="true" /> <div className="flex-item-fluid flex-nowrap flex flex-column overflow-overlay pb-2 md:mt-2">{children}</div> </div> {expanded && <div className="sidebar-backdrop" onClick={onToggle} role="button" />} </> );
7,636
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Section/SubSidebar.scss
#pass-sub-sidebar { inline-size: 100%; block-size: 100%; display: flex; flex-flow: column nowrap; justify-content: flex-start; align-items: stretch; }
7,637
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Section/SubSidebar.tsx
import type { FC } from 'react'; import './SubSidebar.scss'; export const SubSidebar: FC = ({ children }) => ( <div id="pass-sub-sidebar" className="flex-item-fluid relative"> {children} </div> );
7,638
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Theme/ThemeProvider.tsx
import type { FC } from 'react'; // @ts-ignore import theme from '@proton/colors/themes/dist/pass.theme.css'; export const THEME_ID = 'theme-root'; export const ThemeProvider: FC = () => { return <style id={THEME_ID}>{theme.toString()}</style>; };
7,639
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout
petrpan-code/ProtonMail/WebClients/packages/pass/components/Layout/Theme/types.ts
import type { ItemMap } from '@proton/pass/types'; export enum SubTheme { LIME = 'ui-lime', ORANGE = 'ui-orange', RED = 'ui-red', TEAL = 'ui-teal', VIOLET = 'ui-violet', } export const itemTypeToSubThemeClassName: ItemMap<SubTheme> = { alias: SubTheme.TEAL, creditCard: SubTheme.LIME, login: SubTheme.VIOLET, note: SubTheme.ORANGE, };
7,640
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Lock/LockConfirmContextProvider.tsx
import { type FC, createContext, useContext, useMemo } from 'react'; import { c } from 'ttag'; import { type UseAsyncModalHandle, useAsyncModalHandles } from '../../hooks/useAsyncModalHandles'; import { LockPinModal } from './LockPinModal'; type ModalState = { title: string; assistiveText: string }; type LockConfirmContextValue = { confirmPin: UseAsyncModalHandle<string, ModalState> }; const LockConfirmContext = createContext<LockConfirmContextValue>({ confirmPin: async () => {} }); const getInitialModalState = (): ModalState => ({ title: c('Title').t`Enter your PIN`, assistiveText: c('Info').t`Please enter your current PIN code to continue`, }); export const LockConfirmContextProvider: FC = ({ children }) => { const { handler, abort, resolver, state } = useAsyncModalHandles<string, ModalState>({ getInitialModalState }); const contextValue = useMemo<LockConfirmContextValue>(() => ({ confirmPin: handler }), [handler]); return ( <LockConfirmContext.Provider value={contextValue}> {children} <LockPinModal onSubmit={resolver} onClose={abort} {...state} /> </LockConfirmContext.Provider> ); }; export const useSessionLockConfirmContext = () => useContext(LockConfirmContext);
7,641
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Lock/LockCreate.tsx
import { type VFC, useCallback } from 'react'; import { c } from 'ttag'; import { useNotifications } from '@proton/components/index'; import { PASS_APP_NAME } from '@proton/shared/lib/constants'; import { useSessionLockConfirmContext } from './LockConfirmContextProvider'; import { LockPinModal } from './LockPinModal'; type Props = { opened: boolean; onClose: () => void; onSubmit: (options: { pin: string; ttl: number }) => void; }; export const LockCreate: VFC<Props> = ({ opened, onClose, onSubmit }) => { const { createNotification } = useNotifications(); const { confirmPin } = useSessionLockConfirmContext(); const handleOnSubmit = useCallback( async (pin: string) => { onClose(); const options: Parameters<typeof confirmPin>[0] = { title: c('Title').t`Confirm PIN code`, assistiveText: c('Info').t`Please confirm your PIN code to finish registering your auto-lock settings.`, onError: () => confirmPin(options) /* recurse on error */, onSubmit: (pinConfirmation) => { if (pin !== pinConfirmation) { createNotification({ type: 'error', text: c('Error').t`PIN codes do not match`, }); throw new Error('invalid'); } onSubmit({ pin: pinConfirmation, ttl: 900 /* default to 15 minutes */ }); }, }; await confirmPin(options); }, [onClose] ); return ( <LockPinModal open={opened} title={c('Title').t`Create PIN code`} assistiveText={c('Info') .t`You will use this PIN to unlock ${PASS_APP_NAME} once it auto-locks after a period of inactivity.`} onSubmit={handleOnSubmit} onClose={onClose} /> ); };
7,642
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Lock/LockPinModal.tsx
import { type VFC, useEffect, useState } from 'react'; import { Card } from '@proton/atoms/Card'; import { type ModalProps, ModalTwo, ModalTwoContent, ModalTwoHeader } from '@proton/components/components'; import { useSessionLockPinSubmitEffect } from '../../hooks/useSessionLockPinSubmitEffect'; import { PinCodeInput } from './PinCodeInput'; type Props = Omit<ModalProps, 'onSubmit'> & { title: string; assistiveText?: string; loading?: boolean; onSubmit: (pin: string) => void; }; export const LockPinModal: VFC<Props> = ({ title, assistiveText, loading, onSubmit, ...modalProps }) => { const [value, setValue] = useState<string>(''); useSessionLockPinSubmitEffect(value, { onSubmit }); useEffect(() => { if (!modalProps.open) { setValue(''); } }, [modalProps.open]); return ( <ModalTwo {...modalProps} size="small" className="mt-10"> <ModalTwoHeader title={title} /> <ModalTwoContent className="mb-8"> {assistiveText && ( <Card rounded className="text-sm mb-7"> {assistiveText} </Card> )} <PinCodeInput loading={loading} value={value} onValue={setValue} /> </ModalTwoContent> </ModalTwo> ); };
7,643
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Lock/LockTTLUpdate.tsx
import { type VFC } from 'react'; import { c } from 'ttag'; import { InputFieldTwo, Option, SelectTwo } from '@proton/components/index'; import { useSessionLockConfirmContext } from './LockConfirmContextProvider'; type Props = { ttl?: number; disabled?: boolean; onChange: (options: { pin: string; ttl: number }) => void; }; const getSessionLockTTLOptions = () => [ { title: c('Label').t`30 seconds`, value: 30 }, { title: c('Label').t`1 minute`, value: 60 }, { title: c('Label').t`5 minutes`, value: 300 }, { title: c('Label').t`10 minutes`, value: 600 }, { title: c('Label').t`15 minutes`, value: 900 }, { title: c('Label').t`30 minutes`, value: 1800 }, { title: c('Label').t`1 hour`, value: 3600 }, ]; export const LockTTLUpdate: VFC<Props> = ({ ttl, disabled, onChange }) => { const { confirmPin } = useSessionLockConfirmContext(); const handleOnChange = async (ttl: number) => confirmPin({ onSubmit: (pin) => onChange({ pin, ttl }), title: c('Title').t`Auto-lock update`, assistiveText: c('Info').t`Please confirm your PIN code to edit this setting.`, }); return ( <InputFieldTwo as={SelectTwo<number>} label={c('Label').t`Auto-lock after`} disabled={disabled} placeholder={c('Label').t`15 minutes`} onValue={handleOnChange} value={ttl} dense > {getSessionLockTTLOptions().map(({ title, value }) => ( <Option key={value} title={title} value={value} /> ))} </InputFieldTwo> ); };
7,644
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Lock/PinCodeInput.scss
.pass-pin--input { .input { border: 1px solid var(--interaction-default-active); background: var(--field-norm); } .input.focus, .input:not(.disabled):focus-within { background: var(--field-norm); } .input:hover, .input.hover { background: var(--field-weak); } }
7,645
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Lock/PinCodeInput.tsx
import { type VFC, useEffect, useRef } from 'react'; import { TotpInput } from '@proton/components/components'; import clsx from '@proton/utils/clsx'; import './PinCodeInput.scss'; type Props = { value: string; loading?: boolean; autoFocus?: boolean; onValue: (value: string) => void; }; export const PinCodeInput: VFC<Props> = ({ value, onValue, loading = false, autoFocus = true }) => { const focusRef = useRef<HTMLInputElement>(null); useEffect(() => { if (autoFocus) focusRef.current?.focus(); }, [autoFocus]); return ( <div className={clsx('pass-pin--input', loading && 'opacity-30 no-pointer-events')}> <TotpInput ref={focusRef} length={6} value={value} onValue={onValue} inputType="password" disableChange={loading} autoFocus={autoFocus} /> </div> ); };
7,646
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Lock/Unlock.tsx
import { type VFC, useState } from 'react'; import { PinCodeInput } from '@proton/pass/components/Lock/PinCodeInput'; import { useActionRequest } from '@proton/pass/hooks/useActionRequest'; import { useSessionLockPinSubmitEffect } from '@proton/pass/hooks/useSessionLockPinSubmitEffect'; import { sessionUnlockIntent } from '@proton/pass/store/actions'; import { sessionUnlockRequest } from '@proton/pass/store/actions/requests'; export const Unlock: VFC = () => { const [value, setValue] = useState(''); const [disabled, setDisabled] = useState(false); const unlock = useActionRequest({ action: sessionUnlockIntent, initialRequestId: sessionUnlockRequest(), onStart: () => setDisabled(true), onFailure: () => setDisabled(false), }); useSessionLockPinSubmitEffect(value, { onSubmit: (pin) => unlock.dispatch({ pin }) }); return <PinCodeInput loading={disabled} value={value} onValue={setValue} />; };
7,647
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Lock/constants.ts
export const SESSION_LOCK_PIN_LENGTH = 6;
7,648
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu/Submenu.scss
.pass-submenu--item { > button { border-radius: var(--border-radius-md); padding-inline-start: 1.5em; } }
7,649
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu/Submenu.tsx
import { type FC } from 'react'; import type { IconName } from '@proton/components'; import { Collapsible, CollapsibleContent, CollapsibleHeader, CollapsibleHeaderIconButton, Icon, } from '@proton/components'; import { usePassCore } from '@proton/pass/components/Core/PassCoreProvider'; import { DropdownMenuButton, DropdownMenuButtonLabel, } from '@proton/pass/components/Layout/Dropdown/DropdownMenuButton'; import type { MenuItem } from '@proton/pass/hooks/useMenuItems'; import clsx from '@proton/utils/clsx'; import './Submenu.scss'; type Props = { contentClassname?: string; headerClassname?: string; icon: IconName; items: MenuItem[]; label: string; }; export const Submenu: FC<Props> = ({ contentClassname, headerClassname, icon, items, label }) => { const { onLink } = usePassCore(); return ( <Collapsible className="flex-item-noshrink"> <CollapsibleHeader className={clsx(headerClassname, 'flex-item-noshrink pl-4 pr-2')} suffix={ <CollapsibleHeaderIconButton className="p-0" pill size="small"> <Icon name="chevron-down" /> </CollapsibleHeaderIconButton> } > <DropdownMenuButtonLabel label={label} icon={icon} /> </CollapsibleHeader> <CollapsibleContent as="ul" className={clsx(contentClassname, 'unstyled mx-2 my-1')}> {items.map(({ url, label, icon, onClick }: MenuItem) => ( <DropdownMenuButton onClick={url ? () => onLink(url) : onClick} parentClassName="w-full pass-submenu--item" key={label} label={label} icon={icon} /> ))} </CollapsibleContent> </Collapsible> ); };
7,650
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu/Item/ItemQuickActions.tsx
import { type FC, useMemo } from 'react'; import { useSelector } from 'react-redux'; import { c } from 'ttag'; import { Button } from '@proton/atoms/Button'; import { Dropdown, DropdownMenu, DropdownMenuButton, Icon, usePopperAnchor } from '@proton/components/components'; import { DropdownMenuButtonLabel } from '@proton/pass/components/Layout/Dropdown/DropdownMenuButton'; import { itemTypeToIconName } from '@proton/pass/components/Layout/Icon/ItemIcon'; import { itemTypeToSubThemeClassName } from '@proton/pass/components/Layout/Theme/types'; import { usePasswordContext } from '@proton/pass/components/PasswordGenerator/PasswordContext'; import { useCopyToClipboard } from '@proton/pass/hooks/useCopyToClipboard'; import { selectAliasLimits, selectPassPlan } from '@proton/pass/store/selectors'; import type { ItemType } from '@proton/pass/types'; import { UserPassPlan } from '@proton/pass/types/api/plan'; import { pipe } from '@proton/pass/utils/fp/pipe'; import noop from '@proton/utils/noop'; type Props = { disabled?: boolean; onNewItem: (type: ItemType) => void; onPasswordGenerated?: (password: string) => void; }; export const ItemQuickActions: FC<Props> = ({ disabled = false, onNewItem, onPasswordGenerated }) => { const { generatePassword } = usePasswordContext(); const copyToClipboard = useCopyToClipboard(); const { needsUpgrade, aliasLimit, aliasLimited, aliasTotalCount } = useSelector(selectAliasLimits); const isFreePlan = useSelector(selectPassPlan) === UserPassPlan.FREE; const { anchorRef, isOpen, toggle, close } = usePopperAnchor<HTMLButtonElement>(); const withClose = <T extends (...args: any[]) => void>(action: T) => pipe(action, close) as T; const handleNewPasswordClick = () => { void generatePassword({ actionLabel: c('Action').t`Copy and close`, className: 'ui-red', onSubmit: (password) => { onPasswordGenerated?.(password); copyToClipboard(password).catch(noop); }, }); }; const quickActions = useMemo( () => [ { label: c('Label').t`Login`, type: 'login' }, { label: c('Label').t`Alias`, type: 'alias' }, { label: c('Label').t`Card`, type: 'creditCard' }, { label: c('Label').t`Note`, type: 'note' }, ] as const, [] ); return ( <> <Button icon pill color="norm" disabled={disabled} onClick={toggle} ref={anchorRef} size="small" title={c('Action').t`Add new item`} > <Icon name="plus" alt={c('Action').t`Add new item`} /> </Button> <Dropdown isOpen={isOpen} anchorRef={anchorRef} autoClose={false} onClose={close} originalPlacement="bottom-start" > <DropdownMenu> {quickActions.map(({ type, label }) => ( <DropdownMenuButton key={`item-type-dropdown-button-${type}`} className={itemTypeToSubThemeClassName[type]} onClick={withClose(() => onNewItem(type))} disabled={isFreePlan && type === 'creditCard'} > <DropdownMenuButtonLabel label={label} extra={ type === 'alias' && aliasLimited ? ( <span className={needsUpgrade ? 'color-danger' : 'color-weak'} >{`(${aliasTotalCount}/${aliasLimit})`}</span> ) : undefined } icon={ <span className="mr-2 w-custom h-custom rounded-lg overflow-hidden relative pass-item-icon flex-item-noshrink" style={{ '--w-custom': `2em`, '--h-custom': `2em` }} > <Icon name={itemTypeToIconName[type]} className="absolute-center" color="var(--interaction-norm)" /> </span> } /> </DropdownMenuButton> ))} <DropdownMenuButton className="ui-red" onClick={withClose(handleNewPasswordClick)}> <DropdownMenuButtonLabel label={c('Label').t`Password`} icon={ <span className="mr-2 w-custom h-custom rounded-lg overflow-hidden relative pass-item-icon flex-item-noshrink" style={{ '--w-custom': `2em`, '--h-custom': `2em` }} > <Icon name="key" className="absolute-center" color="var(--interaction-norm)" /> </span> } /> </DropdownMenuButton> </DropdownMenu> </Dropdown> </> ); };
7,651
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu/Vault/TrashItem.tsx
import { type VFC } from 'react'; import { useSelector } from 'react-redux'; import { c } from 'ttag'; import { VAULT_COLOR_MAP } from '@proton/pass/components/Vault/constants'; import { selectAllTrashedItems } from '@proton/pass/store/selectors'; import { VaultColor } from '@proton/pass/types/protobuf/vault-v1'; import clsx from '@proton/utils/clsx'; import { CountLabel } from '../../Layout/Dropdown/CountLabel'; import { DropdownMenuButton } from '../../Layout/Dropdown/DropdownMenuButton'; import { getVaultOptionInfo } from './utils'; type Props = { dense?: boolean; selected: boolean; handleTrashEmpty: () => void; handleTrashRestore: () => void; onSelect: () => void; }; export const TrashItem: VFC<Props> = ({ dense, selected, handleTrashRestore, handleTrashEmpty, onSelect }) => { const count = useSelector(selectAllTrashedItems).length; return ( <DropdownMenuButton label={<CountLabel label={getVaultOptionInfo('trash').label} count={count} />} icon="trash" onClick={onSelect} className={clsx(!dense && 'py-3')} parentClassName={clsx('pass-vault-submenu-vault-item w-full', selected && 'selected')} style={{ '--vault-icon-color': VAULT_COLOR_MAP[VaultColor.COLOR_UNSPECIFIED], }} quickActions={[ <DropdownMenuButton key="trash-restore" onClick={handleTrashRestore} label={c('Label').t`Restore all items`} icon="arrow-up-and-left" />, <DropdownMenuButton key="trash-empty" onClick={handleTrashEmpty} label={c('Label').t`Empty trash`} icon="trash-cross" danger />, ]} /> ); };
7,652
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu/Vault/VaultItem.tsx
import { type VFC } from 'react'; import { useSelector } from 'react-redux'; import { c } from 'ttag'; import { ButtonLike } from '@proton/atoms'; import { Icon } from '@proton/components'; import { useSpotlightContext } from '@proton/pass/components/Spotlight/SpotlightContext'; import { VAULT_COLOR_MAP } from '@proton/pass/components/Vault/constants'; import { isVaultMemberLimitReached, isWritableVault } from '@proton/pass/lib/vaults/vault.predicates'; import { type ShareItem } from '@proton/pass/store/reducers'; import { selectPassPlan } from '@proton/pass/store/selectors'; import type { ShareType } from '@proton/pass/types'; import { ShareRole } from '@proton/pass/types'; import { UserPassPlan } from '@proton/pass/types/api/plan'; import { VaultColor } from '@proton/pass/types/protobuf/vault-v1'; import { truthy } from '@proton/pass/utils/fp/predicates'; import clsx from '@proton/utils/clsx'; import { DropdownMenuButton } from '../../Layout/Dropdown/DropdownMenuButton'; import { VaultIcon } from '../../Vault/VaultIcon'; type Props = { count: number; dense?: boolean; label: string; selected: boolean; vault?: ShareItem<ShareType.Vault>; onDelete?: () => void; onEdit?: () => void; onInvite?: () => void; onLeave?: () => void; onManage?: () => void; onMove?: () => void; onSelect: () => void; }; const handleClickEvent = (handler?: () => void) => (evt: React.MouseEvent) => { evt.preventDefault(); evt.stopPropagation(); handler?.(); }; export const VaultItem: VFC<Props> = ({ count, dense, label, selected, vault, onDelete, onEdit, onInvite, onLeave, onManage, onMove, onSelect, }) => { const withActions = onEdit || onDelete || onInvite || onManage || onLeave; const allowSharing = vault !== undefined; const shared = vault?.shared ?? false; const notification = (vault?.newUserInvitesReady ?? 0) > 0; const spotlight = useSpotlightContext(); const plan = useSelector(selectPassPlan); return ( <DropdownMenuButton onClick={() => onSelect()} label={<span className="block text-ellipsis">{label}</span>} parentClassName={clsx( 'pass-vault-submenu-vault-item w-full', selected && 'selected', !withActions && 'pass-vault-submenu-vault-item--no-actions' )} className={clsx(!dense && 'py-3')} style={{ '--vault-icon-color': VAULT_COLOR_MAP[vault?.content.display.color ?? VaultColor.COLOR1], }} extra={ <> {shared && ( <ButtonLike as="div" icon pill size="small" color="weak" onClick={handleClickEvent(onManage)} shape="ghost" title={c('Action').t`See members`} className="relative" > {notification && ( <Icon name="exclamation-circle-filled" size={12} className="absolute top-custom right-custom" style={{ '--top-custom': '-1px', '--right-custom': '-1px', color: 'var(--signal-danger)', }} /> )} <Icon name="users" alt={c('Action').t`See members`} color="var(--text-weak)" /> </ButtonLike> )} <span className="pass-vault--count flex-item-noshrink color-weak mx-1">{count}</span> </> } icon={ <VaultIcon className="flex-item-noshrink" size={14} color={vault?.content.display.color} icon={vault?.content.display.icon} /> } quickActions={ withActions ? [ <DropdownMenuButton key="vault-edit" disabled={!onEdit} label={c('Action').t`Edit vault`} icon="pen" onClick={handleClickEvent(onEdit)} />, allowSharing && shared && ( <DropdownMenuButton key="vault-manage" className="flex flex-align-items-center py-2 px-4" icon="users" label={ vault.shareRoleId === ShareRole.ADMIN ? c('Action').t`Manage access` : c('Action').t`See members` } onClick={handleClickEvent(onManage)} /> ), allowSharing && !shared && ( <DropdownMenuButton key="vault-share" className="flex flex-align-items-center py-2 px-4" disabled={!isWritableVault(vault)} icon="user-plus" label={c('Action').t`Share`} onClick={ plan === UserPassPlan.FREE && isVaultMemberLimitReached(vault) ? () => spotlight.setUpselling('pass-plus') : handleClickEvent(onInvite) } /> ), <DropdownMenuButton key="vault-move" disabled={!onMove} onClick={handleClickEvent(onMove)} label={c('Action').t`Move all items`} icon="folder-arrow-in" />, allowSharing && shared && !vault.owner ? ( <DropdownMenuButton key="vault-leave" className="flex flex-align-items-center py-2 px-4" onClick={handleClickEvent(onLeave)} icon="cross-circle" label={c('Action').t`Leave vault`} danger /> ) : ( <DropdownMenuButton key="vault-delete" disabled={!onDelete} onClick={handleClickEvent(onDelete)} label={c('Action').t`Delete vault`} icon="trash" danger /> ), ].filter(truthy) : undefined } /> ); };
7,653
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu/Vault/VaultMenu.scss
.pass-vault-submenu-vault-item { &--no-actions > button { padding-inline-end: 0.5em !important; } > button { border-radius: var(--border-radius-md); } &.selected { > button { background-color: rgb(var(--vault-icon-color) / 1) !important; color: var(--interaction-norm-contrast); &:hover { color: var(--interaction-norm-contrast); } .pass-vault-icon { --vault-icon-color: var(--interaction-norm-contrast) !important; } } svg, .pass-vault--count { color: var(--interaction-norm-contrast) !important; } } }
7,654
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu/Vault/VaultMenu.tsx
import { type FC, type ReactElement, useMemo } from 'react'; import { useSelector } from 'react-redux'; import { TrashItem } from '@proton/pass/components/Menu/Vault/TrashItem'; import { VaultItem } from '@proton/pass/components/Menu/Vault/VaultItem'; import { useVaultActions } from '@proton/pass/components/Vault/VaultActionsProvider'; import { isShareManageable } from '@proton/pass/lib/shares/share.predicates'; import { isOwnVault } from '@proton/pass/lib/vaults/vault.predicates'; import { selectShare, selectVaultsWithItemsCount } from '@proton/pass/store/selectors'; import type { MaybeNull, ShareType } from '@proton/pass/types'; import { withTap } from '@proton/pass/utils/fp/pipe'; import noop from '@proton/utils/noop'; import { type VaultMenuOption, getVaultOptionInfo } from './utils'; import './VaultMenu.scss'; type Props = { dense?: boolean; inTrash: boolean; selectedShareId: MaybeNull<string>; onSelect: (selected: string) => void; onAction?: () => void; render?: (selectedVaultOption: VaultMenuOption, menu: ReactElement) => ReactElement; }; export const VaultMenu: FC<Props> = ({ dense = false, inTrash, selectedShareId, onSelect, render, onAction = noop, }) => { const vaults = useSelector(selectVaultsWithItemsCount); const selectedVault = useSelector(selectShare<ShareType.Vault>(selectedShareId)); const selectedVaultOption = getVaultOptionInfo(selectedVault || (inTrash ? 'trash' : 'all')); const vaultActions = useVaultActions(); const menu = useMemo(() => { const withAction = withTap(onAction); const totalItemCount = vaults.reduce<number>((subtotal, { count }) => subtotal + count, 0); const ownedVaultCount = vaults.filter(isOwnVault).length; return ( <> <VaultItem label={getVaultOptionInfo('all').label} count={totalItemCount} selected={!inTrash && !selectedShareId} onSelect={withAction(() => onSelect('all'))} dense={dense} /> {vaults.map((vault) => { const canEdit = isShareManageable(vault); const canMove = canEdit && vault.count > 0; const canDelete = vault.owner && ownedVaultCount > 1; return ( <VaultItem key={vault.shareId} vault={vault} count={vault.count} label={vault.content.name} selected={!inTrash && selectedShareId === vault.shareId} onSelect={withAction(() => onSelect(vault.shareId))} onDelete={canDelete ? withAction(() => vaultActions.delete(vault)) : undefined} onEdit={canEdit ? withAction(() => vaultActions.edit(vault)) : undefined} onInvite={withAction(() => vaultActions.invite(vault))} onManage={withAction(() => vaultActions.manage(vault))} onMove={canMove ? withAction(() => vaultActions.moveItems(vault)) : undefined} onLeave={withAction(() => vaultActions.leave(vault))} dense={dense} /> ); })} <TrashItem handleTrashRestore={withAction(vaultActions.trashRestore)} handleTrashEmpty={withAction(vaultActions.trashEmpty)} onSelect={withAction(() => onSelect('trash'))} selected={inTrash} dense={dense} /> </> ); }, [vaults, vaultActions, selectedShareId, inTrash, onSelect]); return render?.(selectedVaultOption, menu) ?? menu; };
7,655
0
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu
petrpan-code/ProtonMail/WebClients/packages/pass/components/Menu/Vault/utils.tsx
import { c } from 'ttag'; import type { VaultShareItem } from '@proton/pass/store/reducers'; import type { MaybeNull } from '@proton/pass/types'; import { VaultColor as VaultColorEnum } from '@proton/pass/types/protobuf/vault-v1'; import { type VaultIconName } from '../../Vault/VaultIcon'; export type VaultMenuOption = { id: MaybeNull<string>; label: string; color?: VaultColorEnum; icon?: VaultIconName; }; export const getVaultOptionInfo = (vault: 'all' | 'trash' | VaultShareItem): VaultMenuOption => { switch (vault) { case 'all': return { id: null, label: c('Label').t`All vaults`, color: VaultColorEnum.COLOR_CUSTOM, }; case 'trash': return { id: null, label: c('Label').t`Trash`, icon: 'pass-trash', color: VaultColorEnum.COLOR_UNSPECIFIED, }; default: return { id: vault.shareId, label: vault.content.name, color: vault.content.display.color, icon: vault.content.display.icon, }; } };
7,656
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Navigation/authenticated-path.spec.ts
import { authenticatedPath } from './authenticated-path'; describe('Should append application localID', () => { test('should add perfix /u/*/ if we send string', () => { expect(authenticatedPath('test-path')).toEqual('/u/*/test-path'); }); test('should add perfix /u/*/ if we send string with leading slash', () => { expect(authenticatedPath('/test-path')).toEqual('/u/*/test-path'); }); test('should add perfix /u/*/ if we send string with leading and tailing slash', () => { expect(authenticatedPath('/test-path/')).toEqual('/u/*/test-path'); }); test('should add perfix /u/* if we send empty string', () => { expect(authenticatedPath('')).toEqual('/u/*'); }); test('should add perfix /u/* if we send rooth path', () => { expect(authenticatedPath('/')).toEqual('/u/*'); }); test('should add perfix /u/* and support variables in the path', () => { expect(authenticatedPath('/user/:userId')).toEqual('/u/*/user/:userId'); }); test('should add perfix /u/* and support multiple variables in the path', () => { expect(authenticatedPath('/user/:userId/next/:nextId')).toEqual('/u/*/user/:userId/next/:nextId'); }); });
7,657
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Navigation/authenticated-path.ts
import { stripLeadingAndTrailingSlash, stripTrailingSlash } from '@proton/shared/lib/helpers/string'; export const authenticatedPath = (path: string) => stripTrailingSlash(`/u/*/${stripLeadingAndTrailingSlash(path)}`);
7,658
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Otp/OTPDonut.scss
@import '~@proton/styles/scss/lib'; // FIXME: this is hacking around the // donut component to achieve our OTP // countdown effect .pass-otp--donut { display: block; inline-size: rem(36); block-size: rem(36); position: relative; &::before { content: var(--countdown-value); inset-block: 0; margin: auto; inline-size: 100%; block-size: rem(12); line-height: rem(12); font-size: rem(12); position: absolute; text-align: center; color: var(--text-weak); } svg { transform: scaleX(-1); mask { rect:last-of-type { fill: transparent; } } circle { stroke-width: rem(15); } } }
7,659
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Otp/OTPDonut.tsx
import type { VFC } from 'react'; import { Donut } from '@proton/atoms/Donut'; import { ThemeColor } from '@proton/colors/types'; import clsx from '@proton/utils/clsx'; import './OTPDonut.scss'; type Props = { enabled: boolean; percent: number; period?: number }; export const OTPDonut: VFC<Props> = ({ enabled, percent, period = 0 }) => ( <div className={clsx('pass-otp--donut no-pointer-events')} style={{ '--countdown-value': `"${Math.round(percent * period)}"` }} > {enabled && ( <Donut segments={[[percent * 100, ThemeColor.Success]]} backgroundSegmentColor="var(--text-hint)" /> )} </div> );
7,660
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Otp/OTPValue.tsx
import { type VFC, useMemo } from 'react'; import chunk from '@proton/utils/chunk'; export const OTPValue: VFC<{ code?: string }> = ({ code }) => { const formatted = useMemo(() => { if (!code || code.length % 3) return code; return chunk(Array.from(code), 3) .map((part) => part.join('')) .join('β€’'); }, [code]); return <>{formatted}</>; };
7,661
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/PasswordGenerator/PasswordContext.tsx
import { type FC, createContext, useContext, useMemo, useState } from 'react'; import type { UseAsyncModalHandle } from '@proton/pass/hooks/useAsyncModalHandles'; import { useAsyncModalHandles } from '@proton/pass/hooks/useAsyncModalHandles'; import type { GeneratePasswordOptions } from '@proton/pass/lib/password/generator'; import type { MaybeNull } from '@proton/pass/types'; import noop from '@proton/utils/noop'; import { PasswordGeneratorModal, type BaseProps as PasswordGeneratorModalProps } from './PasswordGeneratorModal'; import { PasswordHistoryModal } from './PasswordHistoryModal'; type ModalState = Omit<PasswordGeneratorModalProps, 'onSubmit'>; type PasswordContextValue = { options: MaybeNull<GeneratePasswordOptions>; generatePassword: UseAsyncModalHandle<string, ModalState>; openPasswordHistory: () => void; }; const PasswordContext = createContext<PasswordContextValue>({ options: null, generatePassword: async () => {}, openPasswordHistory: noop, }); const getInitialModalState = (): ModalState => ({ actionLabel: '' }); export const PasswordContextProvider: FC<{ initial: MaybeNull<GeneratePasswordOptions> }> = ({ children, initial }) => { const { resolver, state, handler, abort } = useAsyncModalHandles<string, ModalState>({ getInitialModalState }); const [showHistory, setShowHistory] = useState(false); const contextValue = useMemo<PasswordContextValue>( () => ({ options: initial, generatePassword: handler, openPasswordHistory: () => setShowHistory(true) }), [handler, initial] ); return ( <PasswordContext.Provider value={contextValue}> {children} <PasswordGeneratorModal onClose={abort} onSubmit={resolver} {...state} /> <PasswordHistoryModal open={showHistory} onClose={() => setShowHistory(false)} className="ui-red" /> </PasswordContext.Provider> ); }; export const usePasswordContext = () => useContext(PasswordContext);
7,662
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/PasswordGenerator/PasswordGenerator.scss
@import '~@proton/styles/scss/lib'; .pass-password-generator--char-alphabetic { color: var(--text-norm); } .pass-password-generator--char-digit { color: var(--interaction-norm-major-1); } .pass-password-generator--char-special { color: var(--interaction-norm-major-1); } button.field.pass-password-generator--select { box-shadow: none !important; block-size: rem(24); padding-inline-end: 0; > span { text-align: end; } }
7,663
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/PasswordGenerator/PasswordGenerator.tsx
import type { VFC } from 'react'; import { useState } from 'react'; import { c, msgid } from 'ttag'; import { Button } from '@proton/atoms/Button'; import { Slider } from '@proton/atoms/Slider'; import { Icon, Option, SelectTwo, Toggle } from '@proton/components/components'; import type { UsePasswordGeneratorResult } from '@proton/pass/hooks/usePasswordGenerator'; import { getCharsGroupedByColor } from '@proton/pass/hooks/usePasswordGenerator'; import type { GeneratePasswordOptions } from '@proton/pass/lib/password/generator'; import type { MemorablePasswordOptions } from '@proton/pass/lib/password/memorable'; import { SeperatorOptions, getSeperatorTranslation } from '@proton/pass/lib/password/memorable'; import './PasswordGenerator.scss'; export const PasswordGenerator: VFC<UsePasswordGeneratorResult> = ({ password, passwordOptions, setPasswordOptions, }) => { const [showAdvanced, setShowAdvanced] = useState(false); return ( <div className="flex-column flex gap-y-2"> <div className="my-4 px-4 py-2 flex flex-align-items-center"> <span className="text-2xl text-center text-break-all text-monospace m-auto min-h-custom" style={{ '--min-h-custom': '4.5rem' }} > {getCharsGroupedByColor(password)} </span> </div> <div className="flex flex-align-items-center gap-x-2"> <label htmlFor="password-type" className="w-custom" style={{ '--w-custom': '5.625rem' }}> {c('Label').t`Type`} </label> <SelectTwo<GeneratePasswordOptions['type']> id="password-type" value={passwordOptions.type} className="pass-password-generator--select border-none flex flex-item-fluid" onValue={(type) => setPasswordOptions(type)} > <Option title={c('Option').t`Memorizable Password`} value="memorable" /> <Option title={c('Option').t`Random Password`} value="random" /> </SelectTwo> </div> <hr className="m-0" /> {passwordOptions.type === 'random' && ( <> <div className="flex flex-align-items-center flex-justify-space-between"> <label htmlFor="password-length" className="w-custom" style={{ '--w-custom': '6.875rem' }}> {c('Label').ngettext( msgid`${passwordOptions.options.length} character`, `${passwordOptions.options.length} characters`, passwordOptions.options.length )} </label> <div className="flex flex-item-fluid"> <Slider id="password-length" min={4} max={64} step={1} size="small" color="norm" value={passwordOptions.options.length} onInput={(length) => setPasswordOptions('random', { length })} /> </div> </div> <hr className="m-0" /> <div className="flex flex-align-items-center flex-justify-space-between"> <label htmlFor="password-special-chars" className="w-custom" style={{ '--w-custom': '10rem' }}> {c('Label').t`Special characters (!&*)`} </label> <Toggle id="password-special-chars" checked={passwordOptions.options.useSpecialChars} onChange={(e) => setPasswordOptions('random', { useSpecialChars: e.target.checked })} /> </div> {showAdvanced && ( <> <hr className="m-0" /> <div className="flex flex-align-items-center flex-justify-space-between"> <label htmlFor="password-capitalise" className="w-custom" style={{ '--w-custom': '10rem' }} > {c('Label').t`Capital letters (A-Z)`} </label> <Toggle id="password-capitalise" checked={passwordOptions.options.useUppercase} onChange={(e) => setPasswordOptions('random', { useUppercase: e.target.checked })} /> </div> <hr className="m-0" /> <div className="flex flex-align-items-center flex-justify-space-between"> <label htmlFor="password-digits" className="w-custom" style={{ '--w-custom': '10rem' }}> {c('Label').t`Include numbers (0-9)`} </label> <Toggle id="password-digits" checked={passwordOptions.options.useDigits} onChange={(e) => setPasswordOptions('random', { useDigits: e.target.checked })} /> </div> </> )} </> )} {passwordOptions.type === 'memorable' && ( <> <div className="flex flex-align-items-center flex-justify-space-between"> <label htmlFor="password-word-count" className="w-custom" style={{ '--w-custom': '6.875rem' }}> {c('Label').ngettext( msgid`${passwordOptions.options.wordCount} word`, `${passwordOptions.options.wordCount} words`, passwordOptions.options.wordCount )} </label> <div className="flex flex-item-fluid"> <Slider id="password-word-count" min={1} max={10} step={1} size="small" color="norm" value={passwordOptions.options.wordCount} onInput={(wordCount) => setPasswordOptions('memorable', { wordCount })} /> </div> </div> <hr className="m-0" /> <div className="flex flex-align-items-center flex-justify-space-between"> <label htmlFor="password-capitalise" className="w-custom" style={{ '--w-custom': '10rem' }}> {c('Label').t`Capitalise`} </label> <Toggle id="password-capitalise" checked={passwordOptions.options.capitalize} onChange={(e) => setPasswordOptions('memorable', { capitalize: e.target.checked })} /> </div> {showAdvanced && ( <> <hr className="m-0" /> <div className="flex flex-align-items-center gap-x-2"> <label htmlFor="password-seperator" className="w-custom" style={{ '--w-custom': '5.625rem' }} > {c('Label').t`Type`} </label> <SelectTwo<MemorablePasswordOptions['seperator']> id="password-seperator" value={passwordOptions.options.seperator} className="pass-password-generator--select border-none flex flex-item-fluid" onValue={(seperator) => setPasswordOptions('memorable', { seperator })} > {Object.values(SeperatorOptions).map((seperator) => ( <Option<MemorablePasswordOptions['seperator']> key={seperator} title={getSeperatorTranslation(seperator)} value={seperator} /> ))} </SelectTwo> </div> <hr className="m-0" /> <div className="flex flex-align-items-center flex-justify-space-between"> <label htmlFor="password-extra-numbers" className="w-custom" style={{ '--w-custom': '10rem' }} > {c('Label').t`Include numbers`} </label> <Toggle id="password-extra-numbers" checked={passwordOptions.options.extraNumbers} onChange={(e) => setPasswordOptions('memorable', { extraNumbers: e.target.checked }) } /> </div> </> )} </> )} <hr className="m-0" /> <div className="flex flex-justify-end"> <Button shape="ghost" onClick={() => setShowAdvanced((advanced) => !advanced)}> <span className="flex flex-align-items-center color-weak text-sm"> <Icon name={showAdvanced ? 'cross' : 'cog-wheel'} className="mr-1" /> {showAdvanced ? c('Action').t`Close advanced options` : c('Action').t`Advanced options`} </span> </Button> </div> </div> ); };
7,664
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/PasswordGenerator/PasswordGeneratorButton.tsx
import { type VFC, memo } from 'react'; import { c } from 'ttag'; import { Button, type ButtonProps } from '@proton/atoms'; import { Icon } from '@proton/components/components'; import { SubTheme } from '@proton/pass/components/Layout/Theme/types'; import { usePasswordContext } from './PasswordContext'; type Props = Omit<ButtonProps, 'onSubmit'> & { onSubmit: (password: string) => void }; const PasswordGeneratorButtonRaw: VFC<Props> = ({ onSubmit, type, ...rest }) => { const { generatePassword } = usePasswordContext(); const handleOnClick = () => generatePassword({ onSubmit, actionLabel: c('Action').t`Fill password`, className: SubTheme.VIOLET /* no-need for a type prop yet: only used for Login items */, }); return ( <Button icon pill color="weak" shape="solid" size="medium" className="pass-item-icon" title={c('Action').t`Generate password`} onClick={handleOnClick} {...rest} > <Icon name="arrows-rotate" size={20} /> </Button> ); }; export const PasswordGeneratorButton = memo(PasswordGeneratorButtonRaw);
7,665
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/PasswordGenerator/PasswordGeneratorModal.tsx
import { type VFC, useCallback, useEffect } from 'react'; import { c } from 'ttag'; import { Button } from '@proton/atoms'; import { Icon } from '@proton/components'; import type { ModalProps } from '@proton/components/components/modalTwo/Modal'; import { SidebarModal } from '@proton/pass/components/Layout/Modal/SidebarModal'; import { Panel } from '@proton/pass/components/Layout/Panel/Panel'; import { PanelHeader } from '@proton/pass/components/Layout/Panel/PanelHeader'; import { usePasswordGenerator } from '@proton/pass/hooks/usePasswordGenerator'; import { usePasswordContext } from './PasswordContext'; import { PasswordGenerator } from './PasswordGenerator'; export type BaseProps = { actionLabel?: string; className?: string; onSubmit?: (password: string) => void }; export type Props = Omit<ModalProps, 'onSubmit'> & BaseProps; export const PasswordGeneratorModal: VFC<Props> = ({ onSubmit, actionLabel, ...props }) => { const { openPasswordHistory, options } = usePasswordContext(); const passwordGenerator = usePasswordGenerator(options); const handleActionClick = useCallback(() => onSubmit?.(passwordGenerator.password), [passwordGenerator, onSubmit]); useEffect(() => { /* regenerate on each modal opening */ if (props.open) passwordGenerator.regeneratePassword(); }, [props.open]); return ( <SidebarModal {...props}> <Panel header={ <PanelHeader actions={[ <Button key="close-modal-button" className="flex-item-noshrink" icon pill shape="solid" onClick={props.onClose} > <Icon className="modal-close-icon" name="cross" alt={c('Action').t`Close`} /> </Button>, <div className="flex gap-1" key="modal-actions-group"> {actionLabel && ( <Button onClick={handleActionClick} color="norm" pill className="text-sm"> {actionLabel} </Button> )} <Button icon pill shape="solid" className="flex-item-noshrink" onClick={passwordGenerator.regeneratePassword} > <Icon name="arrows-rotate" alt={c('Action').t`Regenerate`} /> </Button> </div>, ]} /> } > <PasswordGenerator {...passwordGenerator} /> <hr className="my-2" /> <button className="w-full flex flex-align-items-center flex-justify-space-between" onClick={openPasswordHistory} > <span>{c('Label').t`Password history`}</span> <Icon name="chevron-right" /> </button> </Panel> </SidebarModal> ); };
7,666
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/PasswordGenerator/PasswordHistoryItem.tsx
import type { VFC } from 'react'; import { useDispatch } from 'react-redux'; import { c } from 'ttag'; import { Button } from '@proton/atoms/Button'; import { Icon } from '@proton/components/components'; import { ValueControl } from '@proton/pass/components/Form/Field/Control/ValueControl'; import { FieldsetCluster } from '@proton/pass/components/Form/Field/Layout/FieldsetCluster'; import { getCharsGroupedByColor } from '@proton/pass/hooks/usePasswordGenerator'; import { passwordDelete } from '@proton/pass/store/actions/creators/pw-history'; import type { PasswordHistoryEntry } from '@proton/pass/store/reducers'; import { getFormattedDateFromTimestamp } from '@proton/pass/utils/time/format'; export const PasswordHistoryItem: VFC<PasswordHistoryEntry> = ({ value, origin, id, createTime }) => { const dispatch = useDispatch(); return ( <FieldsetCluster mode="read" as="div"> <ValueControl label={origin ?? c('Placeholder').t`Unknown origin`} actionsContainerClassName="flex gap-2" clickToCopy hidden value={value} actions={[ <Button key="pw-delete-button" className="flex-item-noshrink" icon pill shape="solid" onClick={() => dispatch(passwordDelete({ id }))} > <Icon name="cross" alt={c('Action').t`Delete password`} /> </Button>, ]} extra={<small className="color-weak">{getFormattedDateFromTimestamp(createTime)}</small>} > {getCharsGroupedByColor(value)} </ValueControl> </FieldsetCluster> ); };
7,667
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/PasswordGenerator/PasswordHistoryModal.tsx
import type { VFC } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { c } from 'ttag'; import { Button } from '@proton/atoms/Button'; import type { ModalProps } from '@proton/components/components'; import { Icon } from '@proton/components/components'; import { SidebarModal } from '@proton/pass/components/Layout/Modal/SidebarModal'; import { Panel } from '@proton/pass/components/Layout/Panel/Panel'; import { PanelHeader } from '@proton/pass/components/Layout/Panel/PanelHeader'; import { passwordHistoryClear } from '@proton/pass/store/actions/creators/pw-history'; import { selectPasswordHistory } from '@proton/pass/store/selectors'; import clsx from '@proton/utils/clsx'; import { PasswordHistoryItem } from './PasswordHistoryItem'; export const PasswordHistoryModal: VFC<ModalProps> = (props) => { const dispatch = useDispatch(); const pwHistory = useSelector(selectPasswordHistory); const empty = pwHistory.length === 0; return ( <SidebarModal {...props}> <Panel header={ <PanelHeader actions={[ <Button key="close-modal-button" className="flex-item-noshrink" icon pill shape="solid" onClick={props.onClose} > <Icon className="modal-close-icon" name="chevron-left" alt={c('Action').t`Back`} /> </Button>, <Button key="clear-modal-button" pill color="norm" className="text-sm flex-item-noshrink" onClick={() => dispatch(passwordHistoryClear())} > {c('Action').t`Clear`} </Button>, ]} /> } > <div className={'flex flex-nowrap flex-column gap-1'}> {pwHistory.map((entry) => ( <PasswordHistoryItem key={entry.id} {...entry} /> ))} <div className={clsx('color-weak text-center px-8', empty ? 'mt-10' : 'mt-1 mb-2')}> {empty && <h6 className="text-rg text-semibold mb-1">{c('Label').t`No history`}</h6>} <div className="text-sm"> {empty ? c('Info').t`Generated passwords will be stored for a period of one day.` : c('Info').t`Passwords older than 1 day are automatically deleted from history.`} </div> </div> </div> </Panel> </SidebarModal> ); };
7,668
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Share/ShareMember.tsx
import type { VFC } from 'react'; import { useMemo } from 'react'; import { c } from 'ttag'; import Info from '@proton/components/components/link/Info'; import { ConfirmationModal } from '@proton/pass/components/Confirmation/ConfirmationModal'; import { DropdownMenuButton } from '@proton/pass/components/Layout/Dropdown/DropdownMenuButton'; import { QuickActionsDropdown } from '@proton/pass/components/Layout/Dropdown/QuickActionsDropdown'; import { useActionRequest } from '@proton/pass/hooks/useActionRequest'; import { useConfirm } from '@proton/pass/hooks/useConfirm'; import { shareEditMemberAccessIntent, shareRemoveMemberAccessIntent, vaultTransferOwnerIntent, } from '@proton/pass/store/actions'; import { ShareRole } from '@proton/pass/types'; import { ShareMemberAvatar } from './ShareMemberAvatar'; import { getShareRoleDefinition } from './ShareRoleOptions'; export type ShareMemberProps = { canManage: boolean; canTransfer: boolean; email: string; me: boolean; owner: boolean; role: ShareRole; shareId: string; userShareId: string; }; export const ShareMember: VFC<ShareMemberProps> = ({ canManage, canTransfer, email, me, owner, role, shareId, userShareId, }: ShareMemberProps) => { const initials = email.toUpperCase().slice(0, 2) ?? ''; const { title, description } = useMemo(() => { if (owner) { return { title: c('Info').t`Owner`, description: c('Info').t`Can grant and revoke access to this vault, and delete it.`, }; } return getShareRoleDefinition()[role]; }, [owner, role]); const removeAccess = useActionRequest({ action: shareRemoveMemberAccessIntent }); const editAccess = useActionRequest({ action: shareEditMemberAccessIntent }); const transferOwnership = useActionRequest({ action: vaultTransferOwnerIntent }); const handleRemoveAccess = () => removeAccess.dispatch({ shareId, userShareId }); const handleEditRole = (shareRoleId: ShareRole) => editAccess.dispatch({ shareId, userShareId, shareRoleId }); const handleTransferOwnership = useConfirm(transferOwnership.dispatch); const loading = transferOwnership.loading || removeAccess.loading || editAccess.loading; return ( <div className="flex flex-nowrap flex-align-items-center border rounded-xl px-4 py-3 w-full"> <ShareMemberAvatar value={initials} loading={loading} /> <div className="flex-item-fluid"> <div className="flex flex-nowrap flex-item-fluid flex-align-items-center gap-2"> <div className="text-ellipsis">{email}</div> {me && <span className="color-primary text-sm">({c('Info').t`me`})</span>} </div> <div className="flex flex-align-items-center gap-1"> <span className="color-weak">{title}</span> <Info title={description} className="color-weak" questionMark /> </div> </div> {!me && canManage && !owner && ( <QuickActionsDropdown color="weak" shape="ghost"> <DropdownMenuButton label={c('Action').t`Make viewer`} icon={role === ShareRole.READ ? 'checkmark' : undefined} onClick={() => handleEditRole(ShareRole.READ)} disabled={editAccess.loading} className={role !== ShareRole.READ ? 'pl-10' : ''} /> <DropdownMenuButton label={c('Action').t`Make editor`} icon={role === ShareRole.WRITE ? 'checkmark' : undefined} onClick={() => handleEditRole(ShareRole.WRITE)} disabled={editAccess.loading} className={role !== ShareRole.WRITE ? 'pl-10' : ''} /> <DropdownMenuButton label={c('Action').t`Make admin`} icon={role === ShareRole.ADMIN ? 'checkmark' : undefined} onClick={() => handleEditRole(ShareRole.ADMIN)} disabled={editAccess.loading} className={role !== ShareRole.ADMIN ? 'pl-10' : ''} /> {canTransfer && role === ShareRole.ADMIN && ( <DropdownMenuButton label={c('Action').t`Transfer ownership`} icon="shield-half-filled" onClick={() => handleTransferOwnership.prompt({ shareId, userShareId })} /> )} <DropdownMenuButton label={c('Action').t`Remove access`} icon="circle-slash" danger onClick={handleRemoveAccess} /> </QuickActionsDropdown> )} <ConfirmationModal title={c('Title').t`Transfer ownership`} open={handleTransferOwnership.pending} onClose={handleTransferOwnership.cancel} onSubmit={handleTransferOwnership.confirm} submitText={c('Action').t`Confirm`} alertText={c('Warning').t`Transfer ownership of this vault to ${email}?`} /> </div> ); };
7,669
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Share/ShareMemberAvatar.scss
.pass-member--avatar { background-color: var(--interaction-weak) !important; color: var(--interaction-norm-major-1) !important; }
7,670
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Share/ShareMemberAvatar.tsx
import type { VFC } from 'react'; import { Avatar } from '@proton/atoms/Avatar'; import { CircleLoader } from '@proton/atoms/CircleLoader'; import clsx from '@proton/utils/clsx'; import './ShareMemberAvatar.scss'; type Props = { value: string; loading?: boolean }; export const ShareMemberAvatar: VFC<Props> = ({ value, loading }) => ( <div className="mr-4 relative"> <Avatar className={clsx('rounded-lg pass-member--avatar', loading && 'opacity-30')}>{value}</Avatar> {loading && <CircleLoader size="small" className="upper-layer color-primary absolute-center opacity-60" />} </div> );
7,671
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Share/SharePendingMember.tsx
import type { ReactNode, VFC } from 'react'; import { c } from 'ttag'; import { Button } from '@proton/atoms/Button'; import { Info } from '@proton/components/components'; import { DropdownMenuButton } from '@proton/pass/components/Layout/Dropdown/DropdownMenuButton'; import { QuickActionsDropdown } from '@proton/pass/components/Layout/Dropdown/QuickActionsDropdown'; import { useActionRequest } from '@proton/pass/hooks/useActionRequest'; import { inviteRemoveIntent, inviteResendIntent, newUserInvitePromoteIntent, newUserInviteRemoveIntent, } from '@proton/pass/store/actions'; import { NewUserInviteState } from '@proton/pass/types'; import { ShareMemberAvatar } from './ShareMemberAvatar'; type PendingMemberBase = { canManage: boolean; email: string; shareId: string }; type PendingExistingMemberProps = PendingMemberBase & { inviteId: string }; type PendingNewMemberProps = PendingMemberBase & { newUserInviteId: string; state: NewUserInviteState }; type SharePendingMemberProps = { actions?: ReactNode[]; email: string; extra?: ReactNode; loading: boolean }; export const SharePendingMember: VFC<SharePendingMemberProps> = ({ actions, email, extra, loading }) => ( <div className="border rounded-xl px-4 py-3 max-w-full"> <div className="flex flex-nowrap flex-align-items-center w-full"> <ShareMemberAvatar value={email.toUpperCase().slice(0, 2) ?? ''} loading={loading} /> <div className="flex-item-fluid"> <div className="text-ellipsis">{email}</div> <div className="flex flex-align-items-center gap-1"> <span className="color-weak">{c('Info').t`Invitation sent`}</span> <Info title={c('Info').t`The user did not accept the invitation yet.`} className="color-weak" questionMark /> </div> </div> {actions && ( <QuickActionsDropdown color="weak" shape="ghost"> {actions} </QuickActionsDropdown> )} </div> {extra} </div> ); export const PendingExistingMember: VFC<PendingExistingMemberProps> = ({ canManage, email, inviteId, shareId }) => { const resendInvite = useActionRequest({ action: inviteResendIntent }); const removeInvite = useActionRequest({ action: inviteRemoveIntent }); const handleResendInvite = () => resendInvite.dispatch({ shareId, inviteId }); const handleRemoveInvite = () => removeInvite.dispatch({ shareId, inviteId }); const loading = resendInvite.loading || removeInvite.loading; return ( <SharePendingMember email={email} loading={loading} actions={ canManage ? [ <DropdownMenuButton key="resend" label={c('Action').t`Resend invitation`} icon={'paper-plane'} onClick={handleResendInvite} disabled={loading} />, <DropdownMenuButton key="remove" label={c('Action').t`Remove access`} icon="circle-slash" danger onClick={handleRemoveInvite} disabled={loading} />, ] : undefined } /> ); }; export const PendingNewMember: VFC<PendingNewMemberProps> = ({ canManage, email, shareId, state, newUserInviteId }) => { const promoteInvite = useActionRequest({ action: newUserInvitePromoteIntent }); const removeInvite = useActionRequest({ action: newUserInviteRemoveIntent }); const handlePromoteInvite = () => promoteInvite.dispatch({ shareId, newUserInviteId }); const handleRemoveInvite = () => removeInvite.dispatch({ shareId, newUserInviteId }); const loading = promoteInvite.loading || removeInvite.loading; return ( <SharePendingMember email={email} loading={loading} actions={ canManage ? [ <DropdownMenuButton key="remove" label={c('Action').t`Remove access`} icon="circle-slash" danger onClick={handleRemoveInvite} disabled={loading} />, ] : undefined } extra={ canManage && state === NewUserInviteState.READY ? ( <Button pill shape="solid" color="weak" size="small" className="w-full text-sm mt-2" disabled={loading} loading={promoteInvite.loading} onClick={handlePromoteInvite} > {c('Action').t`Confirm access`} </Button> ) : undefined } /> ); };
7,672
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Share/ShareRoleOptions.tsx
import { c } from 'ttag'; import { ShareRole } from '@proton/pass/types'; export const getShareRoleDefinition = (): Record<ShareRole, { title: string; description: string }> => ({ [ShareRole.READ]: { title: c('Info').t`Viewer`, description: c('Info').t`Can view items in this vault.`, }, [ShareRole.WRITE]: { title: c('Info').t`Editor`, description: c('Info').t`Can create, edit, delete, and export items in this vault.`, }, [ShareRole.ADMIN]: { title: c('Info').t`Admin`, description: c('Info').t`Can grant and revoke access to this vault.`, }, }); export const shareRoleOptions = () => Object.entries(getShareRoleDefinition()) .reverse() .map(([value, { title, description }]) => ({ value: value as ShareRole, label: ( <div> <div>{title}</div> <div className="color-weak">{description}</div> </div> ), }));
7,673
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Spotlight/PendingShareAccessModal.tsx
import { type VFC } from 'react'; import { c } from 'ttag'; import { Button } from '@proton/atoms'; import { Icon } from '@proton/components'; import type { ModalProps } from '@proton/components/components/modalTwo/Modal'; import accountImg from '@proton/pass/assets/protonpass-account.svg'; import { SidebarModal } from '@proton/pass/components/Layout/Modal/SidebarModal'; import { Panel } from '@proton/pass/components/Layout/Panel/Panel'; import { PanelHeader } from '@proton/pass/components/Layout/Panel/PanelHeader'; export type Props = Omit<ModalProps, 'onSubmit'>; export const PendingShareAccessModal: VFC<Props> = ({ ...props }) => { return ( <SidebarModal {...props}> <Panel className="text-center" header={ <PanelHeader actions={[ <Button key="close-modal-button" className="flex-item-noshrink" icon pill shape="solid" onClick={props.onClose} > <Icon className="modal-close-icon" name="cross" alt={c('Action').t`Close`} /> </Button>, ]} /> } > <div className="flex flex-columns flex-justify-center flex-align-items-center gap-4"> <img src={accountImg} className="mt-4 w-1/3" alt="pending share access graphic" /> <h3 className="text-bold w-3/4">{c('Title').t`Pending access to the shared data`}</h3> <div className="text-sm w-3/4"> {c('Info').t`For security reasons, your access needs to be confirmed`} </div> </div> </Panel> </SidebarModal> ); };
7,674
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Spotlight/Spotlight.scss
@import '~@proton/styles/scss/lib'; .pass-spotlight-panel { transition: max-block-size 0.25s ease-in-out; max-block-size: rem(180); min-block-size: 0; overflow: hidden; &--hidden { max-block-size: 0; } }
7,675
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Spotlight/SpotlightContent.scss
@import '~@proton/styles/scss/lib'; .pass-spotlight-content { &.weak { background: var(--interaction-norm-minor-1); } background: var(--interaction-norm); }
7,676
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Spotlight/SpotlightContent.tsx
import type { ElementType } from 'react'; import { type MouseEvent, type VFC, useMemo } from 'react'; import { Button } from '@proton/atoms/Button'; import { Icon } from '@proton/components/components'; import clsx from '@proton/utils/clsx'; import './SpotlightContent.scss'; export type SpotlightMessageDefinition = { action?: { label: string; onClick: (e: MouseEvent<HTMLElement>) => void; type: 'link' | 'button' }; className?: string; dense?: boolean; icon?: ElementType; id: string; message: string; title: string; weak?: boolean; onClose?: () => void; }; type Props = SpotlightMessageDefinition; export const SpotlightContent: VFC<Props> = ({ action, className, dense = true, icon, message, title, weak, onClose, }) => { const actionNode = useMemo(() => { switch (action?.type) { case 'link': return ( <button onClick={action.onClick} className="unstyled text-sm color-invert"> <span className="text-underline">{action.label}</span> </button> ); case 'button': return ( <Button pill shape="solid" color="norm" size="small" className="text-sm px-3" onClick={action.onClick} style={{ backgroundColor: 'var(--interaction-norm-major-3)' }} > {action.label} </Button> ); } }, [action]); const CustomIcon = icon; return ( <div className={clsx( `pass-spotlight-content flex flex-align-items-center gap-4 p-4 pr-6 rounded relative mt-2`, className, weak && 'weak' )} > {onClose && ( <Button icon shape="ghost" color="weak" size="small" className="absolute top right" onClick={onClose}> <Icon name="cross" color="var(--interaction-norm-contrast)" /> </Button> )} <div className="flex-item-fluid"> <strong className={clsx('block', !weak && 'color-invert')}>{title}</strong> <span className={clsx('block text-sm', !weak && 'color-invert')}>{message}</span> {!dense && <div className="mt-2">{actionNode}</div>} </div> {CustomIcon && ( <div {...(dense ? { style: { order: -1 } } : { className: 'mr-2' })}> <CustomIcon /> </div> )} {dense && actionNode} </div> ); };
7,677
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Spotlight/SpotlightContext.tsx
import type { FC } from 'react'; import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react'; import { PendingShareAccessModal } from '@proton/pass/components/Spotlight/PendingShareAccessModal'; import { type MaybeNull } from '@proton/pass/types'; import noop from '@proton/utils/noop'; import type { SpotlightMessageDefinition } from './SpotlightContent'; import type { UpsellingModalType } from './UpsellingModal'; import { UpsellingModal } from './UpsellingModal'; import './Spotlight.scss'; type SpotlightState = { open: boolean; upselling: MaybeNull<UpsellingModalType>; pendingShareAccess: boolean; message: MaybeNull<SpotlightMessageDefinition>; }; export type SpotlightContextValue = { setPendingShareAccess: (value: boolean) => void; setUpselling: (value: MaybeNull<UpsellingModalType>) => void; setMessage: (message: MaybeNull<SpotlightMessageDefinition>) => void; state: SpotlightState; }; const INITIAL_STATE: SpotlightState = { open: false, message: null, upselling: null, pendingShareAccess: false }; export const SpotlightContext = createContext<SpotlightContextValue>({ setUpselling: noop, setPendingShareAccess: noop, setMessage: noop, state: INITIAL_STATE, }); export const SpotlightContextProvider: FC = ({ children }) => { const timer = useRef<NodeJS.Timeout>(); const [state, setState] = useState<SpotlightState>(INITIAL_STATE); const ctx = useMemo<SpotlightContextValue>( () => ({ setPendingShareAccess: (pendingShareAccess) => setState((prev) => ({ ...prev, pendingShareAccess })), setUpselling: (upselling) => setState((prev) => ({ ...prev, upselling })), setMessage: (next) => { const prev = state.message; if (prev?.id !== next?.id) { setState((curr) => ({ ...curr, open: false })); timer.current = setTimeout( () => setState((prev) => ({ ...prev, message: next, open: next !== null, })), 500 ); } }, state, }), [state] ); useEffect(() => () => clearTimeout(timer.current), []); return ( <SpotlightContext.Provider value={ctx}> {children} <UpsellingModal open={state.upselling !== null} type={state.upselling ?? 'free-trial'} onClose={() => { state.message?.onClose?.(); setState((prev) => ({ ...prev, upselling: null })); }} /> <PendingShareAccessModal open={state.pendingShareAccess} onClose={() => { state.message?.onClose?.(); setState((prev) => ({ ...prev, pendingShareAccess: false })); }} /> </SpotlightContext.Provider> ); }; export const useSpotlightContext = () => useContext(SpotlightContext);
7,678
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Spotlight/SpotlightIcon.scss
.ui-teal { .pass-spotlight--icon { --onboarding-icon-fill: #0ee48c; --onboarding-icon-contrast: white; } } .ui-violet { .pass-spotlight--icon { --onboarding-icon-fill: #6742f5; --onboarding-icon-contrast: white; } }
7,679
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Spotlight/SpotlightIcon.tsx
import type { VFC } from 'react'; import './SpotlightIcon.scss'; export const ShieldIcon: VFC = () => ( <svg width="36" height="40" viewBox="0 0 36 40" fill="none" className="pass-spotlight--icon"> <path d="M34.5086 4.96515L19.8316 0.293841C18.596 -0.0979469 17.2699 -0.0979469 16.0343 0.293841L1.35731 4.96515C0.603869 5.20625 0.0613915 5.89942 0.031254 6.71313C-0.179708 12.3488 0.18194 34.1985 17.6316 39.9548C17.8425 40.0151 18.0535 40.0151 18.2343 39.9548C35.6839 34.1985 36.0456 12.3488 35.8346 6.71313C35.8045 5.89942 35.262 5.20625 34.5086 4.96515Z" fill="var(--onboarding-icon-fill)" /> <path d="M17.9326 27.2061C22.5931 27.2061 26.3711 23.4281 26.3711 18.7676C26.3711 14.1071 22.5931 10.3291 17.9326 10.3291C13.2722 10.3291 9.49414 14.1071 9.49414 18.7676C9.49414 23.4281 13.2722 27.2061 17.9326 27.2061Z" fill="var(--onboarding-icon-contrast)" /> <path fillRule="evenodd" clipRule="evenodd" d="M22.0497 16.6101C22.2612 16.8216 22.2612 17.1646 22.0497 17.3761L17.5018 21.9239C17.2903 22.1354 16.9473 22.1354 16.7358 21.9239L14.4087 19.5968C14.1971 19.3853 14.1971 19.0423 14.4086 18.8308C14.6202 18.6192 14.9631 18.6192 15.1747 18.8308L17.1188 20.7749L21.2837 16.6101C21.4952 16.3985 21.8382 16.3985 22.0497 16.6101Z" fill="var(--onboarding-icon-fill)" /> </svg> ); export const FiveStarIcon: VFC = () => ( <svg width="75" height="37" viewBox="0 0 75 37" fill="none"> <path d="M7.05163 12.4085C7.23504 12.0369 7.76496 12.0369 7.94837 12.4085L9.58786 15.7305C9.66069 15.878 9.80147 15.9803 9.96433 16.004L13.6303 16.5367C14.0405 16.5963 14.2042 17.1003 13.9074 17.3895L11.2547 19.9753C11.1369 20.0902 11.0831 20.2557 11.1109 20.4179L11.7371 24.0691C11.8072 24.4775 11.3785 24.789 11.0117 24.5962L7.73267 22.8723C7.58701 22.7957 7.41299 22.7957 7.26733 22.8723L3.98835 24.5962C3.62153 24.789 3.19282 24.4775 3.26287 24.0691L3.8891 20.4179C3.91692 20.2557 3.86315 20.0902 3.7453 19.9753L1.09255 17.3895C0.795793 17.1003 0.959547 16.5963 1.36966 16.5367L5.03567 16.004C5.19853 15.9803 5.33931 15.878 5.41214 15.7305L7.05163 12.4085Z" fill="url(#paint0_linear_7253_96138)" /> <path d="M22.0516 12.4085C22.235 12.0369 22.765 12.0369 22.9484 12.4085L24.5879 15.7305C24.6607 15.878 24.8015 15.9803 24.9643 16.004L28.6303 16.5367C29.0405 16.5963 29.2042 17.1003 28.9074 17.3895L26.2547 19.9753C26.1369 20.0902 26.0831 20.2557 26.1109 20.4179L26.7371 24.0691C26.8072 24.4775 26.3785 24.789 26.0117 24.5962L22.7327 22.8723C22.587 22.7957 22.413 22.7957 22.2673 22.8723L18.9883 24.5962C18.6215 24.789 18.1928 24.4775 18.2629 24.0691L18.8891 20.4179C18.9169 20.2557 18.8631 20.0902 18.7453 19.9753L16.0926 17.3895C15.7958 17.1003 15.9595 16.5963 16.3697 16.5367L20.0357 16.004C20.1985 15.9803 20.3393 15.878 20.4121 15.7305L22.0516 12.4085Z" fill="url(#paint1_linear_7253_96138)" /> <path d="M37.0516 12.4085C37.235 12.0369 37.765 12.0369 37.9484 12.4085L39.5879 15.7305C39.6607 15.878 39.8015 15.9803 39.9643 16.004L43.6303 16.5367C44.0405 16.5963 44.2042 17.1003 43.9074 17.3895L41.2547 19.9753C41.1369 20.0902 41.0831 20.2557 41.1109 20.4179L41.7371 24.0691C41.8072 24.4775 41.3785 24.789 41.0117 24.5962L37.7327 22.8723C37.587 22.7957 37.413 22.7957 37.2673 22.8723L33.9883 24.5962C33.6215 24.789 33.1928 24.4775 33.2629 24.0691L33.8891 20.4179C33.9169 20.2557 33.8631 20.0902 33.7453 19.9753L31.0926 17.3895C30.7958 17.1003 30.9595 16.5963 31.3697 16.5367L35.0357 16.004C35.1985 15.9803 35.3393 15.878 35.4121 15.7305L37.0516 12.4085Z" fill="url(#paint2_linear_7253_96138)" /> <path d="M52.0516 12.4085C52.235 12.0369 52.765 12.0369 52.9484 12.4085L54.5879 15.7305C54.6607 15.878 54.8015 15.9803 54.9643 16.004L58.6303 16.5367C59.0405 16.5963 59.2042 17.1003 58.9074 17.3895L56.2547 19.9753C56.1369 20.0902 56.0831 20.2557 56.1109 20.4179L56.7371 24.0691C56.8072 24.4775 56.3785 24.789 56.0117 24.5962L52.7327 22.8723C52.587 22.7957 52.413 22.7957 52.2673 22.8723L48.9883 24.5962C48.6215 24.789 48.1928 24.4775 48.2629 24.0691L48.8891 20.4179C48.9169 20.2557 48.8631 20.0902 48.7453 19.9753L46.0926 17.3895C45.7958 17.1003 45.9595 16.5963 46.3697 16.5367L50.0357 16.004C50.1985 15.9803 50.3393 15.878 50.4121 15.7305L52.0516 12.4085Z" fill="url(#paint3_linear_7253_96138)" /> <path d="M67.0516 12.4085C67.235 12.0369 67.765 12.0369 67.9484 12.4085L69.5879 15.7305C69.6607 15.878 69.8015 15.9803 69.9643 16.004L73.6303 16.5367C74.0405 16.5963 74.2042 17.1003 73.9074 17.3895L71.2547 19.9753C71.1369 20.0902 71.0831 20.2557 71.1109 20.4179L71.7371 24.0691C71.8072 24.4775 71.3785 24.789 71.0117 24.5962L67.7327 22.8723C67.587 22.7957 67.413 22.7957 67.2673 22.8723L63.9883 24.5962C63.6215 24.789 63.1928 24.4775 63.2629 24.0691L63.8891 20.4179C63.9169 20.2557 63.8631 20.0902 63.7453 19.9753L61.0926 17.3895C60.7958 17.1003 60.9595 16.5963 61.3697 16.5367L65.0357 16.004C65.1985 15.9803 65.3393 15.878 65.4121 15.7305L67.0516 12.4085Z" fill="url(#paint4_linear_7253_96138)" /> <path d="M60.8142 5.05102L63.4955 2.0827C63.8657 1.67286 63.8336 1.04052 63.4237 0.670312C63.0139 0.300109 62.3815 0.332241 62.0113 0.74208L59.3301 3.71039C58.9599 4.12023 58.992 4.75258 59.4018 5.12279C59.8117 5.49299 60.444 5.46086 60.8142 5.05102Z" fill="#48D3FF" /> <path d="M14.9497 33.5354L12.1213 30.707C11.7308 30.3164 11.0976 30.3164 10.7071 30.707C10.3166 31.0975 10.3166 31.7306 10.7071 32.1212L13.5355 34.9496C13.9261 35.3401 14.5592 35.3401 14.9497 34.9496C15.3403 34.5591 15.3403 33.9259 14.9497 33.5354Z" fill="#55E5B2" /> <path d="M58.1209 35.9497L60.9493 33.1213C61.3398 32.7308 61.3398 32.0976 60.9493 31.7071C60.5588 31.3166 59.9256 31.3166 59.5351 31.7071L56.7067 34.5355C56.3161 34.9261 56.3161 35.5592 56.7067 35.9497C57.0972 36.3403 57.7303 36.3403 58.1209 35.9497Z" fill="#C867F5" /> <path d="M35.5665 28.5413C35.4828 28.1957 35.222 27.9206 34.8814 27.8186L33.7967 27.4938C33.4537 27.3911 33.0818 27.4797 32.8219 27.7261L31.9912 28.5135C31.7343 28.7571 31.6253 29.1184 31.7046 29.4634L31.9644 30.5927C32.045 30.9432 32.3076 31.2234 32.6521 31.3265L33.7314 31.6497C34.0734 31.7521 34.4441 31.6644 34.704 31.4196L35.5508 30.6216C35.8123 30.3753 35.9215 30.0076 35.837 29.6585L35.5665 28.5413Z" fill="#FFA8A8" /> <path d="M22.4 3.07624C23.1111 3.4868 23.1111 4.5132 22.4 4.92376L19.6 6.54034C18.8889 6.9509 18 6.4377 18 5.61658L18 2.38342C18 1.5623 18.8889 1.0491 19.6 1.45966L22.4 3.07624Z" fill="#FF69B8" /> <defs> <linearGradient id="paint0_linear_7253_96138" x1="7.5" y1="11.5" x2="7.5" y2="26.5" gradientUnits="userSpaceOnUse" > <stop stopColor="#FFE76C" /> <stop offset="1" stopColor="#FFB94F" /> </linearGradient> <linearGradient id="paint1_linear_7253_96138" x1="22.5" y1="11.5" x2="22.5" y2="26.5" gradientUnits="userSpaceOnUse" > <stop stopColor="#FFE76C" /> <stop offset="1" stopColor="#FFB94F" /> </linearGradient> <linearGradient id="paint2_linear_7253_96138" x1="37.5" y1="11.5" x2="37.5" y2="26.5" gradientUnits="userSpaceOnUse" > <stop stopColor="#FFE76C" /> <stop offset="1" stopColor="#FFB94F" /> </linearGradient> <linearGradient id="paint3_linear_7253_96138" x1="52.5" y1="11.5" x2="52.5" y2="26.5" gradientUnits="userSpaceOnUse" > <stop stopColor="#FFE76C" /> <stop offset="1" stopColor="#FFB94F" /> </linearGradient> <linearGradient id="paint4_linear_7253_96138" x1="67.5" y1="11.5" x2="67.5" y2="26.5" gradientUnits="userSpaceOnUse" > <stop stopColor="#FFE76C" /> <stop offset="1" stopColor="#FFB94F" /> </linearGradient> </defs> </svg> ); export const InviteIcon: VFC = () => ( <svg width="58" height="58" viewBox="0 0 58 58" fill="none"> <path d="M54.4533 57.3098H3.48953C1.54454 57.3098 -7.62939e-06 55.7653 -7.62939e-06 53.8203V20.3691H58V53.8203C57.9428 55.708 56.3983 57.3098 54.4533 57.3098Z" fill="url(#paint0_linear_7068_94788)" /> <path d="M-7.62939e-06 20.3691L28.8885 40.7774L58 20.3691H-7.62939e-06Z" fill="#4D34B3" /> <path d="M58 20.369L30.6049 1.24818C29.5752 0.504512 28.2023 0.504512 27.1726 1.24818L0 20.369H58Z" fill="#4D34B3" /> <path d="M49.7143 26.1843L28.8887 40.777L8.28571 26.2247V5.86914H49.7143V26.1843Z" fill="url(#paint1_linear_7068_94788)" /> <path fillRule="evenodd" clipRule="evenodd" d="M5.57479 57.2663H54.2877C56.2327 57.2663 57.7772 55.6646 57.8344 53.7768V20.4854L5.57479 57.2663Z" fill="url(#paint2_linear_7068_94788)" /> <g clipPath="url(#clip0_7068_94788)"> <path d="M25.5587 15.1116C26.7633 13.907 27.3656 13.3047 28.0601 13.079C28.671 12.8806 29.3291 12.8806 29.94 13.079C30.6345 13.3047 31.2368 13.907 32.4414 15.1116L35.4525 18.1227C36.6571 19.3273 37.2594 19.9296 37.485 20.6241C37.6835 21.235 37.6835 21.8931 37.485 22.504C37.2594 23.1985 36.6571 23.8008 35.4525 25.0054L32.4414 28.0166C31.2368 29.2212 30.6345 29.8234 29.94 30.0491C29.3291 30.2476 28.671 30.2476 28.0601 30.0491C27.3656 29.8234 26.7633 29.2212 25.5587 28.0166L24.9926 27.3819C24.65 26.9978 24.4787 26.8058 24.3565 26.5873C24.2482 26.3936 24.1688 26.1852 24.1206 25.9685C24.0664 25.7242 24.0664 25.4669 24.0664 24.9522L24.0664 18.176C24.0664 17.6613 24.0664 17.404 24.1206 17.1597C24.1687 16.943 24.2482 16.7345 24.3565 16.5408C24.4787 16.3224 24.65 16.1303 24.9926 15.7463L25.5587 15.1116Z" fill="url(#paint3_radial_7068_94788)" /> <path d="M25.5587 15.1116C26.7633 13.907 27.3656 13.3047 28.0601 13.079C28.671 12.8806 29.3291 12.8806 29.94 13.079C30.6345 13.3047 31.2368 13.907 32.4414 15.1116L35.4525 18.1227C36.6571 19.3273 37.2594 19.9296 37.485 20.6241C37.6835 21.235 37.6835 21.8931 37.485 22.504C37.2594 23.1985 36.6571 23.8008 35.4525 25.0054L32.4414 28.0166C31.2368 29.2212 30.6345 29.8234 29.94 30.0491C29.3291 30.2476 28.671 30.2476 28.0601 30.0491C27.3656 29.8234 26.7633 29.2212 25.5587 28.0166L24.9926 27.3819C24.65 26.9978 24.4787 26.8058 24.3565 26.5873C24.2482 26.3936 24.1688 26.1852 24.1206 25.9685C24.0664 25.7242 24.0664 25.4669 24.0664 24.9522L24.0664 18.176C24.0664 17.6613 24.0664 17.404 24.1206 17.1597C24.1687 16.943 24.2482 16.7345 24.3565 16.5408C24.4787 16.3224 24.65 16.1303 24.9926 15.7463L25.5587 15.1116Z" fill="url(#paint4_linear_7068_94788)" /> <path d="M25.3436 15.3265C25.9458 14.7243 26.247 14.4231 26.5942 14.3103C26.8997 14.211 27.2287 14.211 27.5342 14.3103C27.8815 14.4231 28.1826 14.7243 28.7849 15.3265L33.3016 19.8433C33.9039 20.4456 34.2051 20.7467 34.3179 21.094C34.4171 21.3994 34.4171 21.7285 34.3179 22.0339C34.2051 22.3812 33.9039 22.6823 33.3016 23.2846L28.7849 27.8014C28.1826 28.4037 27.8815 28.7048 27.5342 28.8176C27.2287 28.9169 26.8997 28.9169 26.5942 28.8176C26.247 28.7048 25.9458 28.4037 25.3436 27.8014L22.5475 25.0053C21.3429 23.8007 20.7406 23.1984 20.5149 22.5039C20.3164 21.893 20.3164 21.2349 20.5149 20.624C20.7406 19.9295 21.3429 19.3272 22.5475 18.1226L25.3436 15.3265Z" fill="url(#paint5_radial_7068_94788)" /> </g> <defs> <linearGradient id="paint0_linear_7068_94788" x1="24.6845" y1="24.1668" x2="-1.90209e-05" y2="57.3096" gradientUnits="userSpaceOnUse" > <stop stopColor="#EEBEFF" /> <stop offset="1" stopColor="#6D4AFF" /> </linearGradient> <linearGradient id="paint1_linear_7068_94788" x1="28.9172" y1="5.76732" x2="28.9172" y2="40.777" gradientUnits="userSpaceOnUse" > <stop stopColor="white" /> <stop offset="1" stopColor="#FFF3EF" /> </linearGradient> <linearGradient id="paint2_linear_7068_94788" x1="68.8751" y1="26.4104" x2="15.5358" y2="57.3092" gradientUnits="userSpaceOnUse" > <stop stopColor="#EEBEFF" /> <stop offset="1" stopColor="#6D4AFF" /> </linearGradient> <radialGradient id="paint3_radial_7068_94788" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(25.5775 30.5345) rotate(-58.142) scale(14.4144 22.5412)" > <stop stopColor="#FFD580" /> <stop offset="0.09375" stopColor="#F6C592" /> <stop offset="0.205" stopColor="#EBB6A2" /> <stop offset="0.324466" stopColor="#DFA5AF" /> <stop offset="0.42875" stopColor="#D397BE" /> <stop offset="0.53375" stopColor="#C486CB" /> <stop offset="0.64875" stopColor="#B578D9" /> <stop offset="0.77125" stopColor="#A166E5" /> <stop offset="0.89125" stopColor="#8B57F2" /> <stop offset="1" stopColor="#704CFF" /> </radialGradient> <linearGradient id="paint4_linear_7068_94788" x1="24.9828" y1="9.50147" x2="28.3409" y2="29.9997" gradientUnits="userSpaceOnUse" > <stop stopColor="#6D4AFF" /> <stop offset="0.392009" stopColor="#B39FFB" stopOpacity="0.978022" /> <stop offset="1" stopColor="#FFE8DB" stopOpacity="0.8" /> </linearGradient> <radialGradient id="paint5_radial_7068_94788" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(24.3113 28.7793) rotate(-58.142) scale(11.5942 18.1309)" > <stop stopColor="#FFD580" /> <stop offset="0.09375" stopColor="#F6C592" /> <stop offset="0.205" stopColor="#EBB6A2" /> <stop offset="0.324466" stopColor="#DFA5AF" /> <stop offset="0.42875" stopColor="#D397BE" /> <stop offset="0.53375" stopColor="#C486CB" /> <stop offset="0.64875" stopColor="#B578D9" /> <stop offset="0.77125" stopColor="#A166E5" /> <stop offset="0.89125" stopColor="#8B57F2" /> <stop offset="1" stopColor="#704CFF" /> </radialGradient> <clipPath id="clip0_7068_94788"> <path d="M14.8718 7.43579H25.9094C35.4191 7.43579 43.1282 15.1449 43.1282 24.6545V35.6922H14.8718V7.43579Z" fill="white" /> </clipPath> </defs> </svg> );
7,680
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Spotlight/UpsellingModal.tsx
import { type VFC } from 'react'; import { useSelector } from 'react-redux'; import { c, msgid } from 'ttag'; import { Button, Card } from '@proton/atoms'; import type { IconName } from '@proton/components'; import { Icon, InlineLinkButton } from '@proton/components'; import type { ModalProps } from '@proton/components/components/modalTwo/Modal'; import { UpgradeButton } from '@proton/pass/components/Layout/Button/UpgradeButton'; import { SidebarModal } from '@proton/pass/components/Layout/Modal/SidebarModal'; import { Panel } from '@proton/pass/components/Layout/Panel/Panel'; import { PanelHeader } from '@proton/pass/components/Layout/Panel/PanelHeader'; import { PASS_BLOG_TRIAL_URL } from '@proton/pass/constants'; import { selectTrialDaysRemaining } from '@proton/pass/store/selectors'; import clsx from '@proton/utils/clsx'; export type Props = Omit<ModalProps, 'onSubmit'> & { type: UpsellingModalType }; export type UpsellingModalType = 'free-trial' | 'pass-plus'; interface OfferFeatures { className: string; icon: IconName; label: string; } interface UpsellModalContent { title: string; description?: string; upgradeLabel: string; } const getFeatures = (): OfferFeatures[] => [ { className: 'ui-orange', icon: 'pass-circles', label: c('Info').t`Multiple vaults` }, { className: 'ui-teal', icon: 'alias', label: c('Info').t`Unlimited Aliases` }, { className: 'ui-red', icon: 'users-plus', label: c('Info').t`Share with 10 others` }, { className: 'ui-lime', icon: 'list-bullets', label: c('Info').t`Credit cards, Custom fields` }, ]; const getContent = (type: UpsellingModalType): UpsellModalContent => ({ 'free-trial': { title: 'Your welcome gift', description: undefined, upgradeLabel: c('Action').t`Upgrade now`, }, 'pass-plus': { title: 'Pass Plus', description: c('Info') .t`Get unlimited aliases, enjoy exclusive features, and support us by subscribing to Pass Plus.`, upgradeLabel: c('Action').t`Upgrade`, }, })[type]; export const UpsellingModal: VFC<Props> = ({ type, ...props }) => { const { title, description, upgradeLabel } = getContent(type); const daysRemaining = useSelector(selectTrialDaysRemaining); const features = getFeatures(); return ( <SidebarModal {...props}> <Panel className="text-center" header={ <PanelHeader actions={[ <Button key="close-modal-button" className="flex-item-noshrink" icon pill shape="solid" onClick={props.onClose} > <Icon className="modal-close-icon" name="cross" alt={c('Action').t`Close`} /> </Button>, <UpgradeButton key="upgrade-button" label={upgradeLabel} />, ]} /> } > <img src="/assets/onboarding.svg" className="mb-2 w-2/3" alt="user onboarding graphic" /> <h3 className="mb-4 text-bold ">{title}</h3> {description && <p className="mb-6 text-rg">{description}</p>} <Card rounded bordered={false} className="mb-4 rounded-lg" style={{ backgroundColor: 'var(--field-norm)', padding: '0 1rem' }} > {features.map(({ className, icon, label }, idx) => ( <div className={clsx( 'flex flex-align-items-center py-3', idx < features.length - 1 && 'border-bottom', className )} key={label} > <Icon className="mr-3" color="var(--interaction-norm)" name={icon} size={18} /> <span>{label}</span> </div> ))} </Card> {daysRemaining !== null && ( <div className="text-sm"> { // translator: the word "these" refers to premium features listed above c('Info').ngettext( msgid`You have ${daysRemaining} day left to try these and other premium features.`, `You have ${daysRemaining} days left to try these and other premium features.`, daysRemaining ) } </div> )} {type === 'free-trial' && ( <InlineLinkButton className="text-sm" onClick={() => window.open(PASS_BLOG_TRIAL_URL, '_blank')}> {c('Action').t`Learn more`} </InlineLinkButton> )} </Panel> </SidebarModal> ); };
7,681
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/SharedVaultItem.tsx
import type { VFC } from 'react'; import { useSelector } from 'react-redux'; import { c, msgid } from 'ttag'; import { selectVaultItemsCount } from '@proton/pass/store/selectors'; import type { VaultColor, VaultIcon as VaultIconEnum } from '@proton/pass/types/protobuf/vault-v1'; import clsx from '@proton/utils/clsx'; import { VaultIcon } from './VaultIcon'; type SharedVaultItemProps = { className?: string; color?: VaultColor; icon?: VaultIconEnum; name: string; shareId?: string; }; export const SharedVaultItem: VFC<SharedVaultItemProps> = ({ className, color, icon, name, shareId = '', }: SharedVaultItemProps) => { const count = useSelector(selectVaultItemsCount(shareId)); return ( <div className={clsx(['flex flex-align-items-center gap-3', className])}> <VaultIcon color={color} icon={icon} size={20} background /> <div className="flex-item-fluid"> <div className="text-xl text-bold text-ellipsis">{name}</div> {count !== null && ( <span className="color-weak"> {c('Info').ngettext(msgid`${count} item`, `${count} items`, count)} </span> )} </div> </div> ); };
7,682
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/Vault.delete.tsx
import { type VFC } from 'react'; import { useDispatch } from 'react-redux'; import type { FormikErrors } from 'formik'; import { Field, Form, FormikProvider, useFormik } from 'formik'; import { c } from 'ttag'; import type { ConfirmationModalProps } from '@proton/pass/components/Confirmation/ConfirmationModal'; import { ConfirmationModal } from '@proton/pass/components/Confirmation/ConfirmationModal'; import { FieldsetCluster } from '@proton/pass/components/Form/Field/Layout/FieldsetCluster'; import { TextField } from '@proton/pass/components/Form/Field/TextField'; import { vaultDeleteIntent } from '@proton/pass/store/actions'; import type { VaultShareItem } from '@proton/pass/store/reducers'; type ConfirmDeleteValues = { name: string }; type Props = { vault: VaultShareItem; onSubmit: (shareId: string) => void; } & Pick<ConfirmationModalProps, 'onClose'>; const FORM_ID = 'vault-confirm-delete'; const initialValues: ConfirmDeleteValues = { name: '' }; export const VaultDelete: VFC<Props> = ({ vault, onClose, onSubmit }) => { const dispatch = useDispatch(); const vaultName = vault?.content?.name ?? ''; const validateVaultDelete = ({ name }: ConfirmDeleteValues) => { const errors: FormikErrors<ConfirmDeleteValues> = {}; if (!name || name !== vaultName) errors.name = c('Error').t`Vault name does not match`; return errors; }; const form = useFormik<ConfirmDeleteValues>({ initialValues, initialErrors: validateVaultDelete(initialValues), validateOnChange: true, validateOnMount: true, validate: validateVaultDelete, onSubmit: () => { const { content, shareId } = vault; dispatch(vaultDeleteIntent({ content, shareId })); onSubmit(shareId); }, }); return ( <ConfirmationModal open size="medium" onClose={onClose} onSubmit={form.submitForm} title={c('Title').t`Delete vault "${vaultName}" ?`} disabled={!form.isValid} submitText={c('Action').t`Delete`} alertText={c('Warning') .t`Vault "${vaultName}" and all its items will be permanently deleted. You cannot undo this action.`} > <FormikProvider value={form}> <Form id={FORM_ID}> <FieldsetCluster> <Field name="name" label={c('Label').t`Confirm vault name`} component={TextField} placeholder={c('Placeholder').t`Retype "${vaultName}" to confirm deletion`} autoFocus /> </FieldsetCluster> </Form> </FormikProvider> </ConfirmationModal> ); };
7,683
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/Vault.edit.tsx
import { type VFC } from 'react'; import { Form, FormikProvider, useFormik } from 'formik'; import { c } from 'ttag'; import { Button } from '@proton/atoms/Button'; import { Icon, type ModalProps } from '@proton/components/components'; import { SidebarModal } from '@proton/pass/components/Layout/Modal/SidebarModal'; import { Panel } from '@proton/pass/components/Layout/Panel/Panel'; import { PanelHeader } from '@proton/pass/components/Layout/Panel/PanelHeader'; import { useActionRequest } from '@proton/pass/hooks/useActionRequest'; import { validateVaultValues } from '@proton/pass/lib/validation/vault'; import { vaultEditIntent } from '@proton/pass/store/actions'; import type { VaultShareItem } from '@proton/pass/store/reducers'; import { VaultColor, VaultIcon } from '@proton/pass/types/protobuf/vault-v1'; import noop from '@proton/utils/noop'; import { VaultForm, type VaultFormValues } from './Vault.form'; type Props = Omit<ModalProps, 'onSubmit'> & { vault: VaultShareItem; onSuccess: () => void }; export const FORM_ID = 'vault-edit'; export const VaultEdit: VFC<Props> = ({ vault, onSuccess, ...modalProps }) => { const editVault = useActionRequest({ action: vaultEditIntent, onSuccess }); const form = useFormik<VaultFormValues>({ initialValues: { name: vault.content.name, description: vault.content.description, color: vault.content.display.color ?? VaultColor.COLOR1, icon: vault.content.display.icon ?? VaultIcon.ICON1, }, validateOnChange: true, validate: validateVaultValues, onSubmit: async ({ name, description, color, icon }) => { editVault.dispatch({ shareId: vault.shareId, content: { name, description, display: { color, icon } }, }); }, }); return ( <SidebarModal {...modalProps} open onBackdropClick={noop} disableCloseOnEscape> {(didEnter) => ( <Panel header={ <PanelHeader actions={[ <Button key="modal-close-button" className="flex-item-noshrink" icon pill shape="solid" onClick={modalProps.onClose} disabled={editVault.loading} > <Icon className="modal-close-icon" name="cross-big" alt={c('Action').t`Close`} /> </Button>, <Button key="modal-submit-button" type="submit" form={FORM_ID} color="norm" pill loading={editVault.loading} disabled={!form.isValid || editVault.loading} > {editVault.loading ? c('Action').t`Saving` : c('Action').t`Save`} </Button>, ]} /> } > <FormikProvider value={form}> <Form id={FORM_ID} className="flex flex-column gap-y-4"> <VaultForm form={form} autoFocus={didEnter} disabled={editVault.loading} /> </Form> </FormikProvider> </Panel> )} </SidebarModal> ); };
7,684
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/Vault.form.tsx
import { type FormikContextType } from 'formik'; import { c } from 'ttag'; import { Field } from '@proton/pass/components/Form/Field/Field'; import { FieldsetCluster } from '@proton/pass/components/Form/Field/Layout/FieldsetCluster'; import { RadioButton, RadioButtonGroupField } from '@proton/pass/components/Form/Field/RadioButtonGroupField'; import { TitleField } from '@proton/pass/components/Form/Field/TitleField'; import { VaultIcon } from '@proton/pass/components/Vault/VaultIcon'; import { VAULT_COLORS, VAULT_ICONS } from '@proton/pass/components/Vault/constants'; import { type VaultColor as VaultColorEnum, type VaultIcon as VaultIconEnum, } from '@proton/pass/types/protobuf/vault-v1'; export type VaultFormValues = { name: string; description: string; color: VaultColorEnum; icon: VaultIconEnum }; type Props<V extends VaultFormValues> = { form: FormikContextType<V>; autoFocus?: boolean; disabled?: boolean }; export const VaultForm = <V extends VaultFormValues>({ form, disabled, autoFocus }: Props<V>) => ( <div style={{ '--min-grid-template-column-size': '2.25rem' }}> <div className="flex flex-align-items-center gap-x-3"> <VaultIcon color={form.values.color} icon={form.values.icon} size={20} background /> <div className="flex-item-fluid"> <FieldsetCluster> <Field name="name" component={TitleField} label={c('Label').t`Title`} placeholder={c('Placeholder').t`Untitled`} autoFocus={autoFocus} disabled={disabled} key={`vault-title-${autoFocus}`} /> </FieldsetCluster> </div> </div> <Field name="color" component={RadioButtonGroupField} className="grid-auto-fill gap-x-6 gap-y-4 my-6" disabled={disabled} > {VAULT_COLORS.slice(2).map(([vaultColor, rgb]) => ( <RadioButton<VaultColorEnum> key={`vault-color-${vaultColor}`} value={vaultColor} color={rgb} /> ))} </Field> <Field name="icon" component={RadioButtonGroupField} className="grid-auto-fill gap-x-6 gap-y-4" disabled={disabled} > {VAULT_ICONS.slice(2).map(([vaultIcon, icon]) => ( <RadioButton<VaultIconEnum> key={`vault-icon-${vaultIcon}`} value={vaultIcon} icon={icon} /> ))} </Field> </div> );
7,685
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/Vault.move.tsx
import type { FC } from 'react'; import { useCallback, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { c } from 'ttag'; import { useConfirm } from '@proton/pass/hooks/useConfirm'; import { vaultMoveAllItemsIntent } from '@proton/pass/store/actions'; import { type VaultShareItem } from '@proton/pass/store/reducers'; import { selectShare, selectWritableVaultsWithItemsCount } from '@proton/pass/store/selectors'; import type { MaybeNull, ShareType } from '@proton/pass/types'; import { pipe, tap } from '@proton/pass/utils/fp/pipe'; import { ConfirmationModal } from '../Confirmation/ConfirmationModal'; import { VaultSelect } from './VaultSelect'; type Props = { vault: VaultShareItem; onClose: () => void }; type VaultMoveSteps = { view: 'select' | 'confirm'; destinationShareId: MaybeNull<string> }; export const VaultMove: FC<Props> = ({ vault, onClose }) => { const dispatch = useDispatch(); const [step, setStep] = useState<VaultMoveSteps>({ view: 'select', destinationShareId: null }); const destination = useSelector(selectShare<ShareType.Vault>(step.destinationShareId)); const fromVaultName = vault.content.name; const toVaultName = destination?.content.name ?? ''; const handleMoveItems = useConfirm( useCallback( (destinationShareId: string) => { const { shareId, content } = vault; dispatch(vaultMoveAllItemsIntent({ destinationShareId, content, shareId })); }, [vault] ) ); return ( <> <VaultSelect shareId={vault.shareId} optionsSelector={selectWritableVaultsWithItemsCount} open={step.view === 'select'} title={c('Info').t`Select destination vault`} onClose={onClose} onSubmit={(destinationShareId) => { setStep({ view: 'confirm', destinationShareId }); handleMoveItems.prompt(destinationShareId); }} downgradeMessage={c('Info') .t`You have exceeded the number of vaults included in your subscription. Items can only be moved to your first two vaults. To move items between all vaults upgrade your subscription.`} /> <ConfirmationModal open={handleMoveItems.pending} onClose={pipe(handleMoveItems.cancel, tap(onClose))} onSubmit={pipe(handleMoveItems.confirm, tap(onClose))} submitText={c('Action').t`Move all items`} title={c('Title').t`Move all items ?`} alertText={ // translator: variables here are the names of the source and destination vault c('Info').t`Are you sure you want to move all items from "${fromVaultName}" to "${toVaultName}" ?` } /> </> ); };
7,686
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/Vault.new.tsx
import { type VFC, useEffect } from 'react'; import { useSelector } from 'react-redux'; import { Form, FormikProvider, useFormik } from 'formik'; import { c } from 'ttag'; import { Button } from '@proton/atoms/Button'; import { Icon, type ModalProps } from '@proton/components/components'; import { UpgradeButton } from '@proton/pass/components/Layout/Button/UpgradeButton'; import { Card } from '@proton/pass/components/Layout/Card/Card'; import { SidebarModal } from '@proton/pass/components/Layout/Modal/SidebarModal'; import { Panel } from '@proton/pass/components/Layout/Panel/Panel'; import { PanelHeader } from '@proton/pass/components/Layout/Panel/PanelHeader'; import { type RequestEntryFromAction, useActionRequest } from '@proton/pass/hooks/useActionRequest'; import { validateVaultValues } from '@proton/pass/lib/validation/vault'; import type { vaultCreationSuccess } from '@proton/pass/store/actions'; import { vaultCreationIntent } from '@proton/pass/store/actions'; import { selectPassPlan, selectVaultLimits } from '@proton/pass/store/selectors'; import { UserPassPlan } from '@proton/pass/types/api/plan'; import { VaultColor, VaultIcon } from '@proton/pass/types/protobuf/vault-v1'; import noop from '@proton/utils/noop'; import { VaultForm, type VaultFormValues } from './Vault.form'; type Props = Omit<ModalProps, 'onSubmit'> & { onSuccess: (shareId: string) => void }; const FORM_ID = 'vault-create'; export const VaultNew: VFC<Props> = ({ onSuccess, ...modalProps }) => { const { vaultLimitReached } = useSelector(selectVaultLimits); const passPlan = useSelector(selectPassPlan); const createVault = useActionRequest({ action: vaultCreationIntent, onSuccess: (req: RequestEntryFromAction<ReturnType<typeof vaultCreationSuccess>>) => onSuccess?.(req.data.shareId), }); const form = useFormik<VaultFormValues>({ initialValues: { name: '', description: '', color: VaultColor.COLOR1, icon: VaultIcon.ICON1, }, validateOnChange: true, validate: validateVaultValues, onSubmit: ({ name, description, color, icon }) => { createVault.dispatch({ content: { name, description, display: { color, icon }, }, }); }, }); useEffect(() => form.resetForm(), [modalProps.open]); return ( <SidebarModal {...modalProps} open onBackdropClick={noop} disableCloseOnEscape> {(didEnter) => ( <Panel header={ <PanelHeader actions={[ <Button key="modal-close-button" className="flex-item-noshrink" icon pill shape="solid" onClick={modalProps.onClose} disabled={createVault.loading} > <Icon className="modal-close-icon" name="cross-big" alt={c('Action').t`Close`} /> </Button>, !vaultLimitReached ? ( <Button key="modal-submit-button" type="submit" form={FORM_ID} color="norm" pill loading={createVault.loading} disabled={!form.isValid || createVault.loading} > {createVault.loading ? c('Action').t`Creating vault` : c('Action').t`Create vault`} </Button> ) : ( <UpgradeButton key="upgrade-button" /> ), ]} /> } > <> {vaultLimitReached && ( <Card className="mb-4"> {c('Info').t`You have reached the limit of vaults you can create.`} {passPlan === UserPassPlan.FREE && c('Info').t` Upgrade to a paid plan to create multiple vaults.`} </Card> )} <FormikProvider value={form}> <Form id={FORM_ID} className="flex flex-column gap-y-4"> <VaultForm form={form} autoFocus={didEnter} disabled={createVault.loading} /> </Form> </FormikProvider> </> </Panel> )} </SidebarModal> ); };
7,687
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/VaultActionsProvider.tsx
import { type FC, createContext, useCallback, useContext, useMemo, useState } from 'react'; import { useDispatch } from 'react-redux'; import { c } from 'ttag'; import { ConfirmationModal } from '@proton/pass/components/Confirmation/ConfirmationModal'; import { useInviteContext } from '@proton/pass/components/Invite/InviteContextProvider'; import { VaultDelete } from '@proton/pass/components/Vault/Vault.delete'; import { emptyTrashIntent, restoreTrashIntent, shareLeaveIntent } from '@proton/pass/store/actions'; import type { VaultShareItem } from '@proton/pass/store/reducers'; import type { MaybeNull } from '@proton/pass/types'; import { pipe } from '@proton/pass/utils/fp/pipe'; import noop from '@proton/utils/noop'; import { VaultEdit } from './Vault.edit'; import { VaultMove } from './Vault.move'; import { VaultNew } from './Vault.new'; type VaultActionsContextValue = { create: () => void; delete: (vault: VaultShareItem) => void; edit: (vault: VaultShareItem) => void; invite: (vault: VaultShareItem) => void; leave: (vault: VaultShareItem) => void; manage: (vault: VaultShareItem) => void; moveItems: (vault: VaultShareItem) => void; trashEmpty: () => void; trashRestore: () => void; }; type VaultActionsProviderProps = { onVaultCreated: (shareId: string) => void; onVaultDeleted: (shareId: string) => void; }; type VaultActionState = | { view: 'create' | 'trash-empty' } | { view: 'edit' | 'delete' | 'move' | 'leave'; vault: VaultShareItem }; export const VaultActionsContext = createContext<VaultActionsContextValue>({ create: noop, delete: noop, edit: noop, invite: noop, leave: noop, manage: noop, moveItems: noop, trashEmpty: noop, trashRestore: noop, }); export const useVaultActions = () => useContext(VaultActionsContext); export const VaultActionsProvider: FC<VaultActionsProviderProps> = ({ onVaultCreated, onVaultDeleted, children }) => { const inviteContext = useInviteContext(); const dispatch = useDispatch(); const [state, setState] = useState<MaybeNull<VaultActionState>>(); const reset = () => setState(null); const handleVaultLeave = useCallback(({ shareId }: VaultShareItem) => dispatch(shareLeaveIntent({ shareId })), []); const handleTrashEmpty = useCallback(() => dispatch(emptyTrashIntent()), []); const actions = useMemo<VaultActionsContextValue>( () => ({ create: () => setState({ view: 'create' }), delete: (vault) => setState({ view: 'delete', vault }), edit: (vault) => setState({ view: 'edit', vault }), invite: (vault) => inviteContext.createInvite({ vault }), leave: (vault) => setState({ view: 'leave', vault }), manage: (vault) => inviteContext.manageAccess(vault.shareId), moveItems: (vault) => setState({ view: 'move', vault }), trashEmpty: () => setState({ view: 'trash-empty' }), trashRestore: () => dispatch(restoreTrashIntent()), }), [inviteContext] ); return ( <VaultActionsContext.Provider value={actions}> {children} {(() => { if (!state) return; switch (state?.view) { case 'create': return <VaultNew onSuccess={pipe(onVaultCreated, reset)} onClose={reset} />; case 'edit': return <VaultEdit vault={state.vault} onSuccess={reset} onClose={reset} />; case 'delete': return ( <VaultDelete vault={state.vault} onSubmit={pipe(onVaultDeleted, reset)} onClose={reset} /> ); case 'move': return <VaultMove vault={state.vault} onClose={reset} />; case 'leave': return ( <ConfirmationModal open onClose={reset} onSubmit={pipe(() => handleVaultLeave(state.vault), reset)} title={c('Title').t`Leave vault ?`} submitText={c('Action').t`Leave`} alertText={c('Warning') .t`You will no longer have access to this vault. To join it again, you will need a new invitation.`} /> ); case 'trash-empty': return ( <ConfirmationModal open onClose={reset} onSubmit={pipe(handleTrashEmpty, reset)} title={c('Title').t`Permanently remove all items ?`} submitText={c('Action').t`Delete all`} alertText={c('Warning') .t`All your trashed items will be permanently deleted. You cannot undo this action.`} /> ); } })()} </VaultActionsContext.Provider> ); };
7,688
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/VaultIcon.scss
@import '~@proton/styles/scss/lib'; .pass-vault-icon { color: rgb(var(--vault-icon-color)); &.background { background-color: rgb(var(--vault-icon-color) / 0.16); } }
7,689
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/VaultIcon.tsx
import type { VFC } from 'react'; import type { IconSize } from '@proton/components/components'; import { Icon } from '@proton/components/components'; import type { VaultIcon as VaultIconEnum } from '@proton/pass/types/protobuf/vault-v1'; import { VaultColor as VaultColorEnum } from '@proton/pass/types/protobuf/vault-v1'; import { rootFontSize } from '@proton/shared/lib/helpers/dom'; import clsx from '@proton/utils/clsx'; import { VAULT_COLOR_MAP, VAULT_ICON_MAP } from '../../components/Vault/constants'; import './VaultIcon.scss'; export type VaultIconName = VaultIconEnum | 'pass-all-vaults' | 'pass-trash'; type Props = { background?: boolean; className?: string; color?: VaultColorEnum; highlighted?: boolean; icon?: VaultIconName; size?: IconSize; }; const rem = (px: number) => `${px / rootFontSize()}rem`; export const VaultIcon: VFC<Props> = ({ className, background, highlighted, size = 20, color, icon = 'pass-all-vaults', }) => ( <span className={clsx([ `pass-vault-icon rounded-xl relative w-custom h-custom`, background && 'background', size >= 20 && 'rounded-full', className, ])} style={{ '--vault-icon-color': highlighted ? 'var(--interaction-norm-contrast)' : VAULT_COLOR_MAP[color ?? VaultColorEnum.COLOR1], '--w-custom': rem(background ? size * 2 : size), '--h-custom': rem(background ? size * 2 : size), }} > <Icon className="absolute-center" name={icon === 'pass-all-vaults' || icon === 'pass-trash' ? icon : VAULT_ICON_MAP[icon]} size={size} /> </span> );
7,690
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/VaultSelect.tsx
import { type VFC, useMemo, useState } from 'react'; import type { Selector } from 'react-redux'; import { useSelector } from 'react-redux'; import { c } from 'ttag'; import { Button } from '@proton/atoms'; import { Icon } from '@proton/components'; import type { ModalProps } from '@proton/components/components/modalTwo/Modal'; import { RadioButtonGroup, RadioLabelledButton } from '@proton/pass/components/Form/Field/RadioButtonGroupField'; import { UpgradeButton } from '@proton/pass/components/Layout/Button/UpgradeButton'; import { Card } from '@proton/pass/components/Layout/Card/Card'; import { SidebarModal } from '@proton/pass/components/Layout/Modal/SidebarModal'; import { Panel } from '@proton/pass/components/Layout/Panel/Panel'; import { PanelHeader } from '@proton/pass/components/Layout/Panel/PanelHeader'; import { VaultIcon } from '@proton/pass/components/Vault/VaultIcon'; import type { VaultShareItem, WithItemCount } from '@proton/pass/store/reducers'; import { selectVaultLimits } from '@proton/pass/store/selectors'; import { NOOP_LIST_SELECTOR } from '@proton/pass/store/selectors/utils'; import type { State } from '@proton/pass/store/types'; type OptionsSelector = Selector<State, WithItemCount<VaultShareItem>[]>; export type Props = Omit<ModalProps, 'onSubmit'> & { downgradeMessage: string; onSubmit: (shareId: string) => void; optionsSelector: OptionsSelector; shareId: string; title?: string; }; /* if the user has downgraded : only allow him to select * his writable vaults as target. This rule applies when moving * an item to a vault or when selecting an item's vault */ export const VaultSelect: VFC<Props> = ({ downgradeMessage, onSubmit, optionsSelector, shareId, title, ...props }) => { const vaults = useSelector(optionsSelector); const { didDowngrade } = useSelector(selectVaultLimits); const sortedVaults = useMemo( () => /* make the current vault appear first in the list */ vaults.slice().sort((a, b) => { if (a.shareId === shareId) return -1; else if (b.shareId === shareId) return 1; else return 0; }), [vaults] ); return ( <SidebarModal {...props}> <Panel header={ <PanelHeader actions={[ <Button key="close-modal-button" className="flex-item-noshrink" icon pill shape="solid" onClick={props.onClose} > <Icon className="modal-close-icon" name="cross-big" alt={c('Action').t`Close`} /> </Button>, ...(didDowngrade ? [<UpgradeButton key="upgrade-button" />] : []), ]} /> } > {title && <div className="mb-2 text-bold text-xl">{title}</div>} {didDowngrade && <Card>{downgradeMessage}</Card>} <RadioButtonGroup name="vault-select" className="flex-columns" value={shareId} onChange={onSubmit}> {sortedVaults.map((vault) => ( <RadioLabelledButton value={vault.shareId} key={vault.shareId} disabled={vault.shareId === shareId} > <VaultIcon size={20} background color={vault.content.display.color} icon={vault.content.display.icon} /> <div className="flex flex-item-fluid flex-column"> <span className="text-ellipsis inline-block max-w-full color-norm"> {vault.content.name} </span> <span className="block color-weak">{vault.count} items</span> </div> </RadioLabelledButton> ))} </RadioButtonGroup> </Panel> </SidebarModal> ); }; export const useVaultSelectModalHandles = () => { const [modalState, setModalState] = useState<Pick<Props, 'shareId' | 'open' | 'optionsSelector'>>({ open: false, shareId: '', optionsSelector: NOOP_LIST_SELECTOR, }); return { modalState, ...useMemo( () => ({ closeVaultSelect: () => setModalState((state) => ({ ...state, open: false, optionsSelector: NOOP_LIST_SELECTOR, })), openVaultSelect: (shareId: string, optionsSelector: OptionsSelector) => setModalState({ shareId, open: true, optionsSelector, }), }), [] ), }; };
7,691
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/VaultTag.scss
.pass-vault-tag { color: var(--text-weak); &--shared { color: rgb(var(--vault-icon-color)); } }
7,692
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/VaultTag.tsx
import type { VFC } from 'react'; import type { IconName, IconSize } from '@proton/components/components'; import { Icon } from '@proton/components/components'; import { VaultColor } from '@proton/pass/types/protobuf/vault-v1'; import clsx from '@proton/utils/clsx'; import { VAULT_COLOR_MAP } from './constants'; import './VaultTag.scss'; type Props = { title: string; shared?: boolean; icon: IconName; color?: VaultColor; count?: number; iconSize?: IconSize; }; export const VaultTag: VFC<Props> = ({ title, shared = false, icon, color, count, iconSize = 12 }) => { return ( <div className={clsx( 'pass-vault-tag flex flex-align-items-center text-sm gap-x-2 flex-nowrap', shared && 'pass-vault-tag--shared' )} style={shared ? { '--vault-icon-color': VAULT_COLOR_MAP[color ?? VaultColor.COLOR1] } : undefined} > {<Icon className="flex-item-noshrink" name={icon} size={iconSize} />} <span className="text-ellipsis">{title}</span> {count !== undefined && count > 1 && <span className="flex-item-noshrink">β€’ {count}</span>} </div> ); };
7,693
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Vault/constants.ts
import type { IconName } from '@proton/components/components'; import type { ColorRGB } from '@proton/pass/types'; import { VaultColor, VaultIcon } from '@proton/pass/types/protobuf/vault-v1'; const numericEntries = <T extends Record<number, any>>( obj: T ): [number, T extends Record<any, infer U> ? U : never][] => Object.keys(obj).map((key) => [Number(key), obj[Number(key)]]); export const VAULT_COLOR_MAP: Record<number, ColorRGB> = { [VaultColor.COLOR_UNSPECIFIED]: '140 140 147', [VaultColor.COLOR_CUSTOM]: '167 121 255', [VaultColor.COLOR1]: '167 121 255', [VaultColor.COLOR2]: '242 146 146', [VaultColor.COLOR3]: '247 215 117', [VaultColor.COLOR4]: '145 199 153', [VaultColor.COLOR5]: '146 179 242', [VaultColor.COLOR6]: '235 141 214', [VaultColor.COLOR7]: '205 90 111', [VaultColor.COLOR8]: '228 163 103', [VaultColor.COLOR9]: '230 230 230', [VaultColor.COLOR10]: '158 226 230', }; export const VAULT_COLORS = numericEntries(VAULT_COLOR_MAP); export const VAULT_ICON_MAP: Record<number, IconName> = { [VaultIcon.ICON_UNSPECIFIED]: 'pass-home', [VaultIcon.ICON_CUSTOM]: 'pass-home', [VaultIcon.ICON1]: 'pass-home', [VaultIcon.ICON2]: 'pass-work', [VaultIcon.ICON3]: 'pass-gift', [VaultIcon.ICON4]: 'pass-shop', [VaultIcon.ICON5]: 'pass-heart', [VaultIcon.ICON6]: 'pass-bear', [VaultIcon.ICON7]: 'pass-circles', [VaultIcon.ICON8]: 'pass-flower', [VaultIcon.ICON9]: 'pass-group', [VaultIcon.ICON10]: 'pass-pacman', [VaultIcon.ICON11]: 'pass-shopping-cart', [VaultIcon.ICON12]: 'pass-leaf', [VaultIcon.ICON13]: 'pass-shield', [VaultIcon.ICON14]: 'pass-basketball', [VaultIcon.ICON15]: 'pass-credit-card', [VaultIcon.ICON16]: 'pass-fish', [VaultIcon.ICON17]: 'pass-smile', [VaultIcon.ICON18]: 'pass-lock', [VaultIcon.ICON19]: 'pass-mushroom', [VaultIcon.ICON20]: 'pass-star', [VaultIcon.ICON21]: 'pass-fire', [VaultIcon.ICON22]: 'pass-wallet', [VaultIcon.ICON23]: 'pass-bookmark', [VaultIcon.ICON24]: 'pass-cream', [VaultIcon.ICON25]: 'pass-laptop', [VaultIcon.ICON26]: 'pass-json', [VaultIcon.ICON27]: 'pass-book', [VaultIcon.ICON28]: 'pass-box', [VaultIcon.ICON29]: 'pass-atom', [VaultIcon.ICON30]: 'pass-cheque', }; export const VAULT_ICONS = numericEntries(VAULT_ICON_MAP);
7,694
0
petrpan-code/ProtonMail/WebClients/packages/pass/components
petrpan-code/ProtonMail/WebClients/packages/pass/components/Views/types.ts
import type { VaultShareItem } from '@proton/pass/store/reducers'; import type { ItemCreateIntent, ItemEditIntent, ItemRevision, ItemType, MaybeNull } from '@proton/pass/types'; import type { ParsedUrl } from '@proton/pass/utils/url/parser'; export type ItemViewProps<T extends ItemType = ItemType> = { failed: boolean; optimistic: boolean; revision: ItemRevision<T>; trashed: boolean; vault: VaultShareItem; handleDeleteClick: () => void; handleDismissClick: () => void; handleEditClick: () => void; handleMoveToTrashClick: () => void; handleMoveToVaultClick: () => void; handleRestoreClick: () => void; handleRetryClick: () => void; handleInviteClick: () => void; handleManageClick: () => void; }; export type ItemEditViewProps<T extends ItemType = ItemType> = { revision: ItemRevision<T>; url: MaybeNull<ParsedUrl>; vault: VaultShareItem; onCancel: () => void; onSubmit: (item: ItemEditIntent<T>) => void; }; export type ItemNewViewProps<T extends ItemType = ItemType> = { shareId: string; url: MaybeNull<ParsedUrl>; onCancel: () => void; onSubmit: (item: ItemCreateIntent<T>) => void; };
7,695
0
petrpan-code/ProtonMail/WebClients/packages/pass
petrpan-code/ProtonMail/WebClients/packages/pass/docs/README.md
# Proton Pass Documentation Documentation for proton pass web clients ### File structure ```bash β”œβ”€β”€ applications β”‚ β”œβ”€β”€ pass-extension # extension codebase β”œβ”€β”€ packages β”‚ β”œβ”€β”€ pass (@proton/pass) # shared code ``` ### Conventions ##### VSCode settings Add the following properties to your `settings.json` ```json "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": { "source.organizeImports": true, "source.fixAll.eslint": true } ``` ##### Best practices - Prefer named exports & avoid index file re-exports - Specify `import type { ... }` or `import { type ... }` when importing types - Use `FC` utility type from react to explicitly type components & `VFC` for children-less components - When using React Context, ensure its responsibilities are well defined & the implementation is correct in regards to having a stable context value or memoized according to its dependencies - Create hooks when composing data from context and/or redux for use in UI components.
7,696
0
petrpan-code/ProtonMail/WebClients/packages/pass
petrpan-code/ProtonMail/WebClients/packages/pass/docs/_sidebar.md
<!-- docs/_sidebar.md --> - [Proton Pass](/) * Extension - [Quick start](extension/quickstart.md) - [Architecture](extension/architecture.md) - [Communication layer](extension/coms.md)
7,697
0
petrpan-code/ProtonMail/WebClients/packages/pass
petrpan-code/ProtonMail/WebClients/packages/pass/docs/index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta name="description" content="Description" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" /> <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css" /> </head> <body> <div id="app"></div> <script> window.$docsify = { loadSidebar: true, name: '', repo: '', }; </script> <!-- Docsify v4 --> <script src="//cdn.jsdelivr.net/npm/docsify@4"></script> <script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script> <script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-json.min.js"></script> </body> </html>
7,698
0
petrpan-code/ProtonMail/WebClients/packages/pass/docs
petrpan-code/ProtonMail/WebClients/packages/pass/docs/extension/architecture.md
# Architecture
7,699