feat: Add toggle button component(#4419)
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
66
app/javascript/dashboard/components/buttons/ToggleButton.vue
Normal file
66
app/javascript/dashboard/components/buttons/ToggleButton.vue
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<template>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="toggle-button"
|
||||||
|
:class="{ active }"
|
||||||
|
role="switch"
|
||||||
|
:aria-checked="active.toString()"
|
||||||
|
@click="onClick"
|
||||||
|
>
|
||||||
|
<span aria-hidden="true" :class="{ active }"></span>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
active: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onClick(e) {
|
||||||
|
this.$emit('click', e);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.toggle-button {
|
||||||
|
--toggle-button-box-shadow: rgb(255, 255, 255) 0px 0px 0px 0px,
|
||||||
|
rgba(59, 130, 246, 0.5) 0px 0px 0px 0px, rgba(0, 0, 0, 0.1) 0px 1px 3px 0px,
|
||||||
|
rgba(0, 0, 0, 0.06) 0px 1px 2px 0px;
|
||||||
|
background-color: var(--s-200);
|
||||||
|
border-radius: var(--border-radius-large);
|
||||||
|
border: 2px solid transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
flex-shrink: 0;
|
||||||
|
height: 19px;
|
||||||
|
position: relative;
|
||||||
|
transition-duration: 200ms;
|
||||||
|
transition-property: background-color;
|
||||||
|
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
width: 34px;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background-color: var(--w-500);
|
||||||
|
}
|
||||||
|
|
||||||
|
span {
|
||||||
|
--space-one-point-five: 1.5rem;
|
||||||
|
background-color: var(--white);
|
||||||
|
border-radius: 100%;
|
||||||
|
box-shadow: var(--toggle-button-box-shadow);
|
||||||
|
display: inline-block;
|
||||||
|
height: var(--space-one-point-five);
|
||||||
|
transform: translate(0, 0);
|
||||||
|
transition-duration: 200ms;
|
||||||
|
transition-property: transform;
|
||||||
|
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
width: var(--space-one-point-five);
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
transform: translate(var(--space-one-point-five), var(--space-zero));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -34,19 +34,10 @@
|
|||||||
<td>{{ automation.name }}</td>
|
<td>{{ automation.name }}</td>
|
||||||
<td>{{ automation.description }}</td>
|
<td>{{ automation.description }}</td>
|
||||||
<td>
|
<td>
|
||||||
<button
|
<toggle-button
|
||||||
type="button"
|
:active="automation.active"
|
||||||
class="toggle-button"
|
|
||||||
:class="{ active: automation.active }"
|
|
||||||
role="switch"
|
|
||||||
:aria-checked="automation.active.toString()"
|
|
||||||
@click="toggleAutomation(automation, automation.active)"
|
@click="toggleAutomation(automation, automation.active)"
|
||||||
>
|
/>
|
||||||
<span
|
|
||||||
aria-hidden="true"
|
|
||||||
:class="{ active: automation.active }"
|
|
||||||
></span>
|
|
||||||
</button>
|
|
||||||
</td>
|
</td>
|
||||||
<td>{{ readableTime(automation.created_on) }}</td>
|
<td>{{ readableTime(automation.created_on) }}</td>
|
||||||
<td class="button-wrapper">
|
<td class="button-wrapper">
|
||||||
@@ -140,11 +131,12 @@ import AddAutomationRule from './AddAutomationRule.vue';
|
|||||||
import EditAutomationRule from './EditAutomationRule.vue';
|
import EditAutomationRule from './EditAutomationRule.vue';
|
||||||
import alertMixin from 'shared/mixins/alertMixin';
|
import alertMixin from 'shared/mixins/alertMixin';
|
||||||
import timeMixin from 'dashboard/mixins/time';
|
import timeMixin from 'dashboard/mixins/time';
|
||||||
|
import ToggleButton from 'dashboard/components/buttons/ToggleButton';
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
AddAutomationRule,
|
AddAutomationRule,
|
||||||
EditAutomationRule,
|
EditAutomationRule,
|
||||||
|
ToggleButton,
|
||||||
},
|
},
|
||||||
mixins: [alertMixin, timeMixin],
|
mixins: [alertMixin, timeMixin],
|
||||||
data() {
|
data() {
|
||||||
@@ -238,7 +230,6 @@ export default {
|
|||||||
mode === 'EDIT'
|
mode === 'EDIT'
|
||||||
? this.$t('AUTOMATION.EDIT.API.SUCCESS_MESSAGE')
|
? this.$t('AUTOMATION.EDIT.API.SUCCESS_MESSAGE')
|
||||||
: this.$t('AUTOMATION.ADD.API.SUCCESS_MESSAGE');
|
: this.$t('AUTOMATION.ADD.API.SUCCESS_MESSAGE');
|
||||||
|
|
||||||
await await this.$store.dispatch(action, payload);
|
await await this.$store.dispatch(action, payload);
|
||||||
this.showAlert(this.$t(successMessage));
|
this.showAlert(this.$t(successMessage));
|
||||||
this.hideAddPopup();
|
this.hideAddPopup();
|
||||||
@@ -290,41 +281,4 @@ export default {
|
|||||||
.automation__status-checkbox {
|
.automation__status-checkbox {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
.toggle-button {
|
|
||||||
background-color: var(--s-200);
|
|
||||||
position: relative;
|
|
||||||
display: inline-flex;
|
|
||||||
height: 19px;
|
|
||||||
width: 34px;
|
|
||||||
border: 2px solid transparent;
|
|
||||||
border-radius: var(--border-radius-large);
|
|
||||||
cursor: pointer;
|
|
||||||
transition-property: background-color;
|
|
||||||
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
|
||||||
transition-duration: 200ms;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.toggle-button.active {
|
|
||||||
background-color: var(--w-500);
|
|
||||||
}
|
|
||||||
|
|
||||||
.toggle-button span {
|
|
||||||
--space-one-point-five: 1.5rem;
|
|
||||||
height: var(--space-one-point-five);
|
|
||||||
width: var(--space-one-point-five);
|
|
||||||
display: inline-block;
|
|
||||||
background-color: var(--white);
|
|
||||||
box-shadow: rgb(255, 255, 255) 0px 0px 0px 0px,
|
|
||||||
rgba(59, 130, 246, 0.5) 0px 0px 0px 0px, rgba(0, 0, 0, 0.1) 0px 1px 3px 0px,
|
|
||||||
rgba(0, 0, 0, 0.06) 0px 1px 2px 0px;
|
|
||||||
transform: translate(0, 0);
|
|
||||||
border-radius: 100%;
|
|
||||||
transition-property: transform;
|
|
||||||
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
|
||||||
transition-duration: 200ms;
|
|
||||||
}
|
|
||||||
.toggle-button span.active {
|
|
||||||
transform: translate(var(--space-one-point-five), var(--space-zero));
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user