_field.scss 2.1 KB

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