-
Notifications
You must be signed in to change notification settings - Fork 11
[Draft] Add Spright Chat Message Welcome to Chat Component #2891
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
Draft
hellovolcano
wants to merge
4
commits into
main
Choose a base branch
from
users/vgleason/spright-start-slot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions
7
change/@ni-spright-angular-3dd80b72-fa3a-4f62-9749-f852ef6a2b91.json
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,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "Add welcome message for spright chat conversation", | ||
| "packageName": "@ni/spright-angular", | ||
| "email": "5265744+hellovolcano@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@ni-spright-blazor-d588028d-8950-4858-88e6-3fc776f415fa.json
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,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "Add welcome message for spright chat conversation", | ||
| "packageName": "@ni/spright-blazor", | ||
| "email": "5265744+hellovolcano@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@ni-spright-components-8210bc64-3fb5-426c-9a91-82be850e2405.json
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,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "Add welcome message for spright chat conversation", | ||
| "packageName": "@ni/spright-components", | ||
| "email": "5265744+hellovolcano@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@ni-spright-react-0718d981-c3df-4a58-8307-7bd5e895e960.json
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,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "Add welcome message for spright chat conversation", | ||
| "packageName": "@ni/spright-react", | ||
| "email": "5265744+hellovolcano@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
6 changes: 6 additions & 0 deletions
6
packages/angular-workspace/spright-angular/chat/message/welcome/ng-package.json
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,6 @@ | ||
| { | ||
| "$schema": "../../../../../../node_modules/ng-packagr/ng-package.schema.json", | ||
| "lib": { | ||
| "entryFile": "public-api.ts" | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
packages/angular-workspace/spright-angular/chat/message/welcome/public-api.ts
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,2 @@ | ||
| export * from './spright-chat-message-welcome.directive'; | ||
| export * from './spright-chat-message-welcome.module'; |
32 changes: 32 additions & 0 deletions
32
...-workspace/spright-angular/chat/message/welcome/spright-chat-message-welcome.directive.ts
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,32 @@ | ||
| import { Directive, ElementRef, Input, Renderer2 } from '@angular/core'; | ||
| import { type ChatMessageWelcome, chatMessageWelcomeTag } from '@ni/spright-components/dist/esm/chat/message/welcome'; | ||
|
|
||
| export type { ChatMessageWelcome }; | ||
| export { chatMessageWelcomeTag }; | ||
|
|
||
| /** | ||
| * Directive to provide Angular integration for the chat welcome message. | ||
| */ | ||
| @Directive({ | ||
| selector: 'spright-chat-message-welcome', | ||
| standalone: false | ||
| }) | ||
| export class SprightChatMessageWelcomeDirective { | ||
| public get title(): string | undefined { | ||
| return this.elementRef.nativeElement.welcomeTitle; | ||
| } | ||
|
|
||
| @Input() public set title(value: string | undefined) { | ||
| this.renderer.setProperty(this.elementRef.nativeElement, 'welcomeTitle', value); | ||
| } | ||
|
|
||
| public get subtitle(): string | undefined { | ||
| return this.elementRef.nativeElement.subtitle; | ||
| } | ||
|
|
||
| @Input() public set subtitle(value: string | undefined) { | ||
| this.renderer.setProperty(this.elementRef.nativeElement, 'subtitle', value); | ||
| } | ||
|
|
||
| public constructor(private readonly renderer: Renderer2, private readonly elementRef: ElementRef<ChatMessageWelcome>) {} | ||
| } |
16 changes: 16 additions & 0 deletions
16
...lar-workspace/spright-angular/chat/message/welcome/spright-chat-message-welcome.module.ts
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,16 @@ | ||
| import { NgModule } from '@angular/core'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { SprightChatMessageWelcomeDirective } from './spright-chat-message-welcome.directive'; | ||
|
|
||
| import '@ni/spright-components/dist/esm/chat/message/welcome'; | ||
|
|
||
| @NgModule({ | ||
| declarations: [ | ||
| SprightChatMessageWelcomeDirective | ||
| ], | ||
| imports: [CommonModule], | ||
| exports: [ | ||
| SprightChatMessageWelcomeDirective | ||
| ] | ||
| }) | ||
| export class SprightChatMessageWelcomeModule { } |
142 changes: 142 additions & 0 deletions
142
...spright-angular/chat/message/welcome/tests/spright-chat-message-welcome.directive.spec.ts
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,142 @@ | ||
| import { Component, ElementRef, ViewChild } from '@angular/core'; | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { SprightChatMessageWelcomeDirective, type ChatMessageWelcome } from '../spright-chat-message-welcome.directive'; | ||
| import { SprightChatMessageWelcomeModule } from '../spright-chat-message-welcome.module'; | ||
|
|
||
| describe('Spright chat message welcome', () => { | ||
| describe('module', () => { | ||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| imports: [SprightChatMessageWelcomeModule] | ||
| }); | ||
| }); | ||
|
|
||
| it('custom element is defined', () => { | ||
| expect(customElements.get('spright-chat-message-welcome')).not.toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with no values in template', () => { | ||
| @Component({ | ||
| template: ` | ||
| <spright-chat-message-welcome #message>Content</spright-chat-message-welcome> | ||
| `, | ||
| standalone: false | ||
| }) | ||
| class TestHostComponent { | ||
| @ViewChild('message', { read: SprightChatMessageWelcomeDirective }) public directive: SprightChatMessageWelcomeDirective; | ||
| @ViewChild('message', { read: ElementRef }) public elementRef: ElementRef<ChatMessageWelcome>; | ||
| } | ||
|
|
||
| let fixture: ComponentFixture<TestHostComponent>; | ||
| let directive: SprightChatMessageWelcomeDirective; | ||
| let nativeElement: ChatMessageWelcome; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [TestHostComponent], | ||
| imports: [SprightChatMessageWelcomeModule] | ||
| }); | ||
| fixture = TestBed.createComponent(TestHostComponent); | ||
| fixture.detectChanges(); | ||
| directive = fixture.componentInstance.directive; | ||
| nativeElement = fixture.componentInstance.elementRef.nativeElement; | ||
| }); | ||
|
|
||
| it('has expected defaults for title', () => { | ||
| expect(directive.title).toBeUndefined(); | ||
| expect(nativeElement.welcomeTitle).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('has expected defaults for subtitle', () => { | ||
| expect(directive.subtitle).toBeUndefined(); | ||
| expect(nativeElement.subtitle).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with template string values', () => { | ||
| @Component({ | ||
| template: ` | ||
| <spright-chat-message-welcome #message title="Welcome title" subtitle="Welcome subtitle"> | ||
| Content | ||
| </spright-chat-message-welcome>`, | ||
| standalone: false | ||
| }) | ||
| class TestHostComponent { | ||
| @ViewChild('message', { read: SprightChatMessageWelcomeDirective }) public directive: SprightChatMessageWelcomeDirective; | ||
| @ViewChild('message', { read: ElementRef }) public elementRef: ElementRef<ChatMessageWelcome>; | ||
| } | ||
|
|
||
| let fixture: ComponentFixture<TestHostComponent>; | ||
| let directive: SprightChatMessageWelcomeDirective; | ||
| let nativeElement: ChatMessageWelcome; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [TestHostComponent], | ||
| imports: [SprightChatMessageWelcomeModule] | ||
| }); | ||
| fixture = TestBed.createComponent(TestHostComponent); | ||
| fixture.detectChanges(); | ||
| directive = fixture.componentInstance.directive; | ||
| nativeElement = fixture.componentInstance.elementRef.nativeElement; | ||
| }); | ||
|
|
||
| it('will use template string values for title', () => { | ||
| expect(directive.title).toBe('Welcome title'); | ||
| expect(nativeElement.welcomeTitle).toBe('Welcome title'); | ||
| }); | ||
|
|
||
| it('will use template string values for subtitle', () => { | ||
| expect(directive.subtitle).toBe('Welcome subtitle'); | ||
| expect(nativeElement.subtitle).toBe('Welcome subtitle'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with property bound values', () => { | ||
| @Component({ | ||
| template: ` | ||
| <spright-chat-message-welcome #message [title]="title" [subtitle]="subtitle"> | ||
| Content | ||
| </spright-chat-message-welcome>`, | ||
| standalone: false | ||
| }) | ||
| class TestHostComponent { | ||
| @ViewChild('message', { read: SprightChatMessageWelcomeDirective }) public directive: SprightChatMessageWelcomeDirective; | ||
| @ViewChild('message', { read: ElementRef }) public elementRef: ElementRef<ChatMessageWelcome>; | ||
| public title = 'initial title'; | ||
| public subtitle = 'initial subtitle'; | ||
| } | ||
|
|
||
| let fixture: ComponentFixture<TestHostComponent>; | ||
| let directive: SprightChatMessageWelcomeDirective; | ||
| let nativeElement: ChatMessageWelcome; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [TestHostComponent], | ||
| imports: [SprightChatMessageWelcomeModule] | ||
| }); | ||
| fixture = TestBed.createComponent(TestHostComponent); | ||
| fixture.detectChanges(); | ||
| directive = fixture.componentInstance.directive; | ||
| nativeElement = fixture.componentInstance.elementRef.nativeElement; | ||
| }); | ||
|
|
||
| it('can be configured with property binding for title and subtitle', () => { | ||
| expect(directive.title).toBe('initial title'); | ||
| expect(nativeElement.welcomeTitle).toBe('initial title'); | ||
| expect(directive.subtitle).toBe('initial subtitle'); | ||
| expect(nativeElement.subtitle).toBe('initial subtitle'); | ||
|
|
||
| fixture.componentInstance.title = 'updated title'; | ||
| fixture.componentInstance.subtitle = 'updated subtitle'; | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(directive.title).toBe('updated title'); | ||
| expect(nativeElement.welcomeTitle).toBe('updated title'); | ||
| expect(directive.subtitle).toBe('updated subtitle'); | ||
| expect(nativeElement.subtitle).toBe('updated subtitle'); | ||
| }); | ||
| }); | ||
| }); |
7 changes: 7 additions & 0 deletions
7
packages/blazor-workspace/SprightBlazor/Components/SprightChatMessageWelcome.razor
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,7 @@ | ||
| @namespace SprightBlazor | ||
| <spright-chat-message-welcome | ||
| @attributes="AdditionalAttributes" | ||
| title="@Title" | ||
| subtitle="@Subtitle"> | ||
| @ChildContent | ||
| </spright-chat-message-welcome> |
30 changes: 30 additions & 0 deletions
30
packages/blazor-workspace/SprightBlazor/Components/SprightChatMessageWelcome.razor.cs
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,30 @@ | ||
| using Microsoft.AspNetCore.Components; | ||
|
|
||
| namespace SprightBlazor; | ||
|
|
||
| public partial class SprightChatMessageWelcome : ComponentBase | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the primary welcome title text. | ||
| /// </summary> | ||
| [Parameter] | ||
| public string? Title { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the secondary subtitle text. | ||
| /// </summary> | ||
| [Parameter] | ||
| public string? Subtitle { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The child content of the element. | ||
| /// </summary> | ||
| [Parameter] | ||
| public RenderFragment? ChildContent { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Any additional attributes that did not match known properties. | ||
| /// </summary> | ||
| [Parameter(CaptureUnmatchedValues = true)] | ||
| public IDictionary<string, object>? AdditionalAttributes { get; set; } | ||
| } |
52 changes: 52 additions & 0 deletions
52
...zor-workspace/Tests/SprightBlazor.Tests/Unit/Components/SprightChatMessageWelcomeTests.cs
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,52 @@ | ||
| using System; | ||
| using System.Linq.Expressions; | ||
| using Bunit; | ||
| using Xunit; | ||
|
|
||
| namespace SprightBlazor.Tests.Unit.Components; | ||
|
|
||
| /// <summary> | ||
| /// Test for <see cref="SprightChatMessageWelcome"/>. | ||
| /// </summary> | ||
| public class SprightChatMessageWelcomeTests | ||
| { | ||
| [Fact] | ||
| public void SprightChatMessageWelcome_Render_HasChatMessageMarkup() | ||
| { | ||
| var context = new TestContext(); | ||
| context.JSInterop.Mode = JSRuntimeMode.Loose; | ||
| var expectedMarkup = "spright-chat-message-welcome"; | ||
|
|
||
| var component = context.RenderComponent<SprightChatMessageWelcome>(); | ||
|
|
||
| Assert.Contains(expectedMarkup, component.Markup); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SprightChatMessageWelcome_SupportsAdditionalAttributes() | ||
| { | ||
| var context = new TestContext(); | ||
| context.JSInterop.Mode = JSRuntimeMode.Loose; | ||
| var exception = Record.Exception(() => context.RenderComponent<SprightChatMessageWelcome>(ComponentParameter.CreateParameter("class", "foo"))); | ||
| Assert.Null(exception); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("Welcome to Nigel", "title=\"Welcome to Nigel\"")] | ||
| [InlineData("Log in to continue", "subtitle=\"Log in to continue\"")] | ||
| public void SprightChatMessageWelcome_AttributeIsSet(string value, string expectedAttribute) | ||
| { | ||
| var message = expectedAttribute.StartsWith("title", StringComparison.Ordinal) | ||
| ? RenderWithPropertySet(x => x.Title, value) | ||
| : RenderWithPropertySet(x => x.Subtitle, value); | ||
|
|
||
| Assert.Contains(expectedAttribute, message.Markup); | ||
| } | ||
|
|
||
| private IRenderedComponent<SprightChatMessageWelcome> RenderWithPropertySet<TProperty>(Expression<Func<SprightChatMessageWelcome, TProperty>> propertyGetter, TProperty propertyValue) | ||
| { | ||
| var context = new TestContext(); | ||
| context.JSInterop.Mode = JSRuntimeMode.Loose; | ||
| return context.RenderComponent<SprightChatMessageWelcome>(p => p.Add(propertyGetter, propertyValue)); | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
packages/react-workspace/spright-react/src/chat/message/welcome/index.ts
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,4 @@ | ||
| import { ChatMessageWelcome } from '@ni/spright-components/dist/esm/chat/message/welcome'; | ||
| import { wrap } from '../../../utilities/react-wrapper'; | ||
|
|
||
| export const SprightChatMessageWelcome = wrap(ChatMessageWelcome); |
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
44 changes: 44 additions & 0 deletions
44
packages/spright-components/src/chat/message/welcome/index.ts
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,44 @@ | ||
| import { attr } from '@ni/fast-element'; | ||
| import { | ||
| applyMixins, | ||
| DesignSystem, | ||
| FoundationElement, | ||
| StartEnd, | ||
| type FoundationElementDefinition, | ||
| type StartEndOptions | ||
| } from '@ni/fast-foundation'; | ||
| import { styles } from './styles'; | ||
| import { template } from './template'; | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'spright-chat-message-welcome': ChatMessageWelcome; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * SprightChatMessageWelcome configuration options | ||
| * @public | ||
| */ | ||
| export type ChatMessageWelcomeOptions = FoundationElementDefinition & StartEndOptions; | ||
|
|
||
| /** | ||
| * A Spright component for displaying a welcome chat message | ||
| */ | ||
| export class ChatMessageWelcome extends FoundationElement { | ||
| @attr({ attribute: 'title' }) | ||
| public welcomeTitle?: string; | ||
|
|
||
| @attr | ||
| public subtitle?: string; | ||
| } | ||
| applyMixins(ChatMessageWelcome, StartEnd); | ||
|
|
||
| const sprightChatMessageWelcome = ChatMessageWelcome.compose({ | ||
| baseName: 'chat-message-welcome', | ||
| template, | ||
| styles | ||
| }); | ||
|
|
||
| DesignSystem.getOrCreate().withPrefix('spright').register(sprightChatMessageWelcome()); | ||
| export const chatMessageWelcomeTag = 'spright-chat-message-welcome'; | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this isn't called
titlebecause it conflicts with a native element property? I hadn't registered that would be a problem. If that's the case then I think we should move away from that conflict completely and change the attribute name too: we don't want confusion between the native attributes and our own.I guess
welcome-titleis a good enough name for the attribute. We can't copy the banner for precedent because it's able to usetitlesince it's the name of a slot, which doesn't conflict with anything.