Skip to content

Commit 2c62886

Browse files
committed
refactor(web-devtools): update-labeled-input-style
1 parent 9ce49a2 commit 2c62886

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

web-devtools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
"dependencies": {
4747
"@kleros/kleros-sdk": "workspace:^",
48-
"@kleros/ui-components-library": "^2.10.0",
48+
"@kleros/ui-components-library": "^2.15.0",
4949
"graphql": "^16.9.0",
5050
"next": "14.2.4",
5151
"react": "^18.2.0",

web-devtools/src/components/LabeledInput.tsx

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,72 @@
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

44
import { Checkbox, Field, type CheckboxProps, type FieldProps } from "@kleros/ui-components-library";
55

66
const 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

2241
const 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" };
5387
type LabeledInputProps = BaseProps & (CheckboxInputProps | DefaultInputProps);
5488

5589
const 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="&nbsp;" {...props} />}
6499
</InputContainer>
65100
</Container>

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7989,7 +7989,7 @@ __metadata:
79897989
"@graphql-codegen/cli": "npm:^5.0.2"
79907990
"@graphql-codegen/client-preset": "npm:^4.3.2"
79917991
"@kleros/kleros-sdk": "workspace:^"
7992-
"@kleros/ui-components-library": "npm:^2.10.0"
7992+
"@kleros/ui-components-library": "npm:^2.15.0"
79937993
"@svgr/webpack": "npm:^8.1.0"
79947994
"@types/node": "npm:^20"
79957995
"@types/react": "npm:18.2.0"
@@ -8098,9 +8098,9 @@ __metadata:
80988098
languageName: unknown
80998099
linkType: soft
81008100

8101-
"@kleros/ui-components-library@npm:^2.10.0":
8102-
version: 2.13.1
8103-
resolution: "@kleros/ui-components-library@npm:2.13.1"
8101+
"@kleros/ui-components-library@npm:^2.14.0":
8102+
version: 2.14.0
8103+
resolution: "@kleros/ui-components-library@npm:2.14.0"
81048104
dependencies:
81058105
"@datepicker-react/hooks": "npm:^2.8.4"
81068106
"@swc/helpers": "npm:^0.3.2"
@@ -8117,13 +8117,13 @@ __metadata:
81178117
react-dom: ^18.0.0
81188118
react-is: ^18.0.0
81198119
styled-components: ^5.3.3
8120-
checksum: db710e97b09a291ad5b6ff7a7a046cd3945e0403fda66ce6b33e501609ad2b712f924e84df2cba273d4ee936d274a6b7f210ff269d27d504bc81bcb712bc9da1
8120+
checksum: ea5d9689562a6aa963eda44ad94336d4152c5d0f46c81e70a0c271a09fb93e9c9fd7b4ee609b1f6e1eb6e18f557f1cc0b132c3ac10d9f5af6ffc911ecb71d9da
81218121
languageName: node
81228122
linkType: hard
81238123

8124-
"@kleros/ui-components-library@npm:^2.14.0":
8125-
version: 2.14.0
8126-
resolution: "@kleros/ui-components-library@npm:2.14.0"
8124+
"@kleros/ui-components-library@npm:^2.15.0":
8125+
version: 2.15.0
8126+
resolution: "@kleros/ui-components-library@npm:2.15.0"
81278127
dependencies:
81288128
"@datepicker-react/hooks": "npm:^2.8.4"
81298129
"@swc/helpers": "npm:^0.3.2"
@@ -8140,7 +8140,7 @@ __metadata:
81408140
react-dom: ^18.0.0
81418141
react-is: ^18.0.0
81428142
styled-components: ^5.3.3
8143-
checksum: ea5d9689562a6aa963eda44ad94336d4152c5d0f46c81e70a0c271a09fb93e9c9fd7b4ee609b1f6e1eb6e18f557f1cc0b132c3ac10d9f5af6ffc911ecb71d9da
8143+
checksum: 7c97e8fe45b1cd002a0aaf7fe4670b8c668a3abbbab82fac9261ef9a8382ccaf7d4a974ee54b8f299f1e8e7b68e58dab1f3f31d7c8b3b60c58a5af8abdf4a783
81448144
languageName: node
81458145
linkType: hard
81468146

0 commit comments

Comments
 (0)