@react-spectrum/inlinealert 3.0.0-nightly.3993
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +3 -0
- package/dist/import.mjs +477 -0
- package/dist/main.css +1 -0
- package/dist/main.js +478 -0
- package/dist/main.js.map +1 -0
- package/dist/module.js +477 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +59 -0
- package/src/InlineAlert.tsx +86 -0
- package/src/index.ts +15 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import AlertMedium from '@spectrum-icons/ui/AlertMedium';
|
|
14
|
+
import {classNames, SlotProvider, useDOMRef, useStyleProps} from '@react-spectrum/utils';
|
|
15
|
+
import {DOMRef} from '@react-types/shared';
|
|
16
|
+
import {filterDOMProps} from '@react-aria/utils';
|
|
17
|
+
import {Grid} from '@react-spectrum/layout';
|
|
18
|
+
import InfoMedium from '@spectrum-icons/ui/InfoMedium';
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
import intlMessages from '../intl/*.json';
|
|
21
|
+
import React from 'react';
|
|
22
|
+
import {SpectrumInlineAlertProps} from '@react-types/inlinealert';
|
|
23
|
+
import styles from '@adobe/spectrum-css-temp/components/inlinealert/vars.css';
|
|
24
|
+
import SuccessMedium from '@spectrum-icons/ui/SuccessMedium';
|
|
25
|
+
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
26
|
+
import {useProviderProps} from '@react-spectrum/provider';
|
|
27
|
+
|
|
28
|
+
let ICONS = {
|
|
29
|
+
info: InfoMedium,
|
|
30
|
+
positive: SuccessMedium,
|
|
31
|
+
notice: AlertMedium,
|
|
32
|
+
negative: AlertMedium
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function InlineAlert(props: SpectrumInlineAlertProps, ref: DOMRef<HTMLDivElement>) {
|
|
36
|
+
props = useProviderProps(props);
|
|
37
|
+
let {
|
|
38
|
+
children,
|
|
39
|
+
variant = 'neutral',
|
|
40
|
+
...otherProps
|
|
41
|
+
} = props;
|
|
42
|
+
|
|
43
|
+
let {styleProps} = useStyleProps(otherProps);
|
|
44
|
+
let domRef = useDOMRef(ref);
|
|
45
|
+
|
|
46
|
+
let slots = {
|
|
47
|
+
header: {UNSAFE_className: styles['spectrum-InLineAlert-header']},
|
|
48
|
+
content: {UNSAFE_className: styles['spectrum-InLineAlert-content']}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
52
|
+
let Icon = null;
|
|
53
|
+
let iconAlt: string;
|
|
54
|
+
if (variant in ICONS) {
|
|
55
|
+
Icon = ICONS[variant];
|
|
56
|
+
iconAlt = stringFormatter.format(variant);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div
|
|
61
|
+
{...filterDOMProps(props)}
|
|
62
|
+
{...styleProps}
|
|
63
|
+
ref={domRef}
|
|
64
|
+
className={classNames(
|
|
65
|
+
styles,
|
|
66
|
+
'spectrum-InLineAlert',
|
|
67
|
+
`spectrum-InLineAlert--${variant}`,
|
|
68
|
+
styleProps.className
|
|
69
|
+
)}
|
|
70
|
+
role="alert">
|
|
71
|
+
<Grid UNSAFE_className={styles['spectrum-InLineAlert-grid']}>
|
|
72
|
+
<SlotProvider slots={slots}>
|
|
73
|
+
{Icon && <Icon UNSAFE_className={styles['spectrum-InLineAlert-icon']} aria-label={iconAlt} />}
|
|
74
|
+
{children}
|
|
75
|
+
</SlotProvider>
|
|
76
|
+
</Grid>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Inline alerts display a non-modal message associated with objects in a view.
|
|
83
|
+
* These are often used in form validation, providing a place to aggregate feedback related to multiple fields.
|
|
84
|
+
*/
|
|
85
|
+
const _InlineAlert = React.forwardRef(InlineAlert);
|
|
86
|
+
export {_InlineAlert as InlineAlert};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/// <reference types="css-module-types" />
|
|
14
|
+
|
|
15
|
+
export {InlineAlert} from './InlineAlert';
|