-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b479374
commit 5f802f9
Showing
9 changed files
with
256 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { css } from '../utils'; | ||
|
||
export const element = 'div'; | ||
export const className = 'form-banner'; | ||
|
||
const variants = [ | ||
'success', | ||
'info', | ||
'error', | ||
'warning', | ||
'neutral', | ||
'purple', | ||
'orange' | ||
] as const; | ||
|
||
export type FormBannerVariant = (typeof variants)[number]; | ||
|
||
export interface Props { | ||
'data-variant': FormBannerVariant; | ||
} | ||
|
||
export const fullStyles = css` | ||
display: flex; | ||
gap: var(--spacing-l2); | ||
color: var(--neutral-text); | ||
background: var(--neutral-surface); | ||
border-radius: var(--border-radius-small); | ||
padding: var(--spacing-l4) var(--spacing-l3); | ||
align-items: flex-start; | ||
width: 100%; | ||
&[data-variant='error'] { | ||
color: var(--error-text); | ||
background: var(--error-surface); | ||
} | ||
&[data-variant='warning'] { | ||
color: var(--warning-text); | ||
background: var(--warning-surface); | ||
} | ||
&[data-variant='success'] { | ||
color: var(--success-text); | ||
background: var(--success-surface); | ||
} | ||
&[data-variant='info'] { | ||
color: var(--info-text); | ||
background: var(--info-surface); | ||
} | ||
&[data-variant='purple'] { | ||
color: var(--purple-text); | ||
background: var(--purple-surface); | ||
} | ||
&[data-variant='orange'] { | ||
color: var(--orange-text); | ||
background: var(--orange-surface); | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type { formBanner } from '@tablecheck/tablekit-core'; | ||
import * as React from 'react'; | ||
|
||
import { getSentimentIcon } from '../config'; | ||
|
||
export type Props = formBanner.Props; | ||
|
||
export const FormBannerCore = React.forwardRef< | ||
HTMLDivElement, | ||
Props & React.HTMLAttributes<HTMLDivElement> | ||
>((props, ref) => ( | ||
<div | ||
{...props} | ||
ref={ref} | ||
className={`${props.className || ''} form-banner`} | ||
/> | ||
)); | ||
|
||
export const FormBannerMessage = React.forwardRef< | ||
HTMLDivElement, | ||
React.HTMLAttributes<HTMLDivElement> | ||
>((props, ref) => ( | ||
<div | ||
{...props} | ||
ref={ref} | ||
style={{ ...(props.style || {}), 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; | ||
} | ||
|
||
export const FormBanner = React.forwardRef< | ||
HTMLDivElement, | ||
ComposedProps & React.HTMLAttributes<HTMLDivElement> | ||
>((props, ref) => { | ||
const { icon, title, children, ...passThrough } = props; | ||
return ( | ||
<FormBannerCore {...passThrough} ref={ref}> | ||
<FormBannerIconWrapper> | ||
{icon ?? getSentimentIcon(passThrough['data-variant'])} | ||
</FormBannerIconWrapper> | ||
<FormBannerMessage>{children}</FormBannerMessage> | ||
</FormBannerCore> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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; | ||
} | ||
|
||
export const FormBanner = React.forwardRef< | ||
HTMLDivElement, | ||
ComposedProps & React.HTMLAttributes<HTMLDivElement> | ||
>((props, ref) => { | ||
const { icon, children, ...passThrough } = props; | ||
return ( | ||
<FormBannerCore {...passThrough} ref={ref}> | ||
<FormBannerIconWrapper> | ||
{icon ?? getSentimentIcon(passThrough['data-variant'])} | ||
</FormBannerIconWrapper> | ||
<FormBannerMessage>{children}</FormBannerMessage> | ||
</FormBannerCore> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Meta, StoryFn } from '@storybook/react'; | ||
import { formBanner } from '@tablecheck/tablekit-core'; | ||
import * as emotion from '@tablecheck/tablekit-react'; | ||
import * as css from '@tablecheck/tablekit-react-css'; | ||
import * as React from 'react'; | ||
|
||
const contentVariants: emotion.FormBannerProps['data-variant'][] = [ | ||
'success', | ||
'info', | ||
'error', | ||
'warning', | ||
'neutral', | ||
'purple', | ||
'orange' | ||
]; | ||
|
||
type LayoutComponents = Record<'FormBanner', React.ElementType>; | ||
|
||
export default { | ||
title: 'Components/FormBanner', | ||
component: emotion.FormBanner, | ||
parameters: { | ||
...formBanner, | ||
variants: contentVariants, | ||
auxiliaryComponents: [ | ||
emotion.FormBannerIconWrapper, | ||
emotion.FormBannerMessage | ||
] | ||
} | ||
} as Meta; | ||
|
||
const Template: StoryFn = ({ FormBanner }) => ( | ||
<> | ||
{contentVariants.map((variant) => ( | ||
<FormBanner key={variant} data-variant={variant}> | ||
Important message to explain a form or a section of a form. | ||
</FormBanner> | ||
))} | ||
</> | ||
); | ||
|
||
export const Emotion: StoryFn = Template.bind({}); | ||
Emotion.args = { | ||
FormBanner: emotion.FormBanner | ||
} satisfies LayoutComponents; | ||
Emotion.parameters = { useEmotion: true }; | ||
|
||
export const Class: StoryFn = Template.bind({}); | ||
Class.args = { | ||
FormBanner: css.FormBanner | ||
} satisfies LayoutComponents; | ||
Class.parameters = { useEmotion: false }; |