fix @grafana/ui type errors
This commit is contained in:
@@ -763,11 +763,6 @@
|
|||||||
"count": 1
|
"count": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/grafana-ui/src/components/Select/resetSelectStyles.ts": {
|
|
||||||
"@typescript-eslint/no-explicit-any": {
|
|
||||||
"count": 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"packages/grafana-ui/src/components/Select/types.ts": {
|
"packages/grafana-ui/src/components/Select/types.ts": {
|
||||||
"@typescript-eslint/no-explicit-any": {
|
"@typescript-eslint/no-explicit-any": {
|
||||||
"count": 6
|
"count": 6
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { autoUpdate, autoPlacement, size, useFloating } from '@floating-ui/react';
|
import { autoUpdate, autoPlacement, size, useFloating } from '@floating-ui/react';
|
||||||
import { useMemo, useRef, useState } from 'react';
|
import { CSSProperties, type RefObject, useMemo, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { BOUNDARY_ELEMENT_ID } from '../../utils/floating';
|
import { BOUNDARY_ELEMENT_ID } from '../../utils/floating';
|
||||||
import { measureText } from '../../utils/measureText';
|
import { measureText } from '../../utils/measureText';
|
||||||
@@ -21,7 +21,21 @@ const POPOVER_PADDING = 16;
|
|||||||
|
|
||||||
const SCROLL_CONTAINER_PADDING = 8;
|
const SCROLL_CONTAINER_PADDING = 8;
|
||||||
|
|
||||||
export const useComboboxFloat = (items: Array<ComboboxOption<string | number>>, isOpen: boolean) => {
|
interface UseComboboxFloatReturn {
|
||||||
|
inputRef: RefObject<HTMLInputElement | null>;
|
||||||
|
floatingRef: RefObject<HTMLDivElement | null>;
|
||||||
|
scrollRef: RefObject<HTMLDivElement | null>;
|
||||||
|
floatStyles: CSSProperties & {
|
||||||
|
width: number;
|
||||||
|
maxWidth: number;
|
||||||
|
maxHeight: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useComboboxFloat = (
|
||||||
|
items: Array<ComboboxOption<string | number>>,
|
||||||
|
isOpen: boolean
|
||||||
|
): UseComboboxFloatReturn => {
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const floatingRef = useRef<HTMLDivElement>(null);
|
const floatingRef = useRef<HTMLDivElement>(null);
|
||||||
const scrollRef = useRef<HTMLDivElement>(null);
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { CSSObjectWithLabel } from 'react-select';
|
import { StylesConfig } from 'react-select';
|
||||||
|
|
||||||
import { GrafanaTheme2 } from '@grafana/data';
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
|
|
||||||
export default function resetSelectStyles(theme: GrafanaTheme2) {
|
export default function resetSelectStyles(theme: GrafanaTheme2): Partial<StylesConfig> {
|
||||||
return {
|
return {
|
||||||
clearIndicator: () => ({}),
|
clearIndicator: () => ({}),
|
||||||
container: () => ({}),
|
container: () => ({}),
|
||||||
@@ -13,7 +13,7 @@ export default function resetSelectStyles(theme: GrafanaTheme2) {
|
|||||||
groupHeading: () => ({}),
|
groupHeading: () => ({}),
|
||||||
indicatorsContainer: () => ({}),
|
indicatorsContainer: () => ({}),
|
||||||
indicatorSeparator: () => ({}),
|
indicatorSeparator: () => ({}),
|
||||||
input: function (originalStyles: CSSObjectWithLabel) {
|
input: function (originalStyles) {
|
||||||
return {
|
return {
|
||||||
...originalStyles,
|
...originalStyles,
|
||||||
color: 'inherit',
|
color: 'inherit',
|
||||||
@@ -27,7 +27,7 @@ export default function resetSelectStyles(theme: GrafanaTheme2) {
|
|||||||
loadingIndicator: () => ({}),
|
loadingIndicator: () => ({}),
|
||||||
loadingMessage: () => ({}),
|
loadingMessage: () => ({}),
|
||||||
menu: () => ({}),
|
menu: () => ({}),
|
||||||
menuList: ({ maxHeight }: { maxHeight: number }) => ({
|
menuList: ({ maxHeight }) => ({
|
||||||
maxHeight,
|
maxHeight,
|
||||||
}),
|
}),
|
||||||
multiValue: () => ({}),
|
multiValue: () => ({}),
|
||||||
@@ -38,7 +38,7 @@ export default function resetSelectStyles(theme: GrafanaTheme2) {
|
|||||||
multiValueRemove: () => ({}),
|
multiValueRemove: () => ({}),
|
||||||
noOptionsMessage: () => ({}),
|
noOptionsMessage: () => ({}),
|
||||||
option: () => ({}),
|
option: () => ({}),
|
||||||
placeholder: (originalStyles: CSSObjectWithLabel) => ({
|
placeholder: (originalStyles) => ({
|
||||||
...originalStyles,
|
...originalStyles,
|
||||||
color: theme.colors.text.secondary,
|
color: theme.colors.text.secondary,
|
||||||
}),
|
}),
|
||||||
@@ -47,11 +47,11 @@ export default function resetSelectStyles(theme: GrafanaTheme2) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useCustomSelectStyles(theme: GrafanaTheme2, width: number | string | undefined) {
|
export function useCustomSelectStyles(theme: GrafanaTheme2, width: number | string | undefined): Partial<StylesConfig> {
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
return {
|
return {
|
||||||
...resetSelectStyles(theme),
|
...resetSelectStyles(theme),
|
||||||
menuPortal: (base: CSSObjectWithLabel) => {
|
menuPortal: (base) => {
|
||||||
// Would like to correct top position when menu is placed bottom, but have props are not sent to this style function.
|
// Would like to correct top position when menu is placed bottom, but have props are not sent to this style function.
|
||||||
// Only state is. https://github.com/JedWatson/react-select/blob/master/packages/react-select/src/components/Menu.tsx#L605
|
// Only state is. https://github.com/JedWatson/react-select/blob/master/packages/react-select/src/components/Menu.tsx#L605
|
||||||
return {
|
return {
|
||||||
@@ -60,7 +60,7 @@ export function useCustomSelectStyles(theme: GrafanaTheme2, width: number | stri
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
//These are required for the menu positioning to function
|
//These are required for the menu positioning to function
|
||||||
menu: ({ top, bottom, position }: CSSObjectWithLabel) => {
|
menu: ({ top, bottom, position }) => {
|
||||||
return {
|
return {
|
||||||
top,
|
top,
|
||||||
bottom,
|
bottom,
|
||||||
@@ -73,7 +73,7 @@ export function useCustomSelectStyles(theme: GrafanaTheme2, width: number | stri
|
|||||||
width: width ? theme.spacing(width) : '100%',
|
width: width ? theme.spacing(width) : '100%',
|
||||||
display: width === 'auto' ? 'inline-flex' : 'flex',
|
display: width === 'auto' ? 'inline-flex' : 'flex',
|
||||||
}),
|
}),
|
||||||
option: (provided: CSSObjectWithLabel, state: any) => ({
|
option: (provided, state) => ({
|
||||||
...provided,
|
...provided,
|
||||||
opacity: state.isDisabled ? 0.5 : 1,
|
opacity: state.isDisabled ? 0.5 : 1,
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user