_button-mixins.scss 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. @mixin button-main-styles {
  3. @include button-padding-styles;
  4. @include button-typography-styles;
  5. @include button-color-styles;
  6. border-radius: var(--wp--custom--button--border--radius);
  7. }
  8. @mixin button-color-styles {
  9. opacity: 1;
  10. color: var(--wp--custom--button--color--text);
  11. background-color: var(--wp--custom--button--color--background);
  12. border-color: currentColor;
  13. svg {
  14. fill: var(--wp--custom--button--color--text);
  15. }
  16. }
  17. //standard Button padding. Account for desired padding size and the size of the border width (so that the total height of
  18. //standard and outline buttons are equal.
  19. @mixin button-padding-styles {
  20. border-width: 0;
  21. padding-top: calc( var(--wp--custom--button--spacing--padding--top) + var(--wp--custom--button--border--width) );
  22. padding-bottom: calc( var(--wp--custom--button--spacing--padding--bottom) + var(--wp--custom--button--border--width) );
  23. padding-left: calc( var(--wp--custom--button--spacing--padding--left) + var(--wp--custom--button--border--width) );
  24. padding-right: calc( var(--wp--custom--button--spacing--padding--right) + var(--wp--custom--button--border--width) );
  25. }
  26. @mixin button-typography-styles {
  27. font-weight: var(--wp--custom--button--typography--font-weight);
  28. font-family: var(--wp--custom--button--typography--font-family);
  29. font-size: var(--wp--custom--button--typography--font-size);
  30. line-height: var(--wp--custom--button--typography--line-height);
  31. text-decoration: none; // Needed because link styles inside .entry-content add a text decoration
  32. }
  33. //apply outline styles. apply padding that does NOT account for border width (as the border width is applied here).
  34. @mixin button-border-styles {
  35. border-style: var(--wp--custom--button--border--style);
  36. border-width: var(--wp--custom--button--border--width);
  37. padding-top: var(--wp--custom--button--spacing--padding--top);
  38. padding-bottom: var(--wp--custom--button--spacing--padding--bottom);
  39. padding-left: var(--wp--custom--button--spacing--padding--left);
  40. padding-right: var(--wp--custom--button--spacing--padding--right);
  41. }
  42. // NOTE: These remain for the hover styling of blocks. This can be removed when the button block has configurable hover states.
  43. // The mechanism below ONLY CHANGES CSS VARIABLES that are already applied to properties (above)
  44. @mixin button-hover-styles {
  45. //The following changes should ONLY be changed if the user has NOT set a custom color
  46. &:not(.has-background):not(.has-text-color) {
  47. &:hover,
  48. &:focus,
  49. &.has-focus {
  50. //change the color variables to the hover equivalent
  51. --wp--custom--button--color--text: var(--wp--custom--button--hover--color--text);
  52. --wp--custom--button--color--background: var(--wp--custom--button--hover--color--background);
  53. --wp--custom--button--border--color: var(--wp--custom--button--hover--border--color);
  54. @include button-color-styles;
  55. border-color: var(--wp--custom--button--border--color);
  56. }
  57. }
  58. }