Skip to content

Commit b75e0d9

Browse files
author
lena.rashkovan
committed
feat: support absent label in fields
1 parent 9e9ca90 commit b75e0d9

File tree

16 files changed

+54
-51
lines changed

16 files changed

+54
-51
lines changed

src/components/experimental/ComboBox/ComboBox.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from 'react-aria-components';
88
import { useIsSSR } from 'react-aria';
99
import { useResizeObserver } from '@react-aria/utils';
10-
import styled from 'styled-components';
1110
import { Popover } from '../Popover/Popover';
1211
import { ListBox } from '../ListBox/ListBox';
1312
import { FakeInput } from '../Field/FakeInput';
@@ -27,11 +26,8 @@ const defaultAriaStrings = {
2726
messageFieldIsCleared: 'The field is cleared'
2827
};
2928

30-
const StyledPopover = styled(Popover)`
31-
overflow: auto;
32-
`;
33-
34-
interface ComboBoxFieldProps extends Pick<FieldProps, 'label' | 'description' | 'errorMessage' | 'leadingIcon'> {
29+
interface ComboBoxFieldProps extends Pick<FieldProps, 'description' | 'errorMessage' | 'leadingIcon'> {
30+
label: string;
3531
placeholder?: string;
3632
/**
3733
* If your project supports multiple languages,
@@ -135,12 +131,9 @@ function ComboBoxComponent<T extends Record<string, unknown>>(
135131
/>
136132
<Footer>{isInvalid ? <FieldError>{errorMessage}</FieldError> : description}</Footer>
137133
</Wrapper>
138-
<StyledPopover
139-
triggerRef={triggerRef}
140-
style={{ '--trigger-width': menuWidth } as React.CSSProperties}
141-
>
134+
<Popover triggerRef={triggerRef} style={{ '--trigger-width': menuWidth } as React.CSSProperties}>
142135
<ListBox>{children}</ListBox>
143-
</StyledPopover>
136+
</Popover>
144137
</>
145138
)}
146139
</BaseComboBox>

src/components/experimental/DateField/DateField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const DateField = React.forwardRef<HTMLDivElement, DateFieldProps>(
2424
<FakeInput $isVisuallyFocused={isVisuallyFocused}>
2525
{leadingIcon}
2626
<InnerWrapper>
27-
<Label $flying>{label}</Label>
27+
{label && <Label $flying>{label}</Label>}
2828
<DateInput>{segment => <DateSegment segment={segment} />}</DateInput>
2929
</InnerWrapper>
3030
{actionIcon}

src/components/experimental/DatePicker/DatePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Button } from '../Field/Button';
1515
import { FieldProps } from '../Field/Props';
1616

1717
interface DatePickerProps extends Pick<FieldProps, 'description' | 'errorMessage'>, BaseDatePickerProps<DateValue> {
18-
label: string;
18+
label?: string;
1919
}
2020

2121
const StyledPopover = styled(Popover)`

src/components/experimental/Field/FakeInput.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const focusStyles = css`
1515
`;
1616

1717
export const FakeInput = styled.div<{ $isVisuallyFocused: boolean }>`
18-
box-sizing: content-box;
18+
box-sizing: border-box;
1919
cursor: text;
2020
2121
color: ${getSemanticValue('on-surface-variant')};
@@ -25,15 +25,15 @@ export const FakeInput = styled.div<{ $isVisuallyFocused: boolean }>`
2525
border-color: ${getSemanticValue('outline-variant')};
2626
border-radius: ${get('radii.4')};
2727
28-
padding: ${get('space.2')} ${get('space.3')} ${get('space.2')} ${get('space.4')};
28+
min-height: 3.5rem;
29+
padding: 0 ${get('space.3')} 0 ${get('space.4')};
2930
display: flex;
30-
align-items: start;
31+
align-items: center;
3132
gap: ${get('space.3')};
3233
3334
/* stylelint-disable selector-type-case, selector-type-no-unknown */
3435
& > :not(${InnerWrapper}) {
3536
flex-shrink: 0;
36-
margin-top: ${get('space.2')};
3737
color: ${getSemanticValue('on-surface-variant')};
3838
}
3939

src/components/experimental/Field/Field.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import styled, { css } from 'styled-components';
22
import { DateInput as BaseDateInput, Input as BaseInput, TextArea as BaseTextArea } from 'react-aria-components';
33
import { getSemanticValue } from '../../../essentials/experimental';
4-
import { textStyles } from '../Text/Text';
54

6-
export const fieldTextStyles = textStyles.variants.body1;
5+
export const fieldTextStyles = css`
6+
font-family: inherit;
7+
font-size: var(--wave-exp-typescale-body-1-size);
8+
font-weight: var(--wave-exp-typescale-body-1-weight);
9+
line-height: var(--wave-exp-typescale-body-1-line-height);
10+
`;
711

812
export const fieldStyles = css`
913
border: none;
@@ -38,7 +42,7 @@ export const TextArea = styled(BaseTextArea).attrs({ rows: 1 })`
3842
${fieldStyles};
3943
4044
resize: none;
41-
min-height: ${fieldTextStyles.lineHeight};
45+
min-height: var(--wave-exp-typescale-body-1-line-height);
4246
`;
4347

4448
export const DateInput = styled(BaseDateInput)`
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import styled from 'styled-components';
2-
import { get } from '../../../utils/experimental/themeGet';
2+
import { Label } from './Label';
33

44
export const InnerWrapper = styled.div`
5-
width: 100%;
6-
padding-top: ${get('space.4')};
7-
85
position: relative;
96
overflow: hidden;
7+
8+
box-sizing: border-box;
9+
width: 100%;
10+
11+
/* stylelint-disable selector-type-no-unknown */
12+
&:has(${Label}) {
13+
padding-top: var(--wave-exp-typescale-label-2-line-height);
14+
}
1015
`;

src/components/experimental/Field/Label.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
import { Label as BaseLabel } from 'react-aria-components';
22
import styled, { css } from 'styled-components';
33
import { getSemanticValue } from '../../../essentials/experimental';
4-
import { textStyles } from '../Text/Text';
54

65
export const flyingLabelStyles = css`
76
top: 0;
8-
transform: translate3d(0, 0, 0);
7+
transform: none;
98
10-
${textStyles.variants.label2}
9+
font-size: var(--wave-exp-typescale-label-2-size);
10+
font-weight: var(--wave-exp-typescale-label-2-weight);
11+
line-height: var(--wave-exp-typescale-label-2-line-height);
1112
`;
1213

1314
export const Label = styled(BaseLabel)<{ $flying: boolean }>`
1415
position: absolute;
1516
top: 50%;
1617
color: currentColor;
1718
18-
${textStyles.variants.body1}
19+
font-family: inherit;
20+
font-size: var(--wave-exp-typescale-body-1-size);
21+
font-weight: var(--wave-exp-typescale-body-1-weight);
22+
line-height: var(--wave-exp-typescale-body-1-line-height);
1923
white-space: nowrap;
2024
21-
transform: translate3d(0, calc(-${textStyles.variants.body1.lineHeight} / 2), 0);
25+
transform: translateY(-50%);
2226
transform-origin: 0;
2327
2428
transition: top 200ms ease, font-size 200ms ease, transform 200ms ease;

src/components/experimental/Field/Props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
export interface FieldProps {
4-
label: string;
4+
label?: string;
55
leadingIcon?: React.ReactNode;
66
actionIcon?: React.ReactNode;
77
description?: string;

src/components/experimental/NumberField/NumberField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const NumberField = React.forwardRef<HTMLDivElement, NumberFieldProps>(
6161
<>
6262
<FakeInput $isVisuallyFocused={isVisuallyFocused}>
6363
<InnerWrapper>
64-
<Label $flying>{label}</Label>
64+
{label && <Label $flying>{label}</Label>}
6565
<Input />
6666
</InnerWrapper>
6767
<GroupControl>

src/components/experimental/NumberField/docs/NumberField.stories.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ const meta: Meta = {
1414
<Story />
1515
</div>
1616
)
17-
],
18-
args: {
19-
label: 'Group size'
20-
}
17+
]
2118
};
2219

2320
export default meta;
@@ -28,12 +25,14 @@ export const Default: Story = {};
2825

2926
export const WithDefaultValue: Story = {
3027
args: {
28+
label: 'Group size',
3129
defaultValue: 5
3230
}
3331
};
3432

3533
export const WithDescription: Story = {
3634
args: {
35+
label: 'Group size',
3736
description: 'Number of passengers'
3837
}
3938
};

0 commit comments

Comments
 (0)