import { Pressable } from '@ankhorage/surface'; import React from 'react'; import type { ChipInteractionState, ChipProps } from '../../../../types/chip'; import { Icon } from '../../../icon/public'; import { resolveIconSize } from '../../../icon/utils/resolveIconSize'; import { View } from '../../../layout/public'; import { withZoraThemeScope } from '../../../theme/adapters/inbound/withZoraThemeScope'; import { useZoraTheme } from '../../../theme/composition/useZoraTheme'; import { Text } from '../../../typography/public'; import { resolveChipColors } from '../../utils/resolveChipColors'; /*** * Compact pill-like control for filters, tags, and quick selections. */ export const Chip = withZoraThemeScope(ChipInner); function resolveChipPadding(size: NonNullable): { px: 's' | 'm'; py: 'xxs' | 'xs'; } { switch (size) { case 's': return { px: 's', py: 'xxs' }; case 'm': return { px: 'm', py: 'xs' }; case 'l': default: return { px: 'm', py: 'xs' }; } } function ChipInner({ themeId: _themeId, mode: _mode, testID, children, icon, selected = false, disabled = false, color = 'neutral', size = 's', interactionPolicy, onPress, }: ChipProps) { const { theme } = useZoraTheme(); const padding = resolveChipPadding(size); const iconSize = resolveIconSize(size); const renderContent = (state: ChipInteractionState) => { const colors = resolveChipColors({ theme, color, selected, state }); const textColor = state.disabled ? undefined : selected && color !== 'neutral' ? color : undefined; const textEmphasis = state.disabled ? 'muted' : 'default'; return ( {icon ? : null} {children} ); }; if (!onPress) { return renderContent({ disabled, focused: false, hovered: false, pressed: false }); } return ( {(state) => renderContent(state)} ); }