1 | import styled, { css, keyframes } from 'styled-components';
|
2 |
|
3 | import { Sizes, Colors, TextHelper } from '../index';
|
4 | import { IProps } from './Textarea';
|
5 |
|
6 | const bounceUp = keyframes`
|
7 | from { transform: scale3d(1, 1, 1); }
|
8 | 50% { transform: scale3d(1.1618, 1.1618, 1.1618); }
|
9 | to { transform: scale3d(1, 1, 1); }
|
10 | `;
|
11 |
|
12 | const shake = keyframes`
|
13 | from, to { transform: translate3d(0, 0, 0); }
|
14 | 10%, 30%, 50%, 70%, 90% { transform: translate3d(-3px, 0, 0); }
|
15 | 20%, 40%, 60%, 80% { transform: translate3d(3px, 0, 0); }
|
16 | `;
|
17 |
|
18 | const bounceUpRule = css`${bounceUp} .4s forwards;`;
|
19 |
|
20 | const shakeRule = (props: any) => css`${props.isInvalid && shake} 1s forwards;`;
|
21 |
|
22 | const GroupInput = styled.div`
|
23 | position: relative;
|
24 | @media screen and (max-width: 600px) {
|
25 | width: 100%;
|
26 | }
|
27 |
|
28 | `;
|
29 |
|
30 | const opacityAndTransition = (opacity: number, transition: string) => `
|
31 | opacity: ${opacity};
|
32 | transition: ${transition};
|
33 | `;
|
34 |
|
35 | const Textarea = styled.textarea<IProps>`
|
36 | position: relative;
|
37 | font-weight: 500;
|
38 | color: ${Colors.codGray};
|
39 | width: 100%;
|
40 | max-height: 176px;
|
41 | min-height: 176px;
|
42 | box-sizing: border-box;
|
43 | letter-spacing: 1px;
|
44 | padding: 4px 10px;
|
45 | border: 1px solid ${Colors.line};
|
46 | border-bottom: 1px solid currentColor;
|
47 | background-color: transparent;
|
48 | font-family: ${TextHelper.fontVariant('medium')};
|
49 | line-height: 22px;
|
50 | overflow: auto;
|
51 | resize: vertical;
|
52 |
|
53 | &:disabled {
|
54 | opacity: 0.5;
|
55 | border-bottom-color: ${Colors.line};
|
56 | }
|
57 |
|
58 | &:not(:placeholder-shown) ~ label {
|
59 | top: -16px;
|
60 | color: ${Colors.support};
|
61 | z-index: 1;
|
62 | ${opacityAndTransition(1, '0.3s')};
|
63 | }
|
64 |
|
65 | ::placeholder {
|
66 | color: ${Colors.support};
|
67 | ${opacityAndTransition(1, '0.2s')};
|
68 | font-family: ${TextHelper.fontVariant('medium')};
|
69 | }
|
70 |
|
71 | &:focus::placeholder {
|
72 | ${opacityAndTransition(0, '0.2s')};
|
73 | }
|
74 |
|
75 | &:focus {
|
76 | outline: none;
|
77 |
|
78 | & ~ .bar {
|
79 | width: 100%;
|
80 | transition: 0.4s;
|
81 | }
|
82 |
|
83 | & ~ label {
|
84 | top: -16px;
|
85 | color: ${Colors.mongeral};
|
86 | opacity: 1;
|
87 | z-index: 1;
|
88 | animation: ${bounceUpRule};
|
89 | }
|
90 | }
|
91 |
|
92 | & ~ .bar {
|
93 | position: relative;
|
94 | display: inherit;
|
95 | top: -5px;
|
96 | width: 0;
|
97 | height: 2px;
|
98 | background-color: ${Colors.mongeral};
|
99 | transition: 0.4s;
|
100 | }
|
101 |
|
102 | ~ label {
|
103 | position: absolute;
|
104 | font-size: ${TextHelper.pxToEm(Sizes.s2)}em;
|
105 | font-family: ${TextHelper.fontVariant('medium')};
|
106 | font-weight: 500;
|
107 | left: 0;
|
108 | top: -16px;
|
109 | z-index: -1;
|
110 | letter-spacing: 0.5px;
|
111 | ${opacityAndTransition(0, 'all .2s ease')};
|
112 | animation: ${shakeRule};
|
113 | text-transform: uppercase;
|
114 | }
|
115 |
|
116 | ~ .feedback {
|
117 | position: absolute;
|
118 | font-size: ${TextHelper.pxToEm(Sizes.s2)}em;
|
119 | font-family: ${TextHelper.fontVariant('medium')};
|
120 | overflow: hidden;
|
121 | font-style: italic;
|
122 |
|
123 | ${({comment}) => comment && `
|
124 | font-style: italic;
|
125 | `}
|
126 | }
|
127 |
|
128 | ${({ isInvalid, isWarning }) => (isInvalid || isWarning) && `
|
129 | border-color: ${isInvalid ? Colors.chestnut : Colors.goldDrop};
|
130 | ~ .feedback,
|
131 | ~ label,
|
132 | &:focus ~ label, &:not(:placeholder-shown) ~ label {
|
133 | color: ${isInvalid ? Colors.chestnut : Colors.goldDrop}
|
134 | }
|
135 |
|
136 | ~ label { opacity: 1; }
|
137 | `}
|
138 | `;
|
139 |
|
140 | export default {
|
141 | Textarea,
|
142 | GroupInput,
|
143 | };
|