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

feat add input #429

Merged
merged 25 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b2cdd7c
feat: add native props & placeholder to input
Sebastien-Ahkrin Nov 30, 2022
ec4e2c3
feat: add label on input
Sebastien-Ahkrin Nov 30, 2022
126ab6a
refactor: change inputs export
Sebastien-Ahkrin Dec 1, 2022
1620942
feat: add size on Input component
Sebastien-Ahkrin Dec 1, 2022
a0bdbcb
refactor: change style to be from ant
Sebastien-Ahkrin Dec 2, 2022
e4fc7fd
feat: add variant on context
Sebastien-Ahkrin Dec 2, 2022
9fcb5a8
empty commit
Sebastien-Ahkrin Dec 6, 2022
9aa3a08
refactor: change some styles
Sebastien-Ahkrin Dec 7, 2022
ecda2dc
feat: add trailing addon
Sebastien-Ahkrin Dec 8, 2022
b6586a7
refactor: change to use styled
Sebastien-Ahkrin Dec 8, 2022
b165d5e
feat: add required
Sebastien-Ahkrin Dec 9, 2022
9d078f6
feat: add addon on input
Sebastien-Ahkrin Dec 12, 2022
f94f2fe
feat: add inline & trailing addon
Sebastien-Ahkrin Dec 13, 2022
8cb19f4
refactor: resolve border color with css vars
Sebastien-Ahkrin Dec 13, 2022
9b862c1
refactor: add focus on input
Sebastien-Ahkrin Dec 13, 2022
5328dcc
refactor: change focus color to use within
Sebastien-Ahkrin Dec 13, 2022
81a4d2d
feat: change line height by variant
Sebastien-Ahkrin Dec 14, 2022
424bd83
refactor: remove Fields
Sebastien-Ahkrin Dec 15, 2022
1afb6f3
feat: add variant on Field
Sebastien-Ahkrin Dec 15, 2022
f4905fe
refactor: move variant to be with default value
Sebastien-Ahkrin Dec 22, 2022
a014f93
fix: resolve line-height bug that affect the height of the input
Sebastien-Ahkrin Dec 23, 2022
b2101d5
refactor: remove not needed any
Sebastien-Ahkrin Dec 23, 2022
60dc91e
refactor: change addon to be icon
Sebastien-Ahkrin Jan 3, 2023
73fdc92
refactor: change the entire Input component to change the DOM
Sebastien-Ahkrin Jan 3, 2023
7cebece
refactor: add types and remove unused pick
Sebastien-Ahkrin Jan 3, 2023
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
36 changes: 36 additions & 0 deletions src/components/forms/Input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';

import { useFieldsContext } from './context/FieldsContext';

const styles = {
input: css`
box-sizing: border-box;
margin: 0px;
padding: 4px 11px;
color: rgba(0, 0, 0, 0.88);
font-size: 14px;
line-height: 1.5714285714285714;
position: relative;
display: inline-block;
width: 100%;
min-width: 0px;
background-color: #fff;
border-radius: 6px;
transition: all 0.2s;
border: 1px solid #d9d9d9;
`,
};

export function Input(props: React.InputHTMLAttributes<HTMLInputElement>) {
const fieldsContext = useFieldsContext();

return (
<input
id={fieldsContext}
name={fieldsContext}
css={styles.input}
{...props}
/>
);
}
51 changes: 51 additions & 0 deletions src/components/forms/context/FieldsContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import { createContext, ReactNode, useContext } from 'react';

interface FieldsProps {
children: ReactNode;
}

interface FieldProps extends FieldsProps {
name: string;
label: string;
}

const context = createContext<string | null>(null);

const styles = {
root: css`
display: flex;
flex-direction: row;
gap: 5px;
align-items: center;
`,
};

export function useFieldsContext() {
const ctx = useContext(context);

if (!ctx) {
return undefined;
}

return ctx;
}

export function Fields(props: FieldsProps) {
const { children } = props;
return <>{children}</>;
}

export function Field(props: FieldProps) {
const { label, name, children } = props;

return (
<context.Provider value={name}>
<div css={styles.root}>
<label htmlFor={name}>{label}: </label>
{children}
</div>
</context.Provider>
);
}
1 change: 1 addition & 0 deletions src/components/forms/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Input';
Sebastien-Ahkrin marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 39 additions & 0 deletions stories/components/input.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ChangeEvent, useState } from 'react';

import { Input } from '../../src/components/forms/Input';
import {
Field,
Fields,
} from '../../src/components/forms/context/FieldsContext';
Sebastien-Ahkrin marked this conversation as resolved.
Show resolved Hide resolved

export default {
title: 'Forms / Input',
};

export function BasicExample() {
const [state, setState] = useState('Hello, World!');

function onChange(event: ChangeEvent<HTMLInputElement>) {
setState(event.target.value);
}

return (
<Input placeholder="Basic example" value={state} onChange={onChange} />
);
}

export function LabelExample() {
const [state, setState] = useState('Hello, World!');

function onChange(event: ChangeEvent<HTMLInputElement>) {
setState(event.target.value);
}

return (
<Fields>
<Field name="inputLabel" label="Label">
<Input placeholder="Label example" value={state} onChange={onChange} />
</Field>
</Fields>
);
}