diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-09-21 16:08:44 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-09-21 22:07:55 +0900 |
commit | c28ae6b82860693b8e6b012a939fb8a3dd320e23 (patch) | |
tree | 2f690587d6c3b83453f52b070151a4c5996028e8 /src/settings/components/ui/Text.tsx | |
parent | 063ceb215f858a8e2a5bde85d8f9ca24240894c6 (diff) |
Introduce styled-components on settings ui
Diffstat (limited to 'src/settings/components/ui/Text.tsx')
-rw-r--r-- | src/settings/components/ui/Text.tsx | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/src/settings/components/ui/Text.tsx b/src/settings/components/ui/Text.tsx index 7ecef88..700b08a 100644 --- a/src/settings/components/ui/Text.tsx +++ b/src/settings/components/ui/Text.tsx @@ -1,42 +1,54 @@ import React from "react"; -import "./Input.scss"; +import styled from "styled-components"; -interface Props extends React.AllHTMLAttributes<HTMLElement> { +const Container = styled.div` + page-break-inside: avoid; +`; + +const Input = styled.input<{ hasError: boolean }>` + padding: 4px; + width: 8rem; + box-shadow: ${({ hasError }) => (hasError ? "0 0 2px red" : "none")}; +`; + +const Label = styled.label` + font-weight: bold; + min-width: 14rem; + display: inline-block; +`; + +interface Props extends React.HTMLAttributes<HTMLElement> { name: string; error?: string; label: string; value: string; onValueChange?: (name: string, value: string) => void; - onBlur?: (e: React.FocusEvent<Element>) => void; } -class Input extends React.Component<Props> { - renderText(props: Props) { - const inputClassName = props.error ? "input-error" : ""; - const pp = { ...props }; - delete pp.onValueChange; - return ( - <div className="settings-ui-input"> - <label htmlFor={props.id}>{props.label}</label> - <input +const Text: React.FC<Props> = (props) => { + const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { + if (props.onValueChange) { + props.onValueChange(e.target.name, e.target.value); + } + }; + + const pp = { ...props }; + delete pp.onValueChange; + + return ( + <Container> + <Label> + {props.label} + <br /> + <Input type="text" - className={inputClassName} - onChange={this.bindOnChange.bind(this)} + hasError={props.error !== undefined} + onChange={onChange} {...pp} /> - </div> - ); - } - - render() { - return this.renderText(this.props); - } - - bindOnChange(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) { - if (this.props.onValueChange) { - this.props.onValueChange(e.target.name, e.target.value); - } - } -} + </Label> + </Container> + ); +}; -export default Input; +export default Text; |