import type { ReactNode } from 'react' import { Box, Center, Flex, type FlexProps, Paper, Stack, Title, type TitleProps, Tooltip, useMantineColorScheme, } from '@mantine/core' import React from 'react' import classes from './InlineWapper.module.css' interface InlineWrapperCallbackProps extends Partial { classNames: React.CSSProperties dataCssProps?: Record size: string } interface InlineWrapperProps extends InlineWrapperPropsOnly{ children?: ((props: InlineWrapperCallbackProps) => ReactNode) | ReactNode } interface InlineWrapperPropsOnly { error?: ReactNode | string flexProps?: FlexProps label: ReactNode | string labelProps?: TitleProps promptArea?: ((props: InlineWrapperCallbackProps) => ReactNode) | ReactNode promptWidth?: FlexProps['w'] required?: boolean rightSection?: ((props: InlineWrapperCallbackProps) => ReactNode) | ReactNode styles?: React.CSSProperties tooltip?: string value?: any } function InlineWrapper(props: InlineWrapperProps) { return ( {props.promptWidth && props.promptWidth !== 0 ? : null}
{typeof props.children === 'function' ? ( props.children({ ...props, classNames: classes, size: 'xs' }) ) : typeof props.children === 'object' && React.isValidElement(props.children) ? ( ) : ( props.children )}
{!props.rightSection ? undefined : typeof props.rightSection === 'function' ? ( props.rightSection({ ...props, classNames: classes, size: 'xs', }) ) : typeof props.rightSection === 'object' && React.isValidElement(props.rightSection) ? ( ) : ( props.rightSection )}
{/* */}
) } function isValueEmpty(inputValue: any) { if (inputValue === null || inputValue === undefined) return true if (typeof inputValue === 'number') { if (inputValue === 0) return false } else if (typeof inputValue === 'string' || inputValue === '') { return inputValue.trim() === '' } else if (inputValue instanceof File) { return inputValue.size === 0 } else if (inputValue.target) { return isValueEmpty(inputValue.target?.value) } else if (inputValue.constructor?.name === 'Date') { return false } } function Prompt(props: Partial) { return ( <> {props.tooltip ? ( ) : ( )} ) } function PromptDetail(props: Partial) { const colors = useColors(props) return props.promptArea ? ( {!props.promptArea ? undefined : typeof props.promptArea === 'function' ? ( props.promptArea({ ...props, classNames: classes, dataCssProps: { 'data-promptArea': true }, size: 'xs', }) ) : typeof props.rightSection === 'object' && React.isValidElement(props.promptArea) ? ( ) : ( props.promptArea )} ) : (
{props.label} {props.required && isValueEmpty(props.value) && <span style={{ color: 'red' }}>*</span>}
) } function useColors(props: Partial) { const { colorScheme } = useMantineColorScheme() let titleColor = colorScheme === 'dark' ? 'dark.0' : 'gray.8' let paperColor = colorScheme === 'dark' ? 'dark.7' : 'gray.1' if (props.required && isValueEmpty(props.value)) { paperColor = colorScheme === 'dark' ? '#413012e7' : 'yellow.1' } if (props.error) { paperColor = colorScheme === 'dark' ? 'red.7' : 'red.0' titleColor = colorScheme === 'dark' ? 'red.0' : 'red.9' } return { paperColor, titleColor } } export { InlineWrapper } export type { InlineWrapperProps }