Skip to content

Commit 14850e9

Browse files
author
Ivan Bulakhov
committed
fix: improve spaces when label is not defined (#450)
The margin has been removed in favour of gap to get rid of unnecessary indentation when label undefined
1 parent 46fe18c commit 14850e9

File tree

9 files changed

+24
-7
lines changed

9 files changed

+24
-7
lines changed

src/components/Checkbox/Checkbox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const WithTapAreaWrapper = styled.div<Pick<CheckboxProps, 'textVerticalAlign'>>`
3838
align-items: center;
3939
4040
height: 1rem;
41-
margin: 0 0.5rem 0 0;
41+
margin: 0 0 0 0;
4242
${({ textVerticalAlign }) => (textVerticalAlign === 'top' ? 'margin-top: 0.1875rem' : undefined)}
4343
`;
4444

src/components/Checkbox/components/LabelWrapper.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ const LabelWrapper = styled.label.attrs({ theme })<LabelWrapperProps>`
7979
font-family: ${get('fonts.normal')};
8080
line-height: 1;
8181
82+
gap: 0.5rem;
83+
8284
&:hover {
8385
${hoverStyle}
8486
}

src/components/Checkbox/docs/Checkbox.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export default meta;
2323

2424
type Story = StoryObj<typeof Checkbox>;
2525

26-
export const Default: Story = {};
26+
export const Default: Story = {
27+
args: {
28+
label: undefined
29+
}
30+
};
2731

2832
export const Selected: Story = {
2933
args: {

src/components/RadioButton/RadioButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TapArea } from './components/TapArea';
1010
import { RadioButtonProps } from './RadioButtonProps';
1111

1212
const WithTapAreaWrapper = styled.div<Pick<RadioButtonProps, 'textVerticalAlign'>>`
13-
width: 1.5rem;
13+
width: 1rem;
1414
position: relative;
1515
display: inline-flex;
1616
align-items: center;

src/components/RadioButton/components/Checkmark.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Checkmark = styled.input<CheckmarkProps>`
1515
width: 1rem;
1616
height: 1rem;
1717
padding: 0;
18-
margin: 0 0.5rem 0 0;
18+
margin: 0 0 0 0;
1919
2020
background-color: ${getSemanticValue('background-page-default')};
2121
box-shadow: inset 0 0 0 0.125rem

src/components/RadioButton/components/LabelWrapper.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const LabelWrapper = styled.label.attrs({ theme })<LabelWrapperProps>`
6363
font-family: ${get('fonts.normal')};
6464
line-height: 1;
6565
66+
gap: 0.5rem;
67+
6668
&:hover {
6769
${hoverStyle}
6870
}

src/components/Toggle/Label.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const Label = styled.label<LabelProps>`
1111
cursor: ${props => (props.disabled ? 'not-allowed' : 'pointer')};
1212
user-select: none;
1313
14+
gap: 0.5rem;
15+
1416
${margin}
1517
`;
1618

src/components/Toggle/Slide.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const Slide = styled.div<SlideProps>`
3131
display: inline-block;
3232
border-radius: 0.5rem;
3333
position: relative;
34-
margin-right: 0.5rem;
3534
3635
&::before {
3736
content: '';

src/components/Toggle/Toggle.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { ComponentPropsWithoutRef, FC, ReactNode, Ref } from 'react';
2+
import styled from 'styled-components';
23
import { MarginProps } from 'styled-system';
34

45
import { ClassNameProps, extractClassNameProps, extractWrapperMarginProps } from '../../utils/extractProps';
@@ -22,6 +23,11 @@ interface ToggleProps extends ToggleHtmlInputProps, ClassNameProps, MarginProps
2223
error?: boolean;
2324
}
2425

26+
const SlideWrapper = styled.span`
27+
display: inline-flex;
28+
align-items: center;
29+
`;
30+
2531
const Toggle: FC<ToggleProps> = props => {
2632
const { classNameProps, restProps: withoutClassName } = extractClassNameProps(props);
2733
const { marginProps, restProps } = extractWrapperMarginProps(withoutClassName);
@@ -34,8 +40,10 @@ const Toggle: FC<ToggleProps> = props => {
3440

3541
return (
3642
<Label disabled={disabled} {...classNameProps} {...marginProps}>
37-
<Input disabled={disabled} error={error} {...rest} type="checkbox" />
38-
<Slide disabled={disabled} error={error} />
43+
<SlideWrapper>
44+
<Input disabled={disabled} error={error} {...rest} type="checkbox" />
45+
<Slide disabled={disabled} error={error} />
46+
</SlideWrapper>
3947
{dynamicLabel}
4048
</Label>
4149
);

0 commit comments

Comments
 (0)