UNPKG

@postenbring/hedwig-react

Version:

React components for [Hedwig Design System](https://github.com/bring/hedwig-design-system).

1 lines 3.67 kB
{"version":3,"sources":["../src/alert/alert.tsx"],"sourcesContent":["import React, { forwardRef, type HTMLAttributes } from \"react\";\nimport { clsx } from \"@postenbring/hedwig-css/typed-classname\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { Box, type BoxProps } from \"../box/box\";\n\nexport interface AlertTitleProps extends HTMLAttributes<HTMLParagraphElement> {\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n *\n * @default false\n */\n asChild?: boolean;\n}\nexport const AlertTitle = forwardRef<HTMLParagraphElement, AlertTitleProps>(\n ({ asChild, className, ...rest }, ref) => {\n const Component = asChild ? Slot : \"div\";\n return (\n <Component className={clsx(\"hds-alert__title\", className as undefined)} ref={ref} {...rest} />\n );\n },\n);\nAlertTitle.displayName = \"Alert.Title\";\n\nexport interface AlertDescriptionProps extends HTMLAttributes<HTMLParagraphElement> {\n /**\n * Change the default rendered element for the one passed as a child, merging their props and behavior.\n *\n * @default false\n */\n asChild?: boolean;\n}\nexport const AlertDescription = forwardRef<HTMLParagraphElement, AlertDescriptionProps>(\n ({ asChild, className, ...rest }, ref) => {\n const Component = asChild ? Slot : \"div\";\n return (\n <Component\n className={clsx(\"hds-alert__description\", className as undefined)}\n ref={ref}\n {...rest}\n />\n );\n },\n);\nAlertDescription.displayName = \"Alert.Description\";\n\nexport type AlertProps = (\n | {\n variant?: \"info\" | \"success\" | \"warning\" | \"error\";\n icon?: never;\n iconClassName?: never;\n }\n | {\n variant: \"neutral\";\n icon?: React.ReactNode;\n iconClassName?: string;\n }\n) &\n Omit<BoxProps, \"variant\" | \"asChild\">;\n\nexport const Alert = forwardRef<HTMLDivElement, AlertProps>(\n ({ children, className, variant = \"success\", icon, iconClassName, ...rest }, ref) => {\n return (\n <Box\n className={clsx(`hds-alert`, `hds-alert--${variant}`, className as undefined)}\n ref={ref}\n {...rest}\n >\n {variant === \"neutral\" && (\n <div className={clsx(\"hds-alert--neutral__icon\", iconClassName as undefined)}>{icon}</div>\n )}\n {children}\n </Box>\n );\n },\n) as AlertType;\nAlert.displayName = \"Alert\";\n\ntype AlertType = ReturnType<typeof forwardRef<HTMLDivElement, AlertProps>> & {\n Title: typeof AlertTitle;\n Description: typeof AlertDescription;\n};\nAlert.Title = AlertTitle;\nAlert.Description = AlertDescription;\n"],"mappings":";;;;;;;;;;AAAA,SAAgB,kBAAuC;AACvD,SAAS,YAAY;AACrB,SAAS,YAAY;AAef,cA6CA,YA7CA;AAJC,IAAM,aAAa;AAAA,EACxB,CAAC,IAAiC,QAAQ;AAAzC,iBAAE,WAAS,UAdd,IAcG,IAAyB,iBAAzB,IAAyB,CAAvB,WAAS;AACV,UAAM,YAAY,UAAU,OAAO;AACnC,WACE,oBAAC,4BAAU,WAAW,KAAK,oBAAoB,SAAsB,GAAG,OAAc,KAAM;AAAA,EAEhG;AACF;AACA,WAAW,cAAc;AAUlB,IAAM,mBAAmB;AAAA,EAC9B,CAAC,IAAiC,QAAQ;AAAzC,iBAAE,WAAS,UAhCd,IAgCG,IAAyB,iBAAzB,IAAyB,CAAvB,WAAS;AACV,UAAM,YAAY,UAAU,OAAO;AACnC,WACE;AAAA,MAAC;AAAA;AAAA,QACC,WAAW,KAAK,0BAA0B,SAAsB;AAAA,QAChE;AAAA,SACI;AAAA,IACN;AAAA,EAEJ;AACF;AACA,iBAAiB,cAAc;AAgBxB,IAAM,QAAQ;AAAA,EACnB,CAAC,IAA4E,QAAQ;AAApF,iBAAE,YAAU,WAAW,UAAU,WAAW,MAAM,cA5DrD,IA4DG,IAAoE,iBAApE,IAAoE,CAAlE,YAAU,aAAW,WAAqB,QAAM;AACjD,WACE;AAAA,MAAC;AAAA;AAAA,QACC,WAAW,KAAK,aAAa,cAAc,OAAO,IAAI,SAAsB;AAAA,QAC5E;AAAA,SACI,OAHL;AAAA,QAKE;AAAA,sBAAY,aACX,oBAAC,SAAI,WAAW,KAAK,4BAA4B,aAA0B,GAAI,gBAAK;AAAA,UAErF;AAAA;AAAA;AAAA,IACH;AAAA,EAEJ;AACF;AACA,MAAM,cAAc;AAMpB,MAAM,QAAQ;AACd,MAAM,cAAc;","names":[]}