_field.scss 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. @use 'sass:map';
  2. @use '../../tools' as *;
  3. @use '../../settings' as *;
  4. /**
  5. * The field component handles form fields’ layout and ancillary elements such as error messages and help text.
  6. * It doesn’t handle the style of the widgets, which are implemented independently for each widget type.
  7. *
  8. * Take special care when changing the field component: it can be used in forms but also in filters, headers, and any
  9. * other arbitrary part of the UI. It has to be very flexible to accommodate for all those use cases.
  10. */
  11. .w-field {
  12. position: relative;
  13. }
  14. .w-field__errors {
  15. .error-message {
  16. @apply w-label-2;
  17. color: theme('colors.text-error');
  18. display: inline-block;
  19. margin: 0;
  20. margin-top: theme('spacing.[0.5]');
  21. }
  22. }
  23. .w-field__errors-icon {
  24. // Position and size the icon according to the text size.
  25. position: relative;
  26. top: 0.125em;
  27. width: 1em;
  28. height: 1em;
  29. margin-inline-end: 0.625rem;
  30. color: theme('colors.text-error');
  31. // Avoid displaying the error message icon if we already have an icon.
  32. + .error-message::before {
  33. display: none;
  34. }
  35. }
  36. .w-field__label {
  37. @apply w-label-2;
  38. display: block;
  39. margin-top: 0;
  40. margin-bottom: 0;
  41. }
  42. .w-field__wrapper {
  43. @include max-form-width();
  44. // This is primarily helpful to add margins between fields, but fields can often
  45. // be wrapped into groups (for example a row), so it’s safer to add a margin regardless
  46. // of what the next element is.
  47. margin-bottom: $form-field-spacing;
  48. // Inside of listing tables we don't need margins because the table row will handle them.
  49. table.listing td & {
  50. margin-bottom: 0;
  51. .w-field__input {
  52. margin-top: 0;
  53. }
  54. }
  55. }
  56. .w-field__input {
  57. position: relative;
  58. margin-top: calc(theme('spacing.[2.5]') * var(--w-density-factor));
  59. }
  60. .w-field__icon {
  61. $size: theme('spacing.4');
  62. $offset: calc($text-input-height / 2 - $size / 2);
  63. width: $size;
  64. height: $size;
  65. color: theme('colors.icon-primary');
  66. position: absolute;
  67. // Top padding of text input and half of text size.
  68. top: $offset;
  69. inset-inline-start: $offset;
  70. pointer-events: none;
  71. + input {
  72. // Allows for a nice square around the icon.
  73. padding-inline-start: $text-input-height;
  74. }
  75. }