updated popovers

This commit is contained in:
Nate Kelley 2025-03-03 23:20:46 -07:00
parent 0bd385799f
commit 2f7289fe85
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 44 additions and 23 deletions

View File

@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import {
Select as SelectBase,
SelectContent,
@ -24,7 +24,7 @@ export interface SelectItem<T = string> {
disabled?: boolean;
}
export interface SelectProps<T = string> {
export interface SelectProps<T> {
items: SelectItem<T>[] | SelectItemGroup[];
disabled?: boolean;
onChange: (value: T) => void;
@ -36,7 +36,7 @@ export interface SelectProps<T = string> {
className?: string;
}
const _Select = <T,>({
const _Select = <T extends string>({
items,
showIndex,
disabled,
@ -68,7 +68,7 @@ const _Select = <T,>({
);
};
_Select.displayName = 'Select';
export const Select = React.memo(_Select) as typeof _Select;
export const Select = _Select;
const SelectItemSelector = <T,>({
item,
@ -113,3 +113,26 @@ SelectItemSelector.displayName = 'SelectItemSelector';
const SelectItemSecondaryText: React.FC<{ children: React.ReactNode }> = ({ children }) => {
return <span className="text-gray-light text2xs">{children}</span>;
};
const ExampleUsage = () => {
const [value, setValue] = useState<string>('');
const values: SelectItem<'1' | '2'>[] = [
{
value: '1',
label: '1'
},
{
value: '2',
label: '2'
}
];
return (
<Select
items={values}
onChange={(v) => {
console.log(v);
}}
/>
);
};

View File

@ -1,15 +1,17 @@
import { IBusterMetricChartConfig } from '@/api/asset_interfaces';
import type { IBusterMetricChartConfig } from '@/api/asset_interfaces';
import { isNumericColumnStyle, isNumericColumnType } from '@/lib/messages';
import React, { useMemo } from 'react';
import { LabelAndInput } from '../../Common';
import { Button, Select } from 'antd';
import { Select } from '@/components/ui/select';
import { Button } from '@/components/ui/buttons';
import { DEFAULT_COLUMN_SETTINGS } from '@/api/asset_interfaces';
import { useMemoizedFn } from 'ahooks';
import { createColumnFieldOptions } from './helpers';
import { AppMaterialIcons, AppPopover } from '@/components/ui';
import { Popover } from '@/components/ui/tooltip/Popover';
import { SelectAxisDropdownContent } from '../SelectAxis/SelectAxisColumnContent';
import { ChartType, DerivedMetricTitle } from '@/components/ui/charts';
import { SelectAxisContainerId } from '../SelectAxis/config';
import { Dots } from '@/components/ui/icons';
export const EditMetricField: React.FC<{
label?: string;
@ -61,9 +63,8 @@ export const EditMetricField: React.FC<{
<LabelAndInput label={label}>
<div className="flex items-center justify-between space-x-1.5 overflow-hidden">
<Select
options={columnFieldOptions}
items={columnFieldOptions}
className="w-full overflow-hidden"
popupMatchSelectWidth={false}
value={selectedOption}
onChange={onChangeOption}
/>
@ -87,9 +88,7 @@ const StylingPopover: React.FC<{
rowCount: number;
}> = ({ metricColumnId, columnLabelFormat, rowCount }) => {
return (
<AppPopover
trigger="click"
destroyTooltipOnHide
<Popover
content={
<div className="w-full max-w-[315px] min-w-[315px]">
<SelectAxisDropdownContent
@ -107,8 +106,9 @@ const StylingPopover: React.FC<{
/>
</div>
}
placement="leftBottom">
<Button type="text" icon={<AppMaterialIcons icon="more_horiz" />} />
</AppPopover>
align="end"
side="left">
<Button variant="ghost" prefix={<Dots />} />
</Popover>
);
};

View File

@ -7,8 +7,8 @@ export const createColumnFieldOptions = (
columnMetadata: ColumnMetaData[],
columnLabelFormats: IBusterMetricChartConfig['columnLabelFormats'],
iconClass: string
): SelectItem[] => {
return columnMetadata.map<SelectItem>((column) => {
): SelectItem<string>[] => {
return columnMetadata.map<SelectItem<string>>((column) => {
const labelFormat = columnLabelFormats[column.name];
const formattedLabel = formatLabel(column.name, labelFormat, true);
const Icon = ColumnTypeIcon[labelFormat.style];

View File

@ -3,9 +3,8 @@ import { createStyles } from 'antd-style';
import React, { useMemo } from 'react';
import { AnimatePresence, motion } from 'framer-motion';
import { useMemoizedFn } from 'ahooks';
import { AppPopover } from '@/components/ui';
import { PopoverProps } from 'antd';
import { isOpenableFile, SelectedFile, useChatLayoutContextSelector } from '@layouts/ChatLayout';
import { Popover } from '@/components/ui/tooltip/Popover';
const duration = 0.25;
@ -103,7 +102,6 @@ const Pill: React.FC<{
Pill.displayName = 'Pill';
const memoizedTrigger: PopoverProps['trigger'] = ['click'];
const OverflowPill = React.memo(
({
hiddenPills,
@ -117,7 +115,7 @@ const OverflowPill = React.memo(
const count = hiddenPills.length;
const content = (
<div className="flex max-w-[400px] flex-wrap gap-1 p-1.5">
<div className="flex max-w-[400px] flex-wrap gap-1">
{hiddenPills.map((pill) => (
<Pill key={pill.id} useAnimation={useAnimation} {...pill} onClick={undefined} />
))}
@ -125,11 +123,11 @@ const OverflowPill = React.memo(
);
return (
<AppPopover destroyTooltipOnHide content={content} trigger={memoizedTrigger}>
<Popover size={'sm'} content={content}>
<div>
<Pill className="cursor-pointer" useAnimation={useAnimation} text={`+${count} more`} />
</div>
</AppPopover>
</Popover>
);
}
);