-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFormBanner.tsx
56 lines (48 loc) · 1.49 KB
/
FormBanner.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
import styled from '@emotion/styled';
import { formBanner } from '@tablecheck/tablekit-core';
import * as React from 'react';
import { getSentimentIcon } from '../config';
export type Props = formBanner.Props;
export const FormBannerCore = styled.div<Props>`
${formBanner.fullStyles}
`;
export const FormBannerMessage = styled.div`
font: var(--body-2);
`;
export const FormBannerIconWrapper = React.forwardRef<
HTMLSpanElement,
React.HTMLAttributes<HTMLSpanElement>
>((props, ref) => (
<span
{...props}
ref={ref}
style={{ ...(props.style || {}), display: 'inline-flex', marginTop: '2px' }}
className={`${props.className || ''} form-banner-icon`}
/>
));
interface ComposedProps extends Props {
/**
* Icon to display in the form banner. Pass `null` to display sentiment one.
*/
icon?: React.ReactNode;
children: React.ReactNode;
}
function getIcon(variant: Props['data-variant']): JSX.Element {
if (variant === 'purple' || variant === 'orange')
return getSentimentIcon('default', 16);
return getSentimentIcon(variant, 16);
}
export const FormBanner = React.forwardRef<
HTMLDivElement,
ComposedProps & React.HTMLAttributes<HTMLDivElement>
>((props, ref) => {
const { icon, children, ...passThrough } = props;
return (
<FormBannerCore {...passThrough} ref={ref}>
<FormBannerIconWrapper>
{icon ?? getIcon(passThrough['data-variant'])}
</FormBannerIconWrapper>
<FormBannerMessage>{children}</FormBannerMessage>
</FormBannerCore>
);
});