Modals
9 months ago
skeletons
9 months ago
ActionButton.vue
9 months ago
ActionButtonsSection.vue
9 months ago
Banner.vue
9 months ago
FAQ.vue
9 months ago
FormItem.vue
9 months ago
FormsSection.vue
9 months ago
Hero.vue
9 months ago
PluginEntriesTable.vue
9 months ago
PluginEntry.vue
9 months ago
PluginExpansion.vue
9 months ago
Toggle.vue
9 months ago
UsageCard.vue
9 months ago
UsageCardsRow.vue
9 months ago
UsageCardsSection.vue
9 months ago
Toggle.vue
92 lines
| 1 | <script setup lang="ts"> |
| 2 | interface Props { |
| 3 | value: boolean; |
| 4 | isDisabled?: boolean; |
| 5 | } |
| 6 | |
| 7 | const props = defineProps<Props>(); |
| 8 | |
| 9 | const emit = defineEmits<{ |
| 10 | toggle: [boolean]; |
| 11 | }>(); |
| 12 | |
| 13 | const handleClick = (event: Event) => { |
| 14 | if (props.isDisabled) return; |
| 15 | |
| 16 | event.preventDefault(); |
| 17 | event.stopPropagation(); |
| 18 | emit('toggle', !props.value); |
| 19 | }; |
| 20 | </script> |
| 21 | |
| 22 | <template> |
| 23 | <div class="controlled-toggle__container"> |
| 24 | <label |
| 25 | class="controlled-toggle" |
| 26 | :class="{ |
| 27 | 'controlled-toggle--active': value, |
| 28 | 'controlled-toggle--disabled': isDisabled |
| 29 | }" |
| 30 | @click="handleClick" |
| 31 | > |
| 32 | <input type="checkbox" :checked="value" :disabled="isDisabled" style="display: none" /> |
| 33 | <span class="controlled-toggle__slider" /> |
| 34 | </label> |
| 35 | </div> |
| 36 | </template> |
| 37 | |
| 38 | <style scoped lang="scss"> |
| 39 | .controlled-toggle { |
| 40 | position: relative; |
| 41 | display: inline-block; |
| 42 | width: 44px; |
| 43 | height: 24px; |
| 44 | cursor: pointer; |
| 45 | margin: 0; |
| 46 | |
| 47 | &--disabled { |
| 48 | cursor: not-allowed; |
| 49 | opacity: 0.5; |
| 50 | } |
| 51 | |
| 52 | &__slider { |
| 53 | position: absolute; |
| 54 | top: 0; |
| 55 | left: 0; |
| 56 | right: 0; |
| 57 | bottom: 0; |
| 58 | background-color: var(--neutral--300); |
| 59 | border-radius: 24px; |
| 60 | transition: all 0.2s ease; |
| 61 | |
| 62 | &::before { |
| 63 | content: ''; |
| 64 | position: absolute; |
| 65 | height: 20px; |
| 66 | width: 20px; |
| 67 | left: 2px; |
| 68 | top: 2px; |
| 69 | background-color: white; |
| 70 | border-radius: 50%; |
| 71 | transition: all 0.2s ease; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | &--active &__slider { |
| 76 | background-color: var(--primary--500); |
| 77 | |
| 78 | &::before { |
| 79 | transform: translateX(20px); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | &:hover:not(&--disabled) &__slider { |
| 84 | background-color: var(--neutral--400); |
| 85 | } |
| 86 | |
| 87 | &--active:hover:not(&--disabled) &__slider { |
| 88 | background-color: var(--primary--600); |
| 89 | } |
| 90 | } |
| 91 | </style> |
| 92 |