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

feat(FieldLabel)!: introduce 2.0 component #1953

Merged
merged 1 commit into from
May 20, 2024
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
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
@import '../../design-tokens/mixins.css';

/*------------------------------------*\
# INPUT LABEL
# FIELD LABEL
\*------------------------------------*/

/**
* Text labeling the input component.
* Text labeling the field component.
*/
.label {
color: var(--eds-theme-color-text-utility-default-primary);
}

/**
* Disabled variant of the input label.
* Disabled variant of the field label.
*/
.label--disabled {
color: var(--eds-theme-color-text-utility-disabled-primary);
}

/**
* Input label size variants.
* Field label size variants.
*/
.label--md {
font: var(--eds-theme-typography-body-sm);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { StoryObj, Meta } from '@storybook/react';
import type { ComponentProps } from 'react';

import { InputLabel } from './InputLabel-v2';
import { FieldLabel } from './FieldLabel';

export default {
title: 'Components/V2/InputLabel',
component: InputLabel,
title: 'Components/V2/FieldLabel',
component: FieldLabel,
args: {
children: 'Label',
},
parameters: {
badges: ['intro-1.0'],
badges: ['intro-2.0', 'current-2.0'],
},
} as Meta<Args>;

type Args = ComponentProps<typeof InputLabel>;
type Args = ComponentProps<typeof FieldLabel>;

export const Default: StoryObj<Args> = {};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import clsx from 'clsx';
import React, { type ReactNode } from 'react';
import type { Size } from '../../util/variant-types';
import styles from './InputLabel-v2.module.css';
import styles from './FieldLabel.module.css';

export type InputLabelProps = {
export type FieldLabelProps = {
// Component API
/**
* Text to render in label.
Expand Down Expand Up @@ -31,11 +31,11 @@ export type InputLabelProps = {
};

/**
* `import {InputLabel} from "@chanzuckerberg/eds";`
* `import {FieldLabel} from "@chanzuckerberg/eds";`
*
* Label associated with an input element such as a radio or checkbox.
* Label associated with an input element or field.
*/
export const InputLabel = React.forwardRef<HTMLLabelElement, InputLabelProps>(
export const FieldLabel = React.forwardRef<HTMLLabelElement, FieldLabelProps>(
({ children, className, htmlFor, size = 'lg', disabled }, ref) => {
const componentClassName = clsx(
styles['label'],
Expand All @@ -52,4 +52,4 @@ export const InputLabel = React.forwardRef<HTMLLabelElement, InputLabelProps>(
},
);

InputLabel.displayName = 'InputLabel';
FieldLabel.displayName = 'FieldLabel';
1 change: 1 addition & 0 deletions src/components/FieldLabel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { FieldLabel as default } from './FieldLabel';
10 changes: 5 additions & 5 deletions src/components/InputField/InputField-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import type {
EitherInclusive,
ForwardedRefComponent,
} from '../../util/utility-types';
import FieldLabel from '../FieldLabel';
import { FieldNoteV2 as FieldNote } from '../FieldNote';
import { IconV2 as Icon, type IconNameV2 as IconName } from '../Icon';
import { InputV2 as Input } from '../Input';
import { InputLabelV2 as InputLabel } from '../InputLabel';
import Text from '../Text';
import styles from './InputField-v2.module.css';

Expand Down Expand Up @@ -149,7 +149,7 @@ type InputFieldType = ForwardedRefComponent<
InputFieldProps
> & {
Input?: typeof Input;
Label?: typeof InputLabel;
Label?: typeof FieldLabel;
};

/**
Expand Down Expand Up @@ -245,9 +245,9 @@ export const InputField: InputFieldType = forwardRef(
{shouldRenderOverline && (
<div className={overlineClassName}>
{label && (
<InputLabel className={labelClassName} htmlFor={idVar}>
<FieldLabel className={labelClassName} htmlFor={idVar}>
{label}
</InputLabel>
</FieldLabel>
)}
{required && showHint && (
<Text
Expand Down Expand Up @@ -342,4 +342,4 @@ export const InputField: InputFieldType = forwardRef(

InputField.displayName = 'InputField';
InputField.Input = Input;
InputField.Label = InputLabel;
InputField.Label = FieldLabel;
1 change: 0 additions & 1 deletion src/components/InputLabel/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { InputLabel as default } from './InputLabel';
export { InputLabel as InputLabelV2 } from './InputLabel-v2';
4 changes: 2 additions & 2 deletions src/components/Select/Select-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { usePopper } from 'react-popper';

import { useId } from '../../util/useId';
import type { ExtractProps } from '../../util/utility-types';
import FieldLabel from '../FieldLabel';
import { FieldNoteV2 as FieldNote } from '../FieldNote';
import { IconV2 as Icon, type IconNameV2 as IconName } from '../Icon';
import { InputLabelV2 as InputLabel } from '../InputLabel';
import {
defaultPopoverModifiers,
PopoverContainerV2 as PopoverContainer,
Expand Down Expand Up @@ -350,7 +350,7 @@ const SelectLabel = ({
return (
<div className={overlineClassName}>
<Listbox.Label
as={InputLabel}
as={FieldLabel}
className={componentClassName}
htmlFor={htmlFor}
>
Expand Down
10 changes: 5 additions & 5 deletions src/components/TextareaField/TextareaField-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
ForwardedRefComponent,
} from '../../util/utility-types';

import FieldLabel from '../FieldLabel';
import { FieldNoteV2 as FieldNote } from '../FieldNote';
import { InputLabelV2 as InputLabel } from '../InputLabel';
import Text from '../Text';

import styles from './TextareaField-v2.module.css';
Expand Down Expand Up @@ -78,7 +78,7 @@ type TextareaFieldType = ForwardedRefComponent<
TextareaFieldProps
> & {
TextArea?: typeof TextArea;
Label?: typeof InputLabel;
Label?: typeof FieldLabel;
};

type TextAreaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement> & {
Expand Down Expand Up @@ -229,9 +229,9 @@ export const TextareaField: TextareaFieldType = forwardRef(
{shouldRenderOverline && (
<div className={overlineClassName}>
{label && (
<InputLabel className={labelClassName} htmlFor={idVar}>
<FieldLabel className={labelClassName} htmlFor={idVar}>
{label}
</InputLabel>
</FieldLabel>
)}
{required && showHint && (
<Text
Expand Down Expand Up @@ -304,4 +304,4 @@ TextareaField.displayName = 'TextareaField';
TextArea.displayName = 'TextareaField.Textarea';

TextareaField.TextArea = TextArea;
TextareaField.Label = InputLabel;
TextareaField.Label = FieldLabel;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export { ButtonV2 } from './components/Button';
export { ButtonGroupV2 } from './components/ButtonGroup';
export { CardV2 } from './components/Card';
export { CheckboxV2 } from './components/Checkbox';
export { default as FieldLabelV2 } from './components/FieldLabel';
export { FieldNoteV2 } from './components/FieldNote';
export { IconV2 } from './components/Icon';
export { InlineNotificationV2 } from './components/InlineNotification';
Expand Down
Loading