1
- import React from "react" ;
2
- import styled from "styled-components" ;
1
+ import React , { useRef } from "react" ;
2
+ import styled , { css } from "styled-components" ;
3
3
4
4
import { Checkbox , Field , type CheckboxProps , type FieldProps } from "@kleros/ui-components-library" ;
5
5
6
6
const Container = styled . div `
7
7
display : flex;
8
- max-width: 300px;
9
- min-width: 250px;
10
- height: 50px;
8
+ align-items : center;
9
+ width : 280px ;
10
+ max-width : 280px ;
11
+ height : 46px ;
12
+ position : relative;
13
+ box-sizing : border-box;
11
14
` ;
12
15
13
- const LabelContainer = styled . div `
16
+ const ContainerCss = css `
14
17
flex : 1 ;
18
+ height : 100% ;
15
19
display : flex;
16
20
align-items : center;
17
21
justify-content : center;
18
22
border : 1px solid ${ ( { theme } ) => theme . klerosUIComponentsStroke } ;
19
- border-radius: 6px 0px 0px 6px;
23
+ ` ;
24
+
25
+ const LabelContainer = styled . div < { isField ?: boolean } > `
26
+ ${ ContainerCss }
27
+ border-radius: 3px 0px 0px 3px;
28
+ background-color: ${ ( { theme } ) => theme . klerosUIComponentsLightBackground } ;
29
+ ${ ( { isField } ) =>
30
+ isField &&
31
+ css `
32
+ width : 50% ;
33
+ height : 45px ;
34
+ position : absolute;
35
+ top : 0.5px ;
36
+ left : 0.5px ;
37
+ z-index : 1 ;
38
+ ` }
20
39
` ;
21
40
22
41
const Label = styled . label `
23
42
color : ${ ( { theme } ) => theme . klerosUIComponentsPrimaryText } ;
24
43
` ;
25
44
26
- const InputContainer = styled ( LabelContainer ) `
45
+ const InputContainer = styled . div < { isField ?: boolean } > `
46
+ ${ ContainerCss }
27
47
position: relative;
28
- border-radius: 0px 6px 6px 0px;
48
+ border-radius: 0px 3px 3px 0px;
29
49
border-left: none;
50
+ background-color: ${ ( { theme } ) => theme . klerosUIComponentsWhiteBackground } ;
51
+ ${ ( { isField } ) =>
52
+ isField &&
53
+ css `
54
+ width : 100% ;
55
+ z-index : 0 ;
56
+ border-radius : 3px ;
57
+ ` }
30
58
` ;
31
59
32
- const StyledField = styled ( Field ) `
33
- width: auto ;
60
+ const StyledField = styled ( Field ) < { paddingLeft ?: number } > `
61
+ width: 100% ;
34
62
> input {
35
63
border: none;
64
+ box-sizing: border-box;
65
+ ${ ( { paddingLeft } ) =>
66
+ paddingLeft &&
67
+ css `
68
+ padding-left : ${ paddingLeft + 8 } px;
69
+ ` }
36
70
}
37
71
` ;
38
72
@@ -53,13 +87,14 @@ type DefaultInputProps = FieldProps & { inputType?: "field" };
53
87
type LabeledInputProps = BaseProps & ( CheckboxInputProps | DefaultInputProps ) ;
54
88
55
89
const LabeledInput : React . FC < LabeledInputProps > = ( { inputType = "field" , label, ...props } ) => {
90
+ const labelRef = useRef < HTMLDivElement > ( null ) ;
56
91
return (
57
92
< Container >
58
- < LabelContainer >
93
+ < LabelContainer ref = { labelRef } isField = { inputType === "field" } >
59
94
< Label > { label } </ Label >
60
95
</ LabelContainer >
61
- < InputContainer >
62
- { inputType === "field" && < StyledField { ...props } /> }
96
+ < InputContainer isField = { inputType === "field" } >
97
+ { inputType === "field" && < StyledField { ...props } paddingLeft = { labelRef . current ?. offsetWidth } /> }
63
98
{ inputType === "checkbox" && < StyledCheckbox label = " " { ...props } /> }
64
99
</ InputContainer >
65
100
</ Container >
0 commit comments