ColumnWrapper.vue
2 years ago
CxVuiCollapseMini.vue
2 years ago
CxVuiDate.vue
2 years ago
CxVuiFSelect.vue
2 years ago
CxVuiPopup.vue
2 years ago
CxVuiSelect.vue
2 years ago
CxVuiTabs.vue
2 years ago
CxVuiTabsPanel.vue
2 years ago
Delimiter.vue
2 years ago
DetailsTable.vue
2 years ago
DetailsTableRow.vue
2 years ago
DetailsTableRowValue.vue
2 years ago
ExternalLink.vue
2 years ago
ListComponents.vue
2 years ago
PrintButton.vue
2 years ago
RowWrapper.vue
2 years ago
Tooltip.vue
2 years ago
Tooltip.vue
185 lines
| 1 | <template> |
| 2 | <div :class="wrapperClasses"> |
| 3 | <span :class="dashIconClass"></span> |
| 4 | <span class="jfb-icon-status--text" v-if="$slots.default"> |
| 5 | <slot></slot> |
| 6 | </span> |
| 7 | <div |
| 8 | v-if="$slots.help" |
| 9 | :class="tooltipClasses" |
| 10 | > |
| 11 | <slot name="help"></slot> |
| 12 | </div> |
| 13 | </div> |
| 14 | </template> |
| 15 | |
| 16 | <script> |
| 17 | const schema = { |
| 18 | success: 'dashicons-yes-alt', |
| 19 | warning: 'dashicons-warning', |
| 20 | 'warning-danger': [ 'dashicons-warning', 'danger' ], |
| 21 | info: 'dashicons-info', |
| 22 | pending: 'dashicons-hourglass', |
| 23 | error: 'dashicons-dismiss', |
| 24 | loading: [ 'dashicons-update', 'loading' ], |
| 25 | }; |
| 26 | |
| 27 | export default { |
| 28 | name: 'Tooltip', |
| 29 | props: { |
| 30 | icon: { |
| 31 | type: String, |
| 32 | validator( value ) { |
| 33 | return Object.keys( schema ).includes( value ); |
| 34 | }, |
| 35 | default: 'info', |
| 36 | }, |
| 37 | position: { |
| 38 | type: String, |
| 39 | validator( value ) { |
| 40 | return [ 'top-right', 'top-left' ].includes( value ); |
| 41 | }, |
| 42 | default: 'top-left', |
| 43 | }, |
| 44 | }, |
| 45 | computed: { |
| 46 | wrapperClasses() { |
| 47 | return { |
| 48 | 'jfb-tooltip': true, |
| 49 | 'jfb-tooltip-has-text': !!this.$slots.default, |
| 50 | 'jfb-tooltip-has-help': !!this.$slots.help, |
| 51 | [ 'jfb-tooltip-position--' + this.position ]: true, |
| 52 | }; |
| 53 | }, |
| 54 | dashIconClass() { |
| 55 | let classes = schema[ this.icon ] ?? ''; |
| 56 | |
| 57 | if ( !Array.isArray( classes ) ) { |
| 58 | classes = [ classes ]; |
| 59 | } |
| 60 | |
| 61 | return [ 'dashicons', ...classes ]; |
| 62 | }, |
| 63 | tooltipClasses() { |
| 64 | return { |
| 65 | 'cx-vui-tooltip': true, |
| 66 | [ 'tooltip-position-' + this.position ]: true, |
| 67 | }; |
| 68 | }, |
| 69 | }, |
| 70 | }; |
| 71 | </script> |
| 72 | |
| 73 | <style scoped lang="scss"> |
| 74 | .jfb-tooltip { |
| 75 | position: relative; |
| 76 | display: inline-block; |
| 77 | |
| 78 | &-has-help { |
| 79 | cursor: pointer; |
| 80 | } |
| 81 | |
| 82 | &-has-text { |
| 83 | display: flex; |
| 84 | column-gap: 0.5em; |
| 85 | align-items: center; |
| 86 | } |
| 87 | |
| 88 | &--text { |
| 89 | text-overflow: ellipsis; |
| 90 | overflow: hidden; |
| 91 | padding: 0.1em 0; |
| 92 | } |
| 93 | |
| 94 | .dashicons { |
| 95 | &-dismiss { |
| 96 | color: #d63638; |
| 97 | } |
| 98 | |
| 99 | &-warning { |
| 100 | color: #ffa500; |
| 101 | } |
| 102 | |
| 103 | &-warning.danger { |
| 104 | color: #d63638; |
| 105 | } |
| 106 | |
| 107 | &-yes-alt { |
| 108 | color: #32cd32; |
| 109 | } |
| 110 | |
| 111 | &-info { |
| 112 | color: #90c6db; |
| 113 | } |
| 114 | |
| 115 | &-hourglass { |
| 116 | color: #b5b5b5; |
| 117 | } |
| 118 | |
| 119 | &-update.loading { |
| 120 | animation: jfb-tooltip-loading-icon 1.5s infinite linear; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | .cx-vui-tooltip { |
| 125 | width: fit-content; |
| 126 | bottom: calc(100% + 15px); |
| 127 | box-sizing: border-box; |
| 128 | pointer-events: none; |
| 129 | transition: all 0.180s linear; |
| 130 | opacity: 0; |
| 131 | padding-left: 1em; |
| 132 | padding-right: 1em; |
| 133 | position: absolute; |
| 134 | z-index: 2; |
| 135 | |
| 136 | &.tooltip-position-top-right { |
| 137 | right: -1.2em; |
| 138 | |
| 139 | &:after { |
| 140 | right: 20px; |
| 141 | left: unset; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | &.tooltip-position-top-left { |
| 146 | left: -0.9em; |
| 147 | |
| 148 | &:after { |
| 149 | left: 20px; |
| 150 | right: unset; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | &:hover { |
| 156 | .cx-vui-tooltip { |
| 157 | opacity: 1; |
| 158 | |
| 159 | &.tooltip-position-top-right { |
| 160 | bottom: 100%; |
| 161 | } |
| 162 | |
| 163 | &.tooltip-position-top-left { |
| 164 | bottom: 100%; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | &-position { |
| 170 | &--top-right { |
| 171 | flex-direction: row-reverse; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | @keyframes jfb-tooltip-loading-icon { |
| 177 | 0% { |
| 178 | transform: rotate(0deg) |
| 179 | } |
| 180 | |
| 181 | to { |
| 182 | transform: rotate(359deg) |
| 183 | } |
| 184 | } |
| 185 | </style> |