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

Change: Use .js as file suffix for hooks #4073

Merged
merged 3 commits into from
Jun 19, 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
32 changes: 32 additions & 0 deletions src/web/components/form/ErrorMarker.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* SPDX-FileCopyrightText: 2024 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import React from 'react';

import styled from 'styled-components';

import Theme from 'web/utils/theme';
import PropTypes from 'web/utils/proptypes';

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

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

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

export default ErrorMarker;
5 changes: 2 additions & 3 deletions src/web/components/form/multiselect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


import React from 'react';

import styled from 'styled-components';
Expand Down Expand Up @@ -33,7 +32,7 @@ import {
SelectedValue,
} from './selectelements';

import {Marker} from './useFormValidation';
import ErrorMarker from './ErrorMarker';

const DEFAULT_WIDTH = '250px';

Expand Down Expand Up @@ -278,7 +277,7 @@ class MultiSelect extends React.Component {
</Menu>
)}
</SelectContainer>
<Marker isVisible={hasError}>×</Marker>
<ErrorMarker isVisible={hasError} />
</Div>
);
}}
Expand Down
5 changes: 2 additions & 3 deletions src/web/components/form/select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


import React from 'react';

import Downshift from 'downshift';
Expand Down Expand Up @@ -31,7 +30,7 @@ import {
SelectedValue,
} from './selectelements';

import {Marker} from './useFormValidation';
import ErrorMarker from './ErrorMarker';
import {styledExcludeProps} from 'web/utils/styledConfig';

const SingleSelectedValue = styled(SelectedValue)`
Expand Down Expand Up @@ -279,7 +278,7 @@ class Select extends React.Component {
</Menu>
)}
</SelectContainer>
<Marker isVisible={hasError}>×</Marker>
<ErrorMarker isVisible={hasError} />
</Div>
);
}}
Expand Down
5 changes: 2 additions & 3 deletions src/web/components/form/textarea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


import React, {useCallback} from 'react';
import {isDefined} from 'gmp/utils/identity';
import PropTypes from 'web/utils/proptypes';
Expand All @@ -15,7 +14,7 @@ import Theme from 'web/utils/theme';
import withLayout from 'web/components/layout/withLayout';

import {DISABLED_OPACITY} from './field';
import {Marker} from './useFormValidation';
import ErrorMarker from './ErrorMarker';
import {styledExcludeProps} from 'web/utils/styledConfig';

const StyledTextArea = styledExcludeProps(styled.textarea, [
Expand Down Expand Up @@ -80,7 +79,7 @@ const TextArea = ({
value={value}
onChange={handleChange}
/>
<Marker isVisible={hasError}>×</Marker>
<ErrorMarker isVisible={hasError} />
</React.Fragment>
);
};
Expand Down
5 changes: 2 additions & 3 deletions src/web/components/form/textfield.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


import React from 'react';

import PropTypes from 'web/utils/proptypes';

import Field from './field';
import {Marker} from './useFormValidation';
import ErrorMarker from './ErrorMarker';

const TextField = ({hasError = false, errorContent, title, ...props}) => {
return (
Expand All @@ -20,7 +19,7 @@ const TextField = ({hasError = false, errorContent, title, ...props}) => {
title={hasError ? `${errorContent}` : title}
type="text"
/>
<Marker isVisible={hasError}>×</Marker>
<ErrorMarker isVisible={hasError} />
</React.Fragment>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,12 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


import React, {useState, useEffect, useCallback} from 'react';

import styled from 'styled-components';
import {useState, useEffect, useCallback} from 'react';

import {_, _l} from 'gmp/locale/lang';

import {hasValue, isDefined, isFunction} from 'gmp/utils/identity';

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

const StyledMarker = styledExcludeProps(styled.div, ['isVisible'])`
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')};
`;

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

const useFormValidation = (
validationRules,
values,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


import {useCallback, useState} from 'react';

const useFormValues = (initialValues = {}) => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading