Skip to content

Commit

Permalink
Updating Label component
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewrmarshall committed Feb 11, 2023
1 parent 3b8ea38 commit e2e2f65
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ export const FormTextField = ({
<Label
htmlFor={id}
required={required}
disabled={disabled}
{...labelProps}
className={classnames(
'mm-form-text-field__label',
labelProps?.className,
)}
>
{label}
</Label>
Expand Down Expand Up @@ -105,13 +108,13 @@ export const FormTextField = ({
/>
{helpText && (
<HelpText
error={error}
marginTop={1}
{...helpTextProps}
className={classnames(
'mm-form-text-field__help-text',
helpTextProps?.className,
)}
error={error}
marginTop={1}
{...helpTextProps}
>
{helpText}
</HelpText>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.mm-form-text-field {
--help-text-opacity-disabled: 0.5;
--text-opacity-disabled: 0.5;

&--disabled {
.mm-form-text-field__label,
.mm-form-text-field__help-text {
opacity: var(--help-text-opacity-disabled);
opacity: var(--text-opacity-disabled);
cursor: default;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ describe('FormTextField', () => {
const { getByText, getByTestId } = render(
<FormTextField
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(getByTestId('help-text-test')).toBeDefined();
expect(getByTestId('help-text-test')).toHaveClass(
'mm-form-text-field__help-text test',
);
});
// 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 () => {
Expand Down Expand Up @@ -141,12 +144,15 @@ describe('FormTextField', () => {
const { getByTestId, getByLabelText } = render(
<FormTextField
label="test label"
labelProps={{ 'data-testid': 'label-test-id' }}
labelProps={{ 'data-testid': 'label-test-id', className: 'test' }}
id="test-id"
/>,
);
expect(getByLabelText('test label')).toBeDefined();
expect(getByTestId('label-test-id')).toBeDefined();
expect(getByTestId('label-test-id')).toHaveClass(
'mm-form-text-field__label test',
);
});
// leftAccessory, // rightAccessory
it('should render with right and left accessories', () => {
Expand Down
8 changes: 0 additions & 8 deletions ui/components/component-library/label/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ import { Label } from '../../component-library';
<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
import { Label } from '../../component-library';

Expand Down
17 changes: 2 additions & 15 deletions ui/components/component-library/label/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,14 @@ import {
AlignItems,
} from '../../../helpers/constants/design-system';

export const Label = ({
htmlFor,
required,
disabled,
className,
children,
...props
}) => (
export const Label = ({ htmlFor, required, className, children, ...props }) => (
<Text
className={classnames(
'mm-label',
{ 'mm-label--disabled': disabled },
{ 'mm-label--html-for': htmlFor && !disabled },
{ 'mm-label--html-for': htmlFor },
className,
)}
as="label"
disabled={disabled}
htmlFor={htmlFor}
variant={TextVariant.bodyMd}
fontWeight={FONT_WEIGHT.BOLD}
Expand Down Expand Up @@ -61,10 +52,6 @@ Label.propTypes = {
* If true the label will display as required
*/
required: PropTypes.bool,
/**
* Whether the label is disabled or not
*/
disabled: PropTypes.bool,
/**
* Additional classNames to be added to the label component
*/
Expand Down
6 changes: 0 additions & 6 deletions ui/components/component-library/label/label.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
.mm-label {
--label-opacity-disabled: 0.5; // TODO: replace with design token

&--html-for {
cursor: pointer;
}

&--disabled {
opacity: var(--label-opacity-disabled);
}
}
8 changes: 0 additions & 8 deletions ui/components/component-library/label/label.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ export default {
required: {
control: 'boolean',
},
disabled: {
control: 'boolean',
},
children: {
control: 'text',
},
Expand Down Expand Up @@ -104,8 +101,3 @@ export const Required = Template.bind({});
Required.args = {
required: true,
};

export const Disabled = Template.bind({});
Disabled.args = {
disabled: true,
};
4 changes: 0 additions & 4 deletions ui/components/component-library/label/label.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,4 @@ describe('label', () => {
expect(getByText('label')).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');
});
});

0 comments on commit e2e2f65

Please sign in to comment.