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

add right text input option #442

Merged
merged 2 commits into from
May 21, 2024
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
25 changes: 15 additions & 10 deletions src/components/Input/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,59 @@ export const _RegularInput = {
<>
<h3>Controlled components</h3>
<Input placeholder={'with no content'} value="" />
<br />
<br /> <br />
<Input placeholder={'something'} value="with content" />
<br />
<br /> <br />
<Input
placeholder={'something'}
value=""
error="that's an error without content"
/>
<br />
<br /> <br />
<Input
placeholder={'something'}
value="with content"
error="that's an error with content"
/>
<br />
<br /> <br />
<Input
placeholder={'something'}
value=""
warning="that's a warning without content"
/>
<br />
<br /> <br />
<Input
placeholder={'something'}
value="123"
warning="that's a warning with content"
/>
<br />

<br /> <br />
<h3>Uncontrolled components</h3>
<Input placeholder={'something'} defaultValue="" disable={true} />
<br />
<br /> <br />
<Input
placeholder={'something'}
defaultValue=""
error="that's an error with|without content"
/>
<br />
<br /> <br />
<Input
placeholder={'something'}
defaultValue=""
warning="that's a warning with|without content"
/>

<br /> <br />
<Input
placeholder={'something'}
defaultValue=""
success="that's a success with|without content"
/>
<br /> <br />
<Input
placeholder={'something with right text'}
defaultValue=""
rightText={'👍'}
/>
</>
),
};
Expand Down
26 changes: 23 additions & 3 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import React from 'react';
import React, { ReactNode } from 'react';

import { ComponentPropsWithoutRef, ChangeEvent, cloneElement } from 'react';

Expand All @@ -12,6 +12,7 @@ export interface InputProps extends ComponentPropsWithoutRef<'input'> {
icon?: JSX.Element;
customClass?: string;
onClickIcon?: () => void;
rightText?: React.ReactNode;
}

export function Input(props: InputProps) {
Expand Down Expand Up @@ -80,7 +81,15 @@ export function IconInput(props: InputProps) {
}

export function RawInput(props: InputProps) {
const { error, warning, success, disable, customClass = '', ...rest } = props;
const {
error,
warning,
success,
disable,
customClass = '',
rightText,
...rest
} = props;

const disabledClass = disable ? 'border-0' : '';
const errorClass = error ? 'border-s-error' : '';
Expand All @@ -100,8 +109,19 @@ export function RawInput(props: InputProps) {
disabled={disable}
{...rest}
/>
<InputMessage error={error} warning={warning} success={success} />
</div>
{rightText && (
<div className="inline -ml-16">
<button
type="button"
className="w-10 h-10 bg-transparent mas-body text-tertiary"
disabled={true}
>
{rightText}
</button>
</div>
)}
<InputMessage error={error} warning={warning} success={success} />
</div>
</div>
);
Expand Down
Loading