@react-spectrum/s2
Version:
Spectrum 2 UI components in React
1 lines • 8.84 kB
Source Map (JSON)
{"mappings":"ACyDoB;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAiEP;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAmCA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;;EAoBG;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAiBA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;;AAjBA;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAiBA;;;;EAAA;;;;;AAjBA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;IAAA","sources":["22171ecf279467c9","packages/@react-spectrum/s2/src/InlineAlert.tsx"],"sourcesContent":["@import \"05e5e4aa26bfa23e\";\n@import \"f0ba8200e7cea625\";\n@import \"0ad65d68fdf037be\";\n@import \"d57ae7ad1398d4b5\";\n@import \"11184415316db266\";\n","/*\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.css.map"}