@material-ui/core#ExtendButton TypeScript Examples

The following examples show how to use @material-ui/core#ExtendButton. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Button.tsx    From storefront with MIT License 5 votes vote down vote up
Button = (({
  as,
  children,
  circle = false,
  disabled = false,
  href,
  loading = false,
  prefetch,
  size = 'medium',
  sx: sxProp,
  ...props
}: ButtonProps) => {
  const handleTrack = () => {
    ReactGA.outboundLink(
      { label: typeof children === 'string' ? `Clicked ${children}` : 'Clicked link' },
      () => {},
    );
  };

  const sx: typeof sxProp = {
    ...sxProp,
    ...(circle && {
      minWidth: 0,
      p: 0,

      ...(size === 'small'
        ? {
            borderRadius: 20,
            height: 20,
            width: 20,
          }
        : {
            borderRadius: 44,
            height: 44,
            width: 44,
          }),
    }),
  };

  return href == null ? (
    <MuiButton disabled={disabled || loading} size={size} sx={sx} {...props}>
      {loading && (
        <Box
          sx={{
            display: 'flex',
            left: '50%',
            position: 'absolute',
            transform: 'translate(-50%)',
            visibility: 'visible',
          }}
        >
          <CircularProgress color="inherit" size={26} />
        </Box>
      )}
      <Box component="span" sx={loading ? { visibility: 'hidden' } : {}}>
        {children}
      </Box>
    </MuiButton>
  ) : /^https?:/.test(href.toString()) ? (
    <MuiButton
      href={href.toString()}
      size={size}
      sx={sx}
      onClick={handleTrack}
      {...(props as ButtonProps<'a'>)}
    >
      {children}
    </MuiButton>
  ) : (
    <Link passHref as={as} href={href} prefetch={prefetch}>
      <MuiButton component="a" size={size} sx={sx} {...(props as ButtonProps<'a'>)}>
        {children}
      </MuiButton>
    </Link>
  );
}) as ExtendButton<TypeMap>