Skip to content

Fix alignment between label and suffix in Field #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-drinks-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cube-dev/ui-kit': patch
---

Fixed alignment between label and suffix in Field component
36 changes: 14 additions & 22 deletions src/components/forms/FieldWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,21 @@ function FieldWrapper(props: CubeFieldWrapperProps, ref) {
{...labelProps}
>
<Flex placeContent="baseline space-between" width="100%">
{tooltip || labelSuffix || extra ? (
<Space placeItems="baseline" gap="0.5x">
{label ? (
tooltip || labelSuffix || extra ? (
<div>{label}</div>
) : (
label
)
) : null}
{tooltip ? (
<TooltipProvider
title={tooltip}
activeWrap
width="initial max-content 40x"
>
<InfoCircleOutlined style={{ color: 'var(--primary-color)' }} />
</TooltipProvider>
) : null}
{labelSuffix && <div>{labelSuffix}</div>}
</Space>
) : (
<Space placeItems="center" gap="1x">
<div>{label}</div>
)}

{tooltip ? (
<TooltipProvider
title={tooltip}
activeWrap
width="initial max-content 40x"
>
<InfoCircleOutlined style={{ color: 'var(--primary-color)' }} />
</TooltipProvider>
) : null}

<div>{labelSuffix}</div>
</Space>

{extra && <Text preset="t3">{extra}</Text>}
</Flex>
Expand Down
24 changes: 24 additions & 0 deletions src/components/forms/Form/Field.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Meta, Story } from '@storybook/react';
import { baseProps } from '../../../stories/lists/baseProps';
import { CubeFieldProps, Field } from './Field';
import { TextInput } from '../TextInput/TextInput';
import { Button } from '../../actions';
import { DollarCircleFilled } from '@ant-design/icons';

export default {
title: 'Forms/Field',
Expand Down Expand Up @@ -77,3 +79,25 @@ WithSuffixExtraAndTooltip.args = {
extra: 'Extra info',
tooltip: 'Long description',
};

export const WithButtonSuffix = Template.bind({});
WithButtonSuffix.args = {
labelSuffix: (
<Button size="small" icon={<DollarCircleFilled />} placeSelf="center" />
),
};

export const WithButtonSuffixAndTooltip = Template.bind({});
WithButtonSuffixAndTooltip.args = {
labelSuffix: (
<Button
width="3x"
height="3x"
type="clear"
size="small"
icon={<DollarCircleFilled />}
placeSelf="center"
/>
),
tooltip: 'Long description',
};
2 changes: 0 additions & 2 deletions src/components/forms/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const INLINE_LABEL_STYLES: Styles = {
color: {
'': '#dark.85',
invalid: '#danger-text',
disabled: '#dark.30',
},
whiteSpace: 'nowrap',
} as const;
Expand All @@ -66,7 +65,6 @@ export const LABEL_STYLES: Styles = {
color: {
'': '#dark',
invalid: '#danger-text',
disabled: '#dark.30',
},
whiteSpace: 'nowrap',
width: {
Expand Down
2 changes: 2 additions & 0 deletions src/components/pickers/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,7 @@ WithIcon.args = { icon: true };
export const OverTheCustomBG = Template.bind({});
OverTheCustomBG.parameters = { backgrounds: { default: 'gray' } };

export const Disabled = Template.bind({});
Disabled.args = { isDisabled: true, label: 'Disabled' };
// export const Multiple = Template.bind({});
// Multiple.args = { icon: true, defaultSelectedKeys: ['red', 'violet'] };