diff --git a/packages/components/src/Input/Input.d.ts b/packages/components/src/Input/Input.d.ts new file mode 100644 index 0000000..4963b73 --- /dev/null +++ b/packages/components/src/Input/Input.d.ts @@ -0,0 +1,5 @@ +import { HTMLProps } from 'react'; + +export interface InputProps extends HTMLProps {} + +export default function Input(props: InputProps): JSX.Element; diff --git a/packages/components/src/Input/Input.js b/packages/components/src/Input/Input.js new file mode 100644 index 0000000..03dbea6 --- /dev/null +++ b/packages/components/src/Input/Input.js @@ -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, + 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.propTypes = { + className: PropTypes.string, + height: PropTypes.number, + width: PropTypes.number, +}; + + + +export default Input; diff --git a/packages/components/src/Input/Input.spec.js b/packages/components/src/Input/Input.spec.js new file mode 100644 index 0000000..e3e4fb5 --- /dev/null +++ b/packages/components/src/Input/Input.spec.js @@ -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( + + + , + ); + + // 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( + + + , + ); + + // 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( + +
+ + + + +
+
, + ); + + // act + const InputTestedText = getByTestId('login-form'); + + // assert + expect(InputTestedText).toHaveFormValues({ + username: 'platzily-user', + rememberMe: true, + }); + }); +}); diff --git a/packages/components/src/Input/index.d.ts b/packages/components/src/Input/index.d.ts new file mode 100644 index 0000000..b64980c --- /dev/null +++ b/packages/components/src/Input/index.d.ts @@ -0,0 +1,2 @@ +export * from './Input'; +export { default } from './Input'; diff --git a/packages/components/src/Input/index.js b/packages/components/src/Input/index.js new file mode 100644 index 0000000..a2e6049 --- /dev/null +++ b/packages/components/src/Input/index.js @@ -0,0 +1 @@ +export { default } from './Input'; diff --git a/packages/components/src/Paper/Paper.js b/packages/components/src/Paper/Paper.js index 735cb08..16412fd 100644 --- a/packages/components/src/Paper/Paper.js +++ b/packages/components/src/Paper/Paper.js @@ -15,7 +15,7 @@ const useStyleSheet = createStyleSheet( (theme, { color, elevation }) => ({ paper: { backgroundColor: detectColor(theme, color || 'neutral-tertiary'), - padding: theme.spacing(), + padding: theme.spacing(1), borderRadius: 5, }, outlined: { diff --git a/packages/components/src/index.d.ts b/packages/components/src/index.d.ts index f2e6a02..beb521d 100644 --- a/packages/components/src/index.d.ts +++ b/packages/components/src/index.d.ts @@ -12,3 +12,6 @@ export { default as Button } from './Button'; export * from './SvgIcon'; export { default as SvgIcon } from './SvgIcon'; + +export * from './Input'; +export { default as Input } from './Input'; diff --git a/packages/components/src/index.js b/packages/components/src/index.js index 008ef0e..e5cde22 100644 --- a/packages/components/src/index.js +++ b/packages/components/src/index.js @@ -3,3 +3,4 @@ export { default as Text } from './Text'; export { default as Header } from './Header'; export { default as Button } from './Button'; export { default as SvgIcon } from './SvgIcon'; +export { default as Input } from './Input'; diff --git a/packages/docs/components/Input/Input.js b/packages/docs/components/Input/Input.js new file mode 100644 index 0000000..ad4d64f --- /dev/null +++ b/packages/docs/components/Input/Input.js @@ -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 ; +}; + +export default InputComponent; diff --git a/packages/docs/components/styling/index.js b/packages/docs/components/styling/index.js index f2e0225..14bba19 100644 --- a/packages/docs/components/styling/index.js +++ b/packages/docs/components/styling/index.js @@ -5,6 +5,7 @@ import UseThemeStyledBoxComponent from './UseThemeStyledBox'; import ColorComponent from './ColorComponent'; import HeaderComponent from '../Header/Header'; +import InputComponent from '../Input/Input'; import { defaultTheme, customTheme } from './theme'; @@ -59,3 +60,11 @@ export function Header() { ); } + +export function Input(props) { + return ( + + + + ); +} diff --git a/packages/docs/package.json b/packages/docs/package.json index e0bac5c..da85377 100644 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -41,8 +41,8 @@ "start": "next dev" }, "dependencies": { - "@platzily-ui/icons": "0.1.0", "@platzily-ui/components": "0.1.0", + "@platzily-ui/icons": "0.1.0", "@platzily-ui/styling": "0.1.4", "next": "12.0.2", "nextra": "1.1.0", diff --git a/packages/docs/pages/components/Input.mdx b/packages/docs/pages/components/Input.mdx new file mode 100644 index 0000000..0c8b9dd --- /dev/null +++ b/packages/docs/pages/components/Input.mdx @@ -0,0 +1,122 @@ +import { Input } from '../../components/styling/index'; + +# Inputs + +Input fields let get the user different type of data. + + +
+ +
+ +------ + +The component has type='text' by default but the user can change it using the attribute type and his prefer value. + +
+ + +
+ +```jsx +import { Input } from '@platzily-ui/components'; + +const InputComponent = () => { + + return ; +}; +export default InputComponent; +``` + + The user should provide width and height properties and his values by props, also can provide any input attribute of HTML. + +
+ + + +
+ +```jsx +import { Button } from '@platzily-ui/components'; +import { Fragment } from 'react'; + +const InputComponent = () => { + return ( + + // Example One + // Example Two + // Example Three + + ); +}; +export default InputComponent; +``` + + +------ + +## Type attribute + +Users can use all his different values in the type attribute like: date, checkbox, password, + +
+ + + +
+ +```jsx +import { Input } from '@platzily-ui/components'; +import { Fragment } from 'react'; + +const InputComponent = () => { + return ( + + + + /> + + ); + return ; +}; +export default InputComponent; +``` + + +---------- +## Styling + +The user can provide styles to the component using the createStyleSheet method. + +
+ +
+ +```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 ; +}; + +export default InputComponent; +```