mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
wip: add action bar for selected blocks
New UI component: ButtonGroup.
This commit is contained in:
53
packages/ui/@/components/ui/button-group.tsx
Normal file
53
packages/ui/@/components/ui/button-group.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Children, ReactElement, cloneElement } from 'react';
|
||||
|
||||
import { ButtonProps } from '@/components/ui/button';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface ButtonGroupProps {
|
||||
className?: string;
|
||||
orientation?: 'horizontal' | 'vertical';
|
||||
children: ReactElement<ButtonProps>[];
|
||||
}
|
||||
|
||||
export const ButtonGroup = ({
|
||||
className,
|
||||
orientation = 'horizontal',
|
||||
children,
|
||||
}: ButtonGroupProps) => {
|
||||
const totalButtons = Children.count(children);
|
||||
const isHorizontal = orientation === 'horizontal';
|
||||
const isVertical = orientation === 'vertical';
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'flex',
|
||||
{
|
||||
'flex-col': isVertical,
|
||||
'w-fit': isVertical,
|
||||
},
|
||||
className
|
||||
)}
|
||||
>
|
||||
{Children.map(children, (child, index) => {
|
||||
const isFirst = index === 0;
|
||||
const isLast = index === totalButtons - 1;
|
||||
|
||||
return cloneElement(child, {
|
||||
className: cn(
|
||||
{
|
||||
'rounded-l-none': isHorizontal && !isFirst,
|
||||
'rounded-r-none': isHorizontal && !isLast,
|
||||
'border-l-0': isHorizontal && !isFirst,
|
||||
|
||||
'rounded-t-none': isVertical && !isFirst,
|
||||
'rounded-b-none': isVertical && !isLast,
|
||||
'border-t-0': isVertical && !isFirst,
|
||||
},
|
||||
child.props.className
|
||||
),
|
||||
});
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { ButtonGroup } from '@/components/ui/button-group'
|
||||
import { Slider, SliderTrack, SliderRange, SliderThumb } from '@/components/ui/slider'
|
||||
import {
|
||||
DropdownMenu,
|
||||
@@ -99,7 +100,7 @@ declare global {
|
||||
}
|
||||
|
||||
const shadui = {
|
||||
Link, Button,
|
||||
Link, Button, ButtonGroup,
|
||||
Slider, SliderTrack, SliderRange, SliderThumb,
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
|
||||
Reference in New Issue
Block a user