Skip to content

Commit 596791f

Browse files
authored
fix(styles): Remove components that import conflicting global styles (#512)
1 parent 179268f commit 596791f

File tree

6 files changed

+54
-18
lines changed

6 files changed

+54
-18
lines changed

src/components/ReplyField/ReplyField.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
@import '~box-ui-elements/es/styles/variables';
2-
@import '~draft-js/dist/Draft.css';
32

43
.ba-ReplyField {
4+
@import '~draft-js/dist/Draft';
5+
56
.public-DraftEditorPlaceholder-hasFocus,
67
.public-DraftEditorPlaceholder-root {
78
margin: 0;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, { HTMLAttributes } from 'react';
2+
import classNames from 'classnames';
3+
4+
export type Props = {
5+
children?: React.ReactNode;
6+
isDisabled?: boolean;
7+
isPrimary?: boolean;
8+
type: 'button' | 'submit' | 'reset' | undefined;
9+
} & HTMLAttributes<HTMLButtonElement>;
10+
11+
export default function ReplyButton({ children, isDisabled, isPrimary, ...rest }: Props): JSX.Element {
12+
return (
13+
<button
14+
aria-disabled={isDisabled ? true : undefined}
15+
className={classNames('btn', {
16+
'btn-primary': isPrimary,
17+
'is-disabled': isDisabled,
18+
})}
19+
disabled={isDisabled ? true : undefined}
20+
type="button"
21+
{...rest}
22+
>
23+
{children}
24+
</button>
25+
);
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ba-ReplyForm {
2+
margin: 0;
3+
}

src/components/ReplyForm/ReplyForm.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React from 'react';
22
import { getFormattedCommentText } from 'box-ui-elements/es/components/form-elements/draft-js-mention-selector/utils';
3-
import Button from 'box-ui-elements/es/components/button';
4-
import PrimaryButton from 'box-ui-elements/es/components/primary-button';
53
import { KEYS } from 'box-ui-elements/es/constants';
64
import { EditorState } from 'draft-js';
75
import { Form, FormikProps } from 'formik';
86
import { FormattedMessage, useIntl } from 'react-intl';
97
import messages from '../Popups/messages';
8+
import ReplyButton from './ReplyButton';
109
import ReplyField from '../ReplyField';
1110
import { FormValues, PropsFromState as ContainerProps } from './ReplyFormContainer';
11+
import './ReplyForm.scss';
1212

1313
export type ReplyFormProps = {
1414
isPending: boolean;
@@ -27,6 +27,9 @@ const ReplyForm = ({ errors, isPending, onCancel, onChange, setFieldValue, value
2727
const hasErrors = Object.keys(errors).length > 0;
2828
const { editorState } = values;
2929

30+
const handleCancel = (): void => {
31+
onCancel(getFormattedCommentText(editorState).text);
32+
};
3033
// Instead of deferring to the Formik handleChange helper, we need to use the setFieldValue helper
3134
// method in order for DraftJS to work correctly by setting back the whole editorState
3235
const handleChange = (nextEditorState: EditorState): void => {
@@ -57,12 +60,12 @@ const ReplyForm = ({ errors, isPending, onCancel, onChange, setFieldValue, value
5760
/>
5861
</div>
5962
<div className="ba-Popup-footer">
60-
<Button data-testid="ba-Popup-cancel" isDisabled={isPending} onClick={onCancel} type="button">
63+
<ReplyButton data-testid="ba-Popup-cancel" isDisabled={isPending} onClick={handleCancel} type="button">
6164
<FormattedMessage {...messages.buttonCancel} />
62-
</Button>
63-
<PrimaryButton data-testid="ba-Popup-submit" isDisabled={hasErrors || isPending} type="submit">
65+
</ReplyButton>
66+
<ReplyButton data-testid="ba-Popup-submit" isDisabled={hasErrors || isPending} isPrimary type="submit">
6467
<FormattedMessage {...messages.buttonPost} />
65-
</PrimaryButton>
68+
</ReplyButton>
6669
</div>
6770
</Form>
6871
);

src/components/ReplyForm/ReplyFormContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const ReplyFormContainer = connect(mapStateToProps)(
6868
handleSubmit,
6969
mapPropsToValues,
7070
validate,
71+
validateOnMount: true,
7172
})(ReplyForm),
7273
);
7374

src/components/ReplyForm/__tests__/ReplyForm-test.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as React from 'react';
2-
import Button from 'box-ui-elements/es/components/button';
3-
import PrimaryButton from 'box-ui-elements/es/components/primary-button';
42
import { EditorState } from 'draft-js';
53
import { Form } from 'formik';
64
import { KEYS } from 'box-ui-elements/es/constants';
75
import { shallow, ShallowWrapper } from 'enzyme';
6+
import ReplyButton from '../ReplyButton';
87
import ReplyForm, { Props } from '../ReplyForm';
98
import ReplyField from '../../ReplyField';
109
import { mockEvent } from '../../../common/__mocks__/events';
@@ -32,28 +31,31 @@ describe('components/ReplyForm/ReplyForm', () => {
3231
const getWrapper = (props = {}): ShallowWrapper<Props, undefined> =>
3332
shallow(<ReplyForm {...defaults} {...props} />);
3433

35-
test('should render Form with ReplyField and Buttons in the footer', () => {
34+
test('should render Form with ReplyField and buttons in the footer', () => {
3635
const wrapper = getWrapper();
3736

3837
expect(wrapper.exists(Form)).toBe(true);
3938
expect(wrapper.exists(ReplyField)).toBe(true);
40-
expect(wrapper.exists(Button)).toBe(true);
41-
expect(wrapper.exists(PrimaryButton)).toBe(true);
39+
expect(wrapper.find(ReplyButton).length).toBe(2);
4240
});
4341

44-
test('should have buttons be disabled if isPending is true', () => {
42+
test('should disable the buttons and form if isPending is true', () => {
4543
const wrapper = getWrapper({ isPending: true });
44+
const cancel = wrapper.find(ReplyButton).at(0);
45+
const submit = wrapper.find(ReplyButton).at(1);
4646

4747
expect(wrapper.find(ReplyField).prop('isDisabled')).toBe(true);
48-
expect(wrapper.find(Button).prop('isDisabled')).toBe(true);
49-
expect(wrapper.find(PrimaryButton).prop('isDisabled')).toBe(true);
48+
expect(cancel.prop('isDisabled')).toBe(true);
49+
expect(submit.prop('isDisabled')).toBe(true);
5050
});
5151

52-
test('should disable PrimaryButton if has errors', () => {
52+
test('should disable the submit button if the form has errors', () => {
5353
const wrapper = getWrapper({ errors: { foo: 'bar' } });
54+
const cancel = wrapper.find(ReplyButton).at(0);
55+
const submit = wrapper.find(ReplyButton).at(1);
5456

55-
expect(wrapper.find(Button).prop('isDisabled')).toBe(false);
56-
expect(wrapper.find(PrimaryButton).prop('isDisabled')).toBe(true);
57+
expect(cancel.prop('isDisabled')).toBe(false);
58+
expect(submit.prop('isDisabled')).toBe(true);
5759
});
5860

5961
test('should call the handleChange callback when change event occurs on ReplyField', () => {

0 commit comments

Comments
 (0)