mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Updating Label component (#17731)
This commit is contained in:
parent
ccde54937f
commit
a4f33ec0ad
@ -62,8 +62,11 @@ export const FormTextField = ({
|
|||||||
<Label
|
<Label
|
||||||
htmlFor={id}
|
htmlFor={id}
|
||||||
required={required}
|
required={required}
|
||||||
disabled={disabled}
|
|
||||||
{...labelProps}
|
{...labelProps}
|
||||||
|
className={classnames(
|
||||||
|
'mm-form-text-field__label',
|
||||||
|
labelProps?.className,
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
</Label>
|
</Label>
|
||||||
@ -105,13 +108,13 @@ export const FormTextField = ({
|
|||||||
/>
|
/>
|
||||||
{helpText && (
|
{helpText && (
|
||||||
<HelpText
|
<HelpText
|
||||||
|
error={error}
|
||||||
|
marginTop={1}
|
||||||
|
{...helpTextProps}
|
||||||
className={classnames(
|
className={classnames(
|
||||||
'mm-form-text-field__help-text',
|
'mm-form-text-field__help-text',
|
||||||
helpTextProps?.className,
|
helpTextProps?.className,
|
||||||
)}
|
)}
|
||||||
error={error}
|
|
||||||
marginTop={1}
|
|
||||||
{...helpTextProps}
|
|
||||||
>
|
>
|
||||||
{helpText}
|
{helpText}
|
||||||
</HelpText>
|
</HelpText>
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
.mm-form-text-field {
|
.mm-form-text-field {
|
||||||
--help-text-opacity-disabled: 0.5;
|
--text-opacity-disabled: 0.5;
|
||||||
|
|
||||||
&--disabled {
|
&--disabled {
|
||||||
|
.mm-form-text-field__label,
|
||||||
.mm-form-text-field__help-text {
|
.mm-form-text-field__help-text {
|
||||||
opacity: var(--help-text-opacity-disabled);
|
opacity: var(--text-opacity-disabled);
|
||||||
|
cursor: default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,11 +96,14 @@ describe('FormTextField', () => {
|
|||||||
const { getByText, getByTestId } = render(
|
const { getByText, getByTestId } = render(
|
||||||
<FormTextField
|
<FormTextField
|
||||||
helpText="test help text"
|
helpText="test help text"
|
||||||
helpTextProps={{ 'data-testid': 'help-text-test' }}
|
helpTextProps={{ 'data-testid': 'help-text-test', className: 'test' }}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
expect(getByText('test help text')).toBeDefined();
|
expect(getByText('test help text')).toBeDefined();
|
||||||
expect(getByTestId('help-text-test')).toBeDefined();
|
expect(getByTestId('help-text-test')).toBeDefined();
|
||||||
|
expect(getByTestId('help-text-test')).toHaveClass(
|
||||||
|
'mm-form-text-field__help-text test',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
// id
|
// id
|
||||||
it('should render the FormTextField with an id and pass it to input and Label as htmlFor. When clicking on Label the input should have focus', async () => {
|
it('should render the FormTextField with an id and pass it to input and Label as htmlFor. When clicking on Label the input should have focus', async () => {
|
||||||
@ -141,12 +144,15 @@ describe('FormTextField', () => {
|
|||||||
const { getByTestId, getByLabelText } = render(
|
const { getByTestId, getByLabelText } = render(
|
||||||
<FormTextField
|
<FormTextField
|
||||||
label="test label"
|
label="test label"
|
||||||
labelProps={{ 'data-testid': 'label-test-id' }}
|
labelProps={{ 'data-testid': 'label-test-id', className: 'test' }}
|
||||||
id="test-id"
|
id="test-id"
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
expect(getByLabelText('test label')).toBeDefined();
|
expect(getByLabelText('test label')).toBeDefined();
|
||||||
expect(getByTestId('label-test-id')).toBeDefined();
|
expect(getByTestId('label-test-id')).toBeDefined();
|
||||||
|
expect(getByTestId('label-test-id')).toHaveClass(
|
||||||
|
'mm-form-text-field__label test',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
// leftAccessory, // rightAccessory
|
// leftAccessory, // rightAccessory
|
||||||
it('should render with right and left accessories', () => {
|
it('should render with right and left accessories', () => {
|
||||||
|
@ -82,14 +82,6 @@ import { Label } from '../../component-library';
|
|||||||
<Label required>Label</Label>;
|
<Label required>Label</Label>;
|
||||||
```
|
```
|
||||||
|
|
||||||
### Disabled
|
|
||||||
|
|
||||||
Use the `disabled` prop to set the `Label` in disabled state
|
|
||||||
|
|
||||||
<Canvas>
|
|
||||||
<Story id="components-componentlibrary-label--disabled" />
|
|
||||||
</Canvas>
|
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
import { Label } from '../../component-library';
|
import { Label } from '../../component-library';
|
||||||
|
|
||||||
|
@ -10,23 +10,14 @@ import {
|
|||||||
AlignItems,
|
AlignItems,
|
||||||
} from '../../../helpers/constants/design-system';
|
} from '../../../helpers/constants/design-system';
|
||||||
|
|
||||||
export const Label = ({
|
export const Label = ({ htmlFor, required, className, children, ...props }) => (
|
||||||
htmlFor,
|
|
||||||
required,
|
|
||||||
disabled,
|
|
||||||
className,
|
|
||||||
children,
|
|
||||||
...props
|
|
||||||
}) => (
|
|
||||||
<Text
|
<Text
|
||||||
className={classnames(
|
className={classnames(
|
||||||
'mm-label',
|
'mm-label',
|
||||||
{ 'mm-label--disabled': disabled },
|
{ 'mm-label--html-for': htmlFor },
|
||||||
{ 'mm-label--html-for': htmlFor && !disabled },
|
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
as="label"
|
as="label"
|
||||||
disabled={disabled}
|
|
||||||
htmlFor={htmlFor}
|
htmlFor={htmlFor}
|
||||||
variant={TextVariant.bodyMd}
|
variant={TextVariant.bodyMd}
|
||||||
fontWeight={FONT_WEIGHT.BOLD}
|
fontWeight={FONT_WEIGHT.BOLD}
|
||||||
@ -61,10 +52,6 @@ Label.propTypes = {
|
|||||||
* If true the label will display as required
|
* If true the label will display as required
|
||||||
*/
|
*/
|
||||||
required: PropTypes.bool,
|
required: PropTypes.bool,
|
||||||
/**
|
|
||||||
* Whether the label is disabled or not
|
|
||||||
*/
|
|
||||||
disabled: PropTypes.bool,
|
|
||||||
/**
|
/**
|
||||||
* Additional classNames to be added to the label component
|
* Additional classNames to be added to the label component
|
||||||
*/
|
*/
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
.mm-label {
|
.mm-label {
|
||||||
--label-opacity-disabled: 0.5; // TODO: replace with design token
|
|
||||||
|
|
||||||
&--html-for {
|
&--html-for {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
&--disabled {
|
|
||||||
opacity: var(--label-opacity-disabled);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,6 @@ export default {
|
|||||||
required: {
|
required: {
|
||||||
control: 'boolean',
|
control: 'boolean',
|
||||||
},
|
},
|
||||||
disabled: {
|
|
||||||
control: 'boolean',
|
|
||||||
},
|
|
||||||
children: {
|
children: {
|
||||||
control: 'text',
|
control: 'text',
|
||||||
},
|
},
|
||||||
@ -104,8 +101,3 @@ export const Required = Template.bind({});
|
|||||||
Required.args = {
|
Required.args = {
|
||||||
required: true,
|
required: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Disabled = Template.bind({});
|
|
||||||
Disabled.args = {
|
|
||||||
disabled: true,
|
|
||||||
};
|
|
||||||
|
@ -62,8 +62,4 @@ describe('label', () => {
|
|||||||
expect(getByText('label')).toBeDefined();
|
expect(getByText('label')).toBeDefined();
|
||||||
expect(getByText('*')).toBeDefined();
|
expect(getByText('*')).toBeDefined();
|
||||||
});
|
});
|
||||||
it('should render with disabled state and have disabled class', () => {
|
|
||||||
const { getByText } = render(<Label disabled>label</Label>);
|
|
||||||
expect(getByText('label')).toHaveClass('mm-label--disabled');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user