Added more form elements

This commit is contained in:
2018-05-13 11:26:51 +10:00
parent 71e77bad71
commit dd9ac5f2f0
5 changed files with 173 additions and 4 deletions

83
public/input/Input.jsx Normal file
View File

@ -0,0 +1,83 @@
// Copyright (c) 2018 Dominic Masters
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import React from 'react';
import Button from './button/Button';
import Form from './form/Form';
import InputGroup from './group/InputGroup';
import Label from './label/Label';
export default class Input extends React.Component {
constructor(props) {
super(props);
}
render() {
let ElementType = "input";
let type = "text";
let value;
let clazzes = "o-input";
//Determining
if(this.props.type) type = this.props.type;
//Values
if(this.props.value) {
value = this.props.value;
} else {
value = this.props.children;
}
//Classes
clazzes += " is-"+type;
if(this.props.className) clazzes += " " + this.props.className;
//Now create the element
let element;
//First we need to switch things like submit and reset
if(type == "submit" || type == "reset" || type == "button") {
element = <Button {...this.props} />;
} else if(type == "textarea") {
element = <textarea {...this.props} className={clazzes}>{ value }</textarea>
} else {
element = <ElementType {...this.props} type={type} className={clazzes} />
}
return element;
}
}
const TextArea = props => {
return <Input {...props} type="textarea" />
}
export {
Button,
Form,
InputGroup,
TextArea,
Label
};

View File

@ -74,6 +74,7 @@ export default class Button extends React.Component {
return (
<ElementType
{...this.props}
type={type}
className={clazzes}
href={href}

View File

@ -0,0 +1,42 @@
// Copyright (c) 2018 Dominic Masters
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import React from 'react';
export default function(props) {
let clazzes = "o-form";
if(props.className) clazzes += " " + props.className;
return (
<form
className={ clazzes }
method={ props.method }
action={ props.action }
autoComplete={ props.autoComplete }
target={ props.target }
>
{ props.children }
</form>
);
}

View File

@ -21,8 +21,16 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import Button from './button/Button';
import React from 'react';
export {
Button
};
export default function(props) {
let clazzes = "o-form__group";
if(props.className) clazzes += " " + props.className;
return (
<div className={clazzes}>
{ props.children }
</div>
);
}

View File

@ -0,0 +1,35 @@
// Copyright (c) 2018 Dominic Masters
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import React from 'react';
export default function(props) {
let clazz = "o-label";
if(props.className) clazz += " " + props.className;
return (
<label htmlFor={ props.htmlFor } className={clazz}>
{ props.children }
</label>
);
}