-
Notifications
You must be signed in to change notification settings - Fork 0
feat(alert): new local alert component #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a3a8144
feat(alert): new local alert component
frideska 8e072b0
fix linting
frideska 08cf2ba
fix
frideska d964394
fix
frideska d459b00
fix
frideska 2da679e
fix
frideska 51165d5
fix
frideska bf96af3
build: add lit analyzer to catch errors during build
eTallang 30869f9
fix: missing import of icon component in docs
eTallang 90dffa4
build: make build fail on pr
eTallang 6b57fd3
build: trigger lint script on lint action
eTallang c40d95e
fix(alert): registered icons
frideska 72371a8
Merge remote-tracking branch 'origin' into alert
frideska a4329b6
fix(alert): linting fails
frideska 4a7b930
refactor(icons): size css refactor
frideska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Binary file not shown.
This file contains hidden or 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 hidden or 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,23 @@ | ||
import { Canvas, Meta, Subtitle, Title } from '@storybook/blocks'; | ||
|
||
import * as stories from './alert.stories'; | ||
|
||
<Meta of={stories} /> | ||
|
||
<Title>Alert</Title> | ||
<Subtitle> | ||
Alerts convey information or warnings to the users and should grab their | ||
attention to help make informed actions and decisions. | ||
</Subtitle> | ||
|
||
### Local alert | ||
|
||
This alert should be placed next to the content it is related to and should not be confused with toast (pops up and disappear) or global alerts (static at the top of the entire web-site). They should help the user correct a problem and then disappear once the problem is corrected. | ||
|
||
<Canvas of={stories.AlertInfo} /> | ||
|
||
<Canvas of={stories.AlertDanger} /> | ||
|
||
<Canvas of={stories.AlertWarning} /> | ||
|
||
<Canvas of={stories.AlertSuccess} /> |
This file contains hidden or 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,33 @@ | ||
import type { Meta, StoryObj } from '@storybook/web-components'; | ||
import { html } from 'lit'; | ||
|
||
import './alert'; | ||
|
||
export default { | ||
title: 'Components/Alert', | ||
} satisfies Meta; | ||
|
||
export const AlertInfo: StoryObj = { | ||
render: () => | ||
html` <cx-alert header=${'Info alert'}> | ||
Lorem ipsum dolor sit amet consectetur. Justo orci pellentesque magna quis. Lorem ipsum dolor sit amet consectetur. Justo orci pellentesque magna quis. | ||
</cx-alert>`, | ||
}; | ||
export const AlertDanger: StoryObj = { | ||
render: () => | ||
html` <cx-alert header=${'Danger alert'} priority=${'Danger'}> | ||
Lorem ipsum dolor sit amet consectetur. Justo orci pellentesque magna quis. Lorem ipsum dolor sit amet consectetur. Justo orci pellentesque magna quis. | ||
</cx-alert>`, | ||
}; | ||
export const AlertWarning: StoryObj = { | ||
render: () => | ||
html` <cx-alert header=${'Warning alert'} priority=${'Warning'}> | ||
Lorem ipsum dolor sit amet consectetur. Justo orci pellentesque magna quis. Lorem ipsum dolor sit amet consectetur. Justo orci pellentesque magna quis. | ||
</cx-alert>`, | ||
}; | ||
export const AlertSuccess: StoryObj = { | ||
render: () => | ||
html` <cx-alert header=${'Success alert'} priority=${'Success'}> | ||
Lorem ipsum dolor sit amet consectetur. Justo orci pellentesque magna quis. Lorem ipsum dolor sit amet consectetur. Justo orci pellentesque magna quis. | ||
</cx-alert>`, | ||
}; |
This file contains hidden or 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,107 @@ | ||
import { LitElement, css, html } from 'lit'; | ||
import { customElement, property } from 'lit/decorators.js'; | ||
import { classMap } from 'lit/directives/class-map.js'; | ||
import { addIcons } from '../icon'; | ||
import { type IconName, checkCircle, errorCircle, infoCircle, warning } from '../icon/iconRegistry'; | ||
|
||
addIcons(errorCircle, infoCircle, warning, checkCircle); | ||
|
||
type AlertPriorityType = 'Info' | 'Danger' | 'Warning' | 'Success'; | ||
@customElement('cx-alert') | ||
export class Alert extends LitElement { | ||
static styles = css` | ||
.cx-alert { | ||
padding: var(--cx-spacing-6); | ||
border-radius: var(--cx-radius-medium); | ||
background-color: var(--cx-color-background-accent-5-soft); | ||
border: 1px solid var(--cx-color-signal-info); | ||
display: flex; | ||
flex-direction: row; | ||
align-items: flex-start; | ||
gap: var(--cx-spacing-6); | ||
|
||
color: var(--cx-color-text-primary); | ||
font-family: 'Open Sans', Arial, sans-serif; | ||
|
||
@media only screen and (max-width: 360px) { | ||
flex-direction: column; | ||
align-items: center; | ||
gap: var(--cx-spacing-3); | ||
} | ||
} | ||
.cx-alert--danger { | ||
background-color: var(--cx-color-background-accent-4-soft); | ||
border-color: var(--cx-color-signal-danger); | ||
} | ||
.cx-alert--warning { | ||
background-color: var(--cx-color-background-accent-3-soft); | ||
border-color: var(--cx-color-signal-warning); | ||
} | ||
.cx-alert--success { | ||
background-color: var(--cx-color-background-accent-2-soft); | ||
border-color: var(--cx-color-signal-success); | ||
} | ||
|
||
.cx-alert__content { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0; | ||
} | ||
.cx-alert__header { | ||
font-weight: 600; | ||
font-size: 1.125rem; | ||
line-height: 1.6; | ||
} | ||
.cx-alert__body { | ||
font-weight: 400; | ||
font-size: 1rem; | ||
line-height: 1.6; | ||
} | ||
`; | ||
|
||
@property({ type: String, reflect: true }) header = 'Tab title'; | ||
|
||
@property({ type: String, reflect: true }) priority: AlertPriorityType = 'Info'; | ||
|
||
render() { | ||
let priorityIcon: IconName = 'info-circle'; | ||
switch (this.priority) { | ||
case 'Danger': | ||
priorityIcon = 'error-circle'; | ||
break; | ||
case 'Warning': | ||
priorityIcon = 'warning'; | ||
break; | ||
case 'Success': | ||
priorityIcon = 'check-circle'; | ||
break; | ||
default: | ||
priorityIcon = 'info-circle'; | ||
break; | ||
} | ||
return html` | ||
<div | ||
role="alert" | ||
class=${classMap({ | ||
'cx-alert': true, | ||
'cx-alert--info': this.priority === 'Info', | ||
'cx-alert--danger': this.priority === 'Danger', | ||
'cx-alert--warning': this.priority === 'Warning', | ||
'cx-alert--success': this.priority === 'Success', | ||
})} | ||
> | ||
<cx-icon name=${priorityIcon} size="8"></cx-icon> | ||
<div class="cx-alert__content"> | ||
<div class="cx-alert__header">${this.header}</div> | ||
<slot class="cx-alert__body"></slot> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'cx-alert': Alert; | ||
} | ||
} |
This file contains hidden or 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 @@ | ||
export * from './alert'; |
This file contains hidden or 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,10 @@ | ||
import { createComponent } from '@lit/react'; | ||
import * as React from 'react'; | ||
|
||
import { Alert } from './index'; | ||
|
||
export const CxAlert = createComponent({ | ||
tagName: 'cx-alert', | ||
elementClass: Alert, | ||
react: React, | ||
}); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.