Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions docs/styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ Variables for customizing the Toggler Card component:

Variables for the Array Base input component:

| Variable | Default Value | Description |
| :--------------------------------------------- | :------------: | :---------------------------------------------- |
| `--df-array-base-items-primitive-min-width` | `100%` | Minimum width for primitive array items |
| `--df-array-base-item-prefix-margin` | `-8px 0px 8px` | Margin for the item prefix (top, right, bottom) |
| `--df-array-base-add-button-right-margin-left` | `4px` | Left margin for the "Add" button on the right |
| Variable | Default Value | Description |
| :----------------------------------------------------- | :------------: | :----------------------------------------------------------------------- |
| `--df-array-base-items-primitive-min-width` | `100%` | Minimum width for primitive array items |
| `--df-array-base-item-prefix-margin` | `-8px 0px 8px` | Margin for the item prefix (top, right, bottom) |
| `--df-array-base-add-button-right-margin-left` | `4px` | Left margin for the "Add" button on the right |
| `--df-array-base-add-button-right-error-margin-bottom` | `18px` | Bottom margin for the "Add" button on the right for last item error case |

---

Expand Down
10 changes: 10 additions & 0 deletions src/lib/kit/components/Inputs/ArrayBase/ArrayBase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@
margin-left: var(--df-array-base-add-button-right-margin-left, var(--g-spacing-1));
}
}

&_add-button-right {
> div:last-child {
transition: margin-bottom 0.2s ease-in-out;
}
}

&_add-button-right_error {
margin-bottom: var(--df-array-base-add-button-right-error-margin-bottom, 18px);
}
}
20 changes: 18 additions & 2 deletions src/lib/kit/components/Inputs/ArrayBase/ArrayBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import './ArrayBase.scss';

const b = block('array-base');

export const ArrayBase: ArrayInput = ({spec, name, arrayInput, input}) => {
export const ArrayBase: ArrayInput = ({spec, name, arrayInput, input, meta}) => {
const keys = React.useMemo(
() =>
Object.keys(arrayInput.value || {})
Expand Down Expand Up @@ -150,6 +150,15 @@ export const ArrayBase: ArrayInput = ({spec, name, arrayInput, input}) => {
],
);

const hasErrorInLastItem = React.useMemo(() => {
if (keys.length === 0) {
return false;
}
const lastKey = keys[keys.length - 1];
const lastItemName = `${name}.<${lastKey}>`;
return Boolean(meta.childErrors[lastItemName]);
}, [keys, name, meta.childErrors]);

if (!itemSpecCorrect) {
return null;
}
Expand All @@ -165,7 +174,14 @@ export const ArrayBase: ArrayInput = ({spec, name, arrayInput, input}) => {
>
{items}
</div>
<AddButton />
<div
className={b({
'add-button-right_error':
spec.viewSpec.addButtonPosition === 'right' && hasErrorInLastItem,
})}
>
<AddButton />
</div>
</div>
);
};