Skip to content

Commit

Permalink
added focus events
Browse files Browse the repository at this point in the history
updated inline button styles
  • Loading branch information
dogusata committed Jun 26, 2024
1 parent e383f1a commit 85713c6
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 35 deletions.
12 changes: 11 additions & 1 deletion example/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export const createMynahUI = (initialData?: MynahUIDataModel): MynahUI => {
id: 'multi',
icon: MynahIcons.ELLIPSIS,
items: [
{
id: 'custom-data-check',
text: 'Custom check',
icon: MynahIcons.MAGIC,
},
{
id: 'show-avatars',
text: 'Show/Hide avatars',
Expand Down Expand Up @@ -92,6 +97,9 @@ export const createMynahUI = (initialData?: MynahUIDataModel): MynahUI => {
},
},
},
onFocusStateChanged: (focusState:boolean) => {
Log(`MynahUI focus state changed: <b>${focusState.toString()}</b>`);
},
onTabBarButtonClick: (tabId: string, buttonId: string) => {
if (buttonId === 'clear') {
mynahUI.updateStore(tabId, {
Expand Down Expand Up @@ -122,6 +130,8 @@ export const createMynahUI = (initialData?: MynahUIDataModel): MynahUI => {
Object.keys(mynahUI.getAllTabs()).forEach(tabIdFromStore=>mynahUI.updateStore(tabIdFromStore, {
showChatAvatars: showChatAvatars
}));
} else if (buttonId === 'custom-data-check') {
// Use for custom temporary checks
}
Log(`Tab bar button clicked when tab ${tabId} is selected: <b>${buttonId}</b>`);
},
Expand Down Expand Up @@ -490,7 +500,7 @@ export const createMynahUI = (initialData?: MynahUIDataModel): MynahUI => {
{
id: 'save-comment',
text: 'Send',
status: 'info',
status: 'primary',
waitMandatoryFormItems: true,
},
{
Expand Down
2 changes: 1 addition & 1 deletion example/src/samples/sample-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ _To send the form, mandatory items should be filled._`,
{
id: 'submit',
text: 'Submit',
status: 'info',
status: 'primary',
},
{
id: 'cancel-feedback',
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aws/mynah-ui",
"displayName": "AWS Mynah UI",
"version": "4.14.0",
"version": "4.14.1",
"description": "AWS Toolkit VSCode and Intellij IDE Extension Mynah UI",
"publisher": "Amazon Web Services",
"license": "Apache License 2.0",
Expand Down
3 changes: 2 additions & 1 deletion src/components/chat-item/chat-item-buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class ChatItemButtonsWrapper {
const actionItem = new Button({
label: chatActionAction.text,
icon: chatActionAction.icon != null ? new Icon({ icon: chatActionAction.icon }).render : undefined,
primary: chatActionAction.status !== undefined,
primary: chatActionAction.status === 'primary',
classNames: chatActionAction.status !== undefined ? [ `status-${chatActionAction.status}` ] : [],
onClick: (e) => {
if (props.formItems !== null) {
props.formItems.disableAll();
Expand Down
37 changes: 35 additions & 2 deletions src/helper/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { MynahPortalNames } from '../static';
import { MynahEventNames, MynahPortalNames } from '../static';
import { MynahUIGlobalEvents } from './events';
import { AllowedTagsInCustomRenderer, AllowedAttributesInCustomRenderer } from './sanitize';

/* eslint-disable @typescript-eslint/method-signature-style */
Expand Down Expand Up @@ -72,14 +73,43 @@ export interface ExtendedHTMLElement extends HTMLInputElement {

export class DomBuilder {
private static instance: DomBuilder;
private rootFocus: boolean;
root: ExtendedHTMLElement;
private portals: Record<string, ExtendedHTMLElement> = {};

private constructor (rootSelector: string) {
this.root = DS(rootSelector)[0] as ExtendedHTMLElement;
this.extendDomFunctionality(this.root);
this.rootFocus = this.root.matches(':focus') ?? false;
this.attachRootFocusListeners();
}

private readonly attachRootFocusListeners = (): void => {
this.root?.setAttribute('tabindex', '0');
this.root?.setAttribute('autofocus', 'true');
this.root?.style.setProperty('outline', 'none');
this.root?.addEventListener('focusin', this.onRootFocus, { capture: true });
window.addEventListener('blur', this.onRootBlur);
};

private readonly onRootFocus = (e: FocusEvent): void => {
if (!this.rootFocus) {
this.rootFocus = true;
MynahUIGlobalEvents.getInstance().dispatch(MynahEventNames.ROOT_FOCUS, { focusState: this.rootFocus });
}
};

private readonly onRootBlur = (e: FocusEvent): void => {
if (this.rootFocus) {
this.rootFocus = false;
MynahUIGlobalEvents.getInstance().dispatch(MynahEventNames.ROOT_FOCUS, { focusState: this.rootFocus });
}
};

public readonly setFocusToRoot = (): void => {
this.root?.focus();
};

public static getInstance (rootSelector?: string): DomBuilder {
if (!DomBuilder.instance) {
DomBuilder.instance = new DomBuilder(rootSelector != null ? rootSelector : 'body');
Expand All @@ -91,14 +121,17 @@ export class DomBuilder {
}

setRoot = (rootSelector?: string): void => {
this.root.removeEventListener('focus', this.onRootFocus);
window.removeEventListener('blur', this.onRootBlur);
this.root = this.extendDomFunctionality((DS(rootSelector ?? 'body')[0] ?? document.body) as HTMLElement);
this.attachRootFocusListeners();
};

addClass = function (this: ExtendedHTMLElement, className: string): ExtendedHTMLElement {
if (className !== '') {
this.classList.add(className);
// eslint-disable-next-line @typescript-eslint/prefer-includes
if (this.builderObject.classNames?.indexOf(className) === -1) {
if (this.builderObject?.classNames?.indexOf(className) === -1) {
this.builderObject.classNames = [ ...this.builderObject.classNames, className ];
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export interface MynahUIProps {
messageId: string,
eventId?: string) => void;
onReady?: () => void;
onFocusStateChanged?: (focusState: boolean) => void;
onVote?: (
tabId: string,
messageId: string,
Expand Down Expand Up @@ -534,6 +535,10 @@ export class MynahUI {
}
});

MynahUIGlobalEvents.getInstance().addListener(MynahEventNames.ROOT_FOCUS, (data: {focusState: boolean}) => {
this.props.onFocusStateChanged?.(data.focusState);
});

MynahUIGlobalEvents.getInstance().addListener(MynahEventNames.FILE_CLICK, (data) => {
if (this.props.onFileClick !== undefined) {
this.props.onFileClick(
Expand Down
5 changes: 3 additions & 2 deletions src/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export interface MynahUITabStoreModel {
export enum MynahEventNames {
RESET_STORE = 'resetStore',
FEEDBACK_SET = 'feedbackSet',
ROOT_FOCUS = 'rootFocusStateChange',
CARD_VOTE = 'cardVote',
SOURCE_LINK_CLICK = 'sourceLinkClick',
INFO_LINK_CLICK = 'infoLinkClick',
Expand Down Expand Up @@ -244,7 +245,7 @@ export interface ChatItemAction extends ChatPrompt {
pillText: string;
disabled?: boolean;
description?: string;
status?: 'info' | 'success' | 'warning' | 'error';
status?: 'primary' | 'info' | 'success' | 'warning' | 'error';
icon?: MynahIcons;
}
export interface ChatItemButton {
Expand All @@ -254,7 +255,7 @@ export interface ChatItemButton {
id: string;
disabled?: boolean;
description?: string;
status?: 'info' | 'success' | 'warning' | 'error';
status?: 'primary' | 'info' | 'success' | 'warning' | 'error';
icon?: MynahIcons;
}

Expand Down
54 changes: 30 additions & 24 deletions src/styles/components/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,29 @@ button.mynah-button {
overflow: hidden;
position: relative;
transform: translate3d(0, 0, 0) scale(1.00001);
padding-left: var(--mynah-sizing-3);
padding-right: var(--mynah-sizing-3);
padding-left: var(--mynah-sizing-2);
padding-right: var(--mynah-sizing-2);
gap: var(--mynah-sizing-2);
filter: brightness(0.9);
opacity: 0.85;
filter: brightness(0.925);
opacity: 1;
line-height: var(--mynah-line-height);
margin-top: var(--mynah-border-width);
margin-bottom: var(--mynah-border-width);
&:after {
content: '';
pointer-events: none;
transition: var(--mynah-text-flow-transition);
opacity: 0;
position: absolute;
top: 0;
left: 0;
width: 125%;
height: 100%;
filter: brightness(1.65) saturate(0.65);
opacity: 0;
background-color: currentColor;
transform: translate3d(-100%, 0, 0);
}
&.mynah-bottom-block-close-button {
position: absolute;
align-self: flex-end;
Expand All @@ -33,30 +50,19 @@ button.mynah-button {
pointer-events: none;
}
&.mynah-button-secondary {
background-color: transparent;
color: inherit;
box-shadow: none;
opacity: 0.75;
height: var(--mynah-sizing-6);
padding-left: var(--mynah-sizing-1);
padding-right: var(--mynah-sizing-1);
border-radius: 0;
&:focus-visible,
&:hover {
opacity: 1;
}
&:active {
box-shadow: none;
}
background-color: rgba(0, 0, 0, 0);
color: currentColor;
box-sizing: border-box;
border: var(--mynah-border-width) solid rgba(0,0,0,0);
}
&:active,
&:focus-visible,
&:hover {
filter: brightness(1);
opacity: 1;
}
&:active {
filter: brightness(0.9);
opacity: 0.85;
&:after {
transform: translate3d(0%, 0, 0);
opacity: 0.2;
}
}
&.mynah-icon-button {
width: var(--mynah-sizing-10);
Expand Down
13 changes: 12 additions & 1 deletion src/styles/components/_form-input.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import '../variables';
.mynah-form-input-wrapper {
position: relative;
display: flex;
Expand Down Expand Up @@ -117,7 +118,7 @@
}
&::after {
$edgeSpace: calc(0 * var(--mynah-border-width));
content: "";
content: '';
transition: inherit;
position: absolute;
top: $edgeSpace;
Expand Down Expand Up @@ -193,4 +194,14 @@
padding-bottom: var(--mynah-sizing-1);
justify-content: flex-end;
align-items: center;

> .mynah-button.mynah-button-secondary {
border: var(--mynah-border-width) solid currentColor !important;
@each $status in $mynah-statuses {
&.status-#{$status} {
color: var(--mynah-color-status-#{$status});
border-color: var(--mynah-color-status-#{$status});
}
}
}
}

0 comments on commit 85713c6

Please sign in to comment.