1- import React from "react" ;
2- import styled from "styled-components" ;
1+ import React , { useRef } from "react" ;
2+ import styled , { css } from "styled-components" ;
33
44import { Checkbox , Field , type CheckboxProps , type FieldProps } from "@kleros/ui-components-library" ;
55
66const Container = styled . div `
77 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;
1114` ;
1215
13- const LabelContainer = styled . div `
16+ const ContainerCss = css `
1417 flex : 1 ;
18+ height : 100% ;
1519 display : flex;
1620 align-items : center;
1721 justify-content : center;
1822 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+ ` }
2039` ;
2140
2241const Label = styled . label `
2342 color : ${ ( { theme } ) => theme . klerosUIComponentsPrimaryText } ;
2443` ;
2544
26- const InputContainer = styled ( LabelContainer ) `
45+ const InputContainer = styled . div < { isField ?: boolean } > `
46+ ${ ContainerCss }
2747 position: relative;
28- border-radius: 0px 6px 6px 0px;
48+ border-radius: 0px 3px 3px 0px;
2949 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+ ` }
3058` ;
3159
32- const StyledField = styled ( Field ) `
33- width: auto ;
60+ const StyledField = styled ( Field ) < { paddingLeft ?: number } > `
61+ width: 100% ;
3462 > input {
3563 border: none;
64+ box-sizing: border-box;
65+ ${ ( { paddingLeft } ) =>
66+ paddingLeft &&
67+ css `
68+ padding-left : ${ paddingLeft + 8 } px;
69+ ` }
3670 }
3771` ;
3872
@@ -53,13 +87,14 @@ type DefaultInputProps = FieldProps & { inputType?: "field" };
5387type LabeledInputProps = BaseProps & ( CheckboxInputProps | DefaultInputProps ) ;
5488
5589const LabeledInput : React . FC < LabeledInputProps > = ( { inputType = "field" , label, ...props } ) => {
90+ const labelRef = useRef < HTMLDivElement > ( null ) ;
5691 return (
5792 < Container >
58- < LabelContainer >
93+ < LabelContainer ref = { labelRef } isField = { inputType === "field" } >
5994 < Label > { label } </ Label >
6095 </ LabelContainer >
61- < InputContainer >
62- { inputType === "field" && < StyledField { ...props } /> }
96+ < InputContainer isField = { inputType === "field" } >
97+ { inputType === "field" && < StyledField { ...props } paddingLeft = { labelRef . current ?. offsetWidth } /> }
6398 { inputType === "checkbox" && < StyledCheckbox label = " " { ...props } /> }
6499 </ InputContainer >
65100 </ Container >
0 commit comments