Add new ValidationCheckmark component
This commit is contained in:
parent
08f114a15c
commit
4fc43afe1b
2 changed files with 57 additions and 0 deletions
|
@ -0,0 +1,29 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { render, screen } from '../../jest/test-helpers';
|
||||||
|
import ValidationCheckmark from '../validation-checkmark';
|
||||||
|
|
||||||
|
describe('<ValidationCheckmark />', () => {
|
||||||
|
it('renders text', () => {
|
||||||
|
const text = 'some validation';
|
||||||
|
render(<ValidationCheckmark text={text} isValid />);
|
||||||
|
|
||||||
|
expect(screen.getByTestId('validation-checkmark')).toHaveTextContent(text);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses a green check when valid', () => {
|
||||||
|
const text = 'some validation';
|
||||||
|
render(<ValidationCheckmark text={text} isValid />);
|
||||||
|
|
||||||
|
expect(screen.getByTestId('svg-icon-loader')).toHaveClass('text-success-500');
|
||||||
|
expect(screen.getByTestId('svg-icon-loader')).not.toHaveClass('text-gray-500');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses a gray check when valid', () => {
|
||||||
|
const text = 'some validation';
|
||||||
|
render(<ValidationCheckmark text={text} isValid={false} />);
|
||||||
|
|
||||||
|
expect(screen.getByTestId('svg-icon-loader')).toHaveClass('text-gray-500');
|
||||||
|
expect(screen.getByTestId('svg-icon-loader')).not.toHaveClass('text-success-500');
|
||||||
|
});
|
||||||
|
});
|
28
app/soapbox/components/validation-checkmark.tsx
Normal file
28
app/soapbox/components/validation-checkmark.tsx
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { HStack, Icon, Text } from 'soapbox/components/ui';
|
||||||
|
|
||||||
|
interface IValidationCheckmark {
|
||||||
|
isValid: boolean
|
||||||
|
text: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const ValidationCheckmark = ({ isValid, text }: IValidationCheckmark) => {
|
||||||
|
return (
|
||||||
|
<HStack alignItems='center' space={2} data-testid='validation-checkmark'>
|
||||||
|
<Icon
|
||||||
|
src={require('@tabler/icons/icons/check.svg')}
|
||||||
|
className={classNames({
|
||||||
|
'w-4 h-4': true,
|
||||||
|
'text-gray-500': !isValid,
|
||||||
|
'text-success-500': isValid,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Text theme='muted' size='sm'>{text}</Text>
|
||||||
|
</HStack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ValidationCheckmark;
|
Loading…
Reference in a new issue