Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
ab129f19
Commit
ab129f19
authored
May 20, 2017
by
wacky6.AriesMBP
Committed by
杨奕
Jun 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch: simplity internal implementation
parent
74f8ccc8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
21 deletions
+18
-21
packages/switch/src/component.vue
packages/switch/src/component.vue
+11
-12
packages/theme-default/src/switch.css
packages/theme-default/src/switch.css
+7
-9
No files found.
packages/switch/src/component.vue
View file @
ab129f19
<
template
>
<
template
>
<label
class=
"el-switch"
:class=
"
{ 'is-disabled': disabled, 'el-switch--wide': hasText }">
<label
class=
"el-switch"
:class=
"
{ 'is-disabled': disabled, 'el-switch--wide': hasText
, 'is-checked': checked
}">
<div
class=
"el-switch__mask"
v-show=
"disabled"
></div>
<div
class=
"el-switch__mask"
v-show=
"disabled"
></div>
<input
<input
class=
"el-switch__input"
class=
"el-switch__input"
type=
"checkbox"
type=
"checkbox"
@
change=
"handleChange"
@
change=
"handleChange"
v-model=
"_value
"
ref=
"input
"
:name=
"name"
:name=
"name"
:true-value=
"onValue"
:true-value=
"onValue"
:false-value=
"offValue"
:false-value=
"offValue"
...
@@ -105,20 +105,12 @@
...
@@ -105,20 +105,12 @@
/* istanbul ignore next */
/* istanbul ignore next */
return
this
.
onText
||
this
.
offText
;
return
this
.
onText
||
this
.
offText
;
},
},
_value
:
{
get
()
{
return
this
.
value
;
},
set
(
val
)
{
this
.
$emit
(
'
input
'
,
val
);
}
},
transform
()
{
transform
()
{
return
this
.
checked
?
`translate(
${
this
.
coreWidth
-
20
}
px, 2px)`
:
'
translate(2px, 2px)
'
;
return
this
.
checked
?
`translate(
${
this
.
coreWidth
-
20
}
px, 2px)`
:
'
translate(2px, 2px)
'
;
}
}
},
},
watch
:
{
watch
:
{
value
()
{
checked
()
{
if
(
this
.
onColor
||
this
.
offColor
)
{
if
(
this
.
onColor
||
this
.
offColor
)
{
this
.
setBackgroundColor
();
this
.
setBackgroundColor
();
}
}
...
@@ -126,7 +118,13 @@
...
@@ -126,7 +118,13 @@
},
},
methods
:
{
methods
:
{
handleChange
(
event
)
{
handleChange
(
event
)
{
this
.
$emit
(
'
change
'
,
event
.
currentTarget
.
checked
?
this
.
onValue
:
this
.
offValue
);
this
.
$emit
(
'
change
'
,
!
this
.
checked
?
this
.
onValue
:
this
.
offValue
);
this
.
$emit
(
'
input
'
,
!
this
.
checked
?
this
.
onValue
:
this
.
offValue
);
this
.
$nextTick
(()
=>
{
// set input's checked property
// in case parent refuses to change component's value
this
.
$refs
.
input
.
checked
=
this
.
checked
;
});
},
},
setBackgroundColor
()
{
setBackgroundColor
()
{
let
newColor
=
this
.
checked
?
this
.
onColor
:
this
.
offColor
;
let
newColor
=
this
.
checked
?
this
.
onColor
:
this
.
offColor
;
...
@@ -142,6 +140,7 @@
...
@@ -142,6 +140,7 @@
if
(
this
.
onColor
||
this
.
offColor
)
{
if
(
this
.
onColor
||
this
.
offColor
)
{
this
.
setBackgroundColor
();
this
.
setBackgroundColor
();
}
}
this
.
$refs
.
input
.
checked
=
this
.
checked
;
}
}
};
};
</
script
>
</
script
>
packages/theme-default/src/switch.css
View file @
ab129f19
...
@@ -49,10 +49,6 @@
...
@@ -49,10 +49,6 @@
@e
input
{
@e
input
{
display
:
none
;
display
:
none
;
&:checked
+
.el-switch__core
{
border-color
:
var
(
--switch-on-color
);
background-color
:
var
(
--switch-on-color
);
}
}
}
@e
core
{
@e
core
{
...
@@ -77,6 +73,13 @@
...
@@ -77,6 +73,13 @@
}
}
}
}
@when
checked
{
.el-switch__core
{
border-color
:
var
(
--switch-on-color
);
background-color
:
var
(
--switch-on-color
);
}
}
@when
disabled
{
@when
disabled
{
.el-switch__core
{
.el-switch__core
{
border-color
:
var
(
--switch-disabled-color
)
!important
;
border-color
:
var
(
--switch-disabled-color
)
!important
;
...
@@ -90,11 +93,6 @@
...
@@ -90,11 +93,6 @@
color
:
var
(
--switch-disabled-text-color
)
!important
;
color
:
var
(
--switch-disabled-text-color
)
!important
;
}
}
}
}
.el-switch__input
:checked
+
.el-switch__core
{
border-color
:
var
(
--switch-disabled-color
);
background-color
:
var
(
--switch-disabled-color
);
}
}
}
@modifier
wide
{
@modifier
wide
{
...
...
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