-
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.
# Pull Request ## π€¨ Rationale See #305 ## π©βπ» Implementation - Created new banner component (not based on FAST) - Added unit tests and visual Storybook tests - Updated README ## π§ͺ Testing Unit tests and Storybook testing ## β Checklist - [x] I have updated the project documentation to reflect my changes or determined no changes are needed. --------- Co-authored-by: mollykreis <20542556+mollykreis@users.noreply.github.com>
- Loading branch information
1 parent
28a5610
commit 0248f3d
Showing
15 changed files
with
792 additions
and
6 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
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-components-9ab8666d-2f01-435f-9a9d-44ca9f141412.json
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,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Banner component", | ||
"packageName": "@ni/nimble-components", | ||
"email": "7282195+m-akinc@users.noreply.github.com", | ||
"dependentChangeType": "patch" | ||
} |
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,87 @@ | ||
import { attr } from '@microsoft/fast-element'; | ||
import { | ||
applyMixins, | ||
ARIAGlobalStatesAndProperties, | ||
DesignSystem, | ||
FoundationElement | ||
} from '@microsoft/fast-foundation'; | ||
import { styles } from './styles'; | ||
import { template } from './template'; | ||
import { BannerSeverity } from './types'; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'nimble-banner': Banner; | ||
} | ||
} | ||
|
||
/** | ||
* A nimble-styled notification banner for persistent messages. | ||
*/ | ||
export class Banner extends FoundationElement { | ||
/** | ||
* @public | ||
* @description | ||
* Whether the banner is visible or not | ||
*/ | ||
@attr({ mode: 'boolean' }) | ||
public open = false; | ||
|
||
/** | ||
* @public | ||
* @description | ||
* Severity of the banner's message | ||
*/ | ||
@attr() | ||
public severity: BannerSeverity = BannerSeverity.default; | ||
|
||
/** | ||
* @public | ||
* @description | ||
* Whether the banner title is hidden | ||
*/ | ||
@attr({ attribute: 'title-hidden', mode: 'boolean' }) | ||
public titleHidden = false; | ||
|
||
/** | ||
* @public | ||
* @description | ||
* Hides the dismiss button | ||
*/ | ||
@attr({ attribute: 'prevent-dismiss', mode: 'boolean' }) | ||
public preventDismiss = false; | ||
|
||
/** | ||
* @public | ||
* @description | ||
* Label (not visible) for the dismiss button | ||
*/ | ||
@attr({ attribute: 'dismiss-button-label' }) | ||
public dismissButtonLabel?: string; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public openChanged(): void { | ||
this.$emit('toggle', { oldState: !this.open, newState: this.open }); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public dismissBanner(): void { | ||
this.open = false; | ||
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface Banner extends ARIAGlobalStatesAndProperties {} | ||
applyMixins(Banner, ARIAGlobalStatesAndProperties); | ||
|
||
const nimbleBanner = Banner.compose({ | ||
baseName: 'banner', | ||
template, | ||
styles | ||
}); | ||
|
||
DesignSystem.getOrCreate().withPrefix('nimble').register(nimbleBanner()); |
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,213 @@ | ||
import { css } from '@microsoft/fast-element'; | ||
import { display } from '@microsoft/fast-foundation'; | ||
import { | ||
BannerFail100DarkUi, | ||
Black75, | ||
Fail100LightUi, | ||
Information100DarkUi, | ||
Information100LightUi, | ||
Warning100DarkUi, | ||
Warning100LightUi, | ||
White | ||
} from '@ni/nimble-tokens/dist/styledictionary/js/tokens'; | ||
|
||
import { | ||
actionRgbPartialColor, | ||
applicationBackgroundColor, | ||
bodyFont, | ||
borderHoverColor, | ||
buttonLabelFontColor, | ||
controlHeight, | ||
controlSlimHeight, | ||
fillSelectedColor, | ||
iconColor, | ||
iconSize, | ||
linkActiveFontColor, | ||
linkDisabledFontColor, | ||
linkFontColor, | ||
standardPadding | ||
} from '../theme-provider/design-tokens'; | ||
import { Theme } from '../theme-provider/types'; | ||
import { hexToRgbaCssColor } from '../utilities/style/colors'; | ||
import { themeBehavior } from '../utilities/style/theme'; | ||
|
||
export const styles = css` | ||
${display('flex')} | ||
:host { | ||
font: ${bodyFont}; | ||
font-size: 12.8px; | ||
align-items: top; | ||
overflow: hidden; | ||
color: ${White}; | ||
${iconColor.cssCustomProperty}: ${hexToRgbaCssColor(White, 0.6)}; | ||
} | ||
:host(:not([open])) { | ||
display: none; | ||
} | ||
.container { | ||
display: flex; | ||
width: 100%; | ||
} | ||
.icon { | ||
width: 48px; | ||
display: flex; | ||
justify-content: center; | ||
margin-top: 8px; | ||
flex: 0 0 auto; | ||
} | ||
.text { | ||
display: inline; | ||
margin-top: 7px; | ||
margin-bottom: 7px; | ||
} | ||
slot[name='title'] { | ||
display: inline; | ||
font-weight: bold; | ||
padding-right: 8px; | ||
white-space: nowrap; | ||
} | ||
:host([title-hidden]) slot[name='title'] { | ||
${ | ||
/** | ||
* Hide content visually while keeping it screen reader-accessible. | ||
* Source: https://webaim.org/techniques/css/invisiblecontent/#techniques | ||
* See discussion here: https://github.com/microsoft/fast/issues/5740#issuecomment-1068195035 | ||
*/ | ||
'' | ||
} | ||
display: inline-block; | ||
height: 1px; | ||
width: 1px; | ||
position: absolute; | ||
margin: -1px; | ||
clip: rect(1px, 1px, 1px, 1px); | ||
clip-path: inset(50%); | ||
overflow: hidden; | ||
padding: 0; | ||
} | ||
.controls { | ||
height: ${controlHeight}; | ||
margin-left: auto; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
align-self: flex-start; | ||
} | ||
slot[name='action'] { | ||
display: flex; | ||
align-content: center; | ||
margin-left: ${standardPadding}; | ||
white-space: nowrap; | ||
} | ||
slot[name='action']::slotted(nimble-anchor) { | ||
${linkFontColor.cssCustomProperty}: ${White}; | ||
${linkDisabledFontColor.cssCustomProperty}: ${White}; | ||
${linkActiveFontColor.cssCustomProperty}: ${hexToRgbaCssColor( | ||
White, | ||
0.6 | ||
)}; | ||
font-size: 12.8px; | ||
} | ||
slot[name='action']::slotted(nimble-button) { | ||
${controlHeight.cssCustomProperty}: ${controlSlimHeight}; | ||
${buttonLabelFontColor.cssCustomProperty}: ${White}; | ||
${fillSelectedColor.cssCustomProperty}: ${hexToRgbaCssColor( | ||
White, | ||
0.2 | ||
)}; | ||
${borderHoverColor.cssCustomProperty}: ${White}; | ||
} | ||
slot[name='action']::slotted(nimble-button[appearance='outline']) { | ||
${actionRgbPartialColor.cssCustomProperty}: ${White} | ||
} | ||
.dismiss { | ||
width: 48px; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
.dismiss nimble-button { | ||
${controlHeight.cssCustomProperty}: 16px; | ||
${iconSize.cssCustomProperty}: 14px; | ||
${buttonLabelFontColor.cssCustomProperty}: ${White}; | ||
${borderHoverColor.cssCustomProperty}: transparent; | ||
${fillSelectedColor.cssCustomProperty}: ${hexToRgbaCssColor( | ||
White, | ||
0.2 | ||
)}; | ||
} | ||
.dismiss nimble-button:focus-within { | ||
outline: 2px solid ${White}; | ||
} | ||
.dismiss nimble-button:hover { | ||
background: ${hexToRgbaCssColor(White, 0.2)}; | ||
} | ||
`.withBehaviors( | ||
themeBehavior( | ||
Theme.light, | ||
css` | ||
:host { | ||
background: ${Black75}; | ||
} | ||
:host([severity='error']) { | ||
background: ${Fail100LightUi}; | ||
} | ||
:host([severity='warning']) { | ||
background: ${Warning100LightUi}; | ||
} | ||
:host([severity='information']) { | ||
background: ${Information100LightUi}; | ||
} | ||
` | ||
), | ||
themeBehavior( | ||
Theme.dark, | ||
css` | ||
:host { | ||
background: ${Black75}; | ||
} | ||
:host([severity='error']) { | ||
background: ${BannerFail100DarkUi}; | ||
} | ||
:host([severity='warning']) { | ||
background: ${Warning100DarkUi}; | ||
} | ||
:host([severity='information']) { | ||
background: ${Information100DarkUi}; | ||
} | ||
` | ||
), | ||
themeBehavior( | ||
Theme.color, | ||
css` | ||
:host { | ||
background: ${applicationBackgroundColor}; | ||
} | ||
.container { | ||
background: ${hexToRgbaCssColor(White, 0.3)}; | ||
} | ||
` | ||
) | ||
); |
Oops, something went wrong.