1 import type { ComponentPropsWithoutRef, ReactNode } from 'react';
2 import { useEffect, useRef } from 'react';
3 import { Link } from 'react-router-dom';
5 import { c } from 'ttag';
7 import Icon from '@proton/components/components/icon/Icon';
8 import ProtonBadge from '@proton/components/components/protonBadge/ProtonBadge';
9 import SettingsSectionTitle from '@proton/components/containers/account/SettingsSectionTitle';
10 import useNotifications from '@proton/components/hooks/useNotifications';
11 import { textToClipboard } from '@proton/shared/lib/helpers/browser';
12 import clsx from '@proton/utils/clsx';
14 export interface SubSettingsSectionProps extends ComponentPropsWithoutRef<'div'> {
17 observer?: IntersectionObserver;
23 const SubSettingsSection = ({ id, observer, title, beta, children, className, ...rest }: SubSettingsSectionProps) => {
24 const ref = useRef<HTMLDivElement>(null);
25 const { createNotification } = useNotifications();
28 const el = ref.current;
29 if (!observer || !el) {
34 observer.unobserve(el);
36 }, [observer, ref.current]);
38 const handleLinkClick = () => {
39 const hash = document.location.hash;
40 const dehashedHref = document.location.href.replace(hash, '');
42 const urlToCopy = `${dehashedHref}#${id}`;
43 textToClipboard(urlToCopy);
46 text: c('Info').t`Link copied to clipboard`,
52 <div className="relative">
53 <div id={id} className="header-height-anchor" />
60 className={clsx([className, 'sub-settings-section'])}
63 <SettingsSectionTitle className="group-hover-opacity-container relative">
66 onClick={handleLinkClick}
67 className="sub-settings-section-anchor absolute group-hover:opacity-100"
76 className="align-middle"
77 text={c('Info').t`Beta`}
78 tooltipText={c('Tooltip').t`Feature in early access`}
81 </SettingsSectionTitle>
89 export default SubSettingsSection;