_forms.scss 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. $form-range-track-width: 100%;
  2. $form-range-track-height: .25rem;
  3. $form-range-track-cursor: pointer;
  4. $form-range-track-bg: $color-border;
  5. $form-range-track-border-radius: 1rem;
  6. $form-range-track-box-shadow: none;
  7. $form-range-thumb-width: 1rem;
  8. $form-range-thumb-height: $form-range-thumb-width;
  9. $form-range-thumb-bg: $color-primary;
  10. $form-range-thumb-border: 0;
  11. $form-range-thumb-border-radius: 1rem;
  12. $form-range-thumb-box-shadow: 0 0 0 .125rem $color-background;
  13. $form-range-thumb-focus-box-shadow: 0 0 0 1px #fff, 0 0 0 4px rgba($color-primary, .2);
  14. $form-range-thumb-focus-box-shadow-width: .25rem;
  15. $form-range-thumb-active-bg: darken($form-range-thumb-bg, 10%);
  16. $form-range-thumb-disabled-bg: #eee;
  17. $form-range-thumb-transition: background-color .3s ease-in-out, border-color .3s ease-in-out;
  18. %form-common {
  19. appearance: none;
  20. border-radius: $border-radius;
  21. border: 1px solid $color-border;
  22. background: $color-white;
  23. color: inherit;
  24. &:focus {
  25. border-color: $color-primary;
  26. box-shadow: 0 0 0 3px rgba($color-primary, .2);
  27. }
  28. }
  29. .form-control {
  30. @extend %form-common;
  31. display: block;
  32. width: 100%;
  33. height: $form-btn-height;
  34. padding: subtract($gap-2, 1px) $gap-3;
  35. &::placeholder {
  36. color: rgba($color-muted, .75);
  37. }
  38. @at-root textarea#{&} {
  39. resize: vertical;
  40. min-height: add(4rem, 2px);
  41. &[rows] {
  42. height: auto;
  43. }
  44. }
  45. &[type="search"] {
  46. background: $color-white url-svg('<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="#{$color-muted}" fill="none" stroke-linecap="round" stroke-linejoin="round"><circle cx="10" cy="10" r="7" /><line x1="21" y1="21" x2="15" y2="15" /></svg>') no-repeat .75rem center/1.25rem;
  47. padding-left: 2.5rem;
  48. }
  49. &[type="search"]::-webkit-search-cancel-button {
  50. -webkit-appearance: none;
  51. height: 2rem;
  52. width: 2rem;
  53. margin-right: -.5rem;
  54. background: url-svg('<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="#{$color-text}" fill="none" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" /></svg>') no-repeat center/1.25rem;
  55. opacity: .64;
  56. cursor: pointer;
  57. &:hover {
  58. opacity: 1;
  59. }
  60. }
  61. }
  62. .form-label {
  63. display: block;
  64. font-weight: $font-weight-medium;
  65. margin-bottom: 0.5rem
  66. }
  67. .form-check {
  68. @extend %form-common;
  69. width: $form-check-size;
  70. height: $form-check-size;
  71. cursor: pointer;
  72. &:checked,
  73. &.checked {
  74. background-image: url-svg('<svg viewBox="0 0 16 16"><polyline points="3 7 7 11 13 4" fill="none" stroke="#{$form-focus-color}" stroke-width="3" /></svg>');
  75. background-repeat: no-repeat;
  76. &:disabled,
  77. &.disabled {
  78. background-image: url-svg('<svg viewBox="0 0 16 16"><polyline points="3 7 7 11 13 4" fill="none" stroke="#{rgba($color-muted, .64)}" stroke-width="3" /></svg>');
  79. }
  80. }
  81. &[type="radio"] {
  82. border-radius: 50%;
  83. &:checked,
  84. &.checked {
  85. background-image: url-svg('<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="4" fill="#{$form-focus-color}" /></svg>');
  86. &:disabled,
  87. &.disabled {
  88. background-image: url-svg('<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="4" fill="#{rgba($color-muted, .64)}" /></svg>');
  89. }
  90. }
  91. }
  92. }
  93. .form-check-label {
  94. display: inline-flex;
  95. align-items: center;
  96. user-select: none;
  97. cursor: pointer;
  98. }
  99. .form-check-text {
  100. margin-left: $gap-2;
  101. @include text-truncate(100%);
  102. }
  103. .form-check-list {
  104. display: flex;
  105. flex-direction: column;
  106. >:not(:first-child) {
  107. margin-top: $gap-1;
  108. }
  109. .form-check-text {
  110. color: $color-muted;
  111. transition: .3s color;
  112. }
  113. .form-check:checked + .form-check-text {
  114. color: $color-text;
  115. }
  116. }
  117. .form-footer {
  118. margin-top: 2rem;
  119. }
  120. .form-range {
  121. width: 100%;
  122. height: add($form-range-thumb-height, $form-range-thumb-focus-box-shadow-width * 2);
  123. padding: 0;
  124. background-color: transparent;
  125. appearance: none;
  126. vertical-align: bottom;
  127. &:focus {
  128. outline: none;
  129. &::-webkit-slider-thumb { box-shadow: $form-range-thumb-focus-box-shadow; }
  130. &::-moz-range-thumb { box-shadow: $form-range-thumb-focus-box-shadow; }
  131. &::-ms-thumb { box-shadow: $form-range-thumb-focus-box-shadow; }
  132. }
  133. &::-moz-focus-outer {
  134. border: 0;
  135. }
  136. &::-webkit-slider-thumb {
  137. width: $form-range-thumb-width;
  138. height: $form-range-thumb-height;
  139. margin-top: ($form-range-track-height - $form-range-thumb-height) * .5;
  140. background: $form-range-thumb-bg;
  141. border: $form-range-thumb-border;
  142. border-radius: $form-range-thumb-border-radius;
  143. box-shadow: $form-range-thumb-box-shadow;
  144. transition: $form-range-thumb-transition;
  145. appearance: none;
  146. &:active {
  147. background: $form-range-thumb-active-bg;
  148. }
  149. }
  150. &::-webkit-slider-runnable-track {
  151. width: $form-range-track-width;
  152. height: $form-range-track-height;
  153. color: transparent;
  154. cursor: $form-range-track-cursor;
  155. background-color: $form-range-track-bg;
  156. border-color: transparent;
  157. border-radius: $form-range-track-border-radius;
  158. box-shadow: $form-range-track-box-shadow;
  159. }
  160. &::-moz-range-thumb {
  161. width: $form-range-thumb-width;
  162. height: $form-range-thumb-height;
  163. background: $form-range-thumb-bg;
  164. border: $form-range-thumb-border;
  165. border-radius: $form-range-thumb-border-radius;
  166. box-shadow: $form-range-thumb-box-shadow;
  167. transition: $form-range-thumb-transition;
  168. cursor: $form-range-track-cursor;
  169. appearance: none;
  170. &:active {
  171. background: $form-range-thumb-active-bg;
  172. }
  173. }
  174. &::-moz-range-progress {
  175. background-color: $form-range-thumb-bg;
  176. }
  177. &::-moz-range-track {
  178. width: $form-range-track-width;
  179. height: $form-range-track-height;
  180. color: transparent;
  181. cursor: $form-range-track-cursor;
  182. background-color: $form-range-track-bg;
  183. border-color: transparent;
  184. border-radius: $form-range-track-border-radius;
  185. box-shadow: $form-range-track-box-shadow;
  186. }
  187. &::-ms-thumb {
  188. width: $form-range-thumb-width;
  189. height: $form-range-thumb-height;
  190. margin-top: 0;
  191. margin-right: $form-range-thumb-focus-box-shadow-width;
  192. margin-left: $form-range-thumb-focus-box-shadow-width;
  193. background: $form-range-thumb-bg;
  194. border: $form-range-thumb-border;
  195. border-radius: $form-range-thumb-border-radius;
  196. box-shadow: $form-range-thumb-box-shadow;
  197. transition: $form-range-thumb-transition;
  198. appearance: none;
  199. &:active {
  200. background: $form-range-thumb-active-bg;
  201. }
  202. }
  203. &::-ms-track {
  204. width: $form-range-track-width;
  205. height: $form-range-track-height;
  206. color: transparent;
  207. cursor: $form-range-track-cursor;
  208. background-color: transparent;
  209. border-color: transparent;
  210. border-width: $form-range-thumb-height * .5;
  211. box-shadow: $form-range-track-box-shadow;
  212. }
  213. &::-ms-fill-lower {
  214. background-color: $form-range-track-bg;
  215. border-radius: $form-range-track-border-radius;
  216. }
  217. &::-ms-fill-upper {
  218. margin-right: 15px;
  219. background-color: $form-range-track-bg;
  220. border-radius: $form-range-track-border-radius;
  221. }
  222. &:disabled {
  223. pointer-events: none;
  224. &::-webkit-slider-thumb {
  225. background-color: $form-range-thumb-disabled-bg;
  226. }
  227. &::-moz-range-thumb {
  228. background-color: $form-range-thumb-disabled-bg;
  229. }
  230. &::-ms-thumb {
  231. background-color: $form-range-thumb-disabled-bg;
  232. }
  233. }
  234. }
  235. .form-value {
  236. text-align: center;
  237. font-weight: $font-weight-bold;
  238. width: 3rem;
  239. }
  240. .form-color {
  241. display: inline-block;
  242. width: 1.75rem;
  243. height: 1.75rem;
  244. border-radius: $border-radius;
  245. }
  246. .form-selector {
  247. position: relative;
  248. select {
  249. position: absolute;
  250. top: 0;
  251. left: 0;
  252. right: 0;
  253. bottom: 0;
  254. width: 100%;
  255. display: block;
  256. background: transparent;
  257. }
  258. }
  259. .input-color {
  260. display: inline-block;
  261. width: 1.25rem;
  262. height: 1.25rem;
  263. border-radius: $border-radius;
  264. background: $color-muted;
  265. border: 1px solid $color-border;
  266. cursor: pointer;
  267. &.checked {
  268. background-image: url-svg('<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="3" stroke="#fff" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12l5 5l10 -10"></path></svg>');
  269. background-size: 1rem 1rem;
  270. background-position: center;
  271. }
  272. }
  273. .input-icon {
  274. display: inline-flex;
  275. align-items: center;
  276. justify-content: center;
  277. width: 2rem;
  278. height: 2rem;
  279. border-radius: $border-radius;
  280. background: $color-white;
  281. color: $color-text;
  282. border: 1px solid $color-border;
  283. cursor: pointer;
  284. .icon {
  285. width: 1.25rem;
  286. height: 1.25rem;
  287. }
  288. &:hover {
  289. border-color: $color-border-hover;
  290. color: $color-text;
  291. }
  292. &.checked {
  293. border-color: $color-primary;
  294. }
  295. }
  296. /* Switch */
  297. .form-switch {
  298. position: relative;
  299. display: inline-block;
  300. height: 1.5rem;
  301. width: 2.75rem;
  302. }
  303. .form-switch input {
  304. opacity: 0;
  305. width: 0;
  306. height: 0;
  307. }
  308. .slider {
  309. position: absolute;
  310. cursor: pointer;
  311. top: 0;
  312. left: 0;
  313. right: 0;
  314. bottom: 0;
  315. background-color: #ccc;
  316. -webkit-transition: .4s;
  317. transition: .4s;
  318. border-radius: 34px;
  319. }
  320. .slider:before {
  321. position: absolute;
  322. content: "";
  323. height: 1rem;
  324. width: 1rem;
  325. left: 4px;
  326. bottom: 4px;
  327. background-color: white;
  328. -webkit-transition: .4s;
  329. transition: .4s;
  330. border-radius: 50%;
  331. }
  332. input:checked + .slider {
  333. background-color: $color-primary;
  334. }
  335. input:focus + .slider {
  336. box-shadow: 0 0 1px $color-primary;
  337. }
  338. input:checked + .slider:before {
  339. -webkit-transform: translateX(1rem);
  340. -ms-transform: translateX(1rem);
  341. transform: translateX(1rem);
  342. }