Skip to content

Commit

Permalink
add textinput
Browse files Browse the repository at this point in the history
  • Loading branch information
lebalz committed Nov 26, 2024
1 parent 2c9fb19 commit 6bddfdb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/components/shared/TextInput/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import clsx from 'clsx';
import styles from './styles.module.scss';
import { observer } from 'mobx-react-lite';

interface Props {
defaultValue?: string;
placeholder?: string;
onChange: (text: string) => void;
onEnter?: () => void;
onEscape?: () => void;
className?: string;
}

const TextInput = observer((props: Props) => {
const [text, setText] = React.useState(props.defaultValue || '');
return (
<input
type="text"
placeholder={props.placeholder}
value={text}
className={clsx(styles.className, styles.textInput)}
onChange={(e) => {
setText(e.target.value);
props.onChange(e.target.value);
}}
onKeyDown={(e) => {
if (e.key === 'Enter') {
props.onEnter?.();
}
if (e.key === 'Escape') {
props.onEscape?.();
}
}}
autoFocus
autoComplete="off"
autoCorrect="off"
/>
);
});

export default TextInput;
16 changes: 16 additions & 0 deletions src/components/shared/TextInput/styles.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.textInput {
width: 100%;
padding: var(--ifm-button-padding-vertical);
border: 1px solid #ccc;
border-radius: var(--ifm-global-radius);
font-size: var(--ifm-font-size-base);
box-shadow: var(--ifm-global-shadow-md);
transition:
border-color 0.3s,
box-shadow 0.3s;
&:focus {
border-color: var(--ifm-link-hover-color);
outline: none;
box-shadow: 0 0 8px var(--ifm-link-hover-color);
}
}

0 comments on commit 6bddfdb

Please sign in to comment.