Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

feat(Label): Label is now aware of multiline inputs #123

Merged
merged 1 commit into from
Jun 10, 2020
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
8 changes: 7 additions & 1 deletion src/Form/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,13 @@ export class Input extends Component {
};

const Label = label ? (
<StyledLabel htmlFor={id} styles={rest.styles} error={error} onClick={this.handleLabelClick} {...statusProps}>
<StyledLabel
htmlFor={id}
styles={rest.styles}
error={error}
multiline={multiline}
onClick={this.handleLabelClick}
{...statusProps}>
{leftIcon && <LeftIcon styles={rest.styles} name={leftIcon} {...statusProps} {...leftIconProps} />}
{label}
</StyledLabel>
Expand Down
1 change: 1 addition & 0 deletions src/Form/Input.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const Multiline = () => (
value="I already have a value! If provided a value, I become controlled, so I won't update when you type here..."
/>
);
export const MultilineFloating = () => <Input {...defaultInputProps} floating multiline />;

export const Autogrow = () => <Input {...defaultInputProps} multiline autogrow />;

Expand Down
66 changes: 35 additions & 31 deletions src/Form/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,45 @@ import { themeGet, createComponent } from '../utils';
const Label = createComponent({
name: 'Label',
tag: 'label',
style: ({ isFloatable, isFloating, isFocused, isDisabled, theme }) => css`
display: block;
transition: 250ms;
margin: 0 0 4px 4px;
font-size: ${themeGet('typography.fontSize')}px;
style: ({ isFloatable, isFloating, isFocused, isDisabled, multiline, theme }) => {
const isLabelFloating = isFloating || (multiline && isFloatable);

${isFloatable &&
css`
position: absolute;
margin: 0;
line-height: 14px;
left: 9px;
font-size: ${isFloating ? 12 : 16}px;
font-weight: 500;
top: ${isFloating ? '6px' : '50%'};
transform: ${isFloating ? 'none' : 'translateY(-50%)'};
color: ${theme.colors.greyDarker};
user-select: none;
z-index: ${isFloating ? '1' : 'auto'};
return css`
display: block;
transition: 250ms;
margin: 0 0 4px 4px;
font-size: ${themeGet('typography.fontSize')}px;

&:hover {
cursor: text;
}
`};
${isFloatable &&
css`
position: absolute;
margin: 0;
line-height: 14px;
left: 9px;
font-size: ${isLabelFloating ? 12 : 16}px;
font-weight: 500;
top: ${isLabelFloating ? '6px' : '50%'};
transform: ${isLabelFloating ? 'none' : 'translateY(-50%)'};
color: ${theme.colors.greyDarker};
user-select: none;
z-index: ${isFloating ? '1' : 'auto'};

${isFocused &&
css`
color: ${theme.colors.primary};
`}
&:hover {
cursor: text;
}
`};

${isDisabled &&
css`
color: ${theme.colors.grey};
`}
`,
${isFocused &&
css`
color: ${theme.colors.primary};
`}

${isDisabled &&
css`
color: ${theme.colors.grey};
`}
`;
},
});

export default Label;