1 /* eslint-disable jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */
4 type ForwardRefRenderFunction,
5 type MouseEventHandler,
13 import { Icon, type IconName } from '@proton/components';
14 import type { MaybeArray } from '@proton/pass/types';
15 import clsx from '@proton/utils/clsx';
17 import './FieldBox.scss';
19 export type FieldBoxProps = {
20 actions?: MaybeArray<ReactElement>;
21 actionsContainerClassName?: string;
22 children?: ReactNode | undefined;
24 icon?: IconName | ReactElement;
26 onClick?: MouseEventHandler;
29 const stopOnClickPropagation = (nodes: MaybeArray<ReactElement>): MaybeArray<ReactElement> =>
30 Children.map(nodes, (node: ReactElement, index) => {
31 const props = node.props as any;
33 return isValidElement(node)
34 ? cloneElement<any>(node, {
35 key: node.key || index,
38 onClick: (e: MouseEvent) => {
44 children: props?.children ? stopOnClickPropagation(props?.children) : undefined,
49 const FieldBoxRender: ForwardRefRenderFunction<HTMLDivElement, FieldBoxProps> = (props, ref) => {
50 const { className, actions, actionsContainerClassName, children, icon } = props;
51 const isCoreIcon = typeof icon == 'string';
52 const iconEl = isCoreIcon ? <Icon name={icon} size={4} /> : icon;
56 className={clsx('pass-field-box flex flex-nowrap items-start', !props.unstyled && 'px-4 py-3', className)}
58 onClick={props.onClick}
62 className={clsx('flex justify-center items-center shrink-0 pr-4', isCoreIcon && 'mt-2')}
63 style={{ color: 'var(--fieldset-cluster-icon-color)' }}
69 <div className="w-full">{children}</div>
72 <span className={clsx('shrink-0 ml-3', actionsContainerClassName)}>
73 {stopOnClickPropagation(actions)}
80 export const FieldBox = forwardRef(FieldBoxRender);