UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

1 lines 3.86 kB
{"version":3,"file":"alert.cjs","names":["OctagonAlertIcon","InfoIcon","CircleCheckBigIcon","TriangleAlertIcon","createSlotComponent","alertStyle","styled","useLoadingComponent"],"sources":["../../../../src/components/alert/alert.tsx"],"sourcesContent":["\"use client\"\n\nimport type { HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { IconProps } from \"../icon\"\nimport type { Loading } from \"../loading\"\nimport type { StatusScheme } from \"../status\"\nimport type { AlertStyle } from \"./alert.style\"\nimport { useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport {\n CircleCheckBigIcon,\n InfoIcon,\n OctagonAlertIcon,\n TriangleAlertIcon,\n} from \"../icon\"\nimport { useLoadingComponent } from \"../loading\"\nimport { alertStyle } from \"./alert.style\"\n\nconst icons = {\n error: OctagonAlertIcon,\n info: InfoIcon,\n success: CircleCheckBigIcon,\n warning: TriangleAlertIcon,\n} as const\n\ninterface ComponentContext {\n status: StatusScheme\n}\n\nexport interface AlertRootProps\n extends HTMLStyledProps,\n ThemeProps<AlertStyle> {\n /**\n * The status of the alert.\n *\n * @default 'info'\n */\n status?: StatusScheme\n}\n\nconst {\n ComponentContext,\n PropsContext: AlertPropsContext,\n useComponentContext,\n usePropsContext: useAlertPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<AlertRootProps, AlertStyle, ComponentContext>(\n \"alert\",\n alertStyle,\n)\n\nexport { AlertPropsContext, useAlertPropsContext }\n\n/**\n * `Alert` is a component that conveys information to the user.\n *\n * @see https://yamada-ui.com/docs/components/alert\n */\nexport const AlertRoot = withProvider<\"div\", AlertRootProps>(\n ({ status, colorScheme = status, ...props }) => {\n const context = useMemo(() => ({ status: status! }), [status])\n\n return (\n <ComponentContext value={context}>\n <styled.div colorScheme={colorScheme} role=\"alert\" {...props} />\n </ComponentContext>\n )\n },\n \"root\",\n)({ status: \"info\" })\n\nexport interface AlertIconProps extends IconProps {}\n\nexport const AlertIcon = withContext<\"svg\", AlertIconProps>(\n ({ as, ...rest }) => {\n const { status } = useComponentContext()\n const Icon = as || icons[status]\n\n return <Icon {...rest} />\n },\n \"icon\",\n)()\n\nexport interface AlertLoadingProps extends Loading.Props {\n /**\n * The loading scheme.\n *\n * @default 'oval'\n */\n loadingScheme?: Loading.Scheme\n}\n\nexport const AlertLoading = withContext<\"svg\", AlertLoadingProps>(\n ({ loadingScheme = \"oval\", ...rest }) => {\n const Component = useLoadingComponent(loadingScheme)\n\n return <Component {...rest} />\n },\n [\"icon\", \"loading\"],\n)()\n\nexport interface AlertTitleProps extends HTMLStyledProps<\"p\"> {}\n\nexport const AlertTitle = withContext<\"p\", AlertTitleProps>(\"p\", \"title\")()\n\nexport interface AlertDescriptionProps extends HTMLStyledProps<\"span\"> {}\n\nexport const AlertDescription = withContext<\"span\", AlertDescriptionProps>(\n \"span\",\n \"description\",\n)()\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,QAAQ;CACZ,OAAOA;CACP,MAAMC;CACN,SAASC;CACT,SAASC;CACV;AAiBD,MAAM,EACJ,kBACA,cAAc,mBACd,qBACA,iBAAiB,sBACjB,aACA,iBACEC,6CACF,SACAC,+BACD;;;;;;AASD,MAAa,YAAY,cACtB,EAAE,QAAQ,cAAc,OAAQ,GAAG,YAAY;AAG9C,QACE,2CAAC;EAAiB,iCAHW,EAAU,QAAS,GAAG,CAAC,OAAO,CAAC;YAI1D,2CAACC,uBAAO;GAAiB;GAAa,MAAK;GAAQ,GAAI;IAAS;GAC/C;GAGvB,OACD,CAAC,EAAE,QAAQ,QAAQ,CAAC;AAIrB,MAAa,YAAY,aACtB,EAAE,GAAI,GAAG,WAAW;CACnB,MAAM,EAAE,WAAW,qBAAqB;AAGxC,QAAO,2CAFM,MAAM,MAAM,WAEZ,GAAI,OAAQ;GAE3B,OACD,EAAE;AAWH,MAAa,eAAe,aACzB,EAAE,gBAAgB,OAAQ,GAAG,WAAW;AAGvC,QAAO,2CAFWC,kDAAoB,cAAc,IAElC,GAAI,OAAQ;GAEhC,CAAC,QAAQ,UAAU,CACpB,EAAE;AAIH,MAAa,aAAa,YAAkC,KAAK,QAAQ,EAAE;AAI3E,MAAa,mBAAmB,YAC9B,QACA,cACD,EAAE"}