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 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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%));
  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. @if $include-additional-styles {
  61. .#{$primary-stylename}-borderless {
  62. @include valo-textfield-borderless-style;
  63. }
  64. .#{$primary-stylename}-tiny {
  65. @include valo-textfield-style($unit-size: $v-unit-size--tiny, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
  66. font-size: $v-font-size--tiny;
  67. }
  68. .#{$primary-stylename}-compact,
  69. .#{$primary-stylename}-small {
  70. @include valo-textfield-style($unit-size: $v-unit-size--small, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
  71. }
  72. .#{$primary-stylename}-small {
  73. font-size: $v-font-size--small;
  74. }
  75. .#{$primary-stylename}-large {
  76. @include valo-textfield-style($unit-size: $v-unit-size--large, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
  77. font-size: $v-font-size--large;
  78. }
  79. .#{$primary-stylename}-huge {
  80. @include valo-textfield-style($unit-size: $v-unit-size--huge, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
  81. font-size: $v-font-size--huge;
  82. }
  83. @include valo-textfield-inline-icon($stylenames: inline-icon);
  84. @include valo-textfield-inline-icon($stylenames: inline-icon tiny, $unit-size: $v-unit-size--tiny, $font-size: $v-font-size--tiny);
  85. @include valo-textfield-inline-icon($stylenames: inline-icon compact, $unit-size: $v-unit-size--small);
  86. @include valo-textfield-inline-icon($stylenames: inline-icon small, $unit-size: $v-unit-size--small, $font-size: $v-font-size--small);
  87. @include valo-textfield-inline-icon($stylenames: inline-icon large, $unit-size: $v-unit-size--large, $font-size: $v-font-size--large);
  88. @include valo-textfield-inline-icon($stylenames: inline-icon huge, $unit-size: $v-unit-size--huge, $font-size: $v-font-size--huge);
  89. .#{$primary-stylename}-align-right {
  90. text-align: right;
  91. }
  92. .#{$primary-stylename}-align-center {
  93. text-align: center;
  94. }
  95. }
  96. }
  97. /**
  98. * Outputs the styles for a text field variant.
  99. *
  100. * @param {size} $unit-size ($v-unit-size) - The sizing of the text field, which corresponds its height
  101. * @param {size | list} $padding (null) - The padding of the text field. Computed from other parameters by default.
  102. * @param {color} $font-color (null) - The font color of the text field. Computed from the $background-color by default.
  103. * @param {number} $font-weight (max(400, $v-font-weight)) - The font weight of the text field
  104. * @param {size} $font-size (null) - The font size of the text field. Inherited from the parent by default.
  105. * @param {color} $background-color ($v-textfield-background-color) - The background color of the text field
  106. * @param {list} $border ($v-textfield-border) - The border of the text field
  107. * @param {size} $border-radius ($v-textfield-border-radius) - The border-radius of the text field
  108. * @param {list} $bevel ($v-textfield-bevel) - Box-shadow value according to $v-bevel documentation
  109. * @param {list} $shadow ($v-textfield-shadow) - Box-shadow value according to $v-shadow documentation
  110. * @param {list} $states (normal focus disabled) - The text field states for which to output corresponding styles
  111. *
  112. * @group textfield
  113. */
  114. @mixin valo-textfield-style (
  115. $unit-size : $v-unit-size,
  116. $padding : null,
  117. $font-color : null,
  118. $font-weight : max(400, $v-font-weight),
  119. $font-size : null,
  120. $background-color : $v-textfield-background-color,
  121. $border : $v-textfield-border,
  122. $border-radius : $v-textfield-border-radius,
  123. $gradient : none,
  124. $bevel : $v-textfield-bevel,
  125. $shadow : $v-textfield-shadow,
  126. $states : (normal, focus, disabled)
  127. ) {
  128. @if contains($states, normal) {
  129. @include appearance(none);
  130. @include user-select(text);
  131. margin: 0;
  132. font: inherit;
  133. font-size: $font-size;
  134. font-weight: $font-weight;
  135. line-height: normal;
  136. height: $unit-size;
  137. border-radius: $border-radius;
  138. @if type-of($padding) == number or type-of($padding) == list {
  139. padding: $padding;
  140. } @else {
  141. $padding-width: ceil($unit-size/6);
  142. @if $border-radius {
  143. $padding-width: $padding-width + ceil($border-radius/3);
  144. }
  145. $padding-height: round($unit-size/9);
  146. padding: $padding-height $padding-width;
  147. }
  148. @if $background-color and $border {
  149. border: valo-border($border, darkest-color($background-color, $v-app-background-color));
  150. }
  151. @if $gradient == none {
  152. background: $background-color;
  153. } @else if $gradient {
  154. @include valo-gradient($color: $background-color, $gradient: $gradient)
  155. }
  156. @if $background-color {
  157. color: valo-font-color($background-color);
  158. }
  159. @include box-shadow(valo-bevel-and-shadow($bevel: $bevel, $shadow: $shadow, $background-color: $background-color, $gradient: $gradient));
  160. @if $v-animations-enabled {
  161. @include transition(box-shadow 180ms, border 180ms);
  162. }
  163. }
  164. @if contains($states, disabled) {
  165. &.v-disabled {
  166. @include opacity($v-textfield-disabled-opacity);
  167. }
  168. }
  169. @if contains($states, focus) {
  170. &:focus {
  171. @include valo-textfield-focus-style($bevel: $bevel, $shadow: $shadow, $gradient: $gradient, $background-color: $background-color);
  172. }
  173. }
  174. // TODO allow parent selector to be used in interpolation
  175. &[class*="prompt"],
  176. &[placeholder] {
  177. @include valo-textfield-prompt-style($background-color);
  178. }
  179. }
  180. /**
  181. * Outputs the styles for a text field input prompt.
  182. *
  183. * @param {color} $background-color ($v-textfield-background-color) - The background color of the text field
  184. *
  185. * @group textfield
  186. */
  187. @mixin valo-textfield-prompt-style ($background-color: $v-textfield-background-color) {
  188. @if $background-color == transparent {
  189. color: inherit;
  190. @include opacity(.5);
  191. } @else if type-of($background-color) == color {
  192. $font-color: valo-font-color($background-color);
  193. $font-color: mix($background-color, $font-color);
  194. @if is-dark-color($background-color) and saturation($background-color) > 50% {
  195. $font-color: scale-color($font-color, $lightness: 20%);
  196. }
  197. $font-color: scale-color($font-color, $saturation: saturation($font-color));
  198. color: $font-color;
  199. }
  200. }
  201. /**
  202. * Outputs the styles for a text field focus state.
  203. *
  204. * @param {list} $bevel ($v-textfield-bevel) - Box-shadow value according to $v-bevel documentation
  205. * @param {list} $shadow ($v-textfield-shadow) - Box-shadow value according to $v-shadow documentation
  206. * @param {color} $background-color ($v-textfield-background-color) - The background color of the text field
  207. * @param {list} $gradient (null) - Valo specific gradient value. See the documentation for $v-gradient.
  208. *
  209. * @group textfield
  210. */
  211. @mixin valo-textfield-focus-style ($bevel: $v-textfield-bevel, $shadow: $v-textfield-shadow, $background-color: $v-textfield-background-color, $gradient: null) {
  212. outline: none;
  213. @if $v-animations-enabled {
  214. @include transition(none);
  215. }
  216. $focus-color: $v-focus-color;
  217. @if color-luminance($focus-color) + 50 < color-luminance($v-background-color) {
  218. border-color: $focus-color;
  219. }
  220. @include box-shadow(valo-bevel-and-shadow($bevel: $bevel, $shadow: $shadow, $background-color: $background-color, $gradient: $gradient, $include-focus: true));
  221. @include valo-focus-style;
  222. }
  223. /**
  224. * Outputs the styles for a read-only text field.
  225. *
  226. * @group textfield
  227. */
  228. @mixin valo-textfield-readonly-style {
  229. background: $v-textfield-background-color--readonly;
  230. color: valo-font-color($v-textfield-background-color--readonly);
  231. @include box-shadow(none);
  232. &:focus {
  233. box-shadow: none;
  234. border-color: first-color(valo-border($v-textfield-border, $v-textfield-background-color--readonly));
  235. }
  236. }
  237. /**
  238. * Outputs the styles for a borderless style text field.
  239. *
  240. * @param {color} $background-color (transparent) - The background color of the text field
  241. *
  242. * @group textfield
  243. */
  244. @mixin valo-textfield-borderless-style ($background-color: transparent) {
  245. border: none;
  246. border-radius: 0;
  247. background: $background-color;
  248. @include box-shadow(none);
  249. $font-color: inherit;
  250. @if $background-color != transparent and type-of($background-color) == color {
  251. $font-color: valo-font-color($background-color);
  252. }
  253. color: $font-color;
  254. &:focus {
  255. @include box-shadow(none);
  256. }
  257. &[class*="prompt"],
  258. &[placeholder] {
  259. @include valo-textfield-prompt-style($background-color);
  260. }
  261. }
  262. /**
  263. * Outputs the styles for a text field error state.
  264. *
  265. * @group textfield
  266. */
  267. @mixin valo-textfield-error-style {
  268. border-color: $v-error-indicator-color !important;
  269. $bg: scale-color($v-error-indicator-color, $lightness: 98%);
  270. background: $bg;
  271. color: valo-font-color($bg);
  272. }
  273. /**
  274. * 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).
  275. *
  276. * @param {string} $primary-stylename (v-textfield) - The primary style name for the selectors
  277. * @param {string | list} $stylenames (inline-icon) - The additional style names which will define the inline-icon style
  278. * @param {string} $input-selector (null) - Additional selector for a nested input element which should be targeted
  279. * @param {size} $unit-size ($v-unit-size) - The unit size which the resulting style will support
  280. * @param {size} $font-size ($v-font-size) - The font size which the resulting style will support (needed for font icons)
  281. * @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)
  282. *
  283. * @group text field
  284. */
  285. @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) {
  286. $slot-selector: "";
  287. $caption-selector: "";
  288. $text-input-selector: "";
  289. @each $style in $stylenames {
  290. $slot-selector: $slot-selector + ".v-slot-" + $style;
  291. $caption-selector: $caption-selector + ".v-caption-" + $style;
  292. $text-input-selector: $text-input-selector + "." + $primary-stylename + "-" + $style;
  293. }
  294. #{$slot-selector} {
  295. position: relative;
  296. }
  297. #{$caption-selector} {
  298. padding: 0;
  299. .v-captiontext {
  300. // Need to include to get the default padding back
  301. @include valo-caption-style;
  302. margin: 0;
  303. }
  304. .v-icon {
  305. position: absolute;
  306. z-index: 10;
  307. }
  308. // Font icons
  309. span.v-icon {
  310. $border-width: first-number($v-textfield-border);
  311. left: $border-width;
  312. bottom: $border-width;
  313. width: $unit-size;
  314. line-height: $unit-size - $border-width*2;
  315. text-align: center;
  316. font-size: $font-size;
  317. }
  318. // Image icons
  319. img.v-icon {
  320. left: round(($unit-size - $image-icon-size)/2);
  321. bottom: round(($unit-size - $image-icon-size)/2);
  322. }
  323. }
  324. #{$text-input-selector} #{$input-selector} {
  325. padding-left: $unit-size;
  326. }
  327. }