@helpwave/hightide
Version:
helpwave's component and theming library
1 lines • 17.3 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/components/loading-states/LoadingButton.tsx","../../../src/components/user-action/Button.tsx","../../../src/util/noop.ts","../../../src/components/icons-and-geometry/Helpwave.tsx"],"sourcesContent":["import clsx from 'clsx'\nimport type { SolidButtonProps } from '../user-action/Button'\nimport { ButtonUtil, SolidButton } from '../user-action/Button'\nimport { noop } from '../../util/noop'\nimport { Helpwave } from '../icons-and-geometry/Helpwave'\n\ntype LoadingButtonProps = {\n isLoading?: boolean,\n} & SolidButtonProps\n\nexport const LoadingButton = ({ isLoading = false, size = 'medium', onClick, ...rest }: LoadingButtonProps) => {\n const paddingClass = ButtonUtil.paddingMapping[size]\n\n return (\n <div className=\"inline-block relative\">\n {\n isLoading && (\n <div className={clsx('flex-row-2 absolute inset-0 items-center justify-center bg-white/40', paddingClass)}>\n <Helpwave animate=\"loading\" className=\"text-white\"/>\n </div>\n )\n }\n <SolidButton {...rest} disabled={rest.disabled} onClick={isLoading ? noop : onClick}/>\n </div>\n )\n}\n","import type { ButtonHTMLAttributes, PropsWithChildren, ReactNode } from 'react'\nimport { forwardRef } from 'react'\nimport clsx from 'clsx'\n\n\nexport const ButtonColorUtil = {\n solid: ['primary', 'secondary', 'tertiary', 'positive', 'warning', 'negative', 'neutral'] as const,\n text: ['primary', 'negative', 'neutral'] as const,\n outline: ['primary'] as const,\n}\n\nexport const IconButtonUtil = {\n icon: [...ButtonColorUtil.solid, 'transparent'] as const,\n}\n\n\n/**\n * The allowed colors for the SolidButton and IconButton\n */\nexport type SolidButtonColor = typeof ButtonColorUtil.solid[number]\n/**\n * The allowed colors for the OutlineButton\n */\nexport type OutlineButtonColor = typeof ButtonColorUtil.outline[number]\n/**\n * The allowed colors for the TextButton\n */\nexport type TextButtonColor = typeof ButtonColorUtil.text[number]\n/**\n * The allowed colors for the IconButton\n */\nexport type IconButtonColor = typeof IconButtonUtil.icon[number]\n\n\n/**\n * The different sizes for a button\n */\ntype ButtonSizes = 'small' | 'medium' | 'large'\n\ntype IconButtonSize = 'tiny' | 'small' | 'medium' | 'large'\n\n/**\n * The shard properties between all button types\n */\nexport type ButtonProps = PropsWithChildren<{\n /**\n * @default 'medium'\n */\n size?: ButtonSizes,\n}> & ButtonHTMLAttributes<Element>\n\nconst paddingMapping: Record<ButtonSizes, string> = {\n small: 'btn-sm',\n medium: 'btn-md',\n large: 'btn-lg'\n}\n\nconst iconPaddingMapping: Record<IconButtonSize, string> = {\n tiny: 'icon-btn-xs',\n small: 'icon-btn-sm',\n medium: 'icon-btn-md',\n large: 'icon-btn-lg'\n}\n\nexport const ButtonUtil = {\n paddingMapping,\n iconPaddingMapping\n}\n\ntype ButtonWithIconsProps = ButtonProps & {\n startIcon?: ReactNode,\n endIcon?: ReactNode,\n}\n\nexport type SolidButtonProps = ButtonWithIconsProps & {\n color?: SolidButtonColor,\n}\n\nexport type OutlineButtonProps = ButtonWithIconsProps & {\n color?: OutlineButtonColor,\n}\n\nexport type TextButtonProps = ButtonWithIconsProps & {\n color?: TextButtonColor,\n coloredHoverBackground?: boolean,\n}\n\n/**\n * The shard properties between all button types\n */\nexport type IconButtonProps = PropsWithChildren<{\n /**\n * @default 'medium'\n */\n size?: IconButtonSize,\n color?: IconButtonColor,\n}> & ButtonHTMLAttributes<Element>\n\n/**\n * A button with a solid background and different sizes\n */\nconst SolidButton = forwardRef<HTMLButtonElement, SolidButtonProps>(function SolidButton({\n children,\n color = 'primary',\n size = 'medium',\n startIcon,\n endIcon,\n onClick,\n className,\n ...restProps\n }, ref) {\n const colorClasses = {\n primary: 'not-disabled:bg-button-solid-primary-background not-disabled:text-button-solid-primary-text',\n secondary: 'not-disabled:bg-button-solid-secondary-background not-disabled:text-button-solid-secondary-text',\n tertiary: 'not-disabled:bg-button-solid-tertiary-background not-disabled:text-button-solid-tertiary-text',\n positive: 'not-disabled:bg-button-solid-positive-background not-disabled:text-button-solid-positive-text',\n warning: 'not-disabled:bg-button-solid-warning-background not-disabled:text-button-solid-warning-text',\n negative: 'not-disabled:bg-button-solid-negative-background not-disabled:text-button-solid-negative-text',\n neutral: 'not-disabled:bg-button-solid-neutral-background not-disabled:text-button-solid-neutral-text',\n }[color]\n\n const iconColorClasses = {\n primary: 'not-group-disabled:text-button-solid-primary-icon',\n secondary: 'not-group-disabled:text-button-solid-secondary-icon',\n tertiary: 'not-group-disabled:text-button-solid-tertiary-icon',\n positive: 'not-group-disabled:text-button-solid-positive-icon',\n warning: 'not-group-disabled:text-button-solid-warning-icon',\n negative: 'not-group-disabled:text-button-solid-negative-icon',\n neutral: 'not-group-disabled:text-button-solid-neutral-icon',\n }[color]\n\n return (\n <button\n ref={ref}\n onClick={onClick}\n className={clsx(\n 'group font-semibold',\n colorClasses,\n 'not-disabled:hover:brightness-90',\n 'disabled:text-disabled-text disabled:bg-disabled-background',\n ButtonUtil.paddingMapping[size],\n className\n )}\n {...restProps}\n >\n {startIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {startIcon}\n </span>\n )}\n {children}\n {endIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {endIcon}\n </span>\n )}\n </button>\n )\n})\n\n/**\n * A button with an outline border and different sizes\n */\nconst OutlineButton = ({\n children,\n color = 'primary',\n size = 'medium',\n startIcon,\n endIcon,\n onClick,\n className,\n ...restProps\n }: OutlineButtonProps) => {\n const colorClasses = {\n primary: 'not-disabled:border-button-outline-primary-text not-disabled:text-button-outline-primary-text',\n }[color]\n\n const iconColorClasses = {\n primary: 'not-group-disabled:text-button-outline-primary-icon',\n }[color]\n return (\n <button\n onClick={onClick}\n className={clsx(\n 'group font-semibold bg-transparent border-2 ',\n 'not-disabled:hover:brightness-80',\n colorClasses,\n 'disabled:text-disabled-text disabled:border-disabled-outline',\n ButtonUtil.paddingMapping[size],\n className\n )}\n {...restProps}\n >\n {startIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {startIcon}\n </span>\n )}\n {children}\n {endIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {endIcon}\n </span>\n )}\n </button>\n )\n}\n\n/**\n * A text that is a button that can have different sizes\n */\nconst TextButton = ({\n children,\n color = 'neutral',\n size = 'medium',\n startIcon,\n endIcon,\n onClick,\n coloredHoverBackground = true,\n className,\n ...restProps\n }: TextButtonProps) => {\n const colorClasses = {\n primary: 'not-disabled:bg-transparent not-disabled:text-button-text-primary-text',\n negative: 'not-disabled:bg-transparent not-disabled:text-button-text-negative-text',\n neutral: 'not-disabled:bg-transparent not-disabled:text-button-text-neutral-text',\n }[color]\n\n const backgroundColor = {\n primary: 'not-disabled:hover:bg-button-text-primary-text/20',\n negative: 'not-disabled:hover:bg-button-text-negative-text/20',\n neutral: 'not-disabled:hover:bg-button-text-neutral-text/20',\n }[color]\n\n const iconColorClasses = {\n primary: 'not-group-disabled:text-button-text-primary-icon',\n negative: 'not-group-disabled:text-button-text-negative-icon',\n neutral: 'not-group-disabled:text-button-text-neutral-icon',\n }[color]\n\n return (\n <button\n onClick={onClick}\n className={clsx(\n 'group font-semibold',\n 'disabled:text-disabled-text',\n colorClasses,\n {\n [backgroundColor]: coloredHoverBackground,\n 'not-disabled:hover:bg-button-text-hover-background': !coloredHoverBackground,\n },\n ButtonUtil.paddingMapping[size],\n className\n )}\n {...restProps}\n >\n {startIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {startIcon}\n </span>\n )}\n {children}\n {endIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {endIcon}\n </span>\n )}\n </button>\n )\n}\n\n\n/**\n * A button for icons with a solid background and different sizes\n */\nconst IconButton = ({\n children,\n color = 'primary',\n size = 'medium',\n className,\n ...restProps\n }: IconButtonProps) => {\n const colorClasses = {\n primary: 'not-disabled:bg-button-solid-primary-background not-disabled:text-button-solid-primary-text',\n secondary: 'not-disabled:bg-button-solid-secondary-background not-disabled:text-button-solid-secondary-text',\n tertiary: 'not-disabled:bg-button-solid-tertiary-background not-disabled:text-button-solid-tertiary-text',\n positive: 'not-disabled:bg-button-solid-positive-background not-disabled:text-button-solid-positive-text',\n warning: 'not-disabled:bg-button-solid-warning-background not-disabled:text-button-solid-warning-text',\n negative: 'not-disabled:bg-button-solid-negative-background not-disabled:text-button-solid-negative-text',\n neutral: 'not-disabled:bg-button-solid-neutral-background not-disabled:text-button-solid-neutral-text',\n transparent: 'not-disabled:bg-transparent',\n }[color]\n\n return (\n <button\n className={clsx(\n colorClasses,\n 'not-disabled:hover:brightness-90',\n 'disabled:text-disabled-text',\n {\n 'disabled:bg-disabled-background': color !== 'transparent',\n 'disabled:opacity-70': color === 'transparent',\n 'not-disabled:hover:bg-button-text-hover-background': color === 'transparent',\n },\n ButtonUtil.iconPaddingMapping[size],\n className\n )}\n {...restProps}\n >\n {children}\n </button>\n )\n}\n\nexport { SolidButton, OutlineButton, TextButton, IconButton }\n","export const noop = () => undefined\n","import type { SVGProps } from 'react'\nimport { clsx } from 'clsx'\n\nexport type HelpwaveProps = SVGProps<SVGSVGElement> & {\n color?: string,\n animate?: 'none' | 'loading' | 'pulse' | 'bounce',\n size?: number,\n}\n\n/**\n * The helpwave loading spinner based on the svg logo.\n */\nexport const Helpwave = ({\n color = 'currentColor',\n animate = 'none',\n size = 64,\n ...props\n }: HelpwaveProps) => {\n const isLoadingAnimation = animate === 'loading'\n let svgAnimationKey = ''\n\n if (animate === 'pulse') {\n svgAnimationKey = 'animate-pulse'\n } else if (animate === 'bounce') {\n svgAnimationKey = 'animate-bounce'\n }\n\n if (size < 0) {\n console.error('size cannot be less than 0')\n size = 64\n }\n\n return (\n <svg\n width={size}\n height={size}\n viewBox=\"0 0 888 888\"\n fill=\"none\"\n strokeLinecap=\"round\"\n strokeWidth={48}\n {...props}\n >\n <g className={clsx(svgAnimationKey)}>\n <path className={clsx({ 'animate-wave-big-left-up': isLoadingAnimation })}\n d=\"M144 543.235C144 423.259 232.164 326 340.92 326\" stroke={color} strokeDasharray=\"1000\"/>\n <path className={clsx({ 'animate-wave-big-right-down': isLoadingAnimation })}\n d=\"M537.84 544.104C429.084 544.104 340.92 446.844 340.92 326.869\" stroke={color} strokeDasharray=\"1000\"/>\n <path className={clsx({ 'animate-wave-small-left-up': isLoadingAnimation })}\n d=\"M462.223 518.035C462.223 432.133 525.348 362.495 603.217 362.495\" stroke={color}\n strokeDasharray=\"1000\"/>\n <path className={clsx({ 'animate-wave-small-right-down': isLoadingAnimation })}\n d=\"M745.001 519.773C666.696 519.773 603.218 450.136 603.218 364.233\" stroke={color}\n strokeDasharray=\"1000\"/>\n </g>\n </svg>\n )\n}\n"],"mappings":";AAAA,OAAOA,WAAU;;;ACCjB,SAAS,kBAAkB;AAC3B,OAAO,UAAU;AAkIb,SAcI,KAdJ;AA/HG,IAAM,kBAAkB;AAAA,EAC7B,OAAO,CAAC,WAAW,aAAa,YAAY,YAAY,WAAW,YAAY,SAAS;AAAA,EACxF,MAAM,CAAC,WAAW,YAAY,SAAS;AAAA,EACvC,SAAS,CAAC,SAAS;AACrB;AAEO,IAAM,iBAAiB;AAAA,EAC5B,MAAM,CAAC,GAAG,gBAAgB,OAAO,aAAa;AAChD;AAsCA,IAAM,iBAA8C;AAAA,EAClD,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AACT;AAEA,IAAM,qBAAqD;AAAA,EACzD,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AACT;AAEO,IAAM,aAAa;AAAA,EACxB;AAAA,EACA;AACF;AAkCA,IAAM,cAAc,WAAgD,SAASC,aAAY;AAAA,EACE;AAAA,EACA,QAAQ;AAAA,EACR,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAG,KAAK;AAC/F,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