2020-04-25 19:38:45 +02:00
|
|
|
<template>
|
2021-12-14 14:21:48 +01:00
|
|
|
<div class="ui-toggle" :class="{'is-disabled': disabled, 'is-negative': negative, 'is-active': on, 'is-content-left': contentLeft }">
|
|
|
|
|
<input type="checkbox" :value="on" @input="onChange" :disabled="disabled" />
|
|
|
|
|
<span class="ui-toggle-switch" :class="{ 'is-active': on }"><i></i></span>
|
|
|
|
|
<i class="fth-minus-circle ui-toggle-off-warning" v-if="offContent && !on && offWarning"></i>
|
|
|
|
|
<span class="ui-toggle-text" v-if="onContent && on" v-localize="onContent"></span>
|
|
|
|
|
<span class="ui-toggle-text" v-if="offContent && !on" v-localize="offContent"></span>
|
2020-04-21 16:23:43 +02:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
name: 'uiToggle',
|
|
|
|
|
|
|
|
|
|
props: {
|
2021-12-14 14:21:48 +01:00
|
|
|
on: {
|
2020-04-21 16:23:43 +02:00
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2020-04-28 14:51:17 +02:00
|
|
|
},
|
|
|
|
|
disabled: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2020-05-07 15:03:29 +02:00
|
|
|
},
|
|
|
|
|
negative: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2020-08-13 11:14:10 +02:00
|
|
|
},
|
|
|
|
|
onContent: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: null
|
|
|
|
|
},
|
|
|
|
|
offContent: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: null
|
|
|
|
|
},
|
2020-08-18 17:46:45 +02:00
|
|
|
offWarning: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
2020-08-13 11:14:10 +02:00
|
|
|
contentLeft: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2020-04-21 16:23:43 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
|
|
onChange(ev)
|
|
|
|
|
{
|
2021-12-14 14:21:48 +01:00
|
|
|
this.$emit('update:on', !this.on);
|
2020-04-21 16:23:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
.ui-toggle
|
|
|
|
|
{
|
2020-08-13 11:14:10 +02:00
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
2020-04-21 16:23:43 +02:00
|
|
|
position: relative;
|
|
|
|
|
height: 22px;
|
|
|
|
|
|
|
|
|
|
input
|
|
|
|
|
{
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
margin: 0;
|
|
|
|
|
z-index: 2;
|
|
|
|
|
opacity: 0;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
2020-04-28 14:51:17 +02:00
|
|
|
|
|
|
|
|
&.is-disabled input
|
|
|
|
|
{
|
|
|
|
|
cursor: default;
|
|
|
|
|
}
|
2020-08-13 11:14:10 +02:00
|
|
|
|
|
|
|
|
&.is-content-left
|
|
|
|
|
{
|
|
|
|
|
flex-direction: row-reverse;
|
|
|
|
|
|
|
|
|
|
.ui-toggle-text
|
|
|
|
|
{
|
|
|
|
|
margin-left: 0;
|
|
|
|
|
margin-right: 12px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ui-toggle-text
|
|
|
|
|
{
|
|
|
|
|
margin-top: 1px;
|
|
|
|
|
margin-left: 12px;
|
|
|
|
|
|
|
|
|
|
.ui-toggle.is-active &
|
|
|
|
|
{
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
}
|
2020-04-21 16:23:43 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-16 15:51:12 +02:00
|
|
|
.ui-toggle-switch
|
2020-04-21 16:23:43 +02:00
|
|
|
{
|
|
|
|
|
display: inline-block;
|
|
|
|
|
height: 22px;
|
2020-07-20 01:29:38 +02:00
|
|
|
width: 36px;
|
2020-09-07 14:55:05 +02:00
|
|
|
background: var(--color-toggle);
|
2020-04-21 16:23:43 +02:00
|
|
|
border-radius: 20px;
|
2020-09-09 18:59:12 +02:00
|
|
|
border: 1px solid transparent;
|
2020-04-21 16:23:43 +02:00
|
|
|
transition: all 0.2s ease;
|
|
|
|
|
z-index: 1;
|
|
|
|
|
pointer-events: none;
|
2020-08-16 15:51:12 +02:00
|
|
|
|
2020-04-21 16:23:43 +02:00
|
|
|
i
|
|
|
|
|
{
|
|
|
|
|
display: inline-block;
|
2022-01-12 17:15:05 +01:00
|
|
|
height: 14px;
|
|
|
|
|
width: 14px;
|
2020-04-21 16:23:43 +02:00
|
|
|
border-radius: 20px;
|
2022-01-12 17:15:05 +01:00
|
|
|
margin: 3px;
|
2020-09-07 14:55:05 +02:00
|
|
|
background: var(--color-toggle-fg);
|
2020-04-21 16:23:43 +02:00
|
|
|
transition: all 0.2s ease;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 13:13:19 +02:00
|
|
|
&.is-active
|
2020-04-21 16:23:43 +02:00
|
|
|
{
|
2020-09-07 14:55:05 +02:00
|
|
|
background: var(--color-toggled);
|
2020-08-16 15:51:12 +02:00
|
|
|
}
|
2020-04-21 16:23:43 +02:00
|
|
|
|
2021-01-06 12:03:21 +01:00
|
|
|
&.is-active i
|
2020-08-16 15:51:12 +02:00
|
|
|
{
|
2020-09-07 14:55:05 +02:00
|
|
|
background: var(--color-toggled-fg);
|
2020-08-16 15:51:12 +02:00
|
|
|
transform: translateX(14px);
|
2020-04-21 16:23:43 +02:00
|
|
|
}
|
2020-09-09 18:59:12 +02:00
|
|
|
|
|
|
|
|
input:focus + &
|
|
|
|
|
{
|
|
|
|
|
border: var(--color-input-focus-border);
|
|
|
|
|
box-shadow: var(--color-input-focus-shadow);
|
|
|
|
|
outline: none;
|
2021-01-06 12:03:21 +01:00
|
|
|
|
|
|
|
|
&.is-active
|
|
|
|
|
{
|
|
|
|
|
background-color: var(--color-toggled);
|
|
|
|
|
}
|
2020-09-09 18:59:12 +02:00
|
|
|
}
|
2021-11-15 13:15:00 +01:00
|
|
|
|
|
|
|
|
.ui-toggle.is-disabled &
|
|
|
|
|
{
|
|
|
|
|
opacity: 0.7;
|
|
|
|
|
pointer-events: none;
|
|
|
|
|
}
|
2020-04-21 16:23:43 +02:00
|
|
|
}
|
2020-05-02 12:20:22 +02:00
|
|
|
|
2021-04-01 13:36:11 +02:00
|
|
|
.ui-toggle.onbg .ui-toggle-switch:not(.is-active)
|
|
|
|
|
{
|
|
|
|
|
background: var(--color-bg);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-07 15:03:29 +02:00
|
|
|
.ui-toggle.is-negative .ui-toggle-switch.is-active
|
|
|
|
|
{
|
|
|
|
|
background: var(--color-negative);
|
2020-09-10 11:57:19 +02:00
|
|
|
border-color: transparent !important;
|
|
|
|
|
|
|
|
|
|
i
|
|
|
|
|
{
|
|
|
|
|
background: white;
|
|
|
|
|
}
|
2020-05-07 15:03:29 +02:00
|
|
|
}
|
2020-08-18 17:46:45 +02:00
|
|
|
|
2021-09-20 15:57:22 +02:00
|
|
|
.ui-toggle.is-accent .ui-toggle-switch.is-active
|
|
|
|
|
{
|
|
|
|
|
background: var(--color-accent);
|
|
|
|
|
border-color: transparent !important;
|
|
|
|
|
|
|
|
|
|
i
|
|
|
|
|
{
|
|
|
|
|
background: var(--color-accent-fg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 17:46:45 +02:00
|
|
|
.ui-toggle-off-warning
|
|
|
|
|
{
|
|
|
|
|
margin: 0 10px 0 -5px;
|
|
|
|
|
}
|
2020-04-21 16:23:43 +02:00
|
|
|
</style>
|