This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature 7 - Input Component [Dev] #78
Open
danielvaldivv
wants to merge
6
commits into
develop
Choose a base branch
from
feature-7
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
85c37f7
feature-7 created Input Component styles default
danielvaldivv 4d9cb26
feature-7 created documentation files
danielvaldivv 6e9f7ab
feature-7 added necessary functionalities to build local server and c…
danielvaldivv 63decaf
feature-7 added Documentation of Input Component on docs folder
danielvaldivv 3ea6619
feature-7 added 3 different tests: provide styles, provide type atrib…
danielvaldivv 4a46de2
feature-7 fixed code review comments of the PR
danielvaldivv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { HTMLProps } from 'react'; | ||
|
||
export interface InputProps extends HTMLProps<HTMLInputElement> {} | ||
|
||
export default function Input(props: InputProps): JSX.Element; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { forwardRef } from 'react'; | ||
import { createStyleSheet } from '@platzily-ui/styling'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const useStyleSheet = createStyleSheet( | ||
(theme, { width, height }) => ({ | ||
inputDefault: { | ||
width: width || 199, | ||
height: height || 40, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here. |
||
backgroundColor: theme.palette.neutral.light, | ||
borderWidth: 1, | ||
borderStyle: 'solid', | ||
borderColor: theme.palette.neutral.secondary, | ||
'&:focus': { | ||
borderColor: theme.palette.tertiary.main, | ||
backgroundColor: theme.palette.neutral.light, | ||
outline: 'none', | ||
}, | ||
'&:disabled': { | ||
borderColor: theme.palette.neutral.tertiary, | ||
cursor: 'not-allowed', | ||
}, | ||
|
||
'&:hover': { | ||
borderColor: theme.palette.tertiary.main, | ||
}, | ||
}, | ||
|
||
}), | ||
{ key: 'Input' }, | ||
); | ||
|
||
const Input = forwardRef(function Input(props, ref) { | ||
const { className, width, height, ...otherProps } = props; | ||
const { classes, cx } = useStyleSheet(props); | ||
|
||
return ( | ||
<input | ||
ref={ref} | ||
className={cx({ | ||
[classes.inputDefault]: true, | ||
[className]: !!className, | ||
})} | ||
{...otherProps} | ||
/> | ||
); | ||
}); | ||
|
||
Input.propTypes = { | ||
className: PropTypes.string, | ||
height: PropTypes.number, | ||
width: PropTypes.number, | ||
}; | ||
|
||
|
||
|
||
export default Input; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { render } from '@testing-library/react'; | ||
import { ThemeProvider, createTheme } from '@platzily-ui/styling'; | ||
import Input from './Input'; | ||
|
||
describe('@Components/Input', () => { | ||
it('Given the Input Component, when the props provide a width and his value, then the component will take those styles', () => { | ||
// arrange | ||
const theme = createTheme(); | ||
const { getByRole } = render( | ||
<ThemeProvider theme={theme}> | ||
<Input role="textbox" width={150} /> | ||
</ThemeProvider>, | ||
); | ||
|
||
// act | ||
const InputTestedText = getByRole('textbox'); | ||
// assert | ||
expect(InputTestedText).toBeDefined(); | ||
expect(InputTestedText).toHaveStyle(`width:150px`); | ||
}); | ||
|
||
it('Given the Input Component, when the props provide type or required attributes then the component will take those props', () => { | ||
// arrange | ||
const { getByRole } = render( | ||
<ThemeProvider theme={createTheme()}> | ||
<Input role="textbox" required /> | ||
</ThemeProvider>, | ||
); | ||
|
||
// act | ||
const InputTestedText = getByRole('textbox'); | ||
|
||
// assert | ||
expect(InputTestedText).toBeDefined(); | ||
expect(InputTestedText).toHaveProperty('required'); | ||
}); | ||
|
||
it('Given the Input Component, when include the component inside form tag, then form tag gets properties and his values. ', () => { | ||
// arrange | ||
const { getByTestId } = render( | ||
<ThemeProvider theme={createTheme()}> | ||
<form data-testid="login-form"> | ||
<Input type="text" name="username" value="platzily-user" /> | ||
<Input type="password" name="password" value="12345678" /> | ||
<Input type="checkbox" name="rememberMe" checked /> | ||
<button type="submit">Sign in</button> | ||
</form> | ||
</ThemeProvider>, | ||
); | ||
|
||
// act | ||
const InputTestedText = getByTestId('login-form'); | ||
|
||
// assert | ||
expect(InputTestedText).toHaveFormValues({ | ||
omarefg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
username: 'platzily-user', | ||
rememberMe: true, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './Input'; | ||
export { default } from './Input'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Input'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ const useStyleSheet = createStyleSheet( | |
(theme, { color, elevation }) => ({ | ||
paper: { | ||
backgroundColor: detectColor(theme, color || 'neutral-tertiary'), | ||
padding: theme.spacing(), | ||
padding: theme.spacing(1), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No needed when the value is one. |
||
borderRadius: 5, | ||
}, | ||
outlined: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Input } from '@platzily-ui/components'; | ||
import { createStyleSheet } from '@platzily-ui/styling'; | ||
|
||
const useStyleSheet = createStyleSheet((theme) => ({ | ||
input: { | ||
borderRadius: theme.spacing(), | ||
padding: theme.spacing(2), | ||
'&:invalid':{ | ||
borderColor: theme.palette.error.main, | ||
'&::placeholder': { | ||
color: theme.palette.error.main, | ||
} | ||
} | ||
}, | ||
}), { key: 'DocsInput' }); | ||
|
||
const InputComponent = (props) => { | ||
const { classes } = useStyleSheet(); | ||
const { type, placeholder, disabled, width, required, ...otherProps } = props; | ||
|
||
return <Input | ||
className={classes.input} | ||
type={type} | ||
placeholder={placeholder} | ||
disabled={disabled} | ||
width={width} | ||
required={required} | ||
{...otherProps} | ||
/>; | ||
}; | ||
|
||
export default InputComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { Input } from '../../components/styling/index'; | ||
|
||
# Inputs | ||
|
||
Input fields let get the user different type of data. | ||
|
||
|
||
<div style={{marginTop: 50, display: 'flex', alignItems:'center', flexDirection:'column', gap:'15px', justifyContent: 'center', padding: '15px', backgroundColor:'#F4F8FB', borderRadius:'5px'}}> | ||
<Input placeholder="Hello Input" /> | ||
</div> | ||
|
||
------ | ||
|
||
The component has type='text' by default but the user can change it using the attribute type and his prefer value. | ||
|
||
<div style={{ display: 'flex', alignItems:'center', flexDirection:'column', gap:'15px', justifyContent: 'center', padding: '15px'}}> | ||
<Input placeholder="Type text by default" /> | ||
|
||
</div> | ||
|
||
```jsx | ||
import { Input } from '@platzily-ui/components'; | ||
|
||
const InputComponent = () => { | ||
|
||
return <Input />; | ||
}; | ||
export default InputComponent; | ||
``` | ||
|
||
The user should provide width and height properties and his values by props, also can provide any input attribute of HTML. | ||
|
||
<div style={{ backgroundColor:'#F4F8FB', display: 'flex', alignItems:'center', flexDirection:'column', gap:'15px', justifyContent: 'center', padding: '15px'}}> | ||
<Input placeholder="Example One" width={200} height={40} /> | ||
<Input placeholder="Example Two" width={180} height={35} /> | ||
<Input placeholder="Example Three" width={160} height={30} /> | ||
</div> | ||
|
||
```jsx | ||
import { Button } from '@platzily-ui/components'; | ||
import { Fragment } from 'react'; | ||
|
||
const InputComponent = () => { | ||
return ( | ||
<Fragment> | ||
<Input width={200} height={40} /> // Example One | ||
<Input width={180} height={35} /> // Example Two | ||
<Input width={160} height={30} /> // Example Three | ||
</Fragment> | ||
); | ||
}; | ||
export default InputComponent; | ||
``` | ||
|
||
|
||
------ | ||
|
||
## Type attribute | ||
|
||
Users can use all his different values in the type attribute like: date, checkbox, password, | ||
|
||
<div style={{ backgroundColor:'#F4F8FB', display: 'flex', alignItems:'center', flexDirection:'column', gap:'15px', justifyContent: 'center', padding: '15px'}}> | ||
<Input type="date" /> | ||
<Input type="checkbox" width={18} /> | ||
<Input placeholder="password" type="password" /> | ||
</div> | ||
|
||
```jsx | ||
import { Input } from '@platzily-ui/components'; | ||
import { Fragment } from 'react'; | ||
|
||
const InputComponent = () => { | ||
return ( | ||
<Fragment> | ||
<Input type="date" /> | ||
<Input type="checkbox" width={18} /> | ||
<Input placeholder="password" type="password" /> /> | ||
</Fragment> | ||
); | ||
return ; | ||
}; | ||
export default InputComponent; | ||
``` | ||
|
||
|
||
---------- | ||
## Styling | ||
|
||
The user can provide styles to the component using the createStyleSheet method. | ||
|
||
<div style={{ backgroundColor:'#F4F8FB', display: 'flex', alignItems:'center', flexDirection:'column', gap:'15px', justifyContent: 'center', padding: '15px'}}> | ||
<Input placeholder="required *" required /> | ||
</div> | ||
|
||
```jsx | ||
import { Input } from '@platzily-ui/components'; | ||
import { createStyleSheet } from '@platzily-ui/styling'; | ||
|
||
const useStyleSheet = createStyleSheet((theme) => ({ | ||
input: { | ||
borderRadius: theme.spacing(), | ||
padding: theme.spacing(2), | ||
'&:invalid':{ | ||
borderColor: theme.palette.error.main, | ||
'&::placeholder': { | ||
color: theme.palette.error.main, | ||
} | ||
} | ||
}, | ||
}), { key: 'classNameStyle' }); | ||
|
||
const InputComponent = (props) => { | ||
const { classes } = useStyleSheet(); | ||
|
||
return <Input | ||
className={classes.input} | ||
required | ||
/>; | ||
}; | ||
|
||
export default InputComponent; | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this why dont we pass a new class when the button is of type checkbox? 🤔