Skip to content
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

chore(BaseInput): reusable, internal Input component #2053

Merged
merged 13 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
112 changes: 112 additions & 0 deletions packages/core/src/components/BaseInput/BaseInput.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
@import "../../styles/Typography";

.wrapper {
width: 100%;
position: relative;
display: flex;
align-items: center;
gap: var(--spacing-small);
padding-block: var(--spacing-xs);
padding-inline: var(--spacing-medium) var(--spacing-xs);
YossiSaadi marked this conversation as resolved.
Show resolved Hide resolved

@include vibe-text(text1, normal);
@include smoothing-text;

outline: none;
border: 1px solid var(--ui-border-color);
border-radius: var(--border-radius-small);
color: var(--primary-text-color);
background-color: var(--secondary-background-color);
transition: border-color var(--motion-productive-medium) ease-in;

&.small {
@include vibe-text(text2, normal);
}

&.large {
padding-block: var(--spacing-small);
}

&.underline {
border-left: none;
border-right: none;
border-top: none;
padding: var(--spacing-small) var(--spacing-large) var(--spacing-small) var(--spacing-xs);
border-radius: 0 !important;
YossiSaadi marked this conversation as resolved.
Show resolved Hide resolved
}

&.rightThinnerPadding {
padding-inline-end: var(--spacing-medium);
}

&:hover {
border-color: var(--primary-text-color);
}

&:has(.input:active, .input:focus) {
border-color: var(--primary-color);
}

// TODO in next major remove withReadOnlyStyle, should only be determined by read-only existence on input
&:has(.input:read-only).withReadOnlyStyle {
background-color: var(--allgrey-background-color);
border: none;

.input {
background-color: var(--allgrey-background-color);
}
}

&:has(.input:disabled) {
cursor: not-allowed;
user-select: none;
border: none;
pointer-events: none;
background-color: var(--disabled-background-color);
}

&.success {
border-color: var(--positive-color);

&:hover {
border-color: var(--positive-color);
}

&:has(.input:active, .input:focus) {
border-color: var(--positive-color);
}
}

&:has(.input[aria-invalid="true"]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we say we can't use has for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added support for both browsers that do and do not support has

border-color: var(--negative-color);

&:hover {
border-color: var(--negative-color);
}

&:has(.input:active, .input:focus) {
border-color: var(--negative-color);
}
}

.input {
all: unset;

width: 100%;
height: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
border: none;
outline: none;

&::placeholder {
color: var(--secondary-text-color);
font-weight: 400;
}

&:disabled::placeholder {
color: var(--disabled-text-color);
}
}
}
35 changes: 35 additions & 0 deletions packages/core/src/components/BaseInput/BaseInput.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call it just Input

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm let's discuss it
I'm leaving it open for having an Input component which would be exported from Vibe

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { forwardRef } from "react";
import cx from "classnames";
import styles from "./BaseInput.module.scss";
import { BaseInputProps } from "./BaseInput.types";
import VibeComponent from "../../types/VibeComponent";
import { getStyle } from "../../helpers/typesciptCssModulesHelper";

const BaseInput: VibeComponent<BaseInputProps, HTMLInputElement> = forwardRef(
({ inputSize = "medium", leftRender, rightRender, withReadOnlyStyle, underline, success, error, ...props }, ref) => {
const wrapperClassNames = cx(
styles.wrapper,
{
[styles.rightThinnerPadding]: !rightRender,
[styles.withReadOnlyStyle]: withReadOnlyStyle,
[styles.underline]: underline,
[styles.success]: success
},
getStyle(styles, inputSize)
);

return (
<div className={wrapperClassNames}>
{leftRender}
<input {...props} ref={ref} className={cx(styles.input, props.className)} aria-invalid={error} />
{rightRender}
</div>
);
}
);

export default BaseInput;

const App = () => {
return <BaseInput inputSize={"small"}></BaseInput>;
};
YossiSaadi marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions packages/core/src/components/BaseInput/BaseInput.types.ts
YossiSaadi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { InputHTMLAttributes, ReactNode } from "react";
import { VibeComponentProps } from "../../types";
import { BASE_SIZES } from "../../constants";

type InputSize = (typeof BASE_SIZES)[keyof typeof BASE_SIZES];
type Renderer = ReactNode | ReactNode[];

export interface BaseInputProps extends InputHTMLAttributes<HTMLInputElement>, VibeComponentProps {
inputSize?: InputSize;
leftRender?: Renderer;
rightRender?: Renderer;
withReadOnlyStyle?: boolean;
underline?: boolean;
success?: boolean;
error?: boolean;
}
Loading