Skip to content

Commit c492d1c

Browse files
committed
feat: show title for array & descriptions as tippy
1 parent cb36c61 commit c492d1c

File tree

9 files changed

+48
-47
lines changed

9 files changed

+48
-47
lines changed

src/Common/RJSF/common/FieldRow.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
*/
1616

1717
import React from 'react'
18+
import { ConditionalWrap } from '../../Helper'
1819
import { FieldRowProps } from './types'
1920
import { DEFAULT_FIELD_TITLE } from '../constants'
21+
import { getTippyWrapperWithContent } from '../utils'
2022

2123
export const FieldRowWithLabel = ({
2224
showLabel,
2325
label,
2426
required,
2527
children,
2628
id,
29+
rawDescription,
2730
shouldAlignCenter = true,
2831
}: FieldRowProps) => (
2932
<div
@@ -34,8 +37,12 @@ export const FieldRowWithLabel = ({
3437
}
3538
>
3639
{showLabel && (
37-
<label className="cn-7 fs-13 lh-32 fw-4 flexbox mb-0" htmlFor={id}>
38-
<span className="dc__ellipsis-right">{label || DEFAULT_FIELD_TITLE}</span>
40+
<label className="cn-7 fs-13 lh-20 fw-4 flexbox mb-0" htmlFor={id}>
41+
<ConditionalWrap condition={!!rawDescription} wrap={getTippyWrapperWithContent(rawDescription, 'top')}>
42+
<span className={`dc__ellipsis-right ${rawDescription ? 'text-underline-dashed-300' : ''}`}>
43+
{label || DEFAULT_FIELD_TITLE}
44+
</span>
45+
</ConditionalWrap>
3946
{required && <span className="cr-5">&nbsp;*</span>}
4047
</label>
4148
)}

src/Common/RJSF/common/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
import { FieldTemplateProps } from '@rjsf/utils'
1818

19-
export interface FieldRowProps extends Pick<FieldTemplateProps, 'children' | 'label' | 'required' | 'id'> {
19+
export interface FieldRowProps
20+
extends Pick<FieldTemplateProps, 'children' | 'label' | 'required' | 'id' | 'rawDescription'> {
2021
showLabel?: boolean
2122
/**
2223
* @default true

src/Common/RJSF/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
ArrayFieldItemTemplate,
2323
ArrayFieldTemplate,
2424
BaseInputTemplate,
25-
DescriptionFieldTemplate,
2625
FieldTemplate,
2726
FieldErrorTemplate,
2827
ObjectFieldTemplate,
@@ -44,7 +43,6 @@ export const templates: FormProps['templates'] = {
4443
ArrayFieldTemplate,
4544
BaseInputTemplate,
4645
ButtonTemplates: { AddButton, RemoveButton, SubmitButton },
47-
DescriptionFieldTemplate,
4846
FieldTemplate,
4947
FieldErrorTemplate,
5048
ObjectFieldTemplate,

src/Common/RJSF/templates/Description.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Common/RJSF/templates/Field.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import React from 'react'
1818
import { FieldTemplateProps, getUiOptions, getTemplate, ADDITIONAL_PROPERTY_FLAG } from '@rjsf/utils'
1919
import { FieldRowWithLabel } from '../common/FieldRow'
20+
import { TitleField } from './TitleField'
2021

2122
export const Field = (props: FieldTemplateProps) => {
2223
const {
@@ -31,7 +32,7 @@ export const Field = (props: FieldTemplateProps) => {
3132
uiSchema,
3233
classNames,
3334
schema,
34-
description,
35+
rawDescription,
3536
} = props
3637
const uiOptions = getUiOptions(uiSchema)
3738
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate'>(
@@ -43,15 +44,32 @@ export const Field = (props: FieldTemplateProps) => {
4344
const hasAdditionalProperties = ADDITIONAL_PROPERTY_FLAG in schema
4445
// Label is not displayed for boolean fields by default and hide for object type fields
4546
const showLabel = (displayLabel || schema.type === 'boolean') && !hasAdditionalProperties
47+
const showTitle = schema.type === 'array'
4648

4749
return hidden ? (
4850
<div className="hidden">{children}</div>
4951
) : (
5052
<div className={`${classNames} mb-12`}>
51-
<FieldRowWithLabel label={label} showLabel={showLabel} id={id} required={required}>
53+
{showTitle && (
54+
<TitleField
55+
id={id}
56+
title={label}
57+
required={required}
58+
registry={registry}
59+
uiSchema={uiSchema}
60+
schema={schema}
61+
description={rawDescription}
62+
/>
63+
)}
64+
<FieldRowWithLabel
65+
label={label}
66+
showLabel={showLabel}
67+
id={id}
68+
required={required}
69+
rawDescription={rawDescription}
70+
>
5271
<WrapIfAdditionalTemplate {...props}>{children}</WrapIfAdditionalTemplate>
5372
</FieldRowWithLabel>
54-
{description}
5573
{errors}
5674
</div>
5775
)

src/Common/RJSF/templates/ObjectFieldTemplate.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
titleId,
2525
} from '@rjsf/utils'
2626
import { FieldRowWithLabel } from '../common/FieldRow'
27+
import { TitleField } from './TitleField'
2728

2829
const Field = ({
2930
disabled,
@@ -87,22 +88,22 @@ const Field = ({
8788
}
8889

8990
export const ObjectFieldTemplate = (props: ObjectFieldTemplateProps) => {
90-
const { idSchema, registry, required, schema, title, uiSchema } = props
91+
const { idSchema, registry, required, schema, title, uiSchema, description } = props
9192
const options = getUiOptions(uiSchema)
92-
const TitleFieldTemplate = getTemplate('TitleFieldTemplate', registry, options)
9393
const hasAdditionalProperties = !!schema.additionalProperties
9494
const showTitle = title && !hasAdditionalProperties
9595

9696
return (
9797
<fieldset id={idSchema.$id}>
9898
{showTitle && (
99-
<TitleFieldTemplate
99+
<TitleField
100100
id={titleId(idSchema)}
101101
title={title}
102102
required={required}
103103
schema={schema}
104104
uiSchema={uiSchema}
105105
registry={registry}
106+
description={description}
106107
/>
107108
)}
108109
{/* Not adding the border and padding for non-objects and root schema */}

src/Common/RJSF/templates/TitleField.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
*/
1616

1717
import React from 'react'
18+
import { ConditionalWrap } from '../../Helper'
1819
import { TitleFieldProps } from '@rjsf/utils'
20+
import { getTippyWrapperWithContent } from '../utils'
1921

20-
export const TitleField = ({ id, title, required }: TitleFieldProps) => (
22+
export const TitleField = ({ id, title, required, description }: TitleFieldProps & Record<'description', string>) => (
2123
<legend className="fs-13 fw-6 cn-9 lh-20 dc__no-border py-9 mb-0" id={id}>
22-
<span>{title}</span>
24+
<ConditionalWrap condition={!!description} wrap={getTippyWrapperWithContent(description, 'top')}>
25+
<span className={`${description ? 'text-underline-dashed-300' : ''}`}>{title}</span>
26+
</ConditionalWrap>
2327
{required && <span className="cr-5">&nbsp;*</span>}
2428
</legend>
2529
)

src/Common/RJSF/templates/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export { ArrayFieldTemplate } from './ArrayFieldTemplate'
1818
export { ArrayFieldItemTemplate } from './ArrayFieldItemTemplate'
1919
export { BaseInput as BaseInputTemplate } from './BaseInput'
2020
export * from './ButtonTemplates'
21-
export { Description as DescriptionFieldTemplate } from './Description'
2221
export { Field as FieldTemplate } from './Field'
2322
export { FieldErrorTemplate } from './FieldErrorTemplate'
2423
export { ObjectFieldTemplate } from './ObjectFieldTemplate'

src/Common/RJSF/utils.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ export const getInferredTypeFromValueType = (value) => {
137137
}
138138
}
139139

140-
export const getTippyWrapperWithContent = (content) => (children) => (
141-
<Tippy className="default-tt dc__word-break" arrow={false} placement="right" content={content}>
142-
{children}
143-
</Tippy>
144-
)
140+
export const getTippyWrapperWithContent =
141+
(content, placement?: React.ComponentProps<typeof Tippy>['placement']) => (children) => (
142+
<Tippy className="default-tt dc__word-break" arrow={false} placement={placement || 'right'} content={content}>
143+
{children}
144+
</Tippy>
145+
)

0 commit comments

Comments
 (0)