File size: 1,343 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
{
  "type": "composition",
  "npmDependencies": [],
  "fileDependencies": [],
  "id": "button",
  "file": {
    "name": "button.tsx",
    "content": "import type { ButtonProps as ChakraButtonProps } from \"@chakra-ui/react\"\nimport {\n  AbsoluteCenter,\n  Button as ChakraButton,\n  Span,\n  Spinner,\n} from \"@chakra-ui/react\"\nimport * as React from \"react\"\n\ninterface ButtonLoadingProps {\n  loading?: boolean\n  loadingText?: React.ReactNode\n}\n\nexport interface ButtonProps extends ChakraButtonProps, ButtonLoadingProps {}\n\nexport const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n  function Button(props, ref) {\n    const { loading, disabled, loadingText, children, ...rest } = props\n    return (\n      <ChakraButton disabled={loading || disabled} ref={ref} {...rest}>\n        {loading && !loadingText ? (\n          <>\n            <AbsoluteCenter display=\"inline-flex\">\n              <Spinner size=\"inherit\" color=\"inherit\" />\n            </AbsoluteCenter>\n            <Span opacity={0}>{children}</Span>\n          </>\n        ) : loading && loadingText ? (\n          <>\n            <Spinner size=\"inherit\" color=\"inherit\" />\n            {loadingText}\n          </>\n        ) : (\n          children\n        )}\n      </ChakraButton>\n    )\n  },\n)\n"
  },
  "component": "Button"
}