input.scss 12 KB

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