Private
Public Access
1
0
Files

35 lines
1.2 KiB
JavaScript

'use client';
import * as React from 'react';
import { useBadgeBase_unstable } from '../Badge/index';
/**
* Returns the props and state required to render the component
*/ export const useCounterBadge_unstable = (props, ref)=>{
const { shape = 'circular', appearance = 'filled', color = 'brand', size = 'medium', ...counterBadgeProps } = props;
const state = useCounterBadgeBase_unstable(counterBadgeProps, ref);
return {
...state,
shape,
appearance,
color,
size
};
};
/**
* Base hook for CounterBadge component, which manages state related to slots structure and counter logic.
*
* @param props - User provided props to the CounterBadge component.
* @param ref - User provided ref to be passed to the CounterBadge component.
*/ export const useCounterBadgeBase_unstable = (props, ref)=>{
const { showZero = false, overflowCount = 99, count = 0, dot = false, ...badgeProps } = props;
const state = {
...useBadgeBase_unstable(badgeProps, ref),
showZero,
count,
dot
};
if ((count !== 0 || showZero) && !dot && !state.root.children) {
state.root.children = count > overflowCount ? `${overflowCount}+` : `${count}`;
}
return state;
};