Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(inputfield): use inputlabel and re-export as subcomp #1699

Merged
merged 2 commits into from
Jul 18, 2023
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
13 changes: 9 additions & 4 deletions src/components/InputField/InputField.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
display: flex;
justify-content: space-between;
margin-bottom: var(--eds-size-half);
color: var(--eds-theme-color-form-label);
}
.input-field__overline--no-label {
justify-content: flex-end;
}
.input-field__overline--disabled {
color: var(--eds-theme-color-text-disabled);
}

/**
* Input field body
Expand All @@ -25,8 +21,17 @@
position: relative;
}

.input-field__label {
color: var(--eds-theme-color-form-label);
font: var(--eds-theme-typography-form-label);
}
.input-field__label--disabled {
color: var(--eds-theme-color-text-disabled);
}

.input-field__required-text {
color: var(--eds-theme-color-text-neutral-subtle);
font: var(--eds-theme-typography-body-sm);
}

.input-field--has-fieldNote {
Expand Down
16 changes: 13 additions & 3 deletions src/components/InputField/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
} from '../../util/utility-types';
import FieldNote from '../FieldNote';
import Input from '../Input';
import Label from '../Label';
import InputLabel from '../InputLabel';
import Text from '../Text';
import styles from './InputField.module.css';

Expand Down Expand Up @@ -127,6 +127,7 @@ export type Props = React.InputHTMLAttributes<HTMLInputElement> & {

type InputFieldType = ForwardedRefComponent<HTMLInputElement, Props> & {
Input?: typeof Input;
Label?: typeof InputLabel;
};

/**
Expand Down Expand Up @@ -157,7 +158,11 @@ export const InputField: InputFieldType = forwardRef(
const overlineClassName = clsx(
styles['input-field__overline'],
!label && styles['input-field__overline--no-label'],
disabled && styles['input-field__overline--disabled'],
);

const labelClassName = clsx(
styles['input-field__label'],
disabled && styles['input-field__label--disabled'],
);

const inputBodyClassName = clsx(
Expand All @@ -177,7 +182,11 @@ export const InputField: InputFieldType = forwardRef(
<div className={className}>
{shouldRenderOverline && (
<div className={overlineClassName}>
{label && <Label htmlFor={idVar} text={label} />}
{label && (
<InputLabel className={labelClassName} htmlFor={idVar}>
{label}
</InputLabel>
)}
{required && (
<Text
as="span"
Expand Down Expand Up @@ -224,3 +233,4 @@ export const InputField: InputFieldType = forwardRef(

InputField.displayName = 'InputField';
InputField.Input = Input;
InputField.Label = InputLabel;
Loading