mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
* Merge intermediate component wrappers into OL-prefixed components * Replace all intermediate wrapper consumers with OL-prefixed components directly * Fix jsx/js files still importing deleted shim components * Remove duplicate OLNotification imports left by first pass * Rename OLTagIcon to TagIcon, remove OL prefix * Rename OLDropdownMenuItem to DropdownMenuItem, remove OL prefix * Remove OLNotification, use Notification directly * Move Notification to the main shared component folder * Update tag-icon import path out of ol/ * Move TagIcon to the main shared component folder * Update dropdown-menu-item import path out of ol/ * Move DropdownMenuItem to the main shared component folder * Fix dropdown-menu-item import path to dropdown/ subfolder * Remove BS5 alias prefixes from shared components * Restore notification-list wrapper in Notification component * Add translation for loading button * Remove redundant import aliasing * Resolve conflicts * Restore notification container `notification-list` GitOrigin-RevId: 24a5af18599a3e02ac6fd61c09cf5a49ef6e0020
88 lines
2.1 KiB
TypeScript
88 lines
2.1 KiB
TypeScript
import { Form, FormTextProps as FormTextProps } from 'react-bootstrap'
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
|
import classnames from 'classnames'
|
|
import { MergeAndOverride } from '../../../../../types/utils'
|
|
|
|
type TextType = 'default' | 'info' | 'success' | 'warning' | 'error'
|
|
|
|
export type OLFormTextProps = MergeAndOverride<
|
|
FormTextProps,
|
|
{
|
|
type?: TextType
|
|
unfilled?: boolean
|
|
marginless?: boolean
|
|
}
|
|
>
|
|
|
|
const typeClassMap: Partial<Record<TextType, string>> = {
|
|
error: 'text-danger',
|
|
success: 'text-success',
|
|
warning: 'text-warning',
|
|
}
|
|
|
|
export const getFormTextClass = (type?: TextType) =>
|
|
typeClassMap[type || 'default']
|
|
|
|
function FormTextIcon({
|
|
type,
|
|
unfilled,
|
|
}: Pick<OLFormTextProps, 'type' | 'unfilled'>) {
|
|
switch (type) {
|
|
case 'info':
|
|
return unfilled ? (
|
|
<MaterialIcon type="info" className="text-info" unfilled />
|
|
) : (
|
|
<MaterialIcon type="info" className="text-info" />
|
|
)
|
|
case 'success':
|
|
return unfilled ? (
|
|
<MaterialIcon type="check_circle" unfilled />
|
|
) : (
|
|
<MaterialIcon type="check_circle" />
|
|
)
|
|
case 'warning':
|
|
return unfilled ? (
|
|
<MaterialIcon type="warning" unfilled />
|
|
) : (
|
|
<MaterialIcon type="warning" />
|
|
)
|
|
case 'error':
|
|
return unfilled ? (
|
|
<MaterialIcon type="error" unfilled />
|
|
) : (
|
|
<MaterialIcon type="error" />
|
|
)
|
|
default:
|
|
return null
|
|
}
|
|
}
|
|
|
|
// Base component without a default `as` — exported for use by the backward-compat shim
|
|
export function FormText({
|
|
type = 'default',
|
|
marginless,
|
|
children,
|
|
className,
|
|
unfilled,
|
|
...rest
|
|
}: OLFormTextProps) {
|
|
return (
|
|
<Form.Text
|
|
className={classnames(className, getFormTextClass(type), { marginless })}
|
|
{...rest}
|
|
>
|
|
<span className="form-text-inner">
|
|
<FormTextIcon type={type} unfilled={unfilled} />
|
|
<span>{children}</span>
|
|
</span>
|
|
</Form.Text>
|
|
)
|
|
}
|
|
|
|
// OL component defaults to rendering as a <div>
|
|
function OLFormText({ as = 'div', ...rest }: OLFormTextProps) {
|
|
return <FormText as={as} {...rest} />
|
|
}
|
|
|
|
export default OLFormText
|