/** * @file AlignmentControls component */ import * as React from "react"; import type { Node } from "../../../types/core"; import { useI18n } from "../../../i18n/context"; import { InspectorLabel } from "../../inspector/parts/InspectorLabel"; import { ALIGNMENT_ACTIONS, ALIGNMENT_GROUPS } from "./constants"; import type { AlignmentActionConfig, AlignmentActionGroup, AlignmentActionType } from "./types"; import styles from "./AlignmentControls.module.css"; export type AlignmentControlsProps = { selectedNodes: Node[]; onAlign: (type: AlignmentActionType) => void; }; /** * Alignment controls component for selected nodes * Provides UI for aligning and distributing multiple nodes */ export const AlignmentControls = React.memo(({ selectedNodes, onAlign }) => { const { t } = useI18n(); const isDisabled = selectedNodes.length < 2; const groupedActions = React.useMemo(() => { return ALIGNMENT_GROUPS.reduce>( (acc, group) => { acc[group] = ALIGNMENT_ACTIONS.filter((action) => action.group === group); return acc; }, { horizontal: [], vertical: [] }, ); }, []); const alignmentSuffix = selectedNodes.length > 1 ? t("alignmentCountLabel", { count: selectedNodes.length }) : t("alignmentSelectPrompt"); const alignmentLabel = `${t("alignmentTitle")} (${alignmentSuffix})`; return (
{alignmentLabel}
{ALIGNMENT_GROUPS.map((group) => (
{groupedActions[group]?.map((button) => { const IconComponent = button.icon; return ( ); })}
))}
); }); AlignmentControls.displayName = "AlignmentControls";