input.scss 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. @use 'sass:map';
  2. @use 'mixins/mixins' as *;
  3. @use 'mixins/var' as *;
  4. @use 'common/var' as *;
  5. @mixin inset-prepend-border($color) {
  6. box-shadow: 1px 0 0 0 $color inset, 0 1px 0 0 $color inset,
  7. 0 -1px 0 0 $color inset;
  8. }
  9. @mixin inset-append-border($color) {
  10. box-shadow: 0 1px 0 0 $color inset, 0 -1px 0 0 $color inset,
  11. -1px 0 0 0 $color inset;
  12. }
  13. @mixin inset-prepend-input-border($color) {
  14. box-shadow: 1px 0 0 0 $color inset, 1px 0 0 0 $color, 0 1px 0 0 $color inset,
  15. 0 -1px 0 0 $color inset !important;
  16. }
  17. @mixin inset-append-input-border($color) {
  18. box-shadow: -1px 0 0 0 $color, -1px 0 0 0 $color inset, 0 1px 0 0 $color inset,
  19. 0 -1px 0 0 $color inset !important;
  20. }
  21. @mixin mixed-input-border($color) {
  22. box-shadow: 0 0 0 1px $color inset;
  23. }
  24. @include b(textarea) {
  25. @include set-component-css-var('input', $input);
  26. }
  27. @include b(textarea) {
  28. position: relative;
  29. display: inline-block;
  30. width: 100%;
  31. vertical-align: bottom;
  32. font-size: getCssVar('font-size', 'base');
  33. @include e(inner) {
  34. position: relative;
  35. display: block;
  36. resize: vertical;
  37. padding: 5px map.get($input-padding-horizontal, 'default')-$border-width;
  38. line-height: 1.5;
  39. box-sizing: border-box;
  40. width: 100%;
  41. font-size: inherit;
  42. font-family: inherit;
  43. color: var(
  44. #{getCssVarName('input-text-color')},
  45. map.get($input, 'text-color')
  46. );
  47. background-color: var(
  48. #{getCssVarName('input-bg-color')},
  49. map.get($input, 'bg-color')
  50. );
  51. background-image: none;
  52. -webkit-appearance: none;
  53. @include inset-input-border(
  54. var(
  55. #{getCssVarName('input-border-color')},
  56. map.get($input, 'border-color')
  57. )
  58. );
  59. border-radius: getCssVarWithDefault(
  60. 'input-border-radius',
  61. map.get($input, 'border-radius')
  62. );
  63. transition: getCssVar('transition-box-shadow');
  64. border: none;
  65. &::placeholder {
  66. color: getCssVarWithDefault(
  67. 'input-placeholder-color',
  68. map.get($input, 'placeholder-color')
  69. );
  70. }
  71. &:hover {
  72. @include inset-input-border(#{getCssVar('input', 'hover-border-color')});
  73. }
  74. &:focus {
  75. outline: none;
  76. @include inset-input-border(#{getCssVar('input', 'focus-border-color')});
  77. }
  78. }
  79. & .#{$namespace}-input__count {
  80. color: getCssVar('color-info');
  81. background: getCssVar('fill-color', 'blank');
  82. position: absolute;
  83. font-size: 12px;
  84. line-height: 14px;
  85. bottom: 5px;
  86. right: 10px;
  87. }
  88. @include when(disabled) {
  89. .#{$namespace}-textarea__inner {
  90. @include inset-input-border(#{getCssVar('disabled-border-color')});
  91. background-color: map.get($input-disabled, 'fill');
  92. color: map.get($input-disabled, 'text-color');
  93. cursor: not-allowed;
  94. &::placeholder {
  95. color: map.get($input-disabled, 'placeholder-color');
  96. }
  97. }
  98. }
  99. @include when(exceed) {
  100. .#{$namespace}-textarea__inner {
  101. @include mixed-input-border(#{getCssVar('color-danger')});
  102. }
  103. .#{$namespace}-input__count {
  104. color: getCssVar('color-danger');
  105. }
  106. }
  107. }
  108. @include b(input) {
  109. @include set-component-css-var('input', $input);
  110. }
  111. @include b(input) {
  112. @include css-var-from-global('input-height', 'component-size');
  113. position: relative;
  114. font-size: getCssVar('font-size', 'base');
  115. display: inline-flex;
  116. width: getCssVar('input-width');
  117. line-height: getCssVar('input-height');
  118. box-sizing: border-box;
  119. vertical-align: middle;
  120. @include scroll-bar;
  121. & .#{$namespace}-input__clear,
  122. & .#{$namespace}-input__password {
  123. color: getCssVar('input-icon-color');
  124. font-size: map.get($input-font-size, 'default');
  125. cursor: pointer;
  126. &:hover {
  127. color: getCssVar('input-clear-hover-color');
  128. }
  129. }
  130. & .#{$namespace}-input__count {
  131. height: 100%;
  132. display: inline-flex;
  133. align-items: center;
  134. color: getCssVar('color-info');
  135. font-size: 12px;
  136. .#{$namespace}-input__count-inner {
  137. background: getCssVar('fill-color', 'blank');
  138. line-height: initial;
  139. display: inline-block;
  140. padding-left: 8px;
  141. }
  142. }
  143. @include e(wrapper) {
  144. display: inline-flex;
  145. flex-grow: 1;
  146. align-items: center;
  147. justify-content: center;
  148. padding: $border-width map.get($input-padding-horizontal, 'default')-$border-width;
  149. background-color: var(
  150. #{getCssVarName('input-bg-color')},
  151. map.get($input, 'bg-color')
  152. );
  153. background-image: none;
  154. border-radius: getCssVarWithDefault(
  155. 'input-border-radius',
  156. map.get($input, 'border-radius')
  157. );
  158. cursor: text;
  159. transition: getCssVar('transition-box-shadow');
  160. transform: translate3d(0, 0, 0);
  161. @include inset-input-border(
  162. var(
  163. #{getCssVarName('input-border-color')},
  164. map.get($input, 'border-color')
  165. )
  166. );
  167. &:hover {
  168. @include inset-input-border(#{getCssVar('input', 'hover-border-color')});
  169. }
  170. @include when(focus) {
  171. @include inset-input-border(#{getCssVar('input', 'focus-border-color')});
  172. }
  173. }
  174. @include e(inner) {
  175. // use map.get as default value for date picker range
  176. @include set-css-var-value(
  177. 'input-inner-height',
  178. calc(
  179. var(
  180. #{getCssVarName('input-height')},
  181. #{map.get($input-height, 'default')}
  182. ) - $border-width * 2
  183. )
  184. );
  185. width: 100%;
  186. flex-grow: 1;
  187. -webkit-appearance: none;
  188. color: var(
  189. #{getCssVarName('input-text-color')},
  190. map.get($input, 'text-color')
  191. );
  192. font-size: inherit;
  193. height: getCssVar('input-inner-height');
  194. line-height: getCssVar('input-inner-height');
  195. padding: 0;
  196. outline: none;
  197. border: none;
  198. background: none;
  199. box-sizing: border-box;
  200. &:focus {
  201. outline: none;
  202. }
  203. &::placeholder {
  204. color: getCssVarWithDefault(
  205. 'input-placeholder-color',
  206. map.get($input, 'placeholder-color')
  207. );
  208. }
  209. // override edge default style
  210. &[type='password']::-ms-reveal {
  211. display: none;
  212. }
  213. &[type='number'] {
  214. line-height: 1;
  215. }
  216. }
  217. @each $slot in (prefix, suffix) {
  218. @include e($slot) {
  219. display: inline-flex;
  220. white-space: nowrap;
  221. flex-shrink: 0;
  222. flex-wrap: nowrap;
  223. height: 100%;
  224. text-align: center;
  225. color: var(
  226. #{getCssVarName('input-icon-color')},
  227. map.get($input, 'icon-color')
  228. );
  229. transition: all getCssVar('transition-duration');
  230. pointer-events: none;
  231. }
  232. @include e(#{$slot}-inner) {
  233. pointer-events: all;
  234. display: inline-flex;
  235. align-items: center;
  236. justify-content: center;
  237. @if $slot == prefix {
  238. > :last-child {
  239. margin-right: 8px;
  240. }
  241. > :first-child {
  242. &,
  243. &.#{$namespace}-input__icon {
  244. margin-left: 0;
  245. }
  246. }
  247. } @else {
  248. > :first-child {
  249. margin-left: 8px;
  250. }
  251. }
  252. }
  253. }
  254. & .#{$namespace}-input__icon {
  255. height: inherit;
  256. line-height: inherit;
  257. display: flex;
  258. justify-content: center;
  259. align-items: center;
  260. transition: all getCssVar('transition-duration');
  261. margin-left: 8px;
  262. }
  263. @include e(validateIcon) {
  264. pointer-events: none;
  265. }
  266. @include when(active) {
  267. .#{$namespace}-input__wrapper {
  268. @include mixed-input-border(
  269. var(
  270. #{getCssVarName('input-focus-color')},
  271. map.get($input, 'focus-color')
  272. )
  273. );
  274. }
  275. }
  276. @include when(disabled) {
  277. cursor: not-allowed;
  278. .#{$namespace}-input__wrapper {
  279. background-color: map.get($input-disabled, 'fill');
  280. @include mixed-input-border(map.get($input-disabled, 'border'));
  281. }
  282. .#{$namespace}-input__inner {
  283. color: map.get($input-disabled, 'text-color');
  284. -webkit-text-fill-color: map.get($input-disabled, 'text-color');
  285. cursor: not-allowed;
  286. &::placeholder {
  287. color: map.get($input-disabled, 'placeholder-color');
  288. }
  289. }
  290. .#{$namespace}-input__icon {
  291. cursor: not-allowed;
  292. }
  293. }
  294. @include when(exceed) {
  295. .#{$namespace}-input__wrapper {
  296. @include mixed-input-border(#{getCssVar('color-danger')});
  297. }
  298. .#{$namespace}-input__suffix {
  299. .#{$namespace}-input__count {
  300. color: getCssVar('color-danger');
  301. }
  302. }
  303. }
  304. @each $size in (large, small) {
  305. @include m($size) {
  306. @include css-var-from-global('input-height', ('component-size', $size));
  307. font-size: map.get($input-font-size, $size);
  308. @include e(wrapper) {
  309. padding: $border-width map.get($input-padding-horizontal, $size)-$border-width;
  310. }
  311. @include e(inner) {
  312. @include set-css-var-value(
  313. 'input-inner-height',
  314. calc(
  315. var(
  316. #{getCssVarName('input-height')},
  317. #{map.get($input-height, $size)}
  318. ) - $border-width * 2
  319. )
  320. );
  321. }
  322. }
  323. }
  324. }
  325. @include b(input-group) {
  326. display: inline-flex;
  327. width: 100%;
  328. align-items: stretch;
  329. @include e((append, prepend)) {
  330. background-color: getCssVar('fill-color', 'light');
  331. color: getCssVar('color-info');
  332. position: relative;
  333. display: inline-flex;
  334. align-items: center;
  335. justify-content: center;
  336. min-height: 100%;
  337. border-radius: getCssVar('input-border-radius');
  338. padding: 0 20px;
  339. white-space: nowrap;
  340. &:focus {
  341. outline: none;
  342. }
  343. .#{$namespace}-select,
  344. .#{$namespace}-button {
  345. display: inline-block;
  346. margin: 0 -20px;
  347. }
  348. button.#{$namespace}-button,
  349. button.#{$namespace}-button:hover,
  350. div.#{$namespace}-select .#{$namespace}-select__wrapper,
  351. div.#{$namespace}-select:hover .#{$namespace}-select__wrapper {
  352. border-color: transparent;
  353. background-color: transparent;
  354. color: inherit;
  355. }
  356. .#{$namespace}-button,
  357. .#{$namespace}-input {
  358. font-size: inherit;
  359. }
  360. }
  361. @include e(prepend) {
  362. border-right: 0;
  363. border-top-right-radius: 0;
  364. border-bottom-right-radius: 0;
  365. @include inset-prepend-border(#{getCssVar('input-border-color')});
  366. }
  367. @include e(append) {
  368. border-left: 0;
  369. border-top-left-radius: 0;
  370. border-bottom-left-radius: 0;
  371. @include inset-append-border(#{getCssVar('input-border-color')});
  372. }
  373. @include m(prepend) {
  374. > .#{$namespace}-input__wrapper {
  375. border-top-left-radius: 0;
  376. border-bottom-left-radius: 0;
  377. }
  378. @include e(prepend) {
  379. .#{$namespace}-select {
  380. .#{$namespace}-select__wrapper {
  381. border-top-right-radius: 0;
  382. border-bottom-right-radius: 0;
  383. @include inset-prepend-border(#{getCssVar('input-border-color')});
  384. }
  385. }
  386. }
  387. }
  388. @include m(append) {
  389. > .#{$namespace}-input__wrapper {
  390. border-top-right-radius: 0;
  391. border-bottom-right-radius: 0;
  392. }
  393. @include e(append) {
  394. .#{$namespace}-select {
  395. .#{$namespace}-select__wrapper {
  396. border-top-left-radius: 0;
  397. border-bottom-left-radius: 0;
  398. @include inset-append-border(#{getCssVar('input-border-color')});
  399. }
  400. }
  401. }
  402. }
  403. }
  404. @include b(input-hidden) {
  405. display: none !important;
  406. }