-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathinline-notice.tsx
62 lines (54 loc) · 1.69 KB
/
inline-notice.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { FC, useEffect, ReactNode } from 'react'
import classNames from 'classnames'
import { EbayNoticeContent } from '../ebay-notice-base/components/ebay-notice-content'
import NoticeContent from '../common/notice-utils/notice-content'
import { findComponent } from '../common/component-utils'
import { EbayIcon, Icon } from '../ebay-icon'
import { NoticeStatus } from './types'
type Props = React.ComponentProps<'div'> & {
status?: NoticeStatus;
onNoticeShow?: () => void;
'aria-label': string;
hidden?: boolean;
className?: string
children?: ReactNode;
}
const EbayInlineNotice: FC<Props> = ({
className,
status = 'general',
children,
hidden = false,
'aria-label': ariaLabel,
onNoticeShow = () => {},
...rest
}) => {
useEffect(() => {
if (!hidden) {
onNoticeShow()
}
}, [hidden])
if (hidden) {
return null
}
const content = findComponent(children, EbayNoticeContent)
if (!content) {
throw new Error(`EbayInlineNotice: Please use a EbayNoticeContent that defines the content of the notice`)
}
const isGeneral = status === `general`
return (
<div
{...rest}
className={classNames(className, 'inline-notice', { [`inline-notice--${status}`]: !isGeneral })}
>
{!isGeneral ? (
<span className="inline-notice__header">
<EbayIcon name={`${status}Filled16` as Icon} a11yText={ariaLabel} a11yVariant="label" />
</span>
) : null}
<NoticeContent
{...content.props}
type="inline" />
</div>
)
}
export default EbayInlineNotice