Skip to content
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

feat: add custom styling and branding v2 #160

Merged
merged 35 commits into from
Dec 12, 2023

Conversation

anfibiacreativa
Copy link
Member

Purpose

  • ...

Does this introduce a breaking change?

[ ] Yes
[x ] No

Pull Request Type

What kind of change does this Pull Request introduce?

[ ] Bugfix
[ x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

How to Test

  • Get the code
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install

What to Check

This is the custom styling and branding feature.

}

@customElement('chat-avatar')
export class ChatAvatarComponent extends LitElement {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there is nothing in this component that's chat specific, it's a simple linked icon, should we just call it something like that? 'link-icon'. It will make it reusable for any place an clickable icon can be used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. Renamed to 'link-icon'


override render() {
return html`
<a class="chat-avatar__link" title="${this.label}" href="${this.url}" target="_blank" rel="noopener noreferrer">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

styles inside a component are isolated and will not be impacted by outside styling of component. So you dont need a class and can style it using as a 'a' link.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. I did deal so much with specificity over the years I still struggle to target native elements for styling, even inside of shadow DOM. I still do believe it may pose extensibility challenges at that granular, encapsulated level. But for the sake of avoiding premature optimization, I updated.

@@ -61,12 +66,18 @@ export class ChatComponent extends LitElement {
@property({ type: String, attribute: 'data-api-url' })
apiUrl = chatHttpOptions.url;

@property({ type: String, attribute: 'data-custom-branding', converter: (value) => value?.toLowerCase() === 'true' })
isCustomBranding: boolean = globalConfig.IS_CUSTOM_BRANDING;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to be consistent with 'useStream' as 'useCustomBranding'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use is a specific convention of react hooks. In general, booleans are named isX or hasX. I am not convinced about porting framework specific conventions to the rest of the development scope.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant more about the already in use "useStream" property just below in this component and to keep to the same standard here and not about porting react convention. But I think hasCustomBranding actually is much better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'd say hasCustomBranding would make more sense

@@ -41,6 +41,12 @@ export class ChatThreadComponent extends LitElement {
@property({ type: Object })
selectedCitation: Citation | undefined = undefined;

@property({ type: Boolean })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you are not using the branding in the thread this can be removed. Same with the icon below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

color: var(--error-color);
padding: 20px;
padding: var(--d-base);
background: var(--error-color-background);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was missed since hte name for error-color-background changed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I tried to make sure they were all updated but missed this one.

}
}
.chat-history__footer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in the chat-component and not chat-thread-component

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. This was likely a merge glitch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved.

border: 0;
background: none;
cursor: pointer;
text-decoration: underline;
}
@keyframes chatmessageanimation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was moved out of here into their respective components

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

padding: 0;
margin: 0;
}
.subheadline--small {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this I think

padding: 5px 0;
font-size: small;
}
.chat__header {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new wrapper to better handle reusable header.

font-size: var(--font-large);
border: var(--border-thin) solid var(--c-light-gray);
border-radius: var(--radius-large);
padding: var(--d-base);
}
.chat-history__footer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like it's still here, but something is causing an issue for it to render...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not see the issue, maybe it has updated?

isEnabled: boolean;
}

@customElement('chat-stage')
Copy link
Contributor

@shibbas shibbas Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure this needs another component. The reuse for this is pretty small...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it may get extended by customers. I think it doesn't hurt to keep it encapsulated.

});

const [customStyles, setCustomStyles] = useState(() => {
const styleDefaultsLight = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated? the themes folder with default will make them shared instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will review this in the context of refactoring the theming, as part of this PR.

return () => {
window.removeEventListener('storage', handleStorageChange);
};
}, [customStyles, isBrandingEnabled, isDarkTheme, isLoading]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to replicate this in OneShot.tsx? If so, I think it might be better to move all this into it's own context. Ideally themes in React should be passed in as a context provider pattern so that root level themes can be passed in and can be updated like that across all the child components.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will also handle this as part of the theming refactoring, before making this PR ready for review.

@anfibiacreativa anfibiacreativa marked this pull request as ready for review December 7, 2023 19:28
@@ -61,12 +66,18 @@ export class ChatComponent extends LitElement {
@property({ type: String, attribute: 'data-api-url' })
apiUrl = chatHttpOptions.url;

@property({ type: String, attribute: 'data-custom-branding', converter: (value) => value?.toLowerCase() === 'true' })
isCustomBranding: boolean = globalConfig.IS_CUSTOM_BRANDING;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'd say hasCustomBranding would make more sense

@@ -108,6 +119,26 @@ export class ChatComponent extends LitElement {

static override styles = [chatStyle];

override updated(changedProperties: Map<string | number | symbol, unknown>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More food for thoughts: maybe we could skip that part entirely and allow to directly override the CSS variables through CSS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think about it. We can have a follow up to this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a follow up issue, btw.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#160 (comment)

I kind of disagree here, though, because it's a 'isCustomBrandingEnabled' as 'isDarkThemeEnabled'. We can assume that the app 'hasCustomBranding', wether it's on or off, regardless. But this indicates it is enabled when true.

}, [isDarkTheme, isConfigPanelOpen]);

return (
<>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the empty container needed? Since there's already a div container

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps something didn't get pushed? I still see the empty <>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sync didn't happen.

@manekinekko
Copy link
Contributor

LGTM

@anfibiacreativa
Copy link
Member Author

@shibbas @sinedied If there are no additional change requests/blockers I would like to merge asap. Any further enhancements we can deal with in follow-up issues, as this PR is already quite massive.

.chat__header--avatar {
display: flex;
align-items: center;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this no longer is in the thread component no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@shibbas
Copy link
Contributor

shibbas commented Dec 12, 2023

@shibbas @sinedied If there are no additional change requests/blockers I would like to merge asap. Any further enhancements we can deal with in follow-up issues, as this PR is already quite massive.

Yea, no blockers. There are a few things here and there that we can follow up in separate issues.

@anfibiacreativa anfibiacreativa merged commit 703d278 into main Dec 12, 2023
6 checks passed
@anfibiacreativa anfibiacreativa deleted the feat/add-custom-styling-and-branding-v2 branch January 19, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants