GithubCorner.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div id="vue-github-corner">
  3. <a :href="url" id="github-corner" target="_blank" aria-label="View source on Github" >
  4. <svg id="github-corner-svg"
  5. aria-hidden="true"
  6. viewBox="0 0 250 250"
  7. :width="size" :height="size"
  8. :style="svgStyle" >
  9. <path :d="svgPath1" @mouseenter="flipColor" @mouseleave="flipColor"></path>
  10. <path :d="svgPath2" :style="gitStyle" class="octo-arm"></path>
  11. <path :d="svgPath3" :style="gitStyle" class="octo-body"></path>
  12. </svg>
  13. </a>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'GithubCorner',
  19. props: {
  20. url: {
  21. type: String,
  22. default: '/'
  23. },
  24. size: {
  25. type: Number,
  26. default: 80
  27. },
  28. colorScheme: {
  29. type: String,
  30. default: 'auto'
  31. },
  32. cornerColor: {
  33. type: String,
  34. default: '#625D5D'
  35. },
  36. gitColor: {
  37. type: String,
  38. default: 'PeachPuff'
  39. },
  40. leftCorner: {
  41. type: Boolean,
  42. default: false
  43. },
  44. flipOnHover: {
  45. type: Boolean,
  46. default: false
  47. }
  48. },
  49. data() {
  50. return {
  51. svgStyle: {
  52. fill: this.cornerColor,
  53. right: (this.leftCorner ? 'auto' : '0'),
  54. left: (this.leftCorner ? '0' : 'auto'),
  55. transform: (this.leftCorner ? 'scale(-1, 1)' : 'none')
  56. },
  57. gitStyle: {
  58. fill: this.gitColor
  59. },
  60. flipped: false,
  61. svgPath1: 'M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z',
  62. svgPath2: 'M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 ' +
  63. '123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2',
  64. svgPath3: 'M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 ' +
  65. 'C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 ' +
  66. '176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 ' +
  67. '216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 ' +
  68. 'C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z'
  69. }
  70. },
  71. methods: {
  72. flipColor: function() {
  73. if (this.flipOnHover) {
  74. let holdSvgFill = this.svgStyle.fill
  75. this.svgStyle.fill = this.gitStyle.fill
  76. this.gitStyle.fill = holdSvgFill
  77. }
  78. }
  79. },
  80. beforeMount: function() {
  81. if (this.colorScheme != 'auto') {
  82. let sch = this.colorScheme
  83. this.gitStyle.fill = '#fff'
  84. if (sch.toLowerCase() == 'black') {
  85. this.svgStyle.fill = '#151513'
  86. }
  87. if (sch.toLowerCase() == 'green') {
  88. this.svgStyle.fill = '#64CEAA'
  89. }
  90. if (sch.toLowerCase() == 'red') {
  91. this.svgStyle.fill = '#FD6C6C'
  92. }
  93. if (sch.toLowerCase() == 'blue') {
  94. this.svgStyle.fill = '#70B7FD'
  95. }
  96. if (sch.toLowerCase() == 'white') {
  97. this.svgStyle.fill = '#fff'
  98. this.gitStyle.fill = '#151513'
  99. }
  100. }
  101. }
  102. }
  103. </script>
  104. <style scoped>
  105. #github-corner .octo-arm {
  106. transform-origin: 130px 106px
  107. }
  108. #github-corner:hover .octo-arm {
  109. animation: octocat-wave 560ms ease-in-out;
  110. }
  111. @keyframes octocat-wave {
  112. 0% { transform: rotate(0deg); }
  113. 20% { transform: rotate(-25deg); }
  114. 40% { transform: rotate(10deg); }
  115. 60% { transform: rotate(-25deg); }
  116. 80% { transform: rotate(10deg); }
  117. 100% { transform: rotate(0deg); }
  118. }
  119. #github-corner-svg {
  120. color: #fff;
  121. position: absolute;
  122. top: 0;
  123. border: 0;
  124. }
  125. #github-corner-svg, #github-corner-svg .octo-arm, #github-corner-svg .octo-body {
  126. transition: fill 1s ease;
  127. }
  128. </style>