Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1. <template>
  2. <div :class="classes" :ref-cy="id">
  3. <label v-if="label || labelIcon" class="label">
  4. <c-icon
  5. v-if="labelIcon"
  6. :size="labelIconSize"
  7. :icon="labelIcon"
  8. class="icon"
  9. />
  10.  
  11. <span v-else class="text">{{ label }}</span>
  12.  
  13. <span v-if="required" class="required">*</span>
  14. </label>
  15.  
  16. <!-- @slot The default slot for the form field. -->
  17. <slot />
  18.  
  19. <div class="validation" :style="{ height: validationHeight }">
  20. <transition name="fade" @enter="onEnter" @leave="onLeave">
  21. <div v-if="!!validation" class="wrapper">
  22. <c-flag
  23. error
  24. class="flag"
  25. icon="exclamation"
  26. size="15"
  27. />
  28. <span class="text" v-html="validation" />
  29. </div>
  30. </transition>
  31. </div>
  32.  
  33. <transition name="fade">
  34. <div
  35. class="jumbo-validation"
  36. v-if="!!validation"
  37. v-tooltip:5.dark="{ value: validation, align: 'left', fontSize: 14 }"
  38. >
  39. <c-icon icon="warning-circle" class="icon" />
  40. </div>
  41. </transition>
  42.  
  43. <div class="hint" v-if="hint">
  44. <span class="text" v-html="hint" />
  45. </div>
  46. </div>
  47. </template>
  48.  
  49. <script>
  50. import CFlag from '../CFlag'
  51. import CIcon from '../CIcon'
  52. import CTransition from '../CTransition'
  53. import Tooltip from '../../directives/tooltip'
  54.  
  55. /**
  56. * The container component for form fields, anything from select fields, input
  57. * or checkboxes. Adds standard styles for label, validations and etc.
  58. */
  59. export default {
  60. name: 'CInputContainer',
  61. components: { CFlag, CIcon, CTransition },
  62.  
  63. directives: { Tooltip },
  64.  
  65. props: {
  66. /**
  67. * The id of the field.
  68. */
  69. id: {
  70. type: [String, Number],
  71. default: ''
  72. },
  73. /**
  74. * The label of the field.
  75. */
  76. label: {
  77. type: String,
  78. default: ''
  79. },
  80.  
  81. /**
  82. * Uses a icon a for the field label.
  83. */
  84. labelIcon: String,
  85.  
  86. /**
  87. *
  88. */
  89. labelIconSize: {
  90. type: [String, Number],
  91. default: 24
  92. },
  93.  
  94. /**
  95. * Displays the label on the left-side instead of in the top.
  96. */
  97. labelLeft: Boolean,
  98.  
  99. /**
  100. * The field validation message.
  101. */
  102. validation: String,
  103.  
  104. /**
  105. * The field hint message.
  106. */
  107. hint: String,
  108.  
  109. /**
  110. * Whether the hint should be displayed.
  111. */
  112. showHint: Boolean,
  113.  
  114. /**
  115. * Adds a visual markes to mark the field as required.
  116. */
  117. required: Boolean,
  118.  
  119. /*
  120. * Flag to manipulate the upload type
  121. */
  122. isUploadType: Boolean
  123. },
  124.  
  125. computed: {
  126. classes () {
  127. return [ 'c-input-container', {
  128. '-label': this.label,
  129. '-label-left': this.labelLeft,
  130. '-validation': this.validation,
  131. '-show-hint': this.showHint
  132. }]
  133. }
  134. },
  135.  
  136. data: () => ({
  137. validationHeight: '0px'
  138. }),
  139.  
  140. methods: {
  141. onEnter (element) {
  142. this.$nextTick(() => {
  143. this.validationHeight = element.clientHeight + 'px'
  144. })
  145. },
  146.  
  147. onLeave (element) {
  148. this.validationHeight = '0px'
  149. }
  150. },
  151. }
  152. </script>
  153.  
  154. <style lang="scss">
  155. %validation {
  156. position: relative;
  157. transition: height .3s;
  158.  
  159. & > .wrapper {
  160. position: absolute;
  161. top: 0;
  162. left: 0;
  163. display: flex;
  164. align-items: center;
  165.  
  166. margin-top: 5px;
  167.  
  168. font-weight: 600;
  169. color: $negative-color;
  170. -webkit-font-smoothing: antialiased;
  171.  
  172. & > .flag {
  173. margin-right: 5px;
  174. padding: 2px; // fix icon size
  175. }
  176.  
  177. & > .text {
  178. font-size: 14px;
  179. margin-top: 2px; // blame calbertoni
  180.  
  181. > b { -webkit-font-smoothing: antialiased; }
  182. }
  183. }
  184.  
  185. & > .fade-enter-active,
  186. & > .fade-leave-active {
  187. transition: opacity .5s !important;
  188. }
  189.  
  190. & > .fade-enter,
  191. & > .fade-leave-to {
  192. opacity: 0 !important;
  193. }
  194. }
  195.  
  196. .c-input-container:not(.c-upload) {
  197. position: relative;
  198.  
  199. & > .jumbo-validation { display: none; }
  200. &.-jumbo > .jumbo-validation { display: block; }
  201.  
  202. &.-label:not(.-label-left) {
  203. margin-top: 22px;
  204. &.multi-check, &.radio { margin-top: 30px; }
  205. }
  206.  
  207. &.-label-left > .label {
  208. display: flex;
  209. align-items: center;
  210.  
  211. height: 40px;
  212.  
  213. top: 0px;
  214. right: 100%;
  215. width: 210px;
  216. text-align: right;
  217. justify-content: flex-end;
  218. padding: { left: 20px; right: 20px; }
  219. }
  220.  
  221. & > .label {
  222. position: absolute;
  223. top: -20px;
  224. font-size: 11px;
  225. margin-bottom: 5px;
  226. padding-right: 10px;
  227. text-transform: uppercase;
  228. font-weight: 500;
  229. font-family: $title-font-family;
  230. color: map-get($text-color, base-50);
  231.  
  232. & > .required {
  233. font-size: 10px;
  234. margin-left: 3px;
  235. color: map-get($negative-color-map, light);
  236. }
  237.  
  238. & > .icon { fill: map-get($text-color, base-30); }
  239. }
  240.  
  241. & > .validation {
  242. @extend %validation;
  243. }
  244.  
  245. & > .hint {
  246. position: absolute;
  247. width: 999px;
  248. max-width: 330px;
  249. top: 50%;
  250. left: 100%;
  251. transform: translate(22px, -50%);
  252. padding-left: 12px;
  253. visibility: hidden;
  254.  
  255. &:before{
  256. content: "";
  257. position: absolute;
  258. top: 50%;
  259. left: 0;
  260. width: 2px;
  261. height: 0%;
  262. background: rgba(#121E48, .1);
  263. transform: translate(-100%, -50%);
  264. transition: .3s ease-out;
  265. }
  266.  
  267. &:after{
  268. content: "";
  269. position: absolute;
  270. left: -1px;
  271. top: 50%;
  272. width: 6px;
  273. height: 6px;
  274. transform: translate(-50%, -50%);
  275. border-radius: 6px;
  276. opacity: 0;
  277. background-color: #121E48;
  278. transition: .3s ease-out;
  279. }
  280.  
  281. > .text {
  282. color: #121E48;
  283. font-size: 14px;
  284. line-height: 19px;
  285. display: block;
  286. transform: translateX(-4px);
  287. opacity: 0;
  288. transition: .3s ease-out;
  289. }
  290. }
  291.  
  292. &.-show-hint{
  293. @include responsive (tablet, desktop) {
  294. & > .hint {
  295. visibility: visible;
  296.  
  297. &:before { height: 100%; }
  298. &:after { opacity: .5; }
  299. > .text{
  300. opacity: .5;
  301. transform: translateX(0px);
  302. }
  303. }
  304. }
  305. }
  306.  
  307. & > .jumbo-validation {
  308. position: absolute;
  309. top: calc(50% - 10px);
  310. right: 20px;
  311. width: 20px;
  312. height: 20px;
  313.  
  314. & > .icon { fill: map-get($negative-color-map, light); }
  315. }
  316.  
  317. & > .validation {
  318.  
  319. }
  320.  
  321. &.c-radio-button {
  322. & > .validation{
  323. top: initial;
  324. bottom: -30px;
  325. @include responsive (tablet, desktop) {
  326. bottom: -13px;
  327. }
  328. }
  329. }
  330. }
  331.  
  332. .c-input-container.c-upload {
  333. & > .validation {
  334. right: 50%;
  335. bottom: 15px;
  336. position: absolute;
  337. @extend %validation;
  338. transform: translateX(50%);
  339. }
  340.  
  341. & > .jumbo-validation { display: none; }
  342. }
  343. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement