template.jsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React from 'react'
  2. import styled from 'styled-components'
  3. import t from 'prop-types'
  4. const scales = {
  5. small: `
  6. padding: 5px 10px;
  7. font-size: 14px;
  8. `,
  9. normal: `
  10. padding: 10px 20px;
  11. font-size: 16px;
  12. `,
  13. big: `
  14. padding: 20px 30px;
  15. font-size: 18px;
  16. `,
  17. }
  18. const kind = outline => (bg, color) => {
  19. const boxShadowColor = outline ? bg : 'transparent'
  20. const backgroundColor = outline ? 'transparent' : bg
  21. return `
  22. background: ${backgroundColor};
  23. box-shadow: inset 0 0 0 1px ${boxShadowColor};
  24. color: ${outline ? bg : color};
  25. transition: all .3s;
  26. &:hover {
  27. box-shadow: inset 0 0 0 1000px ${boxShadowColor};
  28. color: ${color};
  29. }
  30. `
  31. }
  32. const kinds = outline => {
  33. const get = kind(outline)
  34. return {
  35. primary: get('#1FB6FF', 'white'),
  36. secondary: get('#5352ED', 'white'),
  37. cancel: get('#FF4949', 'white'),
  38. dark: get('#273444', 'white'),
  39. gray: get('#8492A6', 'white'),
  40. }
  41. }
  42. const getScale = ({ scale = 'normal' }) => scales[scale]
  43. const getKind = ({ kind = 'primary', outline = false }) => kinds(outline)[kind]
  44. const ButtonStyled = styled('button')`
  45. ${getKind};
  46. ${getScale};
  47. cursor: pointer;
  48. margin: 3px 5px;
  49. border: none;
  50. border-radius: 3px;
  51. `
  52. export const Button = ({ children, ...props }) => (
  53. <ButtonStyled {...props}>{children}</ButtonStyled>
  54. )
  55. Button.propTypes = {
  56. /**
  57. * This is a pretty good description for this prop
  58. */
  59. scales: t.oneOf(['small', 'normal', 'big']),
  60. kind: t.oneOf(['primary', 'secondary', 'cancel', 'dark', 'gray']),
  61. outline: t.bool.isRequired,
  62. }
  63. Button.defaultProps = {
  64. scales: 'normal',
  65. kind: 'primary',
  66. outline: false,
  67. }
  68. export function EditButton(props) {
  69. let encodedStatus = encodeURIComponent(
  70. "This live editor looks pretty darn handy #JavaScript"
  71. )
  72. let encodedURL = encodeURIComponent(
  73. "https://ecs.chenxixian.cn/chenxixian/docz/src/master"
  74. )
  75. return (
  76. <a
  77. href={`https://ecs.chenxixian.cn/chenxixian/docz/_edit/master/template.mdx`}
  78. target="_blank"
  79. className="EditButton">
  80. Edit This Page!
  81. </a>
  82. )
  83. }