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: 11 additions & 0 deletions packages/assets/src/scss/_form-control.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@use 'functions' as *;

.ids-form-control {
&__label-wrapper {
margin-bottom: calculateRem(8px);
}

&__helper-text-wrapper {
margin-top: calculateRem(8px);
}
}
4 changes: 2 additions & 2 deletions packages/assets/src/scss/_helper-text.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ $helper-text-types: (
.ids-helper-text {
$self: &;

font-size: $text-font-size-m;
font-size: $text-font-size-s;
color: #{map.get($helper-text-types, 'default')};
display: flex;

&__icon-wrapper {
display: flex;
align-items: center;
height: $text-font-size-m * $base-line-height;
height: $text-font-size-s * $base-line-height;
padding-right: calculateRem(4px);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/assets/src/scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
@use 'buttons';
@use 'expander';
@use 'fonts';
@use 'form-control';
@use 'helper-text';
@use 'icons';
@use 'input';
@use 'label';
@use 'helper-text';

@use 'inputs/input-text';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';

import HelperText from '../../../HelperText';
import Label from '../../../Label';

import { createCssClassNames } from '@ibexa/ids-core/helpers/cssClassNames';

import { BaseFormControlProps } from './BaseFormControl.types';

const BaseFormControl = ({ children, className = '', helperText, label, type }: BaseFormControlProps) => {
const classes = createCssClassNames({
'ids-form-control': true,
[`ids-form-control--${type}`]: true,
[className]: !!className,
});
const renderLabel = () => {
if (!label) {
return null;
}

const { children: labelContent, ...labelProps } = label;

return (
<div className="ids-form-control__label-wrapper">
<Label {...labelProps}>{labelContent}</Label>
</div>
);
};
const renderHelperText = () => {
if (!helperText) {
return null;
}

const { children: helperTextContent, ...helperTextProps } = helperText;

return (
<div className="ids-form-control__helper-text-wrapper">
<HelperText {...helperTextProps}>{helperTextContent}</HelperText>
</div>
);
};

return (
<div className={classes}>
{renderLabel()}
<div className="ids-form-control__source-wrapper">{children}</div>
{renderHelperText()}
</div>
);
};

export default BaseFormControl;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ReactNode } from 'react';

import { BaseComponentAttributes } from '@ids-types/general';

import { HelperTextProps } from '../../../HelperText/HelperText.types';
import { LabelProps } from '../../../Label/Label.types';

export interface BaseFormControlProps extends BaseComponentAttributes {
children: ReactNode;
type: string;
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type prop uses a generic string type which allows any value. Consider using a union type or enum to restrict valid form control types and improve type safety.

Suggested change
type: string;
type: 'text' | 'password' | 'email' | 'number' | 'search' | 'tel' | 'url' | 'date' | 'datetime-local' | 'month' | 'week' | 'time' | 'checkbox' | 'radio' | 'file' | 'range' | 'color' | 'hidden' | 'submit' | 'reset' | 'button';

Copilot uses AI. Check for mistakes.
helperText?: HelperTextProps;
label?: LabelProps;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import BaseFormControl from './BaseFormControl';
import { BaseFormControlProps } from './BaseFormControl.types';

export default BaseFormControl;
export type { BaseFormControlProps };