Skip to content

Commit

Permalink
feat(FormField): add boldLabel prop for InputPromo (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoannaSikora authored Jan 24, 2025
1 parent 34efe9a commit df33d0d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
flex-direction: row;
align-items: center;
justify-content: flex-start;
margin-bottom: 4px;
margin-bottom: var(--spacing-1);

label {
margin-bottom: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Info } from '@livechat/design-system-icons';
import { Meta, StoryFn } from '@storybook/react';

import { Icon } from '../Icon';
import { Input } from '../Input';
import { Input, InputPromo } from '../Input';
import { IInputProps } from '../Input/types';

import { FormField as FormFieldComponent, FormFieldProps } from './FormField';
Expand All @@ -23,13 +23,21 @@ export default {
labelRightNode: {
control: false,
},
parameters: {
controls: {
exclude: ['boldLabel'],
},
},
},
} as Meta<typeof FormFieldComponent>;

const ExampleIcon = () => <Icon source={Info} />;
const ExampleInput = ({ ...args }: IInputProps) => (
<Input placeholder="Placeholder text" {...args} />
);
const ExampleInputPromo = ({ ...args }: IInputProps) => (
<InputPromo placeholder="Placeholder text" {...args} />
);
const LabelText = 'Email';
const DescriptionText = 'Enter your email address';
const PlaceholderText = 'e.g., [email protected]';
Expand Down Expand Up @@ -93,3 +101,9 @@ export const TextFieldWithError: StoryFn<FormFieldProps> = () => (
<ExampleInput error />
</FormFieldComponent>
);

export const BoldLabelWithPromoInput: StoryFn<FormFieldProps> = () => (
<FormFieldComponent labelText="Username" boldLabel>
<ExampleInputPromo />
</FormFieldComponent>
);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export interface FormFieldProps {
* Define to associate the label with the field
*/
labelFor?: string;
/**
* Makes the label text bold. Note: This prop should only be used together with PromoInput.
*/
boldLabel?: boolean;
/**
* The CSS class for field container
*/
Expand Down Expand Up @@ -59,6 +63,7 @@ export const FormField: React.FC<React.PropsWithChildren<FormFieldProps>> = ({
labelFor,
children,
labelRightNode,
boldLabel = false,
}) => {
const childrenRef = React.useRef<HTMLDivElement>(null);
const [labelHeight, setLabelHeight] = React.useState('auto');
Expand Down Expand Up @@ -125,7 +130,7 @@ export const FormField: React.FC<React.PropsWithChildren<FormFieldProps>> = ({
className={styles[`${baseClass}__label-left-node`]}
htmlFor={labelFor}
>
<Text as="span" size="sm">
<Text as="span" size="sm" bold={boldLabel}>
{labelText}
</Text>
</label>
Expand Down

0 comments on commit df33d0d

Please sign in to comment.