_button-mixins.scss 3.7 KB

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