Skip to content

Commit

Permalink
Ajoute le composant Message au design system
Browse files Browse the repository at this point in the history
fix #2028
  • Loading branch information
johangirod committed Mar 14, 2022
1 parent d023840 commit 59d9304
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 0 deletions.
1 change: 1 addition & 0 deletions site/source/design-system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * as layout from './layout'
export { default as Popover } from './Popover'
export { default as PopoverWithTrigger } from './PopoverWithTrigger'
export * as typography from './typography'
export * from './message'
4 changes: 4 additions & 0 deletions site/source/design-system/message/baseIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions site/source/design-system/message/errorIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions site/source/design-system/message/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { Message } from '@/design-system'

// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
export default {
component: Message,
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
argTypes: {
children: { type: 'string' },
},
} as ComponentMeta<typeof Message>

// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const Template: ComponentStory<typeof Message> = (args) => <Message {...args} />

export const AccompanyingMessage = Template.bind({})
// More on args: https://storybook.js.org/docs/react/writing-stories/args
AccompanyingMessage.args = {
children:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam',
type: 'primary',
icon: true,
border: true,
}

const AlertTemplate: ComponentStory<typeof Message> = (args) => (
<>
<Message {...args} type="success">
Votre message a bien été envoyé
</Message>
<Message {...args} type="info">
Certaines informations sont incorrectes
</Message>
<Message {...args} type="error">
Échec de l’envoi du message
</Message>
</>
)

export const Alert = AlertTemplate.bind({})
Alert.args = {
children: 'Votre message a bien été envoyé',
icon: true,
border: true,
}
91 changes: 91 additions & 0 deletions site/source/design-system/message/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from 'react'
import styled, { css } from 'styled-components'
import baseIcon from './baseIcon.svg'
import infoIcon from './infoIcon.svg'
import errorIcon from './errorIcon.svg'
import successIcon from './successIcon.svg'
import { Body } from '../typography/paragraphs'

type MessageType = 'primary' | 'secondary' | 'info' | 'error' | 'success'
type MessageProps = {
children: React.ReactNode
icon?: boolean
border?: boolean
type: MessageType
light?: boolean
}
export function Message({
type = 'primary',
icon = false,
border = true,
light = false,
children,
}: MessageProps) {
if (typeof children !== 'object') {
children = <Body>{children}</Body>
}
return (
<StyledMessage type={type} border={border} light={light}>
{icon &&
(type === 'success' ? (
<StyledIcon
src={successIcon}
title="succès"
alt="icône signalant une alerte sur un succès"
/>
) : type === 'error' ? (
<StyledIcon
src={errorIcon}
title="error"
alt="icône signalant une alerte sur une erreur"
/>
) : type === 'info' ? (
<StyledIcon
src={infoIcon}
title="info"
alt="icône signalant une alerte sur une information"
/>
) : (
<StyledIcon
src={baseIcon}
title="paragraph"
alt="icône signalant un texte informatif"
/>
))}
<div>{children}</div>
</StyledMessage>
)
}

const StyledMessage = styled.div<
Pick<MessageProps, 'border' | 'type' | 'light'>
>`
display: flex;
align-items: flex-start;
${({ theme, type, border, light }) => {
const colorSpace =
type === 'secondary' || type === 'primary'
? theme.colors.bases[type]
: theme.colors.extended[type]
return css`
padding: ${theme.spacings.xs} ${theme.spacings.lg};
background-color: ${light ? 'rgba(255,255,255,0.75)' : colorSpace[100]};
border: 2px solid ${colorSpace[border ? 500 : 100]};
border-radius: ${theme.box.borderRadius};
margin-bottom: ${theme.spacings.md};
`
}}
`

const StyledIcon = styled.img`
padding-right: ${({ theme }) => theme.spacings.md};
${({ theme, title }) =>
title !== 'paragraph'
? css`
margin-top: calc(${theme.spacings.md} + ${theme.spacings.xxs} / 2);
height: calc(${theme.spacings.md} + ${theme.spacings.xxs});
`
: css`
margin-top: calc(${theme.spacings.lg});
`}
`
5 changes: 5 additions & 0 deletions site/source/design-system/message/infoIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions site/source/design-system/message/successIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 59d9304

Please sign in to comment.