Skip to content

Commit

Permalink
feat(textinput): add variant support to TextInput
Browse files Browse the repository at this point in the history
Added easy styling options to TextInput with a variant prop supporting outline, fill, and text
options.

re #256
  • Loading branch information
PatrickDeVries committed Oct 25, 2021
1 parent a6a8921 commit f88aac8
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/components/TextInput/__tests__/TextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from 'styled-components';
import { render, configure, waitFor } from '@testing-library/react';
import TextInput from '../TextInput';
import { axe, toHaveNoViolations } from 'jest-axe';
import variants from '../../../enums/variants';

expect.extend(toHaveNoViolations);
configure({ testIdAttribute: 'data-test-id' });
Expand All @@ -11,6 +12,27 @@ const testId = 'foundry-text-input';
const containerProps = { 'data-test-id': testId };

describe('TextInput', () => {
describe('Rendering tests', () => {
it('Shows TextInput with default props', async () => {
const { container, getByTestId } = render(<TextInput containerProps={containerProps} />);
await waitFor(() => getByTestId(testId));
expect(container).toMatchSnapshot();
});
it('Shows TextInput with fill variant', async () => {
const { container, getByTestId } = render(
<TextInput variant={variants.fill} containerProps={containerProps} />,
);
await waitFor(() => getByTestId(testId));
expect(container).toMatchSnapshot();
});
it('Shows TextInput with text variant', async () => {
const { container, getByTestId } = render(
<TextInput variant={variants.text} containerProps={containerProps} />,
);
await waitFor(() => getByTestId(testId));
expect(container).toMatchSnapshot();
});
});
describe('Accessibility Tests', () => {
it('Should pass accessibility test with default props', async () => {
const component = <TextInput aria-label="text-input"></TextInput>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TextInput Rendering tests Shows TextInput with default props 1`] = `
.c0 {
min-width: 10rem;
position: relative;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-flow: row;
-ms-flex-flow: row;
flex-flow: row;
border-radius: 0.25em;
border: 1px solid #51575D;
background-color: #fff;
}
.c1 {
border: 0 none;
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
flex-grow: 1;
outline: 0 none;
font-size: 1em;
padding: 0.5rem;
background-color: transparent;
}
.c1:focus {
outline: none;
box-shadow: 0 0 5px 0.150rem #64ACC5;
}
<div>
<div
class=" c0"
data-test-id="foundry-text-input"
>
<input
class=" c1"
cols="10"
rows="10"
type="text"
/>
</div>
</div>
`;

exports[`TextInput Rendering tests Shows TextInput with fill variant 1`] = `
.c0 {
min-width: 10rem;
position: relative;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-flow: row;
-ms-flex-flow: row;
flex-flow: row;
border-radius: 0.25em;
border: 1px solid transparent;
border-bottom: 1px solid #51575D;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
background-color: #e6e6e6;
}
.c1 {
border: 0 none;
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
flex-grow: 1;
outline: 0 none;
font-size: 1em;
padding: 0.5rem;
background-color: transparent;
}
.c1:focus {
outline: none;
box-shadow: 0 0 5px 0.150rem #64ACC5;
}
<div>
<div
class=" c0"
data-test-id="foundry-text-input"
>
<input
class=" c1"
cols="10"
rows="10"
type="text"
/>
</div>
</div>
`;

exports[`TextInput Rendering tests Shows TextInput with text variant 1`] = `
.c0 {
min-width: 10rem;
position: relative;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-flow: row;
-ms-flex-flow: row;
flex-flow: row;
border-radius: 0.25em;
border: 1px solid transparent;
background-color: #fff;
}
.c1 {
border: 0 none;
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
flex-grow: 1;
outline: 0 none;
font-size: 1em;
padding: 0.5rem;
background-color: transparent;
}
.c1:focus {
outline: none;
box-shadow: 0 0 5px 0.150rem #64ACC5;
}
<div>
<div
class=" c0"
data-test-id="foundry-text-input"
>
<input
class=" c1"
cols="10"
rows="10"
type="text"
/>
</div>
</div>
`;

0 comments on commit f88aac8

Please sign in to comment.