_forms.scss 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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: 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. width: 1%;
  343. }
  344. .input-group-btn {
  345. z-index: $zindex-0;
  346. }
  347. .form-input,
  348. .form-select,
  349. .input-group-addon,
  350. .input-group-btn {
  351. &:first-child:not(:last-child) {
  352. border-bottom-right-radius: 0;
  353. border-top-right-radius: 0;
  354. }
  355. &:not(:first-child):not(:last-child) {
  356. border-radius: 0;
  357. margin-left: -$border-width;
  358. }
  359. &:last-child:not(:first-child) {
  360. border-bottom-left-radius: 0;
  361. border-top-left-radius: 0;
  362. margin-left: -$border-width;
  363. }
  364. &:focus {
  365. z-index: $zindex-0 + 1;
  366. }
  367. }
  368. .form-select {
  369. width: auto;
  370. }
  371. &.input-inline {
  372. display: inline-flex;
  373. }
  374. }
  375. // Form validation states
  376. .form-input,
  377. .form-select {
  378. .has-success &,
  379. &.is-success {
  380. border-color: $success-color;
  381. &:focus {
  382. @include control-shadow($success-color);
  383. }
  384. }
  385. .has-error &,
  386. &.is-error {
  387. border-color: $error-color;
  388. &:focus {
  389. @include control-shadow($error-color);
  390. }
  391. }
  392. }
  393. .form-checkbox,
  394. .form-radio,
  395. .form-switch {
  396. .has-error &,
  397. &.is-error {
  398. .form-icon {
  399. border-color: $error-color;
  400. }
  401. input {
  402. &:checked + .form-icon {
  403. background: $error-color;
  404. border-color: $error-color;
  405. }
  406. &:focus + .form-icon {
  407. @include control-shadow($error-color);
  408. border-color: $error-color;
  409. }
  410. }
  411. }
  412. }
  413. .form-checkbox {
  414. .has-error &,
  415. &.is-error {
  416. input {
  417. &:indeterminate + .form-icon {
  418. background: $error-color;
  419. border-color: $error-color;
  420. }
  421. }
  422. }
  423. }
  424. // validation based on :placeholder-shown (Edge doesn't support it yet)
  425. .form-input {
  426. &:not(:placeholder-shown) {
  427. &:invalid {
  428. border-color: $error-color;
  429. &:focus {
  430. @include control-shadow($error-color);
  431. }
  432. & + .form-input-hint {
  433. color: $error-color;
  434. }
  435. }
  436. }
  437. }
  438. // Form disabled and readonly
  439. .form-input,
  440. .form-select {
  441. &:disabled,
  442. &.disabled {
  443. background-color: $bg-color-dark;
  444. cursor: not-allowed;
  445. opacity: .5;
  446. }
  447. }
  448. .form-input {
  449. &[readonly] {
  450. background-color: $bg-color;
  451. }
  452. }
  453. input {
  454. &:disabled,
  455. &.disabled {
  456. & + .form-icon {
  457. background: $bg-color-dark;
  458. cursor: not-allowed;
  459. opacity: .5;
  460. }
  461. }
  462. }
  463. .form-switch {
  464. input {
  465. &:disabled,
  466. &.disabled {
  467. & + .form-icon::before {
  468. background: $bg-color-light;
  469. }
  470. }
  471. }
  472. }
  473. // Form horizontal
  474. .form-horizontal {
  475. padding: $layout-spacing 0;
  476. .form-group {
  477. display: flex;
  478. flex-wrap: wrap;
  479. }
  480. }
  481. // Form inline
  482. .form-inline {
  483. display: inline-block;
  484. }