Skip to content

Commit 07834cf

Browse files
committed
IBX-10537: Base Form Control
1 parent 8a8a172 commit 07834cf

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@use 'functions' as *;
2+
3+
.ids-form-control {
4+
&__label-wrapper {
5+
margin-bottom: calculateRem(8px);
6+
}
7+
8+
&__helper-text-wrapper {
9+
margin-top: calculateRem(8px);
10+
}
11+
}

packages/assets/src/scss/_helper-text.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ $helper-text-types: (
1010
.ids-helper-text {
1111
$self: &;
1212

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

1717
&__icon-wrapper {
1818
display: flex;
1919
align-items: center;
20-
height: $text-font-size-m * $base-line-height;
20+
height: $text-font-size-s * $base-line-height;
2121
padding-right: calculateRem(4px);
2222
}
2323

packages/assets/src/scss/styles.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
@use 'buttons';
77
@use 'expander';
88
@use 'fonts';
9+
@use 'form-control';
10+
@use 'helper-text';
911
@use 'icons';
1012
@use 'input';
1113
@use 'label';
12-
@use 'helper-text';
1314

1415
@use 'inputs/input-text';
1516

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
3+
import HelperText from '../../../HelperText';
4+
import Label from '../../../Label';
5+
6+
import { createCssClassNames } from '@ids-internal/shared/css.class.names';
7+
8+
import { BaseFormControlProps } from './BaseFormControl.types';
9+
10+
const BaseFormControl = ({ children, className = '', helperText, label, type }: BaseFormControlProps) => {
11+
const classes = createCssClassNames({
12+
'ids-form-control': true,
13+
[`ids-form-control--${type}`]: true,
14+
[className]: true,
15+
});
16+
const renderLabel = () => {
17+
if (!label) {
18+
return null;
19+
}
20+
21+
const { children: labelContent, ...labelProps } = label;
22+
23+
return (
24+
<div className="ids-form-control__label-wrapper">
25+
<Label {...labelProps}>{labelContent}</Label>
26+
</div>
27+
);
28+
};
29+
const renderHelperText = () => {
30+
if (!helperText) {
31+
return null;
32+
}
33+
34+
const { children: helperTextContent, ...helperTextProps } = helperText;
35+
36+
return (
37+
<div className="ids-form-control__helper-text-wrapper">
38+
<HelperText {...helperTextProps}>{helperTextContent}</HelperText>
39+
</div>
40+
);
41+
};
42+
43+
return (
44+
<div className={classes}>
45+
{renderLabel()}
46+
<div className="ids-form-control__source-wrapper">{children}</div>
47+
{renderHelperText()}
48+
</div>
49+
);
50+
};
51+
52+
export default BaseFormControl;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ReactNode } from 'react';
2+
3+
import { BaseComponentAttributes } from '@ids-types/general';
4+
5+
import { HelperTextProps } from '../../../HelperText/HelperText.types';
6+
import { LabelProps } from '../../../Label/Label.types';
7+
8+
export interface BaseFormControlProps extends BaseComponentAttributes {
9+
children: ReactNode;
10+
type: string;
11+
helperText?: HelperTextProps;
12+
label?: LabelProps;
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import BaseFormControl from './BaseFormControl';
2+
import { BaseFormControlProps } from './BaseFormControl.types';
3+
4+
export default BaseFormControl;
5+
export type { BaseFormControlProps };

0 commit comments

Comments
 (0)