Ringtone app
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

99 行
1.8 KiB

  1. import styled from 'styled-components';
  2. import {FC, MouseEventHandler, ReactChild} from 'react';
  3. const Base = styled('div')({
  4. height: '3rem',
  5. borderRadius: '0.25rem',
  6. overflow: 'hidden',
  7. position: 'relative',
  8. '::before': {
  9. content: "''",
  10. borderWidth: 1,
  11. borderStyle: 'solid',
  12. borderColor: 'inherit',
  13. position: 'absolute',
  14. top: 0,
  15. left: 0,
  16. width: '100%',
  17. height: '100%',
  18. borderRadius: 'inherit',
  19. boxSizing: 'border-box',
  20. opacity: 0.5,
  21. },
  22. })
  23. const ClickArea = styled('button')({
  24. display: 'grid',
  25. placeContent: 'center',
  26. width: '100%',
  27. height: '100%',
  28. margin: 0,
  29. padding: '0 1rem',
  30. boxSizing: 'border-box',
  31. font: 'inherit',
  32. border: 0,
  33. backgroundColor: 'transparent',
  34. color: 'inherit',
  35. outline: 0,
  36. textTransform: 'uppercase',
  37. fontWeight: 'bolder',
  38. position: 'relative',
  39. lineHeight: 0,
  40. cursor: 'pointer',
  41. ':disabled': {
  42. cursor: 'not-allowed',
  43. }
  44. })
  45. const VARIANTS = {
  46. default: {
  47. backgroundColor: 'var(--color-bg, white)',
  48. borderColor: 'var(--color-fg, black)',
  49. color: 'var(--color-fg, black)',
  50. },
  51. primary: {
  52. backgroundColor: 'var(--color-fg, black)',
  53. borderColor: 'var(--color-fg, black)',
  54. color: 'var(--color-bg, white)',
  55. },
  56. }
  57. type Props = {
  58. children?: ReactChild,
  59. className?: string,
  60. type?: 'button' | 'reset' | 'submit',
  61. block?: boolean,
  62. variant?: keyof typeof VARIANTS,
  63. onClick?: MouseEventHandler<HTMLButtonElement>,
  64. disabled?: boolean,
  65. }
  66. const ActionButton: FC<Props> = ({
  67. children,
  68. className,
  69. type = 'button',
  70. block,
  71. variant = 'default',
  72. ...etcProps
  73. }) => {
  74. return (
  75. <Base
  76. className={className}
  77. style={{
  78. ...VARIANTS[variant],
  79. display: block ? 'block' : 'inline-block',
  80. width: block ? '100%' : undefined,
  81. }}
  82. >
  83. <ClickArea
  84. {...etcProps}
  85. type={type}
  86. >
  87. {children}
  88. </ClickArea>
  89. </Base>
  90. )
  91. }
  92. export default ActionButton