Skip to content

Commit ec7d7b6

Browse files
committed
chore: KeyValueTable - Add support for readOnly mode, CustomInput - add margin-top for helper text
1 parent 0c95fc6 commit ec7d7b6

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/Common/CustomInput/CustomInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const CustomInput = ({
135135

136136
{getInputError()}
137137
{helperText && (
138-
<div className="flex left top dc__gap-4 fs-11 lh-16 cn-7">
138+
<div className="flex left top dc__gap-4 fs-11 lh-16 cn-7 mt-4">
139139
<Info className="icon-dim-16" />
140140
<div>{helperText}</div>
141141
</div>

src/Shared/Components/KeyValueTable/KeyValueTable.component.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const KeyValueTable = <K extends string>({
3535
onDelete,
3636
placeholder,
3737
isAdditionNotAllowed,
38+
readOnly,
3839
}: KeyValueTableProps<K>) => {
3940
// CONSTANTS
4041
const { headers, rows } = config
@@ -168,7 +169,7 @@ export const KeyValueTable = <K extends string>({
168169
return (
169170
<div className="dc__border br-4 w-100 bcn-0 key-value">
170171
<div
171-
className={`key-value__row flexbox dc__align-items-center bcn-50 ${!isAdditionNotAllowed || updatedRows.length ? 'dc__border-bottom-n1' : ''}`}
172+
className={`key-value__row flexbox dc__align-items-center bcn-50 ${(!readOnly && !isAdditionNotAllowed) || updatedRows.length ? 'dc__border-bottom-n1' : ''}`}
172173
>
173174
{headers.map(({ key, label, className }) =>
174175
isSortable && key === firstHeaderKey ? (
@@ -197,18 +198,18 @@ export const KeyValueTable = <K extends string>({
197198
)}
198199
{!!headerComponent && <div className="px-12">{headerComponent}</div>}
199200
</div>
200-
{!isAdditionNotAllowed && (
201+
{!readOnly && !isAdditionNotAllowed && (
201202
<div
202203
className={`key-value__row flexbox dc__align-items-center ${updatedRows.length ? 'dc__border-bottom-n1' : ''}`}
203204
>
204205
{headers.map(({ key }) => (
205206
<div
206207
key={key}
207-
className={`cn-9 fs-13 lh-20 py-8 px-12 flex dc__overflow-auto ${key === firstHeaderKey ? 'dc__align-self-stretch dc__border-right--n1 key-value__header__col-1' : 'flex-grow-1'}`}
208+
className={`cn-9 fs-13 lh-20 flex dc__overflow-auto ${key === firstHeaderKey ? 'dc__align-self-stretch dc__border-right--n1 key-value__header__col-1' : 'flex-grow-1'}`}
208209
>
209210
<textarea
210211
ref={key === firstHeaderKey ? inputRowRef : undefined}
211-
className="key-value__row-input key-value__row-input--add placeholder-cn5 p-0 lh-20 fs-13 fw-4 dc__no-border-imp dc__no-border-radius"
212+
className="key-value__row-input key-value__row-input--add placeholder-cn5 py-8 px-12 lh-20 fs-13 fw-4 dc__no-border-imp dc__no-border-radius"
212213
value=""
213214
rows={1}
214215
placeholder={placeholder[key]}
@@ -226,15 +227,15 @@ export const KeyValueTable = <K extends string>({
226227
{headers.map(({ key }) => (
227228
<div
228229
key={key}
229-
className={`cn-9 fs-13 lh-20 px-12 dc__overflow-auto flexbox dc__align-items-center dc__gap-4 ${key === firstHeaderKey ? 'dc__align-self-stretch dc__border-right--n1 key-value__header__col-1' : 'flex-grow-1'}`}
230+
className={`cn-9 fs-13 lh-20 dc__overflow-auto flexbox dc__align-items-center dc__gap-4 ${key === firstHeaderKey ? 'dc__align-self-stretch dc__border-right--n1 key-value__header__col-1' : 'flex-grow-1'}`}
230231
>
231232
{maskValue?.[key] && row.data[key].value ? (
232233
DEFAULT_SECRET_PLACEHOLDER
233234
) : (
234235
<>
235236
<ResizableTagTextArea
236237
{...row.data[key]}
237-
className="key-value__row-input placeholder-cn5 py-8 px-0 dc__no-border-imp dc__no-border-radius"
238+
className="key-value__row-input placeholder-cn5 py-8 px-12 dc__no-border-imp dc__no-border-radius"
238239
minHeight={20}
239240
maxHeight={160}
240241
value={row.data[key].value}
@@ -251,6 +252,7 @@ export const KeyValueTable = <K extends string>({
251252
? valueTextAreaRef.current?.[row.id]
252253
: keyTextAreaRef.current?.[row.id]
253254
}
255+
disabled={readOnly || row.data[key].disabled}
254256
disableOnBlurResizeToMinHeight
255257
/>
256258
{row.data[key].required && (
@@ -260,13 +262,18 @@ export const KeyValueTable = <K extends string>({
260262
)}
261263
</div>
262264
))}
263-
<button
264-
type="button"
265-
className="dc__unset-button-styles dc__align-self-stretch dc__no-shrink flex py-10 px-8 dc__border-left-n1--important dc__hover-n50"
266-
onClick={onRowDelete(row)}
267-
>
268-
<ICCross aria-label="delete-row" className="icon-dim-16 fcn-4 dc__align-self-start cursor" />
269-
</button>
265+
{!readOnly && (
266+
<button
267+
type="button"
268+
className="dc__unset-button-styles dc__align-self-stretch dc__no-shrink flex py-10 px-8 dc__border-left-n1--important dc__hover-n50"
269+
onClick={onRowDelete(row)}
270+
>
271+
<ICCross
272+
aria-label="delete-row"
273+
className="icon-dim-16 fcn-4 dc__align-self-start cursor"
274+
/>
275+
</button>
276+
)}
270277
</div>
271278
))}
272279
</div>

src/Shared/Components/KeyValueTable/KeyValueTable.types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ export interface KeyValueTableProps<K extends string> {
8282
isSortable?: boolean
8383
/** An optional React node for a custom header component. */
8484
headerComponent?: ReactNode
85-
/** When true, data addition field will not be shown */
85+
/** When true, data addition field will not be shown. */
8686
isAdditionNotAllowed?: boolean
87+
/** When true, data add or update is disabled. */
88+
readOnly?: boolean
8789
/**
8890
* An optional function to handle changes in the table rows.
8991
* @param rowId - The id of the row that changed.

0 commit comments

Comments
 (0)