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(tooltip): add keyboard shortcuts to tooltip #4161

Merged
merged 53 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6c1c489
feat(keyboard-key): component init
krisantrobus Oct 30, 2024
e8304e6
chore(tools): plopfile syntax fix
krisantrobus Oct 30, 2024
461015e
chore(tools): plopfile syntax fix
krisantrobus Oct 30, 2024
8edd0b4
chore(tools): plopfile syntax fix
krisantrobus Oct 30, 2024
693ea4a
feat(keyboard-key): styled w/ hook unit tests
krisantrobus Oct 30, 2024
ca523ac
feat(keyboard-key): added variants and styles
krisantrobus Nov 1, 2024
325c87d
chore(plop): update tsx dependency
krisantrobus Nov 1, 2024
18d09d2
chore(keyboard-key): internal exports in core
krisantrobus Nov 1, 2024
3394496
chore(keyboard-key): typedocs & build
krisantrobus Nov 1, 2024
c7617df
feat(keyboard-key): change to infline-flex style
krisantrobus Nov 1, 2024
b13cde4
chore(keyboard-key): added stroy
krisantrobus Nov 1, 2024
87ab0ff
chore(keyboard-key): linting
krisantrobus Nov 1, 2024
c29afac
fix(keyboard-key): command logic
krisantrobus Nov 4, 2024
d910c26
feat(design-tokens): added new box shadows to support keyboard-keys
krisantrobus Nov 4, 2024
4504056
chore(ci-cd): added chagesets
krisantrobus Nov 4, 2024
6775b36
fix(keyboard-key): boxShadow stylings
krisantrobus Nov 4, 2024
3cc0dff
fix(keyboard-key): remove null component wrapper
krisantrobus Nov 4, 2024
a9b5931
fix(keyboard-key): aria-hidden
krisantrobus Nov 4, 2024
bff42f7
chore(keyboard-key): refactor
krisantrobus Nov 4, 2024
2994e0f
chore(keyboard-key): code cleanup
krisantrobus Nov 4, 2024
720407e
Merge branch 'main' of github.com:twilio-labs/paste into create-keybo…
krisantrobus Nov 4, 2024
a9032d3
chore(keyboard-key): code cleanup
krisantrobus Nov 4, 2024
f0cb7ec
chore(keyboard-key): typedocs
krisantrobus Nov 4, 2024
5c3a833
chore(keyboard-key): fix tests
krisantrobus Nov 4, 2024
196a028
fix(keyboard-key): aria and diableBrowserShortcuts
krisantrobus Nov 5, 2024
1ff559c
fix(keyboard-key): props fix
krisantrobus Nov 5, 2024
59b0d43
chore(keyboard-key): playgorund storybook
krisantrobus Nov 5, 2024
a835ef0
chore(keyboard-key): formatting fix
krisantrobus Nov 5, 2024
528b13b
chore(keyboard-key): stories update
krisantrobus Nov 5, 2024
4fbce7b
chore(keyboard-key): formatting fix
krisantrobus Nov 5, 2024
c1714fb
chore(keyboard-key): typo
krisantrobus Nov 5, 2024
acdf2d0
Update .changeset/sweet-mugs-admire.md
krisantrobus Nov 6, 2024
e3d5827
Update .changeset/shaggy-sheep-confess.md
krisantrobus Nov 6, 2024
781d0b0
chore(keyboard-key): address PR comments
krisantrobus Nov 6, 2024
8ec377e
Merge branch 'create-keyboard-key' of github.com:twilio-labs/paste in…
krisantrobus Nov 6, 2024
5ade11a
feat(keyboard-tooltip): wip
krisantrobus Nov 6, 2024
774095c
chore(tooltip): update types
krisantrobus Nov 8, 2024
be97d29
chore(tooltip): update types
krisantrobus Nov 8, 2024
77b102e
Merge branch 'main' of github.com:twilio-labs/paste into add-keyboard…
krisantrobus Nov 14, 2024
4f693d2
chore(tooltip): better var naming
krisantrobus Nov 14, 2024
c5c4d62
chore(tooltip): fail safe check
krisantrobus Nov 14, 2024
c6fdc17
chore(tooltip): linting
krisantrobus Nov 14, 2024
7c9e275
chore(tooltip): linting
krisantrobus Nov 14, 2024
c5cab1e
chore(tooltip): yarn lock
krisantrobus Nov 14, 2024
4691ce4
chore(tooltip): changeset
krisantrobus Nov 14, 2024
f1bee12
chore(tooltip): fix spelling
krisantrobus Nov 14, 2024
278e997
chore(tooltip): uppdate type name
krisantrobus Nov 14, 2024
345af0f
feat(tooltip): add anonymous keybaord action to tooltip
krisantrobus Nov 15, 2024
529aa0d
Update packages/paste-core/components/tooltip/src/Tooltip.tsx
krisantrobus Nov 18, 2024
30e7f4e
fix(tooltip): update keyboardkey styles
krisantrobus Nov 18, 2024
ec8bbd6
chore(tooltip): formatting
krisantrobus Nov 18, 2024
636c909
Update packages/paste-core/components/tooltip/src/Tooltip.tsx
krisantrobus Nov 19, 2024
9ccfcd6
Merge branch 'main' into add-keyboard-keys-to-tooltip
kodiakhq[bot] Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/happy-panthers-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/tooltip": minor
"@twilio-paste/core": minor
---

