mirror of https://github.com/buster-so/buster.git
update
This commit is contained in:
parent
4ccd54f3af
commit
001c1aa894
|
@ -0,0 +1,122 @@
|
||||||
|
import type { Meta, StoryObj } from '@storybook/react';
|
||||||
|
import { BusterListSelectedOptionPopupContainer } from './BusterListSelectedOptionPopupContainer';
|
||||||
|
import React from 'react';
|
||||||
|
import { AppMaterialIcons } from '@/components/ui';
|
||||||
|
import { cn } from '@/lib/classMerge';
|
||||||
|
|
||||||
|
const meta: Meta<typeof BusterListSelectedOptionPopupContainer> = {
|
||||||
|
title: 'UI/List/ListSelectedOptionPopup',
|
||||||
|
component: BusterListSelectedOptionPopupContainer,
|
||||||
|
tags: ['autodocs'],
|
||||||
|
parameters: {
|
||||||
|
layout: 'centered'
|
||||||
|
},
|
||||||
|
argTypes: {
|
||||||
|
selectedRowKeys: { control: 'object' },
|
||||||
|
onSelectChange: { action: 'onSelectChange' },
|
||||||
|
buttons: { control: 'object' },
|
||||||
|
show: { control: 'boolean' }
|
||||||
|
},
|
||||||
|
decorators: [
|
||||||
|
(Story) => (
|
||||||
|
<div className="bg-background relative h-[200px] w-full min-w-[500px]">
|
||||||
|
<Story />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
export default meta;
|
||||||
|
|
||||||
|
type Story = StoryObj<typeof BusterListSelectedOptionPopupContainer>;
|
||||||
|
|
||||||
|
// Sample data
|
||||||
|
const sampleSelectedRowKeys = ['1', '2', '3'];
|
||||||
|
|
||||||
|
// Custom button component for the stories
|
||||||
|
const CustomButton: React.FC<{
|
||||||
|
icon: 'delete' | 'edit' | 'add' | 'visibility';
|
||||||
|
label: string;
|
||||||
|
onClick: () => void;
|
||||||
|
}> = ({ icon, label, onClick }) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
onClick={onClick}
|
||||||
|
className={cn(
|
||||||
|
'flex cursor-pointer items-center space-x-1 px-2 py-0.5',
|
||||||
|
'bg-bg-container rounded-md',
|
||||||
|
'border-border-default border border-dashed',
|
||||||
|
'text-text-secondary hover:text-text-default transition-colors duration-200'
|
||||||
|
)}>
|
||||||
|
<AppMaterialIcons icon={icon} />
|
||||||
|
<span>{label}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Default: Story = {
|
||||||
|
args: {
|
||||||
|
selectedRowKeys: sampleSelectedRowKeys,
|
||||||
|
onSelectChange: (keys) => console.log('Selection changed:', keys),
|
||||||
|
show: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WithButtons: Story = {
|
||||||
|
args: {
|
||||||
|
selectedRowKeys: sampleSelectedRowKeys,
|
||||||
|
onSelectChange: (keys) => console.log('Selection changed:', keys),
|
||||||
|
buttons: [
|
||||||
|
<CustomButton
|
||||||
|
key="delete"
|
||||||
|
icon="delete"
|
||||||
|
label="Delete"
|
||||||
|
onClick={() => alert('Delete clicked')}
|
||||||
|
/>,
|
||||||
|
<CustomButton key="edit" icon="edit" label="Edit" onClick={() => alert('Edit clicked')} />
|
||||||
|
],
|
||||||
|
show: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Hidden: Story = {
|
||||||
|
args: {
|
||||||
|
selectedRowKeys: [],
|
||||||
|
onSelectChange: (keys) => console.log('Selection changed:', keys),
|
||||||
|
show: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ForceShow: Story = {
|
||||||
|
args: {
|
||||||
|
selectedRowKeys: [],
|
||||||
|
onSelectChange: (keys) => console.log('Selection changed:', keys),
|
||||||
|
buttons: [
|
||||||
|
<CustomButton key="add" icon="add" label="Add" onClick={() => alert('Add clicked')} />
|
||||||
|
],
|
||||||
|
show: true
|
||||||
|
},
|
||||||
|
name: 'Force Show (Even With Empty Selection)'
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SingleSelection: Story = {
|
||||||
|
args: {
|
||||||
|
selectedRowKeys: ['1'],
|
||||||
|
onSelectChange: (keys) => console.log('Selection changed:', keys),
|
||||||
|
buttons: [
|
||||||
|
<CustomButton
|
||||||
|
key="view"
|
||||||
|
icon="visibility"
|
||||||
|
label="View"
|
||||||
|
onClick={() => alert('View clicked')}
|
||||||
|
/>,
|
||||||
|
<CustomButton
|
||||||
|
key="delete"
|
||||||
|
icon="delete"
|
||||||
|
label="Delete"
|
||||||
|
onClick={() => alert('Delete clicked')}
|
||||||
|
/>
|
||||||
|
],
|
||||||
|
show: true
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,9 +1,9 @@
|
||||||
import { AppMaterialIcons } from '@/components/ui';
|
import { AppMaterialIcons } from '@/components/ui';
|
||||||
import { Text } from '@/components/ui';
|
import { Xmark } from '@/components/ui/icons';
|
||||||
import { useAntToken } from '@/styles/useAntToken';
|
import { Text } from '@/components/ui/typography';
|
||||||
import { createStyles } from 'antd-style';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { PopupContainer, PopupSplitter } from '@/components/ui/popup/PopupContainer';
|
import { PopupContainer, PopupSplitter } from '@/components/ui/popup/PopupContainer';
|
||||||
|
import { cn } from '@/lib/classMerge';
|
||||||
|
|
||||||
export const BusterListSelectedOptionPopupContainer: React.FC<{
|
export const BusterListSelectedOptionPopupContainer: React.FC<{
|
||||||
selectedRowKeys: string[];
|
selectedRowKeys: string[];
|
||||||
|
@ -11,8 +11,6 @@ export const BusterListSelectedOptionPopupContainer: React.FC<{
|
||||||
buttons?: React.ReactNode[];
|
buttons?: React.ReactNode[];
|
||||||
show?: boolean;
|
show?: boolean;
|
||||||
}> = ({ selectedRowKeys, onSelectChange, buttons = [], show: showProp }) => {
|
}> = ({ selectedRowKeys, onSelectChange, buttons = [], show: showProp }) => {
|
||||||
const token = useAntToken();
|
|
||||||
|
|
||||||
const show = showProp ?? selectedRowKeys.length > 0;
|
const show = showProp ?? selectedRowKeys.length > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -30,52 +28,35 @@ export const BusterListSelectedOptionPopupContainer: React.FC<{
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const useStyles = createStyles(({ token, css }) => ({
|
|
||||||
closeSelectedButton: css`
|
|
||||||
transition: color 0.2s ease;
|
|
||||||
color: ${token.colorTextSecondary};
|
|
||||||
&:hover {
|
|
||||||
color: ${token.colorText};
|
|
||||||
}
|
|
||||||
`
|
|
||||||
}));
|
|
||||||
|
|
||||||
const SelectedButton: React.FC<{
|
const SelectedButton: React.FC<{
|
||||||
selectedRowKeys: string[];
|
selectedRowKeys: string[];
|
||||||
onSelectChange: (selectedRowKeys: string[]) => void;
|
onSelectChange: (selectedRowKeys: string[]) => void;
|
||||||
}> = ({ selectedRowKeys, onSelectChange }) => {
|
}> = ({ selectedRowKeys, onSelectChange }) => {
|
||||||
const token = useAntToken();
|
|
||||||
const { styles, cx } = useStyles();
|
|
||||||
const text = `${selectedRowKeys.length} selected`;
|
const text = `${selectedRowKeys.length} selected`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="flex items-center"
|
className={cn(
|
||||||
style={{
|
'flex items-center',
|
||||||
backgroundColor: token.colorBgContainer,
|
'bg-bg-container rounded pl-2',
|
||||||
borderRadius: token.borderRadius,
|
'min-h-[28px]',
|
||||||
padding: `0 ${0}px 0 ${token.paddingXS}px`,
|
'border-border-default border border-dashed'
|
||||||
height: token.controlHeight,
|
)}>
|
||||||
border: `0.5px dashed ${token.colorBorder}`
|
|
||||||
}}>
|
|
||||||
<Text>{text}</Text>
|
<Text>{text}</Text>
|
||||||
|
|
||||||
<div
|
<div className="border-border-default ml-1.5 min-h-[28px] border-l border-dashed" />
|
||||||
className="ml-1.5"
|
|
||||||
style={{
|
|
||||||
borderLeft: `0.5px dashed ${token.colorBorder}`,
|
|
||||||
height: token.controlHeight - 2
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onSelectChange([]);
|
onSelectChange([]);
|
||||||
}}
|
}}
|
||||||
className={cx(
|
className={cn(
|
||||||
'flex cursor-pointer items-center justify-center px-0.5',
|
'flex cursor-pointer items-center justify-center px-1',
|
||||||
styles.closeSelectedButton
|
'text-text-secondary hover:text-text-default transition-colors duration-200'
|
||||||
)}>
|
)}>
|
||||||
<AppMaterialIcons icon="close" />
|
<div className="text-base">
|
||||||
|
<Xmark />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue