Skip to content

Commit

Permalink
Feature/tooltip (#132)
Browse files Browse the repository at this point in the history
* Added tooltipcontext property

* Updated strings

* feat:icon tooltip

Co-authored-by: Denise Moran <43950360+denisem-msft@users.noreply.github.com>
  • Loading branch information
Ramakrishnan24689 and denise-msft authored Dec 2, 2022
1 parent 95c2999 commit 149875e
Show file tree
Hide file tree
Showing 12 changed files with 10,223 additions and 6,724 deletions.
9 changes: 9 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ExpandedNodes": [
"",
"\\Icon",
"\\Icon\\Icon"
],
"SelectedNode": "\\Icon\\Icon\\IconComponent.tsx",
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Empty file.
Binary file added .vs/powercat-code-components/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
8 changes: 8 additions & 0 deletions Icon/Icon/ContextExtended.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This is undocumented - but needed since canvas apps sets non-zero tabindexes
// so we must use the tabindex provided by the context for accessibility purposes
export interface ContextEx {
accessibility: {
assignedTabIndex: number;
assignedTooltip?: string;
};
}
36 changes: 20 additions & 16 deletions Icon/Icon/IconComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IPartialTheme,
mergeStyles,
ThemeProvider,
TooltipHost,
} from '@fluentui/react';
import { useAsync } from '@fluentui/react-hooks';

Expand All @@ -18,6 +19,7 @@ export interface IconComponentProps {
height?: number;
iconName?: string;
text?: string;
tooltipContent?: string;
onSelected: () => void;
disabled?: boolean;
tabIndex?: number;
Expand Down Expand Up @@ -46,7 +48,7 @@ export enum IconRenderType {
}

export const IconComponent = React.memo((props: IconComponentProps) => {
const { text, disabled, onSelected, tabIndex, ariaLabel, setFocus, themeJSON, renderType } = props;
const { text, tooltipContent, disabled, onSelected, tabIndex, ariaLabel, setFocus, themeJSON, renderType } = props;
const theme = React.useMemo(() => {
try {
return themeJSON ? createTheme(JSON.parse(themeJSON) as IPartialTheme) : undefined;
Expand All @@ -71,21 +73,23 @@ export const IconComponent = React.memo((props: IconComponentProps) => {

return (
<ThemeProvider applyTo="none" theme={theme} className={getIconContainerStyle(props)}>
{renderType === IconRenderType.Icon && (
<FontIcon aria-label={props.ariaLabel} className={getIconClass(props)} iconName={props.iconName} />
)}
{renderType !== IconRenderType.Icon && (
<RenderButtonAs
componentRef={componentRef}
styles={getButtonStyles(props)}
iconProps={getIconProps(props)}
ariaLabel={ariaLabel}
disabled={disabled}
text={text}
onClick={onSelected}
tabIndex={tabIndex}
/>
)}
<TooltipHost content={tooltipContent}>
{renderType === IconRenderType.Icon && (
<FontIcon aria-label={props.ariaLabel} className={getIconClass(props)} iconName={props.iconName} />
)}
{renderType !== IconRenderType.Icon && (
<RenderButtonAs
componentRef={componentRef}
styles={getButtonStyles(props)}
iconProps={getIconProps(props)}
ariaLabel={ariaLabel}
disabled={disabled}
text={text}
onClick={onSelected}
tabIndex={tabIndex}
/>
)}
</TooltipHost>
</ThemeProvider>
);
});
Expand Down
2 changes: 2 additions & 0 deletions Icon/Icon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Icon implements ComponentFramework.ReactControl<IInputs, IOutputs>
const allocatedWidth = parseInt(context.mode.allocatedWidth as unknown as string);
const allocatedHeight = parseInt(context.mode.allocatedHeight as unknown as string);
const tabIndex = (context as unknown as ContextEx).accessibility?.assignedTabIndex ?? undefined;
const tooltipContent = (context as unknown as ContextEx).accessibility?.assignedTooltip ?? '';
const inputEvent = context.parameters.InputEvent.raw;
const eventChanged = inputEvent && this.inputEvent !== inputEvent;

Expand All @@ -44,6 +45,7 @@ export class Icon implements ComponentFramework.ReactControl<IInputs, IOutputs>
onSelected: this.onSelect,
iconName: defaultIfEmpty(context.parameters.IconName, 'emoji2'),
text: defaultIfEmpty(context.parameters.Text, ''),
tooltipContent: tooltipContent,
justify: TextAlignmentTypes[context.parameters.TextAlignment.raw],
renderType: RenderTypes[context.parameters.IconType.raw],
iconColor: undefinedIfEmpty(context.parameters.IconColor),
Expand Down
4 changes: 4 additions & 0 deletions Icon/Icon/strings/Icon.1033.resx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
<value>Text</value>
<comment/>
</data>
<data name="TooltipContext" xml:space="preserve">
<value>Text</value>
<comment/>
</data>
<data name="TextAlignment" xml:space="preserve">
<value>Text alignment</value>
<comment/>
Expand Down
Loading

0 comments on commit 149875e

Please sign in to comment.