[Tooltip] added the ability to put keyboard combinations using the KeyboardKey in the tooltip
2 changes: 2 additions & 0 deletions packages/paste-core/components/code-block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@twilio-paste/flex": "^8.0.0",
"@twilio-paste/heading": "^11.0.0",
"@twilio-paste/icons": "^12.0.0",
"@twilio-paste/keyboard-key": "^0.0.0",
krisantrobus marked this conversation as resolved.
Show resolved Hide resolved
"@twilio-paste/reakit-library": "^2.0.0",
"@twilio-paste/screen-reader-only": "^13.0.0",
"@twilio-paste/spinner": "^14.0.0",
Expand Down Expand Up @@ -68,6 +69,7 @@
"@twilio-paste/flex": "^8.1.0",
"@twilio-paste/heading": "^11.1.0",
"@twilio-paste/icons": "^12.2.0",
"@twilio-paste/keyboard-key": "^0.0.0",
"@twilio-paste/reakit-library": "^2.1.1",
"@twilio-paste/screen-reader-only": "^13.1.0",
"@twilio-paste/spinner": "^14.1.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/paste-core/components/tooltip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
"@twilio-paste/customization": "^8.0.0",
"@twilio-paste/design-tokens": "^10.0.0",
"@twilio-paste/icons": "^12.0.0",
"@twilio-paste/keyboard-key": "^0.0.0",
"@twilio-paste/reakit-library": "^2.0.0",
"@twilio-paste/spinner": "^14.0.0",
"@twilio-paste/stack": "^8.1.0",
"@twilio-paste/style-props": "^9.0.0",
"@twilio-paste/styling-library": "^3.0.0",
"@twilio-paste/text": "^10.0.0",
Expand All @@ -52,8 +54,10 @@
"@twilio-paste/customization": "^8.1.0",
"@twilio-paste/design-tokens": "^10.2.0",
"@twilio-paste/icons": "^12.2.0",
"@twilio-paste/keyboard-key": "^0.0.0",
"@twilio-paste/reakit-library": "^2.1.0",
"@twilio-paste/spinner": "^14.1.0",
"@twilio-paste/stack": "^8.1.0",
"@twilio-paste/style-props": "^9.1.0",
"@twilio-paste/styling-library": "^3.0.0",
"@twilio-paste/text": "^10.1.0",
Expand Down
97 changes: 84 additions & 13 deletions packages/paste-core/components/tooltip/src/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Box, safelySpreadBoxProps } from "@twilio-paste/box";
import type { BoxProps } from "@twilio-paste/box";
import { KeyboardKey, KeyboardKeyGroup } from "@twilio-paste/keyboard-key";
import { Stack } from "@twilio-paste/stack";
import { Text } from "@twilio-paste/text";
import { StyledBase } from "@twilio-paste/theme";
import { TooltipPrimitive, TooltipPrimitiveReference, useTooltipPrimitiveState } from "@twilio-paste/tooltip-primitive";
Expand Down Expand Up @@ -60,42 +62,111 @@ export interface TooltipProps extends TooltipPrimitiveInitialState {
* @memberof TooltipProps
*/
text: string;
actionHeader?: never;
keyCombinationsActions?: never;
}

