Skip to content

Commit

Permalink
Update the design of the switch component
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal authored and syphax-bouazzouni committed Apr 19, 2023
1 parent 8c2dcaf commit e10b7e7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/assets/stylesheets/components/index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import 'chips';
@import 'card_message'
@import 'card_message';
@import "switch";
64 changes: 64 additions & 0 deletions app/assets/stylesheets/components/switch.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

.switch-filter{
display:flex;
align-items: center;
justify-content: space-between;
margin-bottom: 20px;
}
.switch-filter p{
font-size: 16px;
color: #666666;
margin-bottom: 0;
margin-right: 10px;
}



/* Toggle switch css */
.switch {
position: relative;
display: inline-block;
width: 40px;
height: 20px;
margin-bottom: 0;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 13px;
width: 13px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: var(--primary-color);
}
input:focus + .slider {
box-shadow: 0 0 1px var(--primary-color);
}
input:checked + .slider:before {
-webkit-transform: translateX(19px);
-ms-transform: translateX(19px);
transform: translateX(19px);
}
2 changes: 1 addition & 1 deletion app/components/switch_input_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class SwitchInputComponent < ViewComponent::Base


def initialize(id:, name: , label: nil, value: '', checked: false, boolean_switch: false)
def initialize(id:, name: , label: '', value: '', checked: false, boolean_switch: false)
super
@id = id
@name = name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
%div.custom-control.custom-switch
%div.switch-filter
- if @boolean_switch
= hidden_field_tag @name, @value
= check_box_tag check_box_name, @value, @checked, class: 'custom-control-input', id: check_box_id, onChange: "#{boolean_switch_action}"
%label.custom-control-label{for: check_box_id}
= content || @label
- if content || [email protected]?
%p
= content || @label
%label.switch{for: check_box_id}
= check_box_tag check_box_name, @value, @checked, class: '', id: check_box_id, onChange: "#{boolean_switch_action}"
%span.slider

0 comments on commit e10b7e7

Please sign in to comment.