|
| 1 | +<script> |
| 2 | +/* eslint-disable import/first, no-param-reassign */ |
| 3 | +export default { |
| 4 | + name: 'HStep', |
| 5 | +}; |
| 6 | +</script> |
| 7 | + |
| 8 | +<template> |
| 9 | + <li |
| 10 | + class="h-step" |
| 11 | + :class="{ |
| 12 | + [`h-step--behavior-filled`]: isFilled && !isSelected, |
| 13 | + [`h-step--behavior-selected`]: isSelected, |
| 14 | + [`h-step--behavior-clickable`]: $config.clickable || $props.clickable, |
| 15 | + [`h-step--direction-${$config.direction}`]: $config.direction, |
| 16 | + [`h-step--text-direction-${$config.textDirection}`]: $config.textDirection, |
| 17 | + }" |
| 18 | + > |
| 19 | + <div |
| 20 | + class="h-step__content" |
| 21 | + > |
| 22 | + <div |
| 23 | + class="h-step__badge" |
| 24 | + @click="click" |
| 25 | + > |
| 26 | + <h-icon |
| 27 | + v-if="$props.icon" |
| 28 | + :icon="$props.icon" |
| 29 | + :color="$props.iconColor" |
| 30 | + :size="$props.iconSize" |
| 31 | + /> |
| 32 | + |
| 33 | + <template v-else> |
| 34 | + {{ $props.position }} |
| 35 | + </template> |
| 36 | + </div> |
| 37 | + |
| 38 | + <div class="h-step__text"> |
| 39 | + <h-text |
| 40 | + class="h-step__text-title" |
| 41 | + weight="semi-bold" |
| 42 | + @click="click" |
| 43 | + > |
| 44 | + <slot />{{ $props.title }} |
| 45 | + </h-text> |
| 46 | + |
| 47 | + <transition |
| 48 | + name="h-step__transition" |
| 49 | + > |
| 50 | + <h-text |
| 51 | + v-if="showDescription" |
| 52 | + class="h-step__text-description" |
| 53 | + dynamic |
| 54 | + > |
| 55 | + <slot |
| 56 | + name="description" |
| 57 | + :on="{click}" |
| 58 | + />{{ $props.description }} |
| 59 | + </h-text> |
| 60 | + </transition> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + |
| 64 | + <div class="h-step__line" /> |
| 65 | + </li> |
| 66 | +</template> |
| 67 | + |
| 68 | +<script setup> |
| 69 | +import { inject, computed, useSlots } from 'vue'; |
| 70 | +import { HStepKey } from './step-key'; |
| 71 | +
|
| 72 | +const $props = defineProps({ |
| 73 | + clickable: { |
| 74 | + type: Boolean, |
| 75 | + default: undefined, |
| 76 | + }, |
| 77 | + position: { |
| 78 | + type: Number, |
| 79 | + default: undefined, |
| 80 | + }, |
| 81 | + title: { |
| 82 | + type: String, |
| 83 | + default: undefined, |
| 84 | + }, |
| 85 | + description: { |
| 86 | + type: String, |
| 87 | + default: undefined, |
| 88 | + }, |
| 89 | + icon: { |
| 90 | + type: String, |
| 91 | + default: undefined, |
| 92 | + }, |
| 93 | + iconColor: { |
| 94 | + type: String, |
| 95 | + default: 'inverse', |
| 96 | + }, |
| 97 | + iconSize: { |
| 98 | + type: String, |
| 99 | + default: 'inherit', |
| 100 | + }, |
| 101 | +}); |
| 102 | +
|
| 103 | +const $slots = useSlots(); |
| 104 | +
|
| 105 | +const $config = inject(HStepKey); |
| 106 | +
|
| 107 | +const isSelected = computed(() => $config.modelValue === $props.position); |
| 108 | +const isFilled = computed(() => $config.modelValue >= $props.position); |
| 109 | +
|
| 110 | +const showDescription = computed(() => { |
| 111 | + if (!$slots?.description) return false; |
| 112 | + return ($config.showDescriptionOnlyIfSelected ? isSelected.value : true); |
| 113 | +}); |
| 114 | +
|
| 115 | +const $emit = defineEmits(['update:modelValue']); |
| 116 | +
|
| 117 | +const click = () => { |
| 118 | + if ($config.clickable || $props.clickable) $emit('update:modelValue', $props.position); |
| 119 | +}; |
| 120 | +</script> |
| 121 | +
|
| 122 | +<style lang="scss"> |
| 123 | +:root { |
| 124 | + --h-step--margin: 0; |
| 125 | + --h-step--flex: 1; |
| 126 | + --h-step--flex-direction: column; |
| 127 | + --h-step__content--flex-direction: column; |
| 128 | + --h-step__badge-size: 28px; |
| 129 | + --h-step__line--spacing: 0rem; |
| 130 | + --h-step__line--thickness: 1px; |
| 131 | + --h-step__line: var(--color-blue-grey-scale-300); |
| 132 | + --h-step__line--width: 0; |
| 133 | + --h-step__line--height: 0; |
| 134 | + --h-step__line--space: var(--h-step__badge-size); |
| 135 | + --h-step__line--top: auto; |
| 136 | + --h-step__line--left: auto; |
| 137 | + --h-step__line--position: absolute; |
| 138 | + --h-step__line--flex: 0 1 auto; |
| 139 | + --h-step__line--margin: 0; |
| 140 | + --h-step__line--color: var(--color-grey-scale-500); |
| 141 | + --h-step__line--color--selected: var(--color-grey-scale-500); |
| 142 | + --h-step__line--color--filled: var(--color-grey-scale-500); |
| 143 | + --h-step__badge--background-color: var(--color-grey-scale-500); |
| 144 | + --h-step__badge--background-color--selected: var(--color-blue-scale-800); |
| 145 | + --h-step__badge--background-color--filled: var(--color-blue-scale-800); |
| 146 | + --h-step__badge-color: var(--color-white); |
| 147 | + --h-step__text--margin: 0; |
| 148 | + --h-step__text--color: var(--color-grey-scale-500); |
| 149 | + --h-step__text--color--filled: inherit; |
| 150 | + --h-step__text--color--selected: inherit; |
| 151 | + --h-step--align-items: stretch; |
| 152 | + --h-step__content--align-items: stretch; |
| 153 | +} |
| 154 | +
|
| 155 | +.h-step { |
| 156 | + position: relative; |
| 157 | + display: flex; |
| 158 | + flex: var(--h-step--flex); |
| 159 | + margin: var(--h-step--margin); |
| 160 | + align-items: var(--h-step--align-items); |
| 161 | + flex-direction: var(--h-step--flex-direction); |
| 162 | +} |
| 163 | +
|
| 164 | +.h-step__content { |
| 165 | + display: flex; |
| 166 | + position: relative; |
| 167 | + flex-direction: var(--h-step__content--flex-direction); |
| 168 | + align-items: var(--h-step__content--align-items); |
| 169 | +} |
| 170 | +
|
| 171 | +.h-step--behavior-selected { |
| 172 | + --h-step__badge--background-color: var(--h-step__badge--background-color--selected); |
| 173 | + --h-step__line--color: var(--h-step__line--color--selected); |
| 174 | + --h-step__text--color: var(--h-step__text--color--selected); |
| 175 | +} |
| 176 | +
|
| 177 | +.h-step--behavior-filled { |
| 178 | + --h-step__text--color: var(--h-step__text--color--filled); |
| 179 | + --h-step__line--color: var(--h-step__line--color--filled); |
| 180 | + --h-step__badge--background-color: var(--h-step__badge--background-color--filled); |
| 181 | +} |
| 182 | +
|
| 183 | +.h-step--behavior-clickable .h-step__badge, |
| 184 | +.h-step--behavior-clickable .h-step__text-title { |
| 185 | + cursor: pointer; |
| 186 | + // &:hover { |
| 187 | + // opacity: 0.5; |
| 188 | + // } |
| 189 | + &:active { |
| 190 | + opacity: 0.7; |
| 191 | + } |
| 192 | +} |
| 193 | +
|
| 194 | +.h-step--direction-horizontal.h-step--text-direction-horizontal { |
| 195 | + --h-step--flex-direction: row; |
| 196 | + --h-step__content--flex-direction: row; |
| 197 | + --h-step--flex: 1 1 fit-content; |
| 198 | + --h-step__text--margin: 0 0 0 8px; |
| 199 | + --h-step__line--position: relative; |
| 200 | + --h-step__line--width: 0; |
| 201 | + --h-step__line--flex: 1; |
| 202 | + --h-step__line--margin: 0 8px; |
| 203 | + --h-step__line--height: var(--h-step__line--thickness); |
| 204 | + --h-step--align-items: center; |
| 205 | +
|
| 206 | + &:last-child { |
| 207 | + --h-step--flex: 0 1 auto; |
| 208 | + } |
| 209 | +} |
| 210 | +
|
| 211 | +.h-step--direction-horizontal.h-step--text-direction-vertical { |
| 212 | + --h-step--flex-direction: column; |
| 213 | + --h-step__content--flex-direction: column; |
| 214 | + --h-step__content--align-items: center; |
| 215 | + --h-step__text--margin: 8px 0 0 0; |
| 216 | + --h-step__line--width: calc(100% - var(--h-step__line--space) * 2); |
| 217 | + --h-step__line--top: calc(var(--h-step__line--space) / 2); |
| 218 | + --h-step__line--left: calc(50% + var(--h-step__line--space)); |
| 219 | + --h-step__line--position: absolute; |
| 220 | + --h-step__line--height: var(--h-step__line--thickness); |
| 221 | + --h-step--align-items: center; |
| 222 | +} |
| 223 | +
|
| 224 | +.h-step--direction-vertical.h-step--text-direction-horizontal { |
| 225 | + --h-step--flex-direction: row; |
| 226 | + --h-step__content--flex-direction: row; |
| 227 | + --h-step__text--margin: 0 0 0 8px; |
| 228 | + --h-step__line--height: calc(100% - (var(--h-step__line--space) / 4) * 2); |
| 229 | + --h-step__line--width: var(--h-step__line--thickness); |
| 230 | + --h-step__line--position: absolute; |
| 231 | + --h-step__line--top: calc(var(--h-step__line--space) + var(--h-step__line--space) / 4); |
| 232 | + --h-step__line--left: calc(var(--h-step__line--space) / 2); |
| 233 | + --h-step--margin: 0 0 var(--h-step__line--space) 0; |
| 234 | +} |
| 235 | +
|
| 236 | +.h-step--direction-vertical.h-step--text-direction-vertical { |
| 237 | + --h-step__content--flex-direction: column; |
| 238 | + --h-step--align-items: center; |
| 239 | + --h-step__line--position: relative; |
| 240 | + --h-step__content--align-items: center; |
| 241 | + --h-step__line--height: calc(var(--h-step__line--space) - (var(--h-step__line--space) / 4) * 2); |
| 242 | + --h-step__line--width: var(--h-step__line--thickness); |
| 243 | + --h-step__line--margin: 8px 0; |
| 244 | + --h-step__text--margin: 8px 0 0 0; |
| 245 | +} |
| 246 | +
|
| 247 | +.h-step__line { |
| 248 | + position: var(--h-step__line--position); |
| 249 | + border-radius: 4px; |
| 250 | + width: var(--h-step__line--width); |
| 251 | + top: var(--h-step__line--top); |
| 252 | + left: var(--h-step__line--left); |
| 253 | + flex: var(--h-step__line--flex); |
| 254 | + margin: var(--h-step__line--margin); |
| 255 | + height: var(--h-step__line--height); |
| 256 | + background-color: var(--h-step__line--color); |
| 257 | + z-index: 1000; |
| 258 | +} |
| 259 | +
|
| 260 | +.h-step:last-child { |
| 261 | + --h-step--margin: 0; |
| 262 | +
|
| 263 | + & .h-step__line { |
| 264 | + display: none; |
| 265 | + } |
| 266 | +} |
| 267 | +
|
| 268 | +.h-step__badge { |
| 269 | + width: var(--h-step__badge-size); |
| 270 | + height: var(--h-step__badge-size); |
| 271 | + background-color: var(--h-step__badge--background-color); |
| 272 | + border-radius: var(--border-radius-circle); |
| 273 | + color: var(--h-step__badge-color); |
| 274 | + transition: background-color 0.125s ease-in; |
| 275 | + z-index: 10; |
| 276 | + display: flex; |
| 277 | + justify-content: center; |
| 278 | + align-items: center; |
| 279 | +}; |
| 280 | +
|
| 281 | +.h-step__text { |
| 282 | + margin: var(--h-step__text--margin); |
| 283 | + color: var(--h-step__text--color); |
| 284 | + justify-content: center; |
| 285 | + display: flex; |
| 286 | + flex-direction: column; |
| 287 | +} |
| 288 | +
|
| 289 | +.h-step__text-description { |
| 290 | + max-height: 500px; |
| 291 | + overflow: visible; |
| 292 | +} |
| 293 | +
|
| 294 | +.h-step__transition-enter-active, |
| 295 | +.h-step__transition-leave-active { |
| 296 | + transition: opacity 0.25s ease-in-out, max-height 0.25s ease-in-out; |
| 297 | +} |
| 298 | +
|
| 299 | +.h-step__transition-enter-from, |
| 300 | +.h-step__transition-leave-to { |
| 301 | + opacity: 0; |
| 302 | + max-height: 0; |
| 303 | +} |
| 304 | +</style> |
0 commit comments