Skip to content

Commit

Permalink
Simplify ErrorMarker component
Browse files Browse the repository at this point in the history
Just support the actual prop in use (`isVisible`) and drop passing a
child.
  • Loading branch information
bjoernricks committed Jun 18, 2024
1 parent ef22a6f commit 857f8ff
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/web/components/form/ErrorMarker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@ import React from 'react';

import styled from 'styled-components';

import {styledExcludeProps} from 'web/utils/styledConfig';
import Theme from 'web/utils/theme';
import PropTypes from 'web/utils/proptypes';

const StyledMarker = styledExcludeProps(styled.div, ['isVisible'])`
const StyledMarker = styled.div`
color: ${Theme.darkRed};
color: ${props => props.color};
font-weight: bold;
font-size: 19px;
padding-bottom: 1px;
padding-left: 4px;
display: ${props => (props.isVisible ? 'inline' : 'none')};
display: ${props => (props.$isVisible ? 'inline' : 'none')};
`;

const ErrorMarker = props => (
<StyledMarker {...props} data-testid="error-marker">
const ErrorMarker = ({isVisible}) => (
<StyledMarker $isVisible={isVisible} data-testid="error-marker">
×
</StyledMarker>
);

ErrorMarker.propTypes = {
isVisible: PropTypes.bool,
};

export default ErrorMarker;
2 changes: 1 addition & 1 deletion src/web/components/form/multiselect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class MultiSelect extends React.Component {
</Menu>
)}
</SelectContainer>
<ErrorMarker isVisible={hasError}>×</ErrorMarker>
<ErrorMarker isVisible={hasError} />
</Div>
);
}}
Expand Down
2 changes: 1 addition & 1 deletion src/web/components/form/select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class Select extends React.Component {
</Menu>
)}
</SelectContainer>
<ErrorMarker isVisible={hasError}>×</ErrorMarker>
<ErrorMarker isVisible={hasError} />
</Div>
);
}}
Expand Down
2 changes: 1 addition & 1 deletion src/web/components/form/textarea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const TextArea = ({
value={value}
onChange={handleChange}
/>
<ErrorMarker isVisible={hasError}>×</ErrorMarker>
<ErrorMarker isVisible={hasError} />
</React.Fragment>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/web/components/form/textfield.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const TextField = ({hasError = false, errorContent, title, ...props}) => {
title={hasError ? `${errorContent}` : title}
type="text"
/>
<ErrorMarker isVisible={hasError}>×</ErrorMarker>
<ErrorMarker isVisible={hasError} />
</React.Fragment>
);
};
Expand Down

0 comments on commit 857f8ff

Please sign in to comment.