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aAAK,EAAE,MAAM,SAAS;IACzC,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,aAAa,OAAO,IAAI,OAAO,OAAO,EACxC,OAAO,OAAO,CAAC,KAAK;QAEtB,aAAa,OAAO,GAAG;IACzB,GAAG;QAAC;KAAO;IAEX,qBACE,gBAAC;QACE,GAAG,CAAA,GAAA,qBAAa,EAAE,MAAM;QACxB,GAAG,UAAU;QACd,KAAK;QACL,UAAU,YAAY,KAAK;QAC3B,WAAW;QACX,MAAK;QACL,OAAO,MAAM,YAAY;QACzB,WAAW,AAAC,CAAA,MAAM,gBAAgB,IAAI,EAAC,IAAK,kCAAY;qBACtD;uBACA;4BACA;QACF,GAAG,MAAM,MAAM;kBACf,cAAA,gBAAC;YACC,WAAW;sBACX,cAAA,iBAAC,CAAA,GAAA,eAAO;gBACN,QAAQ;oBACN;wBAAC,CAAA,GAAA,yCAAa;wBAAG;4BAAC,QAAQ,8BAAQ;2CAAC;4BAAS;wBAAE;qBAAE;oBAChD;wBAAC,CAAA,GAAA,yCAAa;wBAAG;4BAAC,QAAQ,8BAAQ;2CAAC;4BAAS;wBAAE;qBAAE;oBAChD;wBAAC,CAAA,GAAA,yCAAU;wBAAG;4BAAC,QAAQ,2BAAK;yCAAC;2CAAS;4BAAS;wBAAE;qBAAE;iBACpD;;oBACA,sBAAQ,gBAAC;wBAAK,cAAY;;oBAC1B;;;;;AAKX","sources":["packages/@react-spectrum/s2/src/InlineAlert.tsx"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport AlertTriangle from '../s2wf-icons/S2_Icon_AlertTriangle_20_N.svg';\nimport CheckmarkCircle from '../s2wf-icons/S2_Icon_CheckmarkCircle_20_N.svg';\nimport {ComponentType, createContext, forwardRef, ReactNode, useEffect, useRef} from 'react';\nimport {ContentContext, HeadingContext} from './Content';\nimport {ContextValue, Provider, SlotProps} from 'react-aria-components';\nimport {DOMProps, DOMRef, DOMRefValue} from '@react-types/shared';\nimport {filterDOMProps} from '@react-aria/utils';\nimport {focusRing, style} from '../style' with {type: 'macro'};\nimport {getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};\nimport {IconContext} from './Icon';\nimport InfoCircle from '../s2wf-icons/S2_Icon_InfoCircle_20_N.svg';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport NoticeSquare from '../s2wf-icons/S2_Icon_AlertDiamond_20_N.svg';\nimport {useDOMRef} from '@react-spectrum/utils';\nimport {useFocusRing} from 'react-aria';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useSpectrumContextProps} from './useSpectrumContextProps';\n\nexport interface InlineAlertProps extends DOMProps, StyleProps, InlineStylesProps, SlotProps {\n /**\n * The contents of the Inline Alert.\n */\n children: ReactNode,\n /**\n * Whether to automatically focus the Inline Alert when it first renders.\n */\n autoFocus?: boolean\n}\n\ninterface InlineStylesProps {\n /**\n * The semantic tone of a Inline Alert.\n * @default neutral\n */\n variant?: 'informative' | 'positive' | 'notice' | 'negative' | 'neutral',\n /**\n * The visual style of the Inline Alert.\n * @default border\n */\n fillStyle?: 'border' | 'subtleFill' | 'boldFill'\n}\n\nexport const InlineAlertContext = createContext<ContextValue<Partial<InlineAlertProps>, DOMRefValue<HTMLDivElement>>>(null);\n\nconst inlineAlert = style<InlineStylesProps & {isFocusVisible?: boolean}>({\n ...focusRing(),\n display: 'inline-block',\n position: 'relative',\n boxSizing: 'border-box',\n padding: 24,\n borderRadius: 'lg',\n borderStyle: 'solid',\n borderWidth: 2,\n borderColor: {\n fillStyle: {\n border: {\n variant: {\n informative: 'informative-800',\n positive: 'positive-700',\n notice: 'notice-700',\n negative: 'negative-800',\n neutral: 'gray-700' // is there a semantic color name for neutral?\n }\n },\n subtleFill: 'transparent',\n boldFill: 'transparent'\n }\n },\n backgroundColor: {\n variant: {\n informative: {\n fillStyle: {\n border: 'gray-25',\n subtleFill: 'informative-subtle',\n boldFill: 'informative'\n }\n },\n positive: {\n fillStyle: {\n border: 'gray-25',\n subtleFill: 'positive-subtle',\n boldFill: 'positive'\n }\n },\n notice: {\n fillStyle: {\n border: 'gray-25',\n subtleFill: 'notice-subtle',\n boldFill: 'notice'\n }\n },\n negative: {\n fillStyle: {\n border: 'gray-25',\n subtleFill: 'negative-subtle',\n boldFill: 'negative'\n }\n },\n neutral: {\n fillStyle: {\n border: 'gray-25',\n subtleFill: 'neutral-subtle',\n boldFill: 'neutral-subdued'\n }\n }\n }\n }\n}, getAllowedOverrides());\n\nconst icon = style<InlineStylesProps>({\n gridArea: 'icon',\n '--iconPrimary': {\n type: 'fill',\n value: {\n fillStyle: {\n border: {\n variant: {\n informative: 'informative',\n positive: 'positive',\n notice: 'notice',\n negative: 'negative',\n neutral: 'neutral'\n }\n },\n subtleFill: {\n variant: {\n informative: 'informative',\n positive: 'positive',\n notice: 'negative',\n negative: 'negative',\n neutral: 'neutral'\n }\n },\n boldFill: {\n default: 'white',\n variant: {\n notice: 'black'\n }\n }\n }\n }\n }\n});\n\nconst grid = style({\n display: 'grid',\n columnGap: 24,\n gridTemplateColumns: '1fr auto',\n gridTemplateRows: 'auto auto auto',\n width: 'full',\n gridTemplateAreas: [\n 'heading icon',\n 'content content'\n ]\n});\n\nlet ICONS = {\n informative: InfoCircle,\n positive: CheckmarkCircle,\n notice: NoticeSquare,\n negative: AlertTriangle,\n neutral: undefined\n};\n\nconst heading = style({\n marginTop: 0,\n gridArea: 'heading',\n font: 'title-sm',\n color: {\n default: 'title',\n fillStyle: {\n boldFill: {\n default: 'white',\n variant: {\n notice: 'black'\n }\n }\n }\n }\n});\n\nconst content = style({\n gridArea: 'content',\n font: 'body-sm',\n color: {\n default: 'body',\n fillStyle: {\n boldFill: {\n default: 'white',\n variant: {\n notice: 'black'\n }\n }\n }\n }\n});\n\n/**\n * Inline alerts display a non-modal message associated with objects in a view.\n * These are often used in form validation, providing a place to aggregate feedback related to multiple fields.\n */\nexport const InlineAlert = /*#__PURE__*/ forwardRef(function InlineAlert(props: InlineAlertProps, ref: DOMRef<HTMLDivElement>) {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/s2');\n [props, ref] = useSpectrumContextProps(props, ref, InlineAlertContext);\n let {\n children,\n variant = 'neutral',\n fillStyle = 'border',\n autoFocus\n } = props;\n\n let domRef = useDOMRef(ref);\n\n let Icon: ComponentType<any> | null | undefined = null;\n let iconAlt = '';\n if (variant in ICONS) {\n Icon = ICONS[variant];\n if (Icon) {\n iconAlt = stringFormatter.format(`inlinealert.${variant}`);\n }\n }\n\n let {isFocusVisible, focusProps} = useFocusRing({autoFocus: props.autoFocus});\n let autoFocusRef = useRef(props.autoFocus);\n useEffect(() => {\n if (autoFocusRef.current && domRef.current) {\n domRef.current.focus();\n }\n autoFocusRef.current = false;\n }, [domRef]);\n\n return (\n <div\n {...filterDOMProps(props)}\n {...focusProps}\n ref={domRef}\n tabIndex={autoFocus ? -1 : undefined}\n autoFocus={autoFocus}\n role=\"alert\"\n style={props.UNSAFE_style}\n className={(props.UNSAFE_className || '') + inlineAlert({\n variant,\n fillStyle,\n isFocusVisible\n }, props.styles)}>\n <div\n className={grid}>\n <Provider\n values={[\n [HeadingContext, {styles: heading({fillStyle})}],\n [ContentContext, {styles: content({fillStyle})}],\n [IconContext, {styles: icon({variant, fillStyle})}]\n ]}>\n {Icon && <Icon aria-label={iconAlt} />}\n {children}\n </Provider>\n </div>\n </div>\n );\n});\n"],"names":[],"version":3,"file":"InlineAlert.mjs.map"}