Skip to content

Commit 07e3f25

Browse files
authored
TextArea component (#686)
* TextArea basic structure created * TesxtArea updated missing correct spacing * FieldTextArea component and tests added * FieldTextAread and TextArea ready for review * updates after review
1 parent 73e44a3 commit 07e3f25

File tree

15 files changed

+942
-0
lines changed

15 files changed

+942
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## UNRELEASED
99

10+
### Added
11+
12+
- `TextArea` component was created with documentation and tests
13+
- `FieldTextArea` component was created with documentation and tests
14+
1015
## [0.7.24] - 2020-03-12
1116

1217
### Added
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2020 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
import React from 'react'
28+
import { assertSnapshot } from '@looker/components-test-utils'
29+
30+
import { FieldTextArea } from './FieldTextArea'
31+
32+
test('A FieldTextArea', () => {
33+
assertSnapshot(<FieldTextArea id="FieldTextArea" label="this is a label" />)
34+
})
35+
36+
test('A FieldTextArea with a validation message', () => {
37+
assertSnapshot(
38+
<FieldTextArea
39+
id="errorMessage"
40+
label="this is a label"
41+
validationMessage={{ message: 'This is an error', type: 'error' }}
42+
/>
43+
)
44+
})
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2020 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
import React, { FC } from 'react'
28+
import styled from 'styled-components'
29+
import { v4 as uuid } from 'uuid'
30+
import { useFormContext } from '../../Form'
31+
import { TextArea, TextAreaProps } from '../../Inputs/TextArea'
32+
import { Field, FieldProps, omitFieldProps, pickFieldProps } from '../Field'
33+
34+
export interface FieldTextAreaProps extends FieldProps, TextAreaProps {}
35+
36+
const FieldTextAreaComponent: FC<FieldTextAreaProps> = ({ ...props }) => {
37+
const { id = uuid() } = props
38+
const validationMessage = useFormContext(props)
39+
return (
40+
<Field
41+
id={id}
42+
alignValidationMessage="bottom"
43+
validationMessage={validationMessage}
44+
{...pickFieldProps(props)}
45+
>
46+
<TextArea
47+
{...omitFieldProps(props)}
48+
validationType={validationMessage && validationMessage.type}
49+
/>
50+
</Field>
51+
)
52+
}
53+
54+
FieldTextAreaComponent.displayName = 'FieldTextAreaComponent'
55+
56+
export const FieldTextArea = styled(FieldTextAreaComponent)``
57+
FieldTextArea.defaultProps = { width: '13rem' }

0 commit comments

Comments
 (0)