interface KeyboardActions {
name: string;
eventKeyCombination: string[];
disabled?: boolean;
}

export interface KeyboardKeyTooltipProps
extends Omit<TooltipProps, "text" | "keyCombinationsActions" | "actionHeader"> {
text?: never;
/**
* The mapping of action names to their respective key combinations.
*
* @type {Array<KeyboardActions>}
* @memberof KeyboardKeyTooltipProps
*/
keyCombinationsActions: Array<KeyboardActions>;
/**
* The header content of the Tooltip.
*
* @type {string}
* @memberof KeyboardKeyTooltipProps
*/
actionHeader?: string;
}

// Union will stop users from adding types from both TooltipProps and KeyboardKeyTooltipProps at the same time.
export type TooltipVariantProps = TooltipProps | KeyboardKeyTooltipProps;

/*
*Tooltip's current structure does not allow for customization of its arrow.
*TODO: refactor Tooltip so that the styling of its arrow can be customized
*using Customization Provider.
*/

const Tooltip = React.forwardRef<HTMLDivElement, TooltipProps>(
({ baseId, children, element = "TOOLTIP", state, text, ...props }, ref) => {
const Tooltip = React.forwardRef<HTMLDivElement, TooltipVariantProps>(
({ baseId, children, element = "TOOLTIP", state, text, actionHeader, keyCombinationsActions, ...props }, ref) => {
const tooltip = state || useTooltipPrimitiveState({ baseId: `paste-tooltip-${useUID()}`, ...props });

return (
<>
{React.Children.only(
<TooltipPrimitiveReference {...tooltip} ref={ref} {...children.props}>
{(referenceProps) => React.cloneElement(children, referenceProps)}
</TooltipPrimitiveReference>,
</TooltipPrimitiveReference>
)}
<TooltipPrimitive element={element} {...tooltip} {...props} as={StyledTooltip}>
{/* import Paste Theme Based Styles due to portal positioning. */}
<StyledBase>
<TooltipArrow {...tooltip} />
<Text
element={`${element}_TEXT`}
as="span"
color="colorTextInverse"
fontSize="fontSize20"
lineHeight="lineHeight10"
>
{text}
</Text>
{text && !keyCombinationsActions && (
<Text
element={`${element}_TEXT`}
as="span"
color="colorTextInverse"
fontSize="fontSize20"
lineHeight="lineHeight10"
>
{text}
</Text>
)}
{keyCombinationsActions && (
krisantrobus marked this conversation as resolved.
Show resolved Hide resolved
<Stack orientation="vertical" spacing="space30">
krisantrobus marked this conversation as resolved.
Show resolved Hide resolved
{actionHeader && (
<Text element={`${element}_HEADER`} fontWeight="fontWeightSemibold" as="p" color="colorTextInverse">
{actionHeader}
krisantrobus marked this conversation as resolved.
Show resolved Hide resolved
</Text>
)}
{keyCombinationsActions.map((action, idx) => (
<Box display="flex" key={`action-${idx}`} justifyContent="space-between">
{action.name && (
<Text
element={`${element}_ACTION_TEXT`}
as="span"
color="colorTextInverse"
fontSize="fontSize20"
lineHeight="lineHeight10"
marginRight="space70"
>
{action.name}
</Text>
)}
<KeyboardKeyGroup
variant="inverse"
element={`${element}_ACTION_KEY_GROUP`}
disabled={action.disabled}
>
{action.eventKeyCombination.map((key, i) => (
<KeyboardKey key={`key-${idx}-${i}`} element={`${element}_ACTION_KEY`}>
{key}
</KeyboardKey>
krisantrobus marked this conversation as resolved.
Show resolved Hide resolved
))}
</KeyboardKeyGroup>
</Box>
))}
</Stack>
)}
</StyledBase>
</TooltipPrimitive>
</>
);
},
}
);

Tooltip.displayName = "Tooltip";
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/tooltip/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { TooltipStateReturn } from "./Tooltip";
export { Tooltip, useTooltipState } from "./Tooltip";
export type {
TooltipProps,
TooltipVariantProps,
KeyboardKeyTooltipProps,
TooltipStateReturn,
UseTooltipInitialStateProps,
} from "./Tooltip";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import type { StoryFn } from "@storybook/react";
import { Anchor } from "@twilio-paste/anchor";
import { Box } from "@twilio-paste/box";
import { Button } from "@twilio-paste/button";
import { CustomizationProvider } from "@twilio-paste/customization";
import { InformationIcon } from "@twilio-paste/icons/esm/InformationIcon";
import { Stack } from "@twilio-paste/stack";
import { Text } from "@twilio-paste/text";
import { Theme, useTheme } from "@twilio-paste/theme";
import * as React from "react";

import { Tooltip, useTooltipState } from "../src";

// eslint-disable-next-line import/no-default-export
export default {
title: "Components/Tooltip/KeyboardKey",
excludeStories: ["StateHookExample"],
component: Tooltip,
parameters: {
chromatic: { delay: 3000, diffThreshold: 0.2 },
},
};

export const Default = (): React.ReactNode => {
return (
<Box as="div" minHeight="400px">
<Tooltip
visible
actionHeader="Search shortcuts"
keyCombinationsActions={[
{ name: "Mac", eventKeyCombination: ["Command", "K"] },
{ name: "Windows", eventKeyCombination: ["Control", "K"] },
]}
>
<Button aria-keyshortcuts="command+k" variant="primary">
Click to search
</Button>
</Tooltip>
</Box>
);
};

export const CustomizedTooltip: StoryFn = (_args, { parameters: { isTestEnvironment } }) => {
const currentTheme = useTheme();
return (
<CustomizationProvider
disableAnimations={isTestEnvironment}
theme={currentTheme}
elements={{
TOOLTIP: {
backgroundColor: "colorBackgroundErrorWeakest",
borderColor: "colorBorderDestructive",
textAlign: "center",
},
TOOLTIP_ACTION_TEXT: {
color: "colorTextErrorStrong",
},
TOOLTIP_HEADER: {
color: "colorTextLinkDestructive",
fontWeight: "fontWeightBold",
},
TOOLTIP_ACTION_KEY_GROUP: {
backgroundColor: "colorBackgroundStrong",
padding: "space30",
},
TOOLTIP_ACTION_KEY: {
backgroundColor: "colorBackgroundPrimary",
color: "colorTextInverse",
},
CUSTOM_TOOLTIP: {
backgroundColor: "colorBackgroundSuccessWeakest",
borderColor: "colorBorderSuccess",
textAlign: "left",
},
CUSTOM_TOOLTIP_ACTION_TEXT: {
color: "colorTextSuccess",
},
CUSTOM_TOOLTIP_HEADER: {
color: "colorTextLinkStrongest",
fontWeight: "fontWeightLight",
},
CUSTOM_TOOLTIP_ACTION_KEY_GROUP: {
backgroundColor: "colorBackgroundInverse",
padding: "space30",
},
CUSTOM_TOOLTIP_ACTION_KEY: {
backgroundColor: "colorBackgroundBusy",
color: "colorTextInverse",
fontFamily: "fontFamilyCode",
},
}}
>
<Box as="div" display="flex" columnGap="space80">
<Box minWidth="200px">
<Tooltip
visible
actionHeader="Search shortcuts"
keyCombinationsActions={[
{ name: "Mac", eventKeyCombination: ["Command", "K"] },
{ name: "Windows", eventKeyCombination: ["Control", "K"] },
]}
>
<Button aria-keyshortcuts="command+k" variant="primary">
Click to search
</Button>
</Tooltip>
</Box>
<Box minWidth="600px">
<Tooltip
element="CUSTOM_TOOLTIP"
visible
actionHeader="Search shortcuts"
keyCombinationsActions={[
{ name: "Mac", eventKeyCombination: ["Command", "K"] },
{ name: "Windows", eventKeyCombination: ["Control", "K"] },
]}
>
<Button aria-keyshortcuts="command+k" variant="primary">
Click to search
</Button>
</Tooltip>
</Box>
</Box>
</CustomizationProvider>
);
};

CustomizedTooltip.storyName = "Customized Tooltip";
CustomizedTooltip.parameters = {
parameters: {
chromatic: { disableSnapshot: true },
},
a11y: {
// no need to a11y check customization
disable: true,
},
};
Loading
Loading