File size: 5,205 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
// @flow
import * as React from 'react';
import Icon from 'src/components/icon';
import { WhiteOutlineButton } from 'src/components/button';
import type { GetUserType } from 'shared/graphql/queries/user/getUser';
import type { GetCommunityType } from 'shared/graphql/queries/community/getCommunity';
import {
StyledLabel,
StyledPrefixLabel,
StyledInput,
StyledTextArea,
StyledUnderlineInput,
StyledHiddenInput,
StyledCheckboxWrapper,
StyledError,
StyledSuccess,
PhotoInputLabel,
CoverInputLabel,
InputOverlay,
CoverImage,
PhotoInputImage,
} from './style';
type InputProps = {
children?: React$Node,
inputType?: string,
defaultValue?: ?string,
value?: ?any,
placeholder?: string,
onChange?: Function,
autoFocus?: boolean,
checked?: boolean,
disabled?: boolean,
id?: string,
dataCy?: string,
user?: GetUserType,
community?: GetCommunityType,
size?: number,
};
export const Input = (props: InputProps) => {
return (
<StyledLabel {...props}>
{props.children}
<StyledInput
id={props.id}
type={props.inputType}
defaultValue={props.defaultValue}
value={props.value}
placeholder={props.placeholder}
onChange={props.onChange}
autoFocus={props.autoFocus}
disabled={props.disabled}
data-cy={props.dataCy}
/>
</StyledLabel>
);
};
type PhotoInputProps = {
size?: number,
type: 'user' | 'community',
defaultValue: string,
onChange: Function,
dataCy?: string,
};
export const PhotoInput = (props: PhotoInputProps) => {
const { size = 48, type, defaultValue, onChange, dataCy } = props;
let visible,
src = defaultValue;
if (!src || src.length === 0) {
visible = true;
src =
type === 'user'
? '/img/default_avatar.svg'
: '/img/default_community.svg';
}
return (
<PhotoInputLabel type={type} size={size}>
<InputOverlay type={type} size={size} visible={visible}>
<Icon glyph="photo" />
</InputOverlay>
<PhotoInputImage
type={type}
alt={'Profile photo'}
src={src}
size={size}
/>
<StyledHiddenInput
type="file"
id="file"
name="file"
accept={'.png, .jpg, .jpeg'}
multiple={false}
onChange={onChange}
data-cy={dataCy}
/>
</PhotoInputLabel>
);
};
type CoverPhotoInputProps = {
defaultValue: string,
onChange: Function,
dataCy?: string,
};
export const CoverInput = (props: CoverPhotoInputProps) => {
return (
<CoverInputLabel>
<InputOverlay
visible={!props.defaultValue || props.defaultValue.length === 1}
>
<WhiteOutlineButton as={'div'}>Add Cover Photo</WhiteOutlineButton>
</InputOverlay>
<CoverImage
src={props.defaultValue ? `${props.defaultValue}` : ''}
role="presentation"
/>
<StyledHiddenInput
type="file"
id="file"
name="file"
accept={
props.allowGif ? '.png, .jpg, .jpeg, .gif, .mp4' : '.png, .jpg, .jpeg'
}
multiple={false}
onChange={props.onChange}
data-cy={props.dataCy}
/>
</CoverInputLabel>
);
};
export const Checkbox = (props: InputProps) => {
return (
<StyledLabel>
<StyledCheckboxWrapper
disabled={props.disabled || false}
align={props.align || 'center'}
data-cy={
props.dataCy
? `${props.dataCy}-${props.checked ? 'checked' : 'unchecked'}`
: null
}
>
{props.checked ? <Icon glyph="checkmark" /> : <Icon glyph="checkbox" />}
<StyledHiddenInput
type="checkbox"
id={props.id}
checked={props.checked}
disabled={props.disabled || false}
onChange={props.onChange}
data-cy={props.dataCy}
/>
{props.children}
</StyledCheckboxWrapper>
</StyledLabel>
);
};
export const TextArea = (props: InputProps) => {
return (
<StyledLabel>
{props.children}
<StyledTextArea
id={props.id}
placeholder={props.placeholder}
defaultValue={props.defaultValue}
onChange={props.onChange}
autoFocus={props.autoFocus}
data-cy={props.dataCy}
/>
</StyledLabel>
);
};
export class UnderlineInput extends React.Component<InputProps> {
render() {
return (
<StyledPrefixLabel disabled={this.props.disabled}>
{this.props.children}
<StyledUnderlineInput
type="text"
id={this.props.id}
placeholder={this.props.placeholder}
value={this.props.value || this.props.defaultValue}
onChange={this.props.onChange}
autoFocus={this.props.autoFocus}
disabled={this.props.disabled}
data-cy={this.props.dataCy}
/>
</StyledPrefixLabel>
);
}
}
export const Error = (props: Object) => {
const { children, ...rest } = props;
return <StyledError {...rest}>{children}</StyledError>;
};
export const Success = (props: Object) => {
const { children, ...rest } = props;
return <StyledSuccess {...rest}>{children}</StyledSuccess>;
};
|