Skip to content

Commit

Permalink
fixup! fixup! feat(react-keytips): draft implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mainframev committed Sep 2, 2024
1 parent 129cb22 commit c48aedd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
22 changes: 10 additions & 12 deletions packages/react-keytips/src/components/Keytip/Keytip.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ export type KeytipSlots = {
content: NonNullable<Slot<'div'>>;
};

export type ExecuteKeytipEventHandler<E = PositioningProps['target']> =
EventHandler<
EventData<'keydown', KeyboardEvent> & {
targetElement: E;
}
>;
export type ExecuteKeytipEventHandler<E = HTMLElement> = EventHandler<
EventData<'keydown', KeyboardEvent> & {
targetElement: E;
}
>;

export type ReturnKeytipEventHandler<E = PositioningProps['target']> =
EventHandler<
EventData<'keydown', KeyboardEvent> & {
targetElement: E;
}
>;
export type ReturnKeytipEventHandler<E = HTMLElement> = EventHandler<
EventData<'keydown', KeyboardEvent> & {
targetElement: E;
}
>;

export type OnVisibleChangeData = {
visible: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ const useStyles = makeStyles({
root: {
display: 'none',
boxSizing: 'border-box',
maxWidth: '240px',
maxWidth: '40px',
minWidth: '24px',
textAlign: 'center',
cursor: 'default',
fontFamily: tokens.fontFamilyBase,
fontSize: tokens.fontSizeBase200,
lineHeight: tokens.lineHeightBase200,
overflowWrap: 'break-word',
borderRadius: tokens.borderRadiusMedium,
border: `1px solid ${tokens.colorTransparentStroke}`,
padding: '4px 11px 6px 11px', // '5px 12px 7px 12px' minus the border width '1px'
padding: tokens.spacingHorizontalXS,
backgroundColor: tokens.colorNeutralBackground1,
color: tokens.colorNeutralForeground1,

Expand Down
3 changes: 1 addition & 2 deletions packages/react-keytips/src/hooks/useTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import * as React from 'react';
import { sequencesToID, createNode } from '../utilities';
import { KTP_ROOT_ID } from '../constants';
import { useFluent } from '@fluentui/react-components';
import { PositioningProps } from '@fluentui/react-components';

export type KeytipTreeNode = Pick<
KeytipProps,
'keySequences' | 'onExecute' | 'onReturn' | 'dynamic'
> & {
id: string;
uniqueId: string;
target: PositioningProps['target'];
target: HTMLElement | null;
parent: string;
children: Set<string>;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/react-keytips/src/utilities/createNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const createNode = ({
const node: KeytipTreeNode = {
id,
uniqueId,
target: positioning?.target || null,
target: positioning?.target as HTMLElement,
parent,
children,
keySequences: keySequences.map((key) => key.toLowerCase()),
Expand Down
2 changes: 1 addition & 1 deletion packages/react-keytips/stories/Dynamic.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const DynamicStory = (props: KeytipsProps) => {
}, [currentButton]);

const onExecute: ExecuteKeytipEventHandler = (_, { targetElement }) => {
if (targetElement) targetElement.click();
if (targetElement) targetElement?.click();
};

const firstButton = useKeytipRef({
Expand Down
8 changes: 4 additions & 4 deletions packages/react-keytips/stories/WithTabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const useStyles = makeStyles({
});

const btnExecute: ExecuteKeytipEventHandler = (_, el) => {
el.targetElement.click();
el.targetElement?.click();
};

export const WithTabsStory = (props: KeytipsProps) => {
Expand All @@ -55,15 +55,15 @@ export const WithTabsStory = (props: KeytipsProps) => {

const refFirstTab = useKeytipRef({
keySequences: ['a'],
content: 'A',
hasDynamicChildren: true,
content: 'A23',
dynamic: true,
onExecute: btnExecute,
});

const refSecondTab = useKeytipRef({
keySequences: ['b'],
content: 'B',
hasDynamicChildren: true,
dynamic: true,
onExecute: btnExecute,
});

Expand Down

0 comments on commit c48aedd

Please sign in to comment.