_button-mixins.scss 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // NOTE: These remain for the styling of buttons that are NOT blocks and is used elsewhere. This can be removed when those no longer exist.
  2. // See https://github.com/WordPress/gutenberg/issues/29167
  3. // We are keeping the mixin in case it's used by any child themes, but this isn't used by Blockbase any more
  4. @mixin button-main-styles {
  5. @include button-padding-styles;
  6. @include button-typography-styles;
  7. @include button-color-styles;
  8. border-radius: var(--wp--custom--button--border--radius);
  9. }
  10. @mixin button-color-styles {
  11. opacity: 1;
  12. color: var(--wp--custom--button--color--text);
  13. background-color: var(--wp--custom--button--color--background);
  14. border-color: currentcolor;
  15. svg {
  16. fill: var(--wp--custom--button--color--text);
  17. }
  18. }
  19. //standard Button padding. Account for desired padding size and the size of the border width (so that the total height of
  20. //standard and outline buttons are equal.
  21. @mixin button-padding-styles {
  22. border-width: 0;
  23. padding-top: calc(var(--wp--custom--button--spacing--padding--top) + var(--wp--custom--button--border--width));
  24. padding-bottom: calc(var(--wp--custom--button--spacing--padding--bottom) + var(--wp--custom--button--border--width));
  25. padding-left: calc(var(--wp--custom--button--spacing--padding--left) + var(--wp--custom--button--border--width));
  26. padding-right: calc(var(--wp--custom--button--spacing--padding--right) + var(--wp--custom--button--border--width));
  27. }
  28. @mixin button-typography-styles {
  29. font-weight: var(--wp--custom--button--typography--font-weight);
  30. font-family: inherit;
  31. font-size: var(--wp--custom--button--typography--font-size);
  32. line-height: var(--wp--custom--button--typography--line-height);
  33. text-decoration: none; // Needed because link styles inside .entry-content add a text decoration
  34. }
  35. //apply outline styles. apply padding that does NOT account for border width (as the border width is applied here).
  36. @mixin button-border-styles {
  37. border-style: var(--wp--custom--button--border--style);
  38. border-width: var(--wp--custom--button--border--width);
  39. padding-top: var(--wp--custom--button--spacing--padding--top);
  40. padding-bottom: var(--wp--custom--button--spacing--padding--bottom);
  41. padding-left: var(--wp--custom--button--spacing--padding--left);
  42. padding-right: var(--wp--custom--button--spacing--padding--right);
  43. }
  44. // NOTE: These remain for the hover styling of blocks. This can be removed when the button block has configurable hover states.
  45. // The mechanism below ONLY CHANGES CSS VARIABLES that are already applied to properties (above)
  46. // See https://github.com/WordPress/gutenberg/issues/4543
  47. @mixin button-hover-styles {
  48. //The following changes should ONLY be changed if the user has NOT set a custom color
  49. &:not(.has-background):not(.has-text-color) {
  50. &:hover,
  51. &:focus,
  52. &.has-focus {
  53. //change the color variables to the hover equivalent
  54. --wp--custom--button--color--text: var(--wp--custom--button--hover--color--text);
  55. --wp--custom--button--color--background: var(--wp--custom--button--hover--color--background);
  56. --wp--custom--button--border--color: var(--wp--custom--button--hover--border--color);
  57. @include button-color-styles;
  58. border-color: var(--wp--custom--button--border--color);
  59. }
  60. }
  61. }
  62. //Mixins for the alternative outline style
  63. @mixin button-outline-hover-styles {
  64. &:hover,
  65. &:focus,
  66. &.has-focus {
  67. border-style: var(--wp--custom--button--border--style);
  68. border-color: currentcolor;
  69. border-width: var(--wp--custom--button--border--width);
  70. padding-top: var(--wp--custom--button--spacing--padding--top);
  71. padding-bottom: var(--wp--custom--button--spacing--padding--bottom);
  72. padding-left: var(--wp--custom--button--spacing--padding--left);
  73. padding-right: var(--wp--custom--button--spacing--padding--right);
  74. }
  75. }