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

Remove positive input and add frowardRef #202

Merged
merged 1 commit into from
Nov 22, 2023
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
3 changes: 0 additions & 3 deletions src/components/input/Input.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ export const Template = ({ value: baseValue, ...args }) => {
<Story name="Error" args={{ placeholder: "Error Field", error: true, size: INPUT_SIZE.small }}>
{Template.bind({})}
</Story>
<Story name="Positive" args={{ placeholder: "Positive Field", positive: true, size: INPUT_SIZE.small }}>
{Template.bind({})}
</Story>
<Story name="Password" args={{ placeholder: "Password Field", type: "password", size: INPUT_SIZE.small }}>
{Template.bind({})}
</Story>
Expand Down
50 changes: 24 additions & 26 deletions src/components/input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from "react";
import { Input as BaseInput, InputProps as BaseInputProps, SIZE } from "baseui/input";
import { forwardRef } from "react";
import { Input as BaseInput, InputProps as BaseInputProps, Input as InputType, SIZE } from "baseui/input";
import { getInputOverrides } from "./overrides";
import { INPUT_SIZE } from "./types";
import { Spinner, SPINNER_SIZE } from "../spinner";
import { useStyletron } from "baseui";
import { spinnerStyles } from "./styles";
import { getMergedOverrides } from "../../shared/utils/getMergedOverrides";

export type InputProps = BaseInputProps & {
export type InputProps = Omit<BaseInputProps, "size" | "positive"> & {
size?: INPUT_SIZE;
isLoading?: boolean;
};
Expand All @@ -16,30 +16,28 @@ const spinnerSize = {
[INPUT_SIZE.small]: SPINNER_SIZE.small,
[INPUT_SIZE.medium]: SPINNER_SIZE.medium,
[INPUT_SIZE.large]: SPINNER_SIZE.large,
};
} as const;

const Input: React.FC<InputProps> = ({
isLoading,
endEnhancer,
size = INPUT_SIZE.medium,
overrides: baseOverrides,
...props
}) => {
const [css] = useStyletron();

const inputOverrides = getInputOverrides(size);
const overrides = getMergedOverrides(inputOverrides, baseOverrides);

const EndEnhancer =
endEnhancer || isLoading ? (
<>
{endEnhancer}
{isLoading && <Spinner animation className={css(spinnerStyles)} size={spinnerSize[size]} />}
</>
) : null;

return <BaseInput {...props} overrides={overrides} endEnhancer={EndEnhancer} />;
};
const Input = forwardRef<InputType, InputProps>(
({ isLoading, endEnhancer, size = INPUT_SIZE.medium, overrides: baseOverrides, ...props }, ref) => {
const [css] = useStyletron();

const inputOverrides = getInputOverrides(size);
const overrides = getMergedOverrides(inputOverrides, baseOverrides);

const EndEnhancer =
endEnhancer || isLoading ? (
<>
{endEnhancer}
{isLoading && <Spinner animation className={css(spinnerStyles)} size={spinnerSize[size]} />}
</>
) : null;

return <BaseInput ref={ref} {...props} overrides={overrides} endEnhancer={EndEnhancer} />;
}
);

Input.displayName = "Input";

export { SIZE };
export default Input;
24 changes: 9 additions & 15 deletions src/components/input/overrides.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@ import { INPUT_SIZE } from "./types";
import { PRIMITIVE_COLORS } from "../../shared";
import { expandProperty } from "inline-style-expand-shorthand";

const getInputColor = (isError: boolean, isPositive: boolean, isFocused: boolean): string => {
const getInputColor = (isError: boolean, isFocused: boolean): string => {
if (isFocused) {
return PRIMITIVE_COLORS.white;
}
if (isError) {
return PRIMITIVE_COLORS.red400;
}
if (isPositive) {
return PRIMITIVE_COLORS.white;
}
return PRIMITIVE_COLORS.gray500;
};

const getIconColor = (isError: boolean, isPositive: boolean, isFocused: boolean): string => {
const getIconColor = (isError: boolean, isFocused: boolean): string => {
if (isFocused) {
return PRIMITIVE_COLORS.gray500;
}
if (isError) {
return PRIMITIVE_COLORS.red400;
}
if (isPositive) {
return PRIMITIVE_COLORS.green400;
}
return PRIMITIVE_COLORS.gray500;
};

Expand All @@ -44,26 +38,26 @@ export const getInputOverrides = (size: INPUT_SIZE): InputOverrides => {
}),
},
Input: {
style: ({ $error, $positive, $isFocused }) => ({
style: ({ $error, $isFocused }) => ({
...inputModifiedStyles[size],
color: getInputColor($error, $positive, $isFocused),
color: getInputColor($error, $isFocused),
"-webkit-text-fill-color": "unset",

"::placeholder": {
color: getInputColor($error, $positive, $isFocused),
color: getInputColor($error, $isFocused),
},
}),
},
StartEnhancer: {
style: ({ $error, $positive, $isFocused }) => ({
color: getIconColor($error, $positive, $isFocused),
style: ({ $error, $isFocused }) => ({
color: getIconColor($error, $isFocused),
...expandProperty("padding", "0 12px 0 0"),
}),
},
EndEnhancer: {
style: ({ $error, $positive, $isFocused }) => ({
style: ({ $error, $isFocused }) => ({
...expandProperty("padding", "0 0 0 12px"),
color: getIconColor($error, $positive, $isFocused),
color: getIconColor($error, $isFocused),
}),
},
ClearIcon: {
Expand Down
6 changes: 3 additions & 3 deletions src/components/input/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export const inputContainerModifiedStyles = {

export const inputModifiedStyles = {
[INPUT_SIZE.small]: {
fontSize: "14px",
lineHeight: "20px",
fontSize: "12px",
lineHeight: "16px",
...expandProperty("padding", "8px 0"),
},
[INPUT_SIZE.medium]: {
fontSize: "16px",
lineHeight: "24px",
lineHeight: "22px",
...expandProperty("padding", "12px 0"),
},
[INPUT_SIZE.large]: {
Expand Down
Loading