18
18
19
19
import styled from 'styled-components' ;
20
20
21
- import { Box , ButtonIcon , ButtonSecondary , Flex } from 'design' ;
21
+ import { Box , ButtonIcon , ButtonSecondary , Flex , Text } from 'design' ;
22
22
import * as Icons from 'design/Icon' ;
23
23
import { inputGeometry } from 'design/Input/Input' ;
24
+ import { IconTooltip } from 'design/Tooltip' ;
24
25
import FieldInput from 'shared/components/FieldInput' ;
25
26
import {
26
27
useRule ,
@@ -63,6 +64,8 @@ type LabelValidationResult = {
63
64
export type LabelsRule = Rule < Label [ ] , LabelListValidationResult > ;
64
65
65
66
export function LabelsInput ( {
67
+ legend,
68
+ tooltipContent,
66
69
labels = [ ] ,
67
70
setLabels,
68
71
disableBtns = false ,
@@ -74,6 +77,8 @@ export function LabelsInput({
74
77
inputWidth = 200 ,
75
78
rule = defaultRule ,
76
79
} : {
80
+ legend ?: string ;
81
+ tooltipContent ?: string ;
77
82
labels : Label [ ] ;
78
83
setLabels ( l : Label [ ] ) : void ;
79
84
disableBtns ?: boolean ;
@@ -141,15 +146,34 @@ export function LabelsInput({
141
146
const width = `${ inputWidth } px` ;
142
147
const inputSize = 'medium' ;
143
148
return (
144
- < >
149
+ < Fieldset >
150
+ { legend && (
151
+ < Legend >
152
+ { tooltipContent ? (
153
+ < >
154
+ < span
155
+ css = { {
156
+ marginRight : '4px' ,
157
+ verticalAlign : 'middle' ,
158
+ } }
159
+ >
160
+ { legend }
161
+ </ span >
162
+ < IconTooltip children = { tooltipContent } />
163
+ </ >
164
+ ) : (
165
+ legend
166
+ ) }
167
+ </ Legend >
168
+ ) }
145
169
{ labels . length > 0 && (
146
- < Flex mt = { 2 } >
170
+ < Flex mt = { legend ? 1 : 0 } mb = { 1 } >
147
171
< Box width = { width } mr = "3" >
148
- { labelKey . fieldName } < SmallText > (required field)</ SmallText >
149
- </ Box >
150
- < Box >
151
- { labelVal . fieldName } < SmallText > (required field)</ SmallText >
172
+ < Text typography = "body3" >
173
+ { labelKey . fieldName } (required field)
174
+ </ Text >
152
175
</ Box >
176
+ < Text typography = "body3" > { labelVal . fieldName } (required field)</ Text >
153
177
</ Flex >
154
178
) }
155
179
< Box >
@@ -229,17 +253,12 @@ export function LabelsInput({
229
253
< Icons . Add className = "icon-add" disabled = { disableBtns } size = "small" />
230
254
{ labels . length > 0 ? `Add another ${ adjective } ` : `Add a ${ adjective } ` }
231
255
</ ButtonSecondary >
232
- </ >
256
+ </ Fieldset >
233
257
) ;
234
258
}
235
259
236
260
const defaultRule = ( ) => ( ) => ( { valid : true } ) ;
237
261
238
- const SmallText = styled . span `
239
- font-size: ${ p => p . theme . fontSizes [ 1 ] } px;
240
- font-weight: lighter;
241
- ` ;
242
-
243
262
export const nonEmptyLabels : LabelsRule = labels => ( ) => {
244
263
const results = labels . map ( label => ( {
245
264
name : requiredField ( 'required' ) ( label . name ) ( ) ,
@@ -250,3 +269,15 @@ export const nonEmptyLabels: LabelsRule = labels => () => {
250
269
results : results ,
251
270
} ;
252
271
} ;
272
+
273
+ const Fieldset = styled . fieldset `
274
+ border: none;
275
+ margin: 0;
276
+ padding: 0;
277
+ ` ;
278
+
279
+ const Legend = styled . legend `
280
+ margin: 0 0 ${ props => props . theme . space [ 1 ] } px 0;
281
+ padding: 0;
282
+ ${ props => props . theme . typography . body3 }
283
+ ` ;
0 commit comments