35 lines
984 B
TypeScript
35 lines
984 B
TypeScript
import type { FlexBoxOwnProps } from '../flex-box';
|
|
import type { ButtonElementProps } from './types';
|
|
|
|
/** Icon, label and end icon in one centred row; `block` stretches it to the full width. */
|
|
export function buttonLayout(block: boolean | null | undefined) {
|
|
return {
|
|
display: block ? 'flex' : 'inline-flex',
|
|
alignItems: 'items-center',
|
|
justifyContent: 'justify-center',
|
|
gap: 'gap-2',
|
|
} as const satisfies FlexBoxOwnProps;
|
|
}
|
|
|
|
/** Props only NextLink understands. */
|
|
const LINK_ONLY_PROPS = new Set([
|
|
'href',
|
|
'as',
|
|
'replace',
|
|
'scroll',
|
|
'shallow',
|
|
'passHref',
|
|
'prefetch',
|
|
'locale',
|
|
'legacyBehavior',
|
|
'onNavigate',
|
|
'unstable_dynamicOnHover',
|
|
]);
|
|
|
|
/** A frozen or loading link renders a `<button>`, which must not receive NextLink's props. */
|
|
export function withoutLinkProps(props: object): ButtonElementProps {
|
|
return Object.fromEntries(
|
|
Object.entries(props).filter(([key]) => !LINK_ONLY_PROPS.has(key)),
|
|
) as ButtonElementProps;
|
|
}
|