-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Infineon/feature/alert-component
new alert component
- Loading branch information
Showing
6 changed files
with
265 additions
and
2 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
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,108 @@ | ||
@use "../../../node_modules/@infineon/design-system-tokens/dist/tokens"; | ||
|
||
.ifx { | ||
|
||
&__alert-text { | ||
font-size: 16px; | ||
width: 100%; | ||
padding: 12px 0px 12px 12px; | ||
color: tokens.$color-text-black; | ||
&.text-overflow { | ||
word-break:break-all | ||
} | ||
} | ||
|
||
&__alert-icon-wrapper { | ||
position: relative; | ||
min-width: 48px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: tokens.$color-default-500; | ||
|
||
& svg { | ||
stroke: tokens.$color-text-white; | ||
} | ||
} | ||
|
||
&__close-icon-wrapper { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
min-width: 40px; | ||
|
||
& a { | ||
line-height: 0; | ||
|
||
& svg { | ||
stroke: tokens.$color-black; | ||
} | ||
|
||
&:hover svg { | ||
stroke: tokens.$color-default-500; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.alert { | ||
display: flex; | ||
border: 1px solid tokens.$color-default-500; | ||
border-radius: 1px; | ||
max-width: 800px; | ||
} | ||
|
||
.alert-primary, | ||
.alert-secondary, | ||
.alert-danger, | ||
.alert-success, | ||
.alert-warning { | ||
color: tokens.$color-text-black; | ||
background-color: tokens.$color-bg-white; | ||
} | ||
|
||
.alert-primary { | ||
border: 1px solid tokens.$color-default-500; | ||
|
||
& .ifx__alert-icon-wrapper { | ||
background-color: tokens.$color-default-500; | ||
} | ||
} | ||
|
||
.alert-secondary { | ||
border: 1px solid tokens.$color-highlight-500; | ||
|
||
& .ifx__alert-icon-wrapper { | ||
background-color: tokens.$color-highlight-500; | ||
} | ||
} | ||
|
||
.alert-success { | ||
border: 1px solid tokens.$color-success-500; | ||
|
||
& .ifx__alert-icon-wrapper { | ||
background-color: tokens.$color-success-500; | ||
} | ||
} | ||
|
||
.alert-danger { | ||
border: 1px solid tokens.$color-danger-500; | ||
|
||
& .ifx__alert-icon-wrapper { | ||
background-color: tokens.$color-danger-500; | ||
} | ||
} | ||
|
||
.alert-warning { | ||
border: 1px solid tokens.$color-warning-500; | ||
|
||
& .ifx__alert-icon-wrapper { | ||
background-color: tokens.$color-warning-500; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
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,29 @@ | ||
export default { | ||
title: "Components/Alert", | ||
args: { | ||
label: 'Attention! This is an alert message — check it out!', | ||
color: "primary", | ||
icon: true, | ||
iconType: 'c-info-24', | ||
}, | ||
|
||
argTypes: { | ||
color: { | ||
options: ['primary', 'secondary', 'success', 'danger', 'warning'], | ||
control: { type: 'radio' }, | ||
}, | ||
|
||
iconType: { | ||
options: ['c-info-24', 'calendar-24', 'download-24', 'upload-24'], | ||
control: {type: 'select'} | ||
} | ||
|
||
} | ||
}; | ||
|
||
|
||
const DefaultTemplate = (args) => | ||
`<ifx-alert color="${args.color}" icon="${args.icon ? args.iconType : ""}">${args.label}</ifx-alert>`; | ||
|
||
export const Default = DefaultTemplate.bind({}); | ||
|
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,88 @@ | ||
import { Component, Prop, h, State, Element } from '@stencil/core'; | ||
import classNames from 'classnames'; | ||
|
||
@Component({ | ||
tag: 'ifx-alert', | ||
styleUrl: '_alert.scss', | ||
shadow: true, | ||
}) | ||
|
||
export class Card { | ||
@Prop() color: 'primary' | 'secondary' | 'success' | 'danger' | 'warning'; | ||
@Prop() icon: string; | ||
@Prop() overflowing: boolean | ||
@Element() el; | ||
@State() iconsArray: any[] = [<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><title>c info 24</title><g stroke-linecap="round" stroke-width="2" fill="none" stroke="" stroke-linejoin="round"><circle cx="12" cy="12" r="11"></circle><line x1="12" y1="11" x2="12" y2="17" stroke=""></line><circle cx="12" cy="7" r="1" stroke="" fill="#000000"></circle></g></svg>] | ||
|
||
isOverflowing() { | ||
const el = this.el.shadowRoot.querySelector('.ifx__alert-text') | ||
if(el.clientWidth < el.scrollWidth || el.clientHeight < el.scrollHeight) { | ||
el.classList.add('text-overflow') | ||
} else if(el.classList.contains('text-overflow')) { | ||
el.classList.remove('text-overflow') | ||
} | ||
} | ||
|
||
verifyIcons(icon1, icon2) { | ||
if(icon1 === icon2) { | ||
return true; | ||
} else if(icon2?.split(" ").join("") === icon1?.split(" ").join("-")) { | ||
return true | ||
} else if(icon2?.split(" ").join("").toLowerCase() === icon1?.split(" ").join("").toLowerCase()) { | ||
return true | ||
} else { | ||
console.error('Icon name does not exist!') | ||
return false | ||
} | ||
} | ||
|
||
|
||
getIcon() { | ||
const svgIcon = this.iconsArray.find((icons) => { | ||
let titleIndex = icons['$children$'].findIndex((val) => val['$tag$'] === 'title'); | ||
let titleArray = icons['$children$'][titleIndex]['$children$'] | ||
let title = titleArray[0]['$text$'] | ||
const icon = this.verifyIcons(title, this.icon) | ||
return icon | ||
}) | ||
|
||
return svgIcon | ||
} | ||
|
||
|
||
componentDidRender() { | ||
this.isOverflowing() | ||
} | ||
|
||
|
||
render() { | ||
|
||
const iconSVG_close = <svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 16 16"><title>cross 16</title><g stroke-width="1" stroke-linejoin="round" fill="none" stroke="" stroke-linecap="round" class="nc-icon-wrapper"><line x1="13.5" y1="2.5" x2="2.5" y2="13.5" data-cap="butt"></line> <line x1="2.5" y1="2.5" x2="13.5" y2="13.5" data-cap="butt"></line> </g></svg> | ||
|
||
return ( | ||
<div class={this.getClassNames()}> | ||
{this.icon && | ||
<div class="ifx__alert-icon-wrapper"> | ||
{this.getIcon()} | ||
</div>} | ||
<div class="ifx__alert-text"> | ||
<slot /> | ||
</div> | ||
<div class="ifx__close-icon-wrapper"> | ||
<a href="#"> | ||
{iconSVG_close} | ||
</a> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
|
||
getClassNames() { | ||
return classNames( | ||
'alert', | ||
`alert-${this.color}`, | ||
); | ||
} | ||
|
||
} |
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,19 @@ | ||
# ifx-alert | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Properties | ||
|
||
| Property | Attribute | Description | Type | Default | | ||
| ------------- | ------------- | ----------- | ---------------------------------------------------------------- | ----------- | | ||
| `color` | `color` | | `"danger" \| "primary" \| "secondary" \| "success" \| "warning"` | `undefined` | | ||
| `icon` | `icon` | | `string` | `undefined` | | ||
| `overflowing` | `overflowing` | | `boolean` | `undefined` | | ||
|
||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
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