Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kus-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Кубота
kus-admin
Commits
2dcefc8e
Commit
2dcefc8e
authored
Jan 28, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
phone input
parent
81a38b8b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
178 additions
and
8 deletions
+178
-8
Field.scss
src/view/cmp/field/Field.scss
+37
-0
PhoneInput.jsx
src/view/cmp/field/PhoneInput.jsx
+103
-6
Fields.jsx
src/view/page/tmp/Fields.jsx
+38
-2
No files found.
src/view/cmp/field/Field.scss
View file @
2dcefc8e
...
@@ -98,3 +98,39 @@
...
@@ -98,3 +98,39 @@
letter-spacing
:
0
.01em
;
letter-spacing
:
0
.01em
;
}
}
}
}
.field__phone-display
,
.field__phone-hidden
{
white-space
:
pre
;
}
.field__phone-hidden
{
opacity
:
0
;
background
:
#27EF60
;
}
.field__phone-display
,
.field__phone-placeholder
{
position
:
absolute
;
box-sizing
:
border-box
;
padding
:
0
;
width
:
300px
;
max-width
:
100%
;
height
:
50px
;
font-weight
:
500
;
text-align
:
center
;
font-size
:
17px
;
line-height
:
36px
;
color
:
#000000
;
margin
:
6px
0
;
}
.field__phone-placeholder
{
font-weight
:
500
;
margin
:
6px
0
;
border
:
0
;
border-radius
:
0
;
background
:
transparent
;
visibility
:
hidden
;
color
:
$gray-medium
}
.field__phone-placeholder__visible
{
visibility
:
visible
;
}
\ No newline at end of file
src/view/cmp/field/PhoneInput.jsx
View file @
2dcefc8e
import
Input
from
'./Input.jsx'
;
import
Input
from
'./Input.jsx'
;
function
setCaretPosition
(
el
,
caretPos
)
{
el
.
value
=
el
.
value
;
// ^ this is used to not only get "focus", but
// to make sure we don't have it everything -selected-
// (it causes an issue in chrome, and having it doesn't hurt any other browser)
if
(
el
!==
null
)
{
if
(
el
.
createTextRange
)
{
var
range
=
el
.
createTextRange
();
range
.
move
(
'character'
,
caretPos
);
range
.
select
();
return
true
;
}
else
{
// (el.selectionStart === 0 added for Firefox bug)
if
(
el
.
selectionStart
||
el
.
selectionStart
===
0
)
{
el
.
focus
();
el
.
setSelectionRange
(
caretPos
,
caretPos
);
return
true
;
}
else
{
// fail city, fortunately this never happens (as far as I've tested) :)
el
.
focus
();
return
false
;
}
}
}
};
export
default
D
.
declare
(
'view.cmp.field.PhoneInput'
,
(
cfg
,
children
)
=>
{
export
default
D
.
declare
(
'view.cmp.field.PhoneInput'
,
(
cfg
,
children
)
=>
{
return
<
div
class=
{
D
.
cls
(
"labeled-field"
,
cfg
.
cls
,
{
"labeled-field--invalid"
:
cfg
.
invalid
}
)
}
>
let
displayDOM
,
placeholderDOM
,
inputDOM
,
<
label
class=
"labeled-field__label"
>
2
dom
=
<
div
class=
'field__input-wrapper field__phone-wrapper'
>
<
span
class=
"labeled-field__label-text"
>
{
cfg
.
label
}
</
span
>
{
displayDOM
=
<
div
class=
{
'field__phone-display'
}
/>
}
<
Input
class=
"labeled-field__input"
type=
{
cfg
.
type
}
placeholder=
{
cfg
.
placeholder
}
{
...
cfg
}
/>
{
placeholderDOM
=
<
div
class=
{
'field__phone-placeholder'
}
>
{
cfg
.
placeholder
||
'Ваш номер'
}
</
div
>
}
</
label
>
{
children
}
<
div
class=
'field__input'
>
{
inputDOM
=
<
input
class=
"field__input field__phone-hidden"
type=
{
'tel'
}
/>
}
</
div
>
</
div
>
</
div
>;
let
focused
=
false
;
if
(
cfg
.
bind
){
var
update
=
function
(
val
)
{
val
=
val
+
''
;
inputDOM
.
value
=
val
;
let
built
=
[];
if
((
val
!==
''
&&
val
!==
'7'
&&
val
!==
'8'
)
||
focused
){
const
pattern
=
'+0 (000) 000-00-00'
;
let
pos
=
0
;
for
(
let
i
=
0
,
_i
=
pattern
.
length
;
i
<
_i
;
i
++
){
const
char
=
pattern
[
i
];
if
(
char
===
'0'
){
built
.
push
(
val
[
pos
]
===
void
0
?
' '
:
val
[
pos
]
);
pos
++
;
}
else
{
built
.
push
(
char
);
}
}
}
if
(
built
.
length
===
0
){
placeholderDOM
.
classList
.
add
(
'field__phone-placeholder__visible'
);
}
else
{
placeholderDOM
.
classList
.
remove
(
'field__phone-placeholder__visible'
);
}
displayDOM
.
innerText
=
built
.
join
(
''
);
};
cfg
.
bind
.
sub
(
update
);
inputDOM
.
addEventListener
(
'keypress'
,
function
(
e
)
{
if
(
inputDOM
.
value
.
length
+
(
e
.
data
!==
null
?
e
.
key
.
length
:
0
)
>
12
){
e
.
preventDefault
()
}
valueGetter
();
});
var
valueGetter
=
function
()
{
cfg
.
bind
.
set
((
inputDOM
.
value
+
''
).
substr
(
0
,
11
));
};
inputDOM
.
addEventListener
(
'keyup'
,
valueGetter
);
inputDOM
.
addEventListener
(
'input'
,
valueGetter
);
var
focus
=
function
(
e
)
{
focused
=
true
;
setTimeout
(()
=>
setCaretPosition
(
inputDOM
,
inputDOM
.
value
.
length
),
0
);
update
(
inputDOM
.
value
);
};
inputDOM
.
addEventListener
(
'focus'
,
focus
);
inputDOM
.
addEventListener
(
'click'
,
focus
);
inputDOM
.
addEventListener
(
'blur'
,
function
()
{
focused
=
false
;
update
(
inputDOM
.
value
);
});
}
return
dom
;
})
})
src/view/page/tmp/Fields.jsx
View file @
2dcefc8e
import
Button
from
"/view/cmp/button/Button.jsx"
;
import
Button
from
"/view/cmp/button/Button.jsx"
;
import
LabeledField
from
"../../cmp/field/LabeledField.jsx"
;
import
LabeledField
from
"../../cmp/field/LabeledField.jsx"
;
import
PhoneInput
from
"../../cmp/field/PhoneInput.jsx"
;
import
PhoneInput
from
"../../cmp/field/PhoneInput.jsx"
;
import
Input
from
"../../cmp/field/Input"
;
export
default
D
.
declare
(
'view.page.tmp.Fields'
,
()
=>
{
export
default
D
.
declare
(
'view.page.tmp.Fields'
,
()
=>
{
var
data
=
new
Store
({
phone
:
''
,
phone3
:
'7'
,
phone4
:
'8'
,
phone5
:
'79132251365'
,
phone2
:
'894'
,
});
return
<
div
>
return
<
div
>
<
div
>
<
div
>
<
h5
>
Labeled field
</
h5
>
<
h5
>
Labeled field
</
h5
>
...
@@ -9,9 +17,36 @@ export default D.declare('view.page.tmp.Fields', () => {
...
@@ -9,9 +17,36 @@ export default D.declare('view.page.tmp.Fields', () => {
</
div
>
</
div
>
<
div
>
<
div
>
<
h5
>
Phone input
</
h5
>
<
h3
>
Phone input
</
h3
>
<
div
style=
{
{
display
:
'flex'
}
}
>
<
div
>
<
h5
>
Empty
</
h5
>
<
PhoneInput
label=
{
'Label'
}
bind=
{
data
.
bind
(
'phone'
)
}
/>
<
Input
bind=
{
data
.
bind
(
'phone'
)
}
/>
</
div
>
<
div
>
<
h5
>
Code +7
</
h5
>
<
PhoneInput
label=
{
'Label'
}
bind=
{
data
.
bind
(
'phone3'
)
}
/>
<
Input
bind=
{
data
.
bind
(
'phone3'
)
}
/>
</
div
>
<
div
>
<
h5
>
Code +8
</
h5
>
<
PhoneInput
label=
{
'Label'
}
bind=
{
data
.
bind
(
'phone4'
)
}
/>
<
Input
bind=
{
data
.
bind
(
'phone4'
)
}
/>
</
div
>
<
div
>
<
h5
>
Partial
</
h5
>
<
PhoneInput
label=
{
'Label'
}
bind=
{
data
.
bind
(
'phone2'
)
}
/>
<
Input
bind=
{
data
.
bind
(
'phone2'
)
}
/>
</
div
>
<
PhoneInput
label=
{
'Label'
}
/>
<
div
>
<
h5
>
Filled
</
h5
>
<
PhoneInput
label=
{
'Label'
}
bind=
{
data
.
bind
(
'phone5'
)
}
/>
<
Input
bind=
{
data
.
bind
(
'phone5'
)
}
/>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
});
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment