Skip to content

Commit

Permalink
New component: Alert (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavorosolem authored Sep 2, 2021
1 parent 3deff92 commit 089fa2f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
27 changes: 27 additions & 0 deletions styleguide/src/Indicators/Alert/Alert.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from "react"
import { composeStories } from "@storybook/testing-react"
import { mount } from "@cypress/react"
import * as stories from "./Alert.stories"

const { Default } = composeStories(stories)

describe('Alert tests', () => {

it('Default', () => {
const text = 'Example text'
mount(<Default content={text} />)
cy.get('.alert').contains(text)
})

it('Variants', () => {
mount(<Default type="success" />)
cy.get('.alert').should('have.class', 'bg-success-light')

mount(<Default type="warning" />)
cy.get('.alert').should('have.class', 'bg-warning-light')

mount(<Default type="danger" />)
cy.get('.alert').should('have.class', 'bg-danger-light')
})

})
16 changes: 16 additions & 0 deletions styleguide/src/Indicators/Alert/Alert.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import { Story, Meta } from '@storybook/react'

import { Alert, AlertProps } from './Alert'

export default {
title: 'Indicators/Alert',
component: Alert,
args: {
content: 'O dinheiro só irá para a conta no mesmo dia se o saque for feito antes das 15h e em dias úteis (segunda a sexta-feira).',
},
} as Meta

const Template: Story<AlertProps> = args => <Alert {...args} />

export const Default = Template.bind({})
37 changes: 37 additions & 0 deletions styleguide/src/Indicators/Alert/Alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react'

const alertTypes = {
success: 'bg-success-light border-success',
warning: 'bg-warning-light border-warning',
danger: 'bg-danger-light border-danger',
info: 'bg-info-light border-info',
primary: 'bg-primary-light border-primary',
}

const AlertComponent = ({ type = 'info', content }: AlertProps) => {
return (
<div
className={`alert border border-l-4 py-3 pl-5 pr-4 rounded text-f6 tracking-4 leading-5 font-semibold w-full relative flex items-center text-on-base ${alertTypes[type]}`}
>
{content}
</div>
)
}

export const Alert = React.memo(AlertComponent)

export interface AlertProps {
/** Alert color
* @default info
* */
type?: keyof typeof alertTypes
/**
* Alert content
* */
content?: string | React.ReactNode
/**
* Need to implement
* */
// onClose
// icon
}
1 change: 1 addition & 0 deletions styleguide/src/Indicators/Alert/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Alert'
1 change: 1 addition & 0 deletions styleguide/src/Indicators/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './Alert'
export * from './Status'
export * from './Toast'

0 comments on commit 089fa2f

Please sign in to comment.