// Copyright 2025 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ButtonHTMLAttributes, FC, ForwardedRef, ReactNode } from 'react';
import React, { forwardRef, memo, useCallback } from 'react';
import { ToggleGroup } from 'radix-ui';
import { ExperimentalAxoBaseSegmentedControl } from './_internal/AxoBaseSegmentedControl.dom.js';
const Namespace = 'AxoSegmentedControl';
/**
* @example Anatomy
* ```tsx
*
*
*
*
*
*
* ```
*/
export namespace ExperimentalAxoSegmentedControl {
export type Variant = ExperimentalAxoBaseSegmentedControl.Variant;
/**
* Component:
* -------------------------------------
*/
export type RootWidth = ExperimentalAxoBaseSegmentedControl.RootWidth;
export type ItemWidth = ExperimentalAxoBaseSegmentedControl.ItemWidth;
export type RootProps = Readonly<{
width: RootWidth;
itemWidth: ItemWidth;
variant: Variant;
value: string | null;
onValueChange: (newValue: string | null) => void;
children: ReactNode;
}>;
export const Root = memo((props: RootProps) => {
const { onValueChange } = props;
const handleValueChange = useCallback(
(newValue: string) => {
onValueChange(newValue === '' ? null : newValue);
},
[onValueChange]
);
return (
{props.children}
);
});
Root.displayName = `${Namespace}.Root`;
/**
* Component:
* -------------------------------------
*/
export type ItemProps = ButtonHTMLAttributes &
Readonly<{
value: string;
children: ReactNode;
}>;
export const Item: FC = memo(
forwardRef((props: ItemProps, ref: ForwardedRef) => {
const { value, children, ...rest } = props;
return (
{children}
);
})
);
Item.displayName = `${Namespace}.Item`;
/**
* Component:
* -----------------------------------------
*/
export type ItemTextProps = Readonly<{
maxWidth?: ExperimentalAxoBaseSegmentedControl.ItemMaxWidth;
children: ReactNode;
}>;
export const ItemText: FC = memo((props: ItemTextProps) => {
return (
{props.children}
);
});
ItemText.displayName = `${Namespace}.ItemText`;
/**
* Component:
* ------------------------------------------
*/
export type ExperimentalItemBadgeProps =
ExperimentalAxoBaseSegmentedControl.ExperimentalItemBadgeProps;
export const { ExperimentalItemBadge } = ExperimentalAxoBaseSegmentedControl;
}