Skip to content

Commit

Permalink
Move DropdownController themeOptions to an instance property
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage committed Jan 26, 2024
1 parent bda0c45 commit a89812f
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions client/src/controllers/DropdownController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,7 @@ export const rotateToggleIcon = {
},
};

const themeOptions = {
'dropdown': {
arrow: true,
maxWidth: 350,
placement: 'bottom',
},
'drilldown': {
arrow: false,
maxWidth: 'none',
placement: 'bottom-end',
},
'dropdown-button': {
arrow: false,
maxWidth: 'none',
placement: 'bottom-start',
},
} as const;

type TippyTheme = keyof typeof themeOptions;
type TippyTheme = 'dropdown' | 'drilldown' | 'dropdown-button';

/**
* A Tippy.js tooltip with interactive "dropdown" options.
Expand Down Expand Up @@ -174,14 +156,12 @@ export class DropdownController extends Controller<HTMLElement> {
...(this.hasContentTarget
? { content: this.contentTarget as Content }
: {}),
...themeOptions[this.themeValue],
...this.themeOptions,
trigger: 'click',
interactive: true,
...(this.hasOffsetValue && { offset: this.offsetValue }),
hideOnClick: !this.useCustomHideOnClickAway,
getReferenceClientRect: () => this.reference.getBoundingClientRect(),
theme: this.themeValue,
plugins: this.plugins,
onShow() {
if (hoverTooltipInstance) {
hoverTooltipInstance.disable();
Expand All @@ -199,13 +179,35 @@ export class DropdownController extends Controller<HTMLElement> {
};
}

get useCustomHideOnClickAway() {
// Tippy's default hideOnClick option for "hiding on click away" doesn't
// work well with our datetime libraries. Instead, we use a custom plugin
// to hide the tooltip when clicking outside the dropdown. It's unlikely
// we'll render a datetime picker for themes other than drilldown, so use
// the custom solution for this theme only.
return this.themeValue === 'drilldown';
get themeOptions() {
return (
{
'dropdown': {
arrow: true,
maxWidth: 350,
placement: 'bottom',
plugins: this.plugins,
},
'drilldown': {
arrow: false,
maxWidth: 'none',
placement: 'bottom-end',
// Tippy's default hideOnClick option for "hiding on click away" doesn't
// work well with our datetime libraries. Instead, we use a custom plugin
// to hide the tooltip when clicking outside the dropdown. It's unlikely
// we'll render a datetime picker for themes other than drilldown, so use
// the custom solution for this theme only.
hideOnClick: false,
plugins: this.plugins.concat([this.hideTooltipOnClickAway]),
},
'dropdown-button': {
arrow: false,
maxWidth: 'none',
placement: 'bottom-start',
plugins: this.plugins,
},
} as const
)[this.themeValue];
}

/**
Expand Down Expand Up @@ -264,9 +266,6 @@ export class DropdownController extends Controller<HTMLElement> {
if (this.hideOnClickValue) {
plugins.push(hideTooltipOnClickInside);
}
if (this.useCustomHideOnClickAway) {
plugins.push(this.hideTooltipOnClickAway);
}
return plugins;
}

Expand Down

0 comments on commit a89812f

Please sign in to comment.