input.scss 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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(#{getCssVarName('input-height')},
  180. #{map.get($input-height, 'default')}) - $border-width * 2
  181. )
  182. );
  183. width: 100%;
  184. flex-grow: 1;
  185. -webkit-appearance: none;
  186. color: var(
  187. #{getCssVarName('input-text-color')},
  188. map.get($input, 'text-color')
  189. );
  190. font-size: inherit;
  191. height: getCssVar('input-inner-height');
  192. line-height: getCssVar('input-inner-height');
  193. padding: 0;
  194. outline: none;
  195. border: none;
  196. background: none;
  197. box-sizing: border-box;
  198. &:focus {
  199. outline: none;
  200. }
  201. &::placeholder {
  202. color: getCssVarWithDefault(
  203. 'input-placeholder-color',
  204. map.get($input, 'placeholder-color')
  205. );
  206. }
  207. // override edge default style
  208. &[type='password']::-ms-reveal {
  209. display: none;
  210. }
  211. &[type='number'] {
  212. line-height: 1;
  213. }
  214. }
  215. @each $slot in (prefix, suffix) {
  216. @include e($slot) {
  217. display: inline-flex;
  218. white-space: nowrap;
  219. flex-shrink: 0;
  220. flex-wrap: nowrap;
  221. height: 100%;
  222. text-align: center;
  223. color: var(
  224. #{getCssVarName('input-icon-color')},
  225. map.get($input, 'icon-color')
  226. );
  227. transition: all getCssVar('transition-duration');
  228. pointer-events: none;
  229. }
  230. @include e(#{$slot}-inner) {
  231. pointer-events: all;
  232. display: inline-flex;
  233. align-items: center;
  234. justify-content: center;
  235. @if $slot == prefix {
  236. > :last-child {
  237. margin-right: 8px;
  238. }
  239. > :first-child {
  240. &,
  241. &.#{$namespace}-input__icon {
  242. margin-left: 0;
  243. }
  244. }
  245. } @else {
  246. > :first-child {
  247. margin-left: 8px;
  248. }
  249. }
  250. }
  251. }
  252. & .#{$namespace}-input__icon {
  253. height: inherit;
  254. line-height: inherit;
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. transition: all getCssVar('transition-duration');
  259. margin-left: 8px;
  260. }
  261. @include e(validateIcon) {
  262. pointer-events: none;
  263. }
  264. @include when(active) {
  265. .#{$namespace}-input__wrapper {
  266. @include mixed-input-border(
  267. var(
  268. #{getCssVarName('input-focus-color')},
  269. map.get($input, 'focus-color')
  270. )
  271. );
  272. }
  273. }
  274. @include when(disabled) {
  275. cursor: not-allowed;
  276. .#{$namespace}-input__wrapper {
  277. background-color: map.get($input-disabled, 'fill');
  278. @include mixed-input-border(map.get($input-disabled, 'border'));
  279. }
  280. .#{$namespace}-input__inner {
  281. color: map.get($input-disabled, 'text-color');
  282. -webkit-text-fill-color: map.get($input-disabled, 'text-color');
  283. cursor: not-allowed;
  284. &::placeholder {
  285. color: map.get($input-disabled, 'placeholder-color');
  286. }
  287. }
  288. .#{$namespace}-input__icon {
  289. cursor: not-allowed;
  290. }
  291. }
  292. @include when(exceed) {
  293. .#{$namespace}-input__wrapper {
  294. @include mixed-input-border(#{getCssVar('color-danger')});
  295. }
  296. .#{$namespace}-input__suffix {
  297. .#{$namespace}-input__count {
  298. color: getCssVar('color-danger');
  299. }
  300. }
  301. }
  302. @each $size in (large, small) {
  303. @include m($size) {
  304. @include css-var-from-global('input-height', ('component-size', $size));
  305. font-size: map.get($input-font-size, $size);
  306. @include e(wrapper) {
  307. padding: $border-width map.get($input-padding-horizontal, $size)-$border-width;
  308. }
  309. @include e(inner) {
  310. @include set-css-var-value(
  311. 'input-inner-height',
  312. calc(
  313. var(#{getCssVarName('input-height')},
  314. #{map.get($input-height, $size)}) - $border-width * 2
  315. )
  316. );
  317. }
  318. }
  319. }
  320. }
  321. @include b(input-group) {
  322. display: inline-flex;
  323. width: 100%;
  324. align-items: stretch;
  325. @include e((append, prepend)) {
  326. background-color: getCssVar('fill-color', 'light');
  327. color: getCssVar('color-info');
  328. position: relative;
  329. display: inline-flex;
  330. align-items: center;
  331. justify-content: center;
  332. min-height: 100%;
  333. border-radius: getCssVar('input-border-radius');
  334. padding: 0 20px;
  335. white-space: nowrap;
  336. &:focus {
  337. outline: none;
  338. }
  339. .#{$namespace}-select,
  340. .#{$namespace}-button {
  341. display: inline-block;
  342. margin: 0 -20px;
  343. }
  344. button.#{$namespace}-button,
  345. button.#{$namespace}-button:hover,
  346. div.#{$namespace}-select .#{$namespace}-select__wrapper,
  347. div.#{$namespace}-select:hover .#{$namespace}-select__wrapper {
  348. border-color: transparent;
  349. background-color: transparent;
  350. color: inherit;
  351. }
  352. .#{$namespace}-button,
  353. .#{$namespace}-input {
  354. font-size: inherit;
  355. }
  356. }
  357. @include e(prepend) {
  358. border-right: 0;
  359. border-top-right-radius: 0;
  360. border-bottom-right-radius: 0;
  361. @include inset-prepend-border(#{getCssVar('input-border-color')});
  362. }
  363. @include e(append) {
  364. border-left: 0;
  365. border-top-left-radius: 0;
  366. border-bottom-left-radius: 0;
  367. @include inset-append-border(#{getCssVar('input-border-color')});
  368. }
  369. @include m(prepend) {
  370. > .#{$namespace}-input__wrapper {
  371. border-top-left-radius: 0;
  372. border-bottom-left-radius: 0;
  373. }
  374. @include e(prepend) {
  375. .#{$namespace}-select {
  376. .#{$namespace}-select__wrapper {
  377. border-top-right-radius: 0;
  378. border-bottom-right-radius: 0;
  379. @include inset-prepend-border(#{getCssVar('input-border-color')});
  380. }
  381. }
  382. }
  383. }
  384. @include m(append) {
  385. > .#{$namespace}-input__wrapper {
  386. border-top-right-radius: 0;
  387. border-bottom-right-radius: 0;
  388. }
  389. @include e(append) {
  390. .#{$namespace}-select {
  391. .#{$namespace}-select__wrapper {
  392. border-top-left-radius: 0;
  393. border-bottom-left-radius: 0;
  394. @include inset-append-border(#{getCssVar('input-border-color')});
  395. }
  396. }
  397. }
  398. }
  399. }