-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23795 from storybookjs/charles-ui-updates
UI: Update IconButton and add new Toolbar component
- Loading branch information
Showing
8 changed files
with
386 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import { Toolbar } from './Toolbar'; | ||
import { IconButton } from '../IconButton/IconButton'; | ||
import { Button } from '../Button/Button'; | ||
|
||
const meta: Meta<typeof Toolbar.Root> = { | ||
title: 'Toolbar', | ||
component: Toolbar.Root, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Toolbar.Root>; | ||
|
||
export const Base: Story = { | ||
args: { | ||
hasPadding: true, | ||
borderTop: false, | ||
borderBottom: true, | ||
}, | ||
render: (_, { args }) => ( | ||
<Toolbar.Root {...args}> | ||
<Toolbar.Left> | ||
<Toolbar.ToogleGroup type="single"> | ||
<Toolbar.ToggleItem value="item1"> | ||
<IconButton icon="Sync" size="small" variant="ghost" onClickAnimation="rotate360" /> | ||
</Toolbar.ToggleItem> | ||
<Toolbar.ToggleItem value="item2"> | ||
<IconButton icon="Zoom" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
<Toolbar.ToggleItem value="item2"> | ||
<IconButton icon="ZoomOut" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
<Toolbar.ToggleItem value="item2"> | ||
<IconButton icon="ZoomReset" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
</Toolbar.ToogleGroup> | ||
<Toolbar.Separator /> | ||
<Toolbar.ToogleGroup type="single"> | ||
<Toolbar.ToggleItem value="item1"> | ||
<IconButton icon="Photo" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
<Toolbar.ToggleItem value="item2"> | ||
<IconButton icon="Grid" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
<Toolbar.ToggleItem value="item2"> | ||
<IconButton icon="Grow" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
</Toolbar.ToogleGroup> | ||
<Toolbar.Separator /> | ||
<Toolbar.ToogleGroup type="single"> | ||
<Toolbar.ToggleItem value="item1"> | ||
<Button icon="CircleHollow" size="small" variant="ghost"> | ||
Theme | ||
</Button> | ||
</Toolbar.ToggleItem> | ||
<Toolbar.ToggleItem value="item2"> | ||
<IconButton icon="Ruler" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
<Toolbar.ToggleItem value="item2"> | ||
<IconButton icon="Outline" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
</Toolbar.ToogleGroup> | ||
</Toolbar.Left> | ||
<Toolbar.Right> | ||
<Toolbar.ToogleGroup type="single"> | ||
<Toolbar.ToggleItem value="item2"> | ||
<IconButton icon="Expand" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
<Toolbar.ToggleItem value="item2"> | ||
<IconButton icon="ShareAlt" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
<Toolbar.ToggleItem value="item2"> | ||
<IconButton icon="Link" size="small" variant="ghost" /> | ||
</Toolbar.ToggleItem> | ||
</Toolbar.ToogleGroup> | ||
</Toolbar.Right> | ||
</Toolbar.Root> | ||
), | ||
}; | ||
|
||
export const NoMargin: Story = { | ||
args: { | ||
...Base.args, | ||
hasPadding: false, | ||
}, | ||
render: Base.render, | ||
}; | ||
|
||
export const BorderTop: Story = { | ||
args: { | ||
...Base.args, | ||
borderTop: true, | ||
borderBottom: false, | ||
}, | ||
render: Base.render, | ||
}; | ||
|
||
export const BorderBottom: Story = { | ||
args: { | ||
...Base.args, | ||
borderTop: false, | ||
borderBottom: true, | ||
}, | ||
render: Base.render, | ||
}; | ||
|
||
export const BorderTopBottom: Story = { | ||
args: { | ||
...Base.args, | ||
borderTop: true, | ||
borderBottom: true, | ||
}, | ||
render: Base.render, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import type { ComponentPropsWithoutRef, ElementRef } from 'react'; | ||
import React, { forwardRef } from 'react'; | ||
import * as ToolbarPrimitive from '@radix-ui/react-toolbar'; | ||
import { styled } from '@storybook/theming'; | ||
|
||
interface RootProps extends ComponentPropsWithoutRef<typeof ToolbarPrimitive.Root> { | ||
hasPadding?: boolean; | ||
borderBottom?: boolean; | ||
borderTop?: boolean; | ||
} | ||
|
||
const ToolbarRoot = forwardRef<ElementRef<typeof ToolbarPrimitive.Root>, RootProps>( | ||
({ className, children, ...props }, ref) => ( | ||
<StyledRoot ref={ref} {...props}> | ||
{children} | ||
</StyledRoot> | ||
) | ||
); | ||
ToolbarRoot.displayName = ToolbarPrimitive.Root.displayName; | ||
|
||
const ToolbarSeparator = React.forwardRef< | ||
ElementRef<typeof ToolbarPrimitive.Separator>, | ||
ComponentPropsWithoutRef<typeof ToolbarPrimitive.Separator> | ||
>(({ className, ...props }, ref) => <StyledSeparator ref={ref} {...props} />); | ||
ToolbarSeparator.displayName = ToolbarPrimitive.Separator.displayName; | ||
|
||
const ToolbarToggleGroup = React.forwardRef< | ||
ElementRef<typeof ToolbarPrimitive.ToggleGroup>, | ||
ToolbarPrimitive.ToolbarToggleGroupSingleProps | ToolbarPrimitive.ToolbarToggleGroupMultipleProps | ||
>(({ className, ...props }, ref) => <StyledToggleGroup ref={ref} {...props} />); | ||
ToolbarToggleGroup.displayName = ToolbarPrimitive.ToggleGroup.displayName; | ||
|
||
const ToolbarToggleItem = React.forwardRef< | ||
ElementRef<typeof ToolbarPrimitive.ToggleItem>, | ||
ComponentPropsWithoutRef<typeof ToolbarPrimitive.ToggleItem> | ||
>(({ className, ...props }, ref) => <ToolbarPrimitive.ToggleItem ref={ref} {...props} asChild />); | ||
ToolbarToggleItem.displayName = ToolbarPrimitive.ToggleItem.displayName; | ||
|
||
const StyledRoot = styled(ToolbarPrimitive.Root)<RootProps>( | ||
({ theme, hasPadding = true, borderBottom = true, borderTop = false }) => ({ | ||
display: 'flex', | ||
padding: hasPadding ? '0 10px' : 0, | ||
justifyContent: 'space-between', | ||
height: 40, | ||
borderBottom: borderBottom ? `1px solid ${theme.appBorderColor}` : 'none', | ||
borderTop: borderTop ? `1px solid ${theme.appBorderColor}` : 'none', | ||
boxSizing: 'border-box', | ||
backgroundColor: theme.barBg, | ||
}) | ||
); | ||
|
||
const StyledSeparator = styled(ToolbarPrimitive.Separator)(({ theme }) => ({ | ||
width: 1, | ||
height: 20, | ||
backgroundColor: theme.appBorderColor, | ||
})); | ||
|
||
const StyledToggleGroup = styled(ToolbarPrimitive.ToggleGroup)({ | ||
display: 'flex', | ||
gap: 5, | ||
alignItems: 'center', | ||
}); | ||
|
||
const Left = styled.div({ | ||
display: 'flex', | ||
gap: 5, | ||
alignItems: 'center', | ||
}); | ||
|
||
const Right = styled.div({ | ||
display: 'flex', | ||
gap: 5, | ||
alignItems: 'center', | ||
}); | ||
|
||
export const Toolbar = { | ||
Root: ToolbarRoot, | ||
Left, | ||
Right, | ||
ToogleGroup: ToolbarToggleGroup, | ||
ToggleItem: ToolbarToggleItem, | ||
Separator: ToolbarSeparator, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.