_forms.scss 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. // Forms basic
  2. // Input + label wrapper styles
  3. .md-form {
  4. // Text inputs
  5. input:not([type]),
  6. input[type="text"]:not(.browser-default),
  7. input[type="password"]:not(.browser-default),
  8. input[type="email"]:not(.browser-default),
  9. input[type="url"]:not(.browser-default),
  10. input[type="time"]:not(.browser-default),
  11. input[type="date"]:not(.browser-default),
  12. input[type="datetime"]:not(.browser-default),
  13. input[type="datetime-local"]:not(.browser-default),
  14. input[type="tel"]:not(.browser-default),
  15. input[type="number"]:not(.browser-default),
  16. input[type="search"]:not(.browser-default),
  17. input[type="search-md"],
  18. textarea.md-textarea {
  19. // General Styles
  20. box-sizing: content-box;
  21. background-color: transparent;
  22. border: none;
  23. border-bottom: 1px solid $input-border-color;
  24. border-radius: 0;
  25. outline: none;
  26. box-shadow: none;
  27. transition: $input-transition;
  28. // Focused input style
  29. &:focus:not([readonly]) {
  30. border-bottom: 1px solid $input-md-focus-color;
  31. box-shadow: 0 1px 0 0 $input-md-focus-color;
  32. // Focused label style
  33. + label {
  34. color: $input-md-focus-color;
  35. }
  36. }
  37. // Form message shared styles
  38. + label::after {
  39. position: absolute;
  40. top: $input-label-after-top;
  41. display: block;
  42. content: "";
  43. opacity: 0;
  44. transition: $input-label-after-transition;
  45. }
  46. // Valid input style
  47. &.valid,
  48. &:focus.valid {
  49. border-bottom: 1px solid $input-success-color;
  50. box-shadow: 0 1px 0 0 $input-success-color;
  51. }
  52. &.valid + label:after,
  53. &:focus.valid + label:after {
  54. color: $input-success-color;
  55. content: attr(data-success);
  56. opacity: 1;
  57. }
  58. // Invalid input style
  59. &.invalid,
  60. &:focus.invalid {
  61. border-bottom: 1px solid $input-error-color;
  62. box-shadow: 0 1px 0 0 $input-error-color;
  63. }
  64. &.invalid + label:after,
  65. &:focus.invalid + label:after {
  66. color: $input-error-color;
  67. content: attr(data-error);
  68. opacity: 1;
  69. }
  70. &.form-control.valid + label:after,
  71. &.form-control:focus.valid + label:after {
  72. top: $input-label-valid-top;
  73. }
  74. &.form-control.invalid + label:after,
  75. &.form-control:focus.invalid + label:after {
  76. top: $input-label-invalid-top;
  77. }
  78. &.form-control-lg.valid + label:after,
  79. &.form-control-lg:focus.valid + label:after {
  80. top: $input-label-valid-top-lg;
  81. }
  82. &.form-control-lg.invalid + label:after,
  83. &.form-control-lg:focus.invalid + label:after {
  84. top: $input-label-invalid-top-lg;
  85. }
  86. &.form-control-sm.valid + label:after,
  87. &.form-control-sm:focus.valid + label:after {
  88. top: $input-label-valid-top-sm;
  89. }
  90. &.form-control-sm.invalid + label:after,
  91. &.form-control-sm:focus.invalid + label:after {
  92. top: $input-label-invalid-top-sm;
  93. }
  94. }
  95. > input[type="date"]:not(.browser-default) + label {
  96. transform: translateY(-27px) scale(.8);
  97. transform-origin: 0 0;
  98. }
  99. > input[type]:-webkit-autofill:not(.browser-default):not([type="search"]) + label,
  100. > input[type="time"]:not(.browser-default) + label {
  101. font-size: .8rem;
  102. transform: translateY(-25px);
  103. transform-origin: 0 0;
  104. }
  105. .was-validated {
  106. input[type="text"] {
  107. &:valid {
  108. + label {
  109. color: $input-success-color !important;
  110. }
  111. }
  112. &:invalid {
  113. + label {
  114. color: $input-error-color !important;
  115. }
  116. }
  117. }
  118. .form-control {
  119. &:valid:focus {
  120. box-shadow: 0 1px 0 0 $input-success-color !important;
  121. }
  122. &:valid {
  123. border-color: $input-success-color !important;
  124. }
  125. &:invalid:focus {
  126. box-shadow: 0 1px 0 0 $input-error-color !important;
  127. }
  128. &:invalid {
  129. border-color: $input-error-color !important;
  130. }
  131. }
  132. }
  133. // Input with label
  134. .form-control {
  135. height: auto;
  136. padding: $input-form-control-padding-top 0 $input-form-control-padding-bottom 0;
  137. margin: 0 0 $input-form-control-margin-bottom 0;
  138. background-color: transparent;
  139. border-radius: 0;
  140. &:focus {
  141. box-shadow: none;
  142. }
  143. &:disabled,
  144. &[readonly] {
  145. background-color: transparent;
  146. border-bottom: 1px solid $grey-lighten-1;
  147. }
  148. &.is-valid {
  149. border-color: $input-success-color;
  150. &:focus {
  151. border-color: $input-success-color !important;
  152. box-shadow: 0 1px 0 0 $input-success-color !important;
  153. }
  154. }
  155. &.is-invalid {
  156. border-color: $input-error-color;
  157. &:focus {
  158. border-color: $input-error-color !important;
  159. box-shadow: 0 1px 0 0 $input-error-color !important;
  160. }
  161. }
  162. &.is-valid,
  163. &.is-invalid {
  164. background-position: center right !important;
  165. }
  166. }
  167. @include make-input($input-validate-mb, $input-label-font-size, $input-label-active-font-size, $input-prefix-top, $input-prefix-font-size, $input-prefix-margin-left, $input-prefix-width, $input-form-text-ml);
  168. position: relative;
  169. margin-top: $input-md-form-margin-top;
  170. margin-bottom: $input-md-form-margin-bottom;
  171. label {
  172. position: absolute;
  173. top: 0;
  174. left: 0;
  175. font-size: 1rem;
  176. color: $input-label-color;
  177. cursor: text;
  178. transition: transform .2s ease-out, color .2s ease-out;
  179. transform: translateY(12px);
  180. transform-origin: 0% 100%;
  181. &.active {
  182. transform: translateY(-14px) scale(.8);
  183. }
  184. }
  185. .prefix {
  186. position: absolute;
  187. transition: $input-prefix-transition;
  188. &.active {
  189. color: $input-md-focus-color;
  190. }
  191. }
  192. &.form-lg {
  193. @include make-input($input-validate-mb-lg, $input-label-font-size-lg, $input-label-active-font-size-lg, $input-prefix-top-lg, $input-prefix-font-size-lg, $input-prefix-margin-left-lg, $input-prefix-width-lg, $input-form-text-ml-lg);
  194. }
  195. &.form-sm {
  196. @include make-input($input-validate-mb-sm, $input-label-font-size-sm, $input-label-active-font-size-sm, $input-prefix-top-sm, $input-prefix-font-size-sm, $input-prefix-margin-left-sm, $input-prefix-width-sm, $input-form-text-ml-sm);
  197. }
  198. // Textarea
  199. textarea {
  200. &.md-textarea {
  201. padding: $textarea-padding 0;
  202. overflow-y: hidden;
  203. }
  204. &.md-textarea-auto {
  205. padding: 0;
  206. padding-top: $textarea-padding;
  207. }
  208. // Label color for textarea
  209. // ~ label {
  210. // &.active {
  211. // color: $input-md-focus-color;
  212. // }
  213. // }
  214. }
  215. &.md-outline {
  216. position: relative;
  217. margin-top: 1.5rem;
  218. margin-bottom: 1.5rem;
  219. input[type="text"],
  220. input[type="password"],
  221. input[type="email"],
  222. input[type="url"],
  223. input[type="time"],
  224. input[type="date"],
  225. input[type="datetime-local"],
  226. input[type="tel"],
  227. input[type="number"],
  228. input[type="search-md"],
  229. input[type="search"],
  230. textarea.md-textarea {
  231. // General Styles
  232. box-sizing: border-box;
  233. background-color: transparent;
  234. border: 1px solid #dadce0;
  235. border-radius: 4px;
  236. outline: none;
  237. box-shadow: none;
  238. transition: all .3s;
  239. // Focused input style
  240. &:focus:not([readonly]) {
  241. border-color: #4285f4;
  242. box-shadow: inset 0 0 0 1px #4285f4;
  243. // Focused label style
  244. + label {
  245. color: #4285f4;
  246. }
  247. }
  248. // Valid input style
  249. &.valid,
  250. &:focus.valid {
  251. border-color: $input-success-color;
  252. box-shadow: inset 0 0 0 1px $input-success-color;
  253. }
  254. &:focus:not([readonly]).valid + label,
  255. &.valid + label:after,
  256. &:focus.valid + label:after {
  257. color: $input-success-color;
  258. content: attr(data-success);
  259. opacity: 1;
  260. }
  261. // Invalid input style
  262. &.invalid,
  263. &:focus.invalid {
  264. border-color: $input-error-color;
  265. box-shadow: inset 0 0 0 1px $input-error-color;
  266. }
  267. &:focus:not([readonly]).invalid + label,
  268. &.invalid + label:after,
  269. &:focus.invalid + label:after {
  270. color: $input-error-color;
  271. content: attr(data-error);
  272. opacity: 1;
  273. }
  274. &.form-control.valid + label:after,
  275. &.form-control:focus.valid + label:after {
  276. position: absolute;
  277. top: 4rem;
  278. left: 0;
  279. }
  280. &.form-control.invalid + label:after,
  281. &.form-control:focus.invalid + label:after {
  282. position: absolute;
  283. top: 4rem;
  284. left: 0;
  285. }
  286. }
  287. > input[type]:-webkit-autofill:not(.browser-default):not([type="search"]) + label,
  288. > input[type="time"]:not(.browser-default) + label {
  289. left: 8px;
  290. padding-right: 5px;
  291. padding-left: 5px;
  292. font-size: 1rem;
  293. font-weight: 500;
  294. background: #fff;
  295. transform: translateY(-9px) scale(.8);
  296. transform-origin: 0 0;
  297. }
  298. > input[type]:-webkit-autofill:not(.browser-default):not([type="search"]) + label.active,
  299. > input[type="time"]:not(.browser-default) + label.active {
  300. transform: translateY(-9px) scale(.8);
  301. transform-origin: 0 0;
  302. }
  303. @-webkit-keyframes autofill {
  304. to {
  305. color: #495057;
  306. background: transparent;
  307. }
  308. }
  309. @keyframes autofill {
  310. to {
  311. color: #495057;
  312. background: transparent;
  313. }
  314. }
  315. input:-webkit-autofill {
  316. -webkit-animation-name: autofill;
  317. animation-name: autofill;
  318. -webkit-animation-fill-mode: both;
  319. animation-fill-mode: both;
  320. }
  321. .form-control {
  322. padding: .375rem .75rem;
  323. }
  324. label {
  325. position: absolute;
  326. top: 0;
  327. left: 0;
  328. padding-left: 10px;
  329. font-size: 1rem;
  330. color: #757575;
  331. cursor: text;
  332. transition: transform .2s ease-out, color .2s ease-out;
  333. transform: translateY(9px);
  334. transform-origin: 0% 100%;
  335. &.active {
  336. left: 8px;
  337. padding-right: 5px;
  338. padding-left: 5px;
  339. font-weight: 500;
  340. background: #fff;
  341. transform: translateY(-13px) scale(.8);
  342. }
  343. }
  344. &.form-lg {
  345. .form-control {
  346. &.form-control-lg {
  347. padding: .5rem .725rem;
  348. }
  349. }
  350. label {
  351. font-size: 1.25rem;
  352. transform: translateY(10px);
  353. &.active {
  354. font-size: 1.1rem;
  355. transform: translateY(-14px) scale(.8);
  356. }
  357. }
  358. .prefix {
  359. top: .65rem;
  360. font-size: 25px;
  361. ~ input,
  362. ~ textarea {
  363. width: calc(100% - 2.2rem);
  364. margin-left: 2.2rem;
  365. }
  366. ~ label {
  367. margin-left: 2.2rem;
  368. }
  369. ~ .form-text {
  370. margin-left: 2.3rem;
  371. }
  372. }
  373. }
  374. &.form-sm {
  375. .form-control {
  376. &.form-control-sm {
  377. padding: .25rem .625rem;
  378. }
  379. }
  380. label {
  381. font-size: .8rem;
  382. transform: translateY(8px);
  383. &.active {
  384. font-size: .85rem;
  385. transform: translateY(-12px) scale(.8);
  386. }
  387. }
  388. .prefix {
  389. top: .5rem;
  390. font-size: 15px;
  391. ~ input,
  392. ~ textarea {
  393. width: calc(100% - 1.6rem);
  394. margin-left: 1.6rem;
  395. }
  396. ~ label {
  397. margin-left: 1.6rem;
  398. }
  399. ~ .form-text {
  400. margin-left: 1.7rem;
  401. }
  402. }
  403. }
  404. .prefix {
  405. position: absolute;
  406. top: .6rem;
  407. font-size: 20px;
  408. transition: color .2s;
  409. &:focus {
  410. color: #4285f4;
  411. }
  412. ~ input,
  413. ~ textarea {
  414. width: calc(100% - 2rem);
  415. margin-left: 2rem;
  416. }
  417. ~ label {
  418. margin-left: 2rem;
  419. }
  420. ~ .form-text {
  421. margin-left: 2.1rem;
  422. }
  423. }
  424. .character-counter {
  425. margin-top: -.5rem;
  426. }
  427. }
  428. &.md-bg {
  429. input[type="text"],
  430. input[type="password"],
  431. input[type="email"],
  432. input[type="url"],
  433. input[type="time"],
  434. input[type="date"],
  435. input[type="datetime-local"],
  436. input[type="tel"],
  437. input[type="number"],
  438. input[type="search-md"],
  439. input[type="search"],
  440. textarea.md-textarea {
  441. &:focus:not([readonly]) {
  442. border-bottom: none;
  443. box-shadow: none;
  444. }
  445. box-sizing: border-box;
  446. padding: 10px 5px;
  447. background: #f5f5f5 no-repeat;
  448. background-image: linear-gradient(to bottom, $input-md-focus-color, $input-md-focus-color), linear-gradient(to bottom, $input-border-color, $input-border-color);
  449. background-position: 50% 100%, 50% 100%;
  450. background-size: 0 2px, 100% 1px;
  451. border: 0;
  452. border-top-left-radius: .3rem;
  453. border-top-right-radius: .3rem;
  454. transition: background-size .3s cubic-bezier(.64, .09, .08, 1);
  455. &:focus {
  456. background-color: #dcdcdc;
  457. background-size: 100% 2px, 100% 1px;
  458. outline: none;
  459. }
  460. }
  461. > input[type="date"]:not(.browser-default) + label {
  462. transform: translateY(-12px) scale(.8);
  463. transform-origin: 0 0;
  464. }
  465. > input[type]:-webkit-autofill:not(.browser-default):not([type="search"]) + label,
  466. > input[type="time"]:not(.browser-default) + label {
  467. font-size: .8rem;
  468. transform: translateY(-12px);
  469. transform-origin: 0 0;
  470. }
  471. .form-control {
  472. padding: 1.1rem .7rem .4rem !important;
  473. }
  474. label {
  475. top: 0;
  476. padding-left: .7rem;
  477. font-size: 1rem;
  478. transition: transform .2s ease-out, color .2s ease-out;
  479. transform: translateY(13px);
  480. transform-origin: 0% 100%;
  481. &.active {
  482. padding-left: .75rem;
  483. font-weight: 500;
  484. transform: translateY(-3px) scale(.8);
  485. }
  486. }
  487. &.form-lg {
  488. label {
  489. transform: translateY(16px);
  490. &.active {
  491. transform: translateY(-4px) scale(.8);
  492. }
  493. }
  494. }
  495. &.form-sm {
  496. label {
  497. transform: translateY(11px);
  498. &.active {
  499. transform: translateY(-2px) scale(.8);
  500. }
  501. }
  502. }
  503. }
  504. }
  505. .md-form .form-control.is-invalid,
  506. .was-validated .md-form .form-control:invalid {
  507. padding-right: 0;
  508. }
  509. .md-form .form-control.is-valid,
  510. .was-validated .md-form .form-control:valid {
  511. padding-right: 0;
  512. }
  513. .needs-validation .md-form label {
  514. left: .3rem;
  515. }
  516. // Custom file input browser support
  517. @each $lang,
  518. $text in $custom-mdb-file-text {
  519. .custom-file-input {
  520. &:lang(#{$lang}) {
  521. & ~ .custom-file-label {
  522. &::after {
  523. content: $text;
  524. }
  525. }
  526. }
  527. }
  528. }