You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_textfield.scss 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /**
  2. * The background color for text fields.
  3. * @group textfield
  4. */
  5. $v-textfield-background-color: if(is-dark-color($v-app-background-color), darken($v-app-background-color, 4%), lighten($v-app-background-color, 8%)) !default;
  6. /**
  7. * The background color for read-only text fields.
  8. * @group textfield
  9. */
  10. $v-textfield-background-color--readonly: darkest-color($v-app-background-color, darken($v-textfield-background-color, 2%)) !default;
  11. /**
  12. * The bevel style for text fields. See the documentation for $v-bevel.
  13. * @group textfield
  14. */
  15. $v-textfield-bevel: if($v-bevel and ($v-bevel != none), inset 0 1px 0 v-shade, $v-bevel) !default;
  16. /**
  17. * The shadow style for text fields. See the documentation for $v-shadow.
  18. * @group textfield
  19. */
  20. $v-textfield-shadow: 0 1px 0 (v-tint 2) !default;
  21. /**
  22. * The font-weight for text fields.
  23. * @group textfield
  24. */
  25. $v-textfield-font-weight: 400 !default;
  26. /**
  27. * The border style for text fields. See the documentation for $v-border.
  28. * @group textfield
  29. */
  30. $v-textfield-border: $v-border !default;
  31. /**
  32. * The border-radius for text fields. See the documentation for $v-border-radius;
  33. * @group textfield
  34. */
  35. $v-textfield-border-radius: $v-border-radius !default;
  36. /**
  37. * The opacity for disabled text fields.
  38. * @group textfield
  39. */
  40. $v-textfield-disabled-opacity: $v-disabled-opacity !default;
  41. /**
  42. * Outputs the selectors and properties for the TextField component.
  43. *
  44. * @param {string} $primary-stylename (v-textfield) - the primary style name for the selectors
  45. * @param {bool} $include-additional-styles - should the mixin output all the different style variations of the component
  46. *
  47. * @group textfield
  48. */
  49. @mixin valo-textfield ($primary-stylename: v-textfield, $include-additional-styles: contains($v-included-additional-styles, textfield)) {
  50. .#{$primary-stylename} {
  51. @include valo-textfield-style;
  52. width: $v-default-field-width;
  53. }
  54. .#{$primary-stylename}-readonly {
  55. @include valo-textfield-readonly-style;
  56. }
  57. .#{$primary-stylename}-error {
  58. @include valo-textfield-error-style;
  59. }
  60. .#{$primary-stylename}-error-info {
  61. @include valo-textfield-error-level-info-style;
  62. }
  63. .#{$primary-stylename}-error-warning {
  64. @include valo-textfield-error-level-warning-style;
  65. }
  66. .#{$primary-stylename}-error-error {
  67. @include valo-textfield-error-level-error-style;
  68. }
  69. .#{$primary-stylename}-error-critical {
  70. @include valo-textfield-error-level-critical-style;
  71. }
  72. .#{$primary-stylename}-error-system {
  73. @include valo-textfield-error-level-system-style;
  74. }
  75. @if $include-additional-styles {
  76. .#{$primary-stylename}-borderless {
  77. @include valo-textfield-borderless-style;
  78. }
  79. .#{$primary-stylename}-tiny {
  80. @include valo-textfield-style($unit-size: $v-unit-size--tiny, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
  81. font-size: $v-font-size--tiny;
  82. }
  83. .#{$primary-stylename}-compact,
  84. .#{$primary-stylename}-small {
  85. @include valo-textfield-style($unit-size: $v-unit-size--small, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
  86. }
  87. .#{$primary-stylename}-small {
  88. font-size: $v-font-size--small;
  89. }
  90. .#{$primary-stylename}-large {
  91. @include valo-textfield-style($unit-size: $v-unit-size--large, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
  92. font-size: $v-font-size--large;
  93. }
  94. .#{$primary-stylename}-huge {
  95. @include valo-textfield-style($unit-size: $v-unit-size--huge, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
  96. font-size: $v-font-size--huge;
  97. }
  98. @include valo-textfield-inline-icon($primary-stylename: $primary-stylename, $stylenames: inline-icon);
  99. @include valo-textfield-inline-icon($primary-stylename: $primary-stylename, $stylenames: inline-icon tiny, $unit-size: $v-unit-size--tiny, $font-size: $v-font-size--tiny);
  100. @include valo-textfield-inline-icon($primary-stylename: $primary-stylename, $stylenames: inline-icon compact, $unit-size: $v-unit-size--small);
  101. @include valo-textfield-inline-icon($primary-stylename: $primary-stylename, $stylenames: inline-icon small, $unit-size: $v-unit-size--small, $font-size: $v-font-size--small);
  102. @include valo-textfield-inline-icon($primary-stylename: $primary-stylename, $stylenames: inline-icon large, $unit-size: $v-unit-size--large, $font-size: $v-font-size--large);
  103. @include valo-textfield-inline-icon($primary-stylename: $primary-stylename, $stylenames: inline-icon huge, $unit-size: $v-unit-size--huge, $font-size: $v-font-size--huge);
  104. .#{$primary-stylename}-align-right {
  105. text-align: right;
  106. }
  107. .#{$primary-stylename}-align-center {
  108. text-align: center;
  109. }
  110. }
  111. }
  112. /**
  113. * Outputs the styles for a text field variant.
  114. *
  115. * @param {size} $unit-size ($v-unit-size) - The sizing of the text field, which corresponds its height
  116. * @param {size | list} $padding (null) - The padding of the text field. Computed from other parameters by default.
  117. * @param {color} $font-color (null) - The font color of the text field. Computed from the $background-color by default.
  118. * @param {number} $font-weight (max(400, $v-font-weight)) - The font weight of the text field
  119. * @param {size} $font-size (null) - The font size of the text field. Inherited from the parent by default.
  120. * @param {color} $background-color ($v-textfield-background-color) - The background color of the text field
  121. * @param {list} $border ($v-textfield-border) - The border of the text field
  122. * @param {size} $border-radius ($v-textfield-border-radius) - The border-radius of the text field
  123. * @param {list} $bevel ($v-textfield-bevel) - Box-shadow value according to $v-bevel documentation
  124. * @param {list} $shadow ($v-textfield-shadow) - Box-shadow value according to $v-shadow documentation
  125. * @param {list} $states (normal focus disabled) - The text field states for which to output corresponding styles
  126. *
  127. * @group textfield
  128. */
  129. @mixin valo-textfield-style (
  130. $unit-size : $v-unit-size,
  131. $padding : null,
  132. $font-color : null,
  133. $font-weight : max(400, $v-font-weight),
  134. $font-size : null,
  135. $background-color : $v-textfield-background-color,
  136. $border : $v-textfield-border,
  137. $border-radius : $v-textfield-border-radius,
  138. $gradient : none,
  139. $bevel : $v-textfield-bevel,
  140. $shadow : $v-textfield-shadow,
  141. $states : (normal, focus, disabled)
  142. ) {
  143. @if contains($states, normal) {
  144. @include appearance(none);
  145. @include user-select(text);
  146. margin: 0;
  147. font: inherit;
  148. font-size: $font-size;
  149. font-weight: $font-weight;
  150. line-height: normal;
  151. height: $unit-size;
  152. border-radius: $border-radius;
  153. @if type-of($padding) == number or type-of($padding) == list {
  154. padding: $padding;
  155. } @else {
  156. $padding-width: ceil($unit-size/6);
  157. @if $border-radius {
  158. $padding-width: $padding-width + ceil($border-radius/3);
  159. }
  160. $padding-height: round($unit-size/9);
  161. padding: $padding-height $padding-width;
  162. }
  163. @if $background-color and $border {
  164. border: valo-border($border, darkest-color($background-color, $v-app-background-color));
  165. }
  166. @if $gradient == none {
  167. background: $background-color;
  168. } @else if $gradient {
  169. @include valo-gradient($color: $background-color, $gradient: $gradient)
  170. }
  171. @if $background-color {
  172. color: valo-font-color($background-color);
  173. }
  174. @include box-shadow(valo-bevel-and-shadow($bevel: $bevel, $shadow: $shadow, $background-color: $background-color, $gradient: $gradient));
  175. @if $v-animations-enabled {
  176. @include transition(box-shadow 180ms, border 180ms);
  177. }
  178. }
  179. @if contains($states, disabled) {
  180. &.v-disabled {
  181. @include opacity($v-textfield-disabled-opacity);
  182. }
  183. }
  184. @if contains($states, focus) {
  185. &:focus {
  186. @include valo-textfield-focus-style($bevel: $bevel, $shadow: $shadow, $gradient: $gradient, $background-color: $background-color);
  187. }
  188. }
  189. // TODO allow parent selector to be used in interpolation
  190. &[class*="prompt"] {
  191. @include valo-textfield-prompt-style($background-color);
  192. }
  193. }
  194. /**
  195. * Outputs the styles for a text field input prompt.
  196. *
  197. * @param {color} $background-color ($v-textfield-background-color) - The background color of the text field
  198. *
  199. * @group textfield
  200. */
  201. @mixin valo-textfield-prompt-style ($background-color: $v-textfield-background-color) {
  202. @if $background-color == transparent {
  203. color: inherit;
  204. @include opacity(.5);
  205. } @else if type-of($background-color) == color {
  206. $font-color: valo-font-color($background-color);
  207. $font-color: mix($background-color, $font-color);
  208. @if is-dark-color($background-color) and saturation($background-color) > 50% {
  209. $font-color: scale-color($font-color, $lightness: 20%);
  210. }
  211. $font-color: scale-color($font-color, $saturation: saturation($font-color));
  212. color: $font-color;
  213. }
  214. }
  215. /**
  216. * Outputs the styles for a text field focus state.
  217. *
  218. * @param {list} $bevel ($v-textfield-bevel) - Box-shadow value according to $v-bevel documentation
  219. * @param {list} $shadow ($v-textfield-shadow) - Box-shadow value according to $v-shadow documentation
  220. * @param {color} $background-color ($v-textfield-background-color) - The background color of the text field
  221. * @param {list} $gradient (null) - Valo specific gradient value. See the documentation for $v-gradient.
  222. *
  223. * @group textfield
  224. */
  225. @mixin valo-textfield-focus-style ($bevel: $v-textfield-bevel, $shadow: $v-textfield-shadow, $background-color: $v-textfield-background-color, $gradient: null) {
  226. outline: none;
  227. @if $v-animations-enabled {
  228. @include transition(none);
  229. }
  230. $focus-color: $v-focus-color;
  231. @if color-luminance($focus-color) + 50 < color-luminance($v-background-color) {
  232. border-color: $focus-color;
  233. }
  234. @include box-shadow(valo-bevel-and-shadow($bevel: $bevel, $shadow: $shadow, $background-color: $background-color, $gradient: $gradient, $include-focus: true));
  235. @include valo-focus-style;
  236. }
  237. /**
  238. * Outputs the styles for a read-only text field.
  239. *
  240. * @group textfield
  241. */
  242. @mixin valo-textfield-readonly-style {
  243. background: $v-textfield-background-color--readonly;
  244. color: valo-font-color($v-textfield-background-color--readonly);
  245. @include box-shadow(none);
  246. &:focus {
  247. box-shadow: none;
  248. border-color: first-color(valo-border($v-textfield-border, $v-textfield-background-color--readonly));
  249. }
  250. }
  251. /**
  252. * Outputs the styles for a borderless style text field.
  253. *
  254. * @param {color} $background-color (transparent) - The background color of the text field
  255. *
  256. * @group textfield
  257. */
  258. @mixin valo-textfield-borderless-style ($background-color: transparent) {
  259. border: none;
  260. border-radius: 0;
  261. background: $background-color;
  262. @include box-shadow(none);
  263. $font-color: inherit;
  264. @if $background-color != transparent and type-of($background-color) == color {
  265. $font-color: valo-font-color($background-color);
  266. }
  267. color: $font-color;
  268. &:focus {
  269. @include box-shadow(none);
  270. }
  271. &[class*="prompt"] {
  272. @include valo-textfield-prompt-style($background-color);
  273. }
  274. }
  275. /**
  276. * Outputs the styles for a text field error state.
  277. *
  278. * @group textfield
  279. */
  280. @mixin valo-textfield-error-style($indicator-color: $v-error-indicator-color) {
  281. border-color: $indicator-color !important;
  282. $bg: scale-color($indicator-color, $lightness: 98%);
  283. background: $bg;
  284. color: valo-font-color($bg);
  285. }
  286. /**
  287. * Outputs the styles for a text field error state with error level 'info'.
  288. *
  289. * @group textfield
  290. */
  291. @mixin valo-textfield-error-level-info-style {
  292. @include valo-textfield-error-style($v-error-indicator-level-info-color);
  293. }
  294. /**
  295. * Outputs the styles for a text field error state with error level 'warning'.
  296. *
  297. * @group textfield
  298. */
  299. @mixin valo-textfield-error-level-warning-style {
  300. @include valo-textfield-error-style($v-error-indicator-level-warning-color);
  301. }
  302. /**
  303. * Outputs the styles for a text field error state with error level 'error'.
  304. *
  305. * @group textfield
  306. */
  307. @mixin valo-textfield-error-level-error-style {
  308. @include valo-textfield-error-style($v-error-indicator-level-error-color);
  309. }
  310. /**
  311. * Outputs the styles for a text field error state with error level 'critical'.
  312. *
  313. * @group textfield
  314. */
  315. @mixin valo-textfield-error-level-critical-style {
  316. @include valo-textfield-error-style($v-error-indicator-level-critical-color);
  317. }
  318. /**
  319. * Outputs the styles for a text field error state with error level 'system'.
  320. *
  321. * @group textfield
  322. */
  323. @mixin valo-textfield-error-level-system-style {
  324. @include valo-textfield-error-style($v-error-indicator-level-system-color);
  325. }
  326. /**
  327. * Outputs the selectors and styles for an inline-icon style for a text field. Included indipendently (i.e. not enclosed with a parent text field selector).
  328. *
  329. * @param {string} $primary-stylename (v-textfield) - The primary style name for the selectors
  330. * @param {string | list} $stylenames (inline-icon) - The additional style names which will define the inline-icon style
  331. * @param {string} $input-selector (null) - Additional selector for a nested input element which should be targeted
  332. * @param {size} $unit-size ($v-unit-size) - The unit size which the resulting style will support
  333. * @param {size} $font-size ($v-font-size) - The font size which the resulting style will support (needed for font icons)
  334. * @param {size} $image-icon-size (16px) - The image icon height which the resulting style will support (needed to center the icon vertically inside the text field)
  335. *
  336. * @group text field
  337. */
  338. @mixin valo-textfield-inline-icon($primary-stylename: v-textfield, $stylenames: inline-icon, $input-selector: null, $unit-size: $v-unit-size, $font-size: $v-font-size, $image-icon-size: 16px) {
  339. $slot-selector: "";
  340. $caption-selector: "";
  341. $text-input-selector: "";
  342. @each $style in $stylenames {
  343. $slot-selector: $slot-selector + ".v-slot-" + $style;
  344. $caption-selector: $caption-selector + ".v-caption-" + $style;
  345. $text-input-selector: $text-input-selector + "." + $primary-stylename + "-" + $style;
  346. }
  347. #{$slot-selector} {
  348. position: relative;
  349. }
  350. #{$caption-selector} {
  351. padding: 0;
  352. .v-captiontext {
  353. // Need to include to get the default padding back
  354. @include valo-caption-style;
  355. margin: 0;
  356. }
  357. .v-icon {
  358. position: absolute;
  359. z-index: 10;
  360. }
  361. // Font icons
  362. span.v-icon {
  363. $border-width: first-number($v-textfield-border);
  364. left: $border-width;
  365. bottom: $border-width;
  366. width: $unit-size;
  367. line-height: $unit-size - $border-width*2;
  368. text-align: center;
  369. font-size: $font-size;
  370. }
  371. // Image icons
  372. img.v-icon {
  373. left: round(($unit-size - $image-icon-size)/2);
  374. bottom: round(($unit-size - $image-icon-size)/2);
  375. }
  376. }
  377. #{$text-input-selector} #{$input-selector} {
  378. padding-left: $unit-size;
  379. }
  380. }