input.scss 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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: 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. }
  214. @each $slot in (prefix, suffix) {
  215. @include e($slot) {
  216. display: inline-flex;
  217. white-space: nowrap;
  218. flex-shrink: 0;
  219. flex-wrap: nowrap;
  220. height: 100%;
  221. text-align: center;
  222. color: var(
  223. #{getCssVarName('input-icon-color')},
  224. map.get($input, 'icon-color')
  225. );
  226. transition: all getCssVar('transition-duration');
  227. pointer-events: none;
  228. }
  229. @include e(#{$slot}-inner) {
  230. pointer-events: all;
  231. display: inline-flex;
  232. align-items: center;
  233. justify-content: center;
  234. @if $slot == prefix {
  235. > :last-child {
  236. margin-right: 8px;
  237. }
  238. > :first-child {
  239. &,
  240. &.#{$namespace}-input__icon {
  241. margin-left: 0;
  242. }
  243. }
  244. } @else {
  245. > :first-child {
  246. margin-left: 8px;
  247. }
  248. }
  249. }
  250. }
  251. & .#{$namespace}-input__icon {
  252. height: inherit;
  253. line-height: inherit;
  254. display: flex;
  255. justify-content: center;
  256. align-items: center;
  257. transition: all getCssVar('transition-duration');
  258. margin-left: 8px;
  259. }
  260. @include e(validateIcon) {
  261. pointer-events: none;
  262. }
  263. @include when(active) {
  264. .#{$namespace}-input__wrapper {
  265. @include mixed-input-border(
  266. var(
  267. #{getCssVarName('input-focus-color')},
  268. map.get($input, 'focus-color')
  269. )
  270. );
  271. }
  272. }
  273. @include when(disabled) {
  274. cursor: not-allowed;
  275. .#{$namespace}-input__wrapper {
  276. background-color: map.get($input-disabled, 'fill');
  277. @include mixed-input-border(map.get($input-disabled, 'border'));
  278. }
  279. .#{$namespace}-input__inner {
  280. color: map.get($input-disabled, 'text-color');
  281. -webkit-text-fill-color: map.get($input-disabled, 'text-color');
  282. cursor: not-allowed;
  283. &::placeholder {
  284. color: map.get($input-disabled, 'placeholder-color');
  285. }
  286. }
  287. .#{$namespace}-input__icon {
  288. cursor: not-allowed;
  289. }
  290. }
  291. @include when(exceed) {
  292. .#{$namespace}-input__wrapper {
  293. @include mixed-input-border(#{getCssVar('color-danger')});
  294. }
  295. .#{$namespace}-input__suffix {
  296. .#{$namespace}-input__count {
  297. color: getCssVar('color-danger');
  298. }
  299. }
  300. }
  301. @each $size in (large, small) {
  302. @include m($size) {
  303. @include css-var-from-global('input-height', ('component-size', $size));
  304. font-size: map.get($input-font-size, $size);
  305. @include e(wrapper) {
  306. padding: $border-width map.get($input-padding-horizontal, $size)-$border-width;
  307. }
  308. @include e(inner) {
  309. @include set-css-var-value(
  310. 'input-inner-height',
  311. calc(
  312. var(
  313. #{getCssVarName('input-height')},
  314. #{map.get($input-height, $size)}
  315. ) - $border-width * 2
  316. )
  317. );
  318. }
  319. }
  320. }
  321. }
  322. @include b(input-group) {
  323. display: inline-flex;
  324. width: 100%;
  325. align-items: stretch;
  326. @include e((append, prepend)) {
  327. background-color: getCssVar('fill-color', 'light');
  328. color: getCssVar('color-info');
  329. position: relative;
  330. display: inline-flex;
  331. align-items: center;
  332. justify-content: center;
  333. min-height: 100%;
  334. border-radius: getCssVar('input-border-radius');
  335. padding: 0 20px;
  336. white-space: nowrap;
  337. &:focus {
  338. outline: none;
  339. }
  340. .#{$namespace}-select,
  341. .#{$namespace}-button {
  342. display: inline-block;
  343. margin: 0 -20px;
  344. }
  345. button.#{$namespace}-button,
  346. button.#{$namespace}-button:hover,
  347. div.#{$namespace}-select .#{$namespace}-input__wrapper,
  348. div.#{$namespace}-select:hover .#{$namespace}-input__wrapper {
  349. border-color: transparent;
  350. background-color: transparent;
  351. color: inherit;
  352. }
  353. .#{$namespace}-button,
  354. .#{$namespace}-input {
  355. font-size: inherit;
  356. }
  357. }
  358. @include e(prepend) {
  359. border-right: 0;
  360. border-top-right-radius: 0;
  361. border-bottom-right-radius: 0;
  362. @include inset-prepend-border(#{getCssVar('input-border-color')});
  363. }
  364. @include e(append) {
  365. border-left: 0;
  366. border-top-left-radius: 0;
  367. border-bottom-left-radius: 0;
  368. @include inset-append-border(#{getCssVar('input-border-color')});
  369. }
  370. @include m(prepend) {
  371. > .#{$namespace}-input__wrapper {
  372. border-top-left-radius: 0;
  373. border-bottom-left-radius: 0;
  374. }
  375. @include e(prepend) {
  376. .#{$namespace}-select {
  377. .#{$namespace}-input {
  378. .#{$namespace}-input__inner {
  379. box-shadow: none !important;
  380. }
  381. .#{$namespace}-input__wrapper {
  382. border-top-right-radius: 0;
  383. border-bottom-right-radius: 0;
  384. @include inset-prepend-border(#{getCssVar('input-border-color')});
  385. }
  386. &.is-focus {
  387. .#{$namespace}-input__inner {
  388. box-shadow: none !important;
  389. }
  390. .#{$namespace}-input__wrapper {
  391. @include inset-prepend-input-border(
  392. getCssVar('input-focus-border-color')
  393. );
  394. z-index: 2;
  395. &:focus {
  396. outline: none;
  397. z-index: 2;
  398. @include inset-prepend-input-border(
  399. getCssVar('input-focus-border-color')
  400. );
  401. }
  402. }
  403. }
  404. }
  405. &:hover {
  406. .#{$namespace}-input__inner {
  407. box-shadow: none !important;
  408. }
  409. .#{$namespace}-input__wrapper {
  410. z-index: 1;
  411. @include inset-prepend-input-border(
  412. getCssVar('input-hover-border-color')
  413. );
  414. }
  415. }
  416. }
  417. }
  418. }
  419. @include m(append) {
  420. > .#{$namespace}-input__wrapper {
  421. border-top-right-radius: 0;
  422. border-bottom-right-radius: 0;
  423. }
  424. @include e(append) {
  425. .#{$namespace}-select {
  426. .#{$namespace}-input {
  427. .#{$namespace}-input__inner {
  428. box-shadow: none !important;
  429. }
  430. .#{$namespace}-input__wrapper {
  431. border-top-left-radius: 0;
  432. border-bottom-left-radius: 0;
  433. @include inset-append-border(#{getCssVar('input-border-color')});
  434. }
  435. &.is-focus {
  436. .#{$namespace}-input__inner {
  437. box-shadow: none !important;
  438. }
  439. .#{$namespace}-input__wrapper {
  440. z-index: 2;
  441. @include inset-append-input-border(
  442. getCssVar('input-focus-border-color')
  443. );
  444. }
  445. }
  446. }
  447. &:hover {
  448. .#{$namespace}-input__inner {
  449. box-shadow: none !important;
  450. }
  451. .#{$namespace}-input__wrapper {
  452. z-index: 1;
  453. @include inset-append-input-border(
  454. getCssVar('input-hover-border-color')
  455. );
  456. }
  457. }
  458. }
  459. }
  460. }
  461. }