UNPKG

@cerberus-design/react

Version:

The Cerberus Design React component library.

1 lines 331 kB
{"version":3,"sources":["../../src/index.ts","../../src/components/deprecated/FieldMessage.tsx","../../src/components/deprecated/FieldsetLabel.tsx","../../src/components/deprecated/Label.tsx","../../src/components/field/field.tsx","../../src/utils/localStorage.ts","../../src/utils/index.ts","../../src/components/show/show.tsx","../../src/components/field/primitives.tsx","../../src/system/primitive-factory.tsx","../../src/system/factory.ts","../../src/system/index.ts","../../src/components/field/start-indicator.tsx","../../src/components/field/status-indicator.tsx","../../src/context/cerberus.tsx","../../src/components/field/input.tsx","../../src/components/field/error-text.tsx","../../src/components/field/helper-text.tsx","../../src/components/field/parts.ts","../../src/components/deprecated/NavMenuTrigger.tsx","../../src/context/navMenu.tsx","../../src/components/deprecated/aria-helpers/nav-menu.aria.ts","../../src/components/deprecated/NavMenuList.tsx","../../src/components/deprecated/NavMenuLink.tsx","../../src/components/deprecated/Legend.tsx","../../src/hooks/useDate.ts","../../src/hooks/useToggle.ts","../../src/components/Droppable.tsx","../../src/components/admonition/primitives.tsx","../../src/components/admonition/parts.ts","../../src/components/admonition/match-avatar.tsx","../../src/components/avatar/primitives.tsx","../../src/components/avatar/parts.ts","../../src/components/avatar/avatar.tsx","../../src/components/admonition/admonition.tsx","../../src/components/accordion/primitives.tsx","../../src/components/accordion/parts.ts","../../src/components/accordion/item-indicator.tsx","../../src/components/accordion/item-group.tsx","../../src/components/avatar/index.ts","../../src/components/button/button.tsx","../../src/components/spinner/spinner.tsx","../../src/components/button/primitives.tsx","../../src/components/button/parts.ts","../../src/components/carousel/primitives.ts","../../src/components/carousel/parts.ts","../../src/components/for/for.tsx","../../src/components/carousel/carousel.tsx","../../src/components/text/text.tsx","../../src/components/checkbox/primitives.tsx","../../src/components/checkbox/parts.ts","../../src/components/checkbox/checkbox-icon.tsx","../../src/components/checkbox/checkbox.tsx","../../src/components/circular-progress/primitives.ts","../../src/components/circular-progress/circular-progress.tsx","../../src/components/combobox/primitives.tsx","../../src/components/combobox/parts.ts","../../src/components/portal/portal.tsx","../../src/components/combobox/combobox.tsx","../../src/components/combobox/item.tsx","../../src/components/combobox/item-group.tsx","../../src/components/combobox/use-stateful-collection.ts","../../src/components/select/primitives.tsx","../../src/components/cta-dialog/provider.tsx","../../src/components/dialog/primitives.tsx","../../src/components/dialog/parts.ts","../../src/components/icon-button/primitives.ts","../../src/components/icon-button/button.tsx","../../src/components/dialog/close-icon-trigger.tsx","../../src/components/dialog/dialog.tsx","../../src/components/cta-dialog/context.tsx","../../src/components/cta-dialog/trigger-item.tsx","../../src/components/cta-dialog/utils.ts","../../src/components/date-picker/primitives.tsx","../../src/components/date-picker/parts.ts","../../src/components/date-picker/date-picker.tsx","../../src/components/date-picker/trigger.tsx","../../src/components/date-picker/input.tsx","../../src/components/date-picker/range-input.tsx","../../src/components/date-picker/content.tsx","../../src/components/date-picker/view-control-group.tsx","../../src/components/date-picker/day-view.tsx","../../src/components/date-picker/month-view.tsx","../../src/components/date-picker/year-view.tsx","../../src/components/date-picker/calendar.tsx","../../src/components/date-picker/index.ts","../../src/context/feature-flags.tsx","../../src/components/feature-flag/feature-flag.tsx","../../src/components/fieldset/primitives.tsx","../../src/components/fieldset/parts.ts","../../src/components/fieldset/fieldset.tsx","../../src/components/file-upload/file-status.tsx","../../src/components/progress/primitives.ts","../../src/components/progress/progress-bar.tsx","../../src/components/file-upload/file-uploader.tsx","../../src/components/menu/primitives.ts","../../src/components/menu/menu.tsx","../../src/components/notifications/primitives.tsx","../../src/components/notifications/parts.ts","../../src/components/notifications/center.tsx","../../src/components/notifications/match-icon.tsx","../../src/components/notifications/close-trigger.tsx","../../src/components/radio/primitives.tsx","../../src/components/radio/parts.ts","../../src/components/radio/radio.tsx","../../src/components/rating/primitives.tsx","../../src/components/rating/parts.tsx","../../src/components/rating/rating.tsx","../../src/components/select/parts.ts","../../src/components/select/select.tsx","../../src/components/select/option.tsx","../../src/components/select/option-group.tsx","../../src/components/switch/primitives.tsx","../../src/components/switch/parts.ts","../../src/components/switch/switch-indicator.tsx","../../src/components/switch/switch.tsx","../../src/components/table/primitives.tsx","../../src/components/table/parts.ts","../../src/components/table/table.tsx","../../src/components/tabs/primitives.tsx","../../src/components/tabs/parts.ts","../../src/components/tabs/tabs.tsx","../../src/components/tag/tag.tsx","../../src/components/theme/theme.tsx","../../src/components/toggle/primitives.tsx","../../src/components/toggle/parts.ts","../../src/components/tooltip/primitives.ts","../../src/components/tooltip/parts.ts","../../src/components/tooltip/tooltip.tsx","../../src/context/confirm-modal.tsx","../../src/context/prompt-modal.tsx","../../src/context/theme.tsx","../../src/hooks/useTheme.ts","../../src/hooks/useRootColors.ts","../../src/config/icons/checkbox.icons.tsx","../../src/components/AnimatingUploadIcon.tsx","../../src/config/defineIcons.ts","../../src/config/index.ts"],"sourcesContent":["/**\n * This module is the entry point for the Cerberus React package.\n * @module\n */\n\n// deprecated\n\nexport * from './components/deprecated/FieldMessage'\nexport * from './components/deprecated/FieldsetLabel'\nexport * from './components/deprecated/Label'\nexport * from './components/deprecated/NavMenuTrigger'\nexport * from './components/deprecated/NavMenuList'\nexport * from './components/deprecated/NavMenuLink'\nexport * from './components/deprecated/Legend'\nexport * from './hooks/useDate'\nexport * from './hooks/useToggle'\nexport * from './components/Droppable'\n\n// components\n\nexport * from './components/admonition/index'\nexport * from './components/accordion/index'\nexport * from './components/avatar/index'\nexport * from './components/button/index'\nexport * from './components/carousel/index'\nexport * from './components/checkbox/index'\nexport * from './components/circular-progress/index'\nexport * from './components/combobox/index'\nexport * from './components/cta-dialog/index'\nexport * from './components/date-picker/index'\nexport * from './components/dialog/index'\nexport * from './components/feature-flag/index'\nexport * from './components/field/index'\nexport * from './components/fieldset/index'\nexport * from './components/file-upload/index'\nexport * from './components/for/index'\nexport * from './components/icon-button/index'\nexport * from './components/menu/index'\nexport * from './components/notifications/index'\nexport * from './components/portal/index'\nexport * from './components/progress/index'\nexport * from './components/radio/index'\nexport * from './components/rating/index'\nexport * from './components/select/index'\nexport * from './components/show/index'\nexport * from './components/spinner/index'\nexport * from './components/switch/index'\nexport * from './components/table/index'\nexport * from './components/tabs/index'\nexport * from './components/tag/index'\nexport * from './components/text/index'\nexport * from './components/theme/index'\nexport * from './components/toggle/index'\nexport * from './components/tooltip/index'\n\n// context\n\nexport * from './context/cerberus'\nexport * from './context/confirm-modal'\nexport * from './context/feature-flags'\nexport * from './context/navMenu'\nexport * from './context/prompt-modal'\nexport * from './context/theme'\n\n// hooks\n\nexport * from './hooks/useTheme'\nexport * from './hooks/useRootColors'\n\n// utils\n\nexport * from './config/index'\nexport * from './utils/index'\nexport * from './system/index'\n\n// shared types\n\nexport * from './types'\n\n// 3rd party\n\nexport * from '@dnd-kit/core'\n","'use client'\n\nimport type { HTMLAttributes } from 'react'\nimport { cx } from 'styled-system/css'\nimport {\n fieldMessage,\n type FieldMessageVariantProps,\n} from 'styled-system/recipes'\nimport { useFieldContext } from '@ark-ui/react/field'\n\n/**\n * This module contains the FieldMessage component.\n * @module\n */\nexport interface FieldMessageBaseProps\n extends HTMLAttributes<HTMLParagraphElement> {\n /**\n * The id of the FieldMessage element describing the field. Required for accessibility. It is considered best practice to use the `help` or `error` prefix to help screen readers identify the type of message.\n *\n * @example For help messages: `help:field_id`\n * @example For error messages: `error:field_id`\n */\n id: string\n}\nexport type FieldMessageProps = FieldMessageBaseProps & FieldMessageVariantProps\n\n/**\n * @deprecated use FieldHelperText, FieldErrorText, or FieldParts instead\n */\nexport function FieldMessage(props: FieldMessageProps) {\n const { invalid } = useFieldContext()\n return (\n <small\n {...props}\n {...(invalid && { 'aria-invalid': true })}\n className={cx(props.className, fieldMessage())}\n />\n )\n}\n","import { cx } from 'styled-system/css'\nimport { label, type LabelVariantProps } from 'styled-system/recipes'\nimport type { LabelProps } from './Label'\n\n/**\n * This module contains the FieldsetLabel component.\n * @module FieldsetLabel\n */\n\nexport type FieldsetLabelProps = LabelProps &\n LabelVariantProps & {\n htmlFor?: string\n }\n\n/**\n * @deprecated\n */\nexport function FieldsetLabel(props: FieldsetLabelProps) {\n const { size, usage, ...nativeProps } = props\n return (\n <label\n {...nativeProps}\n className={cx(\n nativeProps.className,\n label({\n size,\n usage,\n }),\n )}\n />\n )\n}\n","import type { HTMLAttributes, PropsWithChildren } from 'react'\nimport { label, type LabelVariantProps } from 'styled-system/recipes'\nimport { cx } from 'styled-system/css'\nimport { FieldLabel } from '../field'\n\n/**\n * This module contains the Label component.\n * @module\n */\nexport type LabelBaseProps = HTMLAttributes<HTMLLabelElement>\nexport type LabelProps = LabelBaseProps & LabelVariantProps\n\n/**\n * @deprecated Use FieldLabel or FieldParts.Label instead.\n */\nexport function Label(props: PropsWithChildren<LabelProps>) {\n const { size, ...nativeProps } = props\n return (\n <FieldLabel\n {...nativeProps}\n className={cx(label({ size }), props.className)}\n />\n )\n}\n","import { type FieldRootProps } from '@ark-ui/react/field'\nimport { HStack } from 'styled-system/jsx'\nimport { splitProps } from '../../utils/index'\nimport { Show } from '../show/index'\nimport {\n FieldErrorText,\n FieldHelperText,\n FieldLabel,\n FieldRoot,\n} from './primitives'\nimport { HelperText } from './helper-text'\n\nexport interface FieldProps extends FieldRootProps {\n /**\n * The label of the field.\n */\n label?: string\n /**\n * The helper text of the field.\n */\n helperText?: string\n /**\n * A helper text positioned at the end of the field. Good for Textarea fields.\n */\n secondaryHelperText?: string\n /**\n * The error text of the field. Shown when the field is invalid.\n */\n errorText?: string\n}\n\n/**\n * The Field component is the context provider for all FieldParts and displays\n * the label, helperText, and ErrorText.\n * @description [Field Docs](https://cerberus.digitalu.design/react/field)\n * @example\n * ```tsx\n * <Field\n * ids={{\n * control: 'firstName',\n * }}\n * label=\"Label\"\n * helperText=\"This is what people will see on your profile.\"\n * errorText=\"A first name is required to create an account.\"\n * required\n * >\n * <Input name=\"firstName\" type=\"text\" />\n * </Field>\n * ```\n */\nexport function Field(props: FieldProps) {\n const [statusProps, fieldProps, rootProps] = splitProps(\n props,\n ['disabled', 'required', 'readOnly', 'invalid'],\n ['label', 'helperText', 'secondaryHelperText', 'errorText', 'children'],\n )\n\n return (\n <FieldRoot {...statusProps} {...rootProps}>\n <Show when={fieldProps.label}>\n <FieldLabel>{fieldProps.label}</FieldLabel>\n </Show>\n\n {fieldProps.children}\n\n <HStack justifyContent=\"space-between\" w=\"full\">\n <HelperText invalid={statusProps.invalid}>\n {fieldProps.helperText}\n </HelperText>\n\n <FieldErrorText>{fieldProps.errorText}</FieldErrorText>\n\n <Show when={fieldProps.secondaryHelperText}>\n <FieldHelperText>{fieldProps.secondaryHelperText}</FieldHelperText>\n </Show>\n </HStack>\n </FieldRoot>\n )\n}\n","'use client'\n\n/**\n * A utility function to get a value from local storage.\n * @param key The key to get from local storage.\n * @param defaultValue The fallback value if the key is not found.\n * @returns key or defaultValue\n */\nexport function getLocalStorage<T extends string>(\n key: string,\n defaultValue: T,\n): T {\n const value = window.localStorage.getItem(key)\n if (value) {\n return value as T\n }\n return defaultValue\n}\n\n/**\n * A utility function to set a value in local storage.\n * @param key The key to set in local storage.\n * @param value The value to set in local storage.\n */\nexport function setLocalStorage<T>(key: string, value: T): void {\n const stringValue = typeof value === 'string' ? value : JSON.stringify(value)\n window.localStorage.setItem(key, stringValue)\n}\n","/**\n * This module contains utility functions that are used across your app.\n * @module Utils\n */\n\n/**\n * Formats the count of notifications to be displayed in the notification badge.\n * @param count - The number of notifications.\n * @returns The formatted count of notifications.\n * @example\n * ```tsx\n * const count = formatNotifyCount(100)\n * console.log(count) // '99+'\n * ```\n */\nexport function formatNotifyCount(count: number): string {\n if (count > 99) return '99+'\n return count.toString()\n}\n\n/**\n * Splits the properties of an object into multiple groups based on lists of keys.\n * @param props - The object to split.\n * @param keyGroups - The lists of keys to include in each group.\n * @returns An array of objects: each containing the properties specified in the corresponding key group, and the last object containing the remaining keys.\n */\nexport function splitProps<T extends object>(\n props: T,\n ...keyGroups: (keyof T)[][]\n): { [K in keyof T]?: T[K] }[] {\n const result = keyGroups.map(() => ({}) as { [K in keyof T]?: T[K] })\n const rest = {} as { [K in keyof T]?: T[K] }\n\n for (const key in props) {\n let assigned = false\n for (let i = 0; i < keyGroups.length; i++) {\n if (keyGroups[i].includes(key as keyof T)) {\n result[i][key as keyof T] = props[key]\n assigned = true\n break\n }\n }\n if (!assigned) {\n rest[key as keyof T] = props[key]\n }\n }\n\n return [...result, rest]\n}\n\nexport * from './localStorage'\n","import { type PropsWithChildren, type ReactNode } from 'react'\n\n/**\n * This module contains the Show component.\n * @module\n */\n\nexport interface ShowProps<T> {\n /**\n * The condition to render memoized children or the fallback content.\n */\n when: T | boolean | null | undefined\n /**\n * The children to render when the condition is false.\n */\n fallback?: ReactNode\n}\n\n/**\n * Conditionally render a memoized version of the children or optional fallback\n * content.\n * @see https://cerberus.digitalu.design/react/show\n * @example\n * ```tsx\n * <Show when={isLoggedIn} fallback={<Navigate to=\"/login\" />}>\n * <Dashboard />\n * </Show>\n */\nexport function Show<T>(props: PropsWithChildren<ShowProps<T>>) {\n const { when, children, fallback } = props\n\n if (when) {\n return <>{children}</>\n }\n\n if (fallback) {\n return <>{fallback}</>\n }\n\n return null\n}\n","import {\n Field,\n type FieldHelperTextProps as ArkFieldHelperTextProps,\n type FieldInputProps as ArkFieldInputProps,\n type FieldLabelProps as ArkFieldLabelProps,\n type FieldRootProps as ArkFieldRootProps,\n type FieldTextareaProps as ArkFieldTextareaProps,\n type FieldRequiredIndicatorProps as ArkFieldRequiredIndicatorProps,\n} from '@ark-ui/react/field'\nimport { ark, type HTMLArkProps } from '@ark-ui/react'\nimport { field, type FieldVariantProps } from 'styled-system/recipes'\nimport {\n createCerberusPrimitive,\n type CerberusPrimitiveProps,\n} from '../../system/index'\nimport { CerberusFieldInput } from './input'\nimport { CerberusFieldErrorText } from './error-text'\n\n/**\n * This module contains all the primitives of the Field component.\n * @module 'field'\n */\n\nconst { withSlotRecipe, withNoRecipe } = createCerberusPrimitive(field)\n\n// Root\n\nexport type FieldRootProps = CerberusPrimitiveProps<\n ArkFieldRootProps & FieldVariantProps\n>\nexport const FieldRoot = withSlotRecipe<FieldRootProps>(Field.Root, 'root')\n\n// Label\n\nfunction FieldLabelEl(props: FieldLabelProps) {\n const { children, ...nativeProps } = props\n return (\n <Field.Label {...nativeProps}>\n {children}\n <Field.RequiredIndicator>(required)</Field.RequiredIndicator>\n </Field.Label>\n )\n}\n\nexport type FieldLabelProps = CerberusPrimitiveProps<ArkFieldLabelProps>\nexport const FieldLabel = withSlotRecipe<FieldLabelProps>(FieldLabelEl, 'label')\n\n// Required Indicator\n\nfunction FieldRequiredIndicatorEl(props: FieldRequiredIndicatorProps) {\n return (\n <Field.RequiredIndicator {...props}>(required)</Field.RequiredIndicator>\n )\n}\n\nexport type FieldRequiredIndicatorProps =\n CerberusPrimitiveProps<ArkFieldRequiredIndicatorProps>\nexport const FieldRequiredIndicator = withNoRecipe<FieldRequiredIndicatorProps>(\n FieldRequiredIndicatorEl,\n)\n\n// Input\n\nexport type FieldInputRootProps = CerberusPrimitiveProps<\n HTMLArkProps<'div'> & FieldVariantProps\n>\nexport const FieldInputRoot = withSlotRecipe<FieldInputRootProps>(\n ark.div,\n 'inputRoot',\n)\n\nexport type FieldInputProps = CerberusPrimitiveProps<\n ArkFieldInputProps & FieldVariantProps\n>\nexport const FieldInput = withSlotRecipe<FieldInputProps>(Field.Input, 'input')\n\n// Helper Text\n\nexport type FieldHelperTextProps =\n CerberusPrimitiveProps<ArkFieldHelperTextProps>\nexport const FieldHelperText = withSlotRecipe<FieldHelperTextProps>(\n Field.HelperText,\n 'helperText',\n)\n\n// Error Text\n\nexport type FieldErrorTextProps =\n CerberusPrimitiveProps<ArkFieldHelperTextProps>\nexport const FieldErrorText = withSlotRecipe<FieldErrorTextProps>(\n CerberusFieldErrorText,\n 'errorText',\n)\n\n// Textarea\n\nexport type FieldTextareaProps = CerberusPrimitiveProps<ArkFieldTextareaProps>\nexport const FieldTextarea = withSlotRecipe<FieldTextareaProps>(\n Field.Textarea,\n 'textarea',\n)\n\n/**\n * A named export for the FieldInput component.\n * @description [Field Docs](https://cerberus.digitalu.design/react/field)\n * @example\n * ```tsx\n * import { Input } from '@cerberus/react'\n *\n * <Field\n * label=\"Enter your email\"\n * helperText=\"We'll never share your email with anyone else.\"\n * errorText=\"Email is required.\"\n * required\n * >\n * <Input type=\"email\" />\n * </Field>\n * ```\n */\nexport const Input = CerberusFieldInput\n\n/**\n * A named export for the FieldTextarea component.\n * @description [Field Docs](https://cerberus.digitalu.design/react/field)\n * @example\n * ```tsx\n * import { Textarea } from '@cerberus/react'\n *\n * <Field\n * label=\"Comments\"\n * helperText=\"Your comments are valuable to us.\"\n * >\n * <Textarea />\n * </Field>\n * ```\n */\nexport const Textarea = FieldTextarea\n","import { css, cx } from 'styled-system/css'\nimport type { RecipeVariantRecord } from 'styled-system/types'\nimport {\n type ComponentType,\n type ElementType,\n type HTMLAttributes,\n type PropsWithChildren,\n} from 'react'\nimport type { WithCss } from '../types'\nimport type {\n CerberusPrimitiveEl,\n CerberusPrimitiveRecipe,\n CerberusRecipe,\n CerberusSlotRecipe,\n WithRecipeOptions,\n} from './types'\n\n/**\n * This module contains a factory for creating Cerberus primitives.\n * @module @cerberus/core/system/factory\n */\n\nexport class CerberusPrimitive {\n recipe: CerberusPrimitiveRecipe | null\n\n constructor(recipe?: CerberusPrimitiveRecipe) {\n this.recipe = recipe ?? null\n }\n\n private hasStyles(styles: string | undefined): Record<string, unknown> {\n if (styles) {\n return {\n className: styles,\n }\n }\n return {}\n }\n\n private validateComponent<P extends HTMLAttributes<unknown>>(\n Component: ComponentType<P> | string,\n ) {\n if (typeof Component !== 'function' && typeof Component !== 'object') {\n return false\n }\n return true\n }\n\n /**\n * Creates a Cerberus component with bare features and no recipe.\n * @param Component - The React component to enhance with Cerberus features.\n * Can be a string or a component reference.\n * @returns A new React component that applies Cerberus features to the\n * original component.\n *\n * @example\n * ```ts\n * const { withNoRecipe } = createCerberusPrimitive(buttonRecipe)\n * const Button = withNoRecipe('button')\n * ```\n */\n withNoRecipe = <P extends HTMLAttributes<unknown>>(\n Component: ComponentType<P> | string,\n options?: WithRecipeOptions,\n ): CerberusPrimitiveEl<P> => {\n const { defaultProps } = options || {}\n const El = Component as ComponentType<P> | ElementType\n\n const CerbComponent = (props: PropsWithChildren<P> & WithCss) => {\n const { css: customCss, className, ...nativeProps } = props\n const styles = this.hasStyles(cx(className, css(customCss)))\n return <El {...defaultProps} {...styles} {...(nativeProps as P)} />\n }\n\n if (this.validateComponent(El)) {\n const ElName = typeof El === 'string' ? El : El.displayName || El.name\n CerbComponent.displayName = ElName\n }\n\n return CerbComponent\n }\n\n /**\n * Creates a Cerberus component with the given recipe.\n * @param Component - The React component to enhance with the recipe.\n * @param options - Options for the recipe.\n * @returns A new React component that applies the recipe to the original\n * component.\n */\n withRecipe = <P extends HTMLAttributes<unknown>>(\n Component: ComponentType<P> | string,\n options?: WithRecipeOptions,\n ): CerberusPrimitiveEl<P & WithRecipeOptions['defaultProps']> => {\n const { defaultProps } = options || {}\n const El = Component as ComponentType<P> | ElementType\n\n const recipe = this.recipe as CerberusRecipe\n\n const CerbComponent = (internalProps: PropsWithChildren<P> & WithCss) => {\n const {\n css: customCss,\n className,\n ...restOfInternalProps\n } = internalProps\n\n const [variantOptions, nativeProps] =\n recipe.splitVariantProps(restOfInternalProps)\n const recipeStyles = recipe(variantOptions)\n\n return (\n <Component\n {...defaultProps}\n {...(nativeProps as P)}\n className={cx(className, recipeStyles, css(customCss))}\n />\n )\n }\n\n if (this.validateComponent(El)) {\n const ElName = typeof El === 'string' ? El : El.displayName || El.name\n CerbComponent.displayName = ElName\n }\n\n return CerbComponent\n }\n\n /**\n * Creates a Cerberus component with a slot recipe applied.\n * @param Component - The React component to enhance with Cerberus features.\n * @param recipe - The slot recipe to apply to the component.\n * @returns A new React component that applies Cerberus features and the\n * specified slot recipe to the original component.\n * @example\n * ```typescript\n * const { withSlotRecipe } = createCerberusPrimitive(field)\n * const Field = withSlotRecipe(RawField, field)\n * ```\n */\n withSlotRecipe = <P extends HTMLAttributes<unknown>>(\n Component: ComponentType<P> | string,\n slot: keyof RecipeVariantRecord,\n options?: WithRecipeOptions,\n ) => {\n const { defaultProps } = options || {}\n const El = Component as ComponentType<P> | ElementType\n\n const recipe = this.recipe as CerberusSlotRecipe<typeof slot>\n\n const CerbComponent = (internalProps: PropsWithChildren<P> & WithCss) => {\n const {\n css: customCss,\n className,\n ...restOfInternalProps\n } = internalProps\n\n const [variantOptions, nativeProps] =\n recipe.splitVariantProps(restOfInternalProps)\n const styles = recipe(variantOptions)\n const slotStyles = styles[slot as keyof typeof styles]\n\n return (\n <Component\n {...defaultProps}\n {...(nativeProps as P)}\n className={cx(className, slotStyles, css(customCss))}\n />\n )\n }\n\n if (this.validateComponent(El)) {\n const ElName = typeof El === 'string' ? El : El.displayName || El.name\n CerbComponent.displayName = ElName\n }\n\n return CerbComponent\n }\n}\n","import { ark } from '@ark-ui/react/factory'\nimport type { ComponentType } from 'react'\nimport { CerberusPrimitive } from './primitive-factory'\n\nfunction cerberusFactory<T extends Record<string, unknown>>(\n component: keyof typeof ark,\n defaultProps?: T,\n) {\n const { withNoRecipe } = new CerberusPrimitive()\n const arkComponent = ark[component] as ComponentType\n\n if (arkComponent) {\n return withNoRecipe(arkComponent, { defaultProps: defaultProps ?? {} })\n }\n\n throw new Error(\n `Component \"${String(component)}\" is not a valid Cerberus component. Please check the component name.`,\n )\n}\n\nconst cache = new Map()\n\n// Create a proxy that handles both function calls and property access\nexport const cerberusFactoryProxy = new Proxy(cerberusFactory, {\n apply(target, thisArg, argArray) {\n // Handle function calls like cerberus('button')\n // @ts-expect-error: Ignore type error for dynamic property access\n return target.apply(thisArg, argArray)\n },\n get(_target, el: keyof typeof ark) {\n // Handle property access like cerberus.button\n if (!cache.has(el)) {\n cache.set(el, cerberusFactory(el))\n }\n return cache.get(el) as ReturnType<typeof cerberusFactory>\n },\n})\n","import { CerberusPrimitive } from './primitive-factory'\nimport type { CerberusFactory, CerberusPrimitiveRecipe } from './types'\nimport { cerberusFactoryProxy } from './factory'\n\n/**\n * This module contains the user interface for creating Cerberus primitives.\n * @module @cerberus/core/system/create-cerb-primitive\n */\n\n/**\n * A factory function that creates a Cerberus primitive instance with the given\n * recipe.\n * @param recipe\n * @returns An object with three methods: `withNoRecipe`, `withRecipe`, and `withSlotRecipe` that\n * apply the recipes and special Cerberus helpers like `css`.\n *\n * @example\n * ```tsx\n * const { withRecipe } = createCerberusPrimitive(myCustomRecipe);\n * export const Button = withRecipe(MyCustomButton)\n * ```\n */\nexport function createCerberusPrimitive<T extends CerberusPrimitiveRecipe>(\n recipe?: T,\n) {\n return new CerberusPrimitive(recipe)\n}\n\n/**\n * A utility function to access Cerberus components by their name.\n * @param component - The name of the Cerberus component to access.\n * @returns The Cerberus component corresponding to the provided name.\n * @throws An error if the component name is not valid.\n *\n * @example\n * ```tsx\n * import { cerberus } from '@cerberus/react'\n * const Button = cerberus('button')\n *\n * <Button css={{ color: 'blue' }} asChild>\n * <Link href=\"/some-page\">Click me</Link>\n * </Button>\n * ```\n */\nexport const cerberus = cerberusFactoryProxy as CerberusFactory\n\nexport * from './types'\n","import { cx } from 'styled-system/css'\nimport { field } from 'styled-system/recipes'\nimport type { HTMLAttributes } from 'react'\n\nexport type FieldIndicatorProps = HTMLAttributes<HTMLSpanElement>\n\n/**\n * The start indicator displays an indicator at the start of the Input.\n * @description [Field Docs](https://cerberus.digitalu.design/react/field)\n */\nexport function FieldStartIndicator(props: FieldIndicatorProps) {\n const styles = field()\n\n if (!props.children) return null\n\n return (\n <span\n {...props}\n data-part=\"start-indicator\"\n className={cx(props.className, styles.startIndicator)}\n />\n )\n}\n","'use client'\n\nimport { useFieldContext } from '@ark-ui/react'\nimport { cx } from 'styled-system/css'\nimport { field } from 'styled-system/recipes'\nimport { useCerberusContext } from '../../context/cerberus'\nimport type { HTMLAttributes, ReactNode } from 'react'\n\nexport interface FieldStatusIndicatorProps\n extends HTMLAttributes<HTMLSpanElement> {\n /**\n * The fallback content to display when the field is valid.\n */\n fallback?: ReactNode\n}\n\n/**\n * The invalid status indicator for the Field component.\n * @description [Field Docs](https://cerberus.digitalu.design/react/field)\n * @example\n * ```tsx\n * <FieldRoot>\n * <FieldStatusIndicator />\n * </FieldRoot>\n * ```\n */\nexport function FieldStatusIndicator(props: FieldStatusIndicatorProps) {\n const { fallback, ...nativeProps } = props\n\n const fieldContext = useFieldContext()\n const styles = field()\n\n const { icons } = useCerberusContext()\n const { invalid: InvalidIcon } = icons\n\n if (!fieldContext) return null\n\n if (fieldContext.invalid) {\n return (\n <span\n {...nativeProps}\n aria-hidden=\"true\"\n data-invalid\n className={cx(nativeProps.className, styles.statusIndicator)}\n >\n <InvalidIcon />\n </span>\n )\n }\n\n return (\n <span\n {...nativeProps}\n aria-hidden=\"true\"\n data-part=\"end-indicator\"\n className={cx(nativeProps.className, styles.endIndicator)}\n >\n {fallback}\n </span>\n )\n}\n","'use client'\n\nimport { createContext, useContext, type PropsWithChildren } from 'react'\nimport type { SystemConfig } from '../config'\n\n/**\n * This module contains the Cerberus configuration context and helpers.\n * @module context/cerberus\n */\n\ntype CerberusContextValue = SystemConfig\n\nconst CerberusContext = createContext<CerberusContextValue | null>(null)\n\ninterface CerberusProviderProps {\n config: SystemConfig\n}\n\n/**\n * Cerberus configuration provider.\n * @param props.config The Cerberus configuration created with\n * `makeSystemConfig` helper.\n */\nexport function CerberusProvider(\n props: PropsWithChildren<CerberusProviderProps>,\n) {\n return (\n <CerberusContext.Provider value={props.config}>\n {props.children}\n </CerberusContext.Provider>\n )\n}\n\n/**\n * Returns the Cerberus configuration context.\n * @returns The Cerberus configuration context.\n */\nexport function useCerberusContext() {\n const context = useContext(CerberusContext)\n if (!context) {\n throw new Error('useCerberus must be used within a CerberusProvider')\n }\n return context\n}\n","import type { ReactNode } from 'react'\nimport type { FieldVariantProps } from 'styled-system/recipes'\nimport { FieldStartIndicator } from './start-indicator'\nimport { FieldStatusIndicator } from './status-indicator'\nimport {\n FieldInputRoot,\n FieldInput as PrimitiveInput,\n type FieldInputProps as PrimitiveInputProps,\n} from './primitives'\nimport { splitProps } from '../../utils/index'\n\n/**\n * This module contains an abstraction of the Field.Input component.\n * @module 'field/input'\n */\n\nexport interface FieldInputElProps\n extends Omit<PrimitiveInputProps, 'size'>,\n FieldVariantProps {\n /**\n * An optional icon to display at the start of the input.\n */\n startIcon?: ReactNode\n /**\n * An optional icon to display at the end of the input.\n */\n endIcon?: ReactNode\n}\n\nexport function CerberusFieldInput(props: FieldInputElProps) {\n const [{ startIcon, endIcon }, fieldProps] = splitProps(props, [\n 'startIcon',\n 'endIcon',\n ])\n const hasStartIcon = Boolean(startIcon)\n\n return (\n <FieldInputRoot>\n <FieldStartIndicator>{startIcon}</FieldStartIndicator>\n <PrimitiveInput\n {...(fieldProps as Omit<FieldInputElProps, 'size'>)}\n {...(hasStartIcon && { 'data-has': 'start-indicator' })}\n />\n <FieldStatusIndicator fallback={endIcon} />\n </FieldInputRoot>\n )\n}\n","import { Field } from '@ark-ui/react/field'\nimport type { FieldErrorTextProps } from './primitives'\n\n/**\n * The error text for the Field component that is shown when the field is\n * invalid.\n * @description [Field Docs](https://cerberus.digitalu.design/react/field)\n * @example\n * ```tsx\n * <FieldRoot>\n * <FieldInput />\n * <FieldErrorText>Error text</FieldErrorText>\n * </FieldRoot>\n * ```\n */\nexport function CerberusFieldErrorText(props: FieldErrorTextProps) {\n if (!props.children) return null\n return <Field.ErrorText {...props} />\n}\n","import type { PropsWithChildren } from 'react'\nimport { FieldHelperText } from './primitives'\n\ninterface HelperTextProps {\n invalid?: boolean\n}\n\n/**\n * The HelperText component is an abstraction for hiding the helper text\n * when the field is invalid. Ark UI assumes people want the helper text\n * to always be visible, so this is a workaround for that.\n */\nexport function HelperText(props: PropsWithChildren<HelperTextProps>) {\n if (props.invalid) return null\n return (\n <FieldHelperText data-has-content={Boolean(props.children)}>\n {props.children}\n </FieldHelperText>\n )\n}\n","import type { ElementType } from 'react'\nimport {\n FieldErrorText,\n FieldHelperText,\n FieldInput,\n FieldLabel,\n FieldRequiredIndicator,\n FieldRoot,\n FieldTextarea,\n} from './primitives'\nimport { FieldStatusIndicator } from './status-indicator'\nimport { FieldStartIndicator } from './start-indicator'\n\n/**\n * This module contains the parts of the Field component.\n * @module 'field/parts'\n */\n\ninterface FieldPartsValue {\n /**\n * The container of the field.\n */\n Root: ElementType\n /**\n * The label of the field.\n */\n Label: ElementType\n /**\n * The input of the field.\n */\n Input: ElementType\n /**\n * The textarea of the field.\n */\n Textarea: ElementType\n /**\n * The text that displays when the field is valid.\n */\n HelperText: ElementType\n /**\n * The text that displays when the field is invalid.\n */\n ErrorText: ElementType\n /**\n * The indicator that appears at the start of the field.\n */\n StartIndicator: ElementType\n /**\n * The status indicator of the field.\n */\n StatusIndicator: ElementType\n /**\n * The indicator that appears at the end of the field.\n */\n RequiredIndicator: ElementType\n}\n\n/**\n * An Object containing the parts of the Field component. For users that\n * prefer Object component syntax.\n *\n * @remarks\n *\n * When using object component syntax, you import the FieldParts object and\n * the entire family of components vs. only what you use.\n */\nexport const FieldParts: FieldPartsValue = {\n Root: FieldRoot,\n Label: FieldLabel,\n Input: FieldInput,\n Textarea: FieldTextarea,\n HelperText: FieldHelperText,\n ErrorText: FieldErrorText,\n StartIndicator: FieldStartIndicator,\n StatusIndicator: FieldStatusIndicator,\n RequiredIndicator: FieldRequiredIndicator,\n}\n","'use client'\n\nimport {\n useCallback,\n type ButtonHTMLAttributes,\n type ElementType,\n type MouseEvent,\n} from 'react'\nimport { cx } from 'styled-system/css'\nimport { button, type ButtonVariantProps } from 'styled-system/recipes'\nimport { useNavMenuContext } from '../../context/navMenu'\nimport { Show } from '../show/index'\nimport {\n createNavTriggerProps,\n type NavTriggerAriaValues,\n} from './aria-helpers/nav-menu.aria'\n\n/**\n * This module contains the NavMenuTrigger component.\n * @module\n */\n\nexport interface NavMenuTriggerProps\n extends ButtonHTMLAttributes<HTMLButtonElement>,\n ButtonVariantProps,\n NavTriggerAriaValues {\n /**\n * The element type to render as. Recommended to use for an IconButton trigger vs a standard Button.\n * @default 'button'\n * @example\n * ```tsx\n * <NavMenuTrigger as={IconButton} href=\"/home\" />\n * ```\n */\n as?: ElementType\n}\n\n/**\n * @deprecated use the {@link Menu} family instead\n */\nexport function NavMenuTrigger(props: NavMenuTriggerProps) {\n const {\n as,\n palette,\n usage,\n shape,\n controls,\n expanded: propsExpanded,\n onClick,\n ...nativeProps\n } = props\n const { triggerRef, onToggle, expanded } = useNavMenuContext()\n const ariaProps = createNavTriggerProps({\n controls,\n expanded: propsExpanded ?? expanded,\n })\n const hasAs = Boolean(as)\n const AsSub: ElementType = as!\n\n const handleClick = useCallback(\n (e: MouseEvent<HTMLButtonElement>) => {\n if (onClick) return onClick(e)\n onToggle()\n },\n [onClick, onToggle],\n )\n\n return (\n <Show\n when={hasAs}\n fallback={\n <button\n {...nativeProps}\n {...ariaProps}\n className={cx(\n nativeProps.className,\n button({\n palette,\n usage,\n shape,\n }),\n )}\n onClick={handleClick}\n ref={triggerRef}\n >\n {props.children}\n </button>\n }\n >\n {hasAs && (\n <AsSub\n {...nativeProps}\n {...ariaProps}\n onClick={handleClick}\n ref={triggerRef}\n />\n )}\n </Show>\n )\n}\n","'use client'\n\nimport { css } from 'styled-system/css'\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n type PropsWithChildren,\n type RefObject,\n} from 'react'\n\n/**\n * This module provides a context and hook for the nav menu.\n * @module NavMenu\n */\n\nexport type NavTriggerRef = RefObject<HTMLButtonElement | null>\nexport type NavMenuRef = RefObject<HTMLUListElement | null>\n\nexport interface NavMenuContextValue {\n /**\n * The ref for the trigger button.\n */\n triggerRef: NavTriggerRef\n /**\n * The ref for the menu.\n */\n menuRef: NavMenuRef\n /**\n * Whether the menu is expanded.\n */\n expanded: boolean\n /**\n * Called when the menu button is clicked.\n */\n onToggle: () => void\n}\n\nconst NavMenuContext = createContext<NavMenuContextValue | null>(null)\n\n/**\n * @deprecated use the {@link Menu} family instead\n */\nexport function NavMenu(props: PropsWithChildren) {\n const triggerRef = useRef<HTMLButtonElement | null>(null)\n const menuRef = useRef<HTMLUListElement | null>(null)\n const [expanded, setExpanded] = useState<boolean>(false)\n\n const handleToggle = useCallback(() => {\n setExpanded((prev) => !prev)\n }, [])\n\n const value = useMemo(\n () => ({\n triggerRef,\n menuRef,\n expanded,\n onToggle: handleToggle,\n }),\n [expanded, handleToggle],\n )\n\n return (\n <NavMenuContext.Provider value={value}>\n <nav\n className={css({\n position: 'relative',\n })}\n >\n {props.children}\n </nav>\n </NavMenuContext.Provider>\n )\n}\n\n/**\n * Used to access the nav menu context.\n * @returns The nav menu context.\n */\nexport function useNavMenuContext(): NavMenuContextValue {\n const context = useContext(NavMenuContext)\n if (!context) {\n throw new Error('useNavMenuContext must be used within a NavMenu.')\n }\n return context\n}\n","export interface NavTriggerAriaValues {\n controls: string\n expanded?: boolean\n}\n\ninterface NavTriggerAriaReturn {\n ['aria-controls']: string\n ['aria-expanded']: boolean\n}\n\n/**\n * @deprecated will be removed in a future release\n */\nexport function createNavTriggerProps(\n values: NavTriggerAriaValues,\n): NavTriggerAriaReturn {\n return {\n ['aria-controls']: values.controls,\n ['aria-expanded']: values.expanded ?? false,\n }\n}\n","'use client'\n\nimport { useMemo, type HTMLAttributes } from 'react'\nimport { cx } from 'styled-system/css'\nimport { vstack } from 'styled-system/patterns'\nimport { useNavMenuContext } from '../../context/navMenu'\nimport type { Positions } from '../../types'\nimport { Show } from '../show/index'\n\n/**\n * This module contains the NavMenuList component.\n * @module\n */\n\ninterface GetPositionResult {\n /**\n * The left position of the element.\n */\n left: string\n /**\n * The right position of the element.\n */\n right: string\n /**\n * The top position of the element.\n */\n top: string\n /**\n * The bottom position of the element.\n */\n bottom: string\n}\n\n/**\n * @deprecated use the {@link Menu} family instead\n */\nexport function getPosition(position: Positions): GetPositionResult {\n const defaultPositions = {\n left: 'auto',\n right: 'auto',\n top: 'auto',\n bottom: 'auto',\n }\n switch (position) {\n case 'right':\n return { ...defaultPositions, top: '0%', left: '105%' }\n case 'left':\n return { ...defaultPositions, top: '0%', right: '105%' }\n case 'bottom':\n return { ...defaultPositions, top: '110%' }\n case 'top':\n return { ...defaultPositions, bottom: '110%' }\n default:\n return defaultPositions\n }\n}\n\nconst navListStyles = vstack({\n alignItems: 'flex-start',\n bgColor: 'page.surface.100',\n boxShadow: 'lg',\n gap: '2',\n opacity: '0',\n p: '4',\n position: 'absolute',\n rounded: 'md',\n zIndex: 'dropdown',\n _motionSafe: {\n animationName: 'zoomIn',\n animationDelay: '100ms',\n animationDuration: '150ms',\n animationFillMode: 'both',\n animationTimingFunction: 'ease-in-out',\n },\n _positionBottom: {\n transformOrigin: 'top left',\n },\n _positionTop: {\n transformOrigin: 'bottom left',\n },\n _positionLeft: {\n transformOrigin: 'top right',\n },\n _positionRight: {\n transformOrigin: 'top left',\n },\n})\n\nexport interface NavMenuListProps extends HTMLAttributes<HTMLUListElement> {\n /**\n * The unique identifier for the NavMenuList. Required for accessibility.\n */\n id: string\n /**\n * The position of the NavMenuList.\n * @type 'top' | 'right' | 'bottom' | 'left'\n * @default 'bottom'\n */\n position?: Positions\n}\n\n/**\n * A component that allows the user to display a menu of navigation links.\n * @definition [Disclosure Nav](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/examples/disclosure-navigation/)\n * @see https://cerberus.digitalu.design/react/nav-menu\n *\n * @example\n * ```tsx\n * <NavMenu>\n * <NavMenuList id=\"nav-menu-list\" position=\"bottom\">\n * <NavMenuLink href=\"/home\">Home</NavMenuLink>\n * <NavMenuLink href=\"/about\">About</NavMenuLink>\n * </NavMenuList>\n * </NavMenu>\n * ```\n **/\nexport function NavMenuList(props: NavMenuListProps) {\n const { position, ...nativeProps } = props\n const { menuRef, expanded } = useNavMenuContext()\n const locationStyles = useMemo(\n () => getPosition(position ?? 'bottom'),\n [position],\n )\n\n return (\n <Show when={expanded}>\n <ul\n {...nativeProps}\n data-position={position ?? 'bottom'}\n className={cx(nativeProps.className, navListStyles)}\n ref={menuRef}\n style={locationStyles}\n />\n </Show>\n )\n}\n","import type { AnchorHTMLAttributes, ElementType } from 'react'\nimport { css, cx } from 'styled-system/css'\nimport { Show } from '../show/index'\n\n/**\n * This module contains the NavMenuLink component.\n * @module\n */\n\nexport interface NavMenuLinkProps\n extends AnchorHTMLAttributes<HTMLAnchorElement> {\n /**\n * The element type to render as. Recommended to use for Next apps with the\n * `Link` component.\n */\n as?: ElementType\n}\n\n/**\n * @deprecated use the {@link Menu} family instead\n */\nexport function NavMenuLink(props: NavMenuLinkProps) {\n const { as, ...nativeProps } = props\n const hasAs = Boolean(as)\n const AsSub: ElementType = as!\n\n return (\n <li\n className={css({\n w: 'full',\n })}\n >\n <Show\n when={hasAs}\n fallback={\n <a\n {...nativeProps}\n className={cx(\n nativeProps.className,\n css({\n color: 'action.navigation.initial',\n textStyle: 'link',\n _hover: {\n color: 'action.navigation.hover',\n },\n }),\n )}\n />\n }\n >\n {hasAs && <AsSub {...nativeProps} />}\n </Show>\n </li>\n )\n}\n","'use client'\n\nimport { useFieldContext } from '@ark-ui/react/field'\nimport { css, cx } from 'styled-system/css'\nimport { label, type LabelVariantProps } from 'styled-system/recipes'\nimport { hstack } from 'styled-system/patterns'\nimport { type HTMLAttributes } from 'react'\nimport { Show } from '../show/index'\n\n/**\n * This module contains the Fieldset component.\n * @module Fieldset\n */\n\nexport type LegendProps = HTMLAttributes<HTMLLegendElement> & LabelVariantProps\n\n/**\n * @deprecated use Fieldset instead\n */\nexport function Legend(props: LegendProps) {\n const { size, ...nativeProps } = props\n const { invalid, required } = useFieldContext()\n\n return (\n <legend\n {...nativeProps}\n {...(invalid && { 'aria-invalid': true })}\n className={cx(\n nativeProps.className,\n hstack({\n justify: 'space-between',\n w: 'full',\n }),\n label({\n size,\n }),\n )}\n >\n {nativeProps.children}\n <Show when={required}>\n <span\n className={css({\n color: 'page.text.100',\n fontSize: 'inherit',\n })}\n >\n (required)\n </span>\n </Show>\n </legend>\n )\n}\n","'use client'\n\nimport {\n useState,\n useCallback,\n ChangeEvent,\n useMemo,\n type InputHTMLAttributes,\n} from 'react'\n\nexport interface UseDateBase {\n /**\n * The format of the date input\n */\n format?: string\n /**\n * The callback to run when the date input changes\n */\n onChange?: InputHTMLAttributes<HTMLInputElement>['onChange']\n}\n\nexport interface UseDateOptions extends UseDateBase {\n /**\n * The initial value of the date input\n */\n initialValue?: string\n}\n\nexport interface UseDateReturn extends UseDateBase {\n /**\n * The ISO formatted date string\n */\n ISO: string\n /**\n * The value of the date input\n */\n value: string\n}\n\n/**\n * @deprecated use the DatePicker family instead\n */\nexport function useDate(options?: UseDateOptions): UseDateReturn {\n const initialValue = options?.initialValue ?? ''\n const format = options?.format ?? DateFormats.USMilitary\n const onChange = options?.onChange\n const [value, setValue] = useState(initialValue)\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n const newValue = formatMilitaryDate(e.currentTarget.value)\n if (onChange) onChange(e)\n setValue(newValue)\n },\n [onChange],\n )\n\n return useMemo(\n () => ({\n format,\n value,\n ISO: formatMilitaryToISO(value),\n onChange: handleChange,\n }),\n [format, value, handleChange],\n )\n}\n\n// helpers\n\n/**\n * Converts a string in US Military format to ISO format. Used within the `useDate` hook.\n * @param input The string to format\n * @returns The formatted string in ISO format (YYYY-MM-DD)\n */\nexport function formatMilitaryToISO(input: string) {\n const [day, month, year] = input.split(' ')\n const monthIndex = MONTHS.findIndex((m) => m.startsWith(month))\n const monthNum = monthIndex + 1\n return `${year ?? '0000'}-${monthNum.toString().padStart(2, '0')}-${day.padStart(\n 2,\n '0',\n )}`\n}\n\n/**\n * Converts a string to US Military format. Used within the `useDate` hook.\n * @param input The string to format\n * @returns The formatted string in US Military format (DD MMM YYYY)\n */\nexport function formatMilitaryDate(input: string): string {\n let formatted = input.toUpperCase().replace(/[^0-9A-Z]/g, '')\n let day = ''\n let month = ''\n let year = ''\n\n // Format day\n if (formatted.length >= 2) {\n day = formatted.replace(/[^0-9]/g, '').slice(0, 2)\n const dayNum = parseInt(day, 10)\n if (dayNum > 31) day = '31'\n else if (dayNum === 0) day = '01'\n formatted = formatted.slice(2)\n }\n\n // Format month\n if (formatted.length >= 3) {\n month = formatted.slice(0, 3)\n const monthIndex = MONTHS.findIndex((m) => m.startsWith(month))\n if (monthIndex !== -1) {\n month = MONTHS[monthIndex]\n } else {\n month = month.replace(/[^A-Z]/g, '')\n }\n formatted = formatted.slice(3)\n }\