input.scss 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. background-color: map.get($input-disabled, 'fill');
  91. border-color: map.get($input-disabled, 'border');
  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: 100%;
  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. transition: getCssVar('transition-box-shadow');
  159. transform: translate3d(0, 0, 0);
  160. @include inset-input-border(
  161. var(
  162. #{getCssVarName('input-border-color')},
  163. map.get($input, 'border-color')
  164. )
  165. );
  166. &:hover {
  167. @include inset-input-border(#{getCssVar('input', 'hover-border-color')});
  168. }
  169. @include when(focus) {
  170. @include inset-input-border(#{getCssVar('input', 'focus-border-color')});
  171. }
  172. }
  173. @include e(inner) {
  174. // use map.get as default value for date picker range
  175. @include set-css-var-value(
  176. 'input-inner-height',
  177. calc(
  178. var(
  179. #{getCssVarName('input-height')},
  180. #{map.get($input-height, 'default')}
  181. ) - $border-width * 2
  182. )
  183. );
  184. width: 100%;
  185. flex-grow: 1;
  186. -webkit-appearance: none;
  187. color: var(
  188. #{getCssVarName('input-text-color')},
  189. map.get($input, 'text-color')
  190. );
  191. font-size: inherit;
  192. height: getCssVar('input-inner-height');
  193. line-height: getCssVar('input-inner-height');
  194. padding: 0;
  195. outline: none;
  196. border: none;
  197. background: none;
  198. box-sizing: border-box;
  199. &:focus {
  200. outline: none;
  201. }
  202. &::placeholder {
  203. color: getCssVarWithDefault(
  204. 'input-placeholder-color',
  205. map.get($input, 'placeholder-color')
  206. );
  207. }
  208. // override edge default style
  209. &[type='password']::-ms-reveal {
  210. display: none;
  211. }
  212. }
  213. @each $slot in (prefix, suffix) {
  214. @include e($slot) {
  215. display: inline-flex;
  216. white-space: nowrap;
  217. flex-shrink: 0;
  218. flex-wrap: nowrap;
  219. height: 100%;
  220. text-align: center;
  221. color: var(
  222. #{getCssVarName('input-icon-color')},
  223. map.get($input, 'icon-color')
  224. );
  225. transition: all getCssVar('transition-duration');
  226. pointer-events: none;
  227. }
  228. @include e(#{$slot}-inner) {
  229. pointer-events: all;
  230. display: inline-flex;
  231. align-items: center;
  232. justify-content: center;
  233. @if $slot == prefix {
  234. > :last-child {
  235. margin-right: 8px;
  236. }
  237. > :first-child {
  238. &,
  239. &.#{$namespace}-input__icon {
  240. margin-left: 0;
  241. }
  242. }
  243. } @else {
  244. > :first-child {
  245. margin-left: 8px;
  246. }
  247. }
  248. }
  249. }
  250. & .#{$namespace}-input__icon {
  251. height: inherit;
  252. line-height: inherit;
  253. display: flex;
  254. justify-content: center;
  255. align-items: center;
  256. transition: all getCssVar('transition-duration');
  257. margin-left: 8px;
  258. }
  259. @include e(validateIcon) {
  260. pointer-events: none;
  261. }
  262. @include when(active) {
  263. .#{$namespace}-input__wrapper {
  264. @include mixed-input-border(
  265. var(
  266. #{getCssVarName('input-focus-color')},
  267. map.get($input, 'focus-color')
  268. )
  269. );
  270. }
  271. }
  272. @include when(disabled) {
  273. cursor: not-allowed;
  274. .#{$namespace}-input__wrapper {
  275. background-color: map.get($input-disabled, 'fill');
  276. @include mixed-input-border(map.get($input-disabled, 'border'));
  277. }
  278. .#{$namespace}-input__inner {
  279. color: map.get($input-disabled, 'text-color');
  280. -webkit-text-fill-color: map.get($input-disabled, 'text-color');
  281. cursor: not-allowed;
  282. &::placeholder {
  283. color: map.get($input-disabled, 'placeholder-color');
  284. }
  285. }
  286. .#{$namespace}-input__icon {
  287. cursor: not-allowed;
  288. }
  289. }
  290. @include when(exceed) {
  291. .#{$namespace}-input__wrapper {
  292. @include mixed-input-border(#{getCssVar('color-danger')});
  293. }
  294. .#{$namespace}-input__suffix {
  295. .#{$namespace}-input__count {
  296. color: getCssVar('color-danger');
  297. }
  298. }
  299. }
  300. @each $size in (large, small) {
  301. @include m($size) {
  302. @include css-var-from-global('input-height', ('component-size', $size));
  303. font-size: map.get($input-font-size, $size);
  304. @include e(wrapper) {
  305. padding: $border-width map.get($input-padding-horizontal, $size)-$border-width;
  306. }
  307. @include e(inner) {
  308. @include set-css-var-value(
  309. 'input-inner-height',
  310. calc(
  311. var(
  312. #{getCssVarName('input-height')},
  313. #{map.get($input-height, $size)}
  314. ) - $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}-input__wrapper,
  347. div.#{$namespace}-select:hover .#{$namespace}-input__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}-input {
  377. .#{$namespace}-input__inner {
  378. box-shadow: none !important;
  379. }
  380. .#{$namespace}-input__wrapper {
  381. border-top-right-radius: 0;
  382. border-bottom-right-radius: 0;
  383. @include inset-prepend-border(#{getCssVar('input-border-color')});
  384. }
  385. &.is-focus {
  386. .#{$namespace}-input__inner {
  387. box-shadow: none !important;
  388. }
  389. .#{$namespace}-input__wrapper {
  390. @include inset-prepend-input-border(
  391. getCssVar('input-focus-border-color')
  392. );
  393. z-index: 2;
  394. &:focus {
  395. outline: none;
  396. z-index: 2;
  397. @include inset-prepend-input-border(
  398. getCssVar('input-focus-border-color')
  399. );
  400. }
  401. }
  402. }
  403. }
  404. &:hover {
  405. .#{$namespace}-input__inner {
  406. box-shadow: none !important;
  407. }
  408. .#{$namespace}-input__wrapper {
  409. z-index: 1;
  410. @include inset-prepend-input-border(
  411. getCssVar('input-hover-border-color')
  412. );
  413. }
  414. }
  415. }
  416. }
  417. }
  418. @include m(append) {
  419. > .#{$namespace}-input__wrapper {
  420. border-top-right-radius: 0;
  421. border-bottom-right-radius: 0;
  422. }
  423. @include e(append) {
  424. .#{$namespace}-select {
  425. .#{$namespace}-input {
  426. .#{$namespace}-input__inner {
  427. box-shadow: none !important;
  428. }
  429. .#{$namespace}-input__wrapper {
  430. border-top-left-radius: 0;
  431. border-bottom-left-radius: 0;
  432. @include inset-append-border(#{getCssVar('input-border-color')});
  433. }
  434. &.is-focus {
  435. .#{$namespace}-input__inner {
  436. box-shadow: none !important;
  437. }
  438. .#{$namespace}-input__wrapper {
  439. z-index: 2;
  440. @include inset-append-input-border(
  441. getCssVar('input-focus-border-color')
  442. );
  443. }
  444. }
  445. }
  446. &:hover {
  447. .#{$namespace}-input__inner {
  448. box-shadow: none !important;
  449. }
  450. .#{$namespace}-input__wrapper {
  451. z-index: 1;
  452. @include inset-append-input-border(
  453. getCssVar('input-hover-border-color')
  454. );
  455. }
  456. }
  457. }
  458. }
  459. }
  460. }