mirror of https://github.com/buster-so/buster.git
updated popovers
This commit is contained in:
parent
0bd385799f
commit
2f7289fe85
|
@ -1,4 +1,4 @@
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Select as SelectBase,
|
Select as SelectBase,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
|
@ -24,7 +24,7 @@ export interface SelectItem<T = string> {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectProps<T = string> {
|
export interface SelectProps<T> {
|
||||||
items: SelectItem<T>[] | SelectItemGroup[];
|
items: SelectItem<T>[] | SelectItemGroup[];
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
onChange: (value: T) => void;
|
onChange: (value: T) => void;
|
||||||
|
@ -36,7 +36,7 @@ export interface SelectProps<T = string> {
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const _Select = <T,>({
|
const _Select = <T extends string>({
|
||||||
items,
|
items,
|
||||||
showIndex,
|
showIndex,
|
||||||
disabled,
|
disabled,
|
||||||
|
@ -68,7 +68,7 @@ const _Select = <T,>({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
_Select.displayName = 'Select';
|
_Select.displayName = 'Select';
|
||||||
export const Select = React.memo(_Select) as typeof _Select;
|
export const Select = _Select;
|
||||||
|
|
||||||
const SelectItemSelector = <T,>({
|
const SelectItemSelector = <T,>({
|
||||||
item,
|
item,
|
||||||
|
@ -113,3 +113,26 @@ SelectItemSelector.displayName = 'SelectItemSelector';
|
||||||
const SelectItemSecondaryText: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
const SelectItemSecondaryText: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||||
return <span className="text-gray-light text2xs">{children}</span>;
|
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);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import { IBusterMetricChartConfig } from '@/api/asset_interfaces';
|
import type { IBusterMetricChartConfig } from '@/api/asset_interfaces';
|
||||||
import { isNumericColumnStyle, isNumericColumnType } from '@/lib/messages';
|
import { isNumericColumnStyle, isNumericColumnType } from '@/lib/messages';
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { LabelAndInput } from '../../Common';
|
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 { DEFAULT_COLUMN_SETTINGS } from '@/api/asset_interfaces';
|
||||||
import { useMemoizedFn } from 'ahooks';
|
import { useMemoizedFn } from 'ahooks';
|
||||||
import { createColumnFieldOptions } from './helpers';
|
import { createColumnFieldOptions } from './helpers';
|
||||||
import { AppMaterialIcons, AppPopover } from '@/components/ui';
|
import { Popover } from '@/components/ui/tooltip/Popover';
|
||||||
import { SelectAxisDropdownContent } from '../SelectAxis/SelectAxisColumnContent';
|
import { SelectAxisDropdownContent } from '../SelectAxis/SelectAxisColumnContent';
|
||||||
import { ChartType, DerivedMetricTitle } from '@/components/ui/charts';
|
import { ChartType, DerivedMetricTitle } from '@/components/ui/charts';
|
||||||
import { SelectAxisContainerId } from '../SelectAxis/config';
|
import { SelectAxisContainerId } from '../SelectAxis/config';
|
||||||
|
import { Dots } from '@/components/ui/icons';
|
||||||
|
|
||||||
export const EditMetricField: React.FC<{
|
export const EditMetricField: React.FC<{
|
||||||
label?: string;
|
label?: string;
|
||||||
|
@ -61,9 +63,8 @@ export const EditMetricField: React.FC<{
|
||||||
<LabelAndInput label={label}>
|
<LabelAndInput label={label}>
|
||||||
<div className="flex items-center justify-between space-x-1.5 overflow-hidden">
|
<div className="flex items-center justify-between space-x-1.5 overflow-hidden">
|
||||||
<Select
|
<Select
|
||||||
options={columnFieldOptions}
|
items={columnFieldOptions}
|
||||||
className="w-full overflow-hidden"
|
className="w-full overflow-hidden"
|
||||||
popupMatchSelectWidth={false}
|
|
||||||
value={selectedOption}
|
value={selectedOption}
|
||||||
onChange={onChangeOption}
|
onChange={onChangeOption}
|
||||||
/>
|
/>
|
||||||
|
@ -87,9 +88,7 @@ const StylingPopover: React.FC<{
|
||||||
rowCount: number;
|
rowCount: number;
|
||||||
}> = ({ metricColumnId, columnLabelFormat, rowCount }) => {
|
}> = ({ metricColumnId, columnLabelFormat, rowCount }) => {
|
||||||
return (
|
return (
|
||||||
<AppPopover
|
<Popover
|
||||||
trigger="click"
|
|
||||||
destroyTooltipOnHide
|
|
||||||
content={
|
content={
|
||||||
<div className="w-full max-w-[315px] min-w-[315px]">
|
<div className="w-full max-w-[315px] min-w-[315px]">
|
||||||
<SelectAxisDropdownContent
|
<SelectAxisDropdownContent
|
||||||
|
@ -107,8 +106,9 @@ const StylingPopover: React.FC<{
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
placement="leftBottom">
|
align="end"
|
||||||
<Button type="text" icon={<AppMaterialIcons icon="more_horiz" />} />
|
side="left">
|
||||||
</AppPopover>
|
<Button variant="ghost" prefix={<Dots />} />
|
||||||
|
</Popover>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,8 +7,8 @@ export const createColumnFieldOptions = (
|
||||||
columnMetadata: ColumnMetaData[],
|
columnMetadata: ColumnMetaData[],
|
||||||
columnLabelFormats: IBusterMetricChartConfig['columnLabelFormats'],
|
columnLabelFormats: IBusterMetricChartConfig['columnLabelFormats'],
|
||||||
iconClass: string
|
iconClass: string
|
||||||
): SelectItem[] => {
|
): SelectItem<string>[] => {
|
||||||
return columnMetadata.map<SelectItem>((column) => {
|
return columnMetadata.map<SelectItem<string>>((column) => {
|
||||||
const labelFormat = columnLabelFormats[column.name];
|
const labelFormat = columnLabelFormats[column.name];
|
||||||
const formattedLabel = formatLabel(column.name, labelFormat, true);
|
const formattedLabel = formatLabel(column.name, labelFormat, true);
|
||||||
const Icon = ColumnTypeIcon[labelFormat.style];
|
const Icon = ColumnTypeIcon[labelFormat.style];
|
||||||
|
|
|
@ -3,9 +3,8 @@ import { createStyles } from 'antd-style';
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { AnimatePresence, motion } from 'framer-motion';
|
import { AnimatePresence, motion } from 'framer-motion';
|
||||||
import { useMemoizedFn } from 'ahooks';
|
import { useMemoizedFn } from 'ahooks';
|
||||||
import { AppPopover } from '@/components/ui';
|
|
||||||
import { PopoverProps } from 'antd';
|
|
||||||
import { isOpenableFile, SelectedFile, useChatLayoutContextSelector } from '@layouts/ChatLayout';
|
import { isOpenableFile, SelectedFile, useChatLayoutContextSelector } from '@layouts/ChatLayout';
|
||||||
|
import { Popover } from '@/components/ui/tooltip/Popover';
|
||||||
|
|
||||||
const duration = 0.25;
|
const duration = 0.25;
|
||||||
|
|
||||||
|
@ -103,7 +102,6 @@ const Pill: React.FC<{
|
||||||
|
|
||||||
Pill.displayName = 'Pill';
|
Pill.displayName = 'Pill';
|
||||||
|
|
||||||
const memoizedTrigger: PopoverProps['trigger'] = ['click'];
|
|
||||||
const OverflowPill = React.memo(
|
const OverflowPill = React.memo(
|
||||||
({
|
({
|
||||||
hiddenPills,
|
hiddenPills,
|
||||||
|
@ -117,7 +115,7 @@ const OverflowPill = React.memo(
|
||||||
const count = hiddenPills.length;
|
const count = hiddenPills.length;
|
||||||
|
|
||||||
const content = (
|
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) => (
|
{hiddenPills.map((pill) => (
|
||||||
<Pill key={pill.id} useAnimation={useAnimation} {...pill} onClick={undefined} />
|
<Pill key={pill.id} useAnimation={useAnimation} {...pill} onClick={undefined} />
|
||||||
))}
|
))}
|
||||||
|
@ -125,11 +123,11 @@ const OverflowPill = React.memo(
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppPopover destroyTooltipOnHide content={content} trigger={memoizedTrigger}>
|
<Popover size={'sm'} content={content}>
|
||||||
<div>
|
<div>
|
||||||
<Pill className="cursor-pointer" useAnimation={useAnimation} text={`+${count} more`} />
|
<Pill className="cursor-pointer" useAnimation={useAnimation} text={`+${count} more`} />
|
||||||
</div>
|
</div>
|
||||||
</AppPopover>
|
</Popover>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue