_forms.scss 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. // Forms
  2. .form-group {
  3. &:not(:last-child) {
  4. margin-bottom: $layout-spacing;
  5. }
  6. }
  7. fieldset {
  8. margin-bottom: $layout-spacing-lg;
  9. }
  10. legend {
  11. font-size: $font-size-lg;
  12. font-weight: 500;
  13. margin-bottom: $layout-spacing-lg;
  14. }
  15. // Form element: Label
  16. .form-label {
  17. display: block;
  18. line-height: $line-height;
  19. padding: $control-padding-y + $border-width 0;
  20. &.label-sm {
  21. font-size: $font-size-sm;
  22. padding: $control-padding-y-sm + $border-width 0;
  23. }
  24. &.label-lg {
  25. font-size: $font-size-lg;
  26. padding: $control-padding-y-lg + $border-width 0;
  27. }
  28. }
  29. // Form element: Input
  30. .form-input {
  31. @include control-transition();
  32. appearance: none;
  33. background: $bg-color-light;
  34. background-image: none;
  35. border: $border-width solid $border-color-dark;
  36. border-radius: $border-radius;
  37. color: $body-font-color;
  38. display: block;
  39. font-size: $font-size;
  40. height: $control-size;
  41. line-height: $line-height;
  42. max-width: 100%;
  43. outline: none;
  44. padding: $control-padding-y $control-padding-x;
  45. position: relative;
  46. width: 100%;
  47. &:focus {
  48. @include control-shadow();
  49. border-color: $primary-color;
  50. }
  51. &::placeholder {
  52. color: $gray-color;
  53. }
  54. // Input sizes
  55. &.input-sm {
  56. font-size: $font-size-sm;
  57. height: $control-size-sm;
  58. padding: $control-padding-y-sm $control-padding-x-sm;
  59. }
  60. &.input-lg {
  61. font-size: $font-size-lg;
  62. height: $control-size-lg;
  63. padding: $control-padding-y-lg $control-padding-x-lg;
  64. }
  65. &.input-inline {
  66. display: inline-block;
  67. vertical-align: middle;
  68. width: auto;
  69. }
  70. // Input types
  71. &[type="file"] {
  72. height: auto;
  73. }
  74. }
  75. // Form element: Textarea
  76. textarea.form-input {
  77. height: auto;
  78. }
  79. // Form element: Input hint
  80. .form-input-hint {
  81. color: $gray-color;
  82. font-size: $font-size-sm;
  83. margin-top: $unit-1;
  84. .has-success &,
  85. .is-success + & {
  86. color: $success-color;
  87. }
  88. .has-error &,
  89. .is-error + & {
  90. color: $error-color;
  91. }
  92. }
  93. // Form element: Select
  94. .form-select {
  95. appearance: none;
  96. border: $border-width solid $border-color-dark;
  97. border-radius: $border-radius;
  98. color: inherit;
  99. font-size: $font-size;
  100. height: $control-size;
  101. line-height: $line-height;
  102. outline: none;
  103. padding: $control-padding-y $control-padding-x;
  104. vertical-align: middle;
  105. width: 100%;
  106. &[size],
  107. &[multiple] {
  108. height: auto;
  109. option {
  110. padding: $unit-h $unit-1;
  111. }
  112. }
  113. &:not([multiple]):not([size]) {
  114. background: #fff url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%204%205'%3E%3Cpath%20fill='%23667189'%20d='M2%200L0%202h4zm0%205L0%203h4z'/%3E%3C/svg%3E") no-repeat right .35rem center/.4rem .5rem;
  115. padding-right: $control-icon-size + $control-padding-x;
  116. }
  117. &:focus {
  118. @include control-shadow();
  119. border-color: $primary-color;
  120. }
  121. &::-ms-expand {
  122. display: none;
  123. }
  124. // Select sizes
  125. &.select-sm {
  126. font-size: $font-size-sm;
  127. height: $control-size-sm;
  128. padding: $control-padding-y-sm ($control-icon-size + $control-padding-x-sm) $control-padding-y-sm $control-padding-x-sm;
  129. }
  130. &.select-lg {
  131. font-size: $font-size-lg;
  132. height: $control-size-lg;
  133. padding: $control-padding-y-lg ($control-icon-size + $control-padding-x-lg) $control-padding-y-lg $control-padding-x-lg;
  134. }
  135. }
  136. // Form Icons
  137. .has-icon-left,
  138. .has-icon-right {
  139. position: relative;
  140. .form-icon {
  141. height: $control-icon-size;
  142. margin: 0 $control-padding-y;
  143. position: absolute;
  144. top: 50%;
  145. transform: translateY(-50%);
  146. width: $control-icon-size;
  147. z-index: $zindex-0 + 1;
  148. }
  149. }
  150. .has-icon-left {
  151. .form-icon {
  152. left: $border-width;
  153. }
  154. .form-input {
  155. padding-left: $control-icon-size + $control-padding-y * 2;
  156. }
  157. }
  158. .has-icon-right {
  159. .form-icon {
  160. right: $border-width;
  161. }
  162. .form-input {
  163. padding-right: $control-icon-size + $control-padding-y * 2;
  164. }
  165. }
  166. // Form element: Checkbox and Radio
  167. .form-checkbox,
  168. .form-radio,
  169. .form-switch {
  170. display: inline-block;
  171. line-height: $line-height;
  172. margin: ($control-size - $control-size-sm) / 2 0;
  173. min-height: 1.2rem;
  174. padding: (($control-size-sm - $line-height) / 2) $control-padding-x (($control-size-sm - $line-height) / 2) ($control-icon-size + $control-padding-x);
  175. position: relative;
  176. input {
  177. clip: rect(0, 0, 0, 0);
  178. height: 1px;
  179. margin: -1px;
  180. overflow: hidden;
  181. position: absolute;
  182. width: 1px;
  183. &:focus + .form-icon {
  184. @include control-shadow();
  185. border-color: $primary-color;
  186. }
  187. &:checked + .form-icon {
  188. background: $primary-color;
  189. border-color: $primary-color;
  190. }
  191. }
  192. .form-icon {
  193. @include control-transition();
  194. border: $border-width solid $border-color-dark;
  195. cursor: pointer;
  196. display: inline-block;
  197. position: absolute;
  198. }
  199. // Input checkbox, radio and switch sizes
  200. &.input-sm {
  201. font-size: $font-size-sm;
  202. margin: 0;
  203. }
  204. &.input-lg {
  205. font-size: $font-size-lg;
  206. margin: ($control-size-lg - $control-size-sm) / 2 0;
  207. }
  208. }
  209. .form-checkbox,
  210. .form-radio {
  211. .form-icon {
  212. background: $bg-color-light;
  213. height: $control-icon-size;
  214. left: 0;
  215. top: ($control-size-sm - $control-icon-size) / 2;
  216. width: $control-icon-size;
  217. }
  218. input {
  219. &:active + .form-icon {
  220. background: $bg-color-dark;
  221. }
  222. }
  223. }
  224. .form-checkbox {
  225. .form-icon {
  226. border-radius: $border-radius;
  227. }
  228. input {
  229. &:checked + .form-icon {
  230. &::before {
  231. background-clip: padding-box;
  232. border: $border-width-lg solid $light-color;
  233. border-left-width: 0;
  234. border-top-width: 0;
  235. content: "";
  236. height: 12px;
  237. left: 50%;
  238. margin-left: -4px;
  239. margin-top: -8px;
  240. position: absolute;
  241. top: 50%;
  242. transform: rotate(45deg);
  243. width: 8px;
  244. }
  245. }
  246. &:indeterminate + .form-icon {
  247. background: $primary-color;
  248. border-color: $primary-color;
  249. &::before {
  250. background: $bg-color-light;
  251. content: "";
  252. height: 2px;
  253. left: 50%;
  254. margin-left: -5px;
  255. margin-top: -1px;
  256. position: absolute;
  257. top: 50%;
  258. width: 10px;
  259. }
  260. }
  261. }
  262. }
  263. .form-radio {
  264. .form-icon {
  265. border-radius: 50%;
  266. }
  267. input {
  268. &:checked + .form-icon {
  269. &::before {
  270. background: $bg-color-light;
  271. border-radius: 50%;
  272. content: "";
  273. height: 4px;
  274. left: 50%;
  275. position: absolute;
  276. top: 50%;
  277. transform: translate(-50%, -50%);
  278. width: 4px;
  279. }
  280. }
  281. }
  282. }
  283. // Form element: Switch
  284. .form-switch {
  285. padding-left: ($unit-8 + $control-padding-x);
  286. .form-icon {
  287. background: $gray-color-light;
  288. background-clip: padding-box;
  289. border-radius: $unit-2 + $border-width;
  290. height: $unit-4 + $border-width * 2;
  291. left: 0;
  292. top: ($control-size-sm - $unit-4) / 2 - $border-width;
  293. width: $unit-8;
  294. &::before {
  295. @include control-transition();
  296. background: $bg-color-light;
  297. border-radius: 50%;
  298. content: "";
  299. display: block;
  300. height: $unit-4;
  301. left: 0;
  302. position: absolute;
  303. top: 0;
  304. width: $unit-4;
  305. }
  306. }
  307. input {
  308. &:checked + .form-icon {
  309. &::before {
  310. left: 14px;
  311. }
  312. }
  313. &:active + .form-icon {
  314. &::before {
  315. background: $bg-color;
  316. }
  317. }
  318. }
  319. }
  320. // Form element: Input groups
  321. .input-group {
  322. display: flex;
  323. .input-group-addon {
  324. background: $bg-color;
  325. border: $border-width solid $border-color-dark;
  326. border-radius: $border-radius;
  327. line-height: $line-height;
  328. padding: $control-padding-y $control-padding-x;
  329. white-space: nowrap;
  330. &.addon-sm {
  331. font-size: $font-size-sm;
  332. padding: $control-padding-y-sm $control-padding-x-sm;
  333. }
  334. &.addon-lg {
  335. font-size: $font-size-lg;
  336. padding: $control-padding-y-lg $control-padding-x-lg;
  337. }
  338. }
  339. .form-input,
  340. .form-select {
  341. flex: 1 1 auto;
  342. }
  343. .input-group-btn {
  344. z-index: $zindex-0;
  345. }
  346. .form-input,
  347. .form-select,
  348. .input-group-addon,
  349. .input-group-btn {
  350. &:first-child:not(:last-child) {
  351. border-bottom-right-radius: 0;
  352. border-top-right-radius: 0;
  353. }
  354. &:not(:first-child):not(:last-child) {
  355. border-radius: 0;
  356. margin-left: -$border-width;
  357. }
  358. &:last-child:not(:first-child) {
  359. border-bottom-left-radius: 0;
  360. border-top-left-radius: 0;
  361. margin-left: -$border-width;
  362. }
  363. &:focus {
  364. z-index: $zindex-0 + 1;
  365. }
  366. }
  367. .form-select {
  368. width: auto;
  369. }
  370. &.input-inline {
  371. display: inline-flex;
  372. }
  373. }
  374. // Form validation states
  375. .form-input,
  376. .form-select {
  377. .has-success &,
  378. &.is-success {
  379. border-color: $success-color;
  380. &:focus {
  381. @include control-shadow($success-color);
  382. }
  383. }
  384. .has-error &,
  385. &.is-error {
  386. border-color: $error-color;
  387. &:focus {
  388. @include control-shadow($error-color);
  389. }
  390. }
  391. }
  392. .form-checkbox,
  393. .form-radio,
  394. .form-switch {
  395. .has-error &,
  396. &.is-error {
  397. .form-icon {
  398. border-color: $error-color;
  399. }
  400. input {
  401. &:checked + .form-icon {
  402. background: $error-color;
  403. border-color: $error-color;
  404. }
  405. &:focus + .form-icon {
  406. @include control-shadow($error-color);
  407. border-color: $error-color;
  408. }
  409. }
  410. }
  411. }
  412. // validation based on :placeholder-shown (Edge doesn't support it yet)
  413. .form-input {
  414. &:not(:placeholder-shown) {
  415. &:invalid {
  416. border-color: $error-color;
  417. &:focus {
  418. @include control-shadow($error-color);
  419. }
  420. & + .form-input-hint {
  421. color: $error-color;
  422. }
  423. }
  424. }
  425. }
  426. // Form disabled and readonly
  427. .form-input,
  428. .form-select {
  429. &:disabled,
  430. &.disabled {
  431. background-color: $bg-color-dark;
  432. cursor: not-allowed;
  433. opacity: .5;
  434. }
  435. }
  436. .form-input {
  437. &[readonly] {
  438. background-color: $bg-color;
  439. }
  440. }
  441. input {
  442. &:disabled,
  443. &.disabled {
  444. & + .form-icon {
  445. background: $bg-color-dark;
  446. cursor: not-allowed;
  447. opacity: .5;
  448. }
  449. }
  450. }
  451. .form-switch {
  452. input {
  453. &:disabled,
  454. &.disabled {
  455. & + .form-icon::before {
  456. background: $bg-color-light;
  457. }
  458. }
  459. }
  460. }
  461. // Form Horizontal
  462. .form-horizontal {
  463. padding: $layout-spacing 0;
  464. .form-group {
  465. display: flex;
  466. flex-wrap: wrap;
  467. }
  468